Commit | Line | Data |
---|---|---|
8fe81c50 | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
8fe81c50 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | class SurveyModule extends PLModule | |
23 | { | |
8fe81c50 | 24 | function handlers() |
25 | { | |
26 | return array( | |
2f4b93be FB |
27 | 'survey' => $this->make_hook('index', AUTH_COOKIE), |
28 | 'survey/vote' => $this->make_hook('vote', AUTH_COOKIE), | |
29 | /* 'survey/result' => $this->make_hook('result', AUTH_COOKIE), | |
eb5a266d SJ |
30 | 'survey/edit' => $this->make_hook('edit', AUTH_COOKIE), |
31 | 'survey/ajax' => $this->make_hook('ajax', AUTH_COOKIE), | |
32 | 'survey/admin' => $this->make_hook('admin', AUTH_MDP, 'admin'), | |
33 | 'survey/admin/edit' => $this->make_hook('adminEdit', AUTH_MDP, 'admin'), | |
8fe81c50 | 34 | 'survey/admin/valid' => $this->make_hook('adminValidate', AUTH_MDP, 'admin'), |
eb5a266d | 35 | 'survey/admin/del' => $this->make_hook('adminDelete', AUTH_MDP, 'admin'), |
2f4b93be | 36 | */ ); |
8fe81c50 | 37 | } |
8fe81c50 | 38 | |
8fe81c50 | 39 | function handler_index(&$page, $action = null) |
40 | { | |
460d8f55 | 41 | $this->load('survey.inc.php'); |
5c6e38d7 | 42 | |
2f4b93be | 43 | XDB::execute("DELETE FROM surveys"); |
8fe81c50 | 44 | |
2f4b93be FB |
45 | $survey = new Survey(); |
46 | $survey->id = null; | |
47 | $survey->shortname = "blah"; | |
48 | $survey->title = "Blah"; | |
49 | $survey->description = "Blih blih blih blih"; | |
50 | $survey->uid = S::user()->id(); | |
51 | $survey->begin = "09/09/2010"; | |
52 | $survey->end = "30/12/2011"; | |
9f01f40b | 53 | |
2f4b93be FB |
54 | $qpage = $survey->newQuestion("section"); |
55 | $qpage->parameters = array('type' => 'page'); | |
56 | $qpage->label = 'Première page'; | |
8fe81c50 | 57 | |
2f4b93be FB |
58 | $question = $qpage->newQuestion("text"); |
59 | $question->label = "Super question"; | |
60 | $question->flags = "mandatory"; | |
61 | $question->parameters = array("type" => "text", "limit" => 256); | |
8fe81c50 | 62 | |
2f4b93be FB |
63 | $question = $qpage->newQuestion("text"); |
64 | $question->label = "Super question 2"; | |
eaf30d86 | 65 | |
2f4b93be FB |
66 | $qpage = $survey->newQuestion("section"); |
67 | $qpage->parameters = array('type' => 'page'); | |
68 | $qpage->label = 'Deuxième page'; | |
8fe81c50 | 69 | |
2f4b93be FB |
70 | $survey->flags = 'validated'; |
71 | $survey->insert(true); | |
56c6950a | 72 | |
2f4b93be FB |
73 | $page->changeTpl('survey/index.tpl'); |
74 | $page->assign('active', Survey::iterActive()); | |
56c6950a | 75 | } |
56c6950a | 76 | |
2f4b93be | 77 | function handler_vote(PlPage $page, $name) |
9f01f40b | 78 | { |
460d8f55 | 79 | $this->load('survey.inc.php'); |
2f4b93be FB |
80 | $page->changeTpl('survey/vote.tpl'); |
81 | $survey = Survey::get($name); | |
82 | if (is_null($survey)) { | |
83 | return PL_NOT_FOUND; | |
12678e90 | 84 | } |
2f4b93be FB |
85 | if (!$survey->canSee(S::user())) { |
86 | return PL_FORBIDDEN; | |
95fb3c74 | 87 | } |
90343d1e FB |
88 | if (Post::has('vote')) { |
89 | $answers = Post::v('qid'); | |
90 | $vote = $survey->vote(S::user(), $answers); | |
91 | if (is_null($vote)) { | |
92 | $page->kill("Tu n'as pas le droit de voter à ce sondage."); | |
93 | } else if ($vote->inError()) { | |
94 | $page->trigError("Certaines réponses sont invalides et doivent être corrigées"); | |
95 | } else { | |
96 | $vote->insert(true); | |
97 | $page->trigSuccess("Ton vote a été enregistré"); | |
98 | } | |
99 | } | |
2f4b93be | 100 | $page->assign('survey', $survey); |
8fe81c50 | 101 | } |
8fe81c50 | 102 | } |
103 | ||
8602c852 | 104 | // vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8: |
8fe81c50 | 105 | ?> |