X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations.inc.php;h=b00fef36175a05380524b14dcd72592ef915a2ab;hb=315fa6ae2cbee21fec0ad56bda592a184860737a;hp=1edb05c53f89b893af53f5661dc76a2b4016ae13;hpb=cab0809050d58f8484608e91f7555ebd69dcb451;p=platal.git diff --git a/include/validations.inc.php b/include/validations.inc.php index 1edb05c..b00fef3 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -1,6 +1,6 @@ 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(); } // }}} @@ -164,22 +160,40 @@ 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; + } + } + if (!strlen(trim(Env::v('comm')))) { + return true; + } + $this->comments[] = Array(S::v('bestalias'), Env::v('comm'), $formid); // envoi d'un mail à hotliners global $globals; - require_once('diogenes/diogenes.hermes.inc.php'); - $mailer = new HermesMailer; + $mailer = new PlMailer; $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 +216,7 @@ class Validate } if (Env::has('refuse')) { - if (Env::get('comm')) { + if (Env::v('comm')) { $this->sendmail(false); $this->clean(); $this->trig('mail envoyé'); @@ -221,16 +235,15 @@ class Validate function sendmail($isok) { global $globals; - require_once('diogenes/diogenes.hermes.inc.php'); - $mailer = new HermesMailer; + $mailer = new PlMailer(); $mailer->setSubject($this->_mail_subj()); $mailer->setFrom("validation+{$this->type}@{$globals->mail->domain}"); $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)); @@ -246,7 +259,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é @@ -254,9 +267,9 @@ 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) { if ($stamp == -1) { $res = XDB::query('SELECT data FROM requests WHERE user_id={?} and type={?}', $uid, $type); @@ -272,6 +285,21 @@ class Validate } // }}} + // {{{ function get_typed_requests() + + /** same as get_typed_request() but return an array of objects + */ + static function get_typed_requests($uid, $type) + { + $res = XDB::iterRow('SELECT data FROM requests WHERE user_id={?} and type={?}', $uid, $type); + $array = array(); + while (list($data) = $res->next()) { + $array[] = unserialize($data); + } + return $array; + } + + // }}} // {{{ function _mail_body function _mail_body($isok) @@ -302,16 +330,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: */ ?>