Backport
[platal.git] / include / validations.inc.php
index 1edb05c..6af52e8 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-// {{{ DEFINES
-
 define('SIZE_MAX', 32768);
 
-// }}}
-// {{{ class ValidateIterator
+__autoload('XDB');
 
 /**
  * Iterator class, that lists objects through the database
@@ -32,10 +29,10 @@ define('SIZE_MAX', 32768);
 class ValidateIterator extends XOrgDBIterator
 {
     // {{{ constuctor
-    
+
     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);
     }
 
     // }}}
@@ -55,9 +52,6 @@ class ValidateIterator extends XOrgDBIterator
     // }}}
 }
 
-// }}}
-// {{{ class Validate
-
 /** classe "virtuelle" à dériver pour chaque nouvelle implémentation
  */
 class Validate
@@ -75,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
@@ -164,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::get('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;
@@ -174,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::get('comm')."\n\n"
-              . "cf la discussion sur : ".$globals->baseurl."/admin/valider.php";
+              . Env::v('comm')."\n\n"
+              . "cf la discussion sur : ".$globals->baseurl."/admin/validate";
 
             $mailer->setTxtBody(wordwrap($body));
             $mailer->send();
@@ -202,7 +213,7 @@ class Validate
         }
 
         if (Env::has('refuse')) {
-            if (Env::get('comm')) {
+            if (Env::v('comm')) {
                 $this->sendmail(false);
                 $this->clean();
                 $this->trig('mail envoyé');
@@ -230,7 +241,7 @@ class Validate
 
         $body = "Cher(e) camarade,\n\n"
               . $this->_mail_body($isok)
-              . (Env::has('comm') ? "\n\n".Env::get('comm') : '')
+              . (Env::has('comm') ? "\n\n".Env::v('comm') : '')
               . "\n\nCordialement,\nL'équipe Polytechnique.org\n";
 
         $mailer->setTxtBody(wordwrap($body));
@@ -302,16 +313,39 @@ class Validate
     { return null; }
 
     // }}}
-}
+    // {{{ function editor()
 
-// }}}
-// {{{ IMPLEMENTATIONS
+    /** 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) {
     require_once($file);
 }
 
-// }}}
-
 /* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 foldmethod=marker: */
 ?>