X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations.inc.php;h=bc88ddffc2635f9b4cab855004d75550a7557e1a;hb=69b7b6e9d2c1ab2a698257bd7882333c5b9c0b81;hp=45229e764ef50d35f7243bd51089bfe1dfa4d33d;hpb=08cce2ff528b38bde27cdec6d6bc28d6af4a42d4;p=platal.git diff --git a/include/validations.inc.php b/include/validations.inc.php index 45229e7..bc88ddf 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -19,12 +19,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -// {{{ DEFINES - define('SIZE_MAX', 32768); -// }}} -// {{{ class ValidateIterator +require_once dirname(__FILE__) . '/../classes/xdb.php'; /** * 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 @@ -68,6 +62,7 @@ class Validate var $prenom; var $nom; var $promo; + var $sexe; var $bestalias; var $forlife; @@ -75,6 +70,7 @@ class Validate var $unique; // enable the refuse button var $refuse = true; + var $type; var $comments = Array(); // the validations rules : comments for admins @@ -90,18 +86,17 @@ class Validate */ function Validate($_uid, $_unique, $_type) { - global $globals; $this->uid = $_uid; $this->stamp = date('YmdHis'); $this->unique = $_unique; $this->type = $_type; $res = XDB::query( - "SELECT u.prenom, u.nom, u.promo, a.alias, b.alias + "SELECT u.prenom, u.nom, u.promo, FIND_IN_SET('femme', u.flags) AS sexe, a.alias, b.alias FROM auth_user_md5 AS u INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' ) INNER JOIN aliases AS b ON ( u.user_id=b.id AND b.type!='homonyme' AND FIND_IN_SET('bestalias', b.flags) ) WHERE u.user_id={?}", $_uid); - list($this->prenom, $this->nom, $this->promo, $this->forlife, $this->bestalias) = $res->fetchOneRow(); + list($this->prenom, $this->nom, $this->promo, $this->sexe, $this->forlife, $this->bestalias) = $res->fetchOneRow(); } // }}} @@ -112,7 +107,6 @@ class Validate */ function submit () { - global $globals; if ($this->unique) { XDB::execute('DELETE FROM requests WHERE user_id={?} AND type={?}', $this->uid, $this->type); } @@ -129,7 +123,6 @@ class Validate function update () { - global $globals; XDB::execute('UPDATE requests SET data={?}, stamp=stamp WHERE user_id={?} AND type={?} AND stamp={?}', $this, $this->uid, $this->type, $this->stamp); @@ -145,7 +138,6 @@ class Validate */ function clean () { - global $globals; if ($this->unique) { return XDB::execute('DELETE FROM requests WHERE user_id={?} AND type={?}', $this->uid, $this->type); @@ -168,9 +160,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(Session::get('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; @@ -178,12 +186,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" - . Session::get('bestalias')." a ajouté le commentaire :\n\n" - . Env::get('comm')."\n\n" - . "cf la discussion sur : ".$globals->baseurl."/admin/valider.php"; + . S::v('bestalias')." a ajouté le commentaire :\n\n" + . Env::v('comm')."\n\n" + . "cf la discussion sur : ".$globals->baseurl."/admin/validate"; $mailer->setTxtBody(wordwrap($body)); $mailer->send(); @@ -206,7 +214,7 @@ class Validate } if (Env::has('refuse')) { - if (Env::get('comm')) { + if (Env::v('comm')) { $this->sendmail(false); $this->clean(); $this->trig('mail envoyé'); @@ -232,9 +240,9 @@ class Validate $mailer->addTo("\"{$this->prenom} {$this->nom}\" <{$this->bestalias}@{$globals->mail->domain}>"); $mailer->addCc("validation+{$this->type}@{$globals->mail->domain}"); - $body = "Cher(e) camarade,\n\n" + $body = ($this->sexe ? "Chère camarade,\n\n" : "Cher 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)); @@ -250,7 +258,7 @@ class Validate } // }}} - // {{{ function get_request() + // {{{ function get_typed_request() /** fonction statique qui renvoie la requête de l'utilisateur d'id $uidau timestamp $t * @param $uid l'id de l'utilisateur concerné @@ -258,11 +266,10 @@ class Validate * @param $stamp le timestamp de la requête * * XXX fonction "statique" XXX - * à utiliser uniquement pour récupérer un objet dans la BD avec Validate::get_request(...) + * à utiliser uniquement pour récupérer un objet dans la BD avec Validate::get_typed_request(...) */ - function get_request($uid, $type, $stamp = -1) + static function get_typed_request($uid, $type, $stamp = -1) { - global $globals; if ($stamp == -1) { $res = XDB::query('SELECT data FROM requests WHERE user_id={?} and type={?}', $uid, $type); } else { @@ -307,16 +314,39 @@ 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]; + } -// }}} -// {{{ IMPLEMENTATIONS + // }}} + // {{{ 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: */ ?>