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; | |
25 | private $mail; | |
26 | private $web; | |
27 | private $tel; | |
f93fb300 | 28 | private $bool; |
37d44b3b FB |
29 | private $checks; |
30 | ||
31 | public function __construct() | |
32 | { | |
33 | $this->pub = new ProfilePub(); | |
34 | $this->mail = new ProfileEmail(); | |
35 | $this->web = new ProfileWeb(); | |
36 | $this->tel = new ProfileTel(); | |
f93fb300 | 37 | $this->bool = new ProfileBool(); |
37d44b3b FB |
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')); | |
42 | } | |
43 | ||
44 | private function cleanJob(ProfilePage &$page, array &$job, &$success) | |
45 | { | |
46 | $success = true; | |
47 | foreach ($this->checks as $obj=>&$fields) { | |
48 | $chk =& $this->$obj; | |
49 | foreach ($fields as $field) { | |
50 | $job[$field] = $chk->value($page, $field, $job[$field], $s); | |
51 | if (!$s) { | |
52 | $success = false; | |
53 | $job[$field . '_error'] = true; | |
54 | } | |
55 | } | |
56 | } | |
f93fb300 FB |
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); | |
37d44b3b FB |
59 | unset($job['removed']); |
60 | unset($job['new']); | |
61 | unset($job['adr']['changed']); | |
62 | unset($job['adr']['parsevalid']); | |
63 | unset($job['adr']['display']); | |
64 | } | |
65 | ||
66 | public function value(ProfilePage &$page, $field, $value, &$success) | |
67 | { | |
68 | $init = false; | |
69 | if (is_null($value)) { | |
70 | $value = $page->values['jobs']; | |
71 | $init = true; | |
72 | } | |
73 | $success = true; | |
74 | foreach ($value as $key=>&$job) { | |
1879c7b2 | 75 | if (@$job['removed'] || !trim($job['name'])) { |
37d44b3b FB |
76 | unset($value[$key]); |
77 | } | |
78 | } | |
79 | foreach ($value as $key=>&$job) { | |
80 | $ls = true; | |
81 | $this->geolocAddress($job['adr'], $s); | |
82 | $ls = ($ls && $s); | |
83 | $this->cleanJob($page, $job, $s); | |
84 | $ls = ($ls && $s); | |
85 | if (!$init) { | |
86 | $success = ($success && $ls); | |
87 | } | |
88 | } | |
89 | return $value; | |
90 | } | |
91 | ||
92 | public function save(ProfilePage &$page, $field, $value) | |
93 | { | |
94 | XDB::execute("DELETE FROM entreprises | |
95 | WHERE uid = {?}", | |
96 | S::i('uid')); | |
97 | $i = 0; | |
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, | |
de0485fd FB |
103 | pub, adr_pub, tel_pub, email_pub, flags, |
104 | glat, glng) | |
37d44b3b FB |
105 | VALUES ({?}, {?}, {?}, {?}, {?}, |
106 | {?}, {?}, {?}, {?}, {?}, {?}, | |
107 | {?}, {?}, {?}, {?}, {?}, | |
108 | {?}, {?}, {?}, {?}, {?}, | |
de0485fd FB |
109 | {?}, {?}, {?}, {?}, {?}, |
110 | {?}, {?})", | |
37d44b3b FB |
111 | S::i('uid'), $i++, $job['name'], $job['secteur'], $job['ss_secteur'], |
112 | $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'], | |
113 | $job['adr']['postcode'], | |
114 | $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'], | |
115 | $job['adr']['regiontxt'], | |
116 | $job['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'], | |
f93fb300 | 117 | $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub'], |
de0485fd FB |
118 | $job['adr']['checked'] ? 'geoloc' : '', $job['adr']['precise_lat'], |
119 | $job['adr']['precise_lon']); | |
37d44b3b FB |
120 | } |
121 | } | |
122 | } | |
123 | ||
3950bc21 FB |
124 | class ProfileJobs extends ProfilePage |
125 | { | |
126 | protected $pg_template = 'profile/jobs.tpl'; | |
127 | ||
128 | public function __construct(PlWizard &$wiz) | |
129 | { | |
130 | parent::__construct($wiz); | |
37d44b3b FB |
131 | $this->settings['cv'] = null; |
132 | $this->settings['jobs'] = new ProfileJob(); | |
a2a1c2f2 | 133 | $this->watched['cv'] = $this->watched['jobs'] = true; |
37d44b3b FB |
134 | } |
135 | ||
7c2e0f0d | 136 | protected function _fetchData() |
37d44b3b | 137 | { |
37d44b3b FB |
138 | // Checkout the CV |
139 | $res = XDB::query("SELECT cv | |
140 | FROM auth_user_md5 | |
141 | WHERE user_id = {?}", | |
142 | S::i('uid')); | |
143 | $this->values['cv'] = $res->fetchOneCell(); | |
144 | ||
145 | // Build the jobs tree | |
146 | $res = XDB::iterRow("SELECT e.entreprise, e.secteur, e.ss_secteur, | |
147 | e.fonction, e.poste, e.adr1, e.adr2, e.adr3, | |
148 | e.postcode, e.city, e.cityid, e.region, e.regiontxt, | |
149 | e.country, gp.pays, gp.display, | |
f93fb300 | 150 | FIND_IN_SET('geoloc', flags), |
37d44b3b | 151 | e.tel, e.fax, e.mobile, e.email, e.web, e.pub, |
de0485fd FB |
152 | e.adr_pub, e.tel_pub, e.email_pub, |
153 | e.glat AS precise_lat, e.glng AS precise_lon | |
37d44b3b | 154 | FROM entreprises AS e |
095f01be | 155 | LEFT JOIN geoloc_pays AS gp ON(gp.a2 = e.country) |
37d44b3b FB |
156 | WHERE uid = {?} AND entreprise != '' |
157 | ORDER BY entrid", S::i('uid')); | |
158 | $this->values['jobs'] = array(); | |
159 | while (list($name, $secteur, $ss_secteur, $fonction, $poste, | |
160 | $adr1, $adr2, $adr3, $postcode, $city, $cityid, | |
161 | $region, $regiontxt, $country, $countrytxt, $display, | |
f93fb300 | 162 | $checked, $tel, $fax, $mobile, $email, $web, |
de0485fd | 163 | $pub, $adr_pub, $tel_pub, $email_pub, $glat, $glng) = $res->next()) { |
37d44b3b FB |
164 | $this->values['jobs'][] = array('name' => $name, |
165 | 'secteur' => $secteur, | |
166 | 'ss_secteur' => $ss_secteur, | |
167 | 'fonction' => $fonction, | |
168 | 'poste' => $poste, | |
169 | 'adr' => array('adr1' => $adr1, | |
170 | 'adr2' => $adr2, | |
171 | 'adr3' => $adr3, | |
172 | 'postcode' => $postcode, | |
173 | 'city' => $city, | |
174 | 'cityid' => $cityid, | |
175 | 'region' => $region, | |
176 | 'regiontxt' => $regiontxt, | |
177 | 'country' => $country, | |
178 | 'countrytxt' => $countrytxt, | |
179 | 'display' => $display, | |
f93fb300 | 180 | 'pub' => $adr_pub, |
de0485fd FB |
181 | 'checked' => $checked, |
182 | 'precise_lat'=> $glat, | |
183 | 'precise_lon'=> $glng), | |
37d44b3b FB |
184 | 'tel' => $tel, |
185 | 'fax' => $fax, | |
186 | 'mobile' => $mobile, | |
187 | 'email' => $email, | |
188 | 'web' => $web, | |
189 | 'pub' => $pub, | |
37d44b3b FB |
190 | 'tel_pub' => $tel_pub, |
191 | 'email_pub' => $email_pub); | |
192 | } | |
37d44b3b FB |
193 | } |
194 | ||
7c2e0f0d | 195 | protected function _saveData() |
37d44b3b FB |
196 | { |
197 | if ($this->changed['cv']) { | |
198 | XDB::execute("UPDATE auth_user_md5 | |
199 | SET cv = {?} | |
200 | WHERE user_id = {?}", | |
201 | $this->values['cv'], S::i('uid')); | |
202 | } | |
3950bc21 | 203 | } |
2dcac0f5 | 204 | |
7c2e0f0d | 205 | public function _prepare(PlatalPage &$page, $id) |
2dcac0f5 | 206 | { |
2dcac0f5 FB |
207 | $page->assign('secteurs', XDB::iterator("SELECT id, label |
208 | FROM emploi_secteur")); | |
209 | $page->assign('fonctions', XDB::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title | |
210 | FROM fonctions_def | |
211 | ORDER BY id")); | |
212 | } | |
3950bc21 FB |
213 | } |
214 | ||
215 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
216 | ?> |