2 /***************************************************************************
3 * Copyright (C) 2003-2008 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
32 public function __construct()
34 $this->pub
= new ProfilePub();
38 $this->web
= new ProfileWeb();
39 $this->tel
= new ProfileTel();
40 $this->bool
= new ProfileBool();
41 $this->checks
= array('web' => array('web'),
42 'mail_new' => array('email_new'),
43 'mail' => array('email'),
44 'tel' => array('tel', 'fax', 'mobile'),
45 'pub' => array('pub', 'tel_pub', 'email_pub'));
48 private function cleanJob(ProfilePage
&$page, array &$job, &$success)
51 foreach ($this->checks
as $obj=>&$fields) {
53 foreach ($fields as $field) {
54 if ($field == "email_new") {
55 if ($job['email'] == "new@new.new") {
56 $job['email'] = $job[$field];
60 $job[$field] = $chk->value($page, $field, $job[$field], $s);
63 $job[$field . '_error'] = true
;
67 $job['adr']['pub'] = $this->pub
->value($page, 'adr_pub', @$job['adr']['pub'], $s);
68 $job['adr']['checked'] = $this->bool
->value($page, 'adr_checked', @$job['adr']['checked'], $s);
69 unset($job['removed']);
71 unset($job['adr']['changed']);
72 unset($job['adr']['parsevalid']);
73 unset($job['adr']['display']);
76 public function value(ProfilePage
&$page, $field, $value, &$success)
79 if (is_null($value)) {
80 $value = $page->values
['jobs'];
84 foreach ($value as $key=>&$job) {
85 if (@$job['removed'] ||
!trim($job['name'])) {
89 foreach ($value as $key=>&$job) {
91 $this->geolocAddress($job['adr'], $s);
93 $this->cleanJob($page, $job, $s);
96 $success = ($success && $ls);
102 public function save(ProfilePage
&$page, $field, $value)
104 XDB
::execute("DELETE FROM entreprises
108 foreach ($value as &$job) {
109 if ($job['email'] == "new@new.new") {
110 $job['email'] = $job['email_new'];
113 XDB
::execute("INSERT INTO entreprises (uid, entrid, entreprise, secteur, ss_secteur,
114 fonction, poste, adr1, adr2, adr3, postcode,
115 city, cityid, country, region, regiontxt,
116 tel, fax, mobile, email, web,
117 pub, adr_pub, tel_pub, email_pub, flags,
119 VALUES ({?}, {?}, {?}, {?}, {?},
120 {?}, {?}, {?}, {?}, {?}, {?},
121 {?}, {?}, {?}, {?}, {?},
122 {?}, {?}, {?}, {?}, {?},
123 {?}, {?}, {?}, {?}, {?},
125 S
::i('uid'), $i++
, $job['name'], $job['secteur'], $job['ss_secteur'],
126 $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'],
127 $job['adr']['postcode'],
128 $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'],
129 $job['adr']['regiontxt'],
130 $job['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'],
131 $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub'],
132 $job['adr']['checked'] ?
'geoloc' : '', $job['adr']['precise_lat'],
133 $job['adr']['precise_lon']);
138 class ProfileJobs
extends ProfilePage
140 protected $pg_template = 'profile/jobs.tpl';
142 public function __construct(PlWizard
&$wiz)
144 parent
::__construct($wiz);
145 $this->settings
['cv'] = null
;
146 $this->settings
['jobs'] = new ProfileJob();
147 $this->watched
['cv'] = $this->watched
['jobs'] = true
;
150 protected function _fetchData()
153 $res = XDB
::query("SELECT cv
155 WHERE user_id = {?}",
157 $this->values
['cv'] = $res->fetchOneCell();
159 // Build the jobs tree
160 $res = XDB
::iterRow("SELECT e.entreprise, e.secteur, e.ss_secteur,
161 e.fonction, e.poste, e.adr1, e.adr2, e.adr3,
162 e.postcode, e.city, e.cityid, e.region, e.regiontxt,
163 e.country, gp.pays, gp.display,
164 FIND_IN_SET('geoloc', flags),
165 e.tel, e.fax, e.mobile, e.email, e.web, e.pub,
166 e.adr_pub, e.tel_pub, e.email_pub,
167 e.glat AS precise_lat, e.glng AS precise_lon
168 FROM entreprises AS e
169 LEFT JOIN geoloc_pays AS gp ON(gp.a2 = e.country)
170 WHERE uid = {?} AND entreprise != ''
171 ORDER BY entrid", S
::i('uid'));
172 $this->values
['jobs'] = array();
173 while (list($name, $secteur, $ss_secteur, $fonction, $poste,
174 $adr1, $adr2, $adr3, $postcode, $city, $cityid,
175 $region, $regiontxt, $country, $countrytxt, $display,
176 $checked, $tel, $fax, $mobile, $email, $web,
177 $pub, $adr_pub, $tel_pub, $email_pub, $glat, $glng) = $res->next()) {
178 $this->values
['jobs'][] = array('name' => $name,
179 'secteur' => $secteur,
180 'ss_secteur' => $ss_secteur,
181 'fonction' => $fonction,
183 'adr' => array('adr1' => $adr1,
186 'postcode' => $postcode,
190 'regiontxt' => $regiontxt,
191 'country' => $country,
192 'countrytxt' => $countrytxt,
193 'display' => $display,
195 'checked' => $checked,
196 'precise_lat'=> $glat,
197 'precise_lon'=> $glng),
204 'tel_pub' => $tel_pub,
205 'email_pub' => $email_pub);
209 protected function _saveData()
211 if ($this->changed
['cv']) {
212 XDB
::execute("UPDATE auth_user_md5
214 WHERE user_id = {?}",
215 $this->values
['cv'], S
::i('uid'));
219 public function _prepare(PlatalPage
&$page, $id)
221 require_once "emails.combobox.inc.php";
222 fill_email_combobox($page);
224 $page->assign('secteurs', XDB
::iterator("SELECT id, label
225 FROM emploi_secteur"));
226 $page->assign('fonctions', XDB
::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
232 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: