Add labels.
[platal.git] / modules / survey.php
CommitLineData
8fe81c50 1<?php
2/***************************************************************************
5e1513f6 3 * Copyright (C) 2003-2011 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
22class 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),
eb5a266d 29 'survey/edit' => $this->make_hook('edit', AUTH_COOKIE),
d0b836c9
FB
30 /*
31 'survey/result' => $this->make_hook('result', AUTH_COOKIE),
eb5a266d
SJ
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'),
8fe81c50 35 'survey/admin/valid' => $this->make_hook('adminValidate', AUTH_MDP, 'admin'),
eb5a266d 36 'survey/admin/del' => $this->make_hook('adminDelete', AUTH_MDP, 'admin'),
2f4b93be 37 */ );
8fe81c50 38 }
8fe81c50 39
8fe81c50 40 function handler_index(&$page, $action = null)
41 {
460d8f55 42 $this->load('survey.inc.php');
5c6e38d7 43
2f4b93be 44 XDB::execute("DELETE FROM surveys");
8fe81c50 45
2f4b93be
FB
46 $survey = new Survey();
47 $survey->id = null;
48 $survey->shortname = "blah";
49 $survey->title = "Blah";
50 $survey->description = "Blih blih blih blih";
51 $survey->uid = S::user()->id();
52 $survey->begin = "09/09/2010";
53 $survey->end = "30/12/2011";
9f01f40b 54
2f4b93be
FB
55 $qpage = $survey->newQuestion("section");
56 $qpage->parameters = array('type' => 'page');
57 $qpage->label = 'Première page';
8fe81c50 58
2f4b93be
FB
59 $question = $qpage->newQuestion("text");
60 $question->label = "Super question";
61 $question->flags = "mandatory";
62 $question->parameters = array("type" => "text", "limit" => 256);
8fe81c50 63
2f4b93be
FB
64 $question = $qpage->newQuestion("text");
65 $question->label = "Super question 2";
eaf30d86 66
2f4b93be
FB
67 $qpage = $survey->newQuestion("section");
68 $qpage->parameters = array('type' => 'page');
69 $qpage->label = 'Deuxième page';
8fe81c50 70
2f4b93be
FB
71 $survey->flags = 'validated';
72 $survey->insert(true);
56c6950a 73
2f4b93be
FB
74 $page->changeTpl('survey/index.tpl');
75 $page->assign('active', Survey::iterActive());
56c6950a 76 }
56c6950a 77
2f4b93be 78 function handler_vote(PlPage $page, $name)
9f01f40b 79 {
460d8f55 80 $this->load('survey.inc.php');
b46de52d 81 $page->addJsLink('jquery.tmpl.js');
d0b836c9 82 $page->addJsLink('survey.js');
2f4b93be
FB
83 $page->changeTpl('survey/vote.tpl');
84 $survey = Survey::get($name);
85 if (is_null($survey)) {
86 return PL_NOT_FOUND;
12678e90 87 }
2f4b93be
FB
88 if (!$survey->canSee(S::user())) {
89 return PL_FORBIDDEN;
95fb3c74 90 }
90343d1e
FB
91 if (Post::has('vote')) {
92 $answers = Post::v('qid');
93 $vote = $survey->vote(S::user(), $answers);
94 if (is_null($vote)) {
95 $page->kill("Tu n'as pas le droit de voter à ce sondage.");
96 } else if ($vote->inError()) {
97 $page->trigError("Certaines réponses sont invalides et doivent être corrigées");
98 } else {
99 $vote->insert(true);
100 $page->trigSuccess("Ton vote a été enregistré");
101 }
102 }
2f4b93be 103 $page->assign('survey', $survey);
8fe81c50 104 }
d0b836c9
FB
105
106 function handler_edit(PlPage $page, $name = null)
107 {
108 $this->load('survey.inc.php');
109 $page->addJsLink('jquery.ui.core.js');
110 $page->addJsLink('jquery.ui.widget.js');
111 $page->addJsLink('jquery.ui.datepicker.js');
31d63ae1 112 $page->addJsLink('jquery.ui.datepicker-fr.js');
d0b836c9
FB
113 $page->addJsLink('jquery.tmpl.js');
114 $page->addJsLink('survey.js');
115 $page->changeTpl('survey/edit.tpl');
116
117 if (!is_null($name)) {
118 $survey = Survey::get($name);
119 } else {
120 $survey = new Survey();
121 $survey->id = null;
122 $survey->uid = S::user()->id();
123 }
124 if (Post::has('save')) {
125 }
126 $page->assign('survey', $survey);
127 }
8fe81c50 128}
129
8602c852 130// vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8:
8fe81c50 131?>