芝麻web文件管理V1.00
编辑当前文件:/home/p/r/i/prismawe/www/resuamer/site/application/classes/controller/admin/video.php
template->admin = $admin; $this->template->menuActif = Controller_Admin_Accueil::menuVideo(); $this->template->content = null; if ($this->request->is_initial()) $this->tpl = & $this->template->content; else $this->tpl = & $this->template; } public function action_index() { $id = $this->request->param('id'); if($id != ''){ $candidat = ORM::factory('candidat', $id); if(!$candidat->loaded()){ //le video sélectionné n'existe pas $_SESSION['erreur'][] = 'candidat existe pas'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'video','action' => 'index'))); } $videos = ORM::factory('video')->where('candidat_id', '=', $candidat->getId())->find_all(); }else{ $videos = ORM::factory('video')->find_all(); } $this->tpl = View::factory('admin/video/index'); $this->tpl->videos = $videos; } public function action_modifier(){ $id = $this->request->param('id'); if($id != ''){ $video = ORM::factory('video', $id); if(!$video->loaded()){ //le video sélectionné n'existe pas $_SESSION['erreur'][] = 'video existe pas'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'video','action' => 'index'))); } }else{ //c'est une création $video = ORM::factory('video'); } if(count($_POST)>0){ //on tarite le formulaire $candidat_id = $this->request->post('candidat'); $candidat = ORM::factory('candidat', $candidat_id); if(!$candidat->loaded()){ $_SESSION['erreur'][] = 'Candidat existe pas'; $erreur = true; } $lieu = $this->request->post('lieu'); $date = $this->request->post('date'); if($date == ''){ $_SESSION['erreur'][] = 'Date obligatoire'; $erreur = true; } $videoData = $this->request->post('video'); if($videoData==''){ $_SESSION['erreur'][] = 'Vidéo obligatoire'; $erreur = true; } $video->setCandidat_id($candidat->getId()); $video->setLieu($lieu); $video->setDate($date); $video->setVideo($videoData); $video->save(); $langues = ORM::factory('lang')->find_all(); foreach($langues as $langue){ //on traite les donnée traduite $videolang = orm::factory('videolang') ->where('video_id', '=', $video->getId()) ->and_where('lang_id', '=', $langue->getId()) ->find(); if(!$videolang->loaded()){ $videolang->setVideo_id($video->getId()); $videolang->setLang_id($langue->getId()); } $titre = $this->request->post('titre_'.$langue->getId()); //TOTO vérifier que les champs sont bien rempli, si tous vide c'est qu'on enregistre pas le video if($titre != ''){ $videolang->setTitre($titre); $videolang->save(); } } $_SESSION['info'][] = 'saved'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'video','action' => 'index'))); } $this->tpl = View::factory('admin/video/modifier'); $this->tpl->video = $video; $this->tpl->candidats = ORM::factory('candidat')->find_all(); $this->tpl->langues = ORM::factory('lang')->find_all(); $this->tpl->id = $video->getId(); } public function action_supprimer(){ $id = $this->request->param('id'); $video = ORM::factory('video', $id); if(!$video->loaded()){ //le video sélectionné n'existe pas $_SESSION['erreur'][] = 'type evenement existe pas'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'video','action' => 'index'))); }else{ //on supprime les lang associé foreach($video->videoslang->find_all() as $videolang){ $videolang->delete(); } //on supprime l'video $video->delete(); $_SESSION['info'][] = 'Type evenement suprimée'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'video','action' => 'index'))); } } }