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