X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fpage.inc.php;h=77cd2b7e91c4589442ce66116274f700f54d2e28;hb=e5bcd851d41fb3d177bdf48c6d6be57eb6a57441;hp=433947e8b31e08ae9588b415fe925cebc9b7cfed;hpb=f70f2bcdc077c220e40ecebaf569e097f6028743;p=platal.git diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 433947e..77cd2b7 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -76,6 +76,22 @@ class ProfileEmail extends ProfileNoSave } } +class ProfileNumber extends ProfileNoSave +{ + public function value(ProfilePage &$page, $field, $value, &$success) + { + if (is_null($value)) { + return isset($page->values[$field]) ? $page->values[$field] : S::v($field); + } + $value = trim($value); + $success = empty($value) || is_numeric($value); + if (!$success) { + Platal::page()->trigError('Numéro invalide'); + } + return $value; + } +} + class ProfileTel extends ProfileNoSave { @@ -84,12 +100,98 @@ class ProfileTel extends ProfileNoSave if (is_null($value)) { return isset($page->values[$field]) ? $page->values[$field] : S::v($field); } - $success = !preg_match('/[<>{}@&#~\/:;?,!§*_`\[\]|%$^=]/', $value, $matches); + require_once('profil.func.inc.php'); + $value = format_phone_number($value); + if($value == '') { + $success = true; + return $value; + } + $value = format_display_number($value,$error); + $success = !$error; if (!$success) { - Platal::page()->trigError('Le numéro de téléphone contient un caractère interdit : ' . pl_entities($matches[0][0])); + Platal::page()->trigError('Le préfixe international du numéro de téléphone est inconnu. '); + } + return $value; + } +} + +class ProfilePhones implements ProfileSetting +{ + private $tel; + private $pub; + protected $link_type; + protected $link_id; + + public function __construct($type, $link_id) + { + $this->tel = new ProfileTel(); + $this->pub = new ProfilePub(); + $this->link_type = $type; + $this->link_id = $link_id; + } + + public function value(ProfilePage &$page, $field, $value, &$success) + { + $success = true; + if (is_null($value) || !is_array($value)) { + $value = array(); + $res = XDB::iterator("SELECT t.display_tel AS tel, t.tel_type AS type, t.pub, t.comment + FROM profile_phones AS t + WHERE t.uid = {?} AND t.link_type = {?} + ORDER BY t.tel_id", + $page->pid(), $this->link_type); + $value = $res->fetchAllAssoc(); + } + foreach ($value as $key=>&$phone) { + if (@$phone['removed']) { + unset($value[$key]); + } else { + unset($phone['removed']); + $phone['pub'] = $this->pub->value($page, 'pub', $phone['pub'], $s); + $phone['tel'] = $this->tel->value($page, 'tel', $phone['tel'], $s); + if(!isset($phone['type']) || ($phone['type'] != 'fixed' && $phone['type'] != 'mobile' && $phone['type'] != 'fax')) { + $phone['type'] = 'fixed'; + $s = false; + } + if (!$s) { + $phone['error'] = true; + $success = false; + } + if (!isset($phone['comment'])) { + $phone['comment'] = ''; + } + } } return $value; } + + private function saveTel($pid, $telid, array &$phone) + { + if ($phone['tel'] != '') { + XDB::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type, + search_tel, display_tel, pub, comment) + VALUES ({?}, {?}, {?}, {?}, {?}, + {?}, {?}, {?}, {?})", + $pid, $this->link_type, $this->link_id, $telid, $phone['type'], + format_phone_number($phone['tel']), $phone['tel'], $phone['pub'], $phone['comment']); + } + } + + public function save(ProfilePage &$page, $field, $value) + { + XDB::execute("DELETE FROM profile_phones + WHERE uid = {?} AND link_type = {?} AND link_id = {?}", + $page->pid(), $this->link_type, $this->link_id); + $this->saveTels($page->pid(), $field, $value); + } + + //Only saves phones without a delete operation + public function saveTels($pid, $field, $value) + { + foreach ($value as $telid=>&$phone) { + $this->saveTel($pid, $telid, $phone); + } + } } class ProfilePub extends ProfileNoSave @@ -199,10 +301,14 @@ abstract class ProfilePage implements PlWizardPage public $orig = array(); public $values = array(); + public $profile = null; + public $owner = null; public function __construct(PlWizard &$wiz) { $this->wizard =& $wiz; + $this->profile = $this->wizard->getUserData('profile'); + $this->owner = $this->wizard->getUserData('owner'); } protected function _fetchData() @@ -241,20 +347,19 @@ abstract class ProfilePage implements PlWizardPage $setting->save($this, $field, $this->values[$field]); } if ($this->changed[$field] && @$this->watched[$field]) { - register_profile_update(S::i('uid'), $field); + register_profile_update($profile->id(), $field); } } $this->_saveData(); // Update the last modification date XDB::execute('REPLACE INTO user_changes - SET user_id = {?}', S::v('uid')); - if (!S::has('suid')) { - register_watch_op(S::i('uid'), WATCH_FICHE); + SET user_id = {?}', $profile->id()); + if (!S::suid()) { + register_watch_op($profile->id(), WATCH_FICHE); } global $platal; - $log =& $_SESSION['log']; - S::logger()->log('profil', $platal->pl_self(1)); + S::logger()->log('profil', $platal->pl_self(2)); } protected function checkChanges() @@ -284,6 +389,16 @@ abstract class ProfilePage implements PlWizardPage return 'profile/base.tpl'; } + public function pid() + { + return $this->profile->id(); + } + + public function hrpid() + { + return $this->profile->hrpid(); + } + protected function _prepare(PlPage &$page, $id) { } @@ -297,6 +412,8 @@ abstract class ProfilePage implements PlWizardPage $page->assign($field, $value); } $this->_prepare($page, $id); + $page->assign('profile', $this->profile); + $page->assign('owner', $this->owner); $page->assign('profile_page', $this->pg_template); $page->assign('errors', $this->errors); }