+ $page->assign('survey_current', Survey::retrieveList('c'));
+ $page->assign('survey_old', Survey::retrieveList('o'));
+ $page->assign('survey_modes', Survey::getModes(false));
+ }
+ // }}}
+
+ // {{{ 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
+ return $this->handler_index(&$page);
+ }
+ $id = intval($id);
+ if ($id == -1) {
+ return $this->show_error($page, "Un identifiant de sondage doit être précisé.", 'survey');
+ }
+ $this->load('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.", 'survey');
+ } elseif ($survey->isEnded()) {
+ return $this->show_error($page, "Le sondage ".$survey->getTitle()." est terminé.", 'survey');
+ }
+ if (!$this->check_surveyPerms($page, $survey)) {
+ return PL_DO_AUTH;
+ }
+ if (Post::has('survey_submit')) { // checks if the survey has already been filled in
+ // admins can see the survey but not vote
+ if (!$this->check_surveyPerms($page, $survey, false, false)) {
+ return PL_DO_AUTH;
+ }
+ $uid = 0;
+ if (!$survey->isMode(Survey::MODE_ALL)) { // if survey is restriced to alumni
+ $uid = S::v('uid');
+ if ($survey->hasVoted($uid)) { // checks whether the user has already voted
+ return $this->show_error($page, "Tu as déjà voté à ce sondage.", 'survey');
+ }
+ }
+ $survey->vote($uid, Post::v('survey'.$id)); // performs vote
+ $this->show_success($page, "Ta réponse a bien été prise en compte. Merci d'avoir participé à ce sondage.", 'survey');
+ } else { // offers to fill in the survey
+ if ($survey->isMode(Survey::MODE_ALL) || !$survey->hasVoted(S::v('uid'))) {
+ $page->assign('survey_votemode', true);
+ } else {
+ $page->assign('survey_warning', "Tu as déjà voté à ce sondage.");
+ }
+ //$page->assign('survey_id', $id);
+ $this->show_survey($page, $survey);
+ }
+ }
+ // }}}
+
+ // {{{ function handler_result() : show the results of the votes to a survey
+ function handler_result($page, $id = -1, $show = 'all')
+ {
+ $id = intval($id);
+ if ($id == -1) {
+ return $this->show_error($page, "Un identifiant de sondage doit être précisé.", 'survey');
+ }
+ $this->load('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.", 'survey');
+ } elseif (!$survey->isEnded() && !$survey->canSeeEarlyResults(S::user())) {
+ return $this->show_error($page, "Le sondage ".$survey->getTitle()." n'est pas encore terminé.", 'survey');
+ }
+ if (!$survey->canSeeEarlyResults(S::user()) && !$this->check_surveyPerms($page, $survey)) {
+ return PL_DO_AUTH;
+ }
+ if ($show == 'csv') {
+ pl_content_headers("text/csv");
+ header('Content-Disposition: attachment; filename="'.addslashes($survey->getTitle()).'.csv"');
+ echo $survey->toCSV();
+ exit;
+ } else {
+ $page->assign('survey_resultmode', true);
+ $this->show_survey($page, $survey);
+ }