Fix subscription to promotion list during registration.
[platal.git] / modules / profile / jobs.inc.php
index 785a48f..723370b 100644 (file)
@@ -83,7 +83,7 @@ class ProfileSettingJob implements ProfileSetting
         $backtrack = array();
         foreach ($jobs as $key=>$job) {
             $compagnies[] = $job['jobid'];
-            $backtrack[$job['jobid']] = $key;
+            $backtrack[$job['id']] = $key;
         }
 
         $it = Address::iterate(array($page->pid()), array(Address::LINK_JOB));
@@ -94,18 +94,19 @@ class ProfileSettingJob implements ProfileSetting
         while ($phone = $it->next()) {
             $jobs[$phone->linkId()]['w_phone'][$phone->id()] = $phone->toFormArray();
         }
-        $res = XDB::iterator("SELECT  e.jtid, e.full_name, j.jid AS jobid
+        $res = XDB::iterator("SELECT  e.jtid, e.full_name, j.jid
                                 FROM  profile_job_term_enum AS e
                           INNER JOIN  profile_job_term AS j USING(jtid)
                                WHERE  pid = {?}
                             ORDER BY  j.jid",
                              $page->pid());
         while ($term = $res->next()) {
-            $jobid = $term['jobid'];
-            if (!isset($backtrack[$jobid])) {
+            // $jid is the ID of the job among this user's jobs
+            $jid = $term['jid'];
+            if (!isset($backtrack[$jid])) {
                 continue;
             }
-            $job =& $jobs[$backtrack[$jobid]];
+            $job =& $jobs[$backtrack[$jid]];
             if (!isset($job['terms'])) {
                 $job['terms'] = array();
             }
@@ -250,7 +251,7 @@ class ProfileSettingJob implements ProfileSetting
         XDB::execute("DELETE FROM  profile_job_term
                             WHERE  pid = {?}",
                      $page->pid());
-        Address::delete($page->pid(), Address::LINK_JOB);
+        Address::deleteAddresses($page->pid(), Address::LINK_JOB);
         Phone::deletePhones($page->pid(), Phone::LINK_JOB);
         $terms_values = array();
         foreach ($value as $id => &$job) {
@@ -283,8 +284,9 @@ class ProfileSettingJob implements ProfileSetting
             }
         }
         if (count($terms_values) > 0) {
-            XDB::execute('REPLACE INTO  profile_job_term (pid, jid, jtid, computed)
-                                VALUES  '.implode(', ', $terms_values));
+            XDB::rawExecute('INSERT INTO  profile_job_term (pid, jid, jtid, computed)
+                                  VALUES  ' . implode(', ', $terms_values) . '
+                 ON DUPLICATE KEY UPDATE  computed = VALUES(computed)');
         }
     }
 
@@ -322,8 +324,10 @@ class ProfileSettingCorps implements ProfileSetting
 
     public function save(ProfilePage &$page, $field, $value)
     {
-        XDB::execute('REPLACE INTO  profile_corps (original_corpsid, current_corpsid, rankid, corps_pub, pid)
-                            VALUES  ({?}, {?}, {?}, {?}, {?})',
+        XDB::execute('INSERT INTO  profile_corps (original_corpsid, current_corpsid, rankid, corps_pub, pid)
+                           VALUES  ({?}, {?}, {?}, {?}, {?})
+          ON DUPLICATE KEY UPDATE  original_corpsid = VALUES(original_corpsid), current_corpsid = VALUES(current_corpsid),
+                                   rankid = VALUES(rankid), corps_pub = VALUES(corps_pub)',
                       $value['original'], $value['current'], $value['rank'], $value['pub'], $page->pid());
     }