2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 ProfileJob
extends ProfileGeoloc
31 public function __construct()
33 $this->pub
= new ProfilePub();
34 $this->mail
= new ProfileEmail();
35 $this->web
= new ProfileWeb();
36 $this->tel
= new ProfileTel();
37 $this->bool
= new ProfileBool();
38 $this->checks
= array('web' => array('web'),
39 'mail' => array('email'),
40 'tel' => array('tel', 'fax', 'mobile'),
41 'pub' => array('pub', 'tel_pub', 'email_pub'));
44 private function cleanJob(ProfilePage
&$page, array &$job, &$success)
47 foreach ($this->checks
as $obj=>&$fields) {
49 foreach ($fields as $field) {
50 $job[$field] = $chk->value($page, $field, $job[$field], $s);
53 $job[$field . '_error'] = true
;
57 $job['adr']['pub'] = $this->pub
->value($page, 'adr_pub', @$job['adr']['pub'], $s);
58 $job['adr']['checked'] = $this->bool
->value($page, 'adr_checked', @$job['adr']['checked'], $s);
59 unset($job['removed']);
61 unset($job['adr']['changed']);
62 unset($job['adr']['parsevalid']);
63 unset($job['adr']['display']);
66 public function value(ProfilePage
&$page, $field, $value, &$success)
69 if (is_null($value)) {
70 $value = $page->values
['jobs'];
74 foreach ($value as $key=>&$job) {
75 if (@$job['removed'] ||
!trim($job['name'])) {
79 foreach ($value as $key=>&$job) {
81 $this->geolocAddress($job['adr'], $s);
83 $this->cleanJob($page, $job, $s);
86 $success = ($success && $ls);
92 public function save(ProfilePage
&$page, $field, $value)
94 XDB
::execute("DELETE FROM entreprises
98 foreach ($value as &$job) {
99 XDB
::execute("INSERT INTO entreprises (uid, entrid, entreprise, secteur, ss_secteur,
100 fonction, poste, adr1, adr2, adr3, postcode,
101 city, cityid, country, region, regiontxt,
102 tel, fax, mobile, email, web,
103 pub, adr_pub, tel_pub, email_pub, flags,
105 VALUES ({?}, {?}, {?}, {?}, {?},
106 {?}, {?}, {?}, {?}, {?}, {?},
107 {?}, {?}, {?}, {?}, {?},
108 {?}, {?}, {?}, {?}, {?},
109 {?}, {?}, {?}, {?}, {?},
111 S
::i('uid'), $i++
, $job['name'], $job['secteur'], $job['ss_secteur'],
112 $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'],
113 $job['adr']['postcode'],
114 $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'],
115 $job['adr']['regiontxt'],
116 $job['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'],
117 $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub'],
118 $job['adr']['checked'] ?
'geoloc' : '', $job['adr']['precise_lat'],
119 $job['adr']['precise_lon']);
124 class ProfileJobs
extends ProfilePage
126 protected $pg_template = 'profile/jobs.tpl';
128 public function __construct(PlWizard
&$wiz)
130 parent
::__construct($wiz);
131 $this->settings
['cv'] = null
;
132 $this->settings
['jobs'] = new ProfileJob();
133 $this->watched
['cv'] = $this->watched
['jobs'] = true
;
136 protected function _fetchData()
139 $res = XDB
::query("SELECT cv
141 WHERE user_id = {?}",
143 $this->values
['cv'] = $res->fetchOneCell();
145 // Build the jobs tree
146 $res = XDB
::iterRow("SELECT e.entreprise, e.secteur, e.ss_secteur,
147 e.fonction, e.poste, e.adr1, e.adr2, e.adr3,
148 e.postcode, e.city, e.cityid, e.region, e.regiontxt,
149 e.country, gp.pays, gp.display,
150 FIND_IN_SET('geoloc', flags),
151 e.tel, e.fax, e.mobile, e.email, e.web, e.pub,
152 e.adr_pub, e.tel_pub, e.email_pub,
153 e.glat AS precise_lat, e.glng AS precise_lon
154 FROM entreprises AS e
155 LEFT JOIN geoloc_pays AS gp ON(gp.a2 = e.country)
156 WHERE uid = {?} AND entreprise != ''
157 ORDER BY entrid", S
::i('uid'));
158 $this->values
['jobs'] = array();
159 while (list($name, $secteur, $ss_secteur, $fonction, $poste,
160 $adr1, $adr2, $adr3, $postcode, $city, $cityid,
161 $region, $regiontxt, $country, $countrytxt, $display,
162 $checked, $tel, $fax, $mobile, $email, $web,
163 $pub, $adr_pub, $tel_pub, $email_pub, $glat, $glng) = $res->next()) {
164 $this->values
['jobs'][] = array('name' => $name,
165 'secteur' => $secteur,
166 'ss_secteur' => $ss_secteur,
167 'fonction' => $fonction,
169 'adr' => array('adr1' => $adr1,
172 'postcode' => $postcode,
176 'regiontxt' => $regiontxt,
177 'country' => $country,
178 'countrytxt' => $countrytxt,
179 'display' => $display,
181 'checked' => $checked,
182 'precise_lat'=> $glat,
183 'precise_lon'=> $glng),
190 'tel_pub' => $tel_pub,
191 'email_pub' => $email_pub);
195 protected function _saveData()
197 if ($this->changed
['cv']) {
198 XDB
::execute("UPDATE auth_user_md5
200 WHERE user_id = {?}",
201 $this->values
['cv'], S
::i('uid'));
205 public function _prepare(PlPage
&$page, $id)
207 $page->assign('secteurs', XDB
::iterator("SELECT id, label
208 FROM emploi_secteur"));
209 $page->assign('fonctions', XDB
::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
215 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: