芝麻web文件管理V1.00
编辑当前文件:/home/p/r/i/prismawe/www/resupres/application/classes/controller/accueil.php
request->redirect('elections2012/resultat_second_tour'); $this->template->menuActif = 'accueil'; //On récupère le duel de la date du jour $duel = ORM::factory('duel') ->where('dateDebut', '<=', DB::expr('current_date')) ->and_where('dateFin', '>=', DB::expr('current_date')) ->find(); //On récupère le duel du lendemain $duelLendemain = ORM::factory('duel') ->where('dateDebut', '>', $duel->dateFin) ->order_by('dateDebut') ->find(); // On récupère le duel du sur-lendemain $duelSurLendemain = ORM::factory('duel') ->where('dateDebut', '>', $duelLendemain->dateFin) ->order_by('dateDebut') ->find(); // On récupère le duel d'hier $duelHier = ORM::factory('duel') ->where('dateDebut', '<', $duel->dateDebut) ->order_by('dateDebut', 'DESC') ->find(); // On détermine le vainqueur d'hier $votesCandidat1Hier = ORM::factory('vote') ->where('duel_id', '=', $duelHier->id) ->and_where('candidat_id', '=', $duelHier->candidat1_id) ->find_all() ->count(); $votesCandidat2Hier = ORM::factory('vote') ->where('duel_id', '=', $duelHier->id) ->and_where('candidat_id', '=', $duelHier->candidat2_id) ->find_all() ->count(); $votesCandidatBlancHier = ORM::factory('vote') ->where('duel_id', '=', $duelHier->id) ->and_where('candidat_id', '=', 0) ->find_all() ->count(); $regions = ORM::factory('region') ->order_by('nom','asc') ->find_all(); $ages = ORM::factory('age') ->find_all(); $categSocProcs = ORM::factory('categoriesocio') ->order_by('nom','asc') ->find_all(); $regionsVote = ORM::factory('region') ->where('id', '!=', '0') ->order_by('nom','asc') ->find_all(); $agesVote = ORM::factory('age') ->where('id', '!=', '0') ->find_all(); $categSocProcsVote = ORM::factory('categoriesocio') ->where('id', '!=', '0') ->order_by('nom','asc') ->find_all(); $nbVotesHier = $votesCandidat1Hier + $votesCandidat2Hier + $votesCandidatBlancHier; if ($votesCandidat1Hier >= $votesCandidat2Hier) { $vainqueurHier = $duelHier->candidat1; $perdantHier = $duelHier->candidat2; $votesVainqueurHier = $votesCandidat1Hier; $votesPerdantHier = $votesCandidat2Hier; } else { $vainqueurHier = $duelHier->candidat2; $perdantHier = $duelHier->candidat1; $votesVainqueurHier = $votesCandidat2Hier; $votesPerdantHier = $votesCandidat1Hier; } //On vérifie si l'adresse ip a déja voté $adresseSha = hash("sha256", $_SERVER['REMOTE_ADDR']); $verif = ORM::factory('vote') ->where('cle', '=', $adresseSha) ->and_where('duel_id', '=', $duel->id)->find(); //On renvoit un booleen qui signale a la page si il y a eu vote $dejaVote = $verif->loaded(); //On place en session l'id du Duel $_SESSION['idDuel'] = $duel->id; //On prépare les requetes pour les résultats de chaque candidats $votesCandidat1 = ORM::factory('vote')->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat1_id); // ->find_all(); $votesCandidat2 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat2_id); // ->find_all(); $votesCandidatBlanc = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', 0); //->find_all(); if (count($_POST) > 0) { //Si une region a été saisie if ($this->request->post('region_id') !== '-1') { //On le rajoute à toute les requêtes $votesCandidat1->and_where('region_id', '=', $this->request->post('region_id')); $votesCandidat2->and_where('region_id', '=', $this->request->post('region_id')); $votesCandidatBlanc->and_where('region_id', '=', $this->request->post('region_id')); } //Si un age a été saisi if ($this->request->post('age_id') !== '-1') { //On le rajoute à toute les requêtes $votesCandidat1->and_where('age_id', '=', $this->request->post('age_id')); $votesCandidat2->and_where('age_id', '=', $this->request->post('age_id')); $votesCandidatBlanc->and_where('age_id', '=', $this->request->post('age_id')); } //Si une categ a été saisie if ($this->request->post('categoriesocio_id') !== '-1') { //On le rajoute à toute les requêtes $votesCandidat1->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); $votesCandidat2->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); $votesCandidatBlanc->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); } } $votesCandidat1 = $votesCandidat1->find_all(); $votesCandidat2 = $votesCandidat2->find_all(); $votesCandidatBlanc = $votesCandidatBlanc->find_all(); //Pour afficher le nombre de votant dans chaque catégorie $nombreVotantAge = ''; foreach ($ages as $age) { $req = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('age_id', '=', $age->id); if (count($_POST) > 0) { if ($this->request->post('region_id') !== '-1') { $req->and_where('region_id', '=', $this->request->post('region_id')); } if ($this->request->post('age_id') !== '-1') { $req->and_where('age_id', '=', $this->request->post('age_id')); } if ($this->request->post('categoriesocio_id') !== '-1') { $req->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); } } $req = $req->find_all(); $nombreVotantAge[$age->id] = count($req); } $nombreVotantCat = ''; foreach ($categSocProcs as $cat) { $req = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('categoriesocio_id', '=', $cat->id); if (count($_POST) > 0) { if ($this->request->post('region_id') !== '-1') { $req->and_where('region_id', '=', $this->request->post('region_id')); } if ($this->request->post('age_id') !== '-1') { $req->and_where('age_id', '=', $this->request->post('age_id')); } if ($this->request->post('categoriesocio_id') !== '-1') { $req->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); } } $req = $req->find_all(); $nombreVotantCat[$cat->id] = count($req); } $nombreVotantRegion = ''; foreach ($regions as $region) { $req = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('region_id', '=', $region->id); if (count($_POST) > 0) { if ($this->request->post('region_id') !== '-1') { $req->and_where('region_id', '=', $this->request->post('region_id')); } if ($this->request->post('age_id') !== '-1') { $req->and_where('age_id', '=', $this->request->post('age_id')); } if ($this->request->post('categoriesocio_id') !== '-1') { $req->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); } } $req = $req->find_all(); $nombreVotantRegion[$region->id] = count($req); } $totalVotes = count($votesCandidat1) + count($votesCandidat2) + count($votesCandidatBlanc); if ($totalVotes > 0) { //Si il y a quelque chose dans le post on mets les options //selectionnées en selectionnées et on recalcule les pourcentages. $pourcentage1 = count($votesCandidat1) / $totalVotes * 100; $pourcentage2 = count($votesCandidat2) / $totalVotes * 100; $pourcentageBlanc = count($votesCandidatBlanc) / $totalVotes * 100; } else { $pourcentage1 = 0; $pourcentage2 = 0; $pourcentageBlanc = 0; } $this->template->metaDescription = 'Chaque semaine un duel politique entre deux prétendants à l\'élection présidentielle de 2012! Grace aux résultats affichés en direct, suivez heure par heure l\'évolution du sondage!'; $this->template->metaKeywords = 'résultat présidentielle 2012, résultats présidentielles 2012,présidentielle, sondage 2012, ségolène royale, Nicolas Sarkozy, François Hollande'; $this->template->content = View::factory('accueil/index'); $this->template->content->duel = $duel; $this->template->content->duelHier = $duelHier; $this->template->content->duelLendemain = $duelLendemain; $this->template->content->duelSurLendemain = $duelSurLendemain; $this->template->content->dejaVote = $dejaVote; $this->template->content->votesCandidat1 = $votesCandidat1; $this->template->content->votesCandidat2 = $votesCandidat2; $this->template->content->votesCandidatBlanc = $votesCandidatBlanc; $this->template->content->totalVotes = $totalVotes; $this->template->content->pourcentage1 = round($pourcentage1, 2); $this->template->content->pourcentage2 = round($pourcentage2, 2); $this->template->content->pourcentageBlanc = round($pourcentageBlanc, 2); $this->template->content->vainqueurHier = $vainqueurHier; $this->template->content->perdantHier = $perdantHier; $this->template->content->nbVotesHier = $nbVotesHier; $this->template->content->votesVainqueurHier = $votesVainqueurHier; $this->template->content->votesPerdantHier = $votesPerdantHier; $this->template->content->votesCandidatBlancHier = $votesCandidatBlancHier; $this->template->content->regions = $regions; $this->template->content->ages = $ages; $this->template->content->categSocProcs = $categSocProcs; $this->template->content->regionsVote = $regionsVote; $this->template->content->agesVote = $agesVote; $this->template->content->categSocProcsVote = $categSocProcsVote; $this->template->content->nbVotantAge = $nombreVotantAge; $this->template->content->nbVotantCat = $nombreVotantCat; $this->template->content->nbVotantRegion = $nombreVotantRegion; // On regarde s'il vient tout juste de voter if (isset($_SESSION['hasJustVoted'])) { $this->template->content->hasJustVoted = true; unset($_SESSION['hasJustVoted']); } /* * Flux rss 20Minutes politique http://www.20minutes.fr/rss/politique.xml */ $url = 'http://www.20minutes.fr/rss/politique.xml'; /* $rss_file = file_get_contents($url); $xml = new SimpleXMLElement($rss_file); $this->template->content->xml = $xml; */ } public function action_vote() { // On vérifie s'il n'y a pas déjà eu un vote $alreadyVoted = ORM::factory('vote') ->where('cle', '=', hash('sha256', $_SERVER['REMOTE_ADDR'])) ->and_where('duel_id', '=', $_SESSION['idDuel']) ->find(); if (!$alreadyVoted->loaded()) { $vote = ORM::factory('vote'); $vote->cle = hash("sha256", $_SERVER['REMOTE_ADDR']); $vote->jourHeure = date('Y-m-d H:i:s'); $vote->candidat_id = $this->request->param('id'); $vote->duel_id = $_SESSION['idDuel']; if (count($_POST > 0)) { $vote->region_id = $this->request->post('region_id'); $vote->age_id = $this->request->post('age_id'); $vote->categoriesocio_id = $this->request->post('categoriesocio_id'); $mail = $this->request->post('mail'); if ($mail != '') { if (filter_var($mail, FILTER_VALIDATE_EMAIL)) { $email = new Model_Mail(); $email->mail = $mail; $email->save(); //ajout à la mailing list try { $soap = new SoapClient("https://www.ovh.com/soapi/soapi-re-1.24.wsdl"); //login $session = $soap->login("lr23459-ovh", "c1i3p9", "fr", false); //echo "login successfull\n"; $result = $soap->mailingListSubscriberList($session, "prisma-web.pro", "resultats-presidentielles-2012"); if (in_array($mail, $result)) { $_SESSION['mailInfo'] = 'Déjà inscrit.'; } else { //email existe pas on l'ajoute //mailingListSubscriberAdd $soap->mailingListSubscriberAdd($session, "prisma-web.pro", "resultats-presidentielles-2012", $mail); //echo "mailingListSubscriberAdd successfull\n"; $_SESSION['mailInfo'] = 'E-mail enregistré.'; } //logout $soap->logout($session); //echo "logout successfull\n"; } catch (SoapFault $fault) { //echo $fault; } } } } $vote->save(); if ($vote->saved()) { $_SESSION['hasJustVoted'] = true; $this->request->redirect('accueil#duel'); } else { //Redirige vers une page d'érreur (à faire) $this->request->redirect('election2012/erreur'); } } else $this->request->redirect('accueil'); } public function action_newsletter(){ if(count($_POST)>0){ $mail = $this->request->post('mail'); if ($mail != '') { if (filter_var($mail, FILTER_VALIDATE_EMAIL)) { //on vérfie qu'il est pas déjà inscrit $checkMail = ORM::factory('mail')->where('mail', '=', $mail)->find(); if(!$checkMail->loaded()){ //existe pas on enregistre $email = new Model_Mail(); $email->mail = $mail; $email->save(); //ajout à la mailing list try { $soap = new SoapClient("https://www.ovh.com/soapi/soapi-re-1.24.wsdl"); //login $session = $soap->login("lr23459-ovh", "c1i3p9", "fr", false); //echo "login successfull\n"; $result = $soap->mailingListSubscriberList($session, "prisma-web.pro", "resultats-presidentielles-2012"); if (in_array($mail, $result)) { $_SESSION['mailInfo'] = 'Déjà inscrit.'; } else { //email existe pas on l'ajoute //mailingListSubscriberAdd $soap->mailingListSubscriberAdd($session, "prisma-web.pro", "resultats-presidentielles-2012", $mail); //echo "mailingListSubscriberAdd successfull\n"; $_SESSION['mailInfo'] = 'E-mail enregistré.'; } //logout $soap->logout($session); //echo "logout successfull\n"; } catch (SoapFault $fault) { //echo $fault; } $_SESSION['mailInfo'] = 'E-mail enregistré.'; }else{ //petite erreur $_SESSION['mailInfo'] = 'Déjà inscrit.'; } }else{ //mail incorrecte $_SESSION['mailErreur'] = 'Adresse e-mail incorrecte.'; } }else{ $_SESSION['mailErreur'] = 'Aucune adresse e-mail.'; } } $this->request->redirect('accueil'); } public function action_duelEnCoursJSON(){ $duel = ORM::factory('duel') ->where('dateDebut', '<=', DB::expr('current_date')) ->and_where('dateFin', '>=', DB::expr('current_date')) ->find(); if ($duel->loaded()){ $this->template = View::factory('duelencoursjson'); $this->template->duel = $duel; } } }