Permalink
Browse files

Merge pull request #6 from filipvaz/master

J'ai ajouté le lien tombapik et la page Média. il ya aussi un début de page admin.
  • Loading branch information...
2 parents 5004bcb + 922184a commit 23d7a3f816181d4d292f69fec0ba6edeb889c534 @Godefroy committed Dec 1, 2011
View
@@ -344,6 +344,19 @@
'vars' => 'controller=IsepOr&action=IsepOrAutocomplete&mode=json',
'url' => 'ajax/isepor/autocomplete'
),
+ //Media's Liste
+ 'media' => array(
+ 'regexp' => '^media(?=\?|$)',
+ 'vars' => 'controller=Media&action=index',
+ 'url' => 'media'
+ ),
+ //Administration
+ 'admin' => array(
+ 'regexp' => '^administration(?=\?|$)',
+ 'vars' => 'controller=Administration&action=index',
+ 'url' => 'administration'
+ ),
+
);
}
@@ -0,0 +1,203 @@
+<?php
+
+class Administration_Controller extends Controller {
+ public function index(){
+ $this->setView('index.php');
+
+ $is_logged = isset(User_Model::$auth_data);
+ $is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
+ $is_admin = $is_logged && User_Model::$auth_data['admin']=='1';
+
+ $this->set(array(
+ 'username' => User_Model::$auth_data['username'],
+ 'is_logged' => $is_logged,
+ 'is_student' => $is_student,
+ 'is_admin' => $is_admin
+ ));
+
+
+ //Fonction qui met à jour l'annuaire dans mysql et ajoute les avatars
+
+
+ //$uploaded_files=array();
+ if(isset($_FILES['uploadzip'])){
+ if($_FILES['uploadzip']['size'] > Config::UPLOAD_MAX_SIZE_FILE)
+ throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE))));
+
+ //On déplace le fichier zipper vers le serveur
+ if($filepaths = File::upload('uploadzip')){
+ // foreach($filepaths as $filepath)
+ // $uploaded_files[] = $filepath;
+ //foreach($filepaths as $i => $filepath){
+ if(!preg_match('#\.zip$#', $filepaths))
+ throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT'));
+ $name = $filepaths;
+ //}
+ }
+ $path=DATA_DIR.Config::DIR_DATA_TMP.'annuaire/';
+ // On dézip celui-ci
+ if(FILE::exists($path)){
+ FILE::delete($path);
+ }
+ File::makeDir($path);
+ $zip = new ZipArchive;
+ $res = $zip->open($name);
+ if ($res === TRUE) {
+ $zip->extractTo($path);
+ $zip->close();
+ unlink($name);
+ }
+ else{
+ throw new Exception(__('ADMIN_POST_ZIPERROR'));
+ }
+ if(File::delete(DATA_DIR.Config::DIR_DATA_TMP.$name)){
+ // On aplique le chmod a tous les dossiers et fichiers du zip
+ FILE::chmodDirectory($path,0);
+ // on traite les fichiers students.csv et users.csv
+
+ if (file_exists($path.'users.csv')){
+ $fp = fopen($path.'users.csv', "r");
+ }
+ else{
+ throw new Exception(__('ADMIN_POST_CSVERROR1'));
+ }
+
+ $i=0;
+ while (!feof($fp)) {
+ $i = $i+1;
+ // Tant qu'on n'atteint pas la fin du fichier
+ $ligne = fgets($fp,4096); /* On lit une ligne */
+ // On récupère les champs séparés par ; dans liste
+ $liste = explode( ";",$ligne);
+ // On assigne les variables
+ if(strlen($liste[0])>1){
+ if (isset($liste[0])){
+ $username = $liste[0];
+ }
+ if (isset($liste[1])){
+ $admin = $liste[1];
+ }
+ if (isset($liste[2])){
+ $mail = $liste[2];
+ }
+ if (isset($liste[3])){
+ $msn = $liste[3];
+ }
+ if (isset($liste[4])){
+ $jabber = $liste[4];
+ }
+ if (isset($liste[5])){
+ $address = $liste[5];
+ }
+ if (isset($liste[6])){
+ $zipcode = $liste[6];
+ }
+ if (isset($liste[7])){
+ $city = $liste[7];
+ }
+ if (isset($liste[8])){
+ $cellphone = $liste[8];
+ }
+ if (isset($liste[9])){
+ $phone = $liste[9];
+ }
+ if (isset($liste[10])){
+ $birthday = $liste[10];
+ }
+
+ if(!$this->model->checkuser($username,1)){
+ $this->model->insertUsers(trim($username),trim($admin),trim($mail),trim($msn),trim($jabber),trim($address),trim($zipcode),trim($city),trim($cellphone),trim($phone),trim($birthday));
+ }
+
+ }
+ }
+ fclose($fp);
+
+ if (file_exists($path.'students.csv')){
+ $fp = fopen($path.'students.csv', "r");
+ }
+ else{
+ throw new Exception(__('ADMIN_POST_CSVERROR2'));
+ }
+
+ $i=0;
+ while (!feof($fp)) {
+ $i = $i+1;
+ // Tant qu'on n'atteint pas la fin du fichier
+ $ligne = fgets($fp,4096); /* On lit une ligne */
+ // On récupère les champs séparés par ; dans liste
+ $liste = explode( ";",$ligne);
+ // On assigne les variables
+ if(strlen($liste[0])>1){
+ if (isset($liste[0])){
+ $username = $liste[0];
+ }
+ if (isset($liste[1])){
+ $lastname = $liste[1];
+ }
+ if (isset($liste[2])){
+ $firstname = $liste[2];
+ }
+ if (isset($liste[3])){
+ $student_number = $liste[3];
+ }
+ if (isset($liste[4])){
+ $promo = $liste[4];
+ }
+ if (isset($liste[5])){
+ $cesure = $liste[5];
+ }
+
+ if(!$this->model->checkuser($username,2)){
+ $this->model->insertStudents(trim($username),trim($lastname),trim($firstname),trim($student_number),trim($promo),trim($cesure));
+ }
+
+ // On déplace et formate les photos dans le dossier avatars
+ $avatarpath = $path.'photos_students/'.$student_number.'.jpg';
+
+ $img = new Image();
+ $img->load($avatarpath);
+ $type = $img->getType();
+ if($type==IMAGETYPE_JPEG)
+ $ext = 'jpg';
+ else if($type==IMAGETYPE_GIF)
+ $ext = 'gif';
+ else if($type==IMAGETYPE_PNG)
+ $ext = 'png';
+ else
+ throw new Exception();
+
+ if($img->getWidth() > 800)
+ $img->setWidth(800, true);
+ $img->setType(IMAGETYPE_JPEG);
+ $img->save($avatarpath);
+
+ // Thumb
+ $avatarthumbpath = $path.'photos_students/'.$student_number.'_thumb.jpg';
+ $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
+ $img->setType(IMAGETYPE_JPEG);
+ $img->save($avatarthumbpath);
+
+ if(FILE::exists(DATA_DIR.Config::DIR_DATA_STORAGE.'avatars/'.substr($student_number, 0, -2).'/')){
+ FILE::move($avatarthumbpath,DATA_DIR.Config::DIR_DATA_STORAGE.'avatars/'.substr($student_number, 0, -2).'/');
+ FILE::move($avatarpath,DATA_DIR.Config::DIR_DATA_STORAGE.'avatars/'.substr($student_number, 0, -2).'/');
+ }
+ else{
+ FILE::makeDir(DATA_DIR.Config::DIR_DATA_STORAGE.'avatars/'.substr($student_number, 0, -2).'/');
+ FILE::move($avatarthumbpath,DATA_DIR.Config::DIR_DATA_STORAGE.'avatars/'.substr($student_number, 0, -2).'/');
+ FILE::move($avatarpath,DATA_DIR.Config::DIR_DATA_STORAGE.'avatars/'.substr($student_number, 0, -2).'/');
+ }
+ unset($img);
+ }
+
+ }
+ fclose($fp);
+ // On supprime le tout du dossier temp
+ FILE::delete($path);
+
+ }
+ }
+
+ }
+
+}
View
@@ -0,0 +1,146 @@
+<?php
+
+class Media_Controller extends Controller {
+ public function index(){
+ $this->setView('index.php');
+
+ $is_logged = isset(User_Model::$auth_data);
+ $is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
+ $is_admin = $is_logged && User_Model::$auth_data['admin']=='1';
+
+ $this->set(array(
+ 'is_logged' => $is_logged,
+ 'is_student' => $is_student,
+ 'is_admin' => $is_admin
+ ));
+ //Pour tout les média
+ $medias=$this->model->getMedias();
+ $annee=array();
+ $mediaannee=array(array());
+ foreach($medias as $media){
+ $date=date('Y',$media['time']);
+ $ok=0;
+ for($i=0;$i<=count($annee);$i++){
+ if($date==$annee[$i]){
+ $ok=1;
+ }
+ }
+ if($ok==0){
+ $annee[count($annee)]=$date;
+ }
+ $mediaannee[''.$date.''][0]=0;
+ array_push($mediaannee[''.$date.''],$media['id']);
+ $mediamessage[''.$media['id'].'']=$media['message'];
+ $categorie[''.$media['id'].'']=$media['category_id'];
+ }
+ $this->set(array(
+ 'annee' => $annee,
+ 'mediaannee' =>$mediaannee,
+ 'mediamessage' =>$mediamessage,
+ 'categorie' =>$categorie
+ ));
+
+ //Pour les photos
+ $photos=$this->model->getPhotos();
+ $annee1=array();
+ $mediaannee1=array(array());
+ foreach($photos as $photo){
+ $date=date('Y',$photo['time']);
+ $ok=0;
+ for($i=0;$i<=count($annee1);$i++){
+ if($date==$annee1[$i]){
+ $ok=1;
+ }
+ }
+ if($ok==0){
+ $annee1[count($annee1)]=$date;
+ }
+ $mediaannee1[''.$date.''][0]=0;
+ array_push($mediaannee1[''.$date.''],$photo['id']);
+ $mediamessage1[''.$photo['id'].'']=$photo['message'];
+ }
+ $this->set(array(
+ 'annee1' => $annee1,
+ 'mediaannee1' =>$mediaannee1,
+ 'mediamessage1' =>$mediamessage1
+ ));
+
+ //Pour les videos
+ $videos=$this->model->getVideos();
+ $annee2=array();
+ $mediaannee2=array(array());
+ foreach($videos as $video){
+ $date=date('Y',$video['time']);
+ $ok=0;
+ for($i=0;$i<=count($annee2);$i++){
+ if($date==$annee2[$i]){
+ $ok=1;
+ }
+ }
+ if($ok==0){
+ $annee2[count($annee2)]=$date;
+ }
+ $mediaannee2[''.$date.''][0]=0;
+ array_push($mediaannee2[''.$date.''],$video['id']);
+ $mediamessage2[''.$video['id'].'']=$video['message'];
+ }
+ $this->set(array(
+ 'annee2' => $annee2,
+ 'mediaannee2' =>$mediaannee2,
+ 'mediamessage2' =>$mediamessage2
+ ));
+
+ //Pour les journaux
+ $journaux=$this->model->getJournaux();
+ $annee3=array();
+ $mediaannee3=array(array());
+ foreach($journaux as $journal){
+ $date=date('Y',$journal['time']);
+ $ok=0;
+ for($i=0;$i<=count($annee3);$i++){
+ if($date==$annee3[$i]){
+ $ok=1;
+ }
+ }
+ if($ok==0){
+ $annee3[count($annee3)]=$date;
+ }
+ $mediaannee3[''.$date.''][0]=0;
+ array_push($mediaannee3[''.$date.''],$journal['id']);
+ $mediamessage3[''.$journal['id'].'']=$journal['message'];
+ }
+ $this->set(array(
+ 'annee3' => $annee3,
+ 'mediaannee3' =>$mediaannee3,
+ 'mediamessage3' =>$mediamessage3
+ ));
+
+ //Pour les Podcast
+ $podcasts=$this->model->getPodcast();
+ $annee4=array();
+ $mediaannee4=array(array());
+ foreach($podcasts as $podcast){
+ $date=date('Y',$podcast['time']);
+ $ok=0;
+ for($i=0;$i<=count($annee4);$i++){
+ if($date==$annee4[$i]){
+ $ok=1;
+ }
+ }
+ if($ok==0){
+ $annee4[count($annee4)]=$date;
+ }
+ $mediaannee4[''.$date.''][0]=0;
+ array_push($mediaannee4[''.$date.''],$podcast['id']);
+ $mediamessage4[''.$podcast['id'].'']=$podcast['message'];
+ }
+ $this->set(array(
+ 'annee4' => $annee4,
+ 'mediaannee4' =>$mediaannee4,
+ 'mediamessage4' =>$mediamessage4
+ ));
+ }
+
+
+}
+?>
Oops, something went wrong.

0 comments on commit 23d7a3f

Please sign in to comment.