+class ProfileJob extends ProfileGeoloc
+{
+ private $pub;
+ private $mail;
+ private $web;
+ private $tel;
+ private $checks;
+
+ public function __construct()
+ {
+ $this->pub = new ProfilePub();
+ $this->mail = new ProfileEmail();
+ $this->web = new ProfileWeb();
+ $this->tel = new ProfileTel();
+ $this->checks = array('web' => array('web'),
+ 'mail' => array('email'),
+ 'tel' => array('tel', 'fax', 'mobile'),
+ 'pub' => array('pub', 'tel_pub', 'email_pub'));
+ }
+
+ private function cleanJob(ProfilePage &$page, array &$job, &$success)
+ {
+ $success = true;
+ foreach ($this->checks as $obj=>&$fields) {
+ $chk =& $this->$obj;
+ foreach ($fields as $field) {
+ $job[$field] = $chk->value($page, $field, $job[$field], $s);
+ if (!$s) {
+ $success = false;
+ $job[$field . '_error'] = true;
+ }
+ }
+ }
+ 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']) {
+ unset($value[$key]);
+ }
+ }
+ foreach ($value as $key=>&$job) {
+ $ls = true;
+ $this->geolocAddress($job['adr'], $s);
+ $ls = ($ls && $s);
+ $this->cleanJob($page, $job, $s);
+ $ls = ($ls && $s);
+ if (!$init) {
+ $success = ($success && $ls);
+ }
+ }
+ return $value;
+ }
+
+ public function save(ProfilePage &$page, $field, $value)
+ {
+ XDB::execute("DELETE FROM entreprises
+ WHERE uid = {?}",
+ S::i('uid'));
+ $i = 0;
+ foreach ($value as &$job) {
+ XDB::execute("INSERT INTO entreprises (uid, entrid, entreprise, secteur, ss_secteur,
+ fonction, poste, adr1, adr2, adr3, postcode,
+ city, cityid, country, region, regiontxt,
+ tel, fax, mobile, email, web,
+ pub, adr_pub, tel_pub, email_pub)
+ 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['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'],
+ $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub']);
+ }
+ }
+}
+