X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fpage.inc.php;h=02f33168d30402d33290ca0518a91a56b59364ec;hb=285e2fe72d086ae94fc95696a0cefc8755113277;hp=651bb389f1a29ed8ee6658f190e619f5974b5d47;hpb=7f7b00425f9cb2dc2a611cd1ca985813893d5bfe;p=platal.git diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 651bb38..02f3316 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -1,6 +1,6 @@ values[$field]) ? $page->values[$field] : S::v($field); @@ -70,7 +70,7 @@ class ProfileSettingWeb extends ProfileNoSave class ProfileSettingEmail extends ProfileNoSave { - public function value(ProfilePage &$page, $field, $value, &$success) + public function value(ProfilePage $page, $field, $value, &$success) { if (is_null($value)) { return isset($page->values[$field]) ? $page->values[$field] : S::v($field); @@ -86,7 +86,7 @@ class ProfileSettingEmail extends ProfileNoSave class ProfileSettingNumber extends ProfileNoSave { - public function value(ProfilePage &$page, $field, $value, &$success) + public function value(ProfilePage $page, $field, $value, &$success) { if (is_null($value)) { return isset($page->values[$field]) ? $page->values[$field] : S::v($field); @@ -102,13 +102,13 @@ class ProfileSettingNumber extends ProfileNoSave class ProfileSettingPhones implements ProfileSetting { - public function value(ProfilePage &$page, $field, $value, &$success) + public function value(ProfilePage $page, $field, $value, &$success) { $success = true; $phones = array(); if (is_null($value)) { - $it = Phone::iterate(array($page->pid()), array(Phone::LINK_PROFILE), array(0)); + $it = Phone::iterate(array($page->pid()), array(Phone::LINK_PROFILE), array(0), Visibility::defaultForEdit()); while ($phone = $it->next()) { $success = ($phone->format() && $success); $phones[] = $phone->toFormArray(); @@ -127,9 +127,9 @@ class ProfileSettingPhones implements ProfileSetting } } - public function save(ProfilePage &$page, $field, $value) + public function save(ProfilePage $page, $field, $value) { - Phone::deletePhones($page->pid(), Phone::LINK_PROFILE); + Phone::deletePhones($page->pid(), Phone::LINK_PROFILE, null, S::user()->isMe($page->owner) || S::admin()); Phone::savePhones($value, $page->pid(), Phone::LINK_PROFILE); } @@ -141,7 +141,7 @@ class ProfileSettingPhones implements ProfileSetting class ProfileSettingPub extends ProfileNoSave { - public function value(ProfilePage &$page, $field, $value, &$success) + public function value(ProfilePage $page, $field, $value, &$success) { $success = true; if (is_null($value)) { @@ -156,13 +156,14 @@ class ProfileSettingPub extends ProfileNoSave } public function getText($value) { - return $value; + static $pubs = array('public' => 'publique', 'ax' => 'annuaire AX', 'private' => 'privé'); + return $pubs[$value]; } } class ProfileSettingBool extends ProfileNoSave { - public function value(ProfilePage &$page, $field, $value, &$success) + public function value(ProfilePage $page, $field, $value, &$success) { $success = true; if (is_null($value)) { @@ -181,7 +182,7 @@ class ProfileSettingDate extends ProfileNoSave $this->allowEmpty = $allowEmpty; } - public function value(ProfilePage &$page, $field, $value, &$success) + public function value(ProfilePage $page, $field, $value, &$success) { $success = true; if (is_null($value)) { @@ -227,7 +228,7 @@ abstract class ProfilePage implements PlWizardPage public $profile = null; public $owner = null; - public function __construct(PlWizard &$wiz) + public function __construct(PlWizard $wiz) { $this->wizard =& $wiz; $this->profile = $this->wizard->getUserData('profile'); @@ -270,13 +271,13 @@ abstract class ProfilePage implements PlWizardPage if ($this->changed[$field]) { if (!is_null($setting)) { $changedFields[$field] = array( - str_replace("\n", " - ", $setting->getText($this->orig[$field])), - str_replace("\n", " - ", $setting->getText($this->values[$field])), + preg_replace('/(\r\n|\n|\r)/', ' - ', $setting->getText($this->orig[$field])), + preg_replace('/(\r\n|\n|\r)/', ' - ', $setting->getText($this->values[$field])), ); } else { $changedFields[$field] = array( - str_replace("\n", " - ", $this->orig[$field]), - str_replace("\n", " - ", $this->values[$field]), + preg_replace('/(\r\n|\n|\r)/', ' - ', $this->orig[$field]), + preg_replace('/(\r\n|\n|\r)/', ' - ', $this->values[$field]), ); } if (!is_null($setting)) { @@ -296,18 +297,23 @@ abstract class ProfilePage implements PlWizardPage global $platal; S::logger()->log('profil', $platal->pl_self(2)); - /** If the update was made by a third party and the profile corresponds - * to a registered user, stores both former and new text. - * This will be daily sent to the user. + /** Stores all profile modifications for active users in order to: + * -daily notify the user in case of third party edition, + * -display the modification to the secretaries for verification in + * case of an edition made by the user. */ $owner = $this->profile->owner(); $user = S::user(); - if ($owner->isActive() && $owner->id() != $user->id()) { + if ($owner->isActive()) { foreach ($changedFields as $field => $values) { - XDB::execute('INSERT INTO profile_modifications (pid, uid, field, oldText, newText) - VALUES ({?}, {?}, {?}, {?}, {?}) - ON DUPLICATE KEY UPDATE oldText = VALUES(oldText), newText = VALUES(newText)', - $this->pid(), $user->id(), $field, $values[0], $values[1]); + if (in_array($field, Profile::$descriptions)) { + XDB::execute('INSERT INTO profile_modifications (pid, uid, field, oldText, newText, type, timestamp) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW()) + ON DUPLICATE KEY UPDATE uid = VALUES(uid), oldText = IF(VALUES(type) != type, VALUES(oldText), oldText), + newText = VALUES(newText), type = VALUES(type), timestamp = NOW()', + $this->pid(), $user->id(), Profile::$descriptions[$field], $values[0], $values[1], + ($owner->id() == $user->id()) ? 'self' : 'third_party'); + } } } return true; @@ -350,11 +356,11 @@ abstract class ProfilePage implements PlWizardPage return $this->profile->hrpid(); } - protected function _prepare(PlPage &$page, $id) + protected function _prepare(PlPage $page, $id) { } - public function prepare(PlPage &$page, $id) + public function prepare(PlPage $page, $id) { if (count($this->values) == 0) { $this->fetchData(); @@ -429,8 +435,8 @@ require_once dirname(__FILE__) . '/addresses.inc.php'; require_once dirname(__FILE__) . '/groups.inc.php'; require_once dirname(__FILE__) . '/decos.inc.php'; require_once dirname(__FILE__) . '/jobs.inc.php'; -require_once dirname(__FILE__) . '/skills.inc.php'; require_once dirname(__FILE__) . '/mentor.inc.php'; +require_once dirname(__FILE__) . '/deltaten.inc.php'; // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>