X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fsurvey.php;h=105111766d78da50f85bd857106d1549e1c91d20;hb=9f01f40bbb3074f13b228d98f3a9db8f23ea4992;hp=b53577f41a937294b9336e4f3f0c3e1080d32a90;hpb=441c2451a618423c3ce326af2598714b68e40631;p=platal.git diff --git a/modules/survey.php b/modules/survey.php index b53577f..1051117 100644 --- a/modules/survey.php +++ b/modules/survey.php @@ -27,6 +27,7 @@ class SurveyModule extends PLModule return array( 'survey' => $this->make_hook('index', AUTH_PUBLIC), 'survey/vote' => $this->make_hook('vote', AUTH_PUBLIC), + 'survey/result' => $this->make_hook('result', AUTH_PUBLIC), 'survey/edit' => $this->make_hook('edit', AUTH_COOKIE), 'survey/ajax' => $this->make_hook('ajax', AUTH_COOKIE), 'survey/admin' => $this->make_hook('admin', AUTH_MDP, 'admin'), @@ -48,7 +49,7 @@ class SurveyModule extends PLModule } // }}} - // {{{ function handler_vote() + // {{{ function handler_vote() : handles the vote to a survey function handler_vote(&$page, $id = -1) { if (Post::has('survey_cancel')) { // if the user cancels, returns to index @@ -65,15 +66,8 @@ class SurveyModule extends PLModule } elseif ($survey->isEnded()) { return $this->show_error($page, "Le sondage ".$survey->getTitle()." est terminé."); } - if (!$survey->isMode(Survey::MODE_ALL)) { // if the survey is reserved to alumni - global $globals; - if (!call_user_func(array($globals->session, 'doAuth'))) { // checks authentification - global $platal; - $platal->force_login($page); - } - if ($survey->isMode(Survey::MODE_XIDENT) && !$survey->checkPromo(S::v('promo'))) { // checks promotion - return $this->show_error($page, "Tu n'as pas accès à ce sondage car il est réservé à d'autres promotions."); - } + if (!$this->check_surveyPerms($page, $survey)) { + return; } if (Post::has('survey_submit')) { // checks if the survey has already been filled in $uid = 0; @@ -97,6 +91,28 @@ class SurveyModule extends PLModule } // }}} + // {{{ function handler_result() : show the results of the votes to a survey + function handler_result($page, $id = -1, $qid = 'all') + { + $id = intval($id); + if ($id == -1) { + return $this->show_error($page, "Un identifiant de sondage doit être précisé.", ''); + } + require_once dirname(__FILE__).'/survey/survey.inc.php'; + $survey = Survey::retrieveSurvey($id); // retrieves the survey object structure + if ($survey == null || !$survey->isValid()) { + return $this->show_error($page, "Sondage ".$id." introuvable.", ''); + } elseif (!$survey->isEnded()) { + return $this->show_error($page, "Le sondage ".$survey->getTitle()." n'est pas encore terminé."); + } + if (!$this->check_surveyPerms($page, $survey)) { + return; + } + $page->assign('survey_resultmode', true); + $this->show_survey($page, $survey); + } + // }}} + // {{{ function handler_admin() : index of admin mode function handler_admin(&$page, $id = -1) { @@ -348,6 +364,25 @@ class SurveyModule extends PLModule } // }}} + // {{{ function check_surveyPerms() : checks the particular surveys access permissions + function check_surveyPerms(&$page, $survey) + { + require_once dirname(__FILE__).'/survey/survey.inc.php'; + if (!$survey->isMode(Survey::MODE_ALL)) { // if the survey is reserved to alumni + global $globals; + if (!call_user_func(array($globals->session, 'doAuth'))) { // checks authentification + global $platal; + $platal->force_login($page); + } + if (!$survey->checkPromo(S::v('promo'))) { // checks promotion + $this->show_error($page, "Tu n'as pas accès à ce sondage car il est réservé à d'autres promotions."); + return false; + } + } + return true; + } + // }}} + // {{{ function show_survey() : calls the template to display a survey, for editing, voting, or consulting the results function show_survey(&$page, $survey) {