X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations.inc.php;h=085fffc5a83a8a25d983056a554497f871bd8528;hb=95c97c1e96e999a8e6792854bed8f1b6660cb3b4;hp=2f11046c701ce680f34d7c30cccfc92b06e5da50;hpb=d4775fe2dea4db5e6ca3db4a6034bb03a8b711cc;p=platal.git diff --git a/include/validations.inc.php b/include/validations.inc.php index 2f11046..085fffc 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -1,6 +1,6 @@ stamp = $stamp; return($result); } else { @@ -59,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; @@ -81,23 +75,16 @@ 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(); } // }}} @@ -109,12 +96,12 @@ 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; $globals->updateNbValid(); @@ -128,7 +115,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; } @@ -140,12 +127,14 @@ 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); } $globals->updateNbValid(); return $success; @@ -185,7 +174,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; @@ -194,10 +183,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(); @@ -242,10 +231,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"; @@ -291,7 +280,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; } @@ -317,7 +306,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; } @@ -384,7 +373,7 @@ abstract class Validate public function id() { - return $this->uid . '_' . $this->type . '_' . $this->stamp; + return $this->user->id() . '_' . $this->type . '_' . $this->stamp; } // }}} @@ -396,6 +385,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) {