芝麻web文件管理V1.00
编辑当前文件:/home/p/r/i/prismawe/www/resuamer/site/application/classes/controller/admin/proposition.php
template->admin = $admin; $this->template->menuActif = Controller_Admin_Accueil::menuThemes(); $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/proposition/index'); $this->tpl->propositions = ORM::factory('proposition')->find_all(); } public function action_modifier(){ $id = $this->request->param('id'); if($id != ''){ $proposition = ORM::factory('proposition', $id); if(!$proposition->loaded()){ //le theme sélectionné n'existe pas $_SESSION['erreur'][] = 'proposition existe pas'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'proposition','action' => 'index'))); } }else{ //c'est une création $proposition = ORM::factory('proposition'); } if(count($_POST)>0){ //on tarite le formulaire //on traite les donnée non traduite $rules = Validation::factory($_POST) ->rule('candidat', 'not_empty') ->rule('election', 'not_empty') ->rule('theme', 'not_empty'); $data = $rules->as_array(); //on peuple theme mais on save que si c'est correcte $erreur = false; $candidat = ORM::factory('candidat', $data['candidat']); if($candidat->loaded()) $proposition->setCandidat_id($candidat->getId()); else{ $erreur = true; $_SESSION['erreur'][] = 'Le candidat n\'existe pas'; } $election = ORM::factory('election', $data['election']); if($election->loaded()) $proposition->setElection_id($election->getId()); else{ $erreur = true; $_SESSION['erreur'][] = 'L\'election n\'existe pas'; } $theme = ORM::factory('theme', $data['theme']); if($theme->loaded()) $proposition->setTheme_id($theme->getId()); else{ $erreur = true; $_SESSION['erreur'][] = 'Le theme n\'existe pas'; } if($rules->check() && !$erreur){ $proposition->save(); $langues = ORM::factory('lang')->find_all(); foreach($langues as $langue){ //on traite les donnée traduite $propositionlang = ORM::factory('propositionlang') ->where('proposition_id', '=', $proposition->getId()) ->and_where('lang_id', '=', $langue->getId()) ->find(); if(!$propositionlang->loaded()){ $propositionlang->setProposition_id($proposition->getId()); $propositionlang->setLang_id($langue->getId()); } $libelle = $this->request->post('libelle_'.$langue->getId()); $question = $this->request->post('question_'.$langue->getId()); //TOTO vérifier que les champs sont bien rempli, si tous vide c'est qu'on enregistre pas le theme if($libelle != '' && $question != ''){ $propositionlang->setLibelle($libelle); $propositionlang->setQuestion($question); $propositionlang->save(); } } $_SESSION['info'][] = 'saved'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'proposition','action' => 'index'))); }else{ //erreur dans le fomulaire foreach ($rules->errors('messages/admin/theme') as $error) { $_SESSION['erreur'][] = $error; } } } $this->tpl = View::factory('admin/proposition/modifier'); $this->tpl->proposition = $proposition; $this->tpl->candidats = ORM::factory('candidat')->find_all(); $this->tpl->elections = ORM::factory('election')->find_all(); $this->tpl->themes = ORM::factory('theme')->find_all(); $this->tpl->langues = ORM::factory('lang')->find_all(); $this->tpl->id = $proposition->id; } }