c2a590103501aedc04536a9b5699b890fc1363b2
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_COOKIE
, '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/watch' => $this->make_hook('account_watch', AUTH_MDP
, 'admin'),
51 'admin/account/types' => $this->make_hook('account_types', AUTH_MDP
, 'admin'),
52 'admin/jobs' => $this->make_hook('jobs', AUTH_MDP
, 'admin'),
56 function handler_phpinfo(&$page)
62 function handler_get_rights(&$page)
65 $page->kill('Déjà en SUID');
67 S
::assert_xsrf_token();
68 $level = Post
::s('account_type');
69 if ($level != 'admin') {
70 $user = User
::getSilentWithUID(S
::user()->id());
71 $user->is_admin
= false
;
72 $types = DirEnum
::getOptions(DirEnum
::ACCOUNTTYPES
);
73 if (!empty($types[$level])) {
74 $user->setPerms($types[$level]);
76 S
::set('suid_startpage', $_SERVER['HTTP_REFERER']);
77 Platal
::session()->startSUID($user);
79 if (!empty($_SERVER['HTTP_REFERER'])) {
80 http_redirect($_SERVER['HTTP_REFERER']);
86 function handler_default(&$page)
88 $page->changeTpl('admin/index.tpl');
89 $page->setTitle('Administration');
92 function handler_postfix_delayed(&$page)
94 $page->changeTpl('admin/postfix_delayed.tpl');
95 $page->setTitle('Administration - Postfix : Retardés');
97 if (Env
::has('del')) {
99 XDB
::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
100 $page->trigSuccess($crc . " verra tous ses emails supprimés !");
101 } elseif (Env
::has('ok')) {
102 $crc = Env
::v('crc');
103 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
104 $page->trigSuccess($crc . " a le droit de passer !");
107 $sql = XDB
::iterator(
108 "SELECT crc, nb, update_time, create_time,
109 FIND_IN_SET('del', p.release) AS del,
110 FIND_IN_SET('ok', p.release) AS ok
111 FROM postfix_mailseen AS p
113 ORDER BY p.release != ''");
115 $page->assign_by_ref('mails', $sql);
118 function handler_postfix_regexpsbounces(&$page, $new = null
) {
119 $page->changeTpl('admin/emails_bounces_re.tpl');
120 $page->setTitle('Administration - Postfix : Regexps Bounces');
121 $page->assign('new', $new);
123 if (Post
::has('submit')) {
124 foreach (Env
::v('lvl') as $id=>$val) {
126 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
127 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
132 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
137 /** Retrieves the available days for a given year and month.
138 * Obtain a list of days of the given month in the given year
139 * that are within the range of dates that we have log entries for.
141 * @param integer year
142 * @param integer month
143 * @return array days in that month we have log entries covering.
146 function _getDays($year, $month)
148 // give a 'no filter' option
152 if ($year && $month) {
153 $day_max = Array(-1, 31, checkdate(2, 29, $year) ?
29 : 28 , 31,
154 30, 31, 30, 31, 31, 30, 31, 30, 31);
155 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
156 MONTH(MAX(start)), MONTH(MIN(start)),
157 DAYOFMONTH(MAX(start)),
158 DAYOFMONTH(MIN(start))
160 list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow();
162 if (($year < $ymin) ||
($year == $ymin && $month < $mmin)) {
166 if (($year > $ymax) ||
($year == $ymax && $month > $mmax)) {
170 $min = ($year==$ymin && $month==$mmin) ?
intval($dmin) : 1;
171 $max = ($year==$ymax && $month==$mmax) ?
intval($dmax) : $day_max[$month];
173 for($i = $min; $i<=$max; $i++
) {
181 /** Retrieves the available months for a given year.
182 * Obtains a list of month numbers that are within the timeframe that
183 * we have log entries for.
185 * @param integer year
186 * @return array List of month numbers we have log info for.
189 function _getMonths($year)
191 // give a 'no filter' option
196 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
197 MONTH(MAX(start)), MONTH(MIN(start))
199 list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow();
201 if (($year < $ymin) ||
($year > $ymax)) {
205 $min = $year == $ymin ?
intval($mmin) : 1;
206 $max = $year == $ymax ?
intval($mmax) : 12;
208 for($i = $min; $i<=$max; $i++
) {
216 /** Retrieves the available years.
217 * Obtains a list of years that we have log entries covering.
219 * @return array years we have log entries for.
224 // give a 'no filter' option
228 // retrieve available years
229 $res = XDB
::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM log_sessions");
230 list($max, $min) = $res->fetchOneRow();
232 for($i = intval($min); $i<=$max; $i++
) {
239 /** Make a where clause to get a user's sessions.
240 * Prepare the where clause request that will retrieve the sessions.
242 * @param $year INTEGER Only get log entries made during the given year.
243 * @param $month INTEGER Only get log entries made during the given month.
244 * @param $day INTEGER Only get log entries made during the given day.
245 * @param $uid INTEGER Only get log entries referring to the given user ID.
247 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
250 function _makeWhere($year, $month, $day, $uid)
252 // start constructing the "where" clause
256 array_push($where, "s.uid='$uid'");
258 // we were given at least a year
261 $dmin = mktime(0, 0, 0, $month, $day, $year);
262 $dmax = mktime(0, 0, 0, $month, $day+
1, $year);
264 $dmin = mktime(0, 0, 0, $month, 1, $year);
265 $dmax = mktime(0, 0, 0, $month+
1, 1, $year);
267 $dmin = mktime(0, 0, 0, 1, 1, $year);
268 $dmax = mktime(0, 0, 0, 1, 1, $year+
1);
270 $where[] = "start >= " . date("Ymd000000", $dmin);
271 $where[] = "start < " . date("Ymd000000", $dmax);
274 if (!empty($where)) {
275 return ' WHERE ' . implode($where, " AND ");
279 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
284 function handler_logger(&$page, $action = null
, $arg = null
) {
285 if ($action == 'session') {
287 // we are viewing a session
288 $res = XDB
::query("SELECT ls.*, a.alias AS username, sa.alias AS suer
289 FROM log_sessions AS ls
290 LEFT JOIN aliases AS a ON (a.uid = ls.uid AND a.type='a_vie')
291 LEFT JOIN aliases AS sa ON (sa.uid = ls.suid AND sa.type='a_vie')
292 WHERE ls.id = {?}", $arg);
294 $page->assign('session', $a = $res->fetchOneAssoc());
296 $res = XDB
::iterator('SELECT a.text, e.data, e.stamp
298 LEFT JOIN log_actions AS a ON e.action=a.id
299 WHERE e.session={?}', $arg);
300 while ($myarr = $res->next()) {
301 $page->append('events', $myarr);
305 $loguser = $action == 'user' ?
$arg : Env
::v('loguser');
307 $res = XDB
::query('SELECT uid FROM aliases WHERE alias={?}',
309 $loguid = $res->fetchOneCell();
312 $year = Env
::i('year');
313 $month = Env
::i('month');
314 $day = Env
::i('day');
316 $year = Env
::i('year', intval(date('Y')));
317 $month = Env
::i('month', intval(date('m')));
318 $day = Env
::i('day', intval(date('d')));
326 // smarty assignments
327 // retrieve available years
328 $page->assign('years', $this->_getYears());
329 $page->assign('year', $year);
331 // retrieve available months for the current year
332 $page->assign('months', $this->_getMonths($year));
333 $page->assign('month', $month);
335 // retrieve available days for the current year and month
336 $page->assign('days', $this->_getDays($year, $month));
337 $page->assign('day', $day);
339 $page->assign('loguser', $loguser);
340 // smarty assignments
342 if ($loguid ||
$year) {
344 // get the requested sessions
345 $where = $this->_makeWhere($year, $month, $day, $loguid);
346 $select = "SELECT s.id, s.start, s.uid,
348 FROM log_sessions AS s
349 LEFT JOIN aliases AS a ON (a.uid = s.uid AND a.type='a_vie')
351 ORDER BY start DESC";
352 $res = XDB
::iterator($select);
355 while ($mysess = $res->next()) {
356 $mysess['events'] = array();
357 $sessions[$mysess['id']] = $mysess;
359 array_reverse($sessions);
362 $sql = "SELECT s.id, a.text
363 FROM log_sessions AS s
364 LEFT JOIN log_events AS e ON(e.session=s.id)
365 INNER JOIN log_actions AS a ON(a.id=e.action)
368 $res = XDB
::iterator($sql);
369 while ($event = $res->next()) {
370 array_push($sessions[$event['id']]['events'], $event['text']);
372 $page->assign_by_ref('sessions', $sessions);
374 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
378 $page->changeTpl('admin/logger-view.tpl');
380 $page->setTitle('Administration - Logs des sessions');
383 function handler_user(&$page, $login = false
)
386 $page->changeTpl('admin/user.tpl');
387 $page->setTitle('Administration - Compte');
390 $page->kill("Déjà en SUID !!!");
393 // Loads the user identity using the environment.
395 $user = User
::get($login);
398 pl_redirect('admin/accounts');
401 $listClient = new MMList(S
::user());
402 $login = $user->login();
403 $registered = ($user->state
!= 'pending');
406 if (!empty($_POST)) {
407 S
::assert_xsrf_token();
408 if (Post
::has('uid') && Post
::i('uid') != $user->id()) {
409 $page->kill('Une erreur s\'est produite');
413 // Handles specific requests (AX sync, su, ...).
414 if(Post
::has('log_account')) {
415 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
418 if(Post
::has('su_account') && $registered) {
419 if (!Platal
::session()->startSUID($user)) {
420 $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login());
426 // Handles account deletion.
427 if (Post
::has('account_deletion_confirmation')) {
429 $name = $user->fullName();
430 $profile = $user->profile();
431 if ($profile && Post
::b('clear_profile')) {
432 $user->profile()->clear();
435 $page->trigSuccess("L'utilisateur $name ($uid) a bien été désinscrit.");
436 if (Post
::b('erase_account')) {
437 XDB
::execute('DELETE FROM accounts
440 $page->trigSuccess("L'utilisateur $name ($uid) a été supprimé de la base de données");
445 $to_update = array();
446 if (Post
::has('disable_weak_access')) {
447 $to_update['weak_password'] = null
;
448 } else if (Post
::has('update_account')) {
449 if (!$user->hasProfile()) {
450 if (Post
::s('full_name') != $user->fullName()) {
451 $to_update['full_name'] = Post
::s('full_name');
453 if (Post
::s('display_name') != $user->displayName()) {
454 $to_update['display_name'] = Post
::s('display_name');
456 if (Post
::s('directory_name') != $user->directoryName()) {
457 $to_update['directory_name'] = Post
::s('directory_name');
460 if (Post
::s('sex') != ($user->isFemale() ?
'female' : 'male')) {
461 $to_update['sex'] = Post
::s('sex');
462 if ($user->hasProfile()) {
463 XDB
::execute('UPDATE profiles
466 Post
::s('sex'), $user->profile()->id());
469 if (!Post
::blank('pwhash')) {
470 $to_update['password'] = Post
::s('pwhash');
471 require_once 'googleapps.inc.php';
472 $account = new GoogleAppsAccount($user);
473 if ($account->active() && $account->sync_password
) {
474 $account->set_password(Post
::s('pwhash'));
477 if (!Post
::blank('weak_password')) {
478 $to_update['weak_password'] = Post
::s('weak_password');
480 if (Post
::i('token_access', 0) != ($user->token_access ?
1 : 0)) {
481 $to_update['token'] = Post
::i('token_access') ?
rand_url_id(16) : null
;
483 if (Post
::i('skin') != $user->skin
) {
484 $to_update['skin'] = Post
::i('skin');
485 if ($to_update['skin'] == 0) {
486 $to_update['skin'] = null
;
489 if (Post
::s('state') != $user->state
) {
490 $to_update['state'] = Post
::s('state');
492 if (Post
::i('is_admin', 0) != ($user->is_admin ?
1 : 0)) {
493 $to_update['is_admin'] = Post
::b('is_admin');
495 if (Post
::s('type') != $user->type
) {
496 $to_update['type'] = Post
::s('type');
498 if (Post
::i('watch', 0) != ($user->watch ?
1 : 0)) {
499 $to_update['flags'] = new PlFlagset();
500 $to_update['flags']->addFlag('watch', Post
::i('watch'));
502 if (Post
::t('comment') != $user->comment
) {
503 $to_update['comment'] = Post
::blank('comment') ? null
: Post
::t('comment');
505 if (!$user->checkPerms(User
::PERM_MAIL
) && Post
::t('email') != $user->forlifeEmail()) {
506 $to_update['email'] = Post
::t('email');
507 $listClient->change_user_email($user->forlifeEmail(), Post
::t('email'));
510 if (!empty($to_update)) {
511 $res = XDB
::query('SELECT *
513 WHERE uid = {?}', $user->id());
514 $oldValues = $res->fetchAllAssoc();
515 $oldValues = $oldValues[0];
519 foreach ($to_update as $k => $value) {
520 $value = XDB
::format('{?}', $value);
521 $set[] = $k . ' = ' . $value;
522 $diff[$k] = array($oldValues[$k], trim($value, "'"));
523 unset($oldValues[$k]);
525 XDB
::rawExecute('UPDATE accounts
526 SET ' . implode(', ', $set) . '
527 WHERE uid = ' . XDB
::format('{?}', $user->id()));
528 $page->trigSuccess('Données du compte mise à jour avec succès');
529 $user = User
::getWithUID($user->id());
531 /* Formats the $diff and send it to the site administrators. The rules are the folowing:
532 * -formats: password, token, weak_password
534 foreach (array('password', 'token', 'weak_password') as $key) {
535 if (isset($diff[$key])) {
536 $diff[$key] = array('old value', 'new value');
538 $oldValues[$key] = 'old value';
542 $mail = new PlMailer('admin/useredit.mail.tpl');
543 $mail->assign('admin', S
::user()->hruid
);
544 $mail->assign('hruid', $user->hruid
);
545 $mail->assign('diff', $diff);
546 $mail->assign('oldValues', $oldValues);
552 if (Post
::has('add_profile') || Post
::has('del_profile') || Post
::has('owner')) {
553 if (Post
::i('del_profile', 0) != 0) {
554 XDB
::execute('DELETE FROM account_profiles
555 WHERE uid = {?} AND pid = {?}',
556 $user->id(), Post
::i('del_profile'));
557 } else if (!Post
::blank('new_profile')) {
558 $profile = Profile
::get(Post
::t('new_profile'));
560 $page->trigError('Le profil ' . Post
::t('new_profile') . ' n\'existe pas');
562 XDB
::execute('INSERT IGNORE INTO account_profiles (uid, pid)
564 $user->id(), $profile->id());
567 XDB
::execute('UPDATE account_profiles
568 SET perms = IF(pid = {?}, CONCAT(perms, \',owner\'), REPLACE(perms, \'owner\', \'\'))
570 Post
::i('owner'), $user->id());
574 // Email forwards form {{{
575 require_once("emails.inc.php");
576 $redirect = ($registered ?
new Redirect($user) : null
);
577 if (Post
::has('add_fwd')) {
578 $email = Post
::t('email');
579 if (!isvalid_email_redirection($email)) {
580 $page->trigError("Email non valide: $email");
582 $redirect->add_email($email);
583 $page->trigSuccess("Ajout de $email effectué");
585 } else if (!Post
::blank('del_fwd')) {
586 $redirect->delete_email(Post
::t('del_fwd'));
587 } else if (!Post
::blank('activate_fwd')) {
588 $redirect->modify_one_email(Post
::t('activate_fwd', true
));
589 } else if (!Post
::blank('deactivate_fwd')) {
590 $redirect->modify_one_email(Post
::t('deactivate_fwd', false
));
591 } else if (Post
::has('disable_fwd')) {
592 $redirect->disable();
593 } else if (Post
::has('enable_fwd')) {
595 } else if (!Post
::blank('clean_fwd')) {
596 $redirect->clean_errors(Post
::t('clean_fwd'));
600 // Email alias form {{{
601 if (Post
::has('add_alias')) {
602 // Splits new alias in user and fqdn.
603 $alias = Env
::t('email');
604 if (strpos($alias, '@') !== false
) {
605 list($alias, $domain) = explode('@', $alias);
607 $domain = $globals->mail
->domain
;
610 // Checks for alias' user validity.
611 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
612 $page->trigError("'$alias' n'est pas un alias valide");
615 // Eventually adds the alias to the right domain.
616 if ($domain == $globals->mail
->alias_dom ||
$domain == $globals->mail
->alias_dom2
) {
617 $req = new AliasReq($user, $alias, 'Admin request', false
);
618 if ($req->commit()) {
619 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
621 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
623 } elseif ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
624 $res = XDB
::execute("INSERT INTO aliases (uid, alias, type)
625 VALUES ({?}, {?}, 'alias')",
626 $user->id(), $alias);
627 $page->trigSuccess("Nouvel alias '$alias' ajouté");
629 $page->trigError("Le domaine '$domain' n'est pas valide");
631 } else if (!Post
::blank('del_alias')) {
632 XDB
::execute("DELETE FROM aliases
633 WHERE uid = {?} AND alias = {?} AND
634 type NOT IN ('a_vie', 'homonyme')",
636 XDB
::execute("UPDATE emails
638 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
640 fix_bestalias($user);
641 $page->trigSuccess("L'alias '$val' a été supprimé");
642 } else if (!Post
::blank('best')) {
643 XDB
::execute("UPDATE aliases
644 SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))
645 WHERE uid = {?}", $user->id());
646 XDB
::execute("UPDATE aliases
647 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
648 WHERE uid = {?} AND alias = {?}", $user->id(), $val);
649 // As having a non-null bestalias value is critical in
650 // plat/al's code, we do an a posteriori check on the
651 // validity of the bestalias.
652 fix_bestalias($user);
657 if (Post
::has('del_openid')) {
658 XDB
::execute('DELETE FROM account_auth_openid
659 WHERE id = {?}', Post
::i('del_openid'));
664 if (Post
::has('b_edit')) {
665 XDB
::execute("DELETE FROM forum_innd
666 WHERE uid = {?}", $user->id());
667 if (Env
::v('write_perm') != "" || Env
::v('read_perm') != "" || Env
::v('commentaire') != "" ) {
668 XDB
::execute("INSERT INTO forum_innd
669 SET ipmin = '0', ipmax = '4294967295',
670 write_perm = {?}, read_perm = {?},
671 comment = {?}, priority = '200', uid = {?}",
672 Env
::v('write_perm'), Env
::v('read_perm'), Env
::v('comment'), $user->id());
678 $page->addJsLink('jquery.ui.core.js');
679 $page->addJsLink('jquery.ui.tabs.js');
680 $page->addJsLink('password.js');
682 // Displays last login and last host information.
683 $res = XDB
::query("SELECT start, host
685 WHERE uid = {?} AND suid = 0
687 LIMIT 1", $user->id());
688 list($lastlogin,$host) = $res->fetchOneRow();
689 $page->assign('lastlogin', $lastlogin);
690 $page->assign('host', $host);
692 // Display mailing lists
693 $page->assign('mlists', $listClient->get_all_user_lists($user->forlifeEmail()));
695 // Display active aliases.
696 $page->assign('virtuals', $user->emailAliases());
697 $page->assign('aliases', XDB
::iterator("SELECT alias, type='a_vie' AS for_life,
698 FIND_IN_SET('bestalias',flags) AS best, expire
700 WHERE uid = {?} AND type != 'homonyme'
701 ORDER BY type != 'a_vie'", $user->id()));
702 $page->assign('account_types', XDB
::iterator('SELECT * FROM account_types ORDER BY type'));
703 $page->assign('skins', XDB
::iterator('SELECT id, name FROM skins ORDER BY name'));
704 $page->assign('profiles', XDB
::iterator('SELECT p.pid, p.hrpid, FIND_IN_SET(\'owner\', ap.perms) AS owner
705 FROM account_profiles AS ap
706 INNER JOIN profiles AS p ON (ap.pid = p.pid)
707 WHERE ap.uid = {?}', $user->id()));
708 $page->assign('openid', XDB
::iterator('SELECT id, url
709 FROM account_auth_openid
710 WHERE uid = {?}', $user->id()));
712 // Displays email redirection and the general profile.
713 if ($registered && $redirect) {
714 $page->assign('emails', $redirect->emails
);
717 $page->assign('user', $user);
718 $page->assign('hasProfile', $user->hasProfile());
720 // Displays forum bans.
721 $res = XDB
::query("SELECT write_perm, read_perm, comment
723 WHERE uid = {?}", $user->id());
724 $bans = $res->fetchOneAssoc();
725 $page->assign('bans', $bans);
728 private static function getHrid($firstname, $lastname, $promo)
730 if ($firstname != null
&& $lastname != null
&& $promo != null
) {
731 return User
::makeHrid($firstname, $lastname, $promo);
736 private static function formatNewUser(&$page, $infosLine, $separator, $promo, $size)
738 $infos = explode($separator, $infosLine);
739 if (sizeof($infos) > $size ||
sizeof($infos) < 2) {
740 $page->trigError("La ligne $infosLine n'a pas été ajoutée.");
744 array_map('trim', $infos);
745 $hrid = self
::getHrid($infos[1], $infos[0], $promo);
746 $res1 = XDB
::query('SELECT COUNT(*)
748 WHERE hruid = {?}', $hrid);
749 $res2 = XDB
::query('SELECT COUNT(*)
751 WHERE hrpid = {?}', $hrid);
752 if (is_null($hrid) ||
$res1->fetchOneCell() > 0 ||
$res2->fetchOneCell() > 0) {
753 $page->trigError("La ligne $infosLine n'a pas été ajoutée.");
756 $infos['hrid'] = $hrid;
760 private static function formatSex(&$page, $sex, $line)
764 return PlUser
::GENDER_FEMALE
;
766 return PlUser
::GENDER_MALE
;
768 $page->trigError("La ligne $line n'a pas été ajoutée car le sexe $sex n'est pas pris en compte.");
773 private static function formatBirthDate($birthDate)
775 return date("Y-m-d", strtotime($birthDate));
778 function handler_add_accounts(&$page, $action = null
, $promo = null
)
780 $page->changeTpl('admin/add_accounts.tpl');
782 if (Env
::has('add_type') && Env
::has('people')) {
783 $lines = explode("\n", Env
::t('people'));
784 $separator = Env
::t('separator');
785 $promotion = Env
::i('promotion');
786 $nameTypes = DirEnum
::getOptions(DirEnum
::NAMETYPES
);
787 $nameTypes = array_flip($nameTypes);
789 if (Env
::t('add_type') == 'promo') {
791 $eduSchools = DirEnum
::getOptions(DirEnum
::EDUSCHOOLS
);
792 $eduSchools = array_flip($eduSchools);
793 $eduDegrees = DirEnum
::getOptions(DirEnum
::EDUDEGREES
);
794 $eduDegrees = array_flip($eduDegrees);
795 switch (Env
::t('edu_type')) {
797 $degreeid = $eduDegrees[Profile
::DEGREE_X
];
798 $entry_year = $promotion;
799 $grad_year = $promotion +
3;
800 $promo = 'X' . $promotion;
803 $degreeid = $eduDegrees[Profile
::DEGREE_M
];
804 $grad_year = $promotion;
805 $entry_year = $promotion - 2;
806 $promo = 'M' . $promotion;
809 $degreeid = $eduDegrees[Profile
::DEGREE_D
];
810 $grad_year = $promotion;
811 $entry_year = $promotion - 3;
812 $promo = 'D' . $promotion;
815 $page->killError("La formation n'est pas reconnue:" . Env
::t('edu_type') . '.');
818 foreach ($lines as $line) {
819 if ($infos = self
::formatNewUser($page, $line, $separator, $promotion, 6)) {
820 $sex = self
::formatSex($page, $infos[3], $line);
821 if (!is_null($sex)) {
822 $fullName = $infos[1] . ' ' . $infos[0];
823 $directoryName = $infos[0] . ' ' . $infos[1];
824 $birthDate = self
::formatBirthDate($infos[2]);
825 $xorgId = Profile
::getXorgId($infos[4]);
826 if (is_null($xorgId)) {
827 $page->trigError("La ligne $line n'a pas été ajoutée car le matricule École est mal renseigné.");
831 XDB
::execute('INSERT INTO profiles (hrpid, xorg_id, ax_id, birthdate_ref, sex)
832 VALUES ({?}, {?}, {?}, {?}, {?})',
833 $infos['hrid'], $xorgId, $infos[5], $birthDate, $sex);
834 $pid = XDB
::insertId();
835 XDB
::execute('INSERT INTO profile_name (pid, name, typeid)
836 VALUES ({?}, {?}, {?})',
837 $pid, $infos[0], $nameTypes['name_ini']);
838 XDB
::execute('INSERT INTO profile_name (pid, name, typeid)
839 VALUES ({?}, {?}, {?})',
840 $pid, $infos[1], $nameTypes['firstname_ini']);
841 XDB
::execute('INSERT INTO profile_display (pid, yourself, public_name, private_name,
842 directory_name, short_name, sort_name, promo)
843 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
844 $pid, $infos[1], $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo);
845 XDB
::execute('INSERT INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags)
846 VALUES ({?}, {?}, {?}, {?}, {?}, {?})',
847 $pid, $eduSchools[Profile
::EDU_X
], $degreeid, $entry_year, $grad_year, 'primary');
848 XDB
::execute('INSERT INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex)
849 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})',
850 $infos['hrid'], $type, 0, 'active', $fullName, $directoryName, $infos[1], $sex);
851 $uid = XDB
::insertId();
852 XDB
::execute('INSERT INTO account_profiles (uid, pid, perms)
853 VALUES ({?}, {?}, {?})',
854 $uid, $pid, 'owner');
858 } else if (Env
::t('add_type') == 'account') {
859 $type = Env
::t('type');
860 $newAccounts = array();
861 foreach ($lines as $line) {
862 if ($infos = self
::formatNewUser($page, $line, $separator, $type, 4)) {
863 $sex = self
::formatSex($page, $infos[3], $line);
864 if (!is_null($sex)) {
865 $fullName = $infos[1] . ' ' . $infos[0];
866 $directoryName = $infos[0] . ' ' . $infos[1];
867 XDB
::execute('INSERT INTO accounts (hruid, type, is_admin, state, email, full_name, directory_name, display_name, sex)
868 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
869 $infos['hrid'], $type, 0, 'active', $infos[2], $fullName, $directoryName, $infos[1], $sex);
870 $newAccounts[$infos['hrid']] = $infos[1] . ' ' . $infos[0];
874 if (!empty($newAccounts)) {
875 $page->assign('newAccounts', $newAccounts);
877 } else if (Env
::t('add_type') == 'ax_id') {
879 foreach ($lines as $line) {
880 if ($infos = self
::formatNewUser($page, $line, $separator, $promotion, 3)) {
881 XDB
::execute('UPDATE profiles
884 $infos[2], $infos['hrid']);
889 $errors = $page->nb_errs();
891 $page->trigSuccess("L'opération a été effectuée avec succès.");
893 $page->trigSuccess('L\'opération a été effectuée avec succès, sauf pour '
894 . (($errors == 1) ?
'l\'erreur signalée' : "les $errors erreurs signalées") . ' ci-dessus.');
896 } else if (Env
::has('add_type')) {
897 $res = XDB
::query('SELECT type
898 FROM account_types');
899 $page->assign('account_types', $res->fetchColumn());
900 $page->assign('add_type', Env
::s('add_type'));
904 function handler_homonyms(&$page, $op = 'list', $target = null
)
906 $page->changeTpl('admin/homonymes.tpl');
907 $page->setTitle('Administration - Homonymes');
908 $this->load("homonyms.inc.php");
911 $user = User
::getSilent($target);
912 if (!$user ||
!($loginbis = select_if_homonyme($user))) {
915 $page->assign('user', $user);
916 $page->assign('loginbis',$loginbis);
920 $page->assign('op', $op);
921 $page->assign('target', $target);
923 // on a un $target valide, on prepare les mails
925 // on examine l'op a effectuer
928 S
::assert_xsrf_token();
930 send_warning_homonyme($user, $loginbis);
931 switch_bestalias($user, $loginbis);
933 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.');
937 S
::assert_xsrf_token();
939 switch_bestalias($user, $loginbis);
940 XDB
::execute("UPDATE aliases
941 SET type = 'homonyme', expire=NOW()
942 WHERE alias = {?}", $loginbis);
943 XDB
::execute("REPLACE INTO homonyms (homonyme_id, uid)
944 VALUES ({?}, {?})", $target, $target);
945 send_robot_homonyme($user, $loginbis);
947 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.');
953 $res = XDB
::iterator(
954 "SELECT a.alias AS homonyme, s.alias AS forlife,
955 IF(h.homonyme_id = s.uid, a.expire, NULL) AS expire,
956 IF(h.homonyme_id = s.uid, a.type, NULL) AS type, ac.uid
958 LEFT JOIN homonyms AS h ON (h.homonyme_id = a.uid)
959 INNER JOIN aliases AS s ON (s.uid = h.uid AND s.type = 'a_vie')
960 INNER JOIN accounts AS ac ON (ac.uid = a.uid)
961 WHERE a.type = 'homonyme' OR a.expire != ''
962 ORDER BY a.alias, forlife");
964 while ($tab = $res->next()) {
965 $hnymes[$tab['homonyme']][] = $tab;
967 $page->assign_by_ref('hnymes', $hnymes);
971 function handler_deaths(&$page, $promo = 0, $validate = false
)
973 $page->changeTpl('admin/deces_promo.tpl');
974 $page->setTitle('Administration - Deces');
977 $promo = Env
::t('promo', 'X1923');
979 $page->assign('promo', $promo);
985 S
::assert_xsrf_token();
987 $res = XDB
::iterRow('SELECT p.pid, pd.directory_name, p.deathdate
989 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
990 WHERE pd.promo = {?}', $promo);
991 while (list($pid, $name, $death) = $res->next()) {
992 $val = Env
::v('death_' . $pid);
993 if ($val == $death) {
1000 XDB
::execute('UPDATE profiles
1001 SET deathdate = {?}, deathdate_rec = NOW()
1002 WHERE pid = {?}', $val, $pid);
1004 $page->trigSuccess('Édition du décès de ' . $name . ' (' . ($val ?
$val : 'ressuscité') . ').');
1005 if ($val && ($death == '0000-00-00' ||
empty($death))) {
1006 $profile = Profile
::get($pid);
1008 $profile->owner()->clear(false
);
1013 $res = XDB
::iterator('SELECT p.pid, pd.directory_name, p.deathdate
1015 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
1016 WHERE pd.promo = {?}
1017 ORDER BY pd.sort_name', $promo);
1018 $page->assign('profileList', $res);
1021 function handler_dead_but_active(&$page)
1023 $page->changeTpl('admin/dead_but_active.tpl');
1024 $page->setTitle('Administration - Décédés');
1026 $res = XDB
::iterator(
1027 "SELECT a.hruid, pd.promo, p.ax_id, pd.directory_name, p.deathdate, DATE(MAX(s.start)) AS last
1029 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
1030 INNER JOIN profiles AS p ON (p.pid = ap.pid)
1031 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
1032 LEFT JOIN log_sessions AS s ON (s.uid = a.uid AND suid = 0)
1033 WHERE a.state = 'active' AND p.deathdate IS NOT NULL
1035 ORDER BY pd.promo, pd.sort_name");
1036 $page->assign('dead', $res);
1039 function handler_validate(&$page, $action = 'list', $id = null
)
1041 $page->changeTpl('admin/validation.tpl');
1042 $page->setTitle('Administration - Valider une demande');
1043 $page->addCssLink('nl.css');
1044 $page->addJsLink('ajax.js');
1046 if ($action == 'edit' && !is_null($id)) {
1047 $page->assign('preview_id', $id);
1049 $page->assign('preview_id', null
);
1052 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
1053 S
::assert_xsrf_token();
1055 $req = Validate
::get_typed_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
1057 $req->handle_formu();
1059 $page->trigWarning('La validation a déjà été effectuée.');
1063 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
1064 while (($a = $r->next()) && $a['Field'] != 'category');
1065 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
1068 $res = XDB
::query('SELECT hidden_requests
1069 FROM requests_hidden
1070 WHERE uid = {?}', S
::v('uid'));
1071 $hide_requests = $res->fetchOneCell();
1072 if (Post
::has('hide')) {
1074 foreach ($categories as $cat)
1075 if (!Post
::v($cat)) {
1079 $hide_requests = join(',', $hide);
1080 XDB
::query('REPLACE INTO requests_hidden (uid, hidden_requests)
1082 S
::v('uid'), $hide_requests);
1083 } elseif ($hide_requests) {
1084 foreach (explode(',', $hide_requests) as $hide_type)
1085 $hidden[$hide_type] = true
;
1087 $page->assign('hide_requests', $hidden);
1089 // Update the count of item to validate here... useful in development configuration
1090 // where several copies of the site use the same DB, but not the same "dynamic configuration"
1092 $globals->updateNbValid();
1093 $page->assign('vit', Validate
::iterate());
1096 function handler_validate_answers(&$page, $action = 'list', $id = null
)
1098 $page->setTitle('Administration - Réponses automatiques de validation');
1099 $page->assign('title', 'Gestion des réponses automatiques');
1100 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
1101 $table_editor->describe('category','catégorie',true
);
1102 $table_editor->describe('title','titre',true
);
1103 $table_editor->describe('answer','texte',false
);
1104 $table_editor->apply($page, $action, $id);
1107 function handler_skins(&$page, $action = 'list', $id = null
)
1109 $page->setTitle('Administration - Skins');
1110 $page->assign('title', 'Gestion des skins');
1111 $table_editor = new PLTableEditor('admin/skins','skins','id');
1112 $table_editor->describe('name','nom',true
);
1113 $table_editor->describe('skin_tpl','nom du template',true
);
1114 $table_editor->describe('auteur','auteur',false
);
1115 $table_editor->describe('comment','commentaire',true
);
1116 $table_editor->describe('date','date',false
);
1117 $table_editor->describe('ext','extension du screenshot',false
);
1118 $table_editor->apply($page, $action, $id);
1121 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
)
1123 $page->setTitle('Administration - Postfix : Blacklist');
1124 $page->assign('title', 'Blacklist de postfix');
1125 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
1126 $table_editor->describe('reject_text','Texte de rejet',true
);
1127 $table_editor->describe('email','email',true
);
1128 $table_editor->apply($page, $action, $id);
1131 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
)
1133 $page->setTitle('Administration - Postfix : Whitelist');
1134 $page->assign('title', 'Whitelist de postfix');
1135 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
1136 $table_editor->describe('email','email',true
);
1137 $table_editor->apply($page, $action, $id);
1140 function handler_mx_broken(&$page, $action = 'list', $id = null
)
1142 $page->setTitle('Administration - MX Défaillants');
1143 $page->assign('title', 'MX Défaillant');
1144 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true
);
1145 $table_editor->describe('host', 'Masque', true
);
1146 $table_editor->describe('state', 'Niveau', true
);
1147 $table_editor->describe('text', 'Description du problème', false
);
1148 $table_editor->apply($page, $action, $id);
1151 function handler_logger_actions(&$page, $action = 'list', $id = null
)
1153 $page->setTitle('Administration - Actions');
1154 $page->assign('title', 'Gestion des actions de logger');
1155 $table_editor = new PLTableEditor('admin/logger/actions','log_actions','id');
1156 $table_editor->describe('text','intitulé',true
);
1157 $table_editor->describe('description','description',true
);
1158 $table_editor->apply($page, $action, $id);
1161 function handler_downtime(&$page, $action = 'list', $id = null
)
1163 $page->setTitle('Administration - Coupures');
1164 $page->assign('title', 'Gestion des coupures');
1165 $table_editor = new PLTableEditor('admin/downtime','downtimes','id');
1166 $table_editor->describe('debut','date',true
);
1167 $table_editor->describe('duree','durée',false
);
1168 $table_editor->describe('resume','résumé',true
);
1169 $table_editor->describe('services','services affectés',true
);
1170 $table_editor->describe('description','description',false
);
1171 $table_editor->apply($page, $action, $id);
1174 function handler_accounts(PlPage
$page)
1176 $page->changeTpl('admin/accounts.tpl');
1177 $page->setTitle('Administration - Comptes');
1178 $page->addJsLink('password.js');
1180 if (Post
::has('create_account')) {
1181 S
::assert_xsrf_token();
1182 $firstname = Post
::t('firstname');
1183 $lastname = strtoupper(Post
::t('lastname'));
1184 $sex = Post
::b('sex') ? User
::GENDER_FEMALE
: User
::GENDER_MALE
;
1185 $email = Post
::t('email');
1186 $type = Post
::s('type');
1187 $login = PlUser
::makeHrid($firstname, $lastname, $type);
1188 if (!isvalid_email($email)) {
1189 $page->trigError("Invalid email address: $email");
1190 } else if (strlen(Post
::s('pwhash')) != 40) {
1191 $page->trigError("Invalid password hash");
1193 $full_name = $firstname . ' ' . $lastname;
1194 $directory_name = $lastname . ' ' . $firstname;
1195 XDB
::execute("INSERT INTO accounts (hruid, type, state, password,
1196 registration_date, email, full_name,
1197 display_name, sex, directory_name)
1198 VALUES ({?}, {?}, 'active', {?}, NOW(), {?}, {?}, {?}, {?}, {?})",
1199 $login, $type, Post
::s('pwhash'), $email, $full_name, $full_name, $sex,
1204 $uf = new UserFilter(new UFC_AccountType('ax', 'school', 'fx'));
1205 $page->assign('users', $uf->iterUsers());
1209 function handler_account_types(&$page, $action = 'list', $id = null
)
1211 $page->setTitle('Administration - Types de comptes');
1212 $page->assign('title', 'Gestion des types de comptes');
1213 $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true
);
1214 $table_editor->describe('type', 'Catégorie', true
);
1215 $table_editor->describe('perms', 'Permissions associées', true
);
1216 $table_editor->apply($page, $action, $id);
1219 function handler_wiki(&$page, $action = 'list', $wikipage = null
, $wikipage2 = null
)
1221 if (S
::hasAuthToken()) {
1222 $page->setRssLink('Changement Récents',
1223 '/Site/AllRecentChanges?action=rss&user=' . S
::v('hruid') . '&hash=' . S
::user()->token
);
1226 // update wiki perms
1227 if ($action == 'update') {
1228 S
::assert_xsrf_token();
1230 $perms_read = Post
::v('read');
1231 $perms_edit = Post
::v('edit');
1232 if ($perms_read ||
$perms_edit) {
1233 foreach ($_POST as $wiki_page => $val) {
1235 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1236 if ($wp->setPerms($perms_read ?
$perms_read : $wp->readPerms(),
1237 $perms_edit ?
$perms_edit : $wp->writePerms())) {
1238 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1240 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1245 } else if ($action != 'list' && !empty($wikipage)) {
1246 $wp = new PlWikiPage($wikipage);
1247 S
::assert_xsrf_token();
1249 if ($action == 'delete') {
1250 if ($wp->delete()) {
1251 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1253 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1255 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1256 if ($changedLinks = $wp->rename($wikipage2)) {
1257 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1258 if (is_numeric($changedLinks)) {
1259 $s .= $changedLinks.' lien'.(($changedLinks>1)?
's ont été modifiés.':' a été modifié.');
1261 $page->trigSuccess($s);
1263 $page->trigError("Impossible de déplacer la page ".$wikipage);
1268 $perms = PlWikiPage
::permOptions();
1270 // list wiki pages and their perms
1271 $wiki_pages = PlWikiPage
::listPages();
1273 $wiki_tree = array();
1274 foreach ($wiki_pages as $file => $desc) {
1275 list($cat, $name) = explode('.', $file);
1276 if (!isset($wiki_tree[$cat])) {
1277 $wiki_tree[$cat] = array();
1279 $wiki_tree[$cat][$name] = $desc;
1282 $page->changeTpl('admin/wiki.tpl');
1283 $page->assign('wiki_pages', $wiki_tree);
1284 $page->assign('perms_opts', $perms);
1287 function handler_ipwatch(&$page, $action = 'list', $ip = null
)
1289 $page->changeTpl('admin/ipwatcher.tpl');
1291 $states = array('safe' => 'Ne pas surveiller',
1292 'unsafe' => 'Surveiller les inscriptions',
1293 'dangerous' => 'Surveiller tous les accès',
1294 'ban' => 'Bannir cette adresse');
1295 $page->assign('states', $states);
1297 switch (Post
::v('action')) {
1299 if (trim(Post
::v('ipN')) != '') {
1300 S
::assert_xsrf_token();
1301 Xdb
::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1302 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1303 ip_to_uint(trim(Post
::v('ipN'))), ip_to_uint(trim(Post
::v('maskN'))),
1304 Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
1309 S
::assert_xsrf_token();
1310 Xdb
::execute('UPDATE ip_watch
1311 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1312 WHERE ip = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'),
1313 ip_to_uint(Post
::v('maskN')), ip_to_uint(Post
::v('ipN')));
1317 if ($action == 'delete' && !is_null($ip)) {
1318 S
::assert_xsrf_token();
1319 Xdb
::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1322 if ($action != 'create' && $action != 'edit') {
1325 $page->assign('action', $action);
1327 if ($action == 'list') {
1328 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1329 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1330 IF(w.ip = s.ip, s.host, s.forward_host)),
1331 w.mask, w.detection, w.state, a.hruid
1333 LEFT JOIN log_sessions AS s ON (s.ip = w.ip)
1334 LEFT JOIN log_sessions AS s2 ON (s2.forward_ip = w.ip)
1335 LEFT JOIN accounts AS a ON (a.uid = s.uid)
1336 GROUP BY w.ip, a.hruid
1337 ORDER BY w.state, w.ip, a.hruid";
1338 $it = Xdb
::iterRow($sql);
1342 while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) {
1343 $ip = uint_to_ip($ip);
1344 $mask = uint_to_ip($mask);
1345 if (count($props) == 0 ||
$props['ip'] != $ip) {
1346 if (count($props) > 0) {
1349 $props = array('ip' => $ip,
1352 'detection' => $date,
1354 'users' => array($hruid));
1356 $props['users'][] = $hruid;
1359 if (count($props) > 0) {
1362 $page->assign('table', $table);
1363 } elseif ($action == 'edit') {
1364 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1365 a1.hruid AS edit, a2.hruid AS hruid, s.host
1367 LEFT JOIN accounts AS a1 ON (a1.uid = w.uid)
1368 LEFT JOIN log_sessions AS s ON (w.ip = s.ip)
1369 LEFT JOIN accounts AS a2 ON (a2.uid = s.uid)
1373 $it = Xdb
::iterRow($sql, ip_to_uint($ip));
1376 while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) {
1377 if (count($props) == 0) {
1378 $props = array('ip' => $ip,
1379 'mask' => uint_to_ip($mask),
1381 'detection' => $detection,
1384 'description' => $description,
1386 'users' => array($hruid));
1388 $props['users'][] = $hruid;
1391 $page->assign('ip', $props);
1395 function handler_icons(&$page)
1397 $page->changeTpl('admin/icons.tpl');
1398 $dh = opendir('../htdocs/images/icons');
1400 $page->trigError('Dossier des icones introuvables.');
1403 while (($file = readdir($dh)) !== false
) {
1404 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1405 array_push($icons, substr($file, 0, -4));
1409 $page->assign('icons', $icons);
1412 function handler_account_watch(&$page)
1414 $page->changeTpl('admin/accounts.tpl');
1415 $page->assign('disabled', XDB
::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch,
1416 a.state = \'disabled\' AS disabled, a.comment
1418 WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags)
1419 ORDER BY a.hruid'));
1420 $page->assign('admins', XDB
::iterator('SELECT a.hruid
1423 ORDER BY a.hruid'));
1426 function handler_jobs(&$page, $id = -1)
1428 $page->changeTpl('admin/jobs.tpl');
1430 if (Env
::has('search')) {
1431 $res = XDB
::query("SELECT id, name, acronym
1432 FROM profile_job_enum
1433 WHERE name LIKE CONCAT('%', {?}, '%') OR acronym LIKE CONCAT('%', {?}, '%')",
1434 Env
::t('job'), Env
::t('job'));
1436 if ($res->numRows() <= 20) {
1437 $page->assign('jobs', $res->fetchAllAssoc());
1439 $page->trigError("Il y a trop d'entreprises correspondant à ton choix. Affine-le !");
1442 $page->assign('askedJob', Env
::v('job'));
1446 if (Env
::has('edit')) {
1447 S
::assert_xsrf_token();
1448 $selectedJob = Env
::has('selectedJob');
1450 Phone
::deletePhones(0, Phone
::LINK_COMPANY
, $id);
1451 Address
::delete(null
, Address
::LINK_COMPANY
, $id);
1452 if (Env
::has('change')) {
1453 XDB
::execute('UPDATE profile_job
1456 Env
::i('newJobId'), $id);
1457 XDB
::execute('DELETE FROM profile_job_enum
1461 $page->trigSuccess("L'entreprise a bien été remplacée.");
1463 XDB
::execute('UPDATE profile_job_enum
1464 SET name = {?}, acronym = {?}, url = {?}, email = {?},
1465 NAF_code = {?}, AX_code = {?}, holdingid = {?}
1467 Env
::t('name'), Env
::t('acronym'), Env
::t('url'), Env
::t('email'),
1468 Env
::t('NAF_code'), Env
::i('AX_code'), Env
::i('holdingId'), $id);
1470 $phone = new Phone(array('display' => Env
::v('tel'), 'link_id' => $id, 'id' => 0, 'type' => 'fixed',
1471 'link_type' => Phone
::LINK_COMPANY
, 'pub' => 'public'));
1472 $fax = new Phone(array('display' => Env
::v('fax'), 'link_id' => $id, 'id' => 1, 'type' => 'fax',
1473 'link_type' => Phone
::LINK_COMPANY
, 'pub' => 'public'));
1474 $address = new Address(array('jobid' => $jobid, 'type' => Address
::LINK_COMPANY
, 'text' => Env
::t('address')));
1479 $page->trigSuccess("L'entreprise a bien été mise à jour.");
1483 if (!Env
::has('change') && $id != -1) {
1484 $res = XDB
::query("SELECT e.id, e.name, e.acronym, e.url, e.email, e.NAF_code, e.AX_code,
1485 h.id AS holdingId, h.name AS holdingName, h.acronym AS holdingAcronym,
1486 t.display_tel AS tel, f.display_tel AS fax, a.text AS address
1487 FROM profile_job_enum AS e
1488 LEFT JOIN profile_job_enum AS h ON (e.holdingid = h.id)
1489 LEFT JOIN profile_phones AS t ON (t.pid = e.id AND t.link_type = 'hq' AND t.tel_id = 0)
1490 LEFT JOIN profile_phones AS f ON (f.pid = e.id AND f.link_type = 'hq' AND f.tel_id = 1)
1491 LEFT JOIN profile_addresses AS a ON (a.jobid = e.id AND a.type = 'hq')
1495 if ($res->numRows() == 0) {
1496 $page->trigError('Auncune entreprise ne correspond à cet identifiant.');
1498 $page->assign('selectedJob', $res->fetchOneAssoc());
1504 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: