2 /***************************************************************************
3 * Copyright (C) 2003-2007 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)
104 VALUES ({?}, {?}, {?}, {?}, {?},
105 {?}, {?}, {?}, {?}, {?}, {?},
106 {?}, {?}, {?}, {?}, {?},
107 {?}, {?}, {?}, {?}, {?},
108 {?}, {?}, {?}, {?}, {?})",
109 S
::i('uid'), $i++
, $job['name'], $job['secteur'], $job['ss_secteur'],
110 $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'],
111 $job['adr']['postcode'],
112 $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'],
113 $job['adr']['regiontxt'],
114 $job['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'],
115 $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub'],
116 $job['adr']['checked'] ?
'geoloc' : '');
121 class ProfileJobs
extends ProfilePage
123 protected $pg_template = 'profile/jobs.tpl';
125 public function __construct(PlWizard
&$wiz)
127 parent
::__construct($wiz);
128 $this->settings
['cv'] = null
;
129 $this->settings
['jobs'] = new ProfileJob();
132 protected function _fetchData()
135 $res = XDB
::query("SELECT cv
137 WHERE user_id = {?}",
139 $this->values
['cv'] = $res->fetchOneCell();
141 // Build the jobs tree
142 $res = XDB
::iterRow("SELECT e.entreprise, e.secteur, e.ss_secteur,
143 e.fonction, e.poste, e.adr1, e.adr2, e.adr3,
144 e.postcode, e.city, e.cityid, e.region, e.regiontxt,
145 e.country, gp.pays, gp.display,
146 FIND_IN_SET('geoloc', flags),
147 e.tel, e.fax, e.mobile, e.email, e.web, e.pub,
148 e.adr_pub, e.tel_pub, e.email_pub
149 FROM entreprises AS e
150 INNER JOIN geoloc_pays AS gp ON(gp.a2 = e.country)
151 WHERE uid = {?} AND entreprise != ''
152 ORDER BY entrid", S
::i('uid'));
153 $this->values
['jobs'] = array();
154 while (list($name, $secteur, $ss_secteur, $fonction, $poste,
155 $adr1, $adr2, $adr3, $postcode, $city, $cityid,
156 $region, $regiontxt, $country, $countrytxt, $display,
157 $checked, $tel, $fax, $mobile, $email, $web,
158 $pub, $adr_pub, $tel_pub, $email_pub) = $res->next()) {
159 $this->values
['jobs'][] = array('name' => $name,
160 'secteur' => $secteur,
161 'ss_secteur' => $ss_secteur,
162 'fonction' => $fonction,
164 'adr' => array('adr1' => $adr1,
167 'postcode' => $postcode,
171 'regiontxt' => $regiontxt,
172 'country' => $country,
173 'countrytxt' => $countrytxt,
174 'display' => $display,
176 'checked' => $checked),
183 'adr_pub' => $adr_pub,
184 'tel_pub' => $tel_pub,
185 'email_pub' => $email_pub);
189 protected function _saveData()
191 if ($this->changed
['cv']) {
192 XDB
::execute("UPDATE auth_user_md5
194 WHERE user_id = {?}",
195 $this->values
['cv'], S
::i('uid'));
199 public function _prepare(PlatalPage
&$page, $id)
201 $page->assign('secteurs', XDB
::iterator("SELECT id, label
202 FROM emploi_secteur"));
203 $page->assign('fonctions', XDB
::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
209 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: