Integrates the AX emails into the marketing emails, implements an email combobox...
[platal.git] / modules / profile / jobs.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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_new;
26 private $mail;
27 private $web;
28 private $tel;
29 private $bool;
30 private $checks;
31
32 public function __construct()
33 {
34 $this->pub = new ProfilePub();
35 $this->mail
36 = $this->mail_new
37 = new ProfileEmail();
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'));
46 }
47
48 private function cleanJob(ProfilePage &$page, array &$job, &$success)
49 {
50 $success = true;
51 foreach ($this->checks as $obj=>&$fields) {
52 $chk =& $this->$obj;
53 foreach ($fields as $field) {
54 if ($field == "email_new") {
55 if ($job['email'] == "new@new.new") {
56 $job['email'] = $job[$field];
57 }
58 continue;
59 }
60 $job[$field] = $chk->value($page, $field, $job[$field], $s);
61 if (!$s) {
62 $success = false;
63 $job[$field . '_error'] = true;
64 }
65 }
66 }
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']);
70 unset($job['new']);
71 unset($job['adr']['changed']);
72 unset($job['adr']['parsevalid']);
73 unset($job['adr']['display']);
74 }
75
76 public function value(ProfilePage &$page, $field, $value, &$success)
77 {
78 $init = false;
79 if (is_null($value)) {
80 $value = $page->values['jobs'];
81 $init = true;
82 }
83 $success = true;
84 foreach ($value as $key=>&$job) {
85 if (@$job['removed'] || !trim($job['name'])) {
86 unset($value[$key]);
87 }
88 }
89 foreach ($value as $key=>&$job) {
90 $ls = true;
91 $this->geolocAddress($job['adr'], $s);
92 $ls = ($ls && $s);
93 $this->cleanJob($page, $job, $s);
94 $ls = ($ls && $s);
95 if (!$init) {
96 $success = ($success && $ls);
97 }
98 }
99 return $value;
100 }
101
102 public function save(ProfilePage &$page, $field, $value)
103 {
104 XDB::execute("DELETE FROM entreprises
105 WHERE uid = {?}",
106 S::i('uid'));
107 $i = 0;
108 foreach ($value as &$job) {
109 if ($job['email'] == "new@new.new") {
110 $job['email'] = $job['email_new'];
111 }
112
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,
118 glat, glng)
119 VALUES ({?}, {?}, {?}, {?}, {?},
120 {?}, {?}, {?}, {?}, {?}, {?},
121 {?}, {?}, {?}, {?}, {?},
122 {?}, {?}, {?}, {?}, {?},
123 {?}, {?}, {?}, {?}, {?},
124 {?}, {?})",
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']);
134 }
135 }
136 }
137
138 class ProfileJobs extends ProfilePage
139 {
140 protected $pg_template = 'profile/jobs.tpl';
141
142 public function __construct(PlWizard &$wiz)
143 {
144 parent::__construct($wiz);
145 $this->settings['cv'] = null;
146 $this->settings['jobs'] = new ProfileJob();
147 $this->watched['cv'] = $this->watched['jobs'] = true;
148 }
149
150 protected function _fetchData()
151 {
152 // Checkout the CV
153 $res = XDB::query("SELECT cv
154 FROM auth_user_md5
155 WHERE user_id = {?}",
156 S::i('uid'));
157 $this->values['cv'] = $res->fetchOneCell();
158
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,
182 'poste' => $poste,
183 'adr' => array('adr1' => $adr1,
184 'adr2' => $adr2,
185 'adr3' => $adr3,
186 'postcode' => $postcode,
187 'city' => $city,
188 'cityid' => $cityid,
189 'region' => $region,
190 'regiontxt' => $regiontxt,
191 'country' => $country,
192 'countrytxt' => $countrytxt,
193 'display' => $display,
194 'pub' => $adr_pub,
195 'checked' => $checked,
196 'precise_lat'=> $glat,
197 'precise_lon'=> $glng),
198 'tel' => $tel,
199 'fax' => $fax,
200 'mobile' => $mobile,
201 'email' => $email,
202 'web' => $web,
203 'pub' => $pub,
204 'tel_pub' => $tel_pub,
205 'email_pub' => $email_pub);
206 }
207 }
208
209 protected function _saveData()
210 {
211 if ($this->changed['cv']) {
212 XDB::execute("UPDATE auth_user_md5
213 SET cv = {?}
214 WHERE user_id = {?}",
215 $this->values['cv'], S::i('uid'));
216 }
217 }
218
219 public function _prepare(PlatalPage &$page, $id)
220 {
221 require_once "emails.combobox.inc.php";
222 fill_email_combobox($page);
223
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
227 FROM fonctions_def
228 ORDER BY id"));
229 }
230 }
231
232 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
233 ?>