| 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 $bool; |
| 29 | private $checks; |
| 30 | |
| 31 | public function __construct() |
| 32 | { |
| 33 | $this->pub = new ProfilePub(); |
| 34 | $this->mail |
| 35 | = $this->mail_new |
| 36 | = new ProfileEmail(); |
| 37 | $this->web = new ProfileWeb(); |
| 38 | $this->bool = new ProfileBool(); |
| 39 | $this->checks = array('web' => array('web'), |
| 40 | 'mail_new' => array('email_new'), |
| 41 | 'mail' => array('email'), |
| 42 | 'pub' => array('pub', 'email_pub')); |
| 43 | } |
| 44 | |
| 45 | private function cleanJob(ProfilePage &$page,$jobid, array &$job, &$success) |
| 46 | { |
| 47 | $success = true; |
| 48 | foreach ($this->checks as $obj=>&$fields) { |
| 49 | $chk =& $this->$obj; |
| 50 | foreach ($fields as $field) { |
| 51 | if ($field == "email_new") { |
| 52 | if ($job['email'] == "new@example.org") { |
| 53 | $job['email'] = $job[$field]; |
| 54 | } |
| 55 | continue; |
| 56 | } |
| 57 | $job[$field] = $chk->value($page, $field, $job[$field], $s); |
| 58 | if (!$s) { |
| 59 | $success = false; |
| 60 | $job[$field . '_error'] = true; |
| 61 | } |
| 62 | } |
| 63 | } |
| 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); |
| 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); |
| 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) { |
| 87 | if (@$job['removed'] || !trim($job['name'])) { |
| 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); |
| 95 | $this->cleanJob($page, $key, $job, $s); |
| 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 | { |
| 106 | require_once('profil.func.inc.php'); |
| 107 | XDB::execute("DELETE FROM entreprises |
| 108 | WHERE uid = {?}", |
| 109 | S::i('uid')); |
| 110 | XDB::execute("DELETE FROM profile_phones |
| 111 | WHERE uid = {?} AND link_type = 'pro'", |
| 112 | S::i('uid')); |
| 113 | $i = 0; |
| 114 | foreach ($value as $jobid=>&$job) { |
| 115 | if ($job['email'] == "new@example.org") { |
| 116 | $job['email'] = $job['email_new']; |
| 117 | } |
| 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, |
| 121 | email, web, |
| 122 | pub, adr_pub, email_pub, flags, |
| 123 | glat, glng) |
| 124 | VALUES ({?}, {?}, {?}, {?}, {?}, |
| 125 | {?}, {?}, {?}, {?}, {?}, {?}, |
| 126 | {?}, {?}, {?}, {?}, {?}, |
| 127 | {?}, {?}, |
| 128 | {?}, {?}, {?}, {?}, |
| 129 | {?}, {?})", |
| 130 | S::i('uid'), $i, $job['name'], $job['secteur'], $job['ss_secteur'], |
| 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'], |
| 135 | $job['email'], $job['web'], |
| 136 | $job['pub'], $job['adr']['pub'], $job['email_pub'], |
| 137 | $job['adr']['checked'] ? 'geoloc' : '', $job['adr']['precise_lat'], |
| 138 | $job['adr']['precise_lon']); |
| 139 | $profiletel = new ProfilePhones('pro', $jobid); |
| 140 | $profiletel->saveTels('tel', $job['tel']); |
| 141 | $i++; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 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); |
| 153 | $this->settings['cv'] = null; |
| 154 | $this->settings['jobs'] = new ProfileJob(); |
| 155 | $this->watched['cv'] = $this->watched['jobs'] = true; |
| 156 | } |
| 157 | |
| 158 | protected function _fetchData() |
| 159 | { |
| 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 |
| 168 | $res = XDB::iterRow("SELECT e.entrid, e.entreprise, e.secteur, e.ss_secteur, |
| 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, |
| 172 | FIND_IN_SET('geoloc', flags), |
| 173 | e.email, e.web, e.pub, |
| 174 | e.adr_pub, e.email_pub, |
| 175 | e.glat AS precise_lat, e.glng AS precise_lon |
| 176 | FROM entreprises AS e |
| 177 | LEFT JOIN geoloc_pays AS gp ON(gp.a2 = e.country) |
| 178 | WHERE e.uid = {?} AND entreprise != '' |
| 179 | ORDER BY entrid", S::i('uid')); |
| 180 | $this->values['jobs'] = array(); |
| 181 | while (list($id, $name, $secteur, $ss_secteur, $fonction, $poste, |
| 182 | $adr1, $adr2, $adr3, $postcode, $city, $cityid, |
| 183 | $region, $regiontxt, $country, $countrytxt, $display, |
| 184 | $checked, $email, $web, |
| 185 | $pub, $adr_pub, $email_pub, $glat, $glng |
| 186 | ) = $res->next()) { |
| 187 | $this->values['jobs'][] = array('id' => $id, |
| 188 | 'name' => $name, |
| 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, |
| 204 | 'pub' => $adr_pub, |
| 205 | 'checked' => $checked, |
| 206 | 'precise_lat'=> $glat, |
| 207 | 'precise_lon'=> $glng), |
| 208 | 'email' => $email, |
| 209 | 'web' => $web, |
| 210 | 'pub' => $pub, |
| 211 | 'email_pub' => $email_pub); |
| 212 | } |
| 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 | } |
| 244 | } |
| 245 | |
| 246 | protected function _saveData() |
| 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 | } |
| 254 | } |
| 255 | |
| 256 | public function _prepare(PlPage &$page, $id) |
| 257 | { |
| 258 | require_once "emails.combobox.inc.php"; |
| 259 | fill_email_combobox($page); |
| 260 | |
| 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 | } |
| 267 | } |
| 268 | |
| 269 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 270 | ?> |