2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ProfileSettingJob
extends ProfileSettingGeocoding
31 public function __construct()
33 $this->pub
= new ProfileSettingPub();
36 = new ProfileSettingEmail();
37 $this->url
= new ProfileSettingWeb();
38 $this->bool
= new ProfileSettingBool();
39 $this->checks
= array('url' => array('w_url'),
40 'email' => array('w_email'),
41 'pub' => array('pub', 'w_email_pub'),
45 public function emptyJob()
55 'hq_address' => array(
60 'administrativeAreaId' => '',
61 'subAdministrativeAreaId' => '',
77 'subSubSectorName' => null
,
80 'subSubSector' => '0',
89 'administrativeAreaId' => '',
90 'subAdministrativeAreaId' => '',
105 'w_email_pub' => 'private',
107 'w_phone' => array(0 => array(
116 private function cleanJob(ProfilePage
&$page, $jobid, array &$job, &$success)
119 if ($job['w_email'] == "new@example.org") {
120 $job['w_email'] = $job['w_email_new'];
122 foreach ($this->checks
as $obj=>&$fields) {
124 foreach ($fields as $field) {
125 $job[$field] = $chk->value($page, $field, $job[$field], $s);
128 $job[$field . '_error'] = true
;
132 if (!$job['subSubSectorName']) {
133 $res = XDB
::query("SELECT name
134 FROM profile_job_subsubsector_enum
136 $job['subSubSector']);
137 $job['subSubSectorName'] = $res->fetchOneCell();
139 $res = XDB
::query("SELECT sectorid, subsectorid, id
140 FROM profile_job_subsubsector_enum
142 $job['subSubSectorName']);
143 if ($res->numRows() != 1) {
145 $job['sector_error'] = true
;
147 list($job['sector'], $job['subSector'], $job['subSubSector']) = $res->fetchOneRow();
151 $res = XDB
::query("SELECT id
152 FROM profile_job_enum
155 if ($res->numRows() != 1) {
156 $this->geocodeAddress($job['hq_address'], $s);
158 $gmapsGeocoder = new GMapsGeocoder();
159 $job['hq_address'] = $gmapsGeocoder->stripGeocodingFromAddress($job['hq_address']);
161 $req = new EntrReq(S
::user(), $page->profile
, $jobid, $job['name'], $job['hq_acronym'], $job['hq_url'],
162 $job['hq_email'], $job['hq_fixed'], $job['hq_fax'], $job['hq_address']);
164 $job['jobid'] = null
;
167 $job['jobid'] = $res->fetchOneCell();
170 $job['w_address']['pub'] = $this->pub
->value($page, 'address_pub', $job['w_address']['pub'], $s);
171 if (!isset($job['w_phone'])) {
172 $job['w_phone'] = array();
174 $profiletel = new ProfileSettingPhones('pro', $jobid);
175 $job['w_phone'] = $profiletel->value($page, 'tel', $job['w_phone'], $s);
177 unset($job['removed']);
181 public function value(ProfilePage
&$page, $field, $value, &$success)
183 require_once 'validations.inc.php';
184 $entreprise = ProfileValidate
::get_typed_requests($page->pid(), 'entreprise');
188 if (is_null($value)) {
189 $value = $page->values
['jobs'];
193 foreach ($value as $key => &$job) {
194 $job['name'] = trim($job['name']);
195 if ($job['name'] == '' && $entreprise) {
196 $job['tmp_name'] = $entreprise[$entr_val]->name
;
198 } else if ($job['name'] == '') {
199 if ($job['subSubSectorName'] == '' && $job['description'] == '' && $job['w_url'] == ''
200 && $job['w_address']['text'] == '' && $job['w_email'] == ''
201 && count($job['w_phone']) == 1 && $job['w_phone']['tel'] == '') {
202 array_splice($value, $key, 1);
206 $job['name_error'] = true
;
210 if (isset($job['removed']) && $job['removed']) {
211 if ($job['name'] == '' && $entreprise) {
212 $entreprise[$entr_val - 1]->clean();
214 array_splice($value, $key, 1);
217 foreach ($value as $key => &$job) {
219 $this->geocodeAddress($job['w_address'], $s);
221 $this->cleanJob($page, $key, $job, $s);
224 $success = ($success && $ls);
230 public function save(ProfilePage
&$page, $field, $value)
232 // TODO: use address and phone classes to update profile_job_enum and profile_phones once they are done.
234 require_once 'profil.func.inc.php';
236 XDB
::execute("DELETE FROM profile_job
239 XDB
::execute("DELETE FROM profile_addresses
240 WHERE pid = {?} AND type = 'job'",
242 XDB
::execute("DELETE FROM profile_phones
243 WHERE pid = {?} AND link_type = 'pro'",
245 foreach ($value as $id => &$job) {
246 if (isset($job['name']) && $job['name']) {
247 if (isset($job['jobid']) && $job['jobid']) {
248 XDB
::execute("INSERT INTO profile_job (pid, id, description, sectorid, subsectorid,
249 subsubsectorid, email, url, pub, email_pub, jobid)
250 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
251 $page->pid(), $id, $job['description'], $job['sector'], $job['subSector'],
252 $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']);
254 XDB
::execute("INSERT INTO profile_job (pid, id, description, sectorid, subsectorid,
255 subsubsectorid, email, url, pub, email_pub)
256 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
257 $page->pid(), $id, $job['description'], $job['sector'], $job['subSector'],
258 $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub']);
260 $address = new ProfileSettingAddress();
261 $address->saveAddress($page->pid(), $id, $job['w_address'], 'job');
262 $profiletel = new ProfileSettingPhones('pro', $id);
263 $profiletel->saveTels($page->pid(), 'tel', $job['w_phone']);
268 public function getText($value) {
270 foreach ($value as $id => $job) {
271 $address = new ProfileSettingAddress();
272 $phones = new ProfileSettingPhones('pro', $id);
273 $jobs[] = 'Entreprise : ' . $job['name'] . ', secteur : ' . $job['subSubSectorName']
274 . ', description : ' . $job['description'] . ', web : ' . $job['w_url']
275 . ', email : ' . $job['w_email']
276 . ', ' . $phones->getText($job['w_phone']) . ', ' . $address->getText($job['w_address']);
278 return implode(' ; ' , $jobs);
282 class ProfileSettingCorps
implements ProfileSetting
284 public function value(ProfilePage
&$page, $field, $value, &$success)
287 if (is_null($value)) {
288 $res = XDB
::query("SELECT original_corpsid AS original, current_corpsid AS current,
289 rankid AS rank, corps_pub AS pub
293 return $res->fetchOneAssoc();
298 public function save(ProfilePage
&$page, $field, $value)
300 XDB
::execute('REPLACE INTO profile_corps (original_corpsid, current_corpsid, rankid, corps_pub, pid)
301 VALUES ({?}, {?}, {?}, {?}, {?})',
302 $value['original'], $value['current'], $value['rank'], $value['pub'], $page->pid());
305 public function getText($value)
307 $corpsList = DirEnum
::getOptions(DirEnum
::CORPS
);
308 $rankList = DirEnum
::getOptions(DirEnum
::CORPSRANKS
);
309 return 'Corps actuel : ' . $corpsList[$value['current']] . ' , rang : ' . $corpsList[$value['rank']]
310 . ' , corps d\'origine : ' . $corpsList[$value['original']] . ' , affichage : ' . $value['pub'];
314 class ProfileSettingJobs
extends ProfilePage
316 protected $pg_template = 'profile/jobs.tpl';
318 public function __construct(PlWizard
&$wiz)
320 parent
::__construct($wiz);
321 $this->settings
['cv'] = null
;
322 $this->settings
['corps'] = new ProfileSettingCorps();
323 $this->settings
['jobs'] = new ProfileSettingJob();
324 $this->watched
= array('cv' => true
, 'jobs' => true
, 'corps' => true
);
327 protected function _fetchData()
330 $res = XDB
::query("SELECT cv
334 $this->values
['cv'] = $res->fetchOneCell();
336 // Build the jobs tree
337 $res = XDB
::iterRow("SELECT j.id, j.jobid, je.name, j.sectorid, j.subsectorid, j.subsubsectorid,
338 s.name, j.description, j.email, j.email_pub, j.url, j.pub,
339 je.acronym, je.url, je.email,
340 aw.accuracy, aw.text, aw.postalText, aw.postalCode, aw.localityId,
341 aw.subAdministrativeAreaId, aw.administrativeAreaId, aw.countryId,
342 aw.latitude, aw.longitude, aw.pub, aw.updateTime,
343 aw.north, aw.south, aw.east, aw.west,
344 ah.accuracy, ah.text, ah.postalText, ah.postalCode, ah.localityId,
345 ah.subAdministrativeAreaId, ah.administrativeAreaId, ah.countryId,
346 ah.latitude, ah.longitude, ah.pub, ah.updateTime,
347 ah.north, ah.south, ah.east, ah.west
348 FROM profile_job AS j
349 LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id)
350 LEFT JOIN profile_job_subsubsector_enum AS s ON (s.id = j.subsubsectorid)
351 LEFT JOIN profile_addresses AS aw ON (aw.pid = j.pid AND aw.type = 'job'
353 LEFT JOIN profile_addresses AS ah ON (ah.jobid = j.jobid AND ah.type = 'hq')
357 $this->values
['jobs'] = array();
359 if ($res->numRows() > 0) {
360 while (list($id, $jobid, $name, $sector, $subSector, $subSubSector,
361 $subSubSectorName, $description, $w_email, $w_emailPub, $w_url, $pub,
362 $hq_acronym, $hq_url, $hq_email,
363 $w_accuracy, $w_text, $w_postalText, $w_postalCode, $w_localityId,
364 $w_subAdministrativeAreaId, $w_administrativeAreaId, $w_countryId,
365 $w_latitude, $w_longitude, $w_pub, $w_updateTime,
366 $w_north, $w_south, $w_east, $w_west,
367 $hq_accuracy, $hq_text, $hq_postalText, $hq_postalCode, $hq_localityId,
368 $hq_subAdministrativeAreaId, $hq_administrativeAreaId, $hq_countryId,
369 $hq_latitude, $hq_longitude, $hq_pub, $hq_updateTime,
370 $hq_north, $hq_south, $hq_east, $hq_west,
372 $this->values
['jobs'][] = array(
377 'subSector' => $subSector,
378 'subSubSector' => $subSubSector,
379 'subSubSectorName' => $subSubSectorName,
380 'description' => $description,
382 'w_email' => $w_email,
383 'w_email_pub' => $w_emailPub,
385 'hq_acronym' => $hq_acronym,
387 'hq_email' => $hq_email,
388 'w_address' => array(
389 'accuracy' => $w_accuracy,
391 'postalText' => $w_postalText,
392 'postalCode' => $w_postalCode,
393 'localityId' => $w_localityId,
394 'subAdministrativeAreaId' => $w_subAdministrativeAreaId,
395 'administrativeAreaId' => $w_administrativeAreaId,
396 'countryId' => $w_countryId,
397 'latitude' => $w_latitude,
398 'longitude' => $w_longitude,
400 'updateTime' => $w_updateTime,
406 'hq_address' => array(
407 'accuracy' => $hq_accuracy,
409 'postalText' => $hq_postalText,
410 'postalCode' => $hq_postalCode,
411 'localityId' => $hq_localityId,
412 'subAdministrativeAreaId' => $hq_subAdministrativeAreaId,
413 'administrativeAreaId' => $hq_administrativeAreaId,
414 'countryId' => $hq_countryId,
415 'latitude' => $hq_latitude,
416 'longitude' => $hq_longitude,
418 'updateTime' => $hq_updateTime,
419 'north' => $hq_north,
420 'south' => $hq_south,
427 $res = XDB
::iterator("SELECT link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment
429 WHERE pid = {?} AND link_type = 'pro'
433 $jobNb = count($this->values
['jobs']);
434 while ($phone = $res->next()) {
435 $jobid = $phone['jobid'];
436 while ($i < $jobNb && $this->values
['jobs'][$i]['id'] < $jobid) {
442 $job =& $this->values
['jobs'][$i];
443 if (!isset($job['w_phone'])) {
444 $job['w_phone'] = array();
446 if ($job['id'] == $jobid) {
447 $job['w_phone'][] = $phone;
450 foreach ($this->values
['jobs'] as $id => &$job) {
451 if (!isset($job['w_phone'])) {
452 $job['w_phone'] = array(
463 $job['w_email_new'] = '';
464 if (!isset($job['hq_phone'])) {
465 $job['hq_phone'] = '';
467 if (!isset($job['hq_fax'])) {
470 if (!isset($job['w_email_pub'])) {
471 $job['w_email_pub'] = 'private';
473 if (!$job['hq_address']['text']) {
474 $job['hq_address'] = array(
479 'administrativeAreaId' => '',
480 'subAdministrativeAreaId' => '',
495 $job['w_address']['cedex'] = '';
496 $job['w_address']['changed'] = '0';
497 $job['w_address']['removed'] = '0';
499 $this->values
['jobs'][] = $this->settings
['jobs']->emptyJob();
503 protected function _saveData()
505 if ($this->changed
['cv']) {
506 XDB
::execute("UPDATE profiles
509 $this->values
['cv'], $this->pid());
513 public function _prepare(PlPage
&$page, $id)
515 require_once 'emails.combobox.inc.php';
516 fill_email_combobox($page, $this->owner
);
518 $res = XDB
::query("SELECT id, name AS label
519 FROM profile_job_sector_enum");
520 $page->assign('sectors', $res->fetchAllAssoc());
522 $res = XDB
::iterator("SELECT id, name
523 FROM profile_corps_enum
524 ORDER BY id = 1 DESC, name");
525 $page->assign('original_corps', $res->fetchAllAssoc());
527 $res = XDB
::iterator("SELECT id, name
528 FROM profile_corps_enum
529 WHERE still_exists = 1
530 ORDER BY id = 1 DESC, name");
531 $page->assign('current_corps', $res->fetchAllAssoc());
533 $res = XDB
::iterator("SELECT id, name
534 FROM profile_corps_rank_enum
535 ORDER BY id = 1 DESC, name");
536 $page->assign('corps_rank', $res->fetchAllAssoc());
540 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: