芝麻web文件管理V1.00
编辑当前文件:/home/prismawe/www/resupres/application/classes/controller/admin/premiertour.php
where('isCandidate', "=", 1) ->order_by('nom', 'ASC') ->order_by('prenom', 'ASC') ->find_all(); //On récupère les valeurs de la tables résultats à l'échelle nationale $resultats = ORM::factory('resultat') ->and_where_open() ->where("region_id", "IS", NULL) ->and_where("departement_id", "IS", NULL) ->and_where("ville_id", "IS", NULL) ->and_where_close() ->find_all(); //On récupère toutes les régions $regions = ORM::factory('regionrslt')->find_all(); $this->template->content = View::factory('admin/premiertour/list'); $this->template->content->candidats = $candidats; $this->template->content->resultats = $resultats; $this->template->content->regions = $regions; //Si le formulaire a été envoyé if($_SERVER['REQUEST_METHOD'] == 'POST') { $nbvotes = $this->request->post('nbvotes'); $pourcentages = $this->request->post('pourcentage'); foreach ($nbvotes as $key => $value) { $modif = false; $resultat = ORM::factory('resultat') ->where('candidat_id', '=', $key) ->and_where('region_id', "IS", NULL) ->and_where('departement_id', "IS", NULL) ->and_where('ville_id', "IS", NULL) ->find(); if($resultat->loaded()) { if($value != '') { $resultat->nbvotes = $value; } else { $resultat->nbvotes = 0; } if($pourcentages[$key] != '') { $resultat->tauxvotes = $pourcentages[$key]; } $resultat->tour = "Premier tour"; $resultat->candidat_id = $key; $resultat->save(); } else { $candidat = ORM::factory('candidat', $key); if($candidat->loaded()) { if($value != '') { $resultat->nbvotes = $value; $modif = true; } else { $resultat->nbvotes = 0; } if($pourcentages[$key] != '') { $resultat->tauxvotes = $pourcentages[$key]; $modif = true; } if($modif) { $resultat->tour = "Premier tour"; $resultat->candidat_id = $key; $resultat->save(); } } else { echo "Attention : le candidat n'existe pas !
"; } } } $this->request->redirect('admin/premiertour'); } } public function action_departement() { $this->auto_render = FALSE; $departements = ORM::factory('departement')->where('regionrslt_id', "=", $this->request->post('region'))->find_all(); foreach($departements as $dep) { echo $dep->id.";".$dep->nom."|"; } } public function action_ville() { $this->auto_render = FALSE; $villes = ORM::factory('ville') ->where("departement_id", "=", $this->request->post('dept')) ->and_where("nom", "LIKE", $this->request->post('search')."%") //->or_where("code_postal", "LIKE", $this->request->post('search')."%") ->find_all(); foreach($villes as $ville) { echo $ville->nom."/".$ville->id."|"; } } public function action_geo() { if($_SERVER['REQUEST_METHOD'] == 'POST') { $this->template->content = View::factory('admin/premiertour/geo'); if($this->request->post('insee') != '') { $ville = ORM::factory("ville", $this->request->post('insee')); $this->template->content->ville = $ville; $this->request->redirect("admin/premiertour/seg/".$this->request->post('region')."/".$this->request->post('dep')."/".$this->request->post('insee')); } else if($this->request->post('dep') != '*') { $departement = ORM::factory("departement", $this->request->post('dep')); $this->template->content->dept = $departement; $this->request->redirect("admin/premiertour/seg/".$this->request->post('region')."/".$this->request->post('dep')); } else { $regionSelected = ORM::factory("regionrslt", $this->request->post('region')); $this->template->content->regionSelected = $regionSelected; $this->request->redirect("admin/premiertour/seg/".$this->request->post('region')); } // On récupère tous les candidats officiels $candidats = ORM::factory('candidat') ->where('isCandidate', "=", 1) ->order_by('nom', 'ASC') ->order_by('prenom', 'ASC') ->find_all(); //On récupère toutes les régions $regions = ORM::factory('regionrslt')->find_all(); $this->template->content->candidats = $candidats; $this->template->content->regions = $regions; } else { $this->request->redirect('admin/premiertour'); } } public function action_geoTraitement() { //Si le formulaire a été envoyé if($_SERVER['REQUEST_METHOD'] == 'POST') { $nbvotes = $this->request->post('nbvotes'); $pourcentages = $this->request->post('pourcentage'); $champGeo = $this->request->post('champ'); $id = $this->request->post('id'); var_dump($this->request->post()); foreach ($nbvotes as $key => $value) { $modif = false; $resultat = ORM::factory('resultat') ->where('candidat_id', '=', $key) ->and_where($champGeo, "=", $id) ->find(); if($resultat->loaded()) { echo "Candidat ".$key." se met à jour
"; if($value != '') { $resultat->nbvotes = $value; } else { $resultat->nbvotes = 0; } if($pourcentages[$key] != '') { $resultat->tauxvotes = $pourcentages[$key]; } $resultat->tour = "Premier tour"; $resultat->candidat_id = $key; $resultat->save(); } else { echo "Candidat ".$key." n'a pas de résultat !
"; $candidat = ORM::factory('candidat', $key); if($candidat->loaded()) { if($value != '') { $resultat->nbvotes = $value; $modif = true; } else { $resultat->nbvotes = 0; } if($pourcentages[$key] != '') { $resultat->tauxvotes = $pourcentages[$key]; $modif = true; } if($modif) { echo "J'ajoute resultat de ".$key." !
"; $resultat->tour = "Premier tour"; $resultat->candidat_id = $key; $resultat->$champGeo = $id; $resultat->save(); } } else { echo "Attention : le candidat ".$key." n'existe pas !
"; } } } $this->request->redirect($this->request->referrer()); } } public function action_seg() { $this->template->content = View::factory('admin/premiertour/geo'); if($this->request->param('idville') != '') { $ville = ORM::factory("ville", $this->request->param('idville')); $this->template->content->ville = $ville; } else if($this->request->param('iddep')) { $departement = ORM::factory("departement", $this->request->param('iddep')); $this->template->content->dept = $departement; } else { $regionSelected = ORM::factory("regionrslt", $this->request->param('id')); $this->template->content->regionSelected = $regionSelected; } // On récupère tous les candidats officiels $candidats = ORM::factory('candidat') ->where('isCandidate', "=", 1) ->order_by('nom', 'ASC') ->order_by('prenom', 'ASC') ->find_all(); //On récupère toutes les régions $regions = ORM::factory('regionrslt')->find_all(); $this->template->content->candidats = $candidats; $this->template->content->regions = $regions; } }