芝麻web文件管理V1.00
编辑当前文件:/home/p/r/i/prismawe/www/resuamer/site/application/classes/controller/admin/lang.php
template->admin = $admin; $this->template->menuActif = Controller_Admin_Accueil::menuLangues(); $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/lang/index'); $this->tpl->langs = ORM::factory('lang')->find_all(); } public function action_modifier(){ $id = $this->request->param('id'); if($id != ''){ $lang = ORM::factory('lang', $id); if(!$lang->loaded()){ //le lang sélectionné n'existe pas $_SESSION['erreur'][] = 'lang existe pas'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'lang','action' => 'index'))); } }else{ //c'est une création $lang = ORM::factory('lang'); } if(count($_POST)>0){ //on tarite le formulaire //on traite les donnée non traduite $rules = Validation::factory(array_merge($_POST, $_FILES)) ->rule('longname', 'not_empty') ->rule('longname', 'max_length', array(':value', 45)) ->rule('name', 'not_empty') ->rule('name', 'max_length', array(':value', 45)); if($_FILES['image']['size']>1){ $rules=$rules->rule('image', 'Upload::image') ->rule('image', 'Upload::valid') ->rule('image', 'Upload::not_empty') ->rule('image', 'Upload::type', array(':value', array('gif'))); } $data = $rules->as_array(); $lang->setName($data['name']); $lang->setLongname($data['longname']); if($rules->check()){ if($_FILES['image']['size']>1){ // Envoi de la photo en question sur le serveur $name = $lang->getName().'.gif'; if (file_exists('images/lang/'.$name)) { unlink ('images/lang/'.$name); } Upload::save($_FILES['image'], $name, 'images/lang'); } $lang->save(); $_SESSION['info'][] = 'saved'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'lang','action' => 'index'))); }else{ //erreur dans le fomulaire foreach ($rules->errors('messages/admin/lang') as $error) { $_SESSION['erreur'][] = $error; } } } $this->tpl = View::factory('admin/lang/modifier'); $this->tpl->lang = $lang; $this->tpl->langues = ORM::factory('lang')->find_all(); $this->tpl->id = $lang->id; } public function action_supprimer(){ $id = $this->request->param('id'); $lang = ORM::factory('lang', $id); if(!$lang->loaded()){ //le lang sélectionné n'existe pas $_SESSION['erreur'][] = 'lang existe pas'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'lang','action' => 'index'))); }else{ //on supprime la langue if (file_exists('images/lang/'.$lang->getName().'.gif')) { unlink ('images/lang/'.$lang->getName().'.gif'); } $lang->delete(); $_SESSION['erreur'][] = 'Langue suprimée'; $this->request->redirect(Route::get('admin')->uri(array('controller'=>'lang','action' => 'index'))); } } }