List updated fields in carnet notification (only rss and panel for now,
[platal.git] / modules / profile / jobs.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
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
22 class ProfileJob extends ProfileGeoloc
23 {
24 private $pub;
25 private $mail;
26 private $web;
27 private $tel;
28 private $bool;
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();
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'));
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 }
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']);
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) {
75 if (@$job['removed'] || !trim($job['name'])) {
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,
103 pub, adr_pub, tel_pub, email_pub, flags,
104 glat, glng)
105 VALUES ({?}, {?}, {?}, {?}, {?},
106 {?}, {?}, {?}, {?}, {?}, {?},
107 {?}, {?}, {?}, {?}, {?},
108 {?}, {?}, {?}, {?}, {?},
109 {?}, {?}, {?}, {?}, {?},
110 {?}, {?})",
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'],
117 $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub'],
118 $job['adr']['checked'] ? 'geoloc' : '', $job['adr']['precise_lat'],
119 $job['adr']['precise_lon']);
120 }
121 }
122 }
123
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);
131 $this->settings['cv'] = null;
132 $this->settings['jobs'] = new ProfileJob();
133 $this->watched['cv'] = $this->watched['jobs'] = true;
134 }
135
136 protected function _fetchData()
137 {
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,
150 FIND_IN_SET('geoloc', flags),
151 e.tel, e.fax, e.mobile, e.email, e.web, e.pub,
152 e.adr_pub, e.tel_pub, e.email_pub,
153 e.glat AS precise_lat, e.glng AS precise_lon
154 FROM entreprises AS e
155 INNER JOIN geoloc_pays AS gp ON(gp.a2 = e.country)
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,
162 $checked, $tel, $fax, $mobile, $email, $web,
163 $pub, $adr_pub, $tel_pub, $email_pub, $glat, $glng) = $res->next()) {
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,
180 'pub' => $adr_pub,
181 'checked' => $checked,
182 'precise_lat'=> $glat,
183 'precise_lon'=> $glng),
184 'tel' => $tel,
185 'fax' => $fax,
186 'mobile' => $mobile,
187 'email' => $email,
188 'web' => $web,
189 'pub' => $pub,
190 'tel_pub' => $tel_pub,
191 'email_pub' => $email_pub);
192 }
193 }
194
195 protected function _saveData()
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 }
203 }
204
205 public function _prepare(PlatalPage &$page, $id)
206 {
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 }
213 }
214
215 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
216 ?>