2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class SurveyModule
extends PLModule
27 'survey' => $this->make_hook('index', AUTH_COOKIE
),
28 'survey/vote' => $this->make_hook('vote', AUTH_COOKIE
),
29 'survey/edit' => $this->make_hook('edit', AUTH_COOKIE
),
31 'survey/result' => $this->make_hook('result', AUTH_COOKIE),
32 'survey/ajax' => $this->make_hook('ajax', AUTH_COOKIE),
33 'survey/admin' => $this->make_hook('admin', AUTH_MDP, 'admin'),
34 'survey/admin/edit' => $this->make_hook('adminEdit', AUTH_MDP, 'admin'),
35 'survey/admin/valid' => $this->make_hook('adminValidate', AUTH_MDP, 'admin'),
36 'survey/admin/del' => $this->make_hook('adminDelete', AUTH_MDP, 'admin'),
40 private function setup_page(PlPage
$page)
42 $this->load('survey.inc.php');
43 $page->addJsLink('jquery.ui.xorg.js');
44 $page->addJsLink('survey.js');
47 function handler_index(&$page, $action = null
)
49 $this->setup_page($page);
51 $page->changeTpl('survey/index.tpl');
52 $page->assign('active', Survey
::iterActive());
55 function handler_vote(PlPage
$page, $name)
57 $this->setup_page($page);
58 $page->changeTpl('survey/vote.tpl');
60 XDB
::execute('delete from survey_votes');
61 XDB
::execute('delete from survey_voters');
62 $survey = Survey
::get($name);
63 if (is_null($survey)) {
66 if (!$survey->canSee(S
::user())) {
69 if (Post
::has('vote')) {
70 $answers = Post
::v('qid');
71 $vote = $survey->vote(S
::user(), $answers);
73 $page->kill("Tu n'as pas le droit de voter à ce sondage.");
74 } else if ($vote->inError()) {
75 $page->trigError("Certaines réponses sont invalides et doivent être corrigées");
78 $page->trigSuccess("Ton vote a été enregistré");
81 $page->assign('survey', $survey);
84 function handler_edit(PlPage
$page, $name = null
)
86 $this->setup_page($page);
87 $page->changeTpl('survey/edit.tpl');
89 if (!is_null($name)) {
90 $survey = Survey
::get($name);
92 $survey = new Survey();
94 $survey->uid
= S
::user()->id();
96 if (Post
::has('valid')) {
97 $survey->title
= Post
::t('title');
98 $survey->shortname
= Post
::t('shortname');
99 $survey->description
= Post
::t('description');
100 $survey->begin
= Post
::t('begin');
101 $survey->end
= Post
::t('end');
102 $survey->flags
= 'validated';
103 $survey->flags
->addFlag('anonymous', Post
::b('anonymous'));
105 $q_edit = Post
::v('q_edit');
107 $survey->clearQuestions();
108 foreach ($q_edit as $qid => $q_desc) {
109 if (isset($q_desc['parent'])) {
110 $parent = $qs[$q_desc['parent']];
114 $question = $parent->newQuestion($q_desc['type']);
115 $question->label
= $q_desc['label'];
116 unset($q_desc['type']);
117 unset($q_desc['parent']);
118 unset($q_desc['label']);
119 $question->parameters
= $q_desc;
120 $qs[$qid] = $question;
122 $survey->insert('true');
124 $page->assign('survey', $survey);
128 // vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8: