X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Fjobs.inc.php;h=9796e96599e30f68535bb4151199c49393d06f3f;hb=7706cc73e140d7a154136cf1e6836091a25c69c5;hp=05e538c55b96c003248b6c372770e625912d924b;hpb=2dcac0f527e8207d754af8974d81b2bce3f433d9;p=platal.git diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 05e538c..9796e96 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -1,6 +1,6 @@ pub = new ProfilePub(); + $this->mail + = $this->mail_new + = new ProfileEmail(); + $this->web = new ProfileWeb(); + $this->bool = new ProfileBool(); + $this->checks = array('web' => array('web'), + 'mail_new' => array('email_new'), + 'mail' => array('email'), + 'pub' => array('pub', 'email_pub')); + } + + private function cleanJob(ProfilePage &$page,$jobid, array &$job, &$success) + { + $success = true; + foreach ($this->checks as $obj=>&$fields) { + $chk =& $this->$obj; + foreach ($fields as $field) { + if ($field == "email_new") { + if ($job['email'] == "new@example.org") { + $job['email'] = $job[$field]; + } + continue; + } + $job[$field] = $chk->value($page, $field, $job[$field], $s); + if (!$s) { + $success = false; + $job[$field . '_error'] = true; + } + } + } + $job['adr']['pub'] = $this->pub->value($page, 'adr_pub', @$job['adr']['pub'], $s); + $job['adr']['checked'] = $this->bool->value($page, 'adr_checked', @$job['adr']['checked'], $s); + if (!isset($job['tel'])) { + $job['tel'] = array(); + } + $profiletel = new ProfilePhones('pro', $jobid); + $job['tel'] = $profiletel->value($page, 'tel', $job['tel'], $s); + unset($job['removed']); + unset($job['new']); + unset($job['adr']['changed']); + unset($job['adr']['parsevalid']); + unset($job['adr']['display']); + } + + public function value(ProfilePage &$page, $field, $value, &$success) + { + $init = false; + if (is_null($value)) { + $value = $page->values['jobs']; + $init = true; + } + $success = true; + foreach ($value as $key=>&$job) { + if (@$job['removed'] || !trim($job['name'])) { + unset($value[$key]); + } + } + foreach ($value as $key=>&$job) { + $ls = true; + $this->geolocAddress($job['adr'], $s); + $ls = ($ls && $s); + $this->cleanJob($page, $key, $job, $s); + $ls = ($ls && $s); + if (!$init) { + $success = ($success && $ls); + } + } + return $value; + } + + public function save(ProfilePage &$page, $field, $value) + { + require_once('profil.func.inc.php'); + XDB::execute("DELETE FROM entreprises + WHERE uid = {?}", + S::i('uid')); + XDB::execute("DELETE FROM profile_phones + WHERE uid = {?} AND link_type = 'pro'", + S::i('uid')); + $i = 0; + foreach ($value as $jobid=>&$job) { + if ($job['email'] == "new@example.org") { + $job['email'] = $job['email_new']; + } + XDB::execute("INSERT INTO entreprises (uid, entrid, entreprise, secteur, ss_secteur, + fonction, poste, adr1, adr2, adr3, postcode, + city, cityid, country, region, regiontxt, + email, web, + pub, adr_pub, email_pub, flags, + glat, glng) + VALUES ({?}, {?}, {?}, {?}, {?}, + {?}, {?}, {?}, {?}, {?}, {?}, + {?}, {?}, {?}, {?}, {?}, + {?}, {?}, + {?}, {?}, {?}, {?}, + {?}, {?})", + S::i('uid'), $i, $job['name'], $job['secteur'], $job['ss_secteur'], + $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'], + $job['adr']['postcode'], + $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'], + $job['adr']['regiontxt'], + $job['email'], $job['web'], + $job['pub'], $job['adr']['pub'], $job['email_pub'], + $job['adr']['checked'] ? 'geoloc' : '', $job['adr']['precise_lat'], + $job['adr']['precise_lon']); + $profiletel = new ProfilePhones('pro', $jobid); + $profiletel->saveTels('tel', $job['tel']); + $i++; + } + } +} + class ProfileJobs extends ProfilePage { protected $pg_template = 'profile/jobs.tpl'; @@ -26,11 +150,114 @@ class ProfileJobs extends ProfilePage public function __construct(PlWizard &$wiz) { parent::__construct($wiz); + $this->settings['cv'] = null; + $this->settings['jobs'] = new ProfileJob(); + $this->watched['cv'] = $this->watched['jobs'] = true; + } + + protected function _fetchData() + { + // Checkout the CV + $res = XDB::query("SELECT cv + FROM auth_user_md5 + WHERE user_id = {?}", + S::i('uid')); + $this->values['cv'] = $res->fetchOneCell(); + + // Build the jobs tree + $res = XDB::iterRow("SELECT e.entrid, e.entreprise, e.secteur, e.ss_secteur, + e.fonction, e.poste, e.adr1, e.adr2, e.adr3, + e.postcode, e.city, e.cityid, e.region, e.regiontxt, + e.country, gp.pays, gp.display, + FIND_IN_SET('geoloc', flags), + e.email, e.web, e.pub, + e.adr_pub, e.email_pub, + e.glat AS precise_lat, e.glng AS precise_lon + FROM entreprises AS e + LEFT JOIN geoloc_pays AS gp ON(gp.a2 = e.country) + WHERE e.uid = {?} AND entreprise != '' + ORDER BY entrid", S::i('uid')); + $this->values['jobs'] = array(); + while (list($id, $name, $secteur, $ss_secteur, $fonction, $poste, + $adr1, $adr2, $adr3, $postcode, $city, $cityid, + $region, $regiontxt, $country, $countrytxt, $display, + $checked, $email, $web, + $pub, $adr_pub, $email_pub, $glat, $glng + ) = $res->next()) { + $this->values['jobs'][] = array('id' => $id, + 'name' => $name, + 'secteur' => $secteur, + 'ss_secteur' => $ss_secteur, + 'fonction' => $fonction, + 'poste' => $poste, + 'adr' => array('adr1' => $adr1, + 'adr2' => $adr2, + 'adr3' => $adr3, + 'postcode' => $postcode, + 'city' => $city, + 'cityid' => $cityid, + 'region' => $region, + 'regiontxt' => $regiontxt, + 'country' => $country, + 'countrytxt' => $countrytxt, + 'display' => $display, + 'pub' => $adr_pub, + 'checked' => $checked, + 'precise_lat'=> $glat, + 'precise_lon'=> $glng), + 'email' => $email, + 'web' => $web, + 'pub' => $pub, + 'email_pub' => $email_pub); + } + + $res = XDB::iterator("SELECT link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment + FROM profile_phones + WHERE uid = {?} AND link_type = 'pro' + ORDER BY link_id", + S::i('uid')); + $i = 0; + $jobNb = count($this->values['jobs']); + while ($tel = $res->next()) { + $jobid = $tel['jobid']; + unset($tel['jobid']); + while ($i < $jobNb && $this->values['jobs'][$i]['id'] < $jobid) { + $i++; + } + if ($i >= $jobNb) { + break; + } + $job =& $this->values['jobs'][$i]; + if (!isset($job['tel'])) { + $job['tel'] = array(); + } + if ($job['id'] == $jobid) { + $job['tel'][] = $tel; + } + } + foreach ($this->values['jobs'] as $id=>&$job) { + if (!isset($job['tel'])) { + $job['tel'] = array(); + } + unset($job['id']); + } + } + + protected function _saveData() + { + if ($this->changed['cv']) { + XDB::execute("UPDATE auth_user_md5 + SET cv = {?} + WHERE user_id = {?}", + $this->values['cv'], S::i('uid')); + } } - public function prepare(PlatalPage &$page) + public function _prepare(PlPage &$page, $id) { - parent::prepare($page); + require_once "emails.combobox.inc.php"; + fill_email_combobox($page); + $page->assign('secteurs', XDB::iterator("SELECT id, label FROM emploi_secteur")); $page->assign('fonctions', XDB::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title