htdocs/javascript/jquery.ui-$(JQUERY_UI_VERSION).%.js:
@$(download)
-htdocs/javascript/jquery.ui-$(JQUERY_UI_VERSION).datepicker-fr.js: DOWNLOAD_SRC = http://jquery-ui.googlecode.com/svn/tags/$(JQUERY_UI_VERSION)/ui/minified/i18n/jquery.ui.datepicker-fr.min.js
-htdocs/javascript/jquery.ui-$(JQUERY_UI_VERSION).datepicker-fr.js:
- @$(download)
-
-$(JQUERY_UI_PATHES) htdocs/javascript/jquery.ui.datepicker-fr.js: htdocs/javascript/jquery.ui.%.js: htdocs/javascript/jquery.ui-$(JQUERY_UI_VERSION).%.js
+$(JQUERY_UI_PATHES): htdocs/javascript/jquery.ui.%.js: htdocs/javascript/jquery.ui-$(JQUERY_UI_VERSION).%.js
ln -snf $(<F) $@
htdocs/javascript/jquery.tmpl-$(JQUERY_TMPL_VERSION).js: DOWNLOAD_SRC = https://github.com/jquery/jquery-tmpl/raw/$(JQUERY_TMPL_VERSION)/jquery.tmpl.js --no-check-certificate
overflow: hidden;
}
-.ui-datepicker-calendar {
- border-collapse: collapse;
- text-align: right;
-}
-
-.ui-datepicker-calendar td {
- width: 20px;
-}
-
.ui-datepicker-week-end {
background-color: #eee;
}
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2003-2011 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-(function($) {
- var dispatchType = function(method) {
- return function(type) {
- var name = type + '_' + method;
- var args = Array.prototype.slice.call(arguments, 1);
- if ($.isFunction(this[name])) {
- return this[name].apply(this, args);
- }
- return this;
- };
- };
-
- $.extend({
- questions: function() {
- return $('.q_edit:not(#questions)');
- },
-
- lastQuestion: function() {
- return $.questions().last();
- },
-
- renumberQuestions: function() {
- var q = $.questions();
- q.each(function(idx) {
- var elt = $(this);
- var old_id = elt.attr('id');
- var new_id = 'q_edit[' + idx + ']';
- var fixAttrs;
-
- if (old_id === new_id) {
- return;
- }
-
- fixAttrs = function(attr) {
- elt.find('[' + attr + '^="' + old_id + '"]').each(function() {
- var cid = $(this).attr(attr);
- if (cid.startsWith(old_id)) {
- $(this).attr(attr, new_id + cid.substring(old_id.length, cid.length));
- }
- });
- };
- fixAttrs('id');
- fixAttrs('name');
- elt.children().children('.q_edit_label').text('Question ' + (idx + 1));
- elt.attr('id', new_id);
- });
- },
-
- debugPrintQuestions: function() {
- var q = $.questions();
- var str = '';
- q.each(function() {
- str += $(this).attr('id') + '\n';
- });
- alert(str);
- }
- });
-
- $.fn.extend({
- showQuestions: function(questions) {
- var data = $('#question_base').tmpl(questions);
- this.empty();
- data.appendTo(this);
- return this;
- },
-
- /* Edition form */
- prepareQuestions: function(questions) {
- var q, child;
- for (q in questions) {
- q = questions[q];
- child = this.addQuestion(q);
- if ($.isArray(q.children)) {
- child.prepareQuestions(q.children);
- }
- }
- return this;
- },
-
- isQuestion: function() {
- return this.hasClass('q_edit');
- },
-
- isRootSection: function() {
- return this.attr('id') === 'questions';
- },
-
- question: function() {
- return this.isQuestion() ? this : this.parentQuestion();
- },
-
- questionForm: function() {
- return this.question().children('.q_edit_form');
- },
-
- qid: function() {
- var question = this.question();
- if (typeof question.get(0) === 'undefined') {
- return;
- }
- var id = question.attr('id');
- if (id.substr(0, 7) !== 'q_edit[') {
- return;
- }
- if (id.charAt(id.length - 1) !== ']') {
- return;
- }
- id = id.substr(7, id.length - 8);
- return parseInt(id, 10);
- },
-
- parentQuestion: function() {
- return this.parent().closest('.q_edit');
- },
-
- childrenContainer: function() {
- var question = this.question();
- return question.isRootSection() ? question : question.questionForm().children();
- },
-
- childrenQuestion: function() {
- return this.childrenContainer().children('.q_edit');
- },
-
- addQuestion: function(q) {
- var id = $.lastQuestion().qid();
- if (!id) {
- id = 0;
- } else {
- id++;
- }
- if (!q) {
- q = { qid: id };
- }
- console.log(q);
- var question = $("#q_edit_new").tmpl(q);
- var type = question
- .find('select[name$="[type]"]')
- .change(function () {
- var type = $(this).val();
- var form = question.children('.q_edit_form');
- var qid = $(this).qid();
- form.empty();
- if (type) {
- $("#q_edit_base").tmpl({ qid: qid, type: type })
- .bindQuestion(type, qid)
- .appendTo(form);
- }
- return true;
- });
- if (type.val()) {
- question.children('.q_edit_form')
- .bindQuestion(type.val(), q.qid, q)
- }
- this.childrenContainer().children('.add_question').before(question);
- $.renumberQuestions();
- return question;
- },
-
- bindQuestion: dispatchType('bindQuestion'),
-
- removeQuestion: function(force) {
- var question = this.parentQuestion();
- if (!force && question.children('.q_edit_form').children().children('.q_edit').length > 0) {
- if (!alert('Vous avez demander la suppression d\'une section contenant des questions. '
- + 'Ces questions seront supprimées. Etes-vous sur de vouloir continuer ?')) {
- return this;
- }
- }
- var res;
- if (question.isRootSection()) {
- res = question.empty();
- } else {
- res = question.remove();
- }
- $.renumberQuestions();
- return res;
- },
-
- buildParentsQuestions: function() {
- var $this = $(this);
- $.questions().each(function() {
- var parent = $(this).parentQuestion();
- if (!parent.isRootSection()) {
- $('<input>', {
- type: 'hidden',
- name: 'q_edit[' + $(this).qid() + '][parent]',
- value: parent.qid()
- }).appendTo($this);
- }
- });
- return $this;
- },
-
- /* Multiple choices questions */
- multiple_selectSubtype: function() {
- return this.find('select[name$="[subtype]"]');
- },
-
- multiple_bindQuestion: function(id, parameters) {
- var $question = this;
- var answer;
- var value;
- this.multiple_selectSubtype()
- .assertLength(1)
- .change(function() {
- $question.find('.q_edit_answer_box')
- .empty()
- .append($('<input>', {
- type: $(this).val(),
- disabled: "disabled"
- }));
- });
- if (parameters) {
- for (answer = 0; answer < parameters.answers.length; answer++) {
- this.multiple_addAnswer(parameters.answers[answer]);
- }
- }
- return this;
- },
-
- multiple_addAnswer: function(value) {
- var question = this.question();
- var answer = $("#q_edit_multiple_answer").tmpl({ qid: question.qid(), value: value });
- question.childrenContainer().children('.add_answer').before(answer);
- question.multiple_selectSubtype().change();
- return answer;
- },
-
- multiple_removeAnswer: function() {
- return this.parent().remove();
- }
- });
-}(jQuery));
-
-
-$(function() {
- $(".datepicker").datepicker({
- hideIfNoPrevNext: true,
- minDate: new Date()
- });
-});
-
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
class SurveyModule extends PLModule
{
+ // {{{ function handlers() : registers the different handlers
function handlers()
{
return array(
- 'survey' => $this->make_hook('index', AUTH_COOKIE),
- 'survey/vote' => $this->make_hook('vote', AUTH_COOKIE),
+ '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/result' => $this->make_hook('result', AUTH_COOKIE),
'survey/ajax' => $this->make_hook('ajax', AUTH_COOKIE),
'survey/admin' => $this->make_hook('admin', AUTH_MDP, 'admin'),
'survey/admin/edit' => $this->make_hook('adminEdit', AUTH_MDP, 'admin'),
'survey/admin/valid' => $this->make_hook('adminValidate', AUTH_MDP, 'admin'),
'survey/admin/del' => $this->make_hook('adminDelete', AUTH_MDP, 'admin'),
- */ );
+ );
}
+ // }}}
- private function setup_page(PlPage $page)
+ // {{{ function handler_index() : lists all available surveys
+ function handler_index($page, $action = null)
{
$this->load('survey.inc.php');
- $page->addJsLink('jquery.ui.xorg.js');
- $page->addJsLink('survey.js');
+ $page->changeTpl('survey/index.tpl');
+ $page->assign('survey_current', Survey::retrieveList('c'));
+ $page->assign('survey_old', Survey::retrieveList('o'));
+ $page->assign('survey_modes', Survey::getModes(false));
}
+ // }}}
- function handler_index($page, $action = null)
+ // {{{ function handler_vote() : handles the vote to a survey
+ function handler_vote($page, $id = -1)
{
- $this->setup_page($page);
+ 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);
+ }
+ }
+ // }}}
- $page->changeTpl('survey/index.tpl');
- $page->assign('active', Survey::iterActive());
+ // {{{ 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);
+ }
}
+ // }}}
- function handler_vote(PlPage $page, $name)
+ // {{{ function handler_admin() : index of admin mode
+ function handler_admin($page, $id = -1)
{
- $this->setup_page($page);
- $page->changeTpl('survey/vote.tpl');
+ $this->load('survey.inc.php');
+ $this->clear_session();
+ if ($id == -1) {
+ $page->changeTpl('survey/admin.tpl');
+ $page->assign('survey_waiting', Survey::retrieveList('w'));
+ $page->assign('survey_current', Survey::retrieveList('c'));
+ $page->assign('survey_old', Survey::retrieveList('o'));
+ $page->assign('survey_modes', Survey::getModes(false));
+ } else {
+ $id = intval($id);
+ $survey = Survey::retrieveSurvey($id); // retrieves all survey object structure
+ if ($survey == null) {
+ $this->show_error($page, "Sondage ".$id." introuvable.", 'survey/admin');
+ }
+ $page->assign('survey_adminmode', true);
+ $this->show_survey($page, $survey);
+ }
+ }
+ // }}}
- XDB::execute('delete from survey_votes');
- XDB::execute('delete from survey_voters');
- $survey = Survey::get($name);
- if (is_null($survey)) {
- return PL_NOT_FOUND;
+ // {{{ function handler_adminEdit() : edits a survey in admin mode
+ function handler_adminEdit($page, $id = -1, $req = -1)
+ {
+ if ($id == -1 || ($id == 'req' && $req == -1)) {
+ return $this->show_error($page, "Un identifiant de sondage doit être précisé.", 'survey/admin');
+ }
+ $this->load('survey.inc.php');
+ $this->clear_session(); // cleans session (in case there would have been a problem before)
+ if ($id == 'req') {
+ $survey = Survey::retrieveSurveyReq($req);
+ if ($survey == null) {
+ return $this->show_error($page, "Sondage introuvable.", 'survey/admin');
+ }
+ $this->store_session($survey, $req, true);
+ } else {
+ $id = intval($id);
+ $survey = Survey::retrieveSurvey($id); // retrieves the survey in database
+ if ($survey == null) {
+ return $this->show_error($page, "Sondage ".$id." introuvable.", 'survey/admin');
+ }
+ $this->store_session($survey, $id);
+ }
+ $this->handler_edit($page, 'show'); // calls handler_edit, but in admin mode since 'survey_id' is in session
+ }
+ // }}}
+
+ // {{{ function handler_adminValidate() : validates a survey (admin mode)
+ function handler_adminValidate($page, $id = -1)
+ {
+ $id = Post::i('survey_id', $id);
+ if (Post::has('survey_cancel')) { // if the admin cancels the validation, returns to the admin index
+ $this->clear_session();
+ return $this->handler_admin($page, $id);
}
- if (!$survey->canSee(S::user())) {
- return PL_FORBIDDEN;
+ if ($id == -1) {
+ return $this->show_error($page, "Un identifiant de sondage doit être précisé.", 'survey/admin');
}
- if (Post::has('vote')) {
- $answers = Post::v('qid');
- $vote = $survey->vote(S::user(), $answers);
- if (is_null($vote)) {
- $page->kill("Tu n'as pas le droit de voter à ce sondage.");
- } else if ($vote->inError()) {
- $page->trigError("Certaines réponses sont invalides et doivent être corrigées");
+ $id = intval($id);
+ $this->load('survey.inc.php');
+ $surveyInfo = Survey::retrieveSurveyInfo($id); // retrieves information about the survey (does not retrieve and unserialize the object structure)
+ if ($surveyInfo == null) {
+ return $this->show_error($page, "Sondage ".$id." introuvable.", 'survey/admin');
+ }
+ if (Post::has('survey_submit')) { // needs a confirmation before validation
+ if (Survey::validateSurvey($id)) { // validates the survey (in the database)
+ $this->show_success($page, "Le sondage \"".$surveyInfo['title']."\" a bien été validé, les votes sont maintenant ouverts.", 'survey/admin');
} else {
- $vote->insert(true);
- $page->trigSuccess("Ton vote a été enregistré");
+ $this->show_error($page, '', 'survey/admin');
}
+ } else { // asks for a confirmation
+ $this->show_confirm($page, "Êtes-vous certain de vouloir valider le sondage \"".$surveyInfo['title']."\" ? "
+ ."Les votes seront immédiatement ouverts.", 'admin/valid', array('id' => $id));
}
- $page->assign('survey', $survey);
}
+ // }}}
- function handler_edit(PlPage $page, $name = null)
+ // {{{ function handler_adminDelete() : deletes a survey (admin mode)
+ function handler_adminDelete($page, $id = -1)
{
- $this->setup_page($page);
- $page->changeTpl('survey/edit.tpl');
+ $id = Post::i('survey_id', $id);
+ if (Post::has('survey_cancel')) { // if the admin cancels the suppression, returns to the admin index
+ return $this->handler_admin($page, $id);
+ }
+ if ($id == -1) {
+ return $this->show_error($page, "Un identifiant de sondage doit être précisé.", 'survey/admin');
+ }
+ $id = intval($id);
+ $this->load('survey.inc.php');
+ $surveyInfo = Survey::retrieveSurveyInfo($id); // retrieves information about the survey (does not retrieve and unserialize the object structure)
+ if ($surveyInfo == null) {
+ return $this->show_error($page, "Sondage ".$id." introuvable.", 'survey/admin');
+ }
+ if (Post::has('survey_submit')) { // needs a confirmation before suppression
+ if (Survey::deleteSurvey($id)) { // deletes survey in database
+ $this->show_success($page, "Le sondage \"".$surveyInfo['title']."\" a bien été supprimé, ainsi que tous les votes le concernant.", 'survey/admin');
+ } else {
+ $this->show_error($page, '', 'survey/admin');
+ }
+ } else { // asks for a confirmation
+ $this->show_confirm($page, "Êtes-vous certain de vouloir supprimer le sondage \"".$surveyInfo['title']."\" ?", 'admin/del', array('id' => $id));
+ }
+ }
+ // }}}
- if (!is_null($name)) {
- $survey = Survey::get($name);
- } else {
- $survey = new Survey();
- $survey->id = null;
- $survey->uid = S::user()->id();
- }
- if (Post::has('valid')) {
- $survey->title = Post::t('title');
- $survey->shortname = Post::t('shortname');
- $survey->description = Post::t('description');
- $survey->begin = Post::t('begin');
- $survey->end = Post::t('end');
- $survey->flags = 'validated';
- $survey->flags->addFlag('anonymous', Post::b('anonymous'));
-
- $q_edit = Post::v('q_edit');
- $qs = array();
- $survey->clearQuestions();
- foreach ($q_edit as $qid => $q_desc) {
- if (isset($q_desc['parent'])) {
- $parent = $qs[$q_desc['parent']];
+ // {{{ function handler_edit() : edits a survey (in normal mode unless called by handler_adminEdit() )
+ function handler_edit($page, $action = 'show', $qid = 'root')
+ {
+ $this->load('survey.inc.php');
+ $action = Post::v('survey_action', $action);
+ $qid = Post::v('survey_qid', $qid);
+ if (Post::has('survey_cancel')) { // after cancelling changes, shows the survey
+ if (S::has('survey')) {
+ $action = 'show';
+ } else { // unless no editing has been done at all (shows to the surveys index page)
+ return $this->handler_index($page);
+ }
+ }
+ $page->assign('survey_editmode', true);
+ if (S::has('survey_id')) { // if 'survey_id' is in session, it means we are modifying a survey in admin mode
+ $page->assign('survey_updatemode', true);
+ }
+ if ($action == 'show' && !S::has('survey')) {
+ $action = 'new';
+ }
+ if ($action == 'question') { // {{{ modifies an existing question
+ if (Post::has('survey_submit')) { // if the form has been submitted, makes the modifications
+ $survey = unserialize(S::v('survey'));
+ $args = Post::v('survey_question');
+ if (!$survey->editQuestion($qid, $args)) { // update the survey object structure
+ return $this->show_error($page, '', 'survey/edit');
+ }
+ $this->show_survey($page, $survey);
+ $this->store_session($survey);
+ } else { // if a form has not been submitted, shows modification form
+ $survey = unserialize(S::v('survey'));
+ $current = $survey->toArray($qid); // gets the current parameters of the question
+ if ($current == null) {
+ return $this->show_error($page, '', 'survey/edit');
+ }
+ $this->show_form($page, $action, $qid, $current['type'], $current);
+ } // }}}
+ } elseif ($action == 'new') { // {{{ create a new survey : actually store the root question
+ if (Post::has('survey_submit')) { // if the form has been submitted, creates the survey
+ $this->clear_session();
+ $survey = new Survey(Post::v('survey_question')); // creates the object structure
+ $this->show_survey($page, $survey);
+ $this->store_session($survey);
+ } else {
+ $this->clear_session();
+ $this->show_form($page, $action, 'root', 'newsurvey');
+ } // }}}
+ } elseif ($action == 'add') { // {{{ adds a new question
+ if (Post::has('survey_submit')) { // if the form has been submitted, adds the question
+ $survey = unserialize(S::v('survey'));
+ if (!$survey->addQuestion($qid, $survey->factory(Post::v('survey_type'), Post::v('survey_question')))) {
+ return $this->show_error($page, '', 'survey/edit');
+ }
+ $this->show_survey($page, $survey);
+ $this->store_session($survey);
+ } else {
+ $this->show_form($page, $action, $qid);
+ } // }}}
+ } elseif ($action == 'del') { // {{{ deletes a question
+ if (Post::has('survey_submit')) { // if a confirmation has been sent, deletes the question
+ $survey = unserialize(S::v('survey'));
+ if (!$survey->delQuestion(Post::v('survey_qid'))) { // deletes the node in the survey object structure
+ return $this->show_error($page, '', 'survey/edit');
+ }
+ $this->show_survey($page, $survey);
+ $this->store_session($survey);
+ } else { // if user has not confirmed, shows a confirmation form
+ $survey = unserialize(S::v('survey'));
+ $current = $survey->toArray($qid); // needed to get the title of the question to delete (more user-friendly than an id)
+ if ($current == null) {
+ return $this->show_error($page, '', 'survey/edit');
+ }
+ $this->show_confirm($page, 'Êtes-vous certain de vouloir supprimer la question intitulé "'.$current['question'].'" ? '
+ .'Attention, cela supprimera en même temps toutes les questions qui dépendent de celle-ci.',
+ 'edit', array('action' => 'del', 'qid' => $qid));
+ } // }}}
+ } elseif ($action == 'show') { // {{{ simply shows the survey in its current state
+ $this->show_survey($page, unserialize(S::v('survey'))); // }}}
+ } elseif ($action == 'valid') { // {{{ validates the proposition, i.e stores the proposition in the database
+ // but an admin will still need to validate the survey before it is activated
+ if (Post::has('survey_submit')) { // needs a confirmation before storing the proposition
+ $survey = unserialize(S::v('survey'));
+ if (S::has('survey_id')) { // if 'survey_id' is in session, we are modifying an existing survey (in admin mode) instead of proposing a new one
+ $link = (S::has('survey_validate'))? 'admin/validate' : 'survey/admin';
+ if ($survey->updateSurvey()) { // updates the database according the new survey object structure
+ $this->show_success($page, "Les modifications sur le sondage ont bien été enregistrées.", $link);
+ } else {
+ $this->show_error($page, '', $link);
+ }
+ } else { // if no 'survey_id' is in session, we are indeed proposing a new survey
+ if ($survey->proposeSurvey()) { // stores the survey object structure in database
+ $this->show_success($page, "Votre proposition de sondage a bien été enregistrée,
+ elle est en attente de validation par un administrateur du site.", 'survey');
+ } else {
+ $this->show_error($page, '', 'survey');
+ }
+ }
+ $this->clear_session();
+ } else { // asks for a confirmation if it has not been sent
+ $survey = unserialize(S::v('survey'));
+ $errors = $survey->checkSyntax();
+ if (!is_null($errors)) {
+ $this->show_error($page, "", 'survey/edit', $errors);
+ } else {
+ if (S::has('survey_id')) {
+ $this->show_confirm($page, "Veuillez confirmer l'enregistrement des modifications apportées à ce sondage.", 'edit', array('action' => 'valid'));
+ } else {
+ $this->show_confirm($page, "Veuillez confirmer l'envoi de cette proposition de sondage.", 'edit', array('action' => 'valid'));
+ }
+ }
+ } // }}}
+ } elseif ($action == 'cancel') { // {{{ cancels the creation/modification of a survey
+ if (Post::has('survey_submit')) { // needs a confirmation
+ if (S::has('survey_id')) { // only possible when modifying a survey in admin mode
+ if (S::has('survey_validate')) { // if a link has been supplied, uses it
+ $this->clear_session();
+ return $this->show_success($page, "Les modifications effectuées ont été annulées", 'admin/validate');
+ } else { // else shows the admin index
+ $this->clear_session();
+ return $this->handler_admin($page);
+ }
} else {
- $parent = $survey;
+ $this->clear_session();
+ return $this->handler_index($page); // else shows the 'normal' index
}
- $question = $parent->newQuestion($q_desc['type']);
- $question->label = $q_desc['label'];
- unset($q_desc['type']);
- unset($q_desc['parent']);
- unset($q_desc['label']);
- $question->parameters = $q_desc;
- $qs[$qid] = $question;
+ } else { // asks for a confirmation if it has not been sent
+ $this->show_confirm($page, "Êtes-vous certain de vouloir annuler totalement l'édition de ce sondage ? Attention, "
+ ."toutes les données éditées jusque là seront définitivement perdues.",
+ 'edit', array('action' => $action));
+ }
+ } // }}}
+ }
+ // }}}
+
+ // {{{ function handler_ajax() : some ajax in editing a new question (for now, there may be a little more later)
+ function handler_ajax($page, $type)
+ {
+ $this->load('survey.inc.php');
+ pl_content_headers("text/html");
+ if (Survey::isType($type)) { // when type has been chosen, the form is updated to fit exactly the type of question chosen
+ $page->changeTpl('survey/edit_new.tpl', NO_SKIN);
+ $page->assign('survey_types', Survey::getTypes());
+ $page->assign('survey_type', $type);
+ }
+ }
+ // }}}
+
+ // {{{ function clear_session() : clears the data stored in session
+ function clear_session()
+ {
+ S::kill('survey');
+ S::kill('survey_id');
+ S::kill('survey_validate');
+ }
+ // }}}
+
+ // {{{ function store_session() : serializes and stores survey (and survey_id) in session
+ function store_session($survey, $survey_id = -1, $survey_validate = false)
+ {
+ $_SESSION['survey'] = serialize($survey);
+ if ($survey_id != -1) {
+ $_SESSION['survey_id'] = $survey_id;
+ }
+ if ($survey_validate) {
+ $_SESSION['survey_validate'] = true;
+ }
+ }
+ // }}}
+
+ // {{{ function check_surveyPerms() : checks the particular surveys access permissions
+ function check_surveyPerms($page, $survey, $silent = false, $admin_allowed = true)
+ {
+ $this->load('survey.inc.php');
+ if ($survey->isMode(Survey::MODE_ALL)) { // if the survey is not reserved to alumni
+ return true;
+ }
+ if (!S::logged()) {
+ return false;
+ }
+ $profile = S::user()->profile();
+ if (!$profile) {
+ return false;
+ }
+ // checks promotion
+ $allowed = false;
+ foreach ($profile->yearspromo() as $p) {
+ if ($survey->checkPromo($p)) {
+ $allowed = true;
+ break;
+ }
+ }
+ if ($allowed) {
+ return true;
+ }
+ if (S::admin() && $admin_allowed) {
+ if (!$silent) {
+ $page->trigWarning('Tu as accès à ce sondage car tu es administrateur du site.');
}
- $survey->insert('true');
+ return true;
}
- $page->assign('survey', $survey);
+ if (!$silent) {
+ $page->kill("Tu n'as pas accès à ce sondage car il est réservé à d'autres promotions.");
+ }
+ return false;
+ }
+ // }}}
+
+ // {{{ function show_survey() : calls the template to display a survey, for editing, voting, or consulting the results
+ function show_survey($page, $survey)
+ {
+ $page->changeTpl('survey/show_root.tpl');
+ $page->assign('survey', $survey->toArray());
+ $page->assign('survey_modes', Survey::getModes());
+ }
+ // }}}
+
+ // {{{ function show_form() : calls the template to display the editing form
+ function show_form($page, $action, $qid, $type = 'new', $current = null)
+ {
+ $page->changeTpl('survey/edit_survey.tpl');
+ $page->assign('survey_action', $action);
+ $page->assign('survey_qid', $qid);
+ $page->assign('survey_formaction', './survey/edit');
+ $page->assign('survey_type', $type);
+ if (!is_null($current) && is_array($current)) {
+ $page->assign('survey_current', $current);
+ } elseif ($type == 'new') {
+ $page->addJsLink('ajax.js');
+ $page->assign('survey_types', Survey::getTypes());
+ }
+ if ($type == 'root' || $type == 'newsurvey') {
+ $page->assign('survey_modes', Survey::getModes());
+ }
+ }
+ // }}}
+
+ // {{{ function show_confirm() : calls the template to display a confirm form
+ function show_confirm($page, $message, $formaction, $formhidden = null)
+ {
+ $page->changeTpl('survey/confirm.tpl');
+ $page->assign('survey_message', $message);
+ $page->assign('survey_formaction', './survey/'.$formaction);
+ $page->assign('survey_formhidden', $formhidden);
+ }
+ // }}}
+
+ // {{{ function show_error() : calls the template to display an error message
+ function show_error($page, $message, $link = "", $errArray = null)
+ {
+ $page->changeTpl('survey/error.tpl');
+ $page->assign('survey_message', $message);
+ $page->assign('survey_link', $link); // 'return' link to let the user leave the page
+ if (!is_null($errArray)) {
+ $page->assign('survey_errors', $errArray);
+ }
+
+ }
+ // }}}
+
+ // {{{ function show_success() : calls the template to display a success message
+ function show_success($page, $message = "", $link = "")
+ {
+ $page->changeTpl('survey/success.tpl');
+ $page->assign('survey_message', $message);
+ $page->assign('survey_link', $link); // 'return' link to let the user leave the page
}
+ // }}}
}
// vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8:
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2011 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-class SurveyVote extends PlDBTableEntry
-{
- protected $survey;
- protected $user;
-
- private $answers = array();
- private $fetchAnswers;
-
- public function __construct(Survey $survey, User $user)
- {
- parent::__construct('survey_votes');
- $this->survey = $survey;
- $this->user = $user;
- $this->sid = $survey->id;
- }
-
- protected function postSave()
- {
- Platal::assert(!is_null($this->vid), "Cannot process a vote without its identifier");
- XDB::execute("REPLACE INTO survey_voters (sid, uid, vid)
- VALUES ({?}, {?}, {?})",
- $this->survey->id, $this->user->id(),
- $this->survey->flags->hasFlag('anonymous') ? null : $this->vid);
-
- /* Save answers */
- $selector = new SurveyAnswer($this);
- $selector->delete();
-
- $answers = array();
- foreach ($this->answers as $key=>$answer) {
- if (!is_null($answer)) {
- $answer->vid = $this->vid;
- $answers[] = $answer;
- }
- }
- PlDBTableEntry::insertBatch($answers);
- return true;
- }
-
- protected function postFetch()
- {
- $selector = new SurveyAnswer($this);
- foreach ($selector as $answer) {
- $question = $this->survey->questionForId($answer->qid);
- $this->answers[$answer->qid] = $answer;
- }
- return true;
- }
-
- public function inError()
- {
- foreach ($this->answers as $answer) {
- if ($answer->inError !== false) {
- return true;
- }
- }
- return false;
- }
-
- public function getAnswer(SurveyQuestion $question)
- {
- if (!isset($this->answers[$question->qid])) {
- $val = new SurveyAnswer($this);
- $val->qid = $question->qid;
- $this->answers[$question->qid] = $val;
- }
- return $this->answers[$question->qid];
- }
-
- public function export()
- {
- $export = array();
- foreach ($this->answers as $qid=>$answer) {
- $export[$qid] = $answer->export();
- }
- return $export;
- }
-
- public static function getVote(Survey $survey, User $user, $fetchAnswers = true)
- {
- $vid = XDB::query('SELECT vid
- FROM survey_voters
- WHERE sid = {?} AND uid = {?}',
- $survey->id, $user->id());
- if ($vid->numRows() == 0) {
- $vote = new SurveyVote($survey, $user);
- $vote->fetchAnswers = $fetchAnswers;
- return $vote;
- }
- $vid = $vid->fetchOneCell();
- if (is_null($vid)) {
- /* User already vote, but survey is anonymous and the vote
- * cannot be changed
- */
- return null;
- }
- $vote = new SurveyVote($survey, $user);
- $vote->vid = $vid;
- $vote->fetchAnswers = $fetchAnswers;
- $vote->fetch();
- return $vote;
- }
-}
-
-class SurveyAnswer extends PlDBTableEntry
-{
- public $inError = false;
- public $vote;
-
- public function __construct(SurveyVote $vote)
- {
- parent::__construct('survey_vote_answers');
- $this->registerFieldFormatter('answer', 'JSonFieldFormatter');
- $this->vote = $vote;
- if (!is_null($vote->vid)) {
- $this->vid = $vote->vid;
- }
- }
-
- protected function preSave()
- {
- Platal::assert(!$this->inError, "Cannot save an invalid answer");
- $this->sid = $this->vote->sid;
- $this->vid = $this->vote->vid;
- return true;
- }
-
- public function export()
- {
- $export = array();
- if (!is_null($this->answer)) {
- $export['value'] = $this->answer->export();
- }
- if ($this->inError !== false) {
- $export['error'] = $this->inError;
- }
- return $export;
- }
-}
-
-// vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8:
-?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2011 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-class SurveyQuestionMultiple extends SurveyQuestion
-{
- public function __construct(Survey $survey)
- {
- parent::__construct($survey);
- $this->type = "multiple";
- }
-
- protected function buildAnswer(SurveyAnswer $answer, PlDict $data)
- {
- $content = $data->v($this->qid);
- $value = $content['answers'];
- if (empty($value)) {
- $answer->answer = null;
- return true;
- }
- if ($this->parameters['subtype'] == 'radio') {
- if (count($value) > 1) {
- throw new Exception("You cannot select more than one answer");
- }
- }
- $answers = array();
- $answers['answers'] = array();
- foreach ($value as $key=>$text) {
- if (can_convert_to_integer($key)) {
- $key = to_integer($key);
- if ($text != $this->parameters['answers'][$key]) {
- throw new Exception("Answer text does not match");
- }
- $answers['answers'][] = $key;
- } else if ($key != 'other') {
- throw new Exception("Unsupported answer id $key");
- } else if (!$this->parameters['allow_other']) {
- throw new Exception("Got 'Other' answer while not supported");
- } else if (!isset($content['other'])) {
- $answers['other'] = '';
- } else {
- $answers['other'] = $content['other'];
- }
- }
- if (empty($value)) {
- $answer->answer = null;
- return false;
- } else {
- $answer->answer = $answers;
- }
- return true;
- }
-}
-
-?>
public static function instanceForType(Survey $survey, $type)
{
- $file = dirname(__FILE__) . '/' . $type . '.inc.php';
- if (!file_exists($file)) {
- throw new Exception("Unknown question type \"$type\"");
- }
- require_once $file;
+ require_once dirname(__FILE__) . '/' . $type . '.inc.php';
$class = 'SurveyQuestion' . $type;
return new $class($survey);
}
}
return $answer;
}
-
- public function export()
- {
- $export = parent::export();
- if (isset($export['parameters'])) {
- foreach ($export['parameters'] as $key=>$value) {
- $export[$key] = $value;
- }
- unset($export['parameters']);
- }
- return $export;
- }
-
}
class SurveyQuestionGroup extends SurveyQuestion implements SurveyQuestionContainer
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2011 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-class SurveyQuestionSection extends SurveyQuestionGroup
-{
- public function __construct(Survey $survey)
- {
- parent::__construct($survey);
- $this->type = "section";
- $this->flags = 'noanswer';
- }
-}
-
-// vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8:
-?>
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-require_once dirname(__FILE__) . '/question.inc.php';
-require_once dirname(__FILE__) . '/answer.inc.php';
-
-class Survey extends PlDBTableEntry implements SurveyQuestionContainer
+// {{{ class Survey : root of any survey, contains all questions
+class Survey
{
- private $fetchQuestions = true;
- public $questions = array();
- public $viewerFilter = null;
- public $voterFilter = null;
+ // {{{ static properties and functions, regarding survey modes and question types
+ const MODE_ALL = 0;
+ const MODE_XANON = 1;
+ const MODE_XIDENT = 2;
+ private static $longModes = array(self::MODE_ALL => "sondage ouvert à tout le monde, anonyme",
+ self::MODE_XANON => "sondage restreint aux polytechniciens, anonyme",
+ self::MODE_XIDENT => "sondage restreint aux polytechniciens, non anonyme");
+ private static $shortModes = array(self::MODE_ALL => "tout le monde, anonyme",
+ self::MODE_XANON => "polytechniciens, anonyme",
+ self::MODE_XIDENT => "polytechniciens, non anonyme");
+
+ public static function getModes($long = true) {
+ return ($long)? self::$longModes : self::$shortModes;
+ }
+
+ private static $types = array('text' => 'Texte court',
+ 'textarea' => 'Texte long',
+ 'num' => 'Numérique',
+ 'radio' => 'Choix multiples (une réponse)',
+ 'checkbox' => 'Choix multiples (plusieurs réponses)',
+ 'radiotable' => 'Questions multiples à choix multiples (une réponse)',
+ 'checkboxtable' => 'Questions multiples à choix mutliples (plusieurs réponses)');
- public function __construct()
+ public static function getTypes()
{
- parent::__construct('surveys');
- $this->registerFieldValidator('shortname', 'ShortNameFieldValidator');
- $this->registerFieldFormatter('voters', 'JSonFieldFormatter');
- $this->registerFieldFormatter('viewers', 'JSonFieldFormatter');
+ return self::$types;
}
- protected function postFetch()
+ public static function isType($t)
{
- if (!is_null($this->voters)) {
- $this->voterFilter = UserFilter::fromExportedConditions($this->voters);
- } else {
- $this->voterFilter = null;
- }
- if (!is_null($this->viewers)) {
- $this->viewerFilter = UserFilter::fromExportedConditions($this->viewers);
- } else {
- $this->viewerFilter = null;
+ return array_key_exists($t, self::$types);
+ }
+ // }}}
+
+ // {{{ properties, constructor and basic methods
+ private $id;
+ private $title;
+ private $description;
+ private $end;
+ private $mode;
+ private $promos;
+ private $valid;
+ private $questions;
+ private $creator;
+
+ public function __construct($args, $id = -1, $valid = false, $questions = null)
+ {
+ $this->update($args);
+ $this->id = $id;
+ $this->valid = $valid;
+ $this->questions = ($questions == null)? array() : $questions;
+ }
+
+ public function update($args)
+ {
+ $this->title = $args['title'];
+ $this->description = $args['description'];
+ $this->end = $args['end'];
+ $this->mode = (isset($args['mode']))? $args['mode'] : self::MODE_ALL;
+ $this->creator = $args['uid'];
+ if ($this->mode == self::MODE_ALL) {
+ $args['promos'] = '';
}
- if (!$this->fetchQuestions) {
+ $args['promos'] = str_replace(' ', '', $args['promos']);
+ $this->promos = ($args['promos'] == '' || preg_match('#^(\d{4}-?|(\d{4})?-\d{4})(,(\d{4}-?|(\d{4})?-\d{4}))*$#', $args['promos']))? $args['promos'] : '#';
+ }
+
+ public function canSeeEarlyResults(User $user)
+ {
+ return $user->id() == $this->creator || $user->checkPerms('admin');
+ }
+ // }}}
+
+ // {{{ functions to access general information
+ public function isMode($mode)
+ {
+ return ($this->mode == $mode);
+ }
+
+ public function checkPromo($promo)
+ {
+ if ($this->promos == '') {
return true;
}
- $selector = new SurveyQuestion($this);
- $selector->sid = $this->id;
-
- $stack = array();
- foreach ($selector as $question) {
- $question = $question->typedInstance();
- if (is_null($question->parent)) {
- $this->addQuestion($question);
+ $promos = explode(',', $this->promos);
+ foreach ($promos as $p) {
+ if ((preg_match('#^\d{4}$#', $p) && $p == $promo) ||
+ (preg_match('#^\d{4}-$#', $p) && intval(substr($p, 0, 4)) <= $promo) ||
+ (preg_match('#^-\d{4}$#', $p) && intval(substr($p, 1)) >= $promo) ||
+ (preg_match('#^\d{4}-\d{4}$#', $p) &&
+ (intval(substr($p, 0, 4)) <= $promo && intval(substr($p, 5)) >= $promo ||
+ intval(substr($p, 0, 4)) >= $promo && intval(substr($p, 5)) <= $promo ))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public function isValid()
+ {
+ return $this->valid;
+ }
+
+ public function isEnded()
+ {
+ return (strtotime($this->end) - time() <= 0);
+ }
+
+ public function getTitle()
+ {
+ return $this->title;
+ }
+ // }}}
+
+ // {{{ function toArray() : converts a question (or the whole survey) to array, with results if the survey is ended
+ public function toArray($i = 'all')
+ {
+ if ($i != 'all' && $i != 'root') { // if a specific question is requested, then just returns this question converted to array
+ $i = intval($i);
+ if (array_key_exists($i, $this->questions)) {
+ return $this->questions[$i]->toArray();
} else {
- $pos = count($stack) - 1;
- while ($stack[$pos]->qid != $question->parent) {
- --$pos;
- array_pop($stack);
+ return null;
+ }
+ } else { // else returns the root converted to array in any case
+ $a = array('title' => $this->title,
+ 'description' => $this->description,
+ 'end' => $this->end,
+ 'mode' => $this->mode,
+ 'promos' => $this->promos,
+ 'valid' => $this->valid,
+ 'type' => 'root');
+ if ($this->id != -1) {
+ $a['id'] = $this->id;
+ }
+ if ($this->isEnded()) { // if the survey is ended, then adds here the number of votes
+ $sql = 'SELECT COUNT(id)
+ FROM survey_votes
+ WHERE survey_id={?};';
+ $tot = XDB::query($sql, $this->id);
+ $a['votes'] = $tot->fetchOneCell();
+ }
+ if ($i == 'all' && count($this->questions) > 0) { // if the whole survey is requested, then returns all the questions converted to array
+ $qArr = array();
+ for ($k = 0; $k < count($this->questions); $k++) {
+ $q = $this->questions[$k]->toArray();
+ $q['id'] = $k;
+ if ($this->isEnded()) { // if the survey is ended, then adds here the results of this question
+ $q['result'] = $this->questions[$k]->getResultArray($this->id, $k);
+ }
+ $qArr[$k] = $q;
}
- Platal::assert(count($stack) > 0, "Invalid question structure");
- Platal::assert($stack[$pos] instanceof SurveyQuestionContainer, "Invalid question type");
- $stack[$pos]->addQuestion($question);
+ $a['questions'] = $qArr;
}
- array_push($stack, $question);
+ return $a;
}
- return true;
}
+ // }}}
+
+ // {{{ function toCSV() : builds a CSV file containing all the results of the survey
+ public function toCSV($sep = ',', $enc = '"', $asep='|')
+ {
+ $nbq = count($this->questions);
+ //require_once dirname(__FILE__) . '/../../classes/varstream.php';
+ VarStream::init();
+ global $csv_output;
+ $csv_output = '';
+ $csv = fopen('var://csv_output', 'w');
+ $line = ($this->isMode(self::MODE_XIDENT))? array('id', 'Nom', 'Prenom', 'Promo') : array('id');
+ $qids = array();
+ for ($qid = 0; $qid < $nbq; $qid++) {
+ $qids[$qid] = count($line); // stores the first id of a question (in case of questions with subquestions)
+ array_splice($line, count($line), 0, $this->questions[$qid]->getCSVColumns()); // the first line contains the questions
+ }
+ $nbf = count($line);
+ $users = array();
+ if ($this->isMode(self::MODE_XIDENT)) { // if the mode is non anonymous
+ $users = User::getBulkUsersWithUIDs(XDB::fetchAllAssoc('vid', 'SELECT v.id AS vid, v.uid
+ FROM survey_votes AS v
+ WHERE v.survey_id = {?}
+ ORDER BY vid ASC',
+ $this->id));
+ }
+ $sql = 'SELECT v.id AS vid, a.question_id AS qid, a.answer AS answer
+ FROM survey_votes AS v
+ INNER JOIN survey_answers AS a ON a.vote_id=v.id
+ WHERE v.survey_id={?}
+ ORDER BY vid ASC, qid ASC, answer ASC';
+ $res = XDB::iterator($sql, $this->id); // retrieves all answers from database
+ $vid = -1;
+ $vid_ = 0;
+ while (($cur = $res->next()) != null) {
+ if ($vid != $cur['vid']) { // if the vote id changes, then starts a new line
+ fputcsv($csv, $line, $sep, $enc); // stores the former line into $csv_output
+ $vid = $cur['vid'];
+ $line = array_fill(0, $nbf, ''); // creates an array full of empty string
+ $line[0] = $vid_; // the first field is a 'clean' vote id (not the one stored in database)
+ if ($this->isMode(self::MODE_XIDENT)) { // if the mode is non anonymous
+ if (array_key_exists($vid, $users)) { // and if the user data can be found
+ $line[1] = $users[$vid]->lastName(); // adds the user data (in the first fields of the line)
+ $line[2] = $users[$vid]->firstName();;
+ $line[3] = $users[$vid]->promo();
+ }
+ }
+ $vid_++;
+ }
+ $ans = $this->questions[$cur['qid']]->formatAnswer($cur['answer']); // formats the current answer
+ if (!is_null($ans)) {
+ if (is_array($ans)) {
+ $fid = $qids[$cur['qid']] + $ans['id']; // computes the field id
+ $a = $ans['answer'];
+ } else {
+ $fid = $qids[$cur['qid']];
+ $a = $ans;
+ }
+ if ($line[$fid] != '') { // if this field already contains something
+ $line[$fid] .= $asep; // then adds a separator before adding the new answer
+ }
+ $line[$fid] .= $a; // adds the current answer to the correct field
+ }
+ }
+ fputcsv($csv, $line, $sep, $enc); // stores the last line into $csv_output
+ return $csv_output;
+ }
+ // }}}
- protected function preSave()
+ // {{{ function factory($type, $args) : builds a question according to the given type
+ public function factory($t, $args)
{
- if (!is_null($this->voterFilter)) {
- $this->voters = $this->voterFilter->exportConditions();
+ switch ($t) {
+ case 'text':
+ return new SurveyText($args);
+ case 'textarea':
+ return new SurveyTextarea($args);
+ case 'num':
+ return new SurveyNum($args);
+ case 'radio':
+ return new SurveyRadio($args);
+ case 'checkbox':
+ return new SurveyCheckbox($args);
+ case 'radiotable':
+ return new SurveyRadioTable($args);
+ case 'checkboxtable':
+ return new SurveyCheckboxTable($args);
+ default:
+ return null;
+ }
+ }
+ // }}}
+
+ // {{{ questions manipulation functions
+ public function addQuestion($i, $c)
+ {
+ $i = intval($i);
+ if ($this->valid || $i > count($this->questions)) {
+ return false;
} else {
- $this->voters = null;
+ array_splice($this->questions, $i, 0, array($c));
+ return true;
}
- if (!is_null($this->viewerFilter)) {
- $this->viewers = $this->viewerFilter->exportConditions();
+ }
+
+ public function delQuestion($i)
+ {
+ $i = intval($i);
+ if ($this->valid || !array_key_exists($i, $this->questions)) {
+ return false;
+ } else {
+ array_splice($this->questions, $i, 1);
+ return true;
+ }
+ }
+
+ public function editQuestion($i, $a)
+ {
+ if ($i == 'root') {
+ $this->update($a);
} else {
- $this->viewers = null;
+ $i = intval($i);
+ if ($this->valid ||!array_key_exists($i, $this->questions)) {
+ return false;
+ } else {
+ $this->questions[$i]->update($a);
+ }
}
return true;
}
+ // }}}
- protected function postSave()
+ // {{{ function checkSyntax() : checks syntax of the questions (currently the root only) before storing the survey in database
+ private static $errorMessages = array(
+ "datepassed" => "la date de fin de sondage est déjà dépassée : vous devez préciser une date future",
+ "promoformat" => "les restrictions à certaines promotions sont mal formattées"
+ );
+
+ public function checkSyntax()
{
- $questions = array();
- $selector = new SurveyQuestion($this);
- $selector->sid = $this->id;
- $selector->delete();
+ $rArr = array();
+ // checks that the end date given is not already passed
+ // (unless the survey has already been validated : an admin can have a validated survey expired)
+ if (!$this->valid && $this->isEnded()) {
+ $rArr[] = array('question' => 'root', 'error' => self::$errorMessages["datepassed"]);
+ }
+ if ($this->promos != '' && !preg_match('#^(\d{4}-?|(\d{4})?-\d{4})(,(\d{4}-?|(\d{4})?-\d{4}))*$#', $this->promos)) {
+ $rArr[] = array('question' => 'root', 'error' => self::$errorMessages["promoformat"]);
+ }
+ return (empty($rArr))? null : $rArr;
+ }
+ // }}}
+
+ // {{{ functions that manipulate surveys in database
+ // {{{ static function retrieveList() : gets the list of available survey (current, old and not validated surveys)
+ public static function retrieveList($type, $tpl = true)
+ {
+ switch ($type) {
+ case 'c':
+ case 'current':
+ $where = 'end > NOW()';
+ break;
+ case 'o':
+ case 'old':
+ $where = 'end <= NOW()';
+ break;
+ default:
+ return null;
+ }
+ $sql = 'SELECT id, title, end, mode
+ FROM surveys
+ WHERE '.$where.'
+ ORDER BY end DESC;';
+ if ($tpl) {
+ return XDB::iterator($sql);
+ } else {
+ return XDB::iterRow($sql);
+ }
+ }
+ // }}}
- $this->reassignQuestionIds();
- foreach ($this->questions as $question) {
- $question->sid = $this->id;
- $question->insert();
+ // {{{ static function retrieveSurvey() : gets a survey in database (and unserialize the survey object structure)
+ public static function retrieveSurvey($sid)
+ {
+ $sql = 'SELECT questions, title, description, end, mode, promos, uid
+ FROM surveys
+ WHERE id={?}';
+ $res = XDB::query($sql, $sid);
+ $data = $res->fetchOneAssoc();
+ if (is_null($data) || !is_array($data)) {
+ return null;
}
+ $survey = new Survey($data, $sid, true, unserialize($data['questions']));
+ return $survey;
}
+ // }}}
- public function clearQuestions()
+ // {{{ static function retrieveSurveyInfo() : gets information about a survey (title, description, end date, restrictions) but does not unserialize the survey object structure
+ public static function retrieveSurveyInfo($sid)
{
- $this->fetchQuestions = true;
- $this->questions = array();
+ $sql = 'SELECT title, description, end, mode, promos
+ FROM surveys
+ WHERE id={?}';
+ $res = XDB::query($sql, $sid);
+ return $res->fetchOneAssoc();
}
+ // }}}
- public function addQuestion(SurveyQuestion $question, $pos = null)
+ // {{{ static function retrieveSurveyReq() : gets a survey request to validate
+ public static function retrieveSurveyReq($id)
{
- $question->parent = null;
- if (is_null($pos)) {
- $this->questions[] = $question;
- } else {
- array_splice($this->questions, $pos, 0, $question);
+ $surveyreq = Validate::get_request_by_id($id);
+ if ($surveyreq == null) {
+ return null;
}
+ $data = array('title' => $surveyreq->title,
+ 'description' => $surveyreq->description,
+ 'end' => $surveyreq->end,
+ 'mode' => $surveyreq->mode,
+ 'promos' => $surveyreq->promos);
+ $survey = new Survey($data, $id, false, $surveyreq->questions);
+ return $survey;
}
+ // }}}
- public function newQuestion($type, $pos = null)
+ // {{{ function proposeSurvey() : stores a proposition of survey in database (before validation)
+ public function proposeSurvey()
{
- $question = SurveyQuestion::instanceForType($this, $type);
- $this->addQuestion($question, $pos);
- return $question;
+ $surveyreq = new SurveyReq($this->title, $this->description, $this->end, $this->mode, $this->promos, $this->questions, S::user());
+ return $surveyreq->submit();
}
+ // }}}
- public function questionForId($qid)
+ // {{{ function updateSurvey() : updates a survey in database (before validation)
+ public function updateSurvey()
{
- $prev = null;
- foreach ($this->questions as $question) {
- if ($qid == $question->qid) {
- return $question;
- } else if ($qid < $question->qid) {
- Platal::assert($prev instanceof SurveyQuestionGroup,
- "Id gap must be caused by question groups");
- return $prev->child($qid);
+ if ($this->valid) {
+ $sql = 'UPDATE surveys
+ SET questions={?},
+ title={?},
+ description={?},
+ end={?},
+ mode={?},
+ promos={?}
+ WHERE id={?};';
+ return XDB::execute($sql, serialize($this->questions), $this->title, $this->description, $this->end, $this->mode, $this->promos, $this->id);
+ } else {
+ $surveyreq = Validate::get_request_by_id($this->id);
+ if ($surveyreq == null) {
+ return false;
}
- $prev = $question;
+ return $surveyreq->updateReq($this->title, $this->description, $this->end, $this->mode, $this->promos, $this->questions);
}
- Platal::assert($prev instanceof SurveyQuestionGroup,
- "Id gap must be caused by question groups");
- return $prev->child($qid);
}
+ // }}}
- public function reassignQuestionIds()
+ // {{{ functions vote() and hasVoted() : handles vote to a survey
+ public function vote($uid, $args)
{
- $id = 0;
- foreach ($this->questions as $question) {
- $question->qid = $id;
- if ($question instanceof SurveyQuestionContainer) {
- $id = $question->reassignQuestionIds();
- } else {
- $id++;
+ XDB::execute('INSERT INTO survey_votes
+ SET survey_id = {?}, uid = {?}',
+ $this->id, ($uid == 0) ? null : $uid); // notes the user as having voted
+ $vid = XDB::insertId();
+ for ($i = 0; $i < count($this->questions); $i++) {
+ $ans = $this->questions[$i]->checkAnswer($args[$i]);
+ if (!is_null($ans) && is_array($ans)) {
+ foreach ($ans as $a) {
+ XDB::execute('INSERT INTO survey_answers
+ SET vote_id = {?},
+ question_id = {?},
+ answer = {?}', $vid, $i, $a);
+ }
}
}
- return $id;
}
- public function export()
+ public function hasVoted($uid)
{
- $export = parent::export();
- $export['questions'] = $this->exportQuestions();
- return $export;
+ $res = XDB::query('SELECT id
+ FROM survey_votes
+ WHERE survey_id = {?} AND uid = {?};', $this->id, $uid); // checks whether the user has already voted
+ return ($res->numRows() != 0);
}
+ // }}}
- public function exportQuestions()
+ // {{{ static function deleteSurvey() : deletes a survey (and all its votes)
+ public static function deleteSurvey($sid)
{
- $export = array();
- foreach ($this->questions as $question) {
- $export[] = $question->export();
- }
- return $export;
+ $sql = 'DELETE s.*, v.*, a.*
+ FROM surveys AS s
+ LEFT JOIN survey_votes AS v
+ ON v.survey_id=s.id
+ LEFT JOIN survey_answers AS a
+ ON a.vote_id=v.id
+ WHERE s.id={?};';
+ return XDB::execute($sql, $sid);
}
+ // }}}
- public function exportQuestionsToJSON()
+ // {{{ static function purgeVotes() : clears all votes concerning a survey (I'm not sure whether it's really useful)
+ public static function purgeVotes($sid)
{
- return json_encode($this->exportQuestions());
+ $sql = 'DELETE v.*, a.*
+ FROM survey_votes AS v
+ LEFT JOIN survey_answers AS a
+ ON a.vote_id=v.id
+ WHERE v.survey_id={?};';
+ return XDB::execute($sql, $sid);
}
+ // }}}
+
+ // }}}
+}
+// }}}
+
+// {{{ abstract class SurveyQuestion
+abstract class SurveyQuestion
+{
+ // {{{ common properties, constructor, and basic methods
+ private $question;
+ private $comment;
- /* Return an indicator of the progression of the survey:
- * negative values means 'the survey is not started'
- * 0 means 'the survey is in progress'
- * positive values means 'the survey expired'
- */
- public function progression()
+ public function __construct($args)
{
- if (!$this->flags->hasFlag('validated')) {
- return -2;
- }
- $now = time();
- if ($this->begin->format('U') > $now) {
- return -1;
- }
- if ($this->end->format('U') <= $now) {
- return 1;
- }
- return 0;
+ $this->update($args);
}
- public function canSee(User $user)
+ public function update($a)
{
- if ($this->canSeeResults($user) || $this->canVote($user)) {
- return true;
- }
- return false;
+ $this->question = $a['question'];
+ $this->comment = $a['comment'];
}
- public function canSeeResults(User $user)
+ abstract protected function getQuestionType();
+ // }}}
+
+ // {{{ function toArray() : converts to array
+ public function toArray()
{
- if ($user->id() == $this->uid || $user->hasFlag('admin')) {
- return true;
- }
- if (is_null($this->viewerFilter)) {
- return $this->viewerFilter->checkUser($user);
+ return array('type' => $this->getQuestionType(), 'question' => $this->question, 'comment' => $this->comment);
+ }
+ // }}}
+
+ // {{{ function checkSyntax() : checks question elements (before storing into database), not currently needed (with new structure)
+ protected function checkSyntax()
+ {
+ return null;
+ }
+ // }}}
+
+ // {{{ function checkAnswer : returns a correct answer (or a null value if error)
+ public function checkAnswer($ans)
+ {
+ return null;
+ }
+ // }}}
+
+ // {{{ functions regarding the results of a survey
+ abstract public function getResultArray($sid, $qid);
+
+ public function formatAnswer($ans)
+ {
+ return $ans;
+ }
+
+ public function getCSVColumns()
+ {
+ return $this->question;
+ }
+ // }}}
+}
+// }}}
+
+// {{{ abstract class SurveySimple and its derived classes : "open" questions
+// {{{ abstract class SurveySimple extends SurveyQuestion
+abstract class SurveySimple extends SurveyQuestion
+{
+ public function checkAnswer($ans)
+ {
+ return array($ans);
+ }
+
+ public function getResultArray($sid, $qid)
+ {
+ $sql = 'SELECT answer
+ FROM survey_answers
+ WHERE vote_id IN (SELECT id FROM survey_votes WHERE survey_id={?})
+ AND question_id={?}
+ ORDER BY RAND()
+ LIMIT 5;';
+ $res = XDB::query($sql, $sid, $qid);
+ return $res->fetchAllAssoc();
+ }
+}
+// }}}
+
+// {{{ class SurveyText extends SurveySimple : simple text field, allowing a few words
+class SurveyText extends SurveySimple
+{
+ public function getQuestionType()
+ {
+ return "text";
+ }
+}
+// }}}
+
+// {{{ class SurveyTextarea extends SurveySimple : textarea field, allowing longer comments
+class SurveyTextarea extends SurveySimple
+{
+ public function getQuestionType()
+ {
+ return "textarea";
+ }
+}
+// }}}
+
+// {{{ class SurveyNum extends SurveySimple : allows numerical answers
+class SurveyNum extends SurveySimple
+{
+ public function checkAnswer($ans)
+ {
+ return array(intval($ans));
+ }
+
+ protected function getQuestionType()
+ {
+ return "num";
+ }
+}
+// }}}
+// }}}
+
+// {{{ abstract class SurveyList and its derived classes : restricted questions that allows only a list of possible answers
+// {{{ abstract class SurveyList extends SurveyQuestion
+abstract class SurveyList extends SurveyQuestion
+{
+ protected $choices;
+
+ public function update($args)
+ {
+ parent::update($args);
+ $this->choices = array();
+ foreach ($args['choices'] as $val) {
+ if (trim($val) || trim($val) == '0') {
+ $this->choices[] = $val;
+ }
}
- return false;
}
- public function canVote(User $user)
+ public function toArray()
{
- $status = $this->progression();
- if ($status < 0) {
- return "Ce sondage n'est pas encore commencé";
- } else if ($status > 0) {
- return "Ce sondage est terminé";
+ $rArr = parent::toArray();
+ $rArr['choices'] = $this->choices;
+ return $rArr;
+ }
+
+ public function getResultArray($sid, $qid)
+ {
+ $sql = 'SELECT answer, COUNT(id) AS count
+ FROM survey_answers
+ WHERE vote_id IN (SELECT id FROM survey_votes WHERE survey_id={?})
+ AND question_id={?}
+ GROUP BY answer ASC';
+ $res = XDB::query($sql, $sid, $qid);
+ return $res->fetchAllAssoc();
+ }
+
+ public function formatAnswer($ans)
+ {
+ if (array_key_exists($ans, $this->choices)) {
+ return $this->choices[$ans];
+ } else {
+ return null;
}
- if (!is_null($this->voterFilter) && !$this->voterFilter->checkUser($user)) {
- return "Ce sondage ne s'adresse pas à toi";
+ }
+}
+// }}}
+
+// {{{ class SurveyRadio extends SurveyList : radio question, allows one answer among the list offered
+class SurveyRadio extends SurveyList
+{
+ public function checkAnswer($ans)
+ {
+ $a = intval($ans);
+ return (array_key_exists($a, $this->choices))? array($a) : null;
+ }
+
+ protected function getQuestionType()
+ {
+ return "radio";
+ }
+}
+// }}}
+
+// {{{ class SurveyCheckbox extends SurveyList : checkbox question, allows any number of answers among the list offered
+class SurveyCheckbox extends SurveyList
+{
+ public function checkAnswer($ans)
+ {
+ $rep = array();
+ foreach ($ans as $a) {
+ $a = intval($a);
+ if (array_key_exists($a, $this->choices)) {
+ $rep[] = $a;
+ }
}
- $vote = SurveyVote::getVote($this, $user, false);
- if (is_null($vote)) {
- return "Tu as déjà voté à ce sondage.";
+ return (count($rep) == 0)? null : $rep;
+ }
+
+ protected function getQuestionType()
+ {
+ return "checkbox";
+ }
+}
+// }}}
+// }}}
+
+// {{{ abstract class SurveyTable and its derived classes : table question, each column represents a choice, each line represents a question
+// {{{ abstract class SurveyTable extends SurveyList
+abstract class SurveyTable extends SurveyList
+{
+ protected $subquestions;
+
+ public function update($args)
+ {
+ parent::update($args);
+ $this->subquestions = array();
+ foreach ($args['subquestions'] as $val) {
+ if (trim($val) || trim($val) == '0') {
+ $this->subquestions[] = $val;
+ }
}
- return true;
}
- public function vote(User $user, array $answers)
+ public function toArray()
{
- if (!$this->canVote($user)) {
- return array('survey' => "Tu n'es pas autorisé à voter à ce sondage.");
+ $rArr = parent::toArray();
+ $rArr['subquestions'] = $this->subquestions;
+ return $rArr;
+ }
+
+ public function getResultArray($sid, $qid)
+ {
+ $sql = 'SELECT answer, COUNT(id) AS count
+ FROM survey_answers
+ WHERE vote_id IN (SELECT id FROM survey_votes WHERE survey_id={?})
+ AND question_id={?}
+ GROUP BY answer ASC';
+ $res = XDB::iterator($sql, $sid, $qid);
+ $result = array();
+ for ($i = 0; $i < count($this->subquestions); $i++) {
+ $result[$i] = array_fill(0, count($this->choices), 0);
}
- $vote = SurveyVote::getVote($this, $user);
- if (is_null($vote)) {
- return $vote;
+ while ($r = $res->next()) {
+ list($i, $j) = explode(':', $r['answer']);
+ $result[$i][$j] = $r['count'];
}
- $answers = new PlDict($answers);
- foreach ($this->questions as $question) {
- $question->vote($vote, $answers);
+ return $result;
+ }
+
+ public function formatAnswer($ans)
+ {
+ list($q, $c) = explode(':', $ans);
+ if (array_key_exists($q, $this->subquestions) && array_key_exists($c, $this->choices)) {
+ return array('id' => $q, 'answer' => $this->choices[$c]);
+ } else {
+ return null;
}
- return $vote;
}
- public static function get($name, $fetchQuestions = true)
+ public function getCSVColumns()
{
- if (is_array($name)) {
- $name = $name[0];
+ $q = parent::getCSVColumns();
+ if (empty($this->subquestions)) {
+ return $q;
}
- $survey = new Survey();
- $survey->fetchQuestions = $fetchQuestions;
- if (can_convert_to_integer($name)) {
- $survey->id = $name;
- } else {
- $survey->shortname = $name;
+ $a = array();
+ for ($k = 0; $k < count($this->subquestions); $k++) {
+ $a[$k] = $q.' : '.$this->subquestions[$k];
}
- if (!$survey->fetch()) {
- return null;
+ return $a;
+ }
+}
+// }}}
+
+// {{{ class SurveyRadioTable extends SurveyTable : SurveyTable with radio type choices
+class SurveyRadioTable extends SurveyTable
+{
+ public function checkAnswer($ans)
+ {
+ $rep = array();
+ foreach ($ans as $k => $a) {
+ if (!array_key_exists($k, $this->subquestions)) {
+ continue;
+ }
+ $a = intval($a);
+ if (array_key_exists($a, $this->choices)) {
+ $rep[] = $k . ':' . $a;
+ }
}
- return $survey;
+ return (count($rep) == 0)? null : $rep;
}
- public static function iterActive()
+ protected function getQuestionType()
{
- $survey = new Survey();
- $survey->fetchQuestions = false;
- return $survey->iterateOnCondition('begin <= CURDATE() AND end >= CURDATE()
- AND FIND_IN_SET(\'validated\', flags)');
+ return "radiotable";
}
+
}
+// }}}
-class ShortNameFieldValidator implements PlDBTableFieldValidator
+// {{{ class SurveyCheckboxTable extends SurveyTable : SurveyTable with checkbox type choices
+class SurveyCheckboxTable extends SurveyTable
{
- public function __construct(PlDBTableField $field, $value)
+ public function checkAnswer($ans)
{
- if (can_convert_to_integer($value) || !preg_match('/^[a-z0-9]+[-_\.a-z0-9]*[a-z0-9]+$/i', $value)) {
- throw new PlDBBadValueException($value, $field,
- 'The shortname can only contain alphanumerical caracters, dashes, underscores and dots');
+ $rep = array();
+ foreach ($ans as $k => $aa) {
+ if (!array_key_exists($k, $this->subquestions)) {
+ continue;
+ }
+ foreach ($aa as $a) {
+ $a = intval($a);
+ if (array_key_exists($a, $this->choices)) {
+ $rep[] = $k . ':' . $a;
+ }
+ }
}
+ return (count($rep) == 0)? null : $rep;
+ }
+
+ protected function getQuestionType()
+ {
+ return "checkboxtable";
}
+
}
+// }}}
+// }}}
// vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8:
?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2011 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-class SurveyQuestionText extends SurveyQuestion
-{
- public function __construct(Survey $survey)
- {
- parent::__construct($survey);
- $this->type = "text";
- }
-
- protected function buildAnswer(SurveyAnswer $answer, PlDict $data)
- {
- $value = $data->t($this->qid);
- if (!empty($value)) {
- $answer->answer = array('text' => $value);
- } else {
- $answer->answer = null;
- }
- return true;
- }
-}
-
-// vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8:
-?>
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+<h1>Sondages</h1>
+
+<table class="bicol">
+ <tr>
+ <th>
+ Sondages en cours
+ </th>
+ </tr>
+ {iterate item=s from=$survey_current}
+ <tr class="{cycle name=cs_cycle values="impair,pair"}">
+ <td class="half">
+ •
+ <a href="survey/admin/{$s.id}">
+ {$s.title} [{$s.end|date_format:"%x"} - {$survey_modes[$s.mode]}]
+ </a>
+ </td>
+ </tr>
+ {assign var="has_cs" value="true"}
+ {/iterate}
+ {if !$has_cs}
+ <tr>
+ <td class="half">Aucun sondage en cours</td>
+ </tr>
+ {/if}
+</table>
+
+<br />
+
+<table class="bicol">
+ <tr>
+ <th>
+ Anciens sondages
+ </th>
+ </tr>
+ {iterate item=s from=$survey_old}
+ <tr class="{cycle name=os_cycle values="impair,pair"}">
+ <td class="half">
+ •
+ <a href="survey/admin/{$s.id}">
+ {$s.title} [{$s.end|date_format:"%x"} - {$survey_modes[$s.mode]}]
+ </a>
+ </td>
+ </tr>
+ {assign var="has_os" value="true"}
+ {/iterate}
+ {if !$has_os}
+ <tr>
+ <td class="half">Aucun ancien sondage</td>
+ </tr>
+ {/if}
+</table>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+<h1>Sondages : confirmation</h1>
+
+<form action="{$survey_formaction}" method="post">
+ {if is_array($survey_formhidden)}
+ {foreach from=$survey_formhidden item=s_value key=s_key}
+ <input type="hidden" name="survey_{$s_key}" value="{$s_value}"/>
+ {/foreach}
+ {/if}
+ {if $survey_message neq ""}
+ {$survey_message}
+ {else}
+ Une confirmation est requise
+ {/if}
+ <br/>
+ <input type="submit" name="survey_submit" value="Confirmer"/>
+ <input type="submit" name="survey_cancel" value="Annuler"/>
+</form>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
+++ /dev/null
-{**************************************************************************}
-{* *}
-{* Copyright (C) 2003-2011 Polytechnique.org *}
-{* http://opensource.polytechnique.org/ *}
-{* *}
-{* This program is free software; you can redistribute it and/or modify *}
-{* it under the terms of the GNU General Public License as published by *}
-{* the Free Software Foundation; either version 2 of the License, or *}
-{* (at your option) any later version. *}
-{* *}
-{* This program is distributed in the hope that it will be useful, *}
-{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
-{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
-{* GNU General Public License for more details. *}
-{* *}
-{* You should have received a copy of the GNU General Public License *}
-{* along with this program; if not, write to the Free Software *}
-{* Foundation, Inc., *}
-{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
-{* *}
-{**************************************************************************}
-
-{literal}
-<script id="q_edit_new" type="text/x-jquery-tmpl">
- <fieldset style="clear: both; padding-top: 1em; background: inherit; color: inherit"
- class="q_edit" id="q_edit[${qid}]">
- <legend>
- <span class="q_edit_label" style="font-weight: bold">Question ${qid + 1}</span>
- <input type="text" name="q_edit[${qid}][label]" value="{{if label}}${label}{{/if}}" />
- (<a onclick="$(this).removeQuestion()" style="text-decoration: none">
- {/literal}{icon name="delete"}{literal} Supprimer
- </a>)<br />
- Type de question : <select name="q_edit[${qid}][type]">
- <option value=""></option>
- <option value="section" {{if type}}{{if type == 'section'}}selected="selected"{{/if}}{{/if}}>
- Section
- </option>
- <option value="text" {{if type}}{{if type == 'text'}}selected="selected"{{/if}}{{/if}}>
- Champ libre
- </option>
- <option value="multiple" {{if type}}{{if type == 'multiple'}}selected="selected"{{/if}}{{/if}}>
- Question à choix multiples
- </option>
- </select>
- </legend>
- <div class="q_edit_form">
- {{tmpl "#q_edit_base"}}
- </div>
- </fieldset>
-</script>
-
-<script id="q_edit_base" type="text/x-jquery-tmpl">
- {{if type}}
- {{tmpl "#q_edit_" + type}}
- {{/if}}
-</script>
-
-<script id="q_edit_text" type="text/x-jquery-tmpl">
- Type de texte :
- <select name="q_edit[${qid}][subtype]">
- <option value="monoline" {{if subtype}}{{if subtype == 'monoline'}}selected="selected"{{/if}}{{/if}}>
- Une seule ligne
- </option>
- <option value="multiline" {{if subtype}}{{if subtype == 'multiline'}}selected="selected"{{/if}}{{/if}}>
- Plusieurs lignes
- </option>
- </select>
-</script>
-
-<script id="q_edit_section" type="text/x-jquery-tmpl">
- <div>
- Type de section :
- <select name="q_edit[${qid}][subtype]">
- <option value="group" {{if subtype}}{{if subtype == 'group'}}selected="selected"{{/if}}{{/if}}>
- Groupe de questions
- </option>
- <option value="page" {{if subtype}}{{if subtype == 'page'}}selected="selected"{{/if}}{{/if}}>
- Nouvelle page
- </option>
- </select>
- </div>
- <div id="q_edit[${qid}][section]">
- <div class="add_question">
- <a onclick="$(this).addQuestion()" style="text-decoration: none">
- {/literal}{icon name="add"}{literal} Ajouter une question
- </a>
- </div>
- </div>
-</script>
-
-<script id="q_edit_multiple" type="text/x-jquery-tmpl">
- <div id="q_edit[${qid}][answers]">
- <div>
- Permettre la sélection de plusieurs réponses ?
- <select name="q_edit[${qid}][subtype]">
- <option value="checkbox" {{if subtype}}{{if subtype == 'checkbox'}}selected="selected"{{/if}}{{/if}}>
- Oui
- </option>
- <option value="radio" {{if subtype}}{{if subtype == 'radio'}}selected="selected"{{/if}}{{/if}}>
- Non
- </option>
- </select>
- </div>
- <div class="add_answer">
- <a onclick="$(this).multiple_addAnswer()">
- {/literal}{icon name="add"}{literal} Ajouter une réponse
- </a>
- </div>
- <div>
- Ajouter une case Autre ?
- <select name="q_edit[${qid}][allow_other]">
- <option value="1" {{if $item.allow_other}}selected="selected"{{/if}}>Oui</option>
- <option value="" {{if !$item.allow_other}}selected="selected"{{/if}}>Non</option>
- </select>
- </div>
- </div>
-</script>
-
-<script id="q_edit_multiple_answer" type="text/x-jquery-tmpl">
- <div>
- <span class="q_edit_answer_box"></span>
- <input type="text" name="q_edit[${qid}][answers][]" value="${value}" />
- <a onclick="$(this).multiple_removeAnswer()">{/literal}{icon name="delete"}{literal}</a>
- </div>
-</script>
-{/literal}
-
-{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
+++ /dev/null
-{**************************************************************************}
-{* *}
-{* Copyright (C) 2003-2011 Polytechnique.org *}
-{* http://opensource.polytechnique.org/ *}
-{* *}
-{* This program is free software; you can redistribute it and/or modify *}
-{* it under the terms of the GNU General Public License as published by *}
-{* the Free Software Foundation; either version 2 of the License, or *}
-{* (at your option) any later version. *}
-{* *}
-{* This program is distributed in the hope that it will be useful, *}
-{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
-{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
-{* GNU General Public License for more details. *}
-{* *}
-{* You should have received a copy of the GNU General Public License *}
-{* along with this program; if not, write to the Free Software *}
-{* Foundation, Inc., *}
-{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
-{* *}
-{**************************************************************************}
-
-<h1>Edition de sondage</h1>
-
-<form action="survey/edit/{$survey->shortname}" method="post" id="form">
- <fieldset>
- <legend>Description du sondage</legend>
-
- Titre : <input type="text" name="title" value="{$survey->title}" /><br />
- Nom : <input type="text" name="shortname" value="{$survey->shortname}" /><br />
- Description :<br /><textarea name="description" style="width: 100%">{$survey->description}</textarea>
- </fieldset>
-
- <fieldset>
- <legend>Paramètre du sondage</legend>
- Premier jour : <input type="text" class="datepicker" name="begin" value="{$survey->begin}" /><br />
- Dernier jour : <input type="text" class="datepicker" name="end" value="{$survey->end}" /><br />
- Sondage anonyme : <label>Oui <input type="radio" name="anonymous" value="1" checked="checked" /></label>
- <label><input type="radio" name="anonymous" value="0" /> Non</label>
- </fieldset>
-
- <h2>Questions</h2>
-
- <div id="questions" class="q_edit">
- <div class="add_question">
- <a onclick="$(this).addQuestion()" style="text-decoration: none">
- {icon name="add"} Ajouter une question
- </a>
- </div>
- </div>
-
- <div class="center">
- <input type="submit" name="valid" value="Soumettre" />
- </div>
-</form>
-
-{include file="survey/vote.questions.tpl"}
-{include file="survey/edit.questions.tpl"}
-
-{literal}
-<script type="text/javascript">
- //<![CDATA[
- var questions = {/literal}{$survey->exportQuestionsToJSON()|smarty:nodefaults}{literal};
-
- $(function() {
- $('#form').submit(function() {
- $(this).buildParentsQuestions();
- return true;
- });
- $('#questions').prepareQuestions(questions);
- });
- //]]>
-</script>
-{/literal}
-
-{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{include file='survey/edit_radio.tpl'}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{include file='survey/edit_radiotable.tpl'}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+ <tr>
+ <td class="titre">Type</td>
+ <td>
+ <select name="survey_type" id="survey_type" onchange="Ajax.update_html('survey_form', 'survey/ajax/' + document.getElementById('survey_type').value); return false">
+ {foreach from=$survey_types key='stype_v' item='stype_t'}
+ <option value="{$stype_v}"{if $survey_type eq $stype_v} selected="selected"{/if}>{$stype_t}</option>
+ {/foreach}
+ </select>
+ </td>
+ </tr>
+ {if $survey_type == "new"}
+ {include file='survey/edit_question.tpl'}
+ {else}
+ {include file="survey/edit_$survey_type.tpl"}
+ {/if}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+ <tr>
+ <td colspan='2'>
+ Remplissez ici une description générale du sondage, puis cliquer sur "Continuer"
+ pour passer à l'édition des questions.
+ </td>
+ </tr>
+{include file='survey/edit_root.tpl'}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+ {include file='survey/edit_question.tpl'}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+ <tr>
+ <td class="titre">Question</td>
+ <td><input type="text" name="survey_question[question]" size="50" maxlength="200" value="{$survey_current.question}"{if $disable_question} disabled="disabled"{/if}/></td>
+ </tr>
+ <tr>
+ <td class="titre">Commentaire</td>
+ <td><textarea name="survey_question[comment]" rows="5" cols="60">{$survey_current.comment}</textarea></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td class="smaller">
+ <a href="wiki_help/notitle" class="popup3">
+ {icon name=information title="Syntaxe wiki"} Voir la syntaxe wiki autorisée pour le commentaire d'une question
+ </a>
+ </td>
+ </tr>
+ <script type="text/javascript">//<![CDATA[
+ var id = new Array();
+ id['choices'] = {$survey_current.choices|@count};
+ id['subquestions'] = {$survey_current.subquestions|@count};
+ {literal}
+ function newField(name, tid)
+ {
+ fid = "t" + id[name];
+ $("#" + name + "_" + tid).before('<div id="' + name + '_' + fid + '">'
+ + '<input id="' + name + '_' + fid + '_field" type="text" name="survey_question[' + name + '][' + fid + ']" size="50" maxlength="200" value="" /> '
+ + '<a href="javascript:removeField("' + name + '","' + fid + '")"><img src="images/icons/delete.gif" alt="" title="Supprimer" /></a>'
+ + '</div>');
+ id[name]++;
+ $("#" + name + "_" + fid + "_field").focus();
+ }
+ function removeField(name, tid)
+ {
+ $("#" + name + "_" + tid).remove();
+ }
+ {/literal}
+ //]]></script>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+ {include file='survey/edit_question.tpl'}
+ <tr>
+ <td class="titre">Choix</td>
+ <td>
+ {foreach from=$survey_current.choices key=value item=choice}
+ <div id="choices_t{$value}">
+ <input type="text" name="survey_question[choices][t{$value}]" size="50" maxlength="200" value="{$choice}" />
+ <a href="javascript:removeField('choices','t{$value}')">{icon name=delete title="Supprimer"}</a>
+ </div>
+ {/foreach}
+ <div id="choices_last">
+ <a href="javascript:newField('choices','last')">{icon name=add}</a>
+ </div>
+ </td>
+ </tr>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{include file='survey/edit_radio.tpl'}
+ <tr>
+ <td class="titre">Sous-questions</td>
+ <td>
+ {foreach from=$survey_current.subquestions key=value item=subquestion}
+ <div id="subquestions_t{$value}">
+ <input type="text" name="survey_question[subquestions][t{$value}]" size="50" maxlength="200" value="{$subquestion}" />
+ <a href="javascript:removeField('subquestions','t{$value}')">{icon name=delete title="Supprimer"}</a>
+ </div>
+ {/foreach}
+ <div id="subquestions_last">
+ <a href="javascript:newField('subquestions','last')">{icon name=add}</a>
+ </div>
+ </td>
+ </tr>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+ <tr>
+ <td class="titre">Titre</td>
+ <td><input type="text" name="survey_question[title]" size="50" maxlength="200" value="{$survey_current.title}"/></td>
+ </tr>
+ <tr>
+ <td class="titre">Commentaire</td>
+ <td><textarea name="survey_question[description]" rows="5" cols="60">{$survey_current.description}</textarea></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td class="smaller">
+ <a href="wiki_help/notitle" class="popup3">
+ {icon name=information title="Syntaxe wiki"} Voir la syntaxe wiki autorisée pour le commentaire du sondage
+ </a>
+ </td>
+ </tr>
+ <tr>
+ <td class="titre">Date de fin</td>
+ <td>
+ {valid_date name="survey_question[end]" value=$survey_current.end to=90}
+ <script type="text/javascript">//<![CDATA[
+ {literal}
+ $(document).ready(function() {
+ function hidePromo(value) {
+ if (value == "0" || value == "") {
+ $("#ln_promo").hide();
+ $("#ln_promo_exp").hide();
+ } else {
+ $("#ln_promo").show();
+ $("#ln_promo_exp").show();
+ }
+ }
+ $("[name='survey_question[mode]']").change(function() { hidePromo(this.value); });
+ hidePromo({/literal}"{$survey_current.mode}"{literal});
+ });
+ {/literal}
+ //]]></script>
+ </td>
+ </tr>
+ <tr>
+ <td class="titre">Type de sondage</td>
+ <td>
+ <select name="survey_question[mode]">
+ {foreach from=$survey_modes item=text key=name}
+ <option value="{$name}" {if $name eq $survey_current.mode}selected="selected"{/if}>{$text}</option>
+ {/foreach}
+ </select>
+ </td>
+ </tr>
+ <tr id="ln_promo">
+ <td class="titre">Promotions</td>
+ <td><input type="text" name="survey_question[promos]" size="50" maxlength="200" value="{$survey_current.promos}"/></td>
+ </tr>
+ <tr id="ln_promo_exp">
+ <td></td>
+ <td class="smaller">
+ Exemple : 1954,1986-1989,-1942,2000- restreindra le sondage à toutes les promotions suivantes :<br/>
+ 1954, 1986 à 1989, toutes jusqu'à 1942 et toutes à partir 2000 (les bornes sont systématiquement incluses).<br />
+ Pour sélectionner toutes les promotions, laisser le vide.
+ </td>
+ </tr>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
{**************************************************************************}
{* *}
-{* Copyright (C) 2003-2011 Polytechnique.org *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
{* http://opensource.polytechnique.org/ *}
{* *}
{* This program is free software; you can redistribute it and/or modify *}
{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
{* *}
{**************************************************************************}
+<h1>Sondage :
+ {if $survey_type == 'newsurvey'} créer un nouveau sondage
+ {elseif $survey_type == 'new'} ajouter une question
+ {elseif $survey_type == 'root'} modifier la description
+ {else} modifier une question
+ {/if}
+</h1>
-{literal}
-<script id="question_base" type="text/x-jquery-tmpl">
- {{tmpl "#question_" + type}}
-</script>
-
-<script id="question_section" type="text/x-jquery-tmpl">
- <fieldset>
- <legend>${label}</legend>
-
- {{tmpl(children) "#question_base"}}
- </fieldset>
-</script>
-
-<script id="question_text" type="text/x-jquery-tmpl">
- <div>
- {{if subtype}}
- {{if subtype == 'monoline'}}
- <strong>${label}</strong> :
- <input type="text" name="qid[${qid}]" value="" />
- {{else}}
- <div><strong>${label}</strong></div>
- <textarea name="qid[${qid}]" rows="4" cols="80"></textarea>
- {{/if}}
- {{else}}
- <strong>${label}</strong> :
- <input type="text" name="qid[${qid}]" value="" />
- {{/if}}
- </div>
-</script>
-
-<script id="question_multiple" type="text/x-jquery-tmpl">
- <div>
- <div><strong>${label}</strong></div>
- {{each answers}}
- <input type="${subtype}" name="qid[${qid}][answers][${$index}]" value="${$value}" /> ${$value}<br />
- {{/each}}
- {{if allow_other}}
- <input type="${subtype}" name="qid[${qid}][answers][other]" value="other" /> Autre, préciser :
- <input type="text" name="qid[${qid}][other]" />
- {{/if}}
+<form action="{$survey_formaction}" method="post">
+ <input type="hidden" name="survey_action" value="{$survey_action}"/>
+ <input type="hidden" name="survey_qid" value="{$survey_qid}"/>
+ <table class="bicol" id="survey_form">
+ {include file="survey/edit_$survey_type.tpl"}
+ </table>
+ <div class="center">
+ <input type="submit" name="survey_submit" value="{if $survey_type == 'newsurvey'}Continuer{else}Valider{/if}"/>
+ <input type="reset" name="survey_reset" value="Réinitialiser"/>
+ <input type="submit" name="survey_cancel" value="Annuler"/>
</div>
-</script>
-{/literal}
+</form>
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+ {include file='survey/edit_question.tpl'}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+ {include file='survey/edit_question.tpl'}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+<h1>Sondages : erreur</h1>
+
+{if !is_null($survey_errors) && is_array($survey_errors)}
+<table class="bicol">
+ <tr>
+ <th colspan='2'>Une ou plusieurs erreurs sont survenues</th>
+ </tr>
+ {foreach from=$survey_errors item=survey_error}
+ <tr class="{cycle values="impair,pair"}">
+ <td>• {$survey_error.error}</td>
+ <td><a href="survey/edit/question/{$survey_error.question}">corriger</a></td>
+ </tr>
+ {/foreach}
+</table>
+{elseif $survey_message neq ""}
+ {$survey_message}
+{else}
+Une erreur inconnue est survenue dans l'édition de ce sondage. N'hésite pas à <a href='send_bug/{ $smarty.server.REQUEST_URI }'>signaler ce bug</a> s'il persiste.
+{/if}
+<br/>
+<a href="{$survey_link}">Retour</a>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
<h1>Sondages</h1>
-{if $active->total() > 0}
-<table class="bicol" id="surveyList">
+{* Survey::MODE_ALL equals 0. *}
+{assign var=SurveyMODE_ALL value=0}
+{if $survey_current->total() > 0 || $smarty.session.auth}
+<table class="bicol">
<tr>
- <th>
+ <th colspan="3">
Sondages en cours
</th>
- {if hasPerm('admin')}
- <th></th>
- {/if}
</tr>
- {iterate from=$active item=survey}
- <tr class="{cycle values="impair,pair"}">
+ {iterate item=s from=$survey_current}
+ {if $smarty.session.auth || $s.mode == $SurveyMODE_ALL}
+ <tr class="{cycle name=cs_cycle values="impair,pair"}">
+ <td class="half" style="clear: both">
+ <a href="survey/vote/{$s.id}">{$s.title}</a>
+ {if $s.uid eq $smarty.session.user->id() || hasPerm('admin')}
+ (<a href="survey/result/{$s.id}">résultats partiels</a>)
+ {/if}
+ </td>
<td>
- <a href="survey/vote/{$survey->shortname}">{$survey->title}</a>
+ {$s.end|date_format:"%x"}
</td>
- {if hasPerm('admin')}
- <td style="text-align: right">
- <a href="survey/edit/{$survey->shortname}">{icon name=page_edit}</a>
+ <td>
+ {$survey_modes[$s.mode]}
</td>
- {/if}
</tr>
+ {assign var="has_cs" value="true"}
+ {/if}
{/iterate}
+ <tr class="impair">
+ <td colspan="3" style="text-align: right">
+ {if $smarty.session.auth}<a href="survey/edit/new">{icon name=page_edit} Proposer un sondage</a>{/if}
+ </td>
+ </tr>
</table>
{/if}
+
<br />
-<div class="center">
- <a href="survey/edit">{icon name=page_edit} Proposer un nouveau sondage</a>
-</div>
+
+<table class="bicol">
+ <tr>
+ <th colspan="3">
+ Anciens sondages
+ </th>
+ </tr>
+ {iterate item=s from=$survey_old}
+ {if $smarty.session.auth || $s.mode == $SurveyMODE_ALL}
+ <tr class="{cycle name=os_cycle values="impair,pair"}">
+ <td>
+ <a href="survey/result/{$s.id}">
+ {$s.title}
+ </a>
+ </td>
+ <td>
+ {$s.end|date_format:"%x"}
+ </td>
+ <td>
+ {$survey_modes[$s.mode]}
+ </td>
+ </tr>
+ {assign var="has_os" value="true"}
+ {/if}
+ {/iterate}
+ {if !$has_os}
+ <tr>
+ <td class="half">Aucun ancien sondage</td>
+ </tr>
+ {/if}
+</table>
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{if $survey_resultmode}
+ <ul>
+ {foreach item=sresult from=$squestion.result}
+ <li>{$squestion.choices[$sresult.answer]} : {$sresult.count*100/$survey.votes|string_format:"%.1f"}% ({$sresult.count} votes)</li>
+ {/foreach}
+ </ul>
+{else}
+ {assign var=sid value=$survey.id}
+ {assign var=sqid value=$squestion.id}
+ {if $survey_votemode}
+ {html_checkboxes name="survey$sid[$sqid]" options=$squestion.choices separator='<br/>'}
+ {else}
+ {html_checkboxes name="survey$sid[$sqid]" options=$squestion.choices separator='<br/>' disabled='disabled'}
+ {/if}
+{/if}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+<table class="bicol">
+ <tr class="pair">
+ <td></td>
+ {foreach from=$squestion.choices item=schoice}
+ <td>{$schoice}</td>
+ {/foreach}
+ </tr>
+{foreach from=$squestion.subquestions item=ssubq key=ssqid}
+ <tr class="{cycle values="impair,pair"}">
+ <td>{$ssubq}</td>
+ {assign var=sid value=$survey.id}
+ {assign var=sqid value=$squestion.id}
+ {if $survey_resultmode}
+ {foreach from=$squestion.choices item=schoice key=value}
+ <td>
+ {$squestion.result.$ssqid.$value*100/$survey.votes|string_format:"%.1f"}% ({$squestion.result.$ssqid.$value} votes)
+ </td>
+ {/foreach}
+ {else}
+ {foreach from=$squestion.choices item=schoice key=value}
+ <td>
+ <label><input type="checkbox" name="survey{$sid}[{$sqid}][{$ssqid}][]" value="{$value}" {if !$survey_votemode}disabled="disabled" {/if}/></label>
+ </td>
+ {/foreach}
+ {/if}
+ </tr>
+{/foreach}
+</table>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{include file='survey/show_text.tpl'}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+ <h2>{$squestion.question}</h2>
+{if $squestion.comment != ''}
+ {$squestion.comment|miniwiki|smarty:nodefaults}<br/>
+{/if}
+{assign var='squestion_type' value=$squestion.type}
+{include file="survey/show_$squestion_type.tpl"}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{if $survey_resultmode}
+ <ul>
+ {foreach item=sresult from=$squestion.result}
+ <li>{$squestion.choices[$sresult.answer]} : {$sresult.count*100/$survey.votes|string_format:"%.1f"}% ({$sresult.count} votes)</li>
+ {/foreach}
+ </ul>
+{else}
+ {assign var=sid value=$survey.id}
+ {assign var=sqid value=$squestion.id}
+ {if $survey_votemode}
+ {html_radios name="survey$sid[$sqid]" options=$squestion.choices separator='<br/>'}
+ {else}
+ {html_radios name="survey$sid[$sqid]" options=$squestion.choices separator='<br/>' disabled='disabled'}
+ {/if}
+{/if}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+<table class="bicol">
+ <tr class="pair">
+ <td></td>
+ {foreach from=$squestion.choices item=schoice}
+ <td>{$schoice}</td>
+ {/foreach}
+ </tr>
+{foreach from=$squestion.subquestions item=ssubq key=ssqid}
+ <tr class="{cycle values="impair,pair"}">
+ <td>{$ssubq}</td>
+ {assign var=sid value=$survey.id}
+ {assign var=sqid value=$squestion.id}
+ {if $survey_resultmode}
+ {foreach from=$squestion.choices item=schoice key=value}
+ <td>
+ {$squestion.result.$ssqid.$value*100/$survey.votes|string_format:"%.1f"}% ({$squestion.result.$ssqid.$value} votes)
+ </td>
+ {/foreach}
+ {else}
+ {foreach from=$squestion.choices item=schoice key=value}
+ <td>
+ <label><input type="radio" name="survey{$sid}[{$sqid}][{$ssqid}]" value="{$value}" {if !$survey_votemode}disabled="disabled" {/if}/></label>
+ </td>
+ {/foreach}
+ {/if}
+ </tr>
+{/foreach}
+</table>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+<h1>Sondage : {$survey.title}</h1>
+<form action="survey/vote{if $survey_votemode}/{$survey.id}{/if}" method='post'>
+<table style="width: 100%">
+ <tr>
+ <td>
+ <table class="bicol">
+ <tr class="pair">
+ <td colspan="2">{$survey.description|miniwiki|smarty:nodefaults}</td>
+ </tr>
+ <tr>
+ <td class="titre">Fin du sondage :</td>
+ <td>{$survey.end|date_format:"%x"}</td>
+ </tr>
+ <tr>
+ <td class="titre">Type de sondage :</td>
+ <td>{$survey_modes[$survey.mode]}</td>
+ </tr>
+ {if $survey.mode != Survey::MODE_ALL}
+ <tr>
+ <td class="titre">Promotions :</td>
+ <td>
+ {if $survey.promos eq "#"}
+ <span class="erreur">erreur</span>
+ {elseif $survey.promos eq ""}
+ aucune restriction
+ {else}
+ {$survey.promos}
+ {/if}
+ </td>
+ </tr>
+ {/if}
+ {if $survey_warning}
+ <tr class="pair">
+ <td colspan="2">{$survey_warning}</td>
+ </tr>
+ {/if}
+ </table>
+ {if $survey_resultmode}
+ <p class="smaller">{$survey.votes} personnes ont répondu à ce sondage.<br />
+ Récupérer <a href="survey/result/{$survey.id}/csv">l'ensemble des résultats</a> au format csv
+ </p>
+ {/if}
+ </td>
+ {if $survey_editmode && !$survey.valid}
+ {assign var="survey_editallmode" value=true}
+ {/if}
+ {if $survey_editmode}
+ <td style="width: 30%">
+ <a href='survey/edit/question/root'>{icon name=page_edit alt="Modifier" title="Modifier la description"}</a>
+ {if $survey_editallmode}<br /><a href='survey/edit/add/0'>{icon name=add title="Ajouter une question au début" alt="Ajouter"}</a>{/if}
+ </td>
+ {/if}
+ </tr>
+ {if is_array($survey.questions)}
+ {foreach from=$survey.questions item=squestion}
+ <tr>
+ <td>
+ {include file='survey/show_question.tpl' squestion=$squestion}
+ </td>
+ {if $survey_editallmode}
+ <td class="smaller" style="width: 30%; vertical-align: middle">
+ <a href='survey/edit/question/{$squestion.id}'>{icon name=page_edit title="Modifier cette question" alt="Modifier"}</a><br />
+ <a href='survey/edit/del/{$squestion.id}'>{icon name=delete title="Supprimer cette question" alt="Supprimer"}</a><br />
+ <a href='survey/edit/add/{$squestion.id+1}'>{icon name=add title="Ajouter une question après" alt="Ajouter"}</a>
+ </td>
+ {/if}
+ </tr>
+ {/foreach}
+ {/if}
+</table>
+<p class="center">
+ {if $smarty.session.survey_validate || ($survey_editmode && !$survey_updatemode)}
+ <a href='survey/edit/valid'>
+ {icon name=tick}
+ Proposer ce sondage
+ </a> |
+ <a href='survey/edit/cancel'>
+ {icon name=cross}
+ Annuler totalement la création de ce sondage
+ </a>
+ {elseif $survey_adminmode}
+ {if !$survey.valid}<a href="survey/admin/valid/{$survey.id}">Valider ce sondage</a> | {/if}
+ <a href="survey/admin/edit/{$survey.id}">{icon name=tick} Modifier ce sondage</a> |
+ <a href="survey/admin/del/{$survey.id}">{icon name=cross} Supprimer ce sondage</a> |
+ <a href="survey/admin">Retour</a>
+ {elseif $survey_votemode}
+ <input type='submit' name='survey_submit' value='Voter'/>
+ <input type='submit' name='survey_cancel' value='Annuler'/>
+ {else}
+ <a href="survey">Retour</a>
+ {/if}
+</p>
+</form>
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{if $survey_resultmode}
+ {if count($squestion.result) == 0}
+ Aucune réponse n'a été donnée.
+ {else}
+ {if count($squestion.result) ==1}
+ Une réponse donnée par une d{else}Quelques réponses données par l{/if}es personnes sondées :
+ <ul>
+ {assign var=nbhidden value=0}
+ {foreach item=sresult from=$squestion.result}
+ {if trim($result.answer)}
+ <li>{$sresult.answer}</li>
+ {else}
+ {assign var=nbhidden value=$nbhidden+1}
+ {/if}
+ {/foreach}
+ {if $nbhidden > 0}
+ <li>{$nbhidden} réponse{if $nbhidden > 1}s{/if} vide{if $nbhidden > 1}s{/if}</li>
+ {/if}
+ </ul>
+ {/if}
+{else}
+ <input type="text" name="survey{$survey.id}[{$squestion.id}]" value="" size="50" maxlength="200" {if !$survey_votemode}disabled="disabled"{/if}/>
+{/if}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+{if $survey_resultmode}
+ {if count($squestion.result) == 0}
+ Aucune réponse n'a été donnée.
+ {else}
+ {if count($squestion.result) ==1}
+ Une réponse donnée par une d{else}Quelques réponses données par l{/if}es personnes sondées :
+ <ul>
+ {assign var=nbhidden value=0}
+ {foreach item=sresult from=$squestion.result}
+ {if trim($result.answer)}
+ <li>{$sresult.answer}</li>
+ {else}
+ {assign var=nbhidden value=$nbhidden+1}
+ {/if}
+ {/foreach}
+ {if $nbhidden > 0}
+ <li><em>{$nbhidden} réponse{if $nbhidden > 1}s{/if} vide{if $nbhidden > 1}s{/if}</em></li>
+ {/if}
+ </ul>
+ {/if}
+{else}
+ <textarea name="survey{$survey.id}[{$squestion.id}]" rows="5" cols="60" {if !$survey_votemode}disabled="disabled"{/if}></textarea>
+{/if}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
{* *}
{**************************************************************************}
-
-<h1>{$survey->title}</h1>
-
-<p>{$survey->description|miniwiki}</p>
-
-<form action="survey/vote/{$survey->shortname}" method="post">
- <div id="questions">
- </div>
-
- <div class="center">
- {xsrf_token_field}
- <input type="submit" name="vote" value="Enregister mon vote" />
- </div>
-</form>
-
-{include file="survey/vote.questions.tpl"}
-
-<script type="text/javascript">
- //<![CDATA[
- var questions = {$survey->exportQuestionsToJSON()|smarty:nodefaults};
-
- $($("#questions").showQuestions(questions));
- //]]>
-</script>
+<h1>Sondages : succès</h1>
+
+{if $survey_message neq ""}
+ {$survey_message}
+{else}
+ Opération réussie
+{/if}
+<br/>
+<a href="{$survey_link}">Retour</a>
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
+++ /dev/null
-#RENAME TABLE surveys TO old_surveys,
-# survey_answers TO old_survey_answers,
-# survey_votes TO old_survey_votes;
-
-DROP TABLE IF EXISTS survey_vote_answers;
-DROP TABLE IF EXISTS survey_voters;
-DROP TABLE IF EXISTS survey_answers;
-DROP TABLE IF EXISTS survey_votes;
-DROP TABLE IF EXISTS survey_questions;
-DROP TABLE IF EXISTS surveys;
-
-CREATE TABLE surveys (
- id INT(11) UNSIGNED NOT NULL auto_increment,
- uid INT(11) UNSIGNED NOT NULL,
- shortname VARCHAR(32) NOT NULL,
- title VARCHAR(255) NOT NULL,
- description TEXT NOT NULL,
- begin DATE NOT NULL,
- end DATE NOT NULL,
-
- voters TEXT DEFAULT NULL COMMENT "Filter users who can vote",
- viewers TEXT DEFAULT NULL COMMENT "Filter users who can see the results",
-
- flags SET('validated', 'anonymous'),
-
- PRIMARY KEY id (id),
- UNIQUE KEY shortname (shortname),
- FOREIGN KEY (uid) REFERENCES accounts (uid)
- ON UPDATE CASCADE
- ON DELETE CASCADE
-) ENGINE=InnoDB, CHARSET=utf8, COMMENT="Describe a survey";
-
-CREATE TABLE survey_questions (
- sid INT(11) UNSIGNED NOT NULL,
- qid INT(11) UNSIGNED NOT NULL,
- parent INT(11) UNSIGNED DEFAULT NULL COMMENT "Id of the parent question",
-
- type VARCHAR(32) NOT NULL, -- XXX: Use an enum of possible types?
- label TEXT DEFAULT NULL,
- parameters TEXT DEFAULT NULL COMMENT "Parameters of the question",
- flags SET('multiple', 'mandatory', 'noanswer') NOT NULL DEFAULT '',
-
- PRIMARY KEY id (sid, qid),
- FOREIGN KEY (sid) REFERENCES surveys (id)
- ON UPDATE CASCADE
- ON DELETE CASCADE
-) ENGINE=InnoDB, CHARSET=utf8, COMMENT="Describe the questions of the surveys";
-
-CREATE TABLE survey_votes (
- vid INT(11) UNSIGNED NOT NULL auto_increment,
- sid INT(11) UNSIGNED NOT NULL,
-
- PRIMARY KEY vid (vid),
- FOREIGN KEY (sid) REFERENCES surveys (id)
- ON UPDATE CASCADE
- ON DELETE CASCADE
-) ENGINE=InnoDB, CHARSET=utf8, COMMENT="Identify unique votes";
-
-CREATE TABLE survey_voters (
- sid INT(11) UNSIGNED NOT NULL,
- uid INT(11) UNSIGNED NOT NULL,
- vid INT(11) UNSIGNED DEFAULT NULL, -- NULL for anonymous votes
-
- PRIMARY KEY id (sid, uid),
- FOREIGN KEY (uid) REFERENCES accounts (uid)
- ON UPDATE CASCADE
- ON DELETE CASCADE,
- FOREIGN KEY (sid) REFERENCES surveys (id)
- ON UPDATE CASCADE
- ON DELETE CASCADE
-) ENGINE=InnoDB, CHARSET=utf8, COMMENT="List voters";
-
-CREATE TABLE survey_vote_answers (
- sid INT(11) UNSIGNED NOT NULL,
- qid INT(11) UNSIGNED NOT NULL,
- vid INT(11) UNSIGNED NOT NULL,
-
- answer TEXT DEFAULT NULL,
-
- PRIMARY KEY id (sid, vid, qid),
- FOREIGN KEY (vid) REFERENCES survey_votes (vid)
- ON UPDATE CASCADE
- ON DELETE CASCADE,
- FOREIGN KEY (sid, qid) REFERENCES survey_questions (sid, qid)
- ON UPDATE CASCADE
- ON DELETE CASCADE
-) ENGINE=InnoDB, CHARSET=utf8, COMMENT="Answers to the surveys";
-
--- vim:set syntax=mysql:
+++ /dev/null
-#!/bin/bash
-
-. ../inc/pervasive.sh
-
-###########################################################
-[ "$DATABASE" != "x4dat" ] || die "Cannot target x4dat"
-copy_db
-
-confirm "* Running database upgrade scripts"
-#mysql_run_directory .