cf11aecf57532572a2d178681571ac21c9018ae9
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 $user = $page->profile
->owner
;
157 $this->geocodeAddress($job['hq_address'], $s);
159 $gmapsGeocoder = new GMapsGeocoder();
160 $job['hq_address'] = $gmapsGeocoder->stripGeocodingFromAddress($job['hq_address']);
162 $req = new EntrReq($user, $jobid, $job['name'], $job['hq_acronym'], $job['hq_url'],
163 $job['hq_email'], $job['hq_fixed'], $job['hq_fax'], $job['hq_address']);
165 $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 = Validate
::get_typed_requests($page->profile
->owner
->id(), '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 $job['name_error'] = true
;
203 if (isset($job['removed']) && $job['removed']) {
204 if ($job['name'] == '' && $entreprise) {
205 $entreprise[$entr_val - 1]->clean();
207 array_splice($value, $key, 1);
210 foreach ($value as $key => &$job) {
212 $this->geocodeAddress($job['w_address'], $s);
214 $this->cleanJob($page, $key, $job, $s);
217 $success = ($success && $ls);
223 public function save(ProfilePage
&$page, $field, $value)
225 // TODO: use address and phone classes to update profile_job_enum and profile_phones once they are done.
227 require_once 'profil.func.inc.php';
228 require_once 'validations.inc.php';
230 XDB
::execute("DELETE FROM profile_job
233 XDB
::execute("DELETE FROM profile_addresses
234 WHERE pid = {?} AND type = 'job'",
236 XDB
::execute("DELETE FROM profile_phones
237 WHERE pid = {?} AND link_type = 'pro'",
239 foreach ($value as $id => &$job) {
240 if (isset($job['name']) && $job['name']) {
241 if (isset($job['jobid']) && $job['jobid']) {
242 XDB
::execute("INSERT INTO profile_job (pid, id, description, sectorid, subsectorid,
243 subsubsectorid, email, url, pub, email_pub, jobid)
244 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
245 $page->pid(), $id, $job['description'], $job['sector'], $job['subSector'],
246 $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']);
248 XDB
::execute("INSERT INTO profile_job (pid, id, description, sectorid, subsectorid,
249 subsubsectorid, email, url, pub, email_pub)
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']);
254 $address = new ProfileSettingAddress();
255 $address->saveAddress($page->pid(), $id, $job['w_address'], 'job');
256 $profiletel = new ProfileSettingPhones('pro', $id);
257 $profiletel->saveTels($page->pid(), 'tel', $job['w_phone']);
263 class ProfileSettingJobs
extends ProfilePage
265 protected $pg_template = 'profile/jobs.tpl';
267 public function __construct(PlWizard
&$wiz)
269 parent
::__construct($wiz);
270 $this->settings
['cv'] = null
;
271 $this->settings
['corps'] = null
;
272 $this->settings
['jobs'] = new ProfileSettingJob();
273 $this->watched
= array('cv' => true
, 'jobs' => true
, 'corps' => true
);
276 protected function _fetchData()
279 $res = XDB
::query("SELECT cv
283 $this->values
['cv'] = $res->fetchOneCell();
285 // Checkout the corps
286 $res = XDB
::query("SELECT original_corpsid AS original, current_corpsid AS current,
287 rankid AS rank, corps_pub AS pub
291 $this->values
['corps'] = $res->fetchOneAssoc();
293 // Build the jobs tree
294 $res = XDB
::iterRow("SELECT j.id, j.jobid, je.name, j.sectorid, j.subsectorid, j.subsubsectorid,
295 s.name, j.description, j.email, j.email_pub, j.url, j.pub,
296 je.acronym, je.url, je.email,
297 aw.accuracy, aw.text, aw.postalText, aw.postalCode, aw.localityId,
298 aw.subAdministrativeAreaId, aw.administrativeAreaId, aw.countryId,
299 aw.latitude, aw.longitude, aw.pub, aw.updateTime,
300 aw.north, aw.south, aw.east, aw.west,
301 ah.accuracy, ah.text, ah.postalText, ah.postalCode, ah.localityId,
302 ah.subAdministrativeAreaId, ah.administrativeAreaId, ah.countryId,
303 ah.latitude, ah.longitude, ah.pub, ah.updateTime,
304 ah.north, ah.south, ah.east, ah.west
305 FROM profile_job AS j
306 LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id)
307 LEFT JOIN profile_job_subsubsector_enum AS s ON (s.id = j.subsubsectorid)
308 LEFT JOIN profile_addresses AS aw ON (aw.pid = j.pid AND aw.type = 'job'
310 LEFT JOIN profile_addresses AS ah ON (ah.jobid = j.jobid AND ah.type = 'hq')
314 $this->values
['jobs'] = array();
316 if ($res->numRows() > 0) {
317 while (list($id, $jobid, $name, $sector, $subSector, $subSubSector,
318 $subSubSectorName, $description, $w_email, $w_emailPub, $w_url, $pub,
319 $hq_acronym, $hq_url, $hq_email,
320 $w_accuracy, $w_text, $w_postalText, $w_postalCode, $w_localityId,
321 $w_subAdministrativeAreaId, $w_administrativeAreaId, $w_countryId,
322 $w_latitude, $w_longitude, $w_pub, $w_updateTime,
323 $w_north, $w_south, $w_east, $w_west,
324 $hq_accuracy, $hq_text, $hq_postalText, $hq_postalCode, $hq_localityId,
325 $hq_subAdministrativeAreaId, $hq_administrativeAreaId, $hq_countryId,
326 $hq_latitude, $hq_longitude, $hq_pub, $hq_updateTime,
327 $hq_north, $hq_south, $hq_east, $hq_west,
329 $this->values
['jobs'][] = array(
334 'subSector' => $subSector,
335 'subSubSector' => $subSubSector,
336 'subSubSectorName' => $subSubSectorName,
337 'description' => $description,
339 'w_email' => $w_email,
340 'w_email_pub' => $w_emailPub,
342 'hq_acronym' => $hq_acronym,
344 'hq_email' => $hq_email,
345 'w_address' => array(
346 'accuracy' => $w_accuracy,
348 'postalText' => $w_postalText,
349 'postalCode' => $w_postalCode,
350 'localityId' => $w_localityId,
351 'subAdministrativeAreaId' => $w_subAdministrativeAreaId,
352 'administrativeAreaId' => $w_administrativeAreaId,
353 'countryId' => $w_countryId,
354 'latitude' => $w_latitude,
355 'longitude' => $w_longitude,
357 'updateTime' => $w_updateTime,
363 'hq_address' => array(
364 'accuracy' => $hq_accuracy,
366 'postalText' => $hq_postalText,
367 'postalCode' => $hq_postalCode,
368 'localityId' => $hq_localityId,
369 'subAdministrativeAreaId' => $hq_subAdministrativeAreaId,
370 'administrativeAreaId' => $hq_administrativeAreaId,
371 'countryId' => $hq_countryId,
372 'latitude' => $hq_latitude,
373 'longitude' => $hq_longitude,
375 'updateTime' => $hq_updateTime,
376 'north' => $hq_north,
377 'south' => $hq_south,
384 $res = XDB
::iterator("SELECT link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment
386 WHERE pid = {?} AND link_type = 'pro'
390 $jobNb = count($this->values
['jobs']);
391 while ($phone = $res->next()) {
392 $jobid = $phone['jobid'];
393 while ($i < $jobNb && $this->values
['jobs'][$i]['id'] < $jobid) {
399 $job =& $this->values
['jobs'][$i];
400 if (!isset($job['w_phone'])) {
401 $job['w_phone'] = array();
403 if ($job['id'] == $jobid) {
404 $job['w_phone'][] = $phone;
407 foreach ($this->values
['jobs'] as $id => &$job) {
408 if (!isset($job['w_phone'])) {
409 $job['w_phone'] = array(
420 $job['w_email_new'] = '';
421 if (!isset($job['hq_phone'])) {
422 $job['hq_phone'] = '';
424 if (!isset($job['hq_fax'])) {
427 if (!isset($job['w_email_pub'])) {
428 $job['w_email_pub'] = 'private';
430 if (!$job['hq_address']['text']) {
431 $job['hq_address'] = array(
436 'administrativeAreaId' => '',
437 'subAdministrativeAreaId' => '',
452 $job['w_address']['cedex'] = '';
453 $job['w_address']['changed'] = '0';
454 $job['w_address']['removed'] = '0';
456 $this->values
['jobs'][] = $this->settings
['jobs']->emptyJob();
460 protected function _saveData()
462 if ($this->changed
['cv']) {
463 XDB
::execute("UPDATE profiles
466 $this->values
['cv'], $this->pid());
469 if ($this->changed
['corps']) {
470 XDB
::execute('REPLACE INTO profile_corps (original_corpsid, current_corpsid, rankid, corps_pub, pid)
471 VALUES ({?}, {?}, {?}, {?}, {?})',
472 $this->values
['corps']['original'], $this->values
['corps']['current'],
473 $this->values
['corps']['rank'], $this->values
['corps']['pub'], $this->pid());
477 public function _prepare(PlPage
&$page, $id)
479 require_once 'emails.combobox.inc.php';
480 fill_email_combobox($page, $this->owner
, $this->profile
);
482 $res = XDB
::query("SELECT id, name AS label
483 FROM profile_job_sector_enum");
484 $page->assign('sectors', $res->fetchAllAssoc());
486 $res = XDB
::iterator("SELECT id, name
487 FROM profile_corps_enum
488 ORDER BY id = 1 DESC, name");
489 $page->assign('original_corps', $res->fetchAllAssoc());
491 $res = XDB
::iterator("SELECT id, name
492 FROM profile_corps_enum
493 WHERE still_exists = 1
494 ORDER BY id = 1 DESC, name");
495 $page->assign('current_corps', $res->fetchAllAssoc());
497 $res = XDB
::iterator("SELECT id, name
498 FROM profile_corps_rank_enum
499 ORDER BY id = 1 DESC, name");
500 $page->assign('corps_rank', $res->fetchAllAssoc());
504 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: