2 /***************************************************************************
3 * Copyright (C) 2003-2007 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
30 public function __construct()
32 $this->pub
= new ProfilePub();
33 $this->mail
= new ProfileEmail();
34 $this->web
= new ProfileWeb();
35 $this->tel
= new ProfileTel();
36 $this->checks
= array('web' => array('web'),
37 'mail' => array('email'),
38 'tel' => array('tel', 'fax', 'mobile'),
39 'pub' => array('pub', 'tel_pub', 'email_pub'));
42 private function cleanJob(ProfilePage
&$page, array &$job, &$success)
45 foreach ($this->checks
as $obj=>&$fields) {
47 foreach ($fields as $field) {
48 $job[$field] = $chk->value($page, $field, $job[$field], $s);
51 $job[$field . '_error'] = true
;
55 unset($job['removed']);
57 unset($job['adr']['changed']);
58 unset($job['adr']['parsevalid']);
59 unset($job['adr']['display']);
62 public function value(ProfilePage
&$page, $field, $value, &$success)
65 if (is_null($value)) {
66 $value = $page->values
['jobs'];
70 foreach ($value as $key=>&$job) {
71 if (@$job['removed'] ||
!trim($job['name'])) {
75 foreach ($value as $key=>&$job) {
77 $this->geolocAddress($job['adr'], $s);
79 $this->cleanJob($page, $job, $s);
82 $success = ($success && $ls);
88 public function save(ProfilePage
&$page, $field, $value)
90 XDB
::execute("DELETE FROM entreprises
94 foreach ($value as &$job) {
95 XDB
::execute("INSERT INTO entreprises (uid, entrid, entreprise, secteur, ss_secteur,
96 fonction, poste, adr1, adr2, adr3, postcode,
97 city, cityid, country, region, regiontxt,
98 tel, fax, mobile, email, web,
99 pub, adr_pub, tel_pub, email_pub)
100 VALUES ({?}, {?}, {?}, {?}, {?},
101 {?}, {?}, {?}, {?}, {?}, {?},
102 {?}, {?}, {?}, {?}, {?},
103 {?}, {?}, {?}, {?}, {?},
104 {?}, {?}, {?}, {?})",
105 S
::i('uid'), $i++
, $job['name'], $job['secteur'], $job['ss_secteur'],
106 $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'],
107 $job['adr']['postcode'],
108 $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'],
109 $job['adr']['regiontxt'],
110 $job['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'],
111 $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub']);
116 class ProfileJobs
extends ProfilePage
118 protected $pg_template = 'profile/jobs.tpl';
120 public function __construct(PlWizard
&$wiz)
122 parent
::__construct($wiz);
123 $this->settings
['cv'] = null
;
124 $this->settings
['jobs'] = new ProfileJob();
127 protected function fetchData()
129 if (count($this->orig
) > 0) {
130 $this->values
= $this->orig
;
134 $res = XDB
::query("SELECT cv
136 WHERE user_id = {?}",
138 $this->values
['cv'] = $res->fetchOneCell();
140 // Build the jobs tree
141 $res = XDB
::iterRow("SELECT e.entreprise, e.secteur, e.ss_secteur,
142 e.fonction, e.poste, e.adr1, e.adr2, e.adr3,
143 e.postcode, e.city, e.cityid, e.region, e.regiontxt,
144 e.country, gp.pays, gp.display,
145 e.tel, e.fax, e.mobile, e.email, e.web, e.pub,
146 e.adr_pub, e.tel_pub, e.email_pub
147 FROM entreprises AS e
148 INNER JOIN geoloc_pays AS gp ON(gp.a2 = e.country)
149 WHERE uid = {?} AND entreprise != ''
150 ORDER BY entrid", S
::i('uid'));
151 $this->values
['jobs'] = array();
152 while (list($name, $secteur, $ss_secteur, $fonction, $poste,
153 $adr1, $adr2, $adr3, $postcode, $city, $cityid,
154 $region, $regiontxt, $country, $countrytxt, $display,
155 $tel, $fax, $mobile, $email, $web,
156 $pub, $adr_pub, $tel_pub, $email_pub) = $res->next()) {
157 $this->values
['jobs'][] = array('name' => $name,
158 'secteur' => $secteur,
159 'ss_secteur' => $ss_secteur,
160 'fonction' => $fonction,
162 'adr' => array('adr1' => $adr1,
165 'postcode' => $postcode,
169 'regiontxt' => $regiontxt,
170 'country' => $country,
171 'countrytxt' => $countrytxt,
172 'display' => $display,
180 'adr_pub' => $adr_pub,
181 'tel_pub' => $tel_pub,
182 'email_pub' => $email_pub);
187 protected function saveData()
189 if ($this->changed
['cv']) {
190 XDB
::execute("UPDATE auth_user_md5
192 WHERE user_id = {?}",
193 $this->values
['cv'], S
::i('uid'));
198 public function prepare(PlatalPage
&$page)
200 parent
::prepare($page);
201 $page->assign('secteurs', XDB
::iterator("SELECT id, label
202 FROM emploi_secteur"));
203 $page->assign('fonctions', XDB
::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
209 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: