Backport
[platal.git] / include / validations.inc.php
index dc97259..6af52e8 100644 (file)
@@ -21,6 +21,8 @@
 
 define('SIZE_MAX', 32768);
 
+__autoload('XDB');
+
 /**
  * Iterator class, that lists objects through the database
  */
@@ -30,7 +32,7 @@ class ValidateIterator extends XOrgDBIterator
 
     function ValidateIterator ()
     {
-        parent::XOrgDBIterator('SELECT data,stamp FROM requests ORDER BY stamp', MYSQL_NUM);
+        parent::__construct('SELECT data,stamp FROM requests ORDER BY stamp', MYSQL_NUM);
     }
 
     // }}}
@@ -67,6 +69,7 @@ class Validate
     var $unique;
     // enable the refuse button
     var $refuse = true;
+    
     var $type;
     var $comments = Array();
     // the validations rules : comments for admins
@@ -156,9 +159,25 @@ class Validate
             return true;
         }
 
+        // mise à jour des informations
+        if (Env::has('edit')) {
+            if ($this->handle_editor()) {
+                $this->update();
+                $this->trig('requête mise à jour');
+                return true;
+            }
+            return false;
+        }
+
         // ajout d'un commentaire
         if (Env::has('hold') && Env::has('comm')) {
-            $this->comments[] = Array(S::v('bestalias'), Env::v('comm'));
+            $formid = Env::i('formid');
+            foreach ($this->comments as $comment) {
+                if ($comment[2] === $formid) {
+                    return true;
+                }
+            }
+            $this->comments[] = Array(S::v('bestalias'), Env::v('comm'), $formid);
 
             // envoi d'un mail à hotliners
             global $globals;
@@ -166,12 +185,12 @@ class Validate
             $mailer = new HermesMailer;
             $mailer->setSubject("Commentaires de validation {$this->type}");
             $mailer->setFrom("validation+{$this->type}@{$globals->mail->domain}");
-            $mailer->addTo("hotliners@{$globals->mail->domain}");
+            $mailer->addTo("hotliners@staff.polytechnique.org");
 
             $body = "Validation {$this->type} pour {$this->prenom} {$this->nom}\n\n"
               . S::v('bestalias')." a ajouté le commentaire :\n\n" 
               . Env::v('comm')."\n\n"
-              . "cf la discussion sur : ".$globals->baseurl."/admin/valider.php";
+              . "cf la discussion sur : ".$globals->baseurl."/admin/validate";
 
             $mailer->setTxtBody(wordwrap($body));
             $mailer->send();
@@ -294,6 +313,34 @@ class Validate
     { return null; }
 
     // }}}
+    // {{{ function editor()
+
+    /** nom du formulaire d'édition */
+    function editor()
+    { return null; }
+
+    // }}}
+    // {{{ function answers()
+
+    /** automatic answers table for this type of validation */
+    function answers() {
+        static $answers_table;
+        if (!isset($answers_table[$this->type])) {
+            $r = XDB::query("SELECT id, title, answer FROM requests_answers WHERE category = {?}", $this->type);
+            $answers_table[$this->type] = $r->fetchAllAssoc($r);
+        }
+        return $answers_table[$this->type];
+    }
+
+    // }}}
+    // {{{ function id()
+
+    function id()
+    {
+        return $this->uid . '_' . $this->type . '_' . $this->stamp;
+    }
+
+    // }}}
 }
 
 foreach (glob(dirname(__FILE__).'/validations/*.inc.php') as $file) {