Commit | Line | Data |
---|---|---|
3950bc21 FB |
1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
3950bc21 FB |
4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
73f6c165 | 22 | class ProfileJob extends ProfileGeocoding |
37d44b3b FB |
23 | { |
24 | private $pub; | |
541e8d03 SJ |
25 | private $email_new; |
26 | private $email; | |
27 | private $url; | |
f93fb300 | 28 | private $bool; |
37d44b3b FB |
29 | private $checks; |
30 | ||
31 | public function __construct() | |
32 | { | |
c7139c07 | 33 | $this->pub = new ProfilePub(); |
541e8d03 SJ |
34 | $this->email |
35 | = $this->email_new | |
c7139c07 | 36 | = new ProfileEmail(); |
541e8d03 | 37 | $this->url = new ProfileWeb(); |
c7139c07 | 38 | $this->bool = new ProfileBool(); |
541e8d03 SJ |
39 | $this->checks = array('url' => array('w_url'), |
40 | 'email' => array('w_email'), | |
41 | 'pub' => array('pub', 'w_email_pub'), | |
42 | ); | |
37d44b3b FB |
43 | } |
44 | ||
b814a8b8 | 45 | private function cleanJob(ProfilePage &$page, $jobid, array &$job, &$success) |
37d44b3b FB |
46 | { |
47 | $success = true; | |
541e8d03 SJ |
48 | if ($job['w_email'] == "new@example.org") { |
49 | $job['w_email'] = $job['w_email_new']; | |
50 | } | |
37d44b3b FB |
51 | foreach ($this->checks as $obj=>&$fields) { |
52 | $chk =& $this->$obj; | |
53 | foreach ($fields as $field) { | |
54 | $job[$field] = $chk->value($page, $field, $job[$field], $s); | |
55 | if (!$s) { | |
56 | $success = false; | |
57 | $job[$field . '_error'] = true; | |
58 | } | |
59 | } | |
60 | } | |
541e8d03 | 61 | if (!$job['subSubSectorName']) { |
c7139c07 SJ |
62 | $res = XDB::query("SELECT name |
63 | FROM profile_job_subsubsector_enum | |
64 | WHERE id = {?}", | |
541e8d03 SJ |
65 | $job['subSubSector']); |
66 | $job['subSubSectorName'] = $res->fetchOneCell(); | |
c7139c07 SJ |
67 | } else { |
68 | $res = XDB::query("SELECT sectorid, subsectorid, id | |
69 | FROM profile_job_subsubsector_enum | |
70 | WHERE name = {?}", | |
541e8d03 | 71 | $job['subSubSectorName']); |
c7139c07 SJ |
72 | if ($res->numRows() != 1) { |
73 | $success = false; | |
74 | $job['sector_error'] = true; | |
75 | } else { | |
541e8d03 | 76 | list($job['sector'], $job['subSector'], $job['subSubSector']) = $res->fetchOneRow(); |
c7139c07 SJ |
77 | } |
78 | } | |
b814a8b8 | 79 | if ($job['name']) { |
c7139c07 SJ |
80 | $res = XDB::query("SELECT id |
81 | FROM profile_job_enum | |
82 | WHERE name = {?}", | |
83 | $job['name']); | |
84 | if ($res->numRows() != 1) { | |
b814a8b8 | 85 | $user = S::user(); |
4d7d27fc SJ |
86 | $this->geocodeAddress($job['hq_address'], $s); |
87 | if (!$s) { | |
88 | $gmapsGeocoder = new GMapsGeocoder(); | |
89 | $job['hq_address'] = $gmapsGeocoder->stripGeocodingFromAddress($job['hq_address']); | |
90 | } | |
91 | $req = new EntrReq($user, $jobid, $job['name'], $job['hq_acronym'], $job['hq_url'], | |
92 | $job['hq_email'], $job['hq_fixed'], $job['hq_fax'], $job['hq_address']); | |
b814a8b8 SJ |
93 | $req->submit(); |
94 | $job['jobid'] = null; | |
c7139c07 SJ |
95 | } else { |
96 | $job['jobid'] = $res->fetchOneCell(); | |
97 | } | |
98 | } | |
541e8d03 SJ |
99 | $job['w_address']['pub'] = $this->pub->value($page, 'address_pub', $job['w_address']['pub'], $s); |
100 | if (!isset($job['w_phone'])) { | |
101 | $job['w_phone'] = array(); | |
bde2be3b GB |
102 | } |
103 | $profiletel = new ProfilePhones('pro', $jobid); | |
541e8d03 | 104 | $job['w_phone'] = $profiletel->value($page, 'tel', $job['w_phone'], $s); |
37d44b3b FB |
105 | unset($job['removed']); |
106 | unset($job['new']); | |
37d44b3b FB |
107 | } |
108 | ||
109 | public function value(ProfilePage &$page, $field, $value, &$success) | |
110 | { | |
b814a8b8 SJ |
111 | require_once('validations.inc.php'); |
112 | $entreprise = Validate::get_typed_requests(S::i('uid'), 'entreprise'); | |
113 | $entr_val = 0; | |
114 | ||
37d44b3b FB |
115 | $init = false; |
116 | if (is_null($value)) { | |
117 | $value = $page->values['jobs']; | |
118 | $init = true; | |
119 | } | |
120 | $success = true; | |
121 | foreach ($value as $key=>&$job) { | |
b814a8b8 | 122 | $job['name'] = trim($job['name']); |
0345fc9d | 123 | if (!$job['name'] && $entreprise) { |
b814a8b8 SJ |
124 | $job['tmp_name'] = $entreprise[$entr_val]->name; |
125 | $entr_val ++; | |
126 | } | |
541e8d03 | 127 | if (isset($job['removed']) && $job['removed']) { |
37d44b3b FB |
128 | unset($value[$key]); |
129 | } | |
130 | } | |
131 | foreach ($value as $key=>&$job) { | |
132 | $ls = true; | |
541e8d03 | 133 | $this->geocodeAddress($job['w_address'], $s); |
37d44b3b | 134 | $ls = ($ls && $s); |
bde2be3b | 135 | $this->cleanJob($page, $key, $job, $s); |
37d44b3b FB |
136 | $ls = ($ls && $s); |
137 | if (!$init) { | |
138 | $success = ($success && $ls); | |
139 | } | |
140 | } | |
141 | return $value; | |
142 | } | |
143 | ||
144 | public function save(ProfilePage &$page, $field, $value) | |
145 | { | |
ecad8a08 SJ |
146 | // TODO: use address and phone classes to update profile_job_enum and profile_phones once they are done. |
147 | ||
5e4417a9 | 148 | require_once('profil.func.inc.php'); |
b814a8b8 SJ |
149 | require_once('validations.inc.php'); |
150 | ||
c7139c07 | 151 | XDB::execute("DELETE FROM profile_job |
37d44b3b FB |
152 | WHERE uid = {?}", |
153 | S::i('uid')); | |
541e8d03 SJ |
154 | XDB::execute("DELETE FROM profile_addresses |
155 | WHERE pid = {?} AND type = 'job'", | |
156 | S::i('uid')); | |
b235d980 | 157 | XDB::execute("DELETE FROM profile_phones |
5e4417a9 GB |
158 | WHERE uid = {?} AND link_type = 'pro'", |
159 | S::i('uid')); | |
b814a8b8 | 160 | foreach ($value as $id=>&$job) { |
0345fc9d | 161 | if (isset($job['jobid']) && $job['jobid']) { |
563f86f5 | 162 | XDB::execute("INSERT INTO profile_job (uid, id, description, sectorid, subsectorid, |
b814a8b8 SJ |
163 | subsubsectorid, email, url, pub, email_pub, jobid) |
164 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
563f86f5 | 165 | S::i('uid'), $id, $job['description'], $job['sector'], $job['subSector'], |
541e8d03 | 166 | $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']); |
b814a8b8 | 167 | } else { |
563f86f5 | 168 | XDB::execute("INSERT INTO profile_job (uid, id, description, sectorid, subsectorid, |
b814a8b8 | 169 | subsubsectorid, email, url, pub, email_pub) |
0345fc9d | 170 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", |
563f86f5 | 171 | S::i('uid'), $id, $job['description'], $job['sector'], $job['subSector'], |
541e8d03 | 172 | $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub']); |
b814a8b8 | 173 | } |
541e8d03 SJ |
174 | $address = new ProfileAddress(); |
175 | $address->saveAddress($id, $job['w_address'], 'job'); | |
b814a8b8 | 176 | $profiletel = new ProfilePhones('pro', $id); |
541e8d03 | 177 | $profiletel->saveTels('tel', $job['w_phone']); |
37d44b3b FB |
178 | } |
179 | } | |
180 | } | |
181 | ||
3950bc21 FB |
182 | class ProfileJobs extends ProfilePage |
183 | { | |
184 | protected $pg_template = 'profile/jobs.tpl'; | |
185 | ||
186 | public function __construct(PlWizard &$wiz) | |
187 | { | |
188 | parent::__construct($wiz); | |
37d44b3b | 189 | $this->settings['cv'] = null; |
72e96bc0 | 190 | $this->settings['corps'] = null; |
37d44b3b | 191 | $this->settings['jobs'] = new ProfileJob(); |
72e96bc0 | 192 | $this->watched = array('cv' => true, 'jobs' => true, 'corps' => true); |
37d44b3b FB |
193 | } |
194 | ||
7c2e0f0d | 195 | protected function _fetchData() |
37d44b3b | 196 | { |
37d44b3b FB |
197 | // Checkout the CV |
198 | $res = XDB::query("SELECT cv | |
199 | FROM auth_user_md5 | |
200 | WHERE user_id = {?}", | |
201 | S::i('uid')); | |
202 | $this->values['cv'] = $res->fetchOneCell(); | |
203 | ||
72e96bc0 SJ |
204 | // Checkout the corps |
205 | $res = XDB::query("SELECT original_corpsid AS original, current_corpsid AS current, | |
206 | rankid AS rank, corps_pub AS pub | |
207 | FROM profile_corps | |
208 | WHERE uid = {?}", | |
209 | S::i('uid')); | |
210 | $this->values['corps'] = $res->fetchOneAssoc(); | |
211 | ||
37d44b3b | 212 | // Build the jobs tree |
563f86f5 | 213 | $res = XDB::iterRow("SELECT j.id, j.jobid, je.name, j.sectorid, j.subsectorid, j.subsubsectorid, |
541e8d03 SJ |
214 | s.name, j.description, j.email, j.email_pub, j.url, j.pub, |
215 | je.acronym, je.url, je.email, | |
216 | aw.accuracy, aw.text, aw.postalText, aw.postalCode, aw.localityId, | |
217 | aw.subAdministrativeAreaId, aw.administrativeAreaId, aw.countryId, | |
218 | aw.latitude, aw.longitude, aw.pub, aw.updateTime, | |
219 | aw.north, aw.south, aw.east, aw.west, | |
220 | ah.accuracy, ah.text, ah.postalText, ah.postalCode, ah.localityId, | |
221 | ah.subAdministrativeAreaId, ah.administrativeAreaId, ah.countryId, | |
222 | ah.latitude, ah.longitude, ah.pub, ah.updateTime, | |
223 | ah.north, ah.south, ah.east, ah.west | |
c7139c07 SJ |
224 | FROM profile_job AS j |
225 | LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id) | |
c7139c07 | 226 | LEFT JOIN profile_job_subsubsector_enum AS s ON (s.id = j.subsubsectorid) |
4d7d27fc SJ |
227 | LEFT JOIN profile_addresses AS aw ON (aw.pid = j.uid AND aw.type = 'job' |
228 | AND aw.id = j.id) | |
541e8d03 | 229 | LEFT JOIN profile_addresses AS ah ON (ah.jobid = j.jobid AND ah.type = 'hq') |
c7139c07 | 230 | WHERE j.uid = {?} |
541e8d03 SJ |
231 | ORDER BY j.id", |
232 | S::i('uid')); | |
37d44b3b | 233 | $this->values['jobs'] = array(); |
563f86f5 | 234 | while (list($id, $jobid, $name, $sector, $subSector, $subSubSector, |
541e8d03 SJ |
235 | $subSubSectorName, $description, $w_email, $w_emailPub, $w_url, $pub, |
236 | $hq_acronym, $hq_url, $hq_email, | |
237 | $w_accuracy, $w_text, $w_postalText, $w_postalCode, $w_localityId, | |
238 | $w_subAdministrativeAreaId, $w_administrativeAreaId, $w_countryId, | |
239 | $w_latitude, $w_longitude, $w_pub, $w_updateTime, | |
240 | $w_north, $w_south, $w_east, $w_west, | |
241 | $hq_accuracy, $hq_text, $hq_postalText, $hq_postalCode, $hq_localityId, | |
242 | $hq_subAdministrativeAreaId, $hq_administrativeAreaId, $hq_countryId, | |
243 | $hq_latitude, $hq_longitude, $hq_pub, $hq_updateTime, | |
244 | $hq_north, $hq_south, $hq_east, $hq_west, | |
bde2be3b | 245 | ) = $res->next()) { |
c7139c07 | 246 | $this->values['jobs'][] = array('id' => $id, |
541e8d03 | 247 | 'jobid' => $jobid, |
c7139c07 | 248 | 'name' => $name, |
541e8d03 SJ |
249 | 'sector' => $sector, |
250 | 'subSector' => $subSector, | |
251 | 'subSubSector' => $subSubSector, | |
252 | 'subSubSectorName' => $subSubSectorName, | |
c7139c07 | 253 | 'description' => $description, |
c7139c07 | 254 | 'pub' => $pub, |
541e8d03 SJ |
255 | 'w_email' => $w_email, |
256 | 'w_email_pub' => $w_email_pub, | |
257 | 'w_url' => $w_url, | |
258 | 'hq_acronym' => $hq_acronym, | |
259 | 'hq_url' => $hq_url, | |
260 | 'hq_email' => $hq_email, | |
261 | 'w_address' => array('accuracy' => $w_accuracy, | |
262 | 'text' => $w_text, | |
263 | 'postalText' => $w_postalText, | |
264 | 'postalCode' => $w_postalCode, | |
265 | 'localityId' => $w_localityId, | |
266 | 'subAdministrativeAreaId' => $w_subAdministrativeAreaId, | |
267 | 'administrativeAreaId' => $w_administrativeAreaId, | |
268 | 'countryId' => $w_countryId, | |
269 | 'latitude' => $w_latitude, | |
270 | 'longitude' => $w_longitude, | |
271 | 'pub' => $w_pub, | |
272 | 'updateTime' => $w_update, | |
273 | 'north' => $w_north, | |
274 | 'south' => $w_south, | |
275 | 'east' => $w_east, | |
276 | 'west' => $w_west, | |
277 | ), | |
278 | 'hq_address' => array('accuracy' => $hq_accuracy, | |
279 | 'text' => $hq_text, | |
280 | 'postalText' => $hq_postalText, | |
281 | 'postalCode' => $hq_postalCode, | |
282 | 'localityId' => $hq_localityId, | |
283 | 'subAdministrativeAreaId' => $hq_subAdministrativeAreaId, | |
284 | 'administrativeAreaId' => $hq_administrativeAreaId, | |
285 | 'countryId' => $hq_countryId, | |
286 | 'latitude' => $hq_latitude, | |
287 | 'longitude' => $hq_longitude, | |
288 | 'pub' => $hq_pub, | |
289 | 'updateTime' => $hq_update, | |
290 | 'north' => $hq_north, | |
291 | 'south' => $hq_south, | |
292 | 'east' => $hq_east, | |
293 | 'west' => $hq_west, | |
294 | ), | |
295 | ); | |
37d44b3b | 296 | } |
bde2be3b GB |
297 | |
298 | $res = XDB::iterator("SELECT link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment | |
299 | FROM profile_phones | |
300 | WHERE uid = {?} AND link_type = 'pro' | |
301 | ORDER BY link_id", | |
302 | S::i('uid')); | |
303 | $i = 0; | |
304 | $jobNb = count($this->values['jobs']); | |
541e8d03 SJ |
305 | while ($phone = $res->next()) { |
306 | $jobid = $phone['jobid']; | |
bde2be3b GB |
307 | while ($i < $jobNb && $this->values['jobs'][$i]['id'] < $jobid) { |
308 | $i++; | |
309 | } | |
310 | if ($i >= $jobNb) { | |
311 | break; | |
312 | } | |
313 | $job =& $this->values['jobs'][$i]; | |
541e8d03 SJ |
314 | if (!isset($job['w_phone'])) { |
315 | $job['w_phone'] = array(); | |
bde2be3b GB |
316 | } |
317 | if ($job['id'] == $jobid) { | |
541e8d03 | 318 | $job['w_phone'][] = $phone; |
bde2be3b GB |
319 | } |
320 | } | |
541e8d03 SJ |
321 | foreach ($this->values['jobs'] as $id => &$job) { |
322 | if (!isset($job['w_phone'])) { | |
323 | $job['w_phone'] = array(); | |
bde2be3b | 324 | } |
bde2be3b | 325 | } |
37d44b3b FB |
326 | } |
327 | ||
7c2e0f0d | 328 | protected function _saveData() |
37d44b3b FB |
329 | { |
330 | if ($this->changed['cv']) { | |
331 | XDB::execute("UPDATE auth_user_md5 | |
332 | SET cv = {?} | |
333 | WHERE user_id = {?}", | |
334 | $this->values['cv'], S::i('uid')); | |
335 | } | |
72e96bc0 SJ |
336 | |
337 | if ($this->changed['corps']) { | |
338 | XDB::execute("UPDATE profile_corps | |
339 | SET original_corpsid = {?}, current_corpsid = {?}, | |
340 | rankid = {?}, corps_pub = {?} | |
341 | WHERE uid = {?}", | |
342 | $this->values['corps']['original'], $this->values['corps']['current'], | |
343 | $this->values['corps']['rank'], $this->values['corps']['pub'], S::i('uid')); | |
344 | } | |
3950bc21 | 345 | } |
2dcac0f5 | 346 | |
04334c61 | 347 | public function _prepare(PlPage &$page, $id) |
2dcac0f5 | 348 | { |
b715c1e1 SJ |
349 | require_once "emails.combobox.inc.php"; |
350 | fill_email_combobox($page); | |
351 | ||
33b6f5a0 SJ |
352 | $res = XDB::query("SELECT id, name AS label |
353 | FROM profile_job_sector_enum"); | |
541e8d03 | 354 | $page->assign('sectors', $res->fetchAllAssoc()); |
72e96bc0 SJ |
355 | |
356 | $res = XDB::iterator("SELECT id, name | |
357 | FROM profile_corps_enum | |
358 | ORDER BY id = 1 DESC, name"); | |
359 | $page->assign('original_corps', $res->fetchAllAssoc()); | |
360 | ||
361 | $res = XDB::iterator("SELECT id, name | |
362 | FROM profile_corps_enum | |
363 | WHERE still_exists = 1 | |
364 | ORDER BY id = 1 DESC, name"); | |
365 | $page->assign('current_corps', $res->fetchAllAssoc()); | |
366 | ||
367 | $res = XDB::iterator("SELECT id, name | |
368 | FROM profile_corps_rank_enum"); | |
369 | $page->assign('corps_rank', $res->fetchAllAssoc()); | |
2dcac0f5 | 370 | } |
3950bc21 FB |
371 | } |
372 | ||
373 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
374 | ?> |