Notifies profile's owner when profile modified by a third party (Closes #1038).
[platal.git] / modules / profile / jobs.inc.php
index f50e762..924ebac 100644 (file)
@@ -153,16 +153,16 @@ class ProfileSettingJob extends ProfileSettingGeocoding
                                 WHERE  name = {?}",
                               $job['name']);
             if ($res->numRows() != 1) {
-                $user = $page->profile->owner;
                 $this->geocodeAddress($job['hq_address'], $s);
                 if (!$s) {
                     $gmapsGeocoder = new GMapsGeocoder();
                     $job['hq_address'] = $gmapsGeocoder->stripGeocodingFromAddress($job['hq_address']);
                 }
-                $req = new EntrReq($user, $jobid, $job['name'], $job['hq_acronym'], $job['hq_url'],
+                $req = new EntrReq(S::user(), $page->profile, $jobid, $job['name'], $job['hq_acronym'], $job['hq_url'],
                                    $job['hq_email'], $job['hq_fixed'], $job['hq_fax'], $job['hq_address']);
                 $req->submit();
                 $job['jobid'] = null;
+                sleep(1);
             } else {
                 $job['jobid'] = $res->fetchOneCell();
             }
@@ -181,7 +181,7 @@ class ProfileSettingJob extends ProfileSettingGeocoding
     public function value(ProfilePage &$page, $field, $value, &$success)
     {
         require_once 'validations.inc.php';
-        $entreprise = Validate::get_typed_requests($page->profile->owner->id(), 'entreprise');
+        $entreprise = ProfileValidate::get_typed_requests($page->pid(), 'entreprise');
         $entr_val = 0;
 
         $init = false;
@@ -196,10 +196,21 @@ class ProfileSettingJob extends ProfileSettingGeocoding
                 $job['tmp_name'] = $entreprise[$entr_val]->name;
                 ++$entr_val;
             } else if ($job['name'] == '') {
+                if ($job['subSubSectorName'] == '' && $job['description'] == '' && $job['w_url'] == ''
+                    && $job['w_address']['text'] == '' && $job['w_email'] == ''
+                    && count($job['w_phone']) == 1 && $job['w_phone']['tel'] == '') {
+                    array_splice($value, $key, 1);
+                    continue;
+                }
+
                 $job['name_error'] = true;
                 $success = false;
             }
+
             if (isset($job['removed']) && $job['removed']) {
+                if ($job['name'] == '' && $entreprise) {
+                    $entreprise[$entr_val - 1]->clean();
+                }
                 array_splice($value, $key, 1);
             }
         }
@@ -221,7 +232,6 @@ class ProfileSettingJob extends ProfileSettingGeocoding
         // TODO: use address and phone classes to update profile_job_enum and profile_phones once they are done.
 
         require_once 'profil.func.inc.php';
-        require_once 'validations.inc.php';
 
         XDB::execute("DELETE FROM  profile_job
                             WHERE  pid = {?}",
@@ -254,6 +264,19 @@ class ProfileSettingJob extends ProfileSettingGeocoding
             }
         }
     }
+
+    public function getText($value) {
+        $jobs = array();
+        foreach ($value as $id => $job) {
+            $address = new ProfileSettingAddress();
+            $phones = new ProfileSettingPhones('pro', $id);
+            $jobs[] = 'Entreprise : ' . $job['name'] . ', secteur : ' . $job['subSubSectorName']
+                    . ', description : ' . $job['description'] . ', web : ' . $job['w_url']
+                    . ', email : ' . $job['w_email']
+                    . ', ' . $phones->getText($job['w_phone']) . ', ' .  $address->getText($job['w_address']);
+        }
+        return implode(' ; ' , $jobs);
+    }
 }
 
 class ProfileSettingJobs extends ProfilePage
@@ -264,6 +287,7 @@ class ProfileSettingJobs extends ProfilePage
     {
         parent::__construct($wiz);
         $this->settings['cv'] = null;
+        /* TODO: ProfileSettingCorps, required for notifications. */
         $this->settings['corps'] = null;
         $this->settings['jobs'] = new ProfileSettingJob();
         $this->watched = array('cv' => true, 'jobs' => true, 'corps' => true);