芝麻web文件管理V1.00
编辑当前文件:/home/p/r/i/prismawe/www/resuamer/site/application/classes/controller/admin/parti.php
template->admin = $admin; $this->template->menuActif = Controller_Admin_Accueil::menuPartiPolitique(); $this->template->content = null; if ($this->request->is_initial()) $this->tpl = & $this->template->content; else $this->tpl = & $this->template; } public function action_index() { $this->tpl = View::factory('admin/parti/index'); $this->tpl->partis = ORM::factory('parti')->find_all(); } public function action_modifier(){ $id = $this->request->param('id'); if($id != ''){ $parti = ORM::factory('parti', $id); if(!$parti->loaded()){ //le parti sélectionné n'existe pas $_SESSION['erreur'][] = 'parti existe pas'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'parti','action' => 'index'))); } }else{ //c'est une création $parti = ORM::factory('parti'); } if(count($_POST)>0){ //on tarite le formulaire //on traite les donnée non traduite $erreur = false; $dateCreation = $this->request->post('date_creation'); if(!preg_match("#^[\d]{4}-[\d]{2}-[\d]{2}$#", $dateCreation)){ $erreur = true; } $dateDissolution = $this->request->post('date_dissolution'); if(!preg_match("#^[\d]{4}-[\d]{2}-[\d]{2}$#", $dateDissolution) && $dateDissolution!= null){ $erreur = true; } if(!$erreur){ $parti->setDateCreation($dateCreation); $parti->setDateDissolution($dateDissolution); $parti->save(); $langues = ORM::factory('lang')->find_all(); foreach($langues as $langue){ //on traite les donnée traduite $partilang = orm::factory('partilang') ->where('parti_id', '=', $parti->getId()) ->and_where('lang_id', '=', $langue->getId()) ->find(); if(!$partilang->loaded()){ $partilang->setPartiId($parti->getId()); $partilang->setLangId($langue->getId()); } $nom = $this->request->post('nom_'.$langue->getId()); $initiales = $this->request->post('initiales_'.$langue->getId()); $description = $this->request->post('description_'.$langue->getId()); $metadescription = $this->request->post('metadescription_'.$langue->getId()); //TOTO vérifier que les champs sont bien rempli, si tous vide c'est qu'on enregistre pas le parti if($nom != ''&& $initiales != ''&& $description != '' && $metadescription != ''){ $partilang->setNom($nom); $partilang->setInitiales($initiales); $partilang->setDescription($description); $partilang->setMetadescription($metadescription); $partilang->save(); } } $_SESSION['info'][] = 'saved'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'parti','action' => 'index'))); }else{ //erreur dans le fomulaire } } $this->tpl = View::factory('admin/parti/modifier'); $this->tpl->parti = $parti; $this->tpl->langues = ORM::factory('lang')->find_all(); $this->tpl->id = $parti->id; } public function action_supprimer(){ $id = $this->request->param('id'); $parti = ORM::factory('parti', $id); if(!$parti->loaded()){ //le parti sélectionné n'existe pas $_SESSION['erreur'][] = 'parti existe pas'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'parti','action' => 'index'))); }else{ //on supprime le parti $parti->delete(); $_SESSION['info'][] = 'Parti suprimée'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'parti','action' => 'index'))); } } }