X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations.inc.php;h=4415ebc5b0d0ae6934de673c39621403cb84342b;hb=5af85e819a8602f6720dff9e2efa6aa02d257d48;hp=60cceff4c4e76405446c42ef11b0433bbce438ee;hpb=50a40a33a496131e817df875607ea5542d096a64;p=platal.git diff --git a/include/validations.inc.php b/include/validations.inc.php index 60cceff..4415ebc 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -19,20 +19,15 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -// {{{ DEFINES - define('SIZE_MAX', 32768); -// }}} -// {{{ class ValidateIterator - /** * Iterator class, that lists objects through the database */ class ValidateIterator extends XOrgDBIterator { // {{{ constuctor - + function ValidateIterator () { parent::XOrgDBIterator('SELECT data,stamp FROM requests ORDER BY stamp', MYSQL_NUM); @@ -55,9 +50,6 @@ class ValidateIterator extends XOrgDBIterator // }}} } -// }}} -// {{{ class Validate - /** classe "virtuelle" à dériver pour chaque nouvelle implémentation */ class Validate @@ -75,6 +67,7 @@ class Validate var $unique; // enable the refuse button var $refuse = true; + var $type; var $comments = Array(); // the validations rules : comments for admins @@ -90,12 +83,11 @@ class Validate */ function Validate($_uid, $_unique, $_type) { - global $globals; $this->uid = $_uid; $this->stamp = date('YmdHis'); $this->unique = $_unique; $this->type = $_type; - $res = $globals->xdb->query( + $res = XDB::query( "SELECT u.prenom, u.nom, u.promo, 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' ) @@ -112,13 +104,12 @@ class Validate */ function submit () { - global $globals; if ($this->unique) { - $globals->xdb->execute('DELETE FROM requests WHERE user_id={?} AND type={?}', $this->uid, $this->type); + XDB::execute('DELETE FROM requests WHERE user_id={?} AND type={?}', $this->uid, $this->type); } $this->stamp = date('YmdHis'); - $globals->xdb->execute('INSERT INTO requests (user_id, type, data, stamp) VALUES ({?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO requests (user_id, type, data, stamp) VALUES ({?}, {?}, {?}, {?})', $this->uid, $this->type, $this, $this->stamp); return true; @@ -129,8 +120,7 @@ class Validate function update () { - global $globals; - $globals->xdb->execute('UPDATE requests SET data={?}, stamp=stamp + XDB::execute('UPDATE requests SET data={?}, stamp=stamp WHERE user_id={?} AND type={?} AND stamp={?}', $this, $this->uid, $this->type, $this->stamp); @@ -145,12 +135,11 @@ class Validate */ function clean () { - global $globals; if ($this->unique) { - return $globals->xdb->execute('DELETE FROM requests WHERE user_id={?} AND type={?}', + return XDB::execute('DELETE FROM requests WHERE user_id={?} AND type={?}', $this->uid, $this->type); } else { - return $globals->xdb->execute('DELETE FROM requests WHERE user_id={?} AND type={?} AND stamp={?}', + return XDB::execute('DELETE FROM requests WHERE user_id={?} AND type={?} AND stamp={?}', $this->uid, $this->type, $this->stamp); } } @@ -168,9 +157,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 +183,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 +211,7 @@ class Validate } if (Env::has('refuse')) { - if (Env::get('comm')) { + if (Env::v('comm')) { $this->sendmail(false); $this->clean(); $this->trig('mail envoyé'); @@ -234,7 +239,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)); @@ -262,11 +267,10 @@ class Validate */ function get_request($uid, $type, $stamp = -1) { - global $globals; if ($stamp == -1) { - $res = $globals->xdb->query('SELECT data FROM requests WHERE user_id={?} and type={?}', $uid, $type); + $res = XDB::query('SELECT data FROM requests WHERE user_id={?} and type={?}', $uid, $type); } else { - $res = $globals->xdb->query("SELECT data, stamp FROM requests WHERE user_id={?} AND type={?} and stamp={?}", $uid, $type, $stamp); + $res = XDB::query("SELECT data, stamp FROM requests WHERE user_id={?} AND type={?} and stamp={?}", $uid, $type, $stamp); } if ($result = $res->fetchOneCell()) { $result = unserialize($result); @@ -307,16 +311,31 @@ 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]; + } + + // }}} +} foreach (glob(dirname(__FILE__).'/validations/*.inc.php') as $file) { require_once($file); } -// }}} - /* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 foldmethod=marker: */ ?>