Add 'hidden' flag to text descriptions of the 'pub' flag
[platal.git] / modules / profile / page.inc.php
index 9501b58..608d3da 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -31,11 +31,11 @@ interface ProfileSetting
      * Whatever happen, this function must always returns the function to
      * show on the page to the user.
      */
-    public function value(ProfilePage &$page, $field, $value, &$success);
+    public function value(ProfilePage $page, $field, $value, &$success);
 
     /** Save the new value for the given field.
      */
-    public function save(ProfilePage &$page, $field, $new_value);
+    public function save(ProfilePage $page, $field, $new_value);
 
     /** Get text from the value.
      */
@@ -44,7 +44,7 @@ interface ProfileSetting
 
 abstract class ProfileNoSave implements ProfileSetting
 {
-    public function save(ProfilePage &$page, $field, $new_value) { }
+    public function save(ProfilePage $page, $field, $new_value) { }
 
     public function getText($value) {
         return $value;
@@ -53,7 +53,7 @@ abstract class ProfileNoSave implements ProfileSetting
 
 class ProfileSettingWeb 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);
@@ -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::get(Visibility::VIEW_ADMIN));
             while ($phone = $it->next()) {
                 $success = ($phone->format() && $success);
                 $phones[] = $phone->toFormArray();
@@ -127,7 +127,7 @@ 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, 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,14 +156,14 @@ class ProfileSettingPub extends ProfileNoSave
     }
 
     public function getText($value) {
-        static $pubs = array('public' => 'publique', 'ax' => 'annuaire AX', 'private' => 'privĂ©');
+        static $pubs = array('public' => 'publique', 'ax' => 'annuaire papier', 'private' => 'privĂ©', 'hidden' => 'administrateurs');
         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)) {
@@ -182,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)) {
@@ -228,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');
@@ -306,12 +306,14 @@ abstract class ProfilePage implements PlWizardPage
         $user = S::user();
         if ($owner->isActive()) {
             foreach ($changedFields as $field => $values) {
-                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');
+                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;
@@ -354,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();
@@ -433,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:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>