Prevents profile's subitems to be more public than the item they belong to (server...
authorStéphane Jacob <sj@m4x.org>
Wed, 8 Dec 2010 12:15:46 +0000 (13:15 +0100)
committerStéphane Jacob <sj@m4x.org>
Wed, 8 Dec 2010 12:32:51 +0000 (13:32 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/address.php
classes/phone.php
modules/profile/jobs.inc.php

index 88a97aa..92752d5 100644 (file)
@@ -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();
         }
index e8aad78..95a72ad 100644 (file)
@@ -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)
index c239745..a013a1a 100644 (file)
@@ -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) {