Merge remote branch 'origin/xorg/maint' into xorg/master
[platal.git] / modules / profile / jobs.inc.php
index 4726e94..e202908 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -92,7 +92,7 @@ class ProfileSettingJob implements ProfileSetting
         }
         $it = Phone::iterate(array($page->pid()), array(Phone::LINK_JOB));
         while ($phone = $it->next()) {
-            $jobs[$phone->linkId()]['w_phone'][$phone->id()] = $phone->toFormArray();
+            $jobs[$phone->link_id]['w_phone'][$phone->id] = $phone->toFormArray();
         }
         $res = XDB::iterator("SELECT  e.jtid, e.full_name, j.jid
                                 FROM  profile_job_term_enum AS e
@@ -224,11 +224,16 @@ class ProfileSettingJob implements ProfileSetting
             }
 
             if (isset($job['removed']) && $job['removed']) {
-                if ($job['name'] == '' && $entreprise) {
-                    $entreprise[$entr_val - 1]->clean();
+                if (S::user()->checkPerms('directory_ax')
+                    && (Phone::hasPrivate($job['w_phone']) || Address::hasPrivate($job['w_address']) || $job['w_email_pub'] == 'private')) {
+                    Platal::page()->trigWarning("L'entreprise ne peut être supprimée car elle contient des informations pour lesquelles vous n'avez le droit d'édition.");
+                } else {
+                    if ($job['name'] == '' && $entreprise && isset($entreprise[$entr_val - 1])) {
+                        $entreprise[$entr_val - 1]->clean();
+                    }
+                    unset($value[$key]);
+                    continue;
                 }
-                unset($value[$key]);
-                continue;
             }
             if (!isset($job['pub']) || !$job['pub']) {
                 $job['pub'] = 'private';
@@ -248,6 +253,7 @@ class ProfileSettingJob implements ProfileSetting
                 $success = ($success && $s);
             }
         }
+        usort($value, 'ProfileVisibility::comparePublicity');
         return $value;
     }
 
@@ -263,7 +269,7 @@ class ProfileSettingJob implements ProfileSetting
         Phone::deletePhones($page->pid(), Phone::LINK_JOB, null, $deletePrivate);
         $terms_values = array();
         foreach ($value as $id => &$job) {
-            if (isset($job['name']) && $job['name']) {
+            if (($job['pub'] != 'private' || $deletePrivate) && (isset($job['name']) && $job['name'])) {
                 if (isset($job['jobid']) && $job['jobid']) {
                     XDB::execute('INSERT INTO  profile_job (pid, id, description, email,
                                                             url, pub, email_pub, jobid)
@@ -296,6 +302,9 @@ class ProfileSettingJob implements ProfileSetting
                                   VALUES  ' . implode(', ', $terms_values) . '
                  ON DUPLICATE KEY UPDATE  computed = VALUES(computed)');
         }
+        if (S::user()->isMe($page->owner) && count($value) > 1) {
+            Platal::page()->trigWarning('Attention, tu as plusieurs emplois sur ton profil. Pense à supprimer ceux qui sont obsolètes.');
+        }
     }
 
     public function getText($value)