Commit | Line | Data |
---|---|---|
3950bc21 FB |
1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 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 | { | |
33 | $this->pub = new ProfilePub(); | |
b715c1e1 SJ |
34 | $this->mail |
35 | = $this->mail_new | |
36 | = new ProfileEmail(); | |
37d44b3b | 37 | $this->web = new ProfileWeb(); |
f93fb300 | 38 | $this->bool = new ProfileBool(); |
37d44b3b | 39 | $this->checks = array('web' => array('web'), |
b715c1e1 | 40 | 'mail_new' => array('email_new'), |
37d44b3b | 41 | 'mail' => array('email'), |
bde2be3b | 42 | 'pub' => array('pub', 'email_pub')); |
37d44b3b FB |
43 | } |
44 | ||
bde2be3b | 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) { | |
b715c1e1 | 51 | if ($field == "email_new") { |
6ea6d9c1 | 52 | if ($job['email'] == "new@example.org") { |
b715c1e1 SJ |
53 | $job['email'] = $job[$field]; |
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 | } | |
f93fb300 FB |
64 | $job['adr']['pub'] = $this->pub->value($page, 'adr_pub', @$job['adr']['pub'], $s); |
65 | $job['adr']['checked'] = $this->bool->value($page, 'adr_checked', @$job['adr']['checked'], $s); | |
bde2be3b GB |
66 | if (!isset($job['tel'])) { |
67 | $job['tel'] = array(); | |
68 | } | |
69 | $profiletel = new ProfilePhones('pro', $jobid); | |
70 | $job['tel'] = $profiletel->value($page, 'tel', $job['tel'], $s); | |
37d44b3b FB |
71 | unset($job['removed']); |
72 | unset($job['new']); | |
73 | unset($job['adr']['changed']); | |
74 | unset($job['adr']['parsevalid']); | |
75 | unset($job['adr']['display']); | |
76 | } | |
77 | ||
78 | public function value(ProfilePage &$page, $field, $value, &$success) | |
79 | { | |
80 | $init = false; | |
81 | if (is_null($value)) { | |
82 | $value = $page->values['jobs']; | |
83 | $init = true; | |
84 | } | |
85 | $success = true; | |
86 | foreach ($value as $key=>&$job) { | |
1879c7b2 | 87 | if (@$job['removed'] || !trim($job['name'])) { |
37d44b3b FB |
88 | unset($value[$key]); |
89 | } | |
90 | } | |
91 | foreach ($value as $key=>&$job) { | |
92 | $ls = true; | |
93 | $this->geolocAddress($job['adr'], $s); | |
94 | $ls = ($ls && $s); | |
bde2be3b | 95 | $this->cleanJob($page, $key, $job, $s); |
37d44b3b FB |
96 | $ls = ($ls && $s); |
97 | if (!$init) { | |
98 | $success = ($success && $ls); | |
99 | } | |
100 | } | |
101 | return $value; | |
102 | } | |
103 | ||
104 | public function save(ProfilePage &$page, $field, $value) | |
105 | { | |
5e4417a9 | 106 | require_once('profil.func.inc.php'); |
37d44b3b FB |
107 | XDB::execute("DELETE FROM entreprises |
108 | WHERE uid = {?}", | |
109 | S::i('uid')); | |
b235d980 | 110 | XDB::execute("DELETE FROM profile_phones |
5e4417a9 GB |
111 | WHERE uid = {?} AND link_type = 'pro'", |
112 | S::i('uid')); | |
37d44b3b | 113 | $i = 0; |
bde2be3b | 114 | foreach ($value as $jobid=>&$job) { |
6ea6d9c1 | 115 | if ($job['email'] == "new@example.org") { |
b715c1e1 SJ |
116 | $job['email'] = $job['email_new']; |
117 | } | |
37d44b3b FB |
118 | XDB::execute("INSERT INTO entreprises (uid, entrid, entreprise, secteur, ss_secteur, |
119 | fonction, poste, adr1, adr2, adr3, postcode, | |
120 | city, cityid, country, region, regiontxt, | |
5e4417a9 GB |
121 | email, web, |
122 | pub, adr_pub, email_pub, flags, | |
de0485fd | 123 | glat, glng) |
37d44b3b FB |
124 | VALUES ({?}, {?}, {?}, {?}, {?}, |
125 | {?}, {?}, {?}, {?}, {?}, {?}, | |
126 | {?}, {?}, {?}, {?}, {?}, | |
5e4417a9 GB |
127 | {?}, {?}, |
128 | {?}, {?}, {?}, {?}, | |
de0485fd | 129 | {?}, {?})", |
5e4417a9 | 130 | S::i('uid'), $i, $job['name'], $job['secteur'], $job['ss_secteur'], |
37d44b3b FB |
131 | $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'], |
132 | $job['adr']['postcode'], | |
133 | $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'], | |
134 | $job['adr']['regiontxt'], | |
5e4417a9 GB |
135 | $job['email'], $job['web'], |
136 | $job['pub'], $job['adr']['pub'], $job['email_pub'], | |
de0485fd FB |
137 | $job['adr']['checked'] ? 'geoloc' : '', $job['adr']['precise_lat'], |
138 | $job['adr']['precise_lon']); | |
bde2be3b GB |
139 | $profiletel = new ProfilePhones('pro', $jobid); |
140 | $profiletel->saveTels('tel', $job['tel']); | |
5e4417a9 | 141 | $i++; |
37d44b3b FB |
142 | } |
143 | } | |
144 | } | |
145 | ||
3950bc21 FB |
146 | class ProfileJobs extends ProfilePage |
147 | { | |
148 | protected $pg_template = 'profile/jobs.tpl'; | |
149 | ||
150 | public function __construct(PlWizard &$wiz) | |
151 | { | |
152 | parent::__construct($wiz); | |
37d44b3b FB |
153 | $this->settings['cv'] = null; |
154 | $this->settings['jobs'] = new ProfileJob(); | |
a2a1c2f2 | 155 | $this->watched['cv'] = $this->watched['jobs'] = true; |
37d44b3b FB |
156 | } |
157 | ||
7c2e0f0d | 158 | protected function _fetchData() |
37d44b3b | 159 | { |
37d44b3b FB |
160 | // Checkout the CV |
161 | $res = XDB::query("SELECT cv | |
162 | FROM auth_user_md5 | |
163 | WHERE user_id = {?}", | |
164 | S::i('uid')); | |
165 | $this->values['cv'] = $res->fetchOneCell(); | |
166 | ||
167 | // Build the jobs tree | |
bde2be3b | 168 | $res = XDB::iterRow("SELECT e.entrid, e.entreprise, e.secteur, e.ss_secteur, |
37d44b3b FB |
169 | e.fonction, e.poste, e.adr1, e.adr2, e.adr3, |
170 | e.postcode, e.city, e.cityid, e.region, e.regiontxt, | |
171 | e.country, gp.pays, gp.display, | |
f93fb300 | 172 | FIND_IN_SET('geoloc', flags), |
5e4417a9 GB |
173 | e.email, e.web, e.pub, |
174 | e.adr_pub, e.email_pub, | |
bde2be3b | 175 | e.glat AS precise_lat, e.glng AS precise_lon |
37d44b3b | 176 | FROM entreprises AS e |
095f01be | 177 | LEFT JOIN geoloc_pays AS gp ON(gp.a2 = e.country) |
5e4417a9 | 178 | WHERE e.uid = {?} AND entreprise != '' |
37d44b3b FB |
179 | ORDER BY entrid", S::i('uid')); |
180 | $this->values['jobs'] = array(); | |
bde2be3b | 181 | while (list($id, $name, $secteur, $ss_secteur, $fonction, $poste, |
37d44b3b FB |
182 | $adr1, $adr2, $adr3, $postcode, $city, $cityid, |
183 | $region, $regiontxt, $country, $countrytxt, $display, | |
5e4417a9 | 184 | $checked, $email, $web, |
bde2be3b GB |
185 | $pub, $adr_pub, $email_pub, $glat, $glng |
186 | ) = $res->next()) { | |
187 | $this->values['jobs'][] = array('id' => $id, | |
188 | 'name' => $name, | |
37d44b3b FB |
189 | 'secteur' => $secteur, |
190 | 'ss_secteur' => $ss_secteur, | |
191 | 'fonction' => $fonction, | |
192 | 'poste' => $poste, | |
193 | 'adr' => array('adr1' => $adr1, | |
194 | 'adr2' => $adr2, | |
195 | 'adr3' => $adr3, | |
196 | 'postcode' => $postcode, | |
197 | 'city' => $city, | |
198 | 'cityid' => $cityid, | |
199 | 'region' => $region, | |
200 | 'regiontxt' => $regiontxt, | |
201 | 'country' => $country, | |
202 | 'countrytxt' => $countrytxt, | |
203 | 'display' => $display, | |
f93fb300 | 204 | 'pub' => $adr_pub, |
de0485fd FB |
205 | 'checked' => $checked, |
206 | 'precise_lat'=> $glat, | |
207 | 'precise_lon'=> $glng), | |
37d44b3b FB |
208 | 'email' => $email, |
209 | 'web' => $web, | |
210 | 'pub' => $pub, | |
37d44b3b FB |
211 | 'email_pub' => $email_pub); |
212 | } | |
bde2be3b GB |
213 | |
214 | $res = XDB::iterator("SELECT link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment | |
215 | FROM profile_phones | |
216 | WHERE uid = {?} AND link_type = 'pro' | |
217 | ORDER BY link_id", | |
218 | S::i('uid')); | |
219 | $i = 0; | |
220 | $jobNb = count($this->values['jobs']); | |
221 | while ($tel = $res->next()) { | |
222 | $jobid = $tel['jobid']; | |
223 | unset($tel['jobid']); | |
224 | while ($i < $jobNb && $this->values['jobs'][$i]['id'] < $jobid) { | |
225 | $i++; | |
226 | } | |
227 | if ($i >= $jobNb) { | |
228 | break; | |
229 | } | |
230 | $job =& $this->values['jobs'][$i]; | |
231 | if (!isset($job['tel'])) { | |
232 | $job['tel'] = array(); | |
233 | } | |
234 | if ($job['id'] == $jobid) { | |
235 | $job['tel'][] = $tel; | |
236 | } | |
237 | } | |
238 | foreach ($this->values['jobs'] as $id=>&$job) { | |
239 | if (!isset($job['tel'])) { | |
240 | $job['tel'] = array(); | |
241 | } | |
242 | unset($job['id']); | |
243 | } | |
37d44b3b FB |
244 | } |
245 | ||
7c2e0f0d | 246 | protected function _saveData() |
37d44b3b FB |
247 | { |
248 | if ($this->changed['cv']) { | |
249 | XDB::execute("UPDATE auth_user_md5 | |
250 | SET cv = {?} | |
251 | WHERE user_id = {?}", | |
252 | $this->values['cv'], S::i('uid')); | |
253 | } | |
3950bc21 | 254 | } |
2dcac0f5 | 255 | |
04334c61 | 256 | public function _prepare(PlPage &$page, $id) |
2dcac0f5 | 257 | { |
b715c1e1 SJ |
258 | require_once "emails.combobox.inc.php"; |
259 | fill_email_combobox($page); | |
260 | ||
2dcac0f5 FB |
261 | $page->assign('secteurs', XDB::iterator("SELECT id, label |
262 | FROM emploi_secteur")); | |
263 | $page->assign('fonctions', XDB::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title | |
264 | FROM fonctions_def | |
265 | ORDER BY id")); | |
266 | } | |
3950bc21 FB |
267 | } |
268 | ||
269 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
270 | ?> |