changes in surveys validation handling
authorx2004laborde <x2004laborde@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 23 Apr 2007 23:21:39 +0000 (23:21 +0000)
committerx2004laborde <x2004laborde@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 23 Apr 2007 23:21:39 +0000 (23:21 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1734 839d8a87-29fc-0310-9880-83ba4fa771e5

include/validations/surveys.inc.php [new file with mode: 0644]
modules/survey.php
modules/survey/survey.inc.php
templates/include/form.valid.surveys.tpl [new file with mode: 0644]
templates/survey/admin.tpl
upgrade/0.9.14/07_survey.sql

diff --git a/include/validations/surveys.inc.php b/include/validations/surveys.inc.php
new file mode 100644 (file)
index 0000000..7c26267
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2007 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 SurveyReq
+
+class SurveyReq extends Validate
+{
+    // {{{ properties
+    public $title;
+    public $description;
+    public $end;
+    public $mode;
+    public $promos;
+    public $questions;
+    // }}}
+    // {{{ constructor
+
+    public function __construct($_title, $_description, $_end, $_mode, $_promos, $_questions, $_uid)
+    {
+        parent::__construct($_uid, false, 'surveys');
+        $this->title       = $_title;
+        $this->description = $_description;
+        $this->end         = $_end;
+        $this->mode        = $_mode;
+        $this->promos      = $_promos;
+        $this->questions   = $_questions;
+    }
+
+    // }}}
+    // {{{ function formu()
+
+    public function formu()
+    {
+        return 'include/form.valid.surveys.tpl';
+    }
+
+    // }}}
+    // {{{ function _mail_subj
+    
+    protected function _mail_subj()
+    {
+        return "[Polytechnique.org/SONDAGES] Proposition de sondage";
+    }
+
+    // }}}
+    // {{{ function _mail_body
+
+    protected function _mail_body($isok)
+    {
+        if ($isok) {
+            return "  Le sondage que tu avais proposé vient d'être validé.";
+        } else {
+            return "  Le sondage que tu avais proposé a été refusé.";
+        }
+    }
+
+    // }}}
+    // {{{ function updateReq()
+
+    public function updateReq($_title, $_description, $_end, $_mode, $_promos, $_questions)
+    {
+        $this->title       = $_title;
+        $this->description = $_description;
+        $this->end         = $_end;
+        $this->mode        = $_mode;
+        $this->promos      = $_promos;
+        $this->questions   = $_questions;
+        return $this->update();
+    }
+
+    // }}}
+    // {{{ function commit()
+
+    public function commit()
+    {
+        $sql = 'INSERT INTO survey_surveys
+                        SET questions={?},
+                            title={?},
+                            description={?},
+                            author_id={?},
+                            end={?},
+                            mode={?},
+                            promos={?}';
+        return XDB::execute($sql, serialize($this->questions), $this->title, $this->description, $this->uid, $this->end, $this->mode, $this->promos);
+    }
+
+    // }}}
+}
+
+// }}}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index bf9bb4a..af8b0b3 100644 (file)
@@ -57,14 +57,14 @@ class SurveyModule extends PLModule
         }
         $id = intval($id);
         if ($id == -1) {
-            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", '');
+            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", 'survey');
         }
         require_once dirname(__FILE__).'/survey/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.", '');
+            return $this->show_error($page, "Sondage ".$id." introuvable.", 'survey');
         } elseif ($survey->isEnded()) {
-            return $this->show_error($page, "Le sondage ".$survey->getTitle()." est termin&#233;.");
+            return $this->show_error($page, "Le sondage ".$survey->getTitle()." est termin&#233;.", 'survey');
         }
         if (!$this->check_surveyPerms($page, $survey)) {
             return;
@@ -74,11 +74,11 @@ class SurveyModule extends PLModule
             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&#233;j&#224; vot&#233; &#224; ce sondage.");
+                    return $this->show_error($page, "Tu as d&#233;j&#224; vot&#233; &#224; ce sondage.", 'survey');
                 }
             }
             $survey->vote($uid, Post::v('survey'.$id)); // performs vote
-            $this->show_success($page, "Ta r&#233;ponse a bien &#233;t&#233; prise en compte. Merci d'avoir particip&#233; &#224; ce sondage.", '');
+            $this->show_success($page, "Ta r&#233;ponse a bien &#233;t&#233; prise en compte. Merci d'avoir particip&#233; &#224; 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);
@@ -96,14 +96,14 @@ class SurveyModule extends PLModule
     {
         $id = intval($id);
         if ($id == -1) {
-            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", '');
+            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", 'survey');
         }
         require_once dirname(__FILE__).'/survey/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.", '');
+            return $this->show_error($page, "Sondage ".$id." introuvable.", 'survey');
         } elseif (!$survey->isEnded()) {
-            return $this->show_error($page, "Le sondage ".$survey->getTitle()." n'est pas encore termin&#233;.");
+            return $this->show_error($page, "Le sondage ".$survey->getTitle()." n'est pas encore termin&#233;.", 'survey');
         }
         if (!$this->check_surveyPerms($page, $survey)) {
             return;
@@ -134,7 +134,7 @@ class SurveyModule extends PLModule
             $id = intval($id);
             $survey = Survey::retrieveSurvey($id); // retrieves all survey object structure
             if ($survey == null) {
-                $this->show_error($page, "Sondage ".$id." introuvable.", 'admin');
+                $this->show_error($page, "Sondage ".$id." introuvable.", 'survey/admin');
             }
             $page->assign('survey_adminmode', true);
             $this->show_survey($page, $survey);
@@ -143,16 +143,27 @@ class SurveyModule extends PLModule
     // }}}
 
     // {{{ function handler_adminEdit() : edits a survey in admin mode
-    function handler_adminEdit(&$page, $id = -1)
+    function handler_adminEdit(&$page, $id = -1, $req = -1)
     {
-        if ($id == -1) {
-            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", 'admin');
+        if ($id == -1 || ($id == 'req' && $req == -1)) {
+            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", 'survey/admin');
         }
-        $id = intval($id);
         require_once dirname(__FILE__).'/survey/survey.inc.php';
-        $survey = Survey::retrieveSurvey($id); // retrieves the survey in database
         $this->clear_session(); // cleans session (in case there would have been a problem before)
-        $this->store_session($survey, $id);
+        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
     }
     // }}}
@@ -166,19 +177,19 @@ class SurveyModule extends PLModule
             return $this->handler_admin(&$page, $id);
         }
         if ($id == -1) {
-            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", 'admin');
+            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", 'survey/admin');
         }
         $id = intval($id);
         require_once dirname(__FILE__).'/survey/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.", 'admin');
+            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 &#233;t&#233; valid&#233;, les votes sont maintenant ouverts.", 'admin');
+                $this->show_success($page, "Le sondage \"".$surveyInfo['title']."\" a bien &#233;t&#233; valid&#233;, les votes sont maintenant ouverts.", 'survey/admin');
             } else {
-                $this->show_error($page, '', 'admin');
+                $this->show_error($page, '', 'survey/admin');
             }
         } else { // asks for a confirmation
             $this->show_confirm($page, "&#202;tes-vous certain de vouloir valider le sondage \"".$surveyInfo['title']."\" ? "
@@ -195,19 +206,19 @@ class SurveyModule extends PLModule
             return $this->handler_admin(&$page, $id);
         }
         if ($id == -1) {
-            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", 'admin');
+            return $this->show_error($page, "Un identifiant de sondage doit &#234;tre pr&#233;cis&#233;.", 'survey/admin');
         }
         $id = intval($id);
         require_once dirname(__FILE__).'/survey/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.", 'admin');
+            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 &#233;t&#233; supprim&#233;, ainsi que tous les votes le concernant.", 'admin');
+                $this->show_success($page, "Le sondage \"".$surveyInfo['title']."\" a bien &#233;t&#233; supprim&#233;, ainsi que tous les votes le concernant.", 'survey/admin');
             } else {
-                $this->show_error($page, '', 'admin');
+                $this->show_error($page, '', 'survey/admin');
             }
         } else { // asks for a confirmation
             $this->show_confirm($page, "&#202;tes-vous certain de vouloir supprimer le sondage \"".$surveyInfo['title']."\" ?", 'admin/del', array('id' => $id));
@@ -240,7 +251,7 @@ class SurveyModule extends PLModule
                 $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, '', 'edit');
+                    return $this->show_error($page, '', 'survey/edit');
                 }
                 $this->show_survey($page, $survey);
                 $this->store_session($survey);
@@ -248,7 +259,7 @@ class SurveyModule extends PLModule
                 $survey = unserialize(S::v('survey'));
                 $current = $survey->toArray($qid); // gets the current parameters of the question
                 if ($current == null) {
-                    return $this->show_error($page, '', 'edit');
+                    return $this->show_error($page, '', 'survey/edit');
                 }
                 $this->show_form($page, $action, $qid, $current['type'], $current);
             } // }}}
@@ -266,7 +277,7 @@ class SurveyModule extends PLModule
             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, '', 'edit');
+                    return $this->show_error($page, '', 'survey/edit');
                 }
                 $this->show_survey($page, $survey);
                 $this->store_session($survey);
@@ -277,7 +288,7 @@ class SurveyModule extends PLModule
             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, '', 'edit');
+                    return $this->show_error($page, '', 'survey/edit');
                 }
                 $this->show_survey($page, $survey);
                 $this->store_session($survey);
@@ -285,7 +296,7 @@ class SurveyModule extends PLModule
                 $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, '', 'edit');
+                    return $this->show_error($page, '', 'survey/edit');
                 }
                 $this->show_confirm($page, '&#202;tes-vous certain de vouloir supprimer la question intitul&#233; "'.$current['question'].'" ? '
                                           .'Attention, cela supprimera en m&#234;me temps toutes les questions qui d&#233;pendent de celle-ci.',
@@ -298,17 +309,18 @@ class SurveyModule extends PLModule
             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 &#233;t&#233; enregistr&#233;es.", 'admin');
+                        $this->show_success($page, "Les modifications sur le sondage ont bien &#233;t&#233; enregistr&#233;es.", $link);
                     } else {
-                        $this->show_error($page, '', 'admin');
+                        $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 &#233;t&#233; enregistr&#233;e,
-                                                    elle est en attent de validation par un administrateur du site.", '');
+                                                    elle est en attent de validation par un administrateur du site.", 'survey');
                     } else {
-                        $this->show_error($page);
+                        $this->show_error($page, '', 'survey');
                     }
                 }
                 $this->clear_session();
@@ -316,7 +328,7 @@ class SurveyModule extends PLModule
                 $survey = unserialize(S::v('survey'));
                 $errors = $survey->checkSyntax();
                 if (!is_null($errors)) {
-                    $this->show_error($page, "", 'edit', $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&#233;es &#224; ce sondage", 'edit', array('action' => 'valid'));
@@ -327,16 +339,21 @@ class SurveyModule extends PLModule
             } // }}}
         } 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, still this should be considered again,
-                    $this->clear_session();             // maybe some name with "admin" in it, "survey_adminid" or anything that might not be confusing.
-                    return $this->handler_admin($page); // in this case, shows the admin index
+                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&#233;es ont &#233;t&#233; annul&#233;es", 'admin/validate');
+                    } else { // else shows the admin index
+                        $this->clear_session();
+                        return $this->handler_admin($page);
+                    }
                 } else {
-                    $this->clear_session();             // cleans session
+                    $this->clear_session();
                     return $this->handler_index($page); // else shows the 'normal' index
                 }
             } else { // asks for a confirmation if it has not been sent
                 $this->show_confirm(&$page, "&#202;tes-vous certain de vouloir annuler totalement l'&#233;dition de ce sondage ? Attention, "
-                                           ."toutes les donn&#233;es &#233;dit&#233;es jusque l&#226; seront d&#233;finitivement perdues.",
+                                           ."toutes les donn&#233;es &#233;dit&#233;es jusque l&#224; seront d&#233;finitivement perdues.",
                                                 'edit', array('action' => $action));
             }
         } // }}}
@@ -361,16 +378,20 @@ class SurveyModule extends PLModule
     {
         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)
+    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;
+        }
     }
     // }}}
 
@@ -385,7 +406,7 @@ class SurveyModule extends PLModule
                 $platal->force_login($page);
             }
             if (!$survey->checkPromo(S::v('promo'))) { // checks promotion
-                $this->show_error($page, "Tu n'as pas acc&#232;s &#224; ce sondage car il est r&#233;serv&#233; &#224; d'autres promotions.");
+                $this->show_error($page, "Tu n'as pas acc&#232;s &#224; ce sondage car il est r&#233;serv&#233; &#224; d'autres promotions.", 'survey');
                 return false;
             }
         }
@@ -437,7 +458,7 @@ class SurveyModule extends PLModule
     {
         $page->changeTpl('survey/error.tpl');
         $page->assign('survey_message', $message);
-        $page->assign('survey_link', './survey/'.$link); // 'return' link to let the user leave the page
+        $page->assign('survey_link', $link); // 'return' link to let the user leave the page
         if (!is_null($errArray)) {
             $page->assign('survey_errors', $errArray);
         }
@@ -449,7 +470,7 @@ class SurveyModule extends PLModule
     {
         $page->changeTpl('survey/success.tpl');
         $page->assign('survey_message', $message);
-        $page->assign('survey_link', './survey/'.$link); // 'return' link to let the user leave the page
+        $page->assign('survey_link', $link); // 'return' link to let the user leave the page
     }
     // }}}
 }
index ff4fab6..02ccef6 100644 (file)
@@ -323,17 +323,13 @@ class Survey
     public static function retrieveList($type, $tpl = true)
     {
         switch ($type) {
-        case 'w':
-        case 'waiting' :
-            $where = 'valid=0';
-            break;
         case 'c':
         case 'current':
-            $where = 'valid=1 AND end > NOW()';
+            $where = 'end > NOW()';
             break;
         case 'o':
         case 'old':
-            $where = 'valid=1 AND end <= NOW()';
+            $where = 'end <= NOW()';
             break;
         default:
             return null;
@@ -352,7 +348,7 @@ class Survey
     // {{{ 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, valid
+        $sql = 'SELECT questions, title, description, end, mode, promos
                   FROM survey_surveys
                  WHERE id={?}';
         $res = XDB::query($sql, $sid);
@@ -360,7 +356,7 @@ class Survey
         if (is_null($data) || !is_array($data)) {
             return null;
         }
-        $survey = new Survey($data, $sid, (boolean) $data['valid'], unserialize($data['questions']));
+        $survey = new Survey($data, $sid, true, unserialize($data['questions']));
         return $survey;
     }
     // }}}
@@ -368,7 +364,7 @@ class Survey
     // {{{ 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)
     {
-        $sql = 'SELECT title, description, end, mode, promos, valid
+        $sql = 'SELECT title, description, end, mode, promos
                   FROM survey_surveys
                  WHERE id={?}';
         $res = XDB::query($sql, $sid);
@@ -376,47 +372,54 @@ class Survey
     }
     // }}}
 
+    // {{{ static function retrieveSurveyReq() : gets a survey request to validate
+    public static function retrieveSurveyReq($id)
+    {
+        require_once 'validations.inc.php';
+        $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;
+    }
+    // }}}
+
     // {{{ function proposeSurvey() : stores a proposition of survey in database (before validation)
     public function proposeSurvey()
     {
-        $sql = 'INSERT INTO survey_surveys
-                        SET questions={?},
-                            title={?},
-                            description={?},
-                            author_id={?},
-                            end={?},
-                            mode={?},
-                            promos={?},
-                            valid=0;';
-        return XDB::execute($sql, serialize($this->questions), $this->title, $this->description, S::v('uid'), $this->end, $this->mode, $this->promos);
+        require_once 'validations.inc.php';
+        $surveyreq = new SurveyReq($this->title, $this->description, $this->end, $this->mode, $this->promos, $this->questions, S::v('uid'));
+        return $surveyreq->submit();
     }
     // }}}
 
     // {{{ function updateSurvey() : updates a survey in database (before validation)
     public function updateSurvey()
     {
-        if ($this->id == -1) {
-            return false;
+        if ($this->valid) {
+            $sql = 'UPDATE survey_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 {
+            require_once 'validations.inc.php';
+            $surveyreq = Validate::get_request_by_id($this->id);
+            if ($surveyreq == null) {
+                return false;
+            }
+            return $surveyreq->updateReq($this->title, $this->description, $this->end, $this->mode, $this->promos, $this->questions);
         }
-        $sql = 'UPDATE survey_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);
-    }
-    // }}}
-
-    // {{{ static function validateSurvey() : validates a survey
-    public static function validateSurvey($sid)
-    {
-        $sql = 'UPDATE survey_surveys
-                   SET valid=1
-                 WHERE id={?};';
-        return XDB::execute($sql, $sid);
     }
     // }}}
 
diff --git a/templates/include/form.valid.surveys.tpl b/templates/include/form.valid.surveys.tpl
new file mode 100644 (file)
index 0000000..203ce3e
--- /dev/null
@@ -0,0 +1,37 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 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 class="pair">
+  <td class="titre">Titre</td>
+  <td>{$valid->title}</td>
+</tr>
+<tr class="pair">
+  <td class="titre">Description</td>
+  <td>{$valid->description}</td>
+</tr>
+<tr class="impair">
+  <td class="titre">Admin</td>
+  <td><a href="survey/admin/edit/req/{$valid->id()}">Voir / &#201;diter le sondage complet</a></td>
+</tr>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index e1c129a..3845c95 100644 (file)
 <table class="bicol">
   <tr>
     <th>
-      Sondages en attente de validation
-    </th>
-  </tr>
-  {iterate item=s from=$survey_waiting}
-  <tr class="{cycle name=ws_cycle values="impair,pair"}">
-    <td class="half">
-      &bull;
-      <a href="survey/admin/{$s.id}">
-        {$s.title} [{$s.end|date_format:"%x"} - {$survey_modes[$s.mode]}]
-      </a>
-    </td>
-  </tr>
-  {assign var="has_ws" value="true"}
-  {/iterate}
-  {if !$has_ws}
-  <tr>
-    <td class="half">Aucun sondage en attente de validation</td>
-  </tr>
-  {/if}
-</table>
-
-<br />
-
-<table class="bicol">
-  <tr>
-    <th>
       Sondages en cours
     </th>
   </tr>
index b118916..2e0927c 100644 (file)
@@ -17,7 +17,6 @@ CREATE TABLE `survey_surveys` (
   `end` date NOT NULL default '0000-00-00',
   `mode` tinyint(2) unsigned NOT NULL default '0',
   `promos` varchar(255) NOT NULL,
-  `valid` tinyint(1) unsigned NOT NULL default '0',
   PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
@@ -30,4 +29,7 @@ CREATE TABLE `survey_votes` (
   KEY `voter` (`survey_id`,`user_id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
+
+ALTER TABLE `requests_answers` MODIFY `category` enum('alias','liste','usage','photo','evts','marketing','orange','homonyme','nl','paiements','medal','broken','surveys') NOT NULL default 'alias';
+
 # vim: set syntax=mysql: