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 | ||
37d44b3b FB |
22 | class ProfileJob extends ProfileGeoloc |
23 | { | |
24 | private $pub; | |
b715c1e1 | 25 | private $mail_new; |
37d44b3b FB |
26 | private $mail; |
27 | private $web; | |
f93fb300 | 28 | private $bool; |
37d44b3b FB |
29 | private $checks; |
30 | ||
31 | public function __construct() | |
32 | { | |
c7139c07 | 33 | $this->pub = new ProfilePub(); |
b715c1e1 | 34 | $this->mail |
c7139c07 SJ |
35 | = $this->mail_new |
36 | = new ProfileEmail(); | |
37 | $this->web = new ProfileWeb(); | |
38 | $this->bool = new ProfileBool(); | |
39 | $this->checks = array('web' => array('w_web'), | |
40 | 'mail_new' => array('w_email_new'), | |
41 | 'mail' => array('w_email'), | |
42 | 'pub' => array('pub', 'w_email_pub')); | |
37d44b3b FB |
43 | } |
44 | ||
b814a8b8 | 45 | private function cleanJob(ProfilePage &$page, $jobid, array &$job, &$success) |
37d44b3b FB |
46 | { |
47 | $success = true; | |
48 | foreach ($this->checks as $obj=>&$fields) { | |
49 | $chk =& $this->$obj; | |
50 | foreach ($fields as $field) { | |
c7139c07 SJ |
51 | if ($field == "w_email_new") { |
52 | if ($job['w_email'] == "new@example.org") { | |
53 | $job['w_email'] = $job[$field]; | |
b715c1e1 SJ |
54 | } |
55 | continue; | |
56 | } | |
37d44b3b FB |
57 | $job[$field] = $chk->value($page, $field, $job[$field], $s); |
58 | if (!$s) { | |
59 | $success = false; | |
60 | $job[$field . '_error'] = true; | |
61 | } | |
62 | } | |
63 | } | |
b814a8b8 | 64 | if (!$job['sss_secteur_name']) { |
c7139c07 SJ |
65 | $res = XDB::query("SELECT name |
66 | FROM profile_job_subsubsector_enum | |
67 | WHERE id = {?}", | |
68 | $job['sss_secteur']); | |
69 | $job['sss_secteur_name'] = $res->fetchOneCell(); | |
70 | } else { | |
71 | $res = XDB::query("SELECT sectorid, subsectorid, id | |
72 | FROM profile_job_subsubsector_enum | |
73 | WHERE name = {?}", | |
74 | $job['sss_secteur_name']); | |
75 | if ($res->numRows() != 1) { | |
76 | $success = false; | |
77 | $job['sector_error'] = true; | |
78 | } else { | |
79 | list($job['secteur'], $job['ss_secteur'], $job['sss_secteur']) = $res->fetchOneRow(); | |
80 | } | |
81 | } | |
b814a8b8 | 82 | if ($job['name']) { |
c7139c07 SJ |
83 | $res = XDB::query("SELECT id |
84 | FROM profile_job_enum | |
85 | WHERE name = {?}", | |
86 | $job['name']); | |
87 | if ($res->numRows() != 1) { | |
b814a8b8 SJ |
88 | $user = S::user(); |
89 | $req = new EntrReq($user, $jobid, $job['name'], $job['acronym'], $job['hq_web'], $job['hq_email'], $job['hq_tel'], $job['hq_fax']); | |
90 | $req->submit(); | |
91 | $job['jobid'] = null; | |
c7139c07 SJ |
92 | } else { |
93 | $job['jobid'] = $res->fetchOneCell(); | |
94 | } | |
95 | } | |
96 | $job['w_adr']['pub'] = $this->pub->value($page, 'adr_pub', @$job['w_adr']['pub'], $s); | |
97 | $job['w_adr']['checked'] = $this->bool->value($page, 'adr_checked', @$job['w_adr']['checked'], $s); | |
98 | if (!isset($job['w_tel'])) { | |
99 | $job['w_tel'] = array(); | |
bde2be3b GB |
100 | } |
101 | $profiletel = new ProfilePhones('pro', $jobid); | |
c7139c07 | 102 | $job['w_tel'] = $profiletel->value($page, 'tel', $job['w_tel'], $s); |
37d44b3b FB |
103 | unset($job['removed']); |
104 | unset($job['new']); | |
c7139c07 SJ |
105 | unset($job['w_adr']['changed']); |
106 | unset($job['w_adr']['parsevalid']); | |
107 | unset($job['w_adr']['display']); | |
37d44b3b FB |
108 | } |
109 | ||
110 | public function value(ProfilePage &$page, $field, $value, &$success) | |
111 | { | |
b814a8b8 SJ |
112 | require_once('validations.inc.php'); |
113 | $entreprise = Validate::get_typed_requests(S::i('uid'), 'entreprise'); | |
114 | $entr_val = 0; | |
115 | ||
37d44b3b FB |
116 | $init = false; |
117 | if (is_null($value)) { | |
118 | $value = $page->values['jobs']; | |
119 | $init = true; | |
120 | } | |
121 | $success = true; | |
122 | foreach ($value as $key=>&$job) { | |
b814a8b8 SJ |
123 | $job['name'] = trim($job['name']); |
124 | if (!$job['name']) { | |
125 | $job['tmp_name'] = $entreprise[$entr_val]->name; | |
126 | $entr_val ++; | |
127 | } | |
128 | if (@$job['removed']) { | |
37d44b3b FB |
129 | unset($value[$key]); |
130 | } | |
131 | } | |
132 | foreach ($value as $key=>&$job) { | |
133 | $ls = true; | |
c7139c07 | 134 | $this->geolocAddress($job['w_adr'], $s); |
37d44b3b | 135 | $ls = ($ls && $s); |
bde2be3b | 136 | $this->cleanJob($page, $key, $job, $s); |
37d44b3b FB |
137 | $ls = ($ls && $s); |
138 | if (!$init) { | |
139 | $success = ($success && $ls); | |
140 | } | |
141 | } | |
142 | return $value; | |
143 | } | |
144 | ||
145 | public function save(ProfilePage &$page, $field, $value) | |
146 | { | |
5e4417a9 | 147 | require_once('profil.func.inc.php'); |
b814a8b8 SJ |
148 | require_once('validations.inc.php'); |
149 | ||
c7139c07 | 150 | XDB::execute("DELETE FROM profile_job |
37d44b3b FB |
151 | WHERE uid = {?}", |
152 | S::i('uid')); | |
b235d980 | 153 | XDB::execute("DELETE FROM profile_phones |
5e4417a9 GB |
154 | WHERE uid = {?} AND link_type = 'pro'", |
155 | S::i('uid')); | |
b814a8b8 | 156 | foreach ($value as $id=>&$job) { |
c7139c07 SJ |
157 | if ($job['w_email'] == "new@example.org") { |
158 | $job['w_email'] = $job['w_email_new']; | |
b715c1e1 | 159 | } |
b814a8b8 SJ |
160 | if ($job['jobid']) { |
161 | XDB::execute("INSERT INTO profile_job (uid, id, functionid, description, sectorid, subsectorid, | |
162 | subsubsectorid, email, url, pub, email_pub, jobid) | |
163 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
164 | S::i('uid'), $id, $job['fonction'], $job['description'], $job['secteur'], $job['ss_secteur'], | |
165 | $job['sss_secteur'], $job['w_email'], $job['w_web'], $job['pub'], $job['w_email_pub'], $job['jobid']); | |
166 | } else { | |
167 | XDB::execute("INSERT INTO profile_job (uid, id, functionid, description, sectorid, subsectorid, | |
168 | subsubsectorid, email, url, pub, email_pub) | |
169 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
170 | S::i('uid'), $id, $job['fonction'], $job['description'], $job['secteur'], $job['ss_secteur'], | |
171 | $job['sss_secteur'], $job['w_email'], $job['w_web'], $job['pub'], $job['w_email_pub']); | |
172 | } | |
173 | $profiletel = new ProfilePhones('pro', $id); | |
c7139c07 | 174 | $profiletel->saveTels('tel', $job['w_tel']); |
37d44b3b FB |
175 | } |
176 | } | |
177 | } | |
178 | ||
3950bc21 FB |
179 | class ProfileJobs extends ProfilePage |
180 | { | |
181 | protected $pg_template = 'profile/jobs.tpl'; | |
182 | ||
183 | public function __construct(PlWizard &$wiz) | |
184 | { | |
185 | parent::__construct($wiz); | |
37d44b3b | 186 | $this->settings['cv'] = null; |
72e96bc0 | 187 | $this->settings['corps'] = null; |
37d44b3b | 188 | $this->settings['jobs'] = new ProfileJob(); |
72e96bc0 | 189 | $this->watched = array('cv' => true, 'jobs' => true, 'corps' => true); |
37d44b3b FB |
190 | } |
191 | ||
7c2e0f0d | 192 | protected function _fetchData() |
37d44b3b | 193 | { |
37d44b3b FB |
194 | // Checkout the CV |
195 | $res = XDB::query("SELECT cv | |
e5bcd851 FB |
196 | FROM profiles |
197 | WHERE pid = {?}", | |
198 | $this->pid()); | |
37d44b3b FB |
199 | $this->values['cv'] = $res->fetchOneCell(); |
200 | ||
72e96bc0 SJ |
201 | // Checkout the corps |
202 | $res = XDB::query("SELECT original_corpsid AS original, current_corpsid AS current, | |
203 | rankid AS rank, corps_pub AS pub | |
204 | FROM profile_corps | |
205 | WHERE uid = {?}", | |
e5bcd851 | 206 | $this->pid()); |
72e96bc0 SJ |
207 | $this->values['corps'] = $res->fetchOneAssoc(); |
208 | ||
37d44b3b | 209 | // Build the jobs tree |
c7139c07 SJ |
210 | $res = XDB::iterRow("SELECT j.id, je.name, j.functionid, j.sectorid, j.subsectorid, |
211 | j.subsubsectorid, j.description, e.adr1, e.adr2, e.adr3, | |
37d44b3b FB |
212 | e.postcode, e.city, e.cityid, e.region, e.regiontxt, |
213 | e.country, gp.pays, gp.display, | |
f93fb300 | 214 | FIND_IN_SET('geoloc', flags), |
c7139c07 SJ |
215 | j.email, j.url, j.pub, |
216 | e.adr_pub, j.email_pub, | |
217 | e.glat, e.glng, s.name | |
218 | FROM profile_job AS j | |
219 | LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id) | |
220 | LEFT JOIN entreprises AS e ON (j.uid = e.uid AND j.id = e.entrid) | |
221 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.country) | |
222 | LEFT JOIN profile_job_subsubsector_enum AS s ON (s.id = j.subsubsectorid) | |
223 | WHERE j.uid = {?} | |
e5bcd851 | 224 | ORDER BY entrid", $this->pid()); |
37d44b3b | 225 | $this->values['jobs'] = array(); |
c7139c07 SJ |
226 | while (list($id, $name, $function, $secteur, $ss_secteur, $sss_secteur, $description, |
227 | $w_adr1, $w_adr2, $w_adr3, $w_postcode, $w_city, $w_cityid, | |
228 | $w_region, $w_regiontxt, $w_country, $w_countrytxt, $w_display, | |
229 | $w_checked, $w_email, $w_web, | |
230 | $pub, $w_adr_pub, $w_email_pub, $w_glat, $w_glng, $sss_secteur_name | |
bde2be3b | 231 | ) = $res->next()) { |
c7139c07 SJ |
232 | $this->values['jobs'][] = array('id' => $id, |
233 | 'name' => $name, | |
234 | 'fonction' => $function, | |
235 | 'secteur' => $secteur, | |
236 | 'ss_secteur' => $ss_secteur, | |
237 | 'sss_secteur' => $sss_secteur, | |
238 | 'sss_secteur_name' => $sss_secteur_name, | |
239 | 'description' => $description, | |
240 | 'w_adr' => array('adr1' => $w_adr1, | |
241 | 'adr2' => $w_adr2, | |
242 | 'adr3' => $w_adr3, | |
243 | 'postcode' => $w_postcode, | |
244 | 'city' => $w_city, | |
245 | 'cityid' => $w_cityid, | |
246 | 'region' => $w_region, | |
247 | 'regiontxt' => $w_regiontxt, | |
248 | 'country' => $w_country, | |
249 | 'countrytxt' => $w_countrytxt, | |
250 | 'display' => $w_display, | |
251 | 'pub' => $w_adr_pub, | |
252 | 'checked' => $w_checked, | |
253 | 'precise_lat' => $w_glat, | |
254 | 'precise_lon' => $w_glng), | |
255 | 'w_email' => $w_email, | |
256 | 'w_web' => $w_web, | |
257 | 'pub' => $pub, | |
258 | 'w_email_pub' => $w_email_pub); | |
37d44b3b | 259 | } |
bde2be3b GB |
260 | |
261 | $res = XDB::iterator("SELECT link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment | |
262 | FROM profile_phones | |
263 | WHERE uid = {?} AND link_type = 'pro' | |
264 | ORDER BY link_id", | |
e5bcd851 | 265 | $this->pid()); |
bde2be3b GB |
266 | $i = 0; |
267 | $jobNb = count($this->values['jobs']); | |
268 | while ($tel = $res->next()) { | |
269 | $jobid = $tel['jobid']; | |
270 | unset($tel['jobid']); | |
271 | while ($i < $jobNb && $this->values['jobs'][$i]['id'] < $jobid) { | |
272 | $i++; | |
273 | } | |
274 | if ($i >= $jobNb) { | |
275 | break; | |
276 | } | |
277 | $job =& $this->values['jobs'][$i]; | |
c7139c07 SJ |
278 | if (!isset($job['w_tel'])) { |
279 | $job['w_tel'] = array(); | |
bde2be3b GB |
280 | } |
281 | if ($job['id'] == $jobid) { | |
c7139c07 | 282 | $job['w_tel'][] = $tel; |
bde2be3b GB |
283 | } |
284 | } | |
285 | foreach ($this->values['jobs'] as $id=>&$job) { | |
c7139c07 SJ |
286 | if (!isset($job['w_tel'])) { |
287 | $job['w_tel'] = array(); | |
bde2be3b GB |
288 | } |
289 | unset($job['id']); | |
290 | } | |
37d44b3b FB |
291 | } |
292 | ||
7c2e0f0d | 293 | protected function _saveData() |
37d44b3b FB |
294 | { |
295 | if ($this->changed['cv']) { | |
e5bcd851 | 296 | XDB::execute("UPDATE profiles |
37d44b3b | 297 | SET cv = {?} |
e5bcd851 FB |
298 | WHERE pid = {?}", |
299 | $this->values['cv'], $this->pid()); | |
37d44b3b | 300 | } |
72e96bc0 SJ |
301 | |
302 | if ($this->changed['corps']) { | |
303 | XDB::execute("UPDATE profile_corps | |
304 | SET original_corpsid = {?}, current_corpsid = {?}, | |
305 | rankid = {?}, corps_pub = {?} | |
306 | WHERE uid = {?}", | |
307 | $this->values['corps']['original'], $this->values['corps']['current'], | |
e5bcd851 | 308 | $this->values['corps']['rank'], $this->values['corps']['pub'], $this->pid()); |
72e96bc0 | 309 | } |
3950bc21 | 310 | } |
2dcac0f5 | 311 | |
04334c61 | 312 | public function _prepare(PlPage &$page, $id) |
2dcac0f5 | 313 | { |
b715c1e1 | 314 | require_once "emails.combobox.inc.php"; |
e5bcd851 | 315 | fill_email_combobox($page, $this->owner, $this->profile); |
b715c1e1 | 316 | |
33b6f5a0 SJ |
317 | $res = XDB::query("SELECT id, name AS label |
318 | FROM profile_job_sector_enum"); | |
319 | $page->assign('secteurs', $res->fetchAllAssoc()); | |
320 | $res = XDB::query("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title | |
321 | FROM fonctions_def | |
322 | ORDER BY id"); | |
323 | $page->assign('fonctions', $res->fetchAllAssoc()); | |
72e96bc0 SJ |
324 | |
325 | $res = XDB::iterator("SELECT id, name | |
326 | FROM profile_corps_enum | |
327 | ORDER BY id = 1 DESC, name"); | |
328 | $page->assign('original_corps', $res->fetchAllAssoc()); | |
329 | ||
330 | $res = XDB::iterator("SELECT id, name | |
331 | FROM profile_corps_enum | |
332 | WHERE still_exists = 1 | |
333 | ORDER BY id = 1 DESC, name"); | |
334 | $page->assign('current_corps', $res->fetchAllAssoc()); | |
335 | ||
336 | $res = XDB::iterator("SELECT id, name | |
337 | FROM profile_corps_rank_enum"); | |
338 | $page->assign('corps_rank', $res->fetchAllAssoc()); | |
2dcac0f5 | 339 | } |
3950bc21 FB |
340 | } |
341 | ||
342 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
343 | ?> |