From: Stéphane Jacob Date: Wed, 8 Dec 2010 12:15:46 +0000 (+0100) Subject: Prevents profile's subitems to be more public than the item they belong to (server... X-Git-Tag: xorg/1.0.2~95 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=93a45366f5f4b134ec7a6cf9c2c47be36c824187;p=platal.git Prevents profile's subitems to be more public than the item they belong to (server side). Signed-off-by: Stéphane Jacob --- diff --git a/classes/address.php b/classes/address.php index 88a97aa..92752d5 100644 --- a/classes/address.php +++ b/classes/address.php @@ -588,7 +588,7 @@ class Address $this->countryId = null; } $this->geocodeChosen = null; - $this->phones = Phone::formatFormArray($this->phones, $this->error); + $this->phones = Phone::formatFormArray($this->phones, $this->error, $this->pub); if ($format['postalText']) { $this->formatPostalAddress(); } diff --git a/classes/phone.php b/classes/phone.php index e8aad78..95a72ad 100644 --- a/classes/phone.php +++ b/classes/phone.php @@ -349,27 +349,39 @@ class Phone } } - static private function formArrayWalk(array $data, $function, &$success = true, $requiresEmptyPhone = false) + static private function formArrayWalk(array $data, $function, &$success = true, $requiresEmptyPhone = false, $maxPublicity = null) { + static $publicity = array('private' => 0, 'ax' => 1, 'public' => 2); + $phones = array(); foreach ($data as $item) { $phone = new Phone($item); $success = (!$phone->error && ($phone->format() || $phone->isEmpty()) && $success); if (!$phone->isEmpty()) { + if (!is_null($maxPublicity) && array_key_exists($maxPublicity, $publicity)) { + if ($publicity[$phone->pub] > $publicity[$maxPublicity]) { + $phone->pub = $maxPublicity; + } + } $phones[] = call_user_func(array($phone, $function)); } } if (count($phones) == 0 && $requiresEmptyPhone) { $phone = new Phone(); + if (!is_null($maxPublicity) && array_key_exists($maxPublicity, $publicity)) { + if ($publicity[$phone->pub] > $publicity[$maxPublicity]) { + $phone->pub = $maxPublicity; + } + } $phones[] = call_user_func(array($phone, $function)); } return $phones; } // Formats an array of form phones into an array of form formatted phones. - static public function formatFormArray(array $data, &$success = true) + static public function formatFormArray(array $data, &$success = true, $maxPublicity = null) { - return self::formArrayWalk($data, 'toFormArray', $success, true); + return self::formArrayWalk($data, 'toFormArray', $success, true, $maxPublicity); } static public function formArrayToString(array $data) diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index c239745..a013a1a 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -133,6 +133,8 @@ class ProfileSettingJob implements ProfileSetting private function cleanJob(ProfilePage &$page, $jobid, array &$job, &$success) { + static $publicity = array('private' => 0, 'ax' => 1, 'public' => 2); + if ($job['w_email'] == "new@example.org") { $job['w_email'] = $job['w_email_new']; } @@ -181,7 +183,12 @@ class ProfileSettingJob implements ProfileSetting $job['jobid'] = $res->fetchOneCell(); } } - $job['w_phone'] = Phone::formatFormArray($job['w_phone'], $s); + + if ($publicity[$job['w_email_pub']] > $publicity[$job['pub']]) { + $job['w_email_pub'] = $job['pub']; + } + + $job['w_phone'] = Phone::formatFormArray($job['w_phone'], $s, $job['pub']); unset($job['removed']); unset($job['new']); @@ -191,6 +198,8 @@ class ProfileSettingJob implements ProfileSetting public function value(ProfilePage &$page, $field, $value, &$success) { + static $publicity = array('private' => 0, 'ax' => 1, 'public' => 2); + $entreprise = ProfileValidate::get_typed_requests($page->pid(), 'entreprise'); $entr_val = 0; @@ -234,6 +243,9 @@ class ProfileSettingJob implements ProfileSetting foreach ($value as $key => &$job) { $address = new Address($job['w_address']); $s = $address->format(); + if ($publicity[$address->pub] > $publicity[$job['pub']]) { + $address->pub = $job['pub']; + } $job['w_address'] = $address->toFormArray(); $this->cleanJob($page, $key, $job, $s); if (!$init) {