Fixes time saving and uses CRLF in address text because of RFC 1738.
[platal.git] / modules / profile / jobs.inc.php
index 2d03924..b098012 100644 (file)
@@ -83,7 +83,13 @@ class ProfileJob extends ProfileGeocoding
                               $job['name']);
             if ($res->numRows() != 1) {
                 $user = S::user();
-                $req = new EntrReq($user, $jobid, $job['name'], $job['hq_²acronym'], $job['hq_url'], $job['hq_email'], $job['hq_fixed'], $job['hq_fax']);
+                $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'],
+                                   $job['hq_email'], $job['hq_fixed'], $job['hq_fax'], $job['hq_address']);
                 $req->submit();
                 $job['jobid'] = null;
             } else {
@@ -114,7 +120,7 @@ class ProfileJob extends ProfileGeocoding
         $success = true;
         foreach ($value as $key=>&$job) {
             $job['name'] = trim($job['name']);
-            if (!$job['name']) {
+            if (!$job['name'] && $entreprise) {
                 $job['tmp_name'] = $entreprise[$entr_val]->name;
                 $entr_val ++;
             }
@@ -137,6 +143,8 @@ class ProfileJob extends ProfileGeocoding
 
     public function save(ProfilePage &$page, $field, $value)
     {
+        // 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');
 
@@ -150,17 +158,17 @@ class ProfileJob extends ProfileGeocoding
                             WHERE  uid = {?} AND link_type = 'pro'",
                      S::i('uid'));
         foreach ($value as $id=>&$job) {
-            if ($job['jobid']) {
-                XDB::execute("INSERT INTO  profile_job (uid, id, functionid, description, sectorid, subsectorid,
+            if (isset($job['jobid']) && $job['jobid']) {
+                XDB::execute("INSERT INTO  profile_job (uid, id, description, sectorid, subsectorid,
                                                         subsubsectorid, email, url, pub, email_pub, jobid)
                                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
-                             S::i('uid'), $id, $job['fonction'], $job['description'], $job['sector'], $job['subSector'],
+                             S::i('uid'), $id, $job['description'], $job['sector'], $job['subSector'],
                              $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']);
             } else {
-                XDB::execute("INSERT INTO  profile_job (uid, id, functionid, description, sectorid, subsectorid,
+                XDB::execute("INSERT INTO  profile_job (uid, id, description, sectorid, subsectorid,
                                                         subsubsectorid, email, url, pub, email_pub)
-                                   VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
-                             S::i('uid'), $id, $job['fonction'], $job['description'], $job['sector'], $job['subSector'],
+                                   VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
+                             S::i('uid'), $id, $job['description'], $job['sector'], $job['subSector'],
                              $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub']);
             }
             $address = new ProfileAddress();
@@ -202,7 +210,7 @@ class ProfileJobs extends ProfilePage
         $this->values['corps'] = $res->fetchOneAssoc();
 
         // Build the jobs tree
-        $res = XDB::iterRow("SELECT  j.id, j.jobid, je.name, j.functionid, j.sectorid, j.subsectorid, j.subsubsectorid,
+        $res = XDB::iterRow("SELECT  j.id, j.jobid, je.name, j.sectorid, j.subsectorid, j.subsubsectorid,
                                      s.name, j.description, j.email, j.email_pub, j.url, j.pub,
                                      je.acronym, je.url, je.email,
                                      aw.accuracy, aw.text, aw.postalText, aw.postalCode, aw.localityId,
@@ -216,13 +224,14 @@ class ProfileJobs extends ProfilePage
                                FROM  profile_job                   AS j
                           LEFT JOIN  profile_job_enum              AS je ON (j.jobid = je.id)
                           LEFT JOIN  profile_job_subsubsector_enum AS s  ON (s.id = j.subsubsectorid)
-                          LEFT JOIN  profile_addresses             AS aw ON (aw.pid = j.uid AND aw.type = 'job')
+                          LEFT JOIN  profile_addresses             AS aw ON (aw.pid = j.uid AND aw.type = 'job'
+                                                                             AND aw.id = j.id)
                           LEFT JOIN  profile_addresses             AS ah ON (ah.jobid = j.jobid AND ah.type = 'hq')
                               WHERE  j.uid = {?}
                            ORDER BY  j.id",
                             S::i('uid'));
         $this->values['jobs'] = array();
-        while (list($id, $jobid, $name, $function, $sector, $subSector, $subSubSector,
+        while (list($id, $jobid, $name, $sector, $subSector, $subSubSector,
                     $subSubSectorName, $description, $w_email, $w_emailPub, $w_url, $pub,
                     $hq_acronym, $hq_url, $hq_email,
                     $w_accuracy, $w_text, $w_postalText, $w_postalCode, $w_localityId,
@@ -237,7 +246,6 @@ class ProfileJobs extends ProfilePage
             $this->values['jobs'][] = array('id'               => $id,
                                             'jobid'            => $jobid,
                                             'name'             => $name,
-                                            'function'         => $function,
                                             'sector'           => $sector,
                                             'subSector'        => $subSector,
                                             'subSubSector'     => $subSubSector,
@@ -344,10 +352,6 @@ class ProfileJobs extends ProfilePage
         $res = XDB::query("SELECT  id, name AS label
                              FROM  profile_job_sector_enum");
         $page->assign('sectors', $res->fetchAllAssoc());
-        $res = XDB::query("SELECT  id, fonction_fr, FIND_IN_SET('titre', flags) AS title
-                             FROM  fonctions_def
-                         ORDER BY  id");
-        $page->assign('functions', $res->fetchAllAssoc());
 
         $res = XDB::iterator("SELECT  id, name
                                 FROM  profile_corps_enum