| 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 ProfileModule extends PLModule |
| 23 | { |
| 24 | function handlers() |
| 25 | { |
| 26 | return array( |
| 27 | 'photo' => $this->make_hook('photo', AUTH_PUBLIC), |
| 28 | 'photo/change' => $this->make_hook('photo_change', AUTH_MDP), |
| 29 | |
| 30 | 'fiche.php' => $this->make_hook('fiche', AUTH_PUBLIC), |
| 31 | 'profile' => $this->make_hook('profile', AUTH_PUBLIC), |
| 32 | 'profile/private' => $this->make_hook('profile', AUTH_COOKIE), |
| 33 | 'profile/ax' => $this->make_hook('ax', AUTH_COOKIE, 'admin'), |
| 34 | 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP), |
| 35 | 'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_COOKIE, 'user', NO_AUTH), |
| 36 | 'profile/ajax/tel' => $this->make_hook('ajax_tel', AUTH_COOKIE, 'user', NO_AUTH), |
| 37 | 'profile/ajax/edu' => $this->make_hook('ajax_edu', AUTH_COOKIE, 'user', NO_AUTH), |
| 38 | 'profile/ajax/medal' => $this->make_hook('ajax_medal', AUTH_COOKIE, 'user', NO_AUTH), |
| 39 | 'profile/networking' => $this->make_hook('networking', AUTH_PUBLIC), |
| 40 | 'profile/ajax/job' => $this->make_hook('ajax_job', AUTH_COOKIE, 'user', NO_AUTH), |
| 41 | 'profile/ajax/secteur' => $this->make_hook('ajax_secteur', AUTH_COOKIE, 'user', NO_AUTH), |
| 42 | 'profile/ajax/ssecteur' => $this->make_hook('ajax_ssecteur', AUTH_COOKIE, 'user', NO_AUTH), |
| 43 | 'profile/ajax/skill' => $this->make_hook('ajax_skill', AUTH_COOKIE, 'user', NO_AUTH), |
| 44 | 'profile/ajax/searchname' => $this->make_hook('ajax_searchname', AUTH_COOKIE, 'user', NO_AUTH), |
| 45 | 'javascript/education.js' => $this->make_hook('education_js', AUTH_COOKIE), |
| 46 | 'javascript/grades.js' => $this->make_hook('grades_js', AUTH_COOKIE), |
| 47 | 'profile/medal' => $this->make_hook('medal', AUTH_PUBLIC), |
| 48 | 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP), |
| 49 | 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP), |
| 50 | |
| 51 | 'referent' => $this->make_hook('referent', AUTH_COOKIE), |
| 52 | 'emploi' => $this->make_hook('ref_search', AUTH_COOKIE), |
| 53 | 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE), |
| 54 | 'referent/ssect' => $this->make_hook('ref_sect', AUTH_COOKIE, 'user', NO_AUTH), |
| 55 | 'referent/country' => $this->make_hook('ref_country', AUTH_COOKIE, 'user', NO_AUTH), |
| 56 | |
| 57 | 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE), |
| 58 | |
| 59 | 'vcard' => $this->make_hook('vcard', AUTH_COOKIE, 'user', NO_HTTPS), |
| 60 | 'admin/binets' => $this->make_hook('admin_binets', AUTH_MDP, 'admin'), |
| 61 | 'admin/medals' => $this->make_hook('admin_medals', AUTH_MDP, 'admin'), |
| 62 | 'admin/education' => $this->make_hook('admin_education', AUTH_MDP, 'admin'), |
| 63 | 'admin/education_field' => $this->make_hook('admin_education_field', AUTH_MDP, 'admin'), |
| 64 | 'admin/education_degree' => $this->make_hook('admin_education_degree', AUTH_MDP, 'admin'), |
| 65 | 'admin/education_degree_set' => $this->make_hook('admin_education_degree_set', AUTH_MDP, 'admin'), |
| 66 | 'admin/sections' => $this->make_hook('admin_sections', AUTH_MDP, 'admin'), |
| 67 | 'admin/secteurs' => $this->make_hook('admin_secteurs', AUTH_MDP, 'admin'), |
| 68 | 'admin/networking' => $this->make_hook('admin_networking', AUTH_MDP, 'admin'), |
| 69 | 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'), |
| 70 | 'admin/ss_secteurs' => $this->make_hook('admin_ss_secteurs', AUTH_MDP, 'admin'), |
| 71 | 'admin/fonctions' => $this->make_hook('admin_fonctions', AUTH_MDP, 'admin'), |
| 72 | 'admin/corps_enum' => $this->make_hook('admin_corps_enum', AUTH_MDP, 'admin'), |
| 73 | 'admin/corps_rank' => $this->make_hook('admin_corps_rank', AUTH_MDP, 'admin'), |
| 74 | |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | /* XXX COMPAT */ |
| 79 | function handler_fiche(&$page) |
| 80 | { |
| 81 | return $this->handler_profile($page, Env::v('user')); |
| 82 | } |
| 83 | |
| 84 | function handler_photo(&$page, $x = null, $req = null) |
| 85 | { |
| 86 | if (!$x || !($user = User::getSilent($x))) { |
| 87 | return PL_NOT_FOUND; |
| 88 | } |
| 89 | |
| 90 | // Retrieve the photo and its mime type. |
| 91 | $photo_data = null; |
| 92 | $photo_type = null; |
| 93 | |
| 94 | if ($req && S::logged()) { |
| 95 | include 'validations.inc.php'; |
| 96 | $myphoto = PhotoReq::get_request($user->id()); |
| 97 | if ($myphoto) { |
| 98 | $photo_data = $myphoto->data; |
| 99 | $photo_type = $myphoto->mimetype; |
| 100 | } |
| 101 | } else { |
| 102 | $res = XDB::query( |
| 103 | "SELECT attachmime, attach, pub |
| 104 | FROM photo |
| 105 | WHERE uid = {?}", $user->id()); |
| 106 | list($photo_type, $photo_data, $photo_pub) = $res->fetchOneRow(); |
| 107 | if ($photo_pub != 'public' && !S::logged()) { |
| 108 | $photo_type = $photo_data = null; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Display the photo, or a default one when not available. |
| 113 | if ($photo_type && $photo_data != null) { |
| 114 | header('Content-type: image/' . $photo_type); |
| 115 | echo $photo_data; |
| 116 | } else { |
| 117 | header('Content-type: image/png'); |
| 118 | echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png'); |
| 119 | } |
| 120 | exit; |
| 121 | } |
| 122 | |
| 123 | function handler_medal(&$page, $mid) |
| 124 | { |
| 125 | $thumb = ($mid == 'thumb'); |
| 126 | $mid = $thumb ? @func_get_arg(2) : $mid; |
| 127 | |
| 128 | $res = XDB::query("SELECT img |
| 129 | FROM profile_medals |
| 130 | WHERE id = {?}", |
| 131 | $mid); |
| 132 | $img = $thumb ? |
| 133 | dirname(__FILE__).'/../htdocs/images/medals/thumb/' . $res->fetchOneCell() : |
| 134 | dirname(__FILE__).'/../htdocs/images/medals/' . $res->fetchOneCell(); |
| 135 | $type = mime_content_type($img); |
| 136 | header("Content-Type: $type"); |
| 137 | echo file_get_contents($img); |
| 138 | exit; |
| 139 | } |
| 140 | |
| 141 | function handler_networking(&$page, $mid) |
| 142 | { |
| 143 | $res = XDB::query("SELECT icon |
| 144 | FROM profile_networking_enum |
| 145 | WHERE network_type = {?}", |
| 146 | $mid); |
| 147 | $img = dirname(__FILE__) . '/../htdocs/images/networking/' . $res->fetchOneCell(); |
| 148 | $type = mime_content_type($img); |
| 149 | header("Content-Type: $type"); |
| 150 | echo file_get_contents($img); |
| 151 | exit; |
| 152 | } |
| 153 | |
| 154 | function handler_photo_change(&$page) |
| 155 | { |
| 156 | global $globals; |
| 157 | $page->changeTpl('profile/trombino.tpl'); |
| 158 | |
| 159 | require_once('validations.inc.php'); |
| 160 | |
| 161 | $trombi_x = '/home/web/trombino/photos' . S::v('promo') . '/' . S::user()->login() . '.jpg'; |
| 162 | if (Env::has('upload')) { |
| 163 | S::assert_xsrf_token(); |
| 164 | |
| 165 | $upload = new PlUpload(S::user()->login(), 'photo'); |
| 166 | if (!$upload->upload($_FILES['userfile']) && !$upload->download(Env::v('photo'))) { |
| 167 | $page->trigError('Une erreur est survenue lors du téléchargement du fichier'); |
| 168 | } else { |
| 169 | $myphoto = new PhotoReq(S::user(), $upload); |
| 170 | if ($myphoto->isValid()) { |
| 171 | $myphoto->submit(); |
| 172 | } |
| 173 | } |
| 174 | } elseif (Env::has('trombi')) { |
| 175 | S::assert_xsrf_token(); |
| 176 | |
| 177 | $upload = new PlUpload(S::user()->login(), 'photo'); |
| 178 | if ($upload->copyFrom($trombi_x)) { |
| 179 | $myphoto = new PhotoReq(S::user(), $upload); |
| 180 | if ($myphoto->isValid()) { |
| 181 | $myphoto->commit(); |
| 182 | $myphoto->clean(); |
| 183 | } |
| 184 | } |
| 185 | } elseif (Env::v('suppr')) { |
| 186 | S::assert_xsrf_token(); |
| 187 | |
| 188 | XDB::execute('DELETE FROM photo |
| 189 | WHERE uid = {?}', |
| 190 | S::v('uid')); |
| 191 | XDB::execute('DELETE FROM requests |
| 192 | WHERE user_id = {?} AND type="photo"', |
| 193 | S::v('uid')); |
| 194 | $globals->updateNbValid(); |
| 195 | } elseif (Env::v('cancel')) { |
| 196 | S::assert_xsrf_token(); |
| 197 | |
| 198 | $sql = XDB::query('DELETE FROM requests |
| 199 | WHERE user_id={?} AND type="photo"', |
| 200 | S::v('uid')); |
| 201 | $globals->updateNbValid(); |
| 202 | } |
| 203 | |
| 204 | $sql = XDB::query('SELECT COUNT(*) |
| 205 | FROM requests |
| 206 | WHERE user_id={?} AND type="photo"', |
| 207 | S::v('uid')); |
| 208 | $page->assign('submited', $sql->fetchOneCell()); |
| 209 | $page->assign('has_trombi_x', file_exists($trombi_x)); |
| 210 | } |
| 211 | |
| 212 | function handler_profile(&$page, $x = null) |
| 213 | { |
| 214 | // TODO/note for upcoming developers: |
| 215 | // We currently maintain both $user and $login; $user is the old way of |
| 216 | // obtaining information, and eventually everything will be loaded |
| 217 | // through $login. That is the reason why in the template $user is named |
| 218 | // $x, and $login $user (sorry for the confusion). |
| 219 | |
| 220 | // Determines which user to display the profile of, and retrieves basic |
| 221 | // information on this user. |
| 222 | if (is_null($x)) { |
| 223 | return PL_NOT_FOUND; |
| 224 | } |
| 225 | |
| 226 | $login = S::logged() ? User::get($x) : User::getSilent($x); |
| 227 | if (!$login) { |
| 228 | return PL_NOT_FOUND; |
| 229 | } |
| 230 | |
| 231 | // Now that we know this is the profile of an existing user, we can |
| 232 | // switch to the appropriate template. |
| 233 | $page->changeTpl('profile/profile.tpl', SIMPLE); |
| 234 | require_once 'user.func.inc.php'; |
| 235 | |
| 236 | // Determines the access level at which the profile will be displayed. |
| 237 | if (!S::logged() || Env::v('view') == 'public') { |
| 238 | $view = 'public'; |
| 239 | } else if (S::logged() && Env::v('view') == 'ax') { |
| 240 | $view = 'ax'; |
| 241 | } else { |
| 242 | $view = 'private'; |
| 243 | } |
| 244 | |
| 245 | // Determines is the user is registered, and fetches the user infos in |
| 246 | // the appropriate way. |
| 247 | $res = XDB::query("SELECT perms IN ('admin','user','disabled') |
| 248 | FROM auth_user_md5 |
| 249 | WHERE user_id = {?}", $login->id()); |
| 250 | if ($res->fetchOneCell()) { |
| 251 | $new = Env::v('modif') == 'new'; |
| 252 | $user = get_user_details($login->login(), S::v('uid'), $view); |
| 253 | } else { |
| 254 | $new = false; |
| 255 | $user = array(); |
| 256 | if (S::logged()) { |
| 257 | pl_redirect('marketing/public/' . $login->login()); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | // Profile view are logged. |
| 262 | if (S::logged()) { |
| 263 | S::logger()->log('view_profile', $login->login()); |
| 264 | } |
| 265 | |
| 266 | // Sets the title of the html page. |
| 267 | $page->setTitle($login->fullName()); |
| 268 | |
| 269 | // Prepares the display of the user's mugshot. |
| 270 | $photo = 'photo/' . $login->login() . ($new ? '/req' : ''); |
| 271 | if (!isset($user['photo_pub']) || !has_user_right($user['photo_pub'], $view)) { |
| 272 | $photo = ""; |
| 273 | } |
| 274 | $page->assign('photo_url', $photo); |
| 275 | |
| 276 | if (!isset($user['y']) and !isset($user['x'])) { |
| 277 | list($user['x'], $user['y']) = getimagesize("images/none.png"); |
| 278 | } |
| 279 | if (!isset($user['y']) or $user['y'] < 1) $user['y']=1; |
| 280 | if (!isset($user['x']) or $user['x'] < 1) $user['x']=1; |
| 281 | if ($user['x'] > 240) { |
| 282 | $user['y'] = (integer)($user['y']*240/$user['x']); |
| 283 | $user['x'] = 240; |
| 284 | } |
| 285 | if ($user['y'] > 300) { |
| 286 | $user['x'] = (integer)($user['x']*300/$user['y']); |
| 287 | $user['y'] = 300; |
| 288 | } |
| 289 | if ($user['x'] < 160) { |
| 290 | $user['y'] = (integer)($user['y']*160/$user['x']); |
| 291 | $user['x'] = 160; |
| 292 | } |
| 293 | |
| 294 | // Determines and displays the virtual alias. |
| 295 | global $globals; |
| 296 | $res = XDB::query( |
| 297 | "SELECT alias |
| 298 | FROM virtual |
| 299 | INNER JOIN virtual_redirect USING (vid) |
| 300 | INNER JOIN auth_user_quick ON (user_id = {?} AND emails_alias_pub = 'public') |
| 301 | WHERE (redirect={?} OR redirect={?}) |
| 302 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
| 303 | $login->id(), |
| 304 | $login->forlifeEmail(), |
| 305 | // TODO(vzanotti): get ride of all @m4x.org addresses in the |
| 306 | // virtual redirect base, and remove this über-ugly hack. |
| 307 | $login->login() . '@' . $globals->mail->domain2); |
| 308 | $page->assign('virtualalias', $res->fetchOneCell()); |
| 309 | |
| 310 | // Adds miscellaneous properties to the display. |
| 311 | // Adds the global user property array to the display. |
| 312 | $page->assign_by_ref('x', $user); |
| 313 | $page->assign_by_ref('user', $login); |
| 314 | $page->assign('logged', has_user_right('private', $view)); |
| 315 | $page->assign('view', $view); |
| 316 | |
| 317 | $page->addJsLink('close_on_esc.js'); |
| 318 | if (isset($user['date'])) { |
| 319 | header('Last-Modified: ' . date('r', strtotime($user['date']))); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | function handler_ax(&$page, $user = null) |
| 324 | { |
| 325 | $user = User::get($user); |
| 326 | if (!$user) { |
| 327 | return PL_NOT_FOUND; |
| 328 | } |
| 329 | |
| 330 | $res = XDB::query("SELECT matricule_ax |
| 331 | FROM auth_user_md5 |
| 332 | WHERE user_id = {?}", $user->id()); |
| 333 | $mat = $res->fetchOneCell(); |
| 334 | if (!intval($mat)) { |
| 335 | $page->kill("Le matricule AX de {$user->login()} est inconnu"); |
| 336 | } |
| 337 | http_redirect("http://www.polytechniciens.com/?page=AX_FICHE_ANCIEN&anc_id=$mat"); |
| 338 | } |
| 339 | |
| 340 | function handler_p_edit(&$page, $opened_tab = null, $mode = null) |
| 341 | { |
| 342 | global $globals; |
| 343 | |
| 344 | // AX Synchronization |
| 345 | require_once 'synchro_ax.inc.php'; |
| 346 | if (is_ax_key_missing()) { |
| 347 | $page->assign('no_private_key', true); |
| 348 | } |
| 349 | if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) { |
| 350 | ax_synchronize(S::user()->login(), S::v('uid')); |
| 351 | $page->trigSuccess('Ton profil a été synchronisé avec celui du site polytechniciens.com'); |
| 352 | } |
| 353 | |
| 354 | // Build the page |
| 355 | $page->addJsLink('ajax.js'); |
| 356 | $page->addJsLink('education.js'); |
| 357 | $page->addJsLink('grades.js'); |
| 358 | $page->addJsLink('profile.js'); |
| 359 | $page->addJsLink('jquery.autocomplete.js'); |
| 360 | $wiz = new PlWizard('Profil', PlPage::getCoreTpl('plwizard.tpl'), true, true); |
| 361 | $this->load('page.inc.php'); |
| 362 | $wiz->addPage('ProfileGeneral', 'Général', 'general'); |
| 363 | $wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses'); |
| 364 | $wiz->addPage('ProfileGroups', 'Groupes X - Binets', 'poly'); |
| 365 | $wiz->addPage('ProfileDecos', 'Décorations - Medailles', 'deco'); |
| 366 | $wiz->addPage('ProfileJobs', 'Informations professionnelles', 'emploi'); |
| 367 | $wiz->addPage('ProfileSkills', 'Compétences diverses', 'skill'); |
| 368 | $wiz->addPage('ProfileMentor', 'Mentoring', 'mentor'); |
| 369 | $wiz->apply($page, 'profile/edit', $opened_tab, $mode); |
| 370 | |
| 371 | // Misc checks |
| 372 | $res = XDB::query("SELECT user_id |
| 373 | FROM auth_user_md5 |
| 374 | WHERE user_id = {?} AND naissance = '0000-00-00'", S::i('uid')); |
| 375 | if ($res->numRows()) { |
| 376 | $page->trigWarning("Ta date de naissance n'est pas renseignée, ce qui t'empêcheras de réaliser" |
| 377 | . " la procédure de récupération de mot de passe si un jour tu le perdais"); |
| 378 | } |
| 379 | |
| 380 | $page->setTitle('Mon Profil'); |
| 381 | } |
| 382 | |
| 383 | function handler_education_js(&$page) |
| 384 | { |
| 385 | header('Content-Type: text/javascript; charset=utf-8'); |
| 386 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
| 387 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 388 | header('Cache-Control: no-cache, must-revalidate'); |
| 389 | header('Pragma: no-cache'); |
| 390 | $page->changeTpl('profile/education.js.tpl', NO_SKIN); |
| 391 | require_once "education.func.inc.php"; |
| 392 | } |
| 393 | |
| 394 | function handler_grades_js(&$page) |
| 395 | { |
| 396 | header('Content-Type: text/javascript; charset=utf-8'); |
| 397 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
| 398 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 399 | header('Cache-Control: no-cache, must-revalidate'); |
| 400 | header('Pragma: no-cache'); |
| 401 | $page->changeTpl('profile/grades.js.tpl', NO_SKIN); |
| 402 | $res = XDB::iterator("SELECT * |
| 403 | FROM profile_medals_grades |
| 404 | ORDER BY mid, pos"); |
| 405 | $grades = array(); |
| 406 | while ($tmp = $res->next()) { |
| 407 | $grades[$tmp['mid']][] = $tmp; |
| 408 | } |
| 409 | $page->assign('grades', $grades); |
| 410 | |
| 411 | $res = XDB::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate |
| 412 | FROM profile_medals |
| 413 | ORDER BY type, text"); |
| 414 | $mlist = array(); |
| 415 | while ($tmp = $res->next()) { |
| 416 | $mlist[$tmp['type']][] = $tmp; |
| 417 | } |
| 418 | $page->assign('medal_list', $mlist); |
| 419 | } |
| 420 | |
| 421 | function handler_ajax_address(&$page, $adid) |
| 422 | { |
| 423 | header('Content-Type: text/html; charset=utf-8'); |
| 424 | $page->changeTpl('profile/adresses.address.tpl', NO_SKIN); |
| 425 | $page->assign('i', $adid); |
| 426 | $page->assign('adr', array()); |
| 427 | } |
| 428 | |
| 429 | function handler_ajax_tel(&$page, $prefid, $prefname, $telid) |
| 430 | { |
| 431 | header('Content-Type: text/html; charset=utf-8'); |
| 432 | $page->changeTpl('profile/phone.tpl', NO_SKIN); |
| 433 | $page->assign('prefid', $prefid); |
| 434 | $page->assign('prefname', $prefname); |
| 435 | $page->assign('telid', $telid); |
| 436 | $page->assign('tel', array()); |
| 437 | } |
| 438 | |
| 439 | function handler_ajax_edu(&$page, $eduid, $class) |
| 440 | { |
| 441 | header('Content-Type: text/html; charset=utf-8'); |
| 442 | $page->changeTpl('profile/edu.tpl', NO_SKIN); |
| 443 | $res = XDB::iterator("SELECT id, field |
| 444 | FROM profile_education_field_enum |
| 445 | ORDER BY field"); |
| 446 | $page->assign('edu_fields', $res->fetchAllAssoc()); |
| 447 | $page->assign('eduid', $eduid); |
| 448 | $page->assign('class', $class); |
| 449 | require_once "education.func.inc.php"; |
| 450 | } |
| 451 | |
| 452 | function handler_ajax_medal(&$page, $id) |
| 453 | { |
| 454 | header('Content-Type: text/html; charset=utf-8'); |
| 455 | $page->changeTpl('profile/deco.medal.tpl', NO_SKIN); |
| 456 | $page->assign('id', $id); |
| 457 | $page->assign('medal', array('valid' => 0, 'grade' => 0)); |
| 458 | } |
| 459 | |
| 460 | function handler_ajax_job(&$page, $id) |
| 461 | { |
| 462 | header('Content-Type: text/html; charset=utf-8'); |
| 463 | $page->changeTpl('profile/jobs.job.tpl', NO_SKIN); |
| 464 | $page->assign('i', $id); |
| 465 | $page->assign('job', array()); |
| 466 | $page->assign('new', true); |
| 467 | $res = XDB::query("SELECT id, name AS label |
| 468 | FROM profile_job_sector_enum"); |
| 469 | $page->assign('secteurs', $res->fetchAllAssoc()); |
| 470 | $res = XDB::query("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title |
| 471 | FROM fonctions_def |
| 472 | ORDER BY id"); |
| 473 | $page->assign('fonctions', $res->fetchAllAssoc()); |
| 474 | require_once "emails.combobox.inc.php"; |
| 475 | fill_email_combobox($page); |
| 476 | } |
| 477 | |
| 478 | function handler_ajax_secteur(&$page, $id, $jobid, $jobpref, $sect, $ssect = -1) |
| 479 | { |
| 480 | header('Content-Type: text/html; charset=utf-8'); |
| 481 | $res = XDB::iterator("SELECT id, name AS label, FIND_IN_SET('optgroup', flags) AS optgroup |
| 482 | FROM profile_job_subsector_enum |
| 483 | WHERE sectorid = {?}", $sect); |
| 484 | $page->changeTpl('profile/jobs.secteur.tpl', NO_SKIN); |
| 485 | $page->assign('id', $id); |
| 486 | $page->assign('ssecteurs', $res); |
| 487 | $page->assign('sel', $ssect); |
| 488 | if ($id != -1) { |
| 489 | $page->assign('change', 1); |
| 490 | $page->assign('jobid', $jobid); |
| 491 | $page->assign('jobpref', $jobpref); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | function handler_ajax_ssecteur(&$page, $id, $ssect, $sssect = -1) |
| 496 | { |
| 497 | header('Content-Type: text/html; charset=utf-8'); |
| 498 | $res = XDB::iterator("SELECT id, name AS label |
| 499 | FROM profile_job_subsubsector_enum |
| 500 | WHERE subsectorid = {?}", $ssect); |
| 501 | $page->changeTpl('profile/jobs.soussecteur.tpl', NO_SKIN); |
| 502 | $page->assign('id', $id); |
| 503 | $page->assign('sssecteurs', $res); |
| 504 | $page->assign('sel', $sssect); |
| 505 | } |
| 506 | |
| 507 | function handler_ajax_skill(&$page, $cat, $id) |
| 508 | { |
| 509 | header('Content-Type: text/html; charset=utf-8'); |
| 510 | $page->changeTpl('profile/skill.skill.tpl', NO_SKIN); |
| 511 | $page->assign('cat', $cat); |
| 512 | $page->assign('id', $id); |
| 513 | if ($cat == 'competences') { |
| 514 | $page->assign('levels', array('initié' => 'initié', |
| 515 | 'bonne connaissance' => 'bonne connaissance', |
| 516 | 'expert' => 'expert')); |
| 517 | } else { |
| 518 | $page->assign('levels', array(1 => 'connaissance basique', |
| 519 | 2 => 'maîtrise des bases', |
| 520 | 3 => 'maîtrise limitée', |
| 521 | 4 => 'maîtrise générale', |
| 522 | 5 => 'bonne maîtrise', |
| 523 | 6 => 'maîtrise complète')); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | function handler_ajax_searchname(&$page, $snid) |
| 528 | { |
| 529 | header('Content-Type: text/html; charset=utf-8'); |
| 530 | $page->changeTpl('profile/general.searchname.tpl', NO_SKIN); |
| 531 | $page->assign('i', $snid); |
| 532 | $page->assign('sn', array()); |
| 533 | $page->assign('newsn', true); |
| 534 | } |
| 535 | |
| 536 | function handler_p_orange(&$page) |
| 537 | { |
| 538 | $page->changeTpl('profile/orange.tpl'); |
| 539 | |
| 540 | require_once 'validations.inc.php'; |
| 541 | |
| 542 | $res = XDB::query("SELECT e.entry_year, e.grad_year, d.promo_display, FIND_IN_SET('femme', u.flags) AS sexe |
| 543 | FROM auth_user_md5 AS u |
| 544 | INNER JOIN profile_display AS d ON (d.uid = u.user_id) |
| 545 | INNER JOIN profile_education AS e ON (e.uid = u.user_id AND FIND_IN_SET('primary', e.flags)) |
| 546 | WHERE u.user_id = {?}", S::v('uid')); |
| 547 | |
| 548 | list($promo, $promo_sortie_old, $promo_display, $sexe) = $res->fetchOneRow(); |
| 549 | $page->assign('promo_sortie_old', $promo_sortie_old); |
| 550 | $page->assign('promo', $promo); |
| 551 | $page->assign('promo_display', $promo_display); |
| 552 | $page->assign('sexe', $sexe); |
| 553 | |
| 554 | if (!Env::has('promo_sortie')) { |
| 555 | return; |
| 556 | } else { |
| 557 | S::assert_xsrf_token(); |
| 558 | } |
| 559 | |
| 560 | $promo_sortie = Env::i('promo_sortie'); |
| 561 | |
| 562 | if ($promo_sortie < 1000 || $promo_sortie > 9999) { |
| 563 | $page->trigError('L\'année de sortie doit être un nombre de quatre chiffres.'); |
| 564 | } |
| 565 | elseif ($promo_sortie < $promo + 3) { |
| 566 | $page->trigError('Trop tôt !'); |
| 567 | } |
| 568 | elseif ($promo_sortie == $promo_sortie_old) { |
| 569 | $page->trigWarning('Tu appartiens déjà à la promotion correspondante à cette année de sortie.'); |
| 570 | } |
| 571 | elseif ($promo_sortie == $promo + 3) { |
| 572 | XDB::execute("UPDATE profile_education |
| 573 | SET grad_year = {?} |
| 574 | WHERE uid = {?} AND FIND_IN_SET('primary', flags)", $promo_sortie, S::v('uid')); |
| 575 | $page->trigSuccess('Ton statut "orange" a été supprimé.'); |
| 576 | $page->assign('promo_sortie_old', $promo_sortie); |
| 577 | } |
| 578 | else { |
| 579 | $page->assign('promo_sortie', $promo_sortie); |
| 580 | |
| 581 | if (Env::has('submit')) { |
| 582 | $myorange = new OrangeReq(S::user(), $promo_sortie); |
| 583 | $myorange->submit(); |
| 584 | $page->assign('myorange', $myorange); |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | function handler_referent(&$page, $x = null) |
| 590 | { |
| 591 | require_once 'user.func.inc.php'; |
| 592 | $page->changeTpl('profile/fiche_referent.tpl', SIMPLE); |
| 593 | |
| 594 | $user = User::get($x); |
| 595 | if ($user == null) { |
| 596 | return PL_NOT_FOUND; |
| 597 | } |
| 598 | |
| 599 | $res = XDB::query("SELECT cv FROM auth_user_md5 WHERE user_id = {?}", $user->id()); |
| 600 | $cv = $res->fetchOneCell(); |
| 601 | |
| 602 | $page->assign_by_ref('user', $user); |
| 603 | $page->assign('cv', MiniWiki::WikiToHTML($cv, true)); |
| 604 | $page->assign('adr_pro', get_user_details_pro($user->id())); |
| 605 | |
| 606 | ///// recuperations infos referent |
| 607 | |
| 608 | //expertise |
| 609 | $res = XDB::query("SELECT expertise FROM profile_mentor WHERE uid = {?}", $user->id()); |
| 610 | $page->assign('expertise', $res->fetchOneCell()); |
| 611 | |
| 612 | //secteurs |
| 613 | $secteurs = $ss_secteurs = Array(); |
| 614 | $res = XDB::iterRow( |
| 615 | "SELECT s.name AS label, ss.name AS label |
| 616 | FROM profile_mentor_sector AS m |
| 617 | LEFT JOIN profile_job_sector_enum AS s ON(m.sectorid = s.id) |
| 618 | LEFT JOIN profile_job_subsector_enum AS ss ON(m.sectorid = ss.sectorid AND m.subsectorid = ss.id) |
| 619 | WHERE uid = {?}", $user->id()); |
| 620 | while (list($sec, $ssec) = $res->next()) { |
| 621 | $secteurs[] = $sec; |
| 622 | $ss_secteurs[] = $ssec; |
| 623 | } |
| 624 | $page->assign_by_ref('secteurs', $secteurs); |
| 625 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
| 626 | |
| 627 | //pays |
| 628 | $res = XDB::query( |
| 629 | "SELECT gp.pays |
| 630 | FROM profile_mentor_country AS m |
| 631 | LEFT JOIN geoloc_pays AS gp ON (m.country = gp.a2) |
| 632 | WHERE uid = {?}", $user->id()); |
| 633 | $page->assign('pays', $res->fetchColumn()); |
| 634 | |
| 635 | $page->addJsLink('close_on_esc.js'); |
| 636 | } |
| 637 | |
| 638 | function handler_ref_search(&$page, $action = null, $subaction = null) |
| 639 | { |
| 640 | $wp = new PlWikiPage('Docs.Emploi'); |
| 641 | $wp->buildCache(); |
| 642 | |
| 643 | $page->setTitle('Conseil Pro'); |
| 644 | |
| 645 | //recuperation des noms de secteurs |
| 646 | $res = XDB::iterRow("SELECT id, name AS label FROM profile_job_sector_enum"); |
| 647 | $secteurs[''] = ''; |
| 648 | while (list($tmp_id, $tmp_label) = $res->next()) { |
| 649 | $secteurs[$tmp_id] = $tmp_label; |
| 650 | } |
| 651 | $page->assign_by_ref('secteurs', $secteurs); |
| 652 | |
| 653 | // nb de mentors |
| 654 | $res = XDB::query("SELECT count(*) FROM profile_mentor"); |
| 655 | $page->assign('mentors_number', $res->fetchOneCell()); |
| 656 | |
| 657 | // On vient d'un formulaire |
| 658 | $where = array(); |
| 659 | $pays_sel = XDB::escape(Env::v('pays_sel')); |
| 660 | $secteur_sel = XDB::escape(Env::v('secteur')); |
| 661 | $ss_secteur_sel = XDB::escape(Env::v('ss_secteur')); |
| 662 | $expertise_champ = XDB::escape(Env::v('expertise')); |
| 663 | |
| 664 | if ($pays_sel != "''") { |
| 665 | $where[] = "mp.country = $pays_sel"; |
| 666 | } |
| 667 | if ($secteur_sel != "''") { |
| 668 | $where[] = "ms.sectorid = $secteur_sel"; |
| 669 | if ($ss_secteur_sel != "''") { |
| 670 | $where[] = "ms.subsectorid = $ss_secteur_sel"; |
| 671 | } |
| 672 | } |
| 673 | if ($expertise_champ != "''") { |
| 674 | $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)"; |
| 675 | } |
| 676 | |
| 677 | if ($where) { |
| 678 | $where = join(' AND ', $where); |
| 679 | |
| 680 | $set = new UserSet("INNER JOIN profile_mentor AS m ON (m.uid = u.user_id) |
| 681 | LEFT JOIN profile_mentor_country AS mp ON (mp.uid = m.uid) |
| 682 | LEFT JOIN profile_mentor_sector AS ms ON (ms.uid = m.uid)", |
| 683 | $where); |
| 684 | $set->addMod('mentor', 'Référents'); |
| 685 | $set->apply('referent/search', $page, $action, $subaction); |
| 686 | if ($set->count() > 100) { |
| 687 | $page->assign('recherche_trop_large', true); |
| 688 | } |
| 689 | } |
| 690 | $page->changeTpl('profile/referent.tpl'); |
| 691 | } |
| 692 | |
| 693 | function handler_ref_sect(&$page, $sect) |
| 694 | { |
| 695 | header('Content-Type: text/html; charset=utf-8'); |
| 696 | $page->changeTpl('include/field.select.tpl', NO_SKIN); |
| 697 | $page->assign('onchange', 'setSSecteurs()'); |
| 698 | $page->assign('id', 'ssect_field'); |
| 699 | $page->assign('name', 'ss_secteur'); |
| 700 | $it = XDB::iterator("SELECT id, name AS field |
| 701 | FROM profile_job_subsector_enum |
| 702 | WHERE sectorid = {?}", $sect); |
| 703 | $page->assign('list', $it); |
| 704 | } |
| 705 | |
| 706 | function handler_ref_country(&$page, $sect, $ssect = '') |
| 707 | { |
| 708 | header('Content-Type: text/html; charset=utf-8'); |
| 709 | $page->changeTpl('include/field.select.tpl', NO_SKIN); |
| 710 | $page->assign('name', 'pays_sel'); |
| 711 | $where = ($ssect ? ' AND ms.subsectorid = {?}' : ''); |
| 712 | $it = XDB::iterator("SELECT a2 AS id, pays AS field |
| 713 | FROM geoloc_pays AS g |
| 714 | INNER JOIN profile_mentor_country AS mp ON (mp.country = g.a2) |
| 715 | INNER JOIN profile_mentor_sector AS ms ON (ms.uid = mp.uid) |
| 716 | WHERE ms.sectorid = {?} $where |
| 717 | GROUP BY a2 |
| 718 | ORDER BY pays", $sect, $ssect); |
| 719 | $page->assign('list', $it); |
| 720 | } |
| 721 | |
| 722 | function handler_p_usage(&$page) |
| 723 | { |
| 724 | $page->changeTpl('profile/nomusage.tpl'); |
| 725 | |
| 726 | require_once 'validations.inc.php'; |
| 727 | |
| 728 | $res = XDB::query( |
| 729 | "SELECT u.nom, u.nom_usage, u.flags, e.alias |
| 730 | FROM auth_user_md5 AS u |
| 731 | LEFT JOIN aliases AS e ON(u.user_id = e.id |
| 732 | AND FIND_IN_SET('usage', e.flags)) |
| 733 | WHERE user_id={?}", S::v('uid')); |
| 734 | |
| 735 | list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow(); |
| 736 | $flags = new PlFlagSet($flags); |
| 737 | $page->assign('usage_old', $usage_old); |
| 738 | $page->assign('alias_old', $alias_old); |
| 739 | |
| 740 | $nom_usage = replace_accent(trim(Env::v('nom_usage'))); |
| 741 | $nom_usage = strtoupper($nom_usage); |
| 742 | $page->assign('usage_req', $nom_usage); |
| 743 | |
| 744 | if (Env::has('submit') && ($nom_usage != $usage_old)) { |
| 745 | S::assert_xsrf_token(); |
| 746 | |
| 747 | // on vient de recevoir une requete, differente de l'ancien nom d'usage |
| 748 | if ($nom_usage == $nom) { |
| 749 | $page->trigWarning('Le nom d\'usage que tu demandes est identique à ton nom à l\'X, ' |
| 750 | . 'aucune modification n\'a donc été effectuée.'); |
| 751 | $page->assign('same', true); |
| 752 | } else { // le nom de mariage est distinct du nom à l'X |
| 753 | // on calcule l'alias pour l'afficher |
| 754 | $reason = Env::v('reason'); |
| 755 | if ($reason == 'other') { |
| 756 | $reason = Env::v('other_reason'); |
| 757 | } |
| 758 | $myusage = new UsageReq(S::user(), $nom_usage, $reason); |
| 759 | $myusage->submit(); |
| 760 | $page->assign('myusage', $myusage); |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | function handler_xnet(&$page) |
| 766 | { |
| 767 | $page->changeTpl('profile/groupesx.tpl'); |
| 768 | $page->setTitle('Promo, Groupes X, Binets'); |
| 769 | |
| 770 | $req = XDB::query(' |
| 771 | SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo, |
| 772 | COUNT(e.eid) AS events, mail_domain AS lists |
| 773 | FROM groupex.membres AS m |
| 774 | INNER JOIN groupex.asso AS a ON(m.asso_id = a.id) |
| 775 | LEFT JOIN groupex.evenements AS e ON(e.asso_id = m.asso_id AND e.archive = 0) |
| 776 | WHERE uid = {?} GROUP BY m.asso_id ORDER BY a.nom', S::i('uid')); |
| 777 | $page->assign('assos', $req->fetchAllAssoc()); |
| 778 | } |
| 779 | |
| 780 | function handler_vcard(&$page, $x = null) |
| 781 | { |
| 782 | if (is_null($x)) { |
| 783 | return PL_NOT_FOUND; |
| 784 | } |
| 785 | |
| 786 | global $globals; |
| 787 | |
| 788 | if (substr($x, -4) == '.vcf') { |
| 789 | $x = substr($x, 0, strlen($x) - 4); |
| 790 | } |
| 791 | |
| 792 | $vcard = new VCard(); |
| 793 | $vcard->addUser($x); |
| 794 | $vcard->show(); |
| 795 | } |
| 796 | |
| 797 | function handler_admin_trombino(&$page, $login = null, $action = null) { |
| 798 | $page->changeTpl('profile/admin_trombino.tpl'); |
| 799 | $page->setTitle('Administration - Trombino'); |
| 800 | |
| 801 | if (!$login || !($user = User::get($login))) { |
| 802 | return PL_NOT_FOUND; |
| 803 | } else { |
| 804 | $page->assign_by_ref('user', $user); |
| 805 | } |
| 806 | |
| 807 | switch ($action) { |
| 808 | case "original": |
| 809 | header("Content-type: image/jpeg"); |
| 810 | readfile("/home/web/trombino/photos" . $user->promo() . "/" . $user->login() . ".jpg"); |
| 811 | exit; |
| 812 | break; |
| 813 | |
| 814 | case "new": |
| 815 | S::assert_xsrf_token(); |
| 816 | |
| 817 | $data = file_get_contents($_FILES['userfile']['tmp_name']); |
| 818 | list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']); |
| 819 | $mimetype = substr($_FILES['userfile']['type'], 6); |
| 820 | unlink($_FILES['userfile']['tmp_name']); |
| 821 | XDB::execute( |
| 822 | "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}", |
| 823 | $user->id(), $mimetype, $data, $x, $y); |
| 824 | break; |
| 825 | |
| 826 | case "delete": |
| 827 | S::assert_xsrf_token(); |
| 828 | |
| 829 | XDB::execute('DELETE FROM photo WHERE uid = {?}', $user->id()); |
| 830 | break; |
| 831 | } |
| 832 | } |
| 833 | function handler_admin_binets(&$page, $action = 'list', $id = null) { |
| 834 | $page->setTitle('Administration - Binets'); |
| 835 | $page->assign('title', 'Gestion des binets'); |
| 836 | $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id'); |
| 837 | $table_editor->add_join_table('binets_ins','binet_id',true); |
| 838 | $table_editor->describe('text','intitulé',true); |
| 839 | $table_editor->apply($page, $action, $id); |
| 840 | } |
| 841 | function handler_admin_education(&$page, $action = 'list', $id = null) { |
| 842 | $page->setTitle('Administration - Formations'); |
| 843 | $page->assign('title', 'Gestion des formations'); |
| 844 | $table_editor = new PLTableEditor('admin/education', 'profile_education_enum', 'id'); |
| 845 | $table_editor->add_join_table('profile_education', 'eduid', true); |
| 846 | $table_editor->add_join_table('profile_education_degree', 'eduid', true); |
| 847 | $table_editor->describe('name', 'intitulé', true); |
| 848 | $table_editor->describe('url', 'site web', false); |
| 849 | $table_editor->apply($page, $action, $id); |
| 850 | } |
| 851 | function handler_admin_education_field(&$page, $action = 'list', $id = null) { |
| 852 | $page->setTitle('Administration - Domaines de formation'); |
| 853 | $page->assign('title', 'Gestion des domaines de formation'); |
| 854 | $table_editor = new PLTableEditor('admin/education_field', 'profile_education_field_enum', 'id', true); |
| 855 | $table_editor->add_join_table('profile_education', 'fieldid', true); |
| 856 | $table_editor->describe('field', 'domaine', true); |
| 857 | $table_editor->apply($page, $action, $id); |
| 858 | } |
| 859 | function handler_admin_education_degree(&$page, $action = 'list', $id = null) { |
| 860 | $page->setTitle('Administration - Niveau de formation'); |
| 861 | $page->assign('title', 'Gestion des niveau de formation'); |
| 862 | $table_editor = new PLTableEditor('admin/education_degree', 'profile_education_degree_enum', 'id', true); |
| 863 | $table_editor->add_join_table('profile_education_degree', 'degreeid', true); |
| 864 | $table_editor->add_join_table('profile_education', 'degreeid', true); |
| 865 | $table_editor->describe('degree', 'niveau', true); |
| 866 | $table_editor->apply($page, $action, $id); |
| 867 | } |
| 868 | function handler_admin_education_degree_set(&$page, $action = 'list', $id = null) { |
| 869 | $page->setTitle('Administration - Correspondances formations - niveau de formation'); |
| 870 | $page->assign('title', 'Gestion des correspondances formations - niveau de formation'); |
| 871 | $table_editor = new PLTableEditor('admin/education_degree_set', 'profile_education_degree', 'eduid', true); |
| 872 | $table_editor->describe('eduid', 'formation', true); |
| 873 | $table_editor->describe('degreeid', 'niveau', true); |
| 874 | $table_editor->apply($page, $action, $id); |
| 875 | } |
| 876 | function handler_admin_sections(&$page, $action = 'list', $id = null) { |
| 877 | $page->setTitle('Administration - Sections'); |
| 878 | $page->assign('title', 'Gestion des sections'); |
| 879 | $table_editor = new PLTableEditor('admin/sections','sections','id'); |
| 880 | $table_editor->describe('text','intitulé',true); |
| 881 | $table_editor->apply($page, $action, $id); |
| 882 | } |
| 883 | function handler_admin_ss_secteurs(&$page, $action = 'list', $id = null) { |
| 884 | $page->setTitle('Administration - Sous-secteurs'); |
| 885 | $page->assign('title', 'Gestion des sous-secteurs'); |
| 886 | $table_editor = new PLTableEditor('admin/ss_secteurs', 'emploi_ss_secteur', 'id', true); |
| 887 | $table_editor->describe('label', 'intitulé', true); |
| 888 | $table_editor->apply($page, $action, $id); |
| 889 | } |
| 890 | function handler_admin_fonctions(&$page, $action = 'list', $id = null) { |
| 891 | $page->setTitle('Administration - Fonctions'); |
| 892 | $page->assign('title', 'Gestion des fonctions'); |
| 893 | $table_editor = new PLTableEditor('admin/fonctions', 'fonctions_def', 'id', true); |
| 894 | $table_editor->describe('fonction_fr', 'intitulé', true); |
| 895 | $table_editor->describe('fonction_en', 'intitulé (ang)', true); |
| 896 | $table_editor->describe('flags', 'titre', true); |
| 897 | $table_editor->apply($page, $action, $id); |
| 898 | } |
| 899 | function handler_admin_secteurs(&$page, $action = 'list', $id = null) { |
| 900 | $page->setTitle('Administration - Secteurs'); |
| 901 | $page->assign('title', 'Gestion des secteurs'); |
| 902 | $table_editor = new PLTableEditor('admin/secteurs', 'emploi_secteur', 'id', true); |
| 903 | $table_editor->describe('label', 'intitulé', true); |
| 904 | $table_editor->apply($page, $action, $id); |
| 905 | } |
| 906 | function handler_admin_networking(&$page, $action = 'list', $id = null) { |
| 907 | $page->assign('xorg_title', 'Polytechnique.org - Administration - Networking'); |
| 908 | $page->assign('title', 'Gestion des types de networking'); |
| 909 | $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'network_type'); |
| 910 | $table_editor->describe('name', 'intitulé', true); |
| 911 | $table_editor->describe('icon', 'nom de l\'icône', false); |
| 912 | $table_editor->describe('filter', 'filtre', true); |
| 913 | $table_editor->describe('link', 'lien web', true); |
| 914 | $table_editor->apply($page, $action, $id); |
| 915 | } |
| 916 | function handler_admin_corps_enum(&$page, $action = 'list', $id = null) { |
| 917 | $page->setTitle('Administration - Corps'); |
| 918 | $page->assign('title', 'Gestion des Corps'); |
| 919 | $table_editor = new PLTableEditor('admin/corps_enum', 'profile_corps_enum', 'id'); |
| 920 | $table_editor->describe('name', 'intitulé', true); |
| 921 | $table_editor->describe('abbreviation', 'abbréviation', true); |
| 922 | $table_editor->describe('still_exists', 'existe encore ?', true); |
| 923 | $table_editor->apply($page, $action, $id); |
| 924 | } |
| 925 | function handler_admin_corps_rank(&$page, $action = 'list', $id = null) { |
| 926 | $page->setTitle('Administration - Grade dans les Corps'); |
| 927 | $page->assign('title', 'Gestion des grade dans les Corps'); |
| 928 | $table_editor = new PLTableEditor('admin/corps_rank', 'profile_corps_rank_enum', 'id'); |
| 929 | $table_editor->describe('name', 'intitulé', true); |
| 930 | $table_editor->describe('abbreviation', 'abbréviation', true); |
| 931 | $table_editor->apply($page, $action, $id); |
| 932 | } |
| 933 | function handler_admin_medals(&$page, $action = 'list', $id = null) { |
| 934 | $page->setTitle('Administration - Distinctions'); |
| 935 | $page->assign('title', 'Gestion des Distinctions'); |
| 936 | $table_editor = new PLTableEditor('admin/medals','profile_medals','id'); |
| 937 | $table_editor->describe('text', 'intitulé', true); |
| 938 | $table_editor->describe('img', 'nom de l\'image', false); |
| 939 | $table_editor->describe('flags', 'valider', true); |
| 940 | $table_editor->apply($page, $action, $id); |
| 941 | if ($id && $action == 'edit') { |
| 942 | $page->changeTpl('profile/admin_decos.tpl'); |
| 943 | |
| 944 | $mid = $id; |
| 945 | |
| 946 | if (Post::v('act') == 'del') { |
| 947 | XDB::execute('DELETE FROM profile_medals_grades |
| 948 | WHERE mid={?} AND gid={?}', $mid, Post::i('gid')); |
| 949 | } else { |
| 950 | foreach (Post::v('grades', array()) as $gid=>$text) { |
| 951 | if ($gid === 0) { |
| 952 | if (!empty($text)) { |
| 953 | $res = XDB::query('SELECT MAX(gid) |
| 954 | FROM profile_medals_grades |
| 955 | WHERE mid = {?}', $mid); |
| 956 | $gid = $res->fetchOneCell() + 1; |
| 957 | |
| 958 | XDB::execute('INSERT INTO profile_medals_grades (mid, gid, text, pos) |
| 959 | VALUES ({?}, {?}, {?}, {?})', |
| 960 | $mid, $gid, $text, $_POST['pos']['0']); |
| 961 | } |
| 962 | } else { |
| 963 | XDB::execute('UPDATE profile_medals_grades |
| 964 | SET pos={?}, text={?} |
| 965 | WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid); |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid); |
| 970 | $page->assign('grades', $res); |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 976 | ?> |