$page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com');
}
- // Misc checks
- // TODO: Block if birth date is missing ?
-
+ // Build the page
$page->addJsLink('ajax.js');
$page->addJsLink('profile.js');
$page->addJsLink('applis.js');
$wiz->addPage('ProfileMentor', 'Mentoring', 'mentor');
$wiz->apply($page, 'profile/edit', $opened_tab, $mode);
- $page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
+ // Misc checks
+ $res = XDB::query("SELECT user_id
+ FROM auth_user_md5
+ WHERE user_id = {?} AND naissance = '0000-00-00'", S::i('uid'));
+ if ($res->numRows()) {
+ $page->trig("Ta date de naissance n'est pas renseignée, ce qui t'empêcheras de réaliser"
+ . " la procédure de récupération de mot de passe si un jour tu le perdais");
+ }
+
+ $page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
}
function handler_applis_js(&$page)
parent::__construct($wiz);
$this->settings['nom'] = $this->settings['prenom']
= new ProfileNom();
+ $this->settings['naissance'] = new ProfileDate();
$this->settings['mobile_pub']
= $this->settings['web_pub']
= $this->settings['freetext_pub']
protected function _fetchData()
{
// Checkout all data...
- $res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite,
+ $res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite, u.naissance,
q.profile_mobile as mobile, q.profile_mobile_pub as mobile_pub,
q.profile_web as web, q.profile_web_pub as web_pub,
q.profile_freetext as freetext, q.profile_freetext_pub as freetext_pub,
protected function _saveData()
{
- if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom']) {
+ if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom']
+ || $this->changed['naissance']) {
XDB::execute("UPDATE auth_user_md5
- SET nationalite = {?}, nom={?}, prenom={?}
+ SET nationalite = {?}, nom={?}, prenom={?}, naissance={?}
WHERE user_id = {?}",
- $this->values['nationalite'], $this->values['nom'], $this->values['prenom'], S::v('uid'));
+ $this->values['nationalite'], $this->values['nom'], $this->values['prenom'],
+ preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['naissance']),
+ S::v('uid'));
}
if ($this->changed['nick'] || $this->changed['mobile'] || $this->changed['mobile_pub']
|| $this->changed['web'] || $this->changed['web_pub'] || $this->changed['freetext']
}
}
+class ProfileDate extends ProfileNoSave
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ $value = preg_replace('/(\d{4})-(\d{2})-(\d{2})/', '\3/\2/\1', @$page->values[$field]);
+ } else {
+ $success = preg_match('@(\d{2})/(\d{2})/(\d{4})@', $value, $matches);
+ if (!$success) {
+ global $page;
+ $page->trig("Les dates doivent être au format jj/mm/aaaa");
+ } else {
+ $day = (int)$matches[1];
+ $month = (int)$matches[2];
+ $year = (int)$matches[3];
+ $success = ($day > 0 && $day <= 31) && ($month > 0 && $month <= 12) && ($year > 1900 && $year <= 2020);
+ if (!$success) {
+ global $page;
+ $page->trig("La date n'a pas une valeur valide");
+ }
+ }
+ }
+ return $value;
+ }
+}
+
abstract class ProfileGeoloc implements ProfileSetting
{
protected function geolocAddress(array &$address, &$success)