2d03924d2fc41d0825a43f3a9c5dfcc159212259
2 /***************************************************************************
3 * Copyright (C) 2003-2009 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 ProfileGeocoding
31 public function __construct()
33 $this->pub
= new ProfilePub();
37 $this->url
= new ProfileWeb();
38 $this->bool
= new ProfileBool();
39 $this->checks
= array('url' => array('w_url'),
40 'email' => array('w_email'),
41 'pub' => array('pub', 'w_email_pub'),
45 private function cleanJob(ProfilePage
&$page, $jobid, array &$job, &$success)
48 if ($job['w_email'] == "new@example.org") {
49 $job['w_email'] = $job['w_email_new'];
51 foreach ($this->checks
as $obj=>&$fields) {
53 foreach ($fields as $field) {
54 $job[$field] = $chk->value($page, $field, $job[$field], $s);
57 $job[$field . '_error'] = true
;
61 if (!$job['subSubSectorName']) {
62 $res = XDB
::query("SELECT name
63 FROM profile_job_subsubsector_enum
65 $job['subSubSector']);
66 $job['subSubSectorName'] = $res->fetchOneCell();
68 $res = XDB
::query("SELECT sectorid, subsectorid, id
69 FROM profile_job_subsubsector_enum
71 $job['subSubSectorName']);
72 if ($res->numRows() != 1) {
74 $job['sector_error'] = true
;
76 list($job['sector'], $job['subSector'], $job['subSubSector']) = $res->fetchOneRow();
80 $res = XDB
::query("SELECT id
84 if ($res->numRows() != 1) {
86 $req = new EntrReq($user, $jobid, $job['name'], $job['hq_²acronym'], $job['hq_url'], $job['hq_email'], $job['hq_fixed'], $job['hq_fax']);
90 $job['jobid'] = $res->fetchOneCell();
93 $job['w_address']['pub'] = $this->pub
->value($page, 'address_pub', $job['w_address']['pub'], $s);
94 if (!isset($job['w_phone'])) {
95 $job['w_phone'] = array();
97 $profiletel = new ProfilePhones('pro', $jobid);
98 $job['w_phone'] = $profiletel->value($page, 'tel', $job['w_phone'], $s);
99 unset($job['removed']);
103 public function value(ProfilePage
&$page, $field, $value, &$success)
105 require_once('validations.inc.php');
106 $entreprise = Validate
::get_typed_requests(S
::i('uid'), 'entreprise');
110 if (is_null($value)) {
111 $value = $page->values
['jobs'];
115 foreach ($value as $key=>&$job) {
116 $job['name'] = trim($job['name']);
118 $job['tmp_name'] = $entreprise[$entr_val]->name
;
121 if (isset($job['removed']) && $job['removed']) {
125 foreach ($value as $key=>&$job) {
127 $this->geocodeAddress($job['w_address'], $s);
129 $this->cleanJob($page, $key, $job, $s);
132 $success = ($success && $ls);
138 public function save(ProfilePage
&$page, $field, $value)
140 require_once('profil.func.inc.php');
141 require_once('validations.inc.php');
143 XDB
::execute("DELETE FROM profile_job
146 XDB
::execute("DELETE FROM profile_addresses
147 WHERE pid = {?} AND type = 'job'",
149 XDB
::execute("DELETE FROM profile_phones
150 WHERE uid = {?} AND link_type = 'pro'",
152 foreach ($value as $id=>&$job) {
154 XDB
::execute("INSERT INTO profile_job (uid, id, functionid, description, sectorid, subsectorid,
155 subsubsectorid, email, url, pub, email_pub, jobid)
156 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
157 S
::i('uid'), $id, $job['fonction'], $job['description'], $job['sector'], $job['subSector'],
158 $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']);
160 XDB
::execute("INSERT INTO profile_job (uid, id, functionid, description, sectorid, subsectorid,
161 subsubsectorid, email, url, pub, email_pub)
162 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
163 S
::i('uid'), $id, $job['fonction'], $job['description'], $job['sector'], $job['subSector'],
164 $job['subSubSector'], $job['w_email'], $job['w_url'], $job['pub'], $job['w_email_pub']);
166 $address = new ProfileAddress();
167 $address->saveAddress($id, $job['w_address'], 'job');
168 $profiletel = new ProfilePhones('pro', $id);
169 $profiletel->saveTels('tel', $job['w_phone']);
174 class ProfileJobs
extends ProfilePage
176 protected $pg_template = 'profile/jobs.tpl';
178 public function __construct(PlWizard
&$wiz)
180 parent
::__construct($wiz);
181 $this->settings
['cv'] = null
;
182 $this->settings
['corps'] = null
;
183 $this->settings
['jobs'] = new ProfileJob();
184 $this->watched
= array('cv' => true
, 'jobs' => true
, 'corps' => true
);
187 protected function _fetchData()
190 $res = XDB
::query("SELECT cv
192 WHERE user_id = {?}",
194 $this->values
['cv'] = $res->fetchOneCell();
196 // Checkout the corps
197 $res = XDB
::query("SELECT original_corpsid AS original, current_corpsid AS current,
198 rankid AS rank, corps_pub AS pub
202 $this->values
['corps'] = $res->fetchOneAssoc();
204 // Build the jobs tree
205 $res = XDB
::iterRow("SELECT j.id, j.jobid, je.name, j.functionid, j.sectorid, j.subsectorid, j.subsubsectorid,
206 s.name, j.description, j.email, j.email_pub, j.url, j.pub,
207 je.acronym, je.url, je.email,
208 aw.accuracy, aw.text, aw.postalText, aw.postalCode, aw.localityId,
209 aw.subAdministrativeAreaId, aw.administrativeAreaId, aw.countryId,
210 aw.latitude, aw.longitude, aw.pub, aw.updateTime,
211 aw.north, aw.south, aw.east, aw.west,
212 ah.accuracy, ah.text, ah.postalText, ah.postalCode, ah.localityId,
213 ah.subAdministrativeAreaId, ah.administrativeAreaId, ah.countryId,
214 ah.latitude, ah.longitude, ah.pub, ah.updateTime,
215 ah.north, ah.south, ah.east, ah.west
216 FROM profile_job AS j
217 LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id)
218 LEFT JOIN profile_job_subsubsector_enum AS s ON (s.id = j.subsubsectorid)
219 LEFT JOIN profile_addresses AS aw ON (aw.pid = j.uid AND aw.type = 'job')
220 LEFT JOIN profile_addresses AS ah ON (ah.jobid = j.jobid AND ah.type = 'hq')
224 $this->values
['jobs'] = array();
225 while (list($id, $jobid, $name, $function, $sector, $subSector, $subSubSector,
226 $subSubSectorName, $description, $w_email, $w_emailPub, $w_url, $pub,
227 $hq_acronym, $hq_url, $hq_email,
228 $w_accuracy, $w_text, $w_postalText, $w_postalCode, $w_localityId,
229 $w_subAdministrativeAreaId, $w_administrativeAreaId, $w_countryId,
230 $w_latitude, $w_longitude, $w_pub, $w_updateTime,
231 $w_north, $w_south, $w_east, $w_west,
232 $hq_accuracy, $hq_text, $hq_postalText, $hq_postalCode, $hq_localityId,
233 $hq_subAdministrativeAreaId, $hq_administrativeAreaId, $hq_countryId,
234 $hq_latitude, $hq_longitude, $hq_pub, $hq_updateTime,
235 $hq_north, $hq_south, $hq_east, $hq_west,
237 $this->values
['jobs'][] = array('id' => $id,
240 'function' => $function,
242 'subSector' => $subSector,
243 'subSubSector' => $subSubSector,
244 'subSubSectorName' => $subSubSectorName,
245 'description' => $description,
247 'w_email' => $w_email,
248 'w_email_pub' => $w_email_pub,
250 'hq_acronym' => $hq_acronym,
252 'hq_email' => $hq_email,
253 'w_address' => array('accuracy' => $w_accuracy,
255 'postalText' => $w_postalText,
256 'postalCode' => $w_postalCode,
257 'localityId' => $w_localityId,
258 'subAdministrativeAreaId' => $w_subAdministrativeAreaId,
259 'administrativeAreaId' => $w_administrativeAreaId,
260 'countryId' => $w_countryId,
261 'latitude' => $w_latitude,
262 'longitude' => $w_longitude,
264 'updateTime' => $w_update,
270 'hq_address' => array('accuracy' => $hq_accuracy,
272 'postalText' => $hq_postalText,
273 'postalCode' => $hq_postalCode,
274 'localityId' => $hq_localityId,
275 'subAdministrativeAreaId' => $hq_subAdministrativeAreaId,
276 'administrativeAreaId' => $hq_administrativeAreaId,
277 'countryId' => $hq_countryId,
278 'latitude' => $hq_latitude,
279 'longitude' => $hq_longitude,
281 'updateTime' => $hq_update,
282 'north' => $hq_north,
283 'south' => $hq_south,
290 $res = XDB
::iterator("SELECT link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment
292 WHERE uid = {?} AND link_type = 'pro'
296 $jobNb = count($this->values
['jobs']);
297 while ($phone = $res->next()) {
298 $jobid = $phone['jobid'];
299 while ($i < $jobNb && $this->values
['jobs'][$i]['id'] < $jobid) {
305 $job =& $this->values
['jobs'][$i];
306 if (!isset($job['w_phone'])) {
307 $job['w_phone'] = array();
309 if ($job['id'] == $jobid) {
310 $job['w_phone'][] = $phone;
313 foreach ($this->values
['jobs'] as $id => &$job) {
314 if (!isset($job['w_phone'])) {
315 $job['w_phone'] = array();
320 protected function _saveData()
322 if ($this->changed
['cv']) {
323 XDB
::execute("UPDATE auth_user_md5
325 WHERE user_id = {?}",
326 $this->values
['cv'], S
::i('uid'));
329 if ($this->changed
['corps']) {
330 XDB
::execute("UPDATE profile_corps
331 SET original_corpsid = {?}, current_corpsid = {?},
332 rankid = {?}, corps_pub = {?}
334 $this->values
['corps']['original'], $this->values
['corps']['current'],
335 $this->values
['corps']['rank'], $this->values
['corps']['pub'], S
::i('uid'));
339 public function _prepare(PlPage
&$page, $id)
341 require_once "emails.combobox.inc.php";
342 fill_email_combobox($page);
344 $res = XDB
::query("SELECT id, name AS label
345 FROM profile_job_sector_enum");
346 $page->assign('sectors', $res->fetchAllAssoc());
347 $res = XDB
::query("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
350 $page->assign('functions', $res->fetchAllAssoc());
352 $res = XDB
::iterator("SELECT id, name
353 FROM profile_corps_enum
354 ORDER BY id = 1 DESC, name");
355 $page->assign('original_corps', $res->fetchAllAssoc());
357 $res = XDB
::iterator("SELECT id, name
358 FROM profile_corps_enum
359 WHERE still_exists = 1
360 ORDER BY id = 1 DESC, name");
361 $page->assign('current_corps', $res->fetchAllAssoc());
363 $res = XDB
::iterator("SELECT id, name
364 FROM profile_corps_rank_enum");
365 $page->assign('corps_rank', $res->fetchAllAssoc());
369 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: