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->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'));
45 private function cleanJob(ProfilePage
&$page, $jobid, array &$job, &$success)
48 foreach ($this->checks
as $obj=>&$fields) {
50 foreach ($fields as $field) {
51 if ($field == "w_email_new") {
52 if ($job['w_email'] == "new@example.org") {
53 $job['w_email'] = $job[$field];
57 $job[$field] = $chk->value($page, $field, $job[$field], $s);
60 $job[$field . '_error'] = true
;
64 if (!$job['sss_secteur_name']) {
65 $res = XDB
::query("SELECT name
66 FROM profile_job_subsubsector_enum
69 $job['sss_secteur_name'] = $res->fetchOneCell();
71 $res = XDB
::query("SELECT sectorid, subsectorid, id
72 FROM profile_job_subsubsector_enum
74 $job['sss_secteur_name']);
75 if ($res->numRows() != 1) {
77 $job['sector_error'] = true
;
79 list($job['secteur'], $job['ss_secteur'], $job['sss_secteur']) = $res->fetchOneRow();
83 $res = XDB
::query("SELECT id
87 if ($res->numRows() != 1) {
89 $req = new EntrReq($user, $jobid, $job['name'], $job['acronym'], $job['hq_web'], $job['hq_email'], $job['hq_tel'], $job['hq_fax']);
93 $job['jobid'] = $res->fetchOneCell();
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();
101 $profiletel = new ProfilePhones('pro', $jobid);
102 $job['w_tel'] = $profiletel->value($page, 'tel', $job['w_tel'], $s);
103 unset($job['removed']);
105 unset($job['w_adr']['changed']);
106 unset($job['w_adr']['parsevalid']);
107 unset($job['w_adr']['display']);
110 public function value(ProfilePage
&$page, $field, $value, &$success)
112 require_once('validations.inc.php');
113 $entreprise = Validate
::get_typed_requests(S
::i('uid'), 'entreprise');
117 if (is_null($value)) {
118 $value = $page->values
['jobs'];
122 foreach ($value as $key=>&$job) {
123 $job['name'] = trim($job['name']);
125 $job['tmp_name'] = $entreprise[$entr_val]->name
;
128 if (@$job['removed']) {
132 foreach ($value as $key=>&$job) {
134 $this->geocodeAddress($job['w_adr'], $s);
136 $this->cleanJob($page, $key, $job, $s);
139 $success = ($success && $ls);
145 public function save(ProfilePage
&$page, $field, $value)
147 require_once('profil.func.inc.php');
148 require_once('validations.inc.php');
150 XDB
::execute("DELETE FROM profile_job
153 XDB
::execute("DELETE FROM profile_phones
154 WHERE uid = {?} AND link_type = 'pro'",
156 foreach ($value as $id=>&$job) {
157 if ($job['w_email'] == "new@example.org") {
158 $job['w_email'] = $job['w_email_new'];
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']);
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']);
173 $profiletel = new ProfilePhones('pro', $id);
174 $profiletel->saveTels('tel', $job['w_tel']);
179 class ProfileJobs
extends ProfilePage
181 protected $pg_template = 'profile/jobs.tpl';
183 public function __construct(PlWizard
&$wiz)
185 parent
::__construct($wiz);
186 $this->settings
['cv'] = null
;
187 $this->settings
['corps'] = null
;
188 $this->settings
['jobs'] = new ProfileJob();
189 $this->watched
= array('cv' => true
, 'jobs' => true
, 'corps' => true
);
192 protected function _fetchData()
195 $res = XDB
::query("SELECT cv
197 WHERE user_id = {?}",
199 $this->values
['cv'] = $res->fetchOneCell();
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
207 $this->values
['corps'] = $res->fetchOneAssoc();
209 // Build the jobs tree
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,
212 e.postcode, e.city, e.cityid, e.region, e.regiontxt,
213 e.country, gc.countryFR,
214 j.email, j.url, j.pub,
215 e.adr_pub, j.email_pub,
216 e.glat, e.glng, s.name
217 FROM profile_job AS j
218 LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id)
219 LEFT JOIN entreprises AS e ON (j.uid = e.uid AND j.id = e.entrid)
220 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = e.country)
221 LEFT JOIN profile_job_subsubsector_enum AS s ON (s.id = j.subsubsectorid)
223 ORDER BY entrid", S
::i('uid'));
224 $this->values
['jobs'] = array();
225 while (list($id, $name, $function, $secteur, $ss_secteur, $sss_secteur, $description,
226 $w_adr1, $w_adr2, $w_adr3, $w_postcode, $w_city, $w_cityid,
227 $w_region, $w_regiontxt, $w_country, $w_countrytxt,
229 $pub, $w_adr_pub, $w_email_pub, $w_glat, $w_glng, $sss_secteur_name
231 $this->values
['jobs'][] = array('id' => $id,
233 'fonction' => $function,
234 'secteur' => $secteur,
235 'ss_secteur' => $ss_secteur,
236 'sss_secteur' => $sss_secteur,
237 'sss_secteur_name' => $sss_secteur_name,
238 'description' => $description,
239 'w_adr' => array('adr1' => $w_adr1,
242 'postcode' => $w_postcode,
244 'cityid' => $w_cityid,
245 'region' => $w_region,
246 'regiontxt' => $w_regiontxt,
247 'country' => $w_country,
248 'countrytxt' => $w_countrytxt,
250 'checked' => (($w_checked == 0)? true
: false
),
251 'precise_lat' => $w_glat,
252 'precise_lon' => $w_glng),
253 'w_email' => $w_email,
256 'w_email_pub' => $w_email_pub);
259 $res = XDB
::iterator("SELECT link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment
261 WHERE uid = {?} AND link_type = 'pro'
265 $jobNb = count($this->values
['jobs']);
266 while ($tel = $res->next()) {
267 $jobid = $tel['jobid'];
268 unset($tel['jobid']);
269 while ($i < $jobNb && $this->values
['jobs'][$i]['id'] < $jobid) {
275 $job =& $this->values
['jobs'][$i];
276 if (!isset($job['w_tel'])) {
277 $job['w_tel'] = array();
279 if ($job['id'] == $jobid) {
280 $job['w_tel'][] = $tel;
283 foreach ($this->values
['jobs'] as $id=>&$job) {
284 if (!isset($job['w_tel'])) {
285 $job['w_tel'] = array();
291 protected function _saveData()
293 if ($this->changed
['cv']) {
294 XDB
::execute("UPDATE auth_user_md5
296 WHERE user_id = {?}",
297 $this->values
['cv'], S
::i('uid'));
300 if ($this->changed
['corps']) {
301 XDB
::execute("UPDATE profile_corps
302 SET original_corpsid = {?}, current_corpsid = {?},
303 rankid = {?}, corps_pub = {?}
305 $this->values
['corps']['original'], $this->values
['corps']['current'],
306 $this->values
['corps']['rank'], $this->values
['corps']['pub'], S
::i('uid'));
310 public function _prepare(PlPage
&$page, $id)
312 require_once "emails.combobox.inc.php";
313 fill_email_combobox($page);
315 $res = XDB
::query("SELECT id, name AS label
316 FROM profile_job_sector_enum");
317 $page->assign('secteurs', $res->fetchAllAssoc());
318 $res = XDB
::query("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
321 $page->assign('fonctions', $res->fetchAllAssoc());
323 $res = XDB
::iterator("SELECT id, name
324 FROM profile_corps_enum
325 ORDER BY id = 1 DESC, name");
326 $page->assign('original_corps', $res->fetchAllAssoc());
328 $res = XDB
::iterator("SELECT id, name
329 FROM profile_corps_enum
330 WHERE still_exists = 1
331 ORDER BY id = 1 DESC, name");
332 $page->assign('current_corps', $res->fetchAllAssoc());
334 $res = XDB
::iterator("SELECT id, name
335 FROM profile_corps_rank_enum");
336 $page->assign('corps_rank', $res->fetchAllAssoc());
340 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: