2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class AdminModule
extends PLModule
27 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP
, 'admin'),
28 'get_rights' => $this->make_hook('get_rights', AUTH_MDP
, 'admin'),
29 'admin' => $this->make_hook('default', AUTH_MDP
, 'admin'),
30 'admin/dead-but-active' => $this->make_hook('dead_but_active', AUTH_MDP
, 'admin'),
31 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP
, 'admin'),
32 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP
, 'admin'),
33 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP
, 'admin'),
34 'admin/logger' => $this->make_hook('logger', AUTH_MDP
, 'admin'),
35 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP
, 'admin'),
36 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP
, 'admin'),
37 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP
, 'admin'),
38 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP
, 'admin'),
39 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP
, 'admin'),
40 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP
, 'admin'),
41 'admin/skins' => $this->make_hook('skins', AUTH_MDP
, 'admin'),
42 'admin/user' => $this->make_hook('user', AUTH_MDP
, 'admin'),
43 'admin/add_accounts' => $this->make_hook('add_accounts', AUTH_MDP
, 'admin'),
44 'admin/validate' => $this->make_hook('validate', AUTH_MDP
, 'admin'),
45 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP
, 'admin'),
46 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP
, 'admin'),
47 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP
, 'admin'),
48 'admin/icons' => $this->make_hook('icons', AUTH_MDP
, 'admin'),
49 'admin/accounts' => $this->make_hook('accounts', AUTH_MDP
, 'admin'),
50 'admin/account/types' => $this->make_hook('account_types', AUTH_MDP
, 'admin'),
51 'admin/jobs' => $this->make_hook('jobs', AUTH_MDP
, 'admin'),
55 function handler_phpinfo(&$page)
61 function handler_get_rights(&$page, $level)
64 $page->kill('Déjà en SUID');
67 Platal
::session()->startSUID($user, $level);
72 function handler_default(&$page)
74 $page->changeTpl('admin/index.tpl');
75 $page->setTitle('Administration');
78 function handler_postfix_delayed(&$page)
80 $page->changeTpl('admin/postfix_delayed.tpl');
81 $page->setTitle('Administration - Postfix : Retardés');
83 if (Env
::has('del')) {
85 XDB
::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
86 $page->trigSuccess($crc . " verra tous ses emails supprimés !");
87 } elseif (Env
::has('ok')) {
89 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
90 $page->trigSuccess($crc . " a le droit de passer !");
94 "SELECT crc, nb, update_time, create_time,
95 FIND_IN_SET('del', p.release) AS del,
96 FIND_IN_SET('ok', p.release) AS ok
97 FROM postfix_mailseen AS p
99 ORDER BY p.release != ''");
101 $page->assign_by_ref('mails', $sql);
104 function handler_postfix_regexpsbounces(&$page, $new = null
) {
105 $page->changeTpl('admin/emails_bounces_re.tpl');
106 $page->setTitle('Administration - Postfix : Regexps Bounces');
107 $page->assign('new', $new);
109 if (Post
::has('submit')) {
110 foreach (Env
::v('lvl') as $id=>$val) {
112 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
113 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
118 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
123 /** Retrieves the available days for a given year and month.
124 * Obtain a list of days of the given month in the given year
125 * that are within the range of dates that we have log entries for.
127 * @param integer year
128 * @param integer month
129 * @return array days in that month we have log entries covering.
132 function _getDays($year, $month)
134 // give a 'no filter' option
138 if ($year && $month) {
139 $day_max = Array(-1, 31, checkdate(2, 29, $year) ?
29 : 28 , 31,
140 30, 31, 30, 31, 31, 30, 31, 30, 31);
141 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
142 MONTH(MAX(start)), MONTH(MIN(start)),
143 DAYOFMONTH(MAX(start)),
144 DAYOFMONTH(MIN(start))
146 list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow();
148 if (($year < $ymin) ||
($year == $ymin && $month < $mmin)) {
152 if (($year > $ymax) ||
($year == $ymax && $month > $mmax)) {
156 $min = ($year==$ymin && $month==$mmin) ?
intval($dmin) : 1;
157 $max = ($year==$ymax && $month==$mmax) ?
intval($dmax) : $day_max[$month];
159 for($i = $min; $i<=$max; $i++
) {
167 /** Retrieves the available months for a given year.
168 * Obtains a list of month numbers that are within the timeframe that
169 * we have log entries for.
171 * @param integer year
172 * @return array List of month numbers we have log info for.
175 function _getMonths($year)
177 // give a 'no filter' option
182 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
183 MONTH(MAX(start)), MONTH(MIN(start))
185 list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow();
187 if (($year < $ymin) ||
($year > $ymax)) {
191 $min = $year == $ymin ?
intval($mmin) : 1;
192 $max = $year == $ymax ?
intval($mmax) : 12;
194 for($i = $min; $i<=$max; $i++
) {
202 /** Retrieves the available years.
203 * Obtains a list of years that we have log entries covering.
205 * @return array years we have log entries for.
210 // give a 'no filter' option
214 // retrieve available years
215 $res = XDB
::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM log_sessions");
216 list($max, $min) = $res->fetchOneRow();
218 for($i = intval($min); $i<=$max; $i++
) {
225 /** Make a where clause to get a user's sessions.
226 * Prepare the where clause request that will retrieve the sessions.
228 * @param $year INTEGER Only get log entries made during the given year.
229 * @param $month INTEGER Only get log entries made during the given month.
230 * @param $day INTEGER Only get log entries made during the given day.
231 * @param $uid INTEGER Only get log entries referring to the given user ID.
233 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
236 function _makeWhere($year, $month, $day, $uid)
238 // start constructing the "where" clause
242 array_push($where, "s.uid='$uid'");
244 // we were given at least a year
247 $dmin = mktime(0, 0, 0, $month, $day, $year);
248 $dmax = mktime(0, 0, 0, $month, $day+
1, $year);
250 $dmin = mktime(0, 0, 0, $month, 1, $year);
251 $dmax = mktime(0, 0, 0, $month+
1, 1, $year);
253 $dmin = mktime(0, 0, 0, 1, 1, $year);
254 $dmax = mktime(0, 0, 0, 1, 1, $year+
1);
256 $where[] = "start >= " . date("Ymd000000", $dmin);
257 $where[] = "start < " . date("Ymd000000", $dmax);
260 if (!empty($where)) {
261 return ' WHERE ' . implode($where, " AND ");
265 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
270 function handler_logger(&$page, $action = null
, $arg = null
) {
271 if ($action == 'session') {
273 // we are viewing a session
274 $res = XDB
::query("SELECT ls.*, a.alias AS username, sa.alias AS suer
275 FROM log_sessions AS ls
276 LEFT JOIN aliases AS a ON (a.uid = ls.uid AND a.type='a_vie')
277 LEFT JOIN aliases AS sa ON (sa.uid = ls.suid AND sa.type='a_vie')
278 WHERE ls.id = {?}", $arg);
280 $page->assign('session', $a = $res->fetchOneAssoc());
282 $res = XDB
::iterator('SELECT a.text, e.data, e.stamp
284 LEFT JOIN log_actions AS a ON e.action=a.id
285 WHERE e.session={?}', $arg);
286 while ($myarr = $res->next()) {
287 $page->append('events', $myarr);
291 $loguser = $action == 'user' ?
$arg : Env
::v('loguser');
293 $res = XDB
::query('SELECT uid FROM aliases WHERE alias={?}',
295 $loguid = $res->fetchOneCell();
298 $year = Env
::i('year');
299 $month = Env
::i('month');
300 $day = Env
::i('day');
302 $year = Env
::i('year', intval(date('Y')));
303 $month = Env
::i('month', intval(date('m')));
304 $day = Env
::i('day', intval(date('d')));
312 // smarty assignments
313 // retrieve available years
314 $page->assign('years', $this->_getYears());
315 $page->assign('year', $year);
317 // retrieve available months for the current year
318 $page->assign('months', $this->_getMonths($year));
319 $page->assign('month', $month);
321 // retrieve available days for the current year and month
322 $page->assign('days', $this->_getDays($year, $month));
323 $page->assign('day', $day);
325 $page->assign('loguser', $loguser);
326 // smarty assignments
328 if ($loguid ||
$year) {
330 // get the requested sessions
331 $where = $this->_makeWhere($year, $month, $day, $loguid);
332 $select = "SELECT s.id, s.start, s.uid,
334 FROM log_sessions AS s
335 LEFT JOIN aliases AS a ON (a.uid = s.uid AND a.type='a_vie')
337 ORDER BY start DESC";
338 $res = XDB
::iterator($select);
341 while ($mysess = $res->next()) {
342 $mysess['events'] = array();
343 $sessions[$mysess['id']] = $mysess;
345 array_reverse($sessions);
348 $sql = "SELECT s.id, a.text
349 FROM log_sessions AS s
350 LEFT JOIN log_events AS e ON(e.session=s.id)
351 INNER JOIN log_actions AS a ON(a.id=e.action)
354 $res = XDB
::iterator($sql);
355 while ($event = $res->next()) {
356 array_push($sessions[$event['id']]['events'], $event['text']);
358 $page->assign_by_ref('sessions', $sessions);
360 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
364 $page->changeTpl('admin/logger-view.tpl');
366 $page->setTitle('Administration - Logs des sessions');
369 function handler_user(&$page, $login = false
)
372 $page->changeTpl('admin/user.tpl');
373 $page->setTitle('Administration - Compte');
376 $page->kill("Déjà en SUID !!!");
379 // Loads the user identity using the environment.
381 $user = User
::get($login);
387 $login = $user->login();
388 $registered = ($user->state
!= 'pending');
391 if (!empty($_POST)) {
392 S
::assert_xsrf_token();
393 if (Post
::has('uid') && Post
::i('uid') != $user->id()) {
394 $page->kill('Une erreur s\'est produite');
398 // Handles specific requests (AX sync, su, ...).
399 if(Post
::has('log_account')) {
400 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
403 if(Post
::has('su_account') && $registered) {
404 if (!Platal
::session()->startSUID($user)) {
405 $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login());
412 $to_update = array();
413 if (Post
::has('disable_weak_access')) {
414 $to_update['weak_password'] = null
;
415 } else if (Post
::has('update_account')) {
416 if (!$user->hasProfile()) {
417 if (Post
::s('full_name') != $user->fullName()) {
418 $to_update['full_name'] = Post
::s('full_name');
420 if (Post
::s('display_name') != $user->displayName()) {
421 $to_update['display_name'] = Post
::s('display_name');
423 if (Post
::s('directory_name') != $user->directoryName()) {
424 $to_update['directory_name'] = Post
::s('directory_name');
427 if (Post
::s('sex') != ($user->isFemale() ?
'female' : 'male')) {
428 $to_update['sex'] = Post
::s('sex');
429 if ($user->hasProfile()) {
430 XDB
::execute('UPDATE profiles
433 Post
::s('sex'), $user->profile()->id());
436 if (!Post
::blank('pwhash')) {
437 $to_update['password'] = Post
::s('pwhash');
438 require_once 'googleapps.inc.php';
439 $account = new GoogleAppsAccount($user);
440 if ($account->active() && $account->sync_password
) {
441 $account->set_password(Post
::s('pwhash'));
444 if (!Post
::blank('weak_password')) {
445 $to_update['weak_password'] = Post
::s('weak_password');
447 if (Post
::i('token_access', 0) != ($user->token_access ?
1 : 0)) {
448 $to_update['token'] = Post
::i('token_access') ?
rand_url_id(16) : null
;
450 if (Post
::i('skin') != $user->skin
) {
451 $to_update['skin'] = Post
::i('skin');
452 if ($to_update['skin'] == 0) {
453 $to_update['skin'] = null
;
456 if (Post
::s('state') != $user->state
) {
457 $to_update['state'] = Post
::s('state');
459 if (Post
::i('is_admin', 0) != ($user->is_admin ?
1 : 0)) {
460 $to_update['is_admin'] = Post
::b('is_admin');
462 if (Post
::s('type') != $user->type
) {
463 $to_update['type'] = Post
::s('type');
465 if (Post
::i('watch', 0) != ($user->watch ?
1 : 0)) {
466 $to_update['flags'] = new PlFlagset();
467 $to_update['flags']->addFlag('watch', Post
::i('watch'));
469 if (Post
::t('comment') != $user->comment
) {
470 $to_update['comment'] = Post
::blank('comment') ? null
: Post
::t('comment');
473 if (!empty($to_update)) {
474 $res = XDB
::query('SELECT *
476 WHERE uid = {?}', $user->id());
477 $oldValues = $res->fetchAllAssoc();
478 $oldValues = $oldValues[0];
482 foreach ($to_update as $k => $value) {
483 $value = XDB
::format('{?}', $value);
484 $set[] = $k . ' = ' . $value;
485 $diff[$k] = array($oldValues[$k], trim($value, "'"));
486 unset($oldValues[$k]);
488 XDB
::execute('UPDATE accounts
489 SET ' . implode(', ', $set) . '
490 WHERE uid = ' . XDB
::format('{?}', $user->id()));
491 $page->trigSuccess('Données du compte mise à jour avec succès');
492 $user = User
::getWithUID($user->id());
494 /* Formats the $diff and send it to the site administrators. The rules are the folowing:
495 * -formats: password, token, weak_password
497 foreach (array('password', 'token', 'weak_password') as $key) {
498 if (isset($diff[$key])) {
499 $diff[$key] = array('old value', 'new value');
501 $oldValues[$key] = 'old value';
505 $mail = new PlMailer('admin/useredit.mail.tpl');
506 $mail->assign('admin', S
::user()->hruid
);
507 $mail->assign('hruid', $user->hruid
);
508 $mail->assign('diff', $diff);
509 $mail->assign('oldValues', $oldValues);
515 if (Post
::has('add_profile') || Post
::has('del_profile') || Post
::has('owner')) {
516 if (Post
::i('del_profile', 0) != 0) {
517 XDB
::execute('DELETE FROM account_profiles
518 WHERE uid = {?} AND pid = {?}',
519 $user->id(), Post
::i('del_profile'));
520 } else if (!Post
::blank('new_profile')) {
521 $profile = Profile
::get(Post
::t('new_profile'));
523 $page->trigError('Le profil ' . Post
::t('new_profile') . ' n\'existe pas');
525 XDB
::execute('INSERT IGNORE INTO account_profiles (uid, pid)
527 $user->id(), $profile->id());
530 XDB
::execute('UPDATE account_profiles
531 SET perms = IF(pid = {?}, CONCAT(perms, \',owner\'), REPLACE(perms, \'owner\', \'\'))
533 Post
::i('owner'), $user->id());
537 // Email forwards form {{{
538 require_once("emails.inc.php");
539 $redirect = ($registered ?
new Redirect($user) : null
);
540 if (Post
::has('add_fwd')) {
541 $email = Post
::t('email');
542 if (!isvalid_email_redirection($email)) {
543 $page->trigError("Email non valide: $email");
545 $redirect->add_email($email);
546 $page->trigSuccess("Ajout de $email effectué");
548 } else if (!Post
::blank('del_fwd')) {
549 $redirect->delete_email(Post
::t('del_fwd'));
550 } else if (!Post
::blank('activate_fwd')) {
551 $redirect->modify_one_email(Post
::t('activate_fwd', true
));
552 } else if (!Post
::blank('deactivate_fwd')) {
553 $redirect->modify_one_email(Post
::t('deactivate_fwd', false
));
554 } else if (Post
::has('disable_fwd')) {
555 $redirect->disable();
556 } else if (Post
::has('enable_fwd')) {
558 } else if (!Post
::blank('clean_fwd')) {
559 $redirect->clean_errors(Post
::t('clean_fwd'));
563 // Email alias form {{{
564 if (Post
::has('add_alias')) {
565 // Splits new alias in user and fqdn.
566 $alias = Env
::t('email');
567 if (strpos($alias, '@') !== false
) {
568 list($alias, $domain) = explode('@', $alias);
570 $domain = $globals->mail
->domain
;
573 // Checks for alias' user validity.
574 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
575 $page->trigError("'$alias' n'est pas un alias valide");
578 // Eventually adds the alias to the right domain.
579 if ($domain == $globals->mail
->alias_dom ||
$domain == $globals->mail
->alias_dom2
) {
580 $req = new AliasReq($user, $alias, 'Admin request', false
);
581 if ($req->commit()) {
582 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
584 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
586 } elseif ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
587 $res = XDB
::execute("INSERT INTO aliases (uid, alias, type)
588 VALUES ({?}, {?}, 'alias')",
589 $user->id(), $alias);
590 $page->trigSuccess("Nouvel alias '$alias' ajouté");
592 $page->trigError("Le domaine '$domain' n'est pas valide");
594 } else if (!Post
::blank('del_alias')) {
595 XDB
::execute("DELETE FROM aliases
596 WHERE uid = {?} AND alias = {?} AND
597 type NOT IN ('a_vie', 'homonyme')",
599 XDB
::execute("UPDATE emails
601 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
603 fix_bestalias($user);
604 $page->trigSuccess("L'alias '$val' a été supprimé");
605 } else if (!Post
::blank('best')) {
606 XDB
::execute("UPDATE aliases
607 SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))
608 WHERE uid = {?}", $user->id());
609 XDB
::execute("UPDATE aliases
610 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
611 WHERE uid = {?} AND alias = {?}", $user->id(), $val);
612 // As having a non-null bestalias value is critical in
613 // plat/al's code, we do an a posteriori check on the
614 // validity of the bestalias.
615 fix_bestalias($user);
620 if (Post
::has('del_openid')) {
621 XDB
::execute('DELETE FROM account_auth_openid
622 WHERE id = {?}', Post
::i('del_openid'));
627 if (Post
::has('b_edit')) {
628 XDB
::execute("DELETE FROM forum_innd
629 WHERE uid = {?}", $user->id());
630 if (Env
::v('write_perm') != "" || Env
::v('read_perm') != "" || Env
::v('commentaire') != "" ) {
631 XDB
::execute("INSERT INTO forum_innd
632 SET ipmin = '0', ipmax = '4294967295',
633 write_perm = {?}, read_perm = {?},
634 comment = {?}, priority = '200', uid = {?}",
635 Env
::v('write_perm'), Env
::v('read_perm'), Env
::v('comment'), $user->id());
641 $page->addJsLink('jquery.ui.core.js');
642 $page->addJsLink('jquery.ui.tabs.js');
643 $page->addJsLink('password.js');
645 // Displays last login and last host information.
646 $res = XDB
::query("SELECT start, host
648 WHERE uid = {?} AND suid = 0
650 LIMIT 1", $user->id());
651 list($lastlogin,$host) = $res->fetchOneRow();
652 $page->assign('lastlogin', $lastlogin);
653 $page->assign('host', $host);
655 // Display active aliases.
656 $page->assign('virtuals', $user->emailAliases());
657 $page->assign('aliases', XDB
::iterator("SELECT alias, type='a_vie' AS for_life,
658 FIND_IN_SET('bestalias',flags) AS best, expire
660 WHERE uid = {?} AND type != 'homonyme'
661 ORDER BY type != 'a_vie'", $user->id()));
662 $page->assign('account_types', XDB
::iterator('SELECT * FROM account_types ORDER BY type'));
663 $page->assign('skins', XDB
::iterator('SELECT id, name FROM skins ORDER BY name'));
664 $page->assign('profiles', XDB
::iterator('SELECT p.pid, p.hrpid, FIND_IN_SET(\'owner\', ap.perms) AS owner
665 FROM account_profiles AS ap
666 INNER JOIN profiles AS p ON (ap.pid = p.pid)
667 WHERE ap.uid = {?}', $user->id()));
668 $page->assign('openid', XDB
::iterator('SELECT id, url
669 FROM account_auth_openid
670 WHERE uid = {?}', $user->id()));
672 // Displays email redirection and the general profile.
673 if ($registered && $redirect) {
674 $page->assign('emails', $redirect->emails
);
677 $page->assign('user', $user);
678 $page->assign('hasProfile', $user->hasProfile());
680 // Displays forum bans.
681 $res = XDB
::query("SELECT write_perm, read_perm, comment
683 WHERE uid = {?}", $user->id());
684 $bans = $res->fetchOneAssoc();
685 $page->assign('bans', $bans);
688 private static function getHrid($firstname, $lastname, $promo)
690 if ($firstname != null
&& $lastname != null
&& $promo != null
) {
691 return User
::makeHrid($firstname, $lastname, $promo);
696 private static function formatNewUser(&$page, $infosLine, $separator, $promo, $size)
698 $infos = explode($separator, $infosLine);
699 if (sizeof($infos) > $size ||
sizeof($infos) < 2) {
700 $page->trigError("La ligne $infosLine n'a pas été ajoutée.");
704 array_map('trim', $infos);
705 $hrid = self
::getHrid($infos[1], $infos[0], $promo);
706 $res1 = XDB
::query('SELECT COUNT(*)
708 WHERE hruid = {?}', $hrid);
709 $res2 = XDB
::query('SELECT COUNT(*)
711 WHERE hrpid = {?}', $hrid);
712 if (is_null($hrid) ||
$res1->fetchOneCell() > 0 ||
$res2->fetchOneCell() > 0) {
713 $page->trigError("La ligne $infosLine n'a pas été ajoutée.");
716 $infos['hrid'] = $hrid;
720 private static function formatSex(&$page, $sex, $line)
724 return PlUser
::GENDER_FEMALE
;
726 return PlUser
::GENDER_MALE
;
728 $page->trigError("La ligne $line n'a pas été ajoutée car le sexe $sex n'est pas pris en compte.");
733 private static function formatBirthDate($birthDate)
735 return date("Y-m-d", strtotime($birthDate));
738 function handler_add_accounts(&$page, $action = null
, $promo = null
)
740 $page->changeTpl('admin/add_accounts.tpl');
742 if (Env
::has('add_type') && Env
::has('people')) {
743 $lines = explode("\n", Env
::t('people'));
744 $separator = Env
::t('separator');
745 $promotion = Env
::i('promotion');
746 $nameTypes = DirEnum
::getOptions(DirEnum
::NAMETYPES
);
747 $nameTypes = array_flip($nameTypes);
749 if (Env
::t('add_type') == 'promo') {
751 $eduSchools = DirEnum
::getOptions(DirEnum
::EDUSCHOOLS
);
752 $eduSchools = array_flip($eduSchools);
753 $eduDegrees = DirEnum
::getOptions(DirEnum
::EDUDEGREES
);
754 $eduDegrees = array_flip($eduDegrees);
755 switch (Env
::t('edu_type')) {
757 $degreeid = $eduDegrees[Profile
::DEGREE_X
];
758 $entry_year = $promotion;
759 $grad_year = $promotion +
3;
760 $promo = 'X' . $promotion;
763 $degreeid = $eduDegrees[Profile
::DEGREE_M
];
764 $grad_year = $promotion;
765 $entry_year = $promotion - 2;
766 $promo = 'M' . $promotion;
769 $degreeid = $eduDegrees[Profile
::DEGREE_D
];
770 $grad_year = $promotion;
771 $entry_year = $promotion - 3;
772 $promo = 'D' . $promotion;
775 $page->killError("La formation n'est pas reconnue:" . Env
::t('edu_type') . '.');
778 foreach ($lines as $line) {
779 if ($infos = self
::formatNewUser($page, $line, $separator, $promotion, 6)) {
780 $sex = self
::formatSex($page, $infos[3], $line);
781 if (!is_null($sex)) {
782 $fullName = $infos[1] . ' ' . $infos[0];
783 $directoryName = $infos[0] . ' ' . $infos[1];
784 $birthDate = self
::formatBirthDate($infos[2]);
785 $xorgId = Profile
::getXorgId($infos[4]);
786 if (is_null($xorgId)) {
787 $page->trigError("La ligne $line n'a pas été ajoutée car le matricule École est mal renseigné.");
791 XDB
::execute('INSERT INTO profiles (hrpid, xorg_id, ax_id, birthdate_ref, sex)
792 VALUES ({?}, {?}, {?}, {?}, {?})',
793 $infos['hrid'], $xorgId, $infos[5], $birthDate, $sex);
794 $pid = XDB
::insertId();
795 XDB
::execute('INSERT INTO profile_name (pid, name, typeid)
796 VALUES ({?}, {?}, {?})',
797 $pid, $infos[0], $nameTypes['name_ini']);
798 XDB
::execute('INSERT INTO profile_name (pid, name, typeid)
799 VALUES ({?}, {?}, {?})',
800 $pid, $infos[1], $nameTypes['firstname_ini']);
801 XDB
::execute('INSERT INTO profile_display (pid, yourself, public_name, private_name,
802 directory_name, short_name, sort_name, promo)
803 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
804 $pid, $infos[1], $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo);
805 XDB
::execute('INSERT INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags)
806 VALUES ({?}, {?}, {?}, {?}, {?}, {?})',
807 $pid, $eduSchools[Profile
::EDU_X
], $degreeid, $entry_year, $grad_year, 'primary');
808 XDB
::execute('INSERT INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex)
809 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})',
810 $infos['hrid'], $type, 0, 'active', $fullName, $directoryName, $infos[1], $sex);
811 $uid = XDB
::insertId();
812 XDB
::execute('INSERT INTO account_profiles (uid, pid, perms)
813 VALUES ({?}, {?}, {?})',
814 $uid, $pid, 'owner');
818 } else if (Env
::t('add_type') == 'account') {
819 $type = Env
::t('type');
820 $newAccounts = array();
821 foreach ($lines as $line) {
822 if ($infos = self
::formatNewUser($page, $line, $separator, $type, 4)) {
823 $sex = self
::formatSex($page, $infos[3], $line);
824 if (!is_null($sex)) {
825 $fullName = $infos[1] . ' ' . $infos[0];
826 $directoryName = $infos[0] . ' ' . $infos[1];
827 XDB
::execute('INSERT INTO accounts (hruid, type, is_admin, state, email, full_name, directory_name, display_name, sex)
828 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
829 $infos['hrid'], $type, 0, 'active', $infos[2], $fullName, $directoryName, $infos[1], $sex);
830 $newAccounts[$infos['hrid']] = $infos[1] . ' ' . $infos[0];
834 if (!empty($newAccounts)) {
835 $page->assign('newAccounts', $newAccounts);
837 } else if (Env
::t('add_type') == 'ax_id') {
839 foreach ($lines as $line) {
840 if ($infos = self
::formatNewUser($page, $line, $separator, $promotion, 3)) {
841 XDB
::execute('UPDATE profiles
844 $infos[2], $infos['hrid']);
849 $errors = $page->nb_errs();
851 $page->trigSuccess("L'opération a été effectuée avec succès.");
853 $page->trigSuccess('L\'opération a été effectuée avec succès, sauf pour '
854 . (($errors == 1) ?
'l\'erreur signalée' : "les $errors erreurs signalées") . ' ci-dessus.');
856 } else if (Env
::has('add_type')) {
857 $res = XDB
::query('SELECT type
858 FROM account_types');
859 $page->assign('account_types', $res->fetchColumn());
860 $page->assign('add_type', Env
::s('add_type'));
864 function handler_homonyms(&$page, $op = 'list', $target = null
)
866 $page->changeTpl('admin/homonymes.tpl');
867 $page->setTitle('Administration - Homonymes');
868 $this->load("homonyms.inc.php");
871 $user = User
::getSilent($target);
872 if (!$user ||
!($loginbis = select_if_homonyme($user))) {
875 $page->assign('user', $user);
876 $page->assign('loginbis',$loginbis);
880 $page->assign('op', $op);
881 $page->assign('target', $target);
883 // on a un $target valide, on prepare les mails
885 // on examine l'op a effectuer
888 S
::assert_xsrf_token();
890 send_warning_homonyme($user, $loginbis);
891 switch_bestalias($user, $loginbis);
893 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.');
897 S
::assert_xsrf_token();
899 switch_bestalias($user, $loginbis);
900 XDB
::execute("UPDATE aliases
901 SET type = 'homonyme', expire=NOW()
902 WHERE alias = {?}", $loginbis);
903 XDB
::execute("REPLACE INTO homonyms (homonyme_id, uid)
904 VALUES ({?}, {?})", $target, $target);
905 send_robot_homonyme($user, $loginbis);
907 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.');
913 $res = XDB
::iterator(
914 "SELECT a.alias AS homonyme, s.alias AS forlife,
915 IF(h.homonyme_id = s.uid, a.expire, NULL) AS expire,
916 IF(h.homonyme_id = s.uid, a.type, NULL) AS type, ac.uid
918 LEFT JOIN homonyms AS h ON (h.homonyme_id = a.uid)
919 INNER JOIN aliases AS s ON (s.uid = h.uid AND s.type = 'a_vie')
920 INNER JOIN accounts AS ac ON (ac.uid = a.uid)
921 WHERE a.type = 'homonyme' OR a.expire != ''
922 ORDER BY a.alias, forlife");
924 while ($tab = $res->next()) {
925 $hnymes[$tab['homonyme']][] = $tab;
927 $page->assign_by_ref('hnymes', $hnymes);
931 function handler_deaths(&$page, $promo = 0, $validate = false
)
933 $page->changeTpl('admin/deces_promo.tpl');
934 $page->setTitle('Administration - Deces');
937 $promo = Env
::t('promo', 'X1923');
939 $page->assign('promo', $promo);
945 S
::assert_xsrf_token();
947 $res = XDB
::iterRow('SELECT p.pid, pd.directory_name, p.deathdate
949 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
950 WHERE pd.promo = {?}', $promo);
951 while (list($pid, $name, $death) = $res->next()) {
952 $val = Env
::v('death_' . $pid);
953 if ($val == $death) {
960 XDB
::execute('UPDATE profiles
961 SET deathdate = {?}, deathdate_rec = NOW()
962 WHERE pid = {?}', $val, $pid);
964 $page->trigSuccess('Édition du décès de ' . $name . ' (' . ($val ?
$val : 'ressuscité') . ').');
965 if ($val && ($death == '0000-00-00' ||
empty($death))) {
966 $profile = Profile
::get($pid);
968 $profile->owner()->clear(false
);
973 $res = XDB
::iterator('SELECT p.pid, pd.directory_name, p.deathdate
975 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
977 ORDER BY pd.sort_name', $promo);
978 $page->assign('profileList', $res);
981 function handler_dead_but_active(&$page)
983 $page->changeTpl('admin/dead_but_active.tpl');
984 $page->setTitle('Administration - Décédés');
986 $res = XDB
::iterator(
987 "SELECT a.hruid, pd.promo, p.ax_id, pd.directory_name, p.deathdate, DATE(MAX(s.start)) AS last
989 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
990 INNER JOIN profiles AS p ON (p.pid = ap.pid)
991 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
992 LEFT JOIN log_sessions AS s ON (s.uid = a.uid AND suid = 0)
993 WHERE a.state = 'active' AND p.deathdate IS NOT NULL
995 ORDER BY pd.promo, pd.sort_name");
996 $page->assign('dead', $res);
999 function handler_validate(&$page, $action = 'list', $id = null
)
1001 $page->changeTpl('admin/validation.tpl');
1002 $page->setTitle('Administration - Valider une demande');
1003 $page->addCssLink('nl.css');
1004 $page->addJsLink('ajax.js');
1005 require_once("validations.inc.php");
1008 if ($action == 'edit' and !is_null($id)) {
1009 $page->assign('preview_id', $id);
1012 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
1013 S
::assert_xsrf_token();
1015 $req = Validate
::get_typed_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
1017 $req->handle_formu();
1019 $page->trigWarning('La validation a déjà été effectuée.');
1023 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
1024 while (($a = $r->next()) && $a['Field'] != 'category');
1025 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
1028 $res = XDB
::query('SELECT hidden_requests
1029 FROM requests_hidden
1030 WHERE uid = {?}', S
::v('uid'));
1031 $hide_requests = $res->fetchOneCell();
1032 if (Post
::has('hide')) {
1034 foreach ($categories as $cat)
1035 if (!Post
::v($cat)) {
1039 $hide_requests = join(',', $hide);
1040 XDB
::query('REPLACE INTO requests_hidden (uid, hidden_requests)
1042 S
::v('uid'), $hide_requests);
1043 } elseif ($hide_requests) {
1044 foreach (explode(',', $hide_requests) as $hide_type)
1045 $hidden[$hide_type] = true
;
1047 $page->assign('hide_requests', $hidden);
1049 // Update the count of item to validate here... useful in development configuration
1050 // where several copies of the site use the same DB, but not the same "dynamic configuration"
1052 $globals->updateNbValid();
1053 $page->assign('vit', new ValidateIterator());
1056 function handler_validate_answers(&$page, $action = 'list', $id = null
)
1058 $page->setTitle('Administration - Réponses automatiques de validation');
1059 $page->assign('title', 'Gestion des réponses automatiques');
1060 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
1061 $table_editor->describe('category','catégorie',true
);
1062 $table_editor->describe('title','titre',true
);
1063 $table_editor->describe('answer','texte',false
);
1064 $table_editor->apply($page, $action, $id);
1067 function handler_skins(&$page, $action = 'list', $id = null
)
1069 $page->setTitle('Administration - Skins');
1070 $page->assign('title', 'Gestion des skins');
1071 $table_editor = new PLTableEditor('admin/skins','skins','id');
1072 $table_editor->describe('name','nom',true
);
1073 $table_editor->describe('skin_tpl','nom du template',true
);
1074 $table_editor->describe('auteur','auteur',false
);
1075 $table_editor->describe('comment','commentaire',true
);
1076 $table_editor->describe('date','date',false
);
1077 $table_editor->describe('ext','extension du screenshot',false
);
1078 $table_editor->apply($page, $action, $id);
1081 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
)
1083 $page->setTitle('Administration - Postfix : Blacklist');
1084 $page->assign('title', 'Blacklist de postfix');
1085 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
1086 $table_editor->describe('reject_text','Texte de rejet',true
);
1087 $table_editor->describe('email','email',true
);
1088 $table_editor->apply($page, $action, $id);
1091 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
)
1093 $page->setTitle('Administration - Postfix : Whitelist');
1094 $page->assign('title', 'Whitelist de postfix');
1095 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
1096 $table_editor->describe('email','email',true
);
1097 $table_editor->apply($page, $action, $id);
1100 function handler_mx_broken(&$page, $action = 'list', $id = null
)
1102 $page->setTitle('Administration - MX Défaillants');
1103 $page->assign('title', 'MX Défaillant');
1104 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true
);
1105 $table_editor->describe('host', 'Masque', true
);
1106 $table_editor->describe('state', 'Niveau', true
);
1107 $table_editor->describe('text', 'Description du problème', false
);
1108 $table_editor->apply($page, $action, $id);
1111 function handler_logger_actions(&$page, $action = 'list', $id = null
)
1113 $page->setTitle('Administration - Actions');
1114 $page->assign('title', 'Gestion des actions de logger');
1115 $table_editor = new PLTableEditor('admin/logger/actions','log_actions','id');
1116 $table_editor->describe('text','intitulé',true
);
1117 $table_editor->describe('description','description',true
);
1118 $table_editor->apply($page, $action, $id);
1121 function handler_downtime(&$page, $action = 'list', $id = null
)
1123 $page->setTitle('Administration - Coupures');
1124 $page->assign('title', 'Gestion des coupures');
1125 $table_editor = new PLTableEditor('admin/downtime','downtimes','id');
1126 $table_editor->describe('debut','date',true
);
1127 $table_editor->describe('duree','durée',false
);
1128 $table_editor->describe('resume','résumé',true
);
1129 $table_editor->describe('services','services affectés',true
);
1130 $table_editor->describe('description','description',false
);
1131 $table_editor->apply($page, $action, $id);
1134 function handler_account_types(&$page, $action = 'list', $id = null
)
1136 $page->setTitle('Administration - Types de comptes');
1137 $page->assign('title', 'Gestion des types de comptes');
1138 $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true
);
1139 $table_editor->describe('type', 'Catégorie', true
);
1140 $table_editor->describe('perms', 'Permissions associées', true
);
1141 $table_editor->apply($page, $action, $id);
1144 function handler_wiki(&$page, $action = 'list', $wikipage = null
, $wikipage2 = null
)
1146 if (S
::hasAuthToken()) {
1147 $page->setRssLink('Changement Récents',
1148 '/Site/AllRecentChanges?action=rss&user=' . S
::v('hruid') . '&hash=' . S
::user()->token
);
1151 // update wiki perms
1152 if ($action == 'update') {
1153 S
::assert_xsrf_token();
1155 $perms_read = Post
::v('read');
1156 $perms_edit = Post
::v('edit');
1157 if ($perms_read ||
$perms_edit) {
1158 foreach ($_POST as $wiki_page => $val) {
1160 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1161 if ($wp->setPerms($perms_read ?
$perms_read : $wp->readPerms(),
1162 $perms_edit ?
$perms_edit : $wp->writePerms())) {
1163 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1165 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1170 } else if ($action != 'list' && !empty($wikipage)) {
1171 $wp = new PlWikiPage($wikipage);
1172 S
::assert_xsrf_token();
1174 if ($action == 'delete') {
1175 if ($wp->delete()) {
1176 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1178 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1180 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1181 if ($changedLinks = $wp->rename($wikipage2)) {
1182 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1183 if (is_numeric($changedLinks)) {
1184 $s .= $changedLinks.' lien'.(($changedLinks>1)?
's ont été modifiés.':' a été modifié.');
1186 $page->trigSuccess($s);
1188 $page->trigError("Impossible de déplacer la page ".$wikipage);
1193 $perms = PlWikiPage
::permOptions();
1195 // list wiki pages and their perms
1196 $wiki_pages = PlWikiPage
::listPages();
1198 $wiki_tree = array();
1199 foreach ($wiki_pages as $file => $desc) {
1200 list($cat, $name) = explode('.', $file);
1201 if (!isset($wiki_tree[$cat])) {
1202 $wiki_tree[$cat] = array();
1204 $wiki_tree[$cat][$name] = $desc;
1207 $page->changeTpl('admin/wiki.tpl');
1208 $page->assign('wiki_pages', $wiki_tree);
1209 $page->assign('perms_opts', $perms);
1212 function handler_ipwatch(&$page, $action = 'list', $ip = null
)
1214 $page->changeTpl('admin/ipwatcher.tpl');
1216 $states = array('safe' => 'Ne pas surveiller',
1217 'unsafe' => 'Surveiller les inscriptions',
1218 'dangerous' => 'Surveiller tous les accès',
1219 'ban' => 'Bannir cette adresse');
1220 $page->assign('states', $states);
1222 switch (Post
::v('action')) {
1224 if (trim(Post
::v('ipN')) != '') {
1225 S
::assert_xsrf_token();
1226 Xdb
::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1227 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1228 ip_to_uint(trim(Post
::v('ipN'))), ip_to_uint(trim(Post
::v('maskN'))),
1229 Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
1234 S
::assert_xsrf_token();
1235 Xdb
::execute('UPDATE ip_watch
1236 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1237 WHERE ip = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'),
1238 ip_to_uint(Post
::v('maskN')), ip_to_uint(Post
::v('ipN')));
1242 if ($action == 'delete' && !is_null($ip)) {
1243 S
::assert_xsrf_token();
1244 Xdb
::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1247 if ($action != 'create' && $action != 'edit') {
1250 $page->assign('action', $action);
1252 if ($action == 'list') {
1253 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1254 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1255 IF(w.ip = s.ip, s.host, s.forward_host)),
1256 w.mask, w.detection, w.state, a.hruid
1258 LEFT JOIN log_sessions AS s ON (s.ip = w.ip)
1259 LEFT JOIN log_sessions AS s2 ON (s2.forward_ip = w.ip)
1260 LEFT JOIN accounts AS a ON (a.uid = s.uid)
1261 GROUP BY w.ip, a.hruid
1262 ORDER BY w.state, w.ip, a.hruid";
1263 $it = Xdb
::iterRow($sql);
1267 while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) {
1268 $ip = uint_to_ip($ip);
1269 $mask = uint_to_ip($mask);
1270 if (count($props) == 0 ||
$props['ip'] != $ip) {
1271 if (count($props) > 0) {
1274 $props = array('ip' => $ip,
1277 'detection' => $date,
1279 'users' => array($hruid));
1281 $props['users'][] = $hruid;
1284 if (count($props) > 0) {
1287 $page->assign('table', $table);
1288 } elseif ($action == 'edit') {
1289 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1290 a1.hruid AS edit, a2.hruid AS hruid, s.host
1292 LEFT JOIN accounts AS a1 ON (a1.uid = w.uid)
1293 LEFT JOIN log_sessions AS s ON (w.ip = s.ip)
1294 LEFT JOIN accounts AS a2 ON (a2.uid = s.uid)
1298 $it = Xdb
::iterRow($sql, ip_to_uint($ip));
1301 while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) {
1302 if (count($props) == 0) {
1303 $props = array('ip' => $ip,
1304 'mask' => uint_to_ip($mask),
1306 'detection' => $detection,
1309 'description' => $description,
1311 'users' => array($hruid));
1313 $props['users'][] = $hruid;
1316 $page->assign('ip', $props);
1320 function handler_icons(&$page)
1322 $page->changeTpl('admin/icons.tpl');
1323 $dh = opendir('../htdocs/images/icons');
1325 $page->trigError('Dossier des icones introuvables.');
1328 while (($file = readdir($dh)) !== false
) {
1329 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1330 array_push($icons, substr($file, 0, -4));
1334 $page->assign('icons', $icons);
1337 function handler_accounts(&$page)
1339 $page->changeTpl('admin/accounts.tpl');
1340 $page->assign('disabled', XDB
::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch,
1341 a.state = \'disabled\' AS disabled, a.comment
1343 WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags)
1344 ORDER BY a.hruid'));
1345 $page->assign('admins', XDB
::iterator('SELECT a.hruid
1348 ORDER BY a.hruid'));
1351 function handler_jobs(&$page, $id = -1)
1353 $page->changeTpl('admin/jobs.tpl');
1355 if (Env
::has('search')) {
1356 $res = XDB
::query("SELECT e.id, e.name, e.acronym
1357 FROM profile_job_enum AS e
1358 WHERE e.name LIKE CONCAT('% ', {?}, '%') OR e.acronym LIKE CONCAT('% ', {?}, '%')",
1359 Env
::t('job'), Env
::t('job'));
1361 if ($res->numRows() <= 20) {
1362 $page->assign('jobs', $res->fetchAllAssoc());
1364 $page->trigError("Il y a trop d'entreprises correspondant à ton choix. Affine-le !");
1367 $page->assign('askedJob', Env
::v('job'));
1371 if (Env
::has('edit')) {
1372 // TODO: use address class to update profile_job_enum once it is done.
1374 S
::assert_xsrf_token();
1375 $selectedJob = Env
::has('selectedJob');
1377 Phone
::deletePhones(0, Phone
::LINK_COMPANY
, $id);
1378 XDB
::execute("DELETE FROM profile_addresses
1379 WHERE jobid = {?} AND type = 'hq'",
1382 if (Env
::has('change')) {
1383 XDB
::execute('UPDATE profile_job
1386 Env
::i('newJobId'), $id);
1387 XDB
::execute('DELETE FROM profile_job_enum
1391 $page->trigSuccess("L'entreprise a bien été remplacée.");
1393 require_once 'geocoding.inc.php';
1395 $gmapsGeocoder = new GMapsGeocoder();
1396 $address = array('text' => Env
::t('address'));
1397 $address = $gmapsGeocoder->getGeocodedAddress($address);
1398 Geocoder
::getAreaId($address, 'administrativeArea');
1399 Geocoder
::getAreaId($address, 'subAdministrativeArea');
1400 Geocoder
::getAreaId($address, 'locality');
1402 XDB
::execute('UPDATE profile_job_enum
1403 SET name = {?}, acronym = {?}, url = {?}, email = {?},
1404 NAF_code = {?}, AX_code = {?}, holdingid = {?}
1406 Env
::t('name'), Env
::t('acronym'), Env
::t('url'), Env
::t('email'),
1407 Env
::t('NAF_code'), Env
::i('AX_code'), Env
::i('holdingId'), $id);
1409 $phone = new Phone(array('display' => Env
::v('tel'), 'link_id' => $id, 'id' => 0, 'type' => 'fixed',
1410 'link_type' => Phone
::LINK_COMPANY
, 'pub' => 'public'));
1411 $fax = new Phone(array('display' => Env
::v('fax'), 'link_id' => $id, 'id' => 1, 'type' => 'fax',
1412 'link_type' => Phone
::LINK_COMPANY
, 'pub' => 'public'));
1416 XDB
::execute("INSERT INTO profile_addresses (jobid, type, id, accuracy,
1417 text, postalText, postalCode, localityId,
1418 subAdministrativeAreaId, administrativeAreaId,
1419 countryId, latitude, longitude, updateTime,
1420 north, south, east, west)
1421 VALUES ({?}, 'hq', 0, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
1422 {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?})",
1423 $id, $address['accuracy'], $address['text'], $address['postalText'],
1424 $address['postalCode'], $address['localityId'],
1425 $address['subAdministrativeAreaId'], $address['administrativeAreaId'],
1426 $address['countryId'], $address['latitude'], $address['longitude'],
1427 $address['updateTime'], $address['north'], $address['south'],
1428 $address['east'], $address['west']);
1430 $page->trigSuccess("L'entreprise a bien été mise à jour.");
1434 if (!Env
::has('change') && $id != -1) {
1435 $res = XDB
::query("SELECT e.id, e.name, e.acronym, e.url, e.email, e.NAF_code, e.AX_code,
1436 h.id AS holdingId, h.name AS holdingName, h.acronym AS holdingAcronym,
1437 t.display_tel AS tel, f.display_tel AS fax, a.text AS address
1438 FROM profile_job_enum AS e
1439 LEFT JOIN profile_job_enum AS h ON (e.holdingid = h.id)
1440 LEFT JOIN profile_phones AS t ON (t.pid = e.id AND t.link_type = 'hq' AND t.tel_id = 0)
1441 LEFT JOIN profile_phones AS f ON (f.pid = e.id AND f.link_type = 'hq' AND f.tel_id = 1)
1442 LEFT JOIN profile_addresses AS a ON (a.jobid = e.id AND a.type = 'hq')
1446 if ($res->numRows() == 0) {
1447 $page->trigError('Auncune entreprise ne correspond à cet identifiant.');
1449 $page->assign('selectedJob', $res->fetchOneAssoc());
1455 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: