X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations.inc.php;h=fef4df2f294d589f0eebf20790bea61c64e22b0a;hb=9891bd15f772caef0c199a98f036e976bf4ab94a;hp=c65e15b8a6783f2250d51878a7ee955d56415df0;hpb=d7610c358d074c78e1e8dc25fe0cf0e5e7e1c55e;p=platal.git diff --git a/include/validations.inc.php b/include/validations.inc.php index c65e15b..fef4df2 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -1,6 +1,6 @@ spoolroot . '/core/classes/xdb.php'; /** * Iterator class, that lists objects through the database @@ -41,7 +42,7 @@ class ValidateIterator extends XOrgDBIterator public function next () { if (list($result, $stamp) = parent::next()) { - $result = unserialize($result); + $result = Validate::unserialize($result); $result->stamp = $stamp; return($result); } else { @@ -58,13 +59,7 @@ abstract class Validate { // {{{ properties - public $uid; - public $prenom; - public $nom; - public $promo; - public $sexe; - public $bestalias; - public $forlife; + public $user; public $stamp; public $unique; @@ -80,23 +75,20 @@ abstract class Validate // {{{ constructor /** constructeur - * @param $_uid user id + * @param $_user user object * @param $_unique requête pouvant être multiple ou non * @param $_type type de la donnée comme dans le champ type de x4dat.requests */ - public function __construct($_uid, $_unique, $_type) + public function __construct(User &$_user, $_unique, $_type) { - $this->uid = $_uid; + $this->user = &$_user; $this->stamp = date('YmdHis'); $this->unique = $_unique; $this->type = $_type; - $res = XDB::query( - "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->sexe, $this->forlife, $this->bestalias) = $res->fetchOneRow(); + $res = XDB::query("SELECT promo + FROM profile_display + WHERE pid={?}", $this->user->id()); + $this->promo = $res->fetchOneCell(); } // }}} @@ -108,15 +100,15 @@ abstract class Validate public function submit() { if ($this->unique) { - 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->user->id(), $this->type); } $this->stamp = date('YmdHis'); XDB::execute('INSERT INTO requests (user_id, type, data, stamp) VALUES ({?}, {?}, {?}, {?})', - $this->uid, $this->type, $this, $this->stamp); + $this->user->id(), $this->type, $this, $this->stamp); global $globals; - update_NbValid(); + $globals->updateNbValid(); return true; } @@ -127,7 +119,7 @@ abstract class Validate { XDB::execute('UPDATE requests SET data={?}, stamp=stamp WHERE user_id={?} AND type={?} AND stamp={?}', - $this, $this->uid, $this->type, $this->stamp); + $this, $this->user->id(), $this->type, $this->stamp); return true; } @@ -139,14 +131,16 @@ abstract class Validate */ public function clean() { + global $globals; + if ($this->unique) { $success = XDB::execute('DELETE FROM requests WHERE user_id={?} AND type={?}', - $this->uid, $this->type); + $this->user->id(), $this->type); } else { $success = XDB::execute('DELETE FROM requests WHERE user_id={?} AND type={?} AND stamp={?}', - $this->uid, $this->type, $this->stamp); + $this->user->id(), $this->type, $this->stamp); } - update_NbValid(); + $globals->updateNbValid(); return $success; } @@ -184,7 +178,7 @@ abstract class Validate if (!strlen(trim(Env::v('comm')))) { return true; } - $this->comments[] = Array(S::v('bestalias'), Env::v('comm'), $formid); + $this->comments[] = Array(S::user()->login(), Env::v('comm'), $formid); // envoi d'un mail à hotliners global $globals; @@ -193,10 +187,10 @@ abstract class Validate $mailer->setFrom("validation+{$this->type}@{$globals->mail->domain}"); $mailer->addTo($globals->core->admin_email); - $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/validate"; + $body = "Validation {$this->type} pour {$this->user->login()}\n\n" + . S::user()->login() . " 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(); @@ -210,7 +204,7 @@ abstract class Validate if ($this->commit()) { $this->sendmail(true); $this->clean(); - $this->trigSuccess('Mail de validation envoyé'); + $this->trigSuccess('Email de validation envoyé'); return true; } else { $this->trigError('Erreur lors de la validation'); @@ -222,7 +216,7 @@ abstract class Validate if (Env::v('comm')) { $this->sendmail(false); $this->clean(); - $this->trigSuccess('Mail de refus envoyé'); + $this->trigSuccess('Email de refus envoyé'); return true; } else { $this->trigError('pas de motivation pour le refus !!!'); @@ -241,10 +235,10 @@ abstract class Validate $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->addTo("\"{$this->user->fullName()}\" <{$this->user->bestEmail()}>"); $mailer->addCc("validation+{$this->type}@{$globals->mail->domain}"); - $body = ($this->sexe ? "Chère camarade,\n\n" : "Cher camarade,\n\n") + $body = ($this->user->isFemale() ? "Chère camarade,\n\n" : "Cher camarade,\n\n") . $this->_mail_body($isok) . (Env::has('comm') ? "\n\n".Env::v('comm') : '') . "\n\nCordialement,\n\n-- \nL'équipe de Polytechnique.org\n"; @@ -290,7 +284,7 @@ abstract class Validate $res = XDB::query('SELECT data, DATE_FORMAT(stamp, "%Y%m%d%H%i%s") FROM requests WHERE user_id={?} AND type={?} and stamp={?}', $uid, $type, $stamp); } if ($result = $res->fetchOneCell()) { - $result = unserialize($result); + $result = Validate::unserialize($result); } else { $result = false; } @@ -316,7 +310,7 @@ abstract class Validate $res = XDB::iterRow('SELECT data FROM requests WHERE user_id={?} and type={?}', $uid, $type); $array = array(); while (list($data) = $res->next()) { - $array[] = unserialize($data); + $array[] = Validate::unserialize($data); } return $array; } @@ -383,7 +377,7 @@ abstract class Validate public function id() { - return $this->uid . '_' . $this->type . '_' . $this->stamp; + return $this->user->id() . '_' . $this->type . '_' . $this->stamp; } // }}} @@ -395,6 +389,17 @@ abstract class Validate } // }}} + // {{{ function unserialize() + public static function unserialize($data) + { + $obj = unserialize($data); + /* XXX: Temporary for hruid migration */ + if (!isset($obj->user) || !is_object($obj)) { + $obj->user =& User::get($obj->forlife); + } + /* XXX: End temporary block */ + return $obj; + } } foreach (glob(dirname(__FILE__).'/validations/*.inc.php') as $file) {