Adds error, warning, valid cells for (tiny)bicol tables.
[platal.git] / modules / admin.php
CommitLineData
86f0a6af 1<?php
2/***************************************************************************
5e1513f6 3 * Copyright (C) 2003-2011 Polytechnique.org *
86f0a6af 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
22class AdminModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
eb5a266d 27 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP, 'admin'),
93e38398 28 'get_rights' => $this->make_hook('get_rights', AUTH_COOKIE, 'admin'),
b47cc6f0 29 'set_skin' => $this->make_hook('set_skin', AUTH_COOKIE, 'admin'),
eb5a266d 30 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'),
eb5a266d
SJ
31 'admin/dead-but-active' => $this->make_hook('dead_but_active', AUTH_MDP, 'admin'),
32 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'),
33 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'),
34 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'),
35 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'),
36 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'),
37 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'),
38 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'),
e7ae7df9 39 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'),
eb5a266d
SJ
40 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'),
41 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP, 'admin'),
42 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'),
eb5a266d 43 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'),
e02d9fbb 44 'admin/add_accounts' => $this->make_hook('add_accounts', AUTH_MDP, 'admin'),
e33b29e5 45 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin,edit_directory'),
eb5a266d
SJ
46 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'),
47 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'),
48 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'),
49 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'),
50 'admin/accounts' => $this->make_hook('accounts', AUTH_MDP, 'admin'),
8338711c 51 'admin/account/watch' => $this->make_hook('account_watch', AUTH_MDP, 'admin'),
d1e61677 52 'admin/account/types' => $this->make_hook('account_types', AUTH_MDP, 'admin'),
ef7de370 53 'admin/jobs' => $this->make_hook('jobs', AUTH_MDP, 'admin,edit_directory'),
4d5946ac 54 'admin/profile' => $this->make_hook('profile', AUTH_MDP, 'admin,edit_directory')
86f0a6af 55 );
56 }
57
5f9a40b4 58 function handler_phpinfo(&$page)
59 {
60 phpinfo();
61 exit;
62 }
63
20b087ff 64 function handler_get_rights(&$page)
866bd535
FB
65 {
66 if (S::suid()) {
67 $page->kill('Déjà en SUID');
68 }
20b087ff
FB
69 S::assert_xsrf_token();
70 $level = Post::s('account_type');
71 if ($level != 'admin') {
72 $user = User::getSilentWithUID(S::user()->id());
73 $user->is_admin = false;
74 $types = DirEnum::getOptions(DirEnum::ACCOUNTTYPES);
75 if (!empty($types[$level])) {
76 $user->setPerms($types[$level]);
77 }
78 S::set('suid_startpage', $_SERVER['HTTP_REFERER']);
79 Platal::session()->startSUID($user);
80 }
81 if (!empty($_SERVER['HTTP_REFERER'])) {
82 http_redirect($_SERVER['HTTP_REFERER']);
83 } else {
84 pl_redirect('/');
85 }
866bd535
FB
86 }
87
b47cc6f0
FB
88 function handler_set_skin(&$page)
89 {
90 S::assert_xsrf_token();
91 S::set('skin', Post::s('change_skin'));
92 if (!empty($_SERVER['HTTP_REFERER'])) {
93 http_redirect($_SERVER['HTTP_REFERER']);
94 } else {
95 pl_redirect('/');
96 }
97 }
98
86f0a6af 99 function handler_default(&$page)
100 {
101 $page->changeTpl('admin/index.tpl');
46f272fe 102 $page->setTitle('Administration');
86f0a6af 103 }
104
105 function handler_postfix_delayed(&$page)
106 {
107 $page->changeTpl('admin/postfix_delayed.tpl');
46f272fe 108 $page->setTitle('Administration - Postfix : Retardés');
86f0a6af 109
110 if (Env::has('del')) {
111 $crc = Env::v('crc');
112 XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
6bb2f79a 113 $page->trigSuccess($crc . " verra tous ses emails supprimés&nbsp;!");
86f0a6af 114 } elseif (Env::has('ok')) {
115 $crc = Env::v('crc');
116 XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
6bb2f79a 117 $page->trigSuccess($crc . " a le droit de passer&nbsp;!");
86f0a6af 118 }
119
120 $sql = XDB::iterator(
121 "SELECT crc, nb, update_time, create_time,
77fcaa3f
SJ
122 FIND_IN_SET('del', p.release) AS del,
123 FIND_IN_SET('ok', p.release) AS ok
124 FROM postfix_mailseen AS p
86f0a6af 125 WHERE nb >= 30
77fcaa3f 126 ORDER BY p.release != ''");
86f0a6af 127
128 $page->assign_by_ref('mails', $sql);
129 }
86f0a6af 130
441e9e98 131 // {{{ logger view
86f0a6af 132
441e9e98 133 /** Retrieves the available days for a given year and month.
134 * Obtain a list of days of the given month in the given year
135 * that are within the range of dates that we have log entries for.
136 *
137 * @param integer year
138 * @param integer month
139 * @return array days in that month we have log entries covering.
140 * @private
141 */
142 function _getDays($year, $month)
143 {
144 // give a 'no filter' option
9bef113f
PC
145 $days = array();
146 $days[0] = "----";
441e9e98 147
148 if ($year && $month) {
149 $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31,
150 30, 31, 30, 31, 31, 30, 31, 30, 31);
151 $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
152 MONTH(MAX(start)), MONTH(MIN(start)),
153 DAYOFMONTH(MAX(start)),
154 DAYOFMONTH(MIN(start))
6586a74f 155 FROM log_sessions");
441e9e98 156 list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow();
157
158 if (($year < $ymin) || ($year == $ymin && $month < $mmin)) {
159 return array();
160 }
161
162 if (($year > $ymax) || ($year == $ymax && $month > $mmax)) {
163 return array();
164 }
165
166 $min = ($year==$ymin && $month==$mmin) ? intval($dmin) : 1;
167 $max = ($year==$ymax && $month==$mmax) ? intval($dmax) : $day_max[$month];
168
169 for($i = $min; $i<=$max; $i++) {
170 $days[$i] = $i;
171 }
172 }
173 return $days;
174 }
175
176
177 /** Retrieves the available months for a given year.
178 * Obtains a list of month numbers that are within the timeframe that
179 * we have log entries for.
180 *
181 * @param integer year
182 * @return array List of month numbers we have log info for.
183 * @private
184 */
185 function _getMonths($year)
186 {
187 // give a 'no filter' option
9bef113f 188 $months = array();
441e9e98 189 $months[0] = "----";
190
191 if ($year) {
192 $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
193 MONTH(MAX(start)), MONTH(MIN(start))
6586a74f 194 FROM log_sessions");
441e9e98 195 list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow();
196
197 if (($year < $ymin) || ($year > $ymax)) {
198 return array();
199 }
200
201 $min = $year == $ymin ? intval($mmin) : 1;
202 $max = $year == $ymax ? intval($mmax) : 12;
203
204 for($i = $min; $i<=$max; $i++) {
205 $months[$i] = $i;
206 }
207 }
208 return $months;
209 }
210
211
212 /** Retrieves the available years.
213 * Obtains a list of years that we have log entries covering.
214 *
215 * @return array years we have log entries for.
216 * @private
217 */
218 function _getYears()
219 {
220 // give a 'no filter' option
9bef113f 221 $years = array();
441e9e98 222 $years[0] = "----";
223
224 // retrieve available years
6586a74f 225 $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM log_sessions");
441e9e98 226 list($max, $min) = $res->fetchOneRow();
227
228 for($i = intval($min); $i<=$max; $i++) {
229 $years[$i] = $i;
230 }
231 return $years;
232 }
233
234
235 /** Make a where clause to get a user's sessions.
236 * Prepare the where clause request that will retrieve the sessions.
237 *
238 * @param $year INTEGER Only get log entries made during the given year.
239 * @param $month INTEGER Only get log entries made during the given month.
240 * @param $day INTEGER Only get log entries made during the given day.
241 * @param $uid INTEGER Only get log entries referring to the given user ID.
242 *
243 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
244 * @private
245 */
246 function _makeWhere($year, $month, $day, $uid)
247 {
248 // start constructing the "where" clause
249 $where = array();
250
251 if ($uid)
9bef113f 252 array_push($where, "s.uid='$uid'");
441e9e98 253
254 // we were given at least a year
255 if ($year) {
256 if ($day) {
257 $dmin = mktime(0, 0, 0, $month, $day, $year);
258 $dmax = mktime(0, 0, 0, $month, $day+1, $year);
259 } elseif ($month) {
260 $dmin = mktime(0, 0, 0, $month, 1, $year);
261 $dmax = mktime(0, 0, 0, $month+1, 1, $year);
262 } else {
263 $dmin = mktime(0, 0, 0, 1, 1, $year);
264 $dmax = mktime(0, 0, 0, 1, 1, $year+1);
265 }
266 $where[] = "start >= " . date("Ymd000000", $dmin);
267 $where[] = "start < " . date("Ymd000000", $dmax);
268 }
269
270 if (!empty($where)) {
271 return ' WHERE ' . implode($where, " AND ");
272 } else {
273 return '';
274 }
275 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
276 }
277
278 // }}}
279
280 function handler_logger(&$page, $action = null, $arg = null) {
281 if ($action == 'session') {
282
283 // we are viewing a session
bdbda592 284 $res = XDB::query("SELECT ls.*, a.hruid AS username, sa.hruid AS suer
6586a74f 285 FROM log_sessions AS ls
bdbda592
FB
286 INNER JOIN accounts AS a ON (a.uid = ls.uid)
287 LEFT JOIN accounts AS sa ON (sa.uid = ls.suid)
441e9e98 288 WHERE ls.id = {?}", $arg);
289
290 $page->assign('session', $a = $res->fetchOneAssoc());
291
504ccd57 292 $res = XDB::iterator('SELECT a.text, e.data, e.stamp
6586a74f
FB
293 FROM log_events AS e
294 LEFT JOIN log_actions AS a ON e.action=a.id
441e9e98 295 WHERE e.session={?}', $arg);
296 while ($myarr = $res->next()) {
297 $page->append('events', $myarr);
298 }
299
c8ab90e7 300 } else {
441e9e98 301 $loguser = $action == 'user' ? $arg : Env::v('loguser');
c8ab90e7
RB
302
303 if ($loguser) {
304 $user = User::get($loguser);
305 $loguid = $user->id();
306 } else {
307 $loguid = null;
308 }
441e9e98 309
310 if ($loguid) {
311 $year = Env::i('year');
312 $month = Env::i('month');
313 $day = Env::i('day');
314 } else {
315 $year = Env::i('year', intval(date('Y')));
316 $month = Env::i('month', intval(date('m')));
317 $day = Env::i('day', intval(date('d')));
318 }
319
320 if (!$year)
321 $month = 0;
322 if (!$month)
323 $day = 0;
324
325 // smarty assignments
326 // retrieve available years
327 $page->assign('years', $this->_getYears());
328 $page->assign('year', $year);
329
330 // retrieve available months for the current year
331 $page->assign('months', $this->_getMonths($year));
332 $page->assign('month', $month);
333
334 // retrieve available days for the current year and month
335 $page->assign('days', $this->_getDays($year, $month));
336 $page->assign('day', $day);
337
338 $page->assign('loguser', $loguser);
339 // smarty assignments
340
341 if ($loguid || $year) {
342
343 // get the requested sessions
344 $where = $this->_makeWhere($year, $month, $day, $loguid);
504ccd57 345 $select = "SELECT s.id, s.start, s.uid,
bdbda592 346 a.hruid as username
6586a74f 347 FROM log_sessions AS s
bdbda592 348 INNER JOIN accounts AS a ON (a.uid = s.uid)
441e9e98 349 $where
350 ORDER BY start DESC";
351 $res = XDB::iterator($select);
352
353 $sessions = array();
354 while ($mysess = $res->next()) {
355 $mysess['events'] = array();
356 $sessions[$mysess['id']] = $mysess;
357 }
358 array_reverse($sessions);
359
360 // attach events
361 $sql = "SELECT s.id, a.text
6586a74f
FB
362 FROM log_sessions AS s
363 LEFT JOIN log_events AS e ON(e.session=s.id)
364 INNER JOIN log_actions AS a ON(a.id=e.action)
441e9e98 365 $where";
366
367 $res = XDB::iterator($sql);
368 while ($event = $res->next()) {
369 array_push($sessions[$event['id']]['events'], $event['text']);
370 }
371 $page->assign_by_ref('sessions', $sessions);
372 } else {
c8ab90e7 373 $page->assign('msg_nofilters', "Sélectionner une année et/ou un utilisateur");
441e9e98 374 }
86f0a6af 375 }
376
8b1f8e12 377 $page->changeTpl('admin/logger-view.tpl');
86f0a6af 378
46f272fe 379 $page->setTitle('Administration - Logs des sessions');
86f0a6af 380 }
381
f97f90f0 382 function handler_user(&$page, $login = false)
383 {
84270653 384 global $globals;
1412adb2 385 $page->changeTpl('admin/user.tpl');
f9743cf1 386 $page->setTitle('Administration - Compte');
86f0a6af 387
0c02607e 388 if (S::suid()) {
6bb2f79a 389 $page->kill("Déjà en SUID&nbsp;!!!");
86f0a6af 390 }
391
d5fbeef6 392 // Loads the user identity using the environment.
1ac65dd4
PC
393 if ($login) {
394 $user = User::get($login);
395 }
396 if (empty($user)) {
8338711c 397 pl_redirect('admin/accounts');
2ff7e020
VZ
398 }
399
a8a11a70 400 $listClient = new MMList(S::user());
4f903ea6
FB
401 $login = $user->login();
402 $registered = ($user->state != 'pending');
86f0a6af 403
4f903ea6
FB
404 // Form processing
405 if (!empty($_POST)) {
406 S::assert_xsrf_token();
407 if (Post::has('uid') && Post::i('uid') != $user->id()) {
408 $page->kill('Une erreur s\'est produite');
409 }
86f0a6af 410 }
411
d5fbeef6 412 // Handles specific requests (AX sync, su, ...).
9bef113f 413 if(Post::has('log_account')) {
d5fbeef6 414 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
86f0a6af 415 }
416
a19178e9 417 if(Post::has('su_account') && $registered) {
866bd535 418 if (!Platal::session()->startSUID($user)) {
83752d10 419 $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login());
f97f90f0 420 } else {
d5fbeef6 421 pl_redirect("");
eaf30d86 422 }
d5fbeef6 423 }
86f0a6af 424
40965e32
SJ
425 // Handles account deletion.
426 if (Post::has('account_deletion_confirmation')) {
427 $uid = $user->id();
428 $name = $user->fullName();
4cd83ff8 429 $profile = $user->profile();
879d38da 430 if ($profile && Post::b('clear_profile')) {
4cd83ff8
FB
431 $user->profile()->clear();
432 }
40965e32 433 $user->clear(true);
879d38da
FB
434 $page->trigSuccess("L'utilisateur $name ($uid) a bien été désinscrit.");
435 if (Post::b('erase_account')) {
436 XDB::execute('DELETE FROM accounts
437 WHERE uid = {?}',
438 $uid);
439 $page->trigSuccess("L'utilisateur $name ($uid) a été supprimé de la base de données");
440 }
40965e32
SJ
441 }
442
f9743cf1 443 // Account Form {{{
83752d10 444 $to_update = array();
4f903ea6 445 if (Post::has('disable_weak_access')) {
83752d10 446 $to_update['weak_password'] = null;
4f903ea6 447 } else if (Post::has('update_account')) {
aef87266
SJ
448 if (!$user->hasProfile()) {
449 if (Post::s('full_name') != $user->fullName()) {
450 $to_update['full_name'] = Post::s('full_name');
451 }
452 if (Post::s('display_name') != $user->displayName()) {
453 $to_update['display_name'] = Post::s('display_name');
454 }
455 if (Post::s('directory_name') != $user->directoryName()) {
456 $to_update['directory_name'] = Post::s('directory_name');
457 }
d081acb2 458 }
4f903ea6
FB
459 if (Post::s('sex') != ($user->isFemale() ? 'female' : 'male')) {
460 $to_update['sex'] = Post::s('sex');
aef87266
SJ
461 if ($user->hasProfile()) {
462 XDB::execute('UPDATE profiles
463 SET sex = {?}
464 WHERE pid = {?}',
465 Post::s('sex'), $user->profile()->id());
466 }
83752d10 467 }
2477a631
SJ
468 if (!Post::blank('pwhash')) {
469 $to_update['password'] = Post::s('pwhash');
3168041b 470 require_once 'googleapps.inc.php';
1549059d
VZ
471 $account = new GoogleAppsAccount($user);
472 if ($account->active() && $account->sync_password) {
2477a631 473 $account->set_password(Post::s('pwhash'));
1549059d 474 }
83752d10 475 }
4f903ea6
FB
476 if (!Post::blank('weak_password')) {
477 $to_update['weak_password'] = Post::s('weak_password');
83752d10 478 }
4f903ea6
FB
479 if (Post::i('token_access', 0) != ($user->token_access ? 1 : 0)) {
480 $to_update['token'] = Post::i('token_access') ? rand_url_id(16) : null;
83752d10 481 }
fcdbb3bf
SJ
482 if (Post::i('skin') != $user->skin) {
483 $to_update['skin'] = Post::i('skin');
83752d10 484 if ($to_update['skin'] == 0) {
7cfaf494 485 $to_update['skin'] = null;
83752d10
FB
486 }
487 }
4f903ea6
FB
488 if (Post::s('state') != $user->state) {
489 $to_update['state'] = Post::s('state');
83752d10 490 }
4f903ea6
FB
491 if (Post::i('is_admin', 0) != ($user->is_admin ? 1 : 0)) {
492 $to_update['is_admin'] = Post::b('is_admin');
83752d10 493 }
4f903ea6
FB
494 if (Post::s('type') != $user->type) {
495 $to_update['type'] = Post::s('type');
83752d10 496 }
4f903ea6 497 if (Post::i('watch', 0) != ($user->watch ? 1 : 0)) {
83752d10 498 $to_update['flags'] = new PlFlagset();
4f903ea6 499 $to_update['flags']->addFlag('watch', Post::i('watch'));
83752d10 500 }
4f903ea6
FB
501 if (Post::t('comment') != $user->comment) {
502 $to_update['comment'] = Post::blank('comment') ? null : Post::t('comment');
83752d10 503 }
a8a11a70
FB
504 if (!$user->checkPerms(User::PERM_MAIL) && Post::t('email') != $user->forlifeEmail()) {
505 $to_update['email'] = Post::t('email');
506 $listClient->change_user_email($user->forlifeEmail(), Post::t('email'));
507 }
83752d10
FB
508 }
509 if (!empty($to_update)) {
01f78cbb
SJ
510 $res = XDB::query('SELECT *
511 FROM accounts
512 WHERE uid = {?}', $user->id());
513 $oldValues = $res->fetchAllAssoc();
514 $oldValues = $oldValues[0];
515
83752d10 516 $set = array();
01f78cbb 517 $diff = array();
83752d10 518 foreach ($to_update as $k => $value) {
01f78cbb
SJ
519 $value = XDB::format('{?}', $value);
520 $set[] = $k . ' = ' . $value;
521 $diff[$k] = array($oldValues[$k], trim($value, "'"));
522 unset($oldValues[$k]);
83752d10 523 }
a8a11a70
FB
524 XDB::rawExecute('UPDATE accounts
525 SET ' . implode(', ', $set) . '
526 WHERE uid = ' . XDB::format('{?}', $user->id()));
83752d10
FB
527 $page->trigSuccess('Données du compte mise à jour avec succès');
528 $user = User::getWithUID($user->id());
01f78cbb
SJ
529
530 /* Formats the $diff and send it to the site administrators. The rules are the folowing:
531 * -formats: password, token, weak_password
532 */
533 foreach (array('password', 'token', 'weak_password') as $key) {
534 if (isset($diff[$key])) {
535 $diff[$key] = array('old value', 'new value');
536 } else {
537 $oldValues[$key] = 'old value';
538 }
539 }
540
541 $mail = new PlMailer('admin/useredit.mail.tpl');
542 $mail->assign('admin', S::user()->hruid);
543 $mail->assign('hruid', $user->hruid);
544 $mail->assign('diff', $diff);
545 $mail->assign('oldValues', $oldValues);
546 $mail->send();
83752d10 547 }
f9743cf1 548 // }}}
4f903ea6 549
f9743cf1 550 // Profile form {{{
4f903ea6
FB
551 if (Post::has('add_profile') || Post::has('del_profile') || Post::has('owner')) {
552 if (Post::i('del_profile', 0) != 0) {
f9743cf1
FB
553 XDB::execute('DELETE FROM account_profiles
554 WHERE uid = {?} AND pid = {?}',
4f903ea6
FB
555 $user->id(), Post::i('del_profile'));
556 } else if (!Post::blank('new_profile')) {
557 $profile = Profile::get(Post::t('new_profile'));
f9743cf1 558 if (!$profile) {
4f903ea6 559 $page->trigError('Le profil ' . Post::t('new_profile') . ' n\'existe pas');
f9743cf1
FB
560 } else {
561 XDB::execute('INSERT IGNORE INTO account_profiles (uid, pid)
562 VALUES ({?}, {?})',
563 $user->id(), $profile->id());
564 }
565 }
566 XDB::execute('UPDATE account_profiles
567 SET perms = IF(pid = {?}, CONCAT(perms, \',owner\'), REPLACE(perms, \'owner\', \'\'))
568 WHERE uid = {?}',
4f903ea6 569 Post::i('owner'), $user->id());
f9743cf1 570 }
f9743cf1
FB
571 // }}}
572
4f903ea6
FB
573 // Email forwards form {{{
574 require_once("emails.inc.php");
575 $redirect = ($registered ? new Redirect($user) : null);
576 if (Post::has('add_fwd')) {
577 $email = Post::t('email');
578 if (!isvalid_email_redirection($email)) {
579 $page->trigError("Email non valide: $email");
580 } else {
581 $redirect->add_email($email);
582 $page->trigSuccess("Ajout de $email effectué");
583 }
584 } else if (!Post::blank('del_fwd')) {
585 $redirect->delete_email(Post::t('del_fwd'));
586 } else if (!Post::blank('activate_fwd')) {
587 $redirect->modify_one_email(Post::t('activate_fwd', true));
588 } else if (!Post::blank('deactivate_fwd')) {
589 $redirect->modify_one_email(Post::t('deactivate_fwd', false));
590 } else if (Post::has('disable_fwd')) {
591 $redirect->disable();
592 } else if (Post::has('enable_fwd')) {
593 $redirect->enable();
594 } else if (!Post::blank('clean_fwd')) {
595 $redirect->clean_errors(Post::t('clean_fwd'));
596 }
597 // }}}
d5fbeef6 598
4f903ea6
FB
599 // Email alias form {{{
600 if (Post::has('add_alias')) {
601 // Splits new alias in user and fqdn.
602 $alias = Env::t('email');
603 if (strpos($alias, '@') !== false) {
604 list($alias, $domain) = explode('@', $alias);
605 } else {
606 $domain = $globals->mail->domain;
607 }
84270653 608
4f903ea6
FB
609 // Checks for alias' user validity.
610 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
611 $page->trigError("'$alias' n'est pas un alias valide");
612 }
86f0a6af 613
4f903ea6
FB
614 // Eventually adds the alias to the right domain.
615 if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) {
616 $req = new AliasReq($user, $alias, 'Admin request', false);
617 if ($req->commit()) {
618 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
619 } else {
620 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
621 }
622 } elseif ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) {
fe13bc1d 623 $res = XDB::execute("INSERT INTO aliases (uid, alias, type)
4f903ea6
FB
624 VALUES ({?}, {?}, 'alias')",
625 $user->id(), $alias);
626 $page->trigSuccess("Nouvel alias '$alias' ajouté");
627 } else {
628 $page->trigError("Le domaine '$domain' n'est pas valide");
629 }
630 } else if (!Post::blank('del_alias')) {
631 XDB::execute("DELETE FROM aliases
fe13bc1d 632 WHERE uid = {?} AND alias = {?} AND
4f903ea6
FB
633 type NOT IN ('a_vie', 'homonyme')",
634 $user->id(), $val);
635 XDB::execute("UPDATE emails
636 SET rewrite = ''
637 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
638 $user->id(), $val);
639 fix_bestalias($user);
640 $page->trigSuccess("L'alias '$val' a été supprimé");
641 } else if (!Post::blank('best')) {
642 XDB::execute("UPDATE aliases
643 SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))
fe13bc1d 644 WHERE uid = {?}", $user->id());
4f903ea6
FB
645 XDB::execute("UPDATE aliases
646 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
fe13bc1d 647 WHERE uid = {?} AND alias = {?}", $user->id(), $val);
4f903ea6
FB
648 // As having a non-null bestalias value is critical in
649 // plat/al's code, we do an a posteriori check on the
650 // validity of the bestalias.
651 fix_bestalias($user);
652 }
653 // }}}
669cb0e0 654
83353c71
FB
655 // OpenId form {{{
656 if (Post::has('del_openid')) {
864957c1 657 XDB::execute('DELETE FROM account_auth_openid
83353c71
FB
658 WHERE id = {?}', Post::i('del_openid'));
659 }
660 // }}}
661
4f903ea6
FB
662 // Forum form {{{
663 if (Post::has('b_edit')) {
664 XDB::execute("DELETE FROM forum_innd
665 WHERE uid = {?}", $user->id());
666 if (Env::v('write_perm') != "" || Env::v('read_perm') != "" || Env::v('commentaire') != "" ) {
667 XDB::execute("INSERT INTO forum_innd
668 SET ipmin = '0', ipmax = '4294967295',
669 write_perm = {?}, read_perm = {?},
670 comment = {?}, priority = '200', uid = {?}",
671 Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $user->id());
672 }
673 }
674 // }}}
86f0a6af 675
86f0a6af 676
889d9807 677 $page->addJsLink('jquery.ui.core.js');
1b50c20c 678 $page->addJsLink('jquery.ui.widget.js');
889d9807 679 $page->addJsLink('jquery.ui.tabs.js');
2477a631 680 $page->addJsLink('password.js');
669cb0e0 681
d5fbeef6
VZ
682 // Displays last login and last host information.
683 $res = XDB::query("SELECT start, host
6586a74f 684 FROM log_sessions
d5fbeef6
VZ
685 WHERE uid = {?} AND suid = 0
686 ORDER BY start DESC
687 LIMIT 1", $user->id());
688 list($lastlogin,$host) = $res->fetchOneRow();
689 $page->assign('lastlogin', $lastlogin);
690 $page->assign('host', $host);
691
1d889ac4 692 // Display mailing lists
a8a11a70 693 $page->assign('mlists', $listClient->get_all_user_lists($user->forlifeEmail()));
1d889ac4 694
d5fbeef6 695 // Display active aliases.
8f2104cb 696 $page->assign('virtuals', $user->emailAliases());
4f903ea6
FB
697 $page->assign('aliases', XDB::iterator("SELECT alias, type='a_vie' AS for_life,
698 FIND_IN_SET('bestalias',flags) AS best, expire
699 FROM aliases
fe13bc1d 700 WHERE uid = {?} AND type != 'homonyme'
4f903ea6 701 ORDER BY type != 'a_vie'", $user->id()));
8f2104cb
FB
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'));
f9743cf1
FB
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()));
83353c71 708 $page->assign('openid', XDB::iterator('SELECT id, url
864957c1
FB
709 FROM account_auth_openid
710 WHERE uid = {?}', $user->id()));
d5fbeef6
VZ
711
712 // Displays email redirection and the general profile.
713 if ($registered && $redirect) {
714 $page->assign('emails', $redirect->emails);
715 }
716
d5fbeef6 717 $page->assign('user', $user);
aef87266 718 $page->assign('hasProfile', $user->hasProfile());
d5fbeef6
VZ
719
720 // Displays forum bans.
721 $res = XDB::query("SELECT write_perm, read_perm, comment
7d15f750 722 FROM forum_innd
d5fbeef6
VZ
723 WHERE uid = {?}", $user->id());
724 $bans = $res->fetchOneAssoc();
725 $page->assign('bans', $bans);
86f0a6af 726 }
1f53925a 727
e02d9fbb 728 private static function getHrid($firstname, $lastname, $promo)
7c5200a5 729 {
e02d9fbb 730 if ($firstname != null && $lastname != null && $promo != null) {
69fc05dd 731 return User::makeHrid($firstname, $lastname, $promo);
7c5200a5 732 }
f6eacab0 733 return null;
7c5200a5
VZ
734 }
735
cb0c8b1c 736 private static function formatNewUser(&$page, $infosLine, $separator, $promo, $size)
1f53925a 737 {
e02d9fbb 738 $infos = explode($separator, $infosLine);
cb0c8b1c
SJ
739 if (sizeof($infos) > $size || sizeof($infos) < 2) {
740 $page->trigError("La ligne $infosLine n'a pas été ajoutée.");
e02d9fbb 741 return false;
1f53925a 742 }
743
16714428 744 $infos = array_map('trim', $infos);
e02d9fbb
SJ
745 $hrid = self::getHrid($infos[1], $infos[0], $promo);
746 $res1 = XDB::query('SELECT COUNT(*)
747 FROM accounts
748 WHERE hruid = {?}', $hrid);
749 $res2 = XDB::query('SELECT COUNT(*)
750 FROM profiles
751 WHERE hrpid = {?}', $hrid);
752 if (is_null($hrid) || $res1->fetchOneCell() > 0 || $res2->fetchOneCell() > 0) {
981fce7b 753 $page->trigError("La ligne $infosLine n'a pas été ajoutée: une entrée similaire existe déjà");
e02d9fbb
SJ
754 return false;
755 }
756 $infos['hrid'] = $hrid;
757 return $infos;
758 }
759
760 private static function formatSex(&$page, $sex, $line)
761 {
762 switch ($sex) {
763 case 'F':
764 return PlUser::GENDER_FEMALE;
765 case 'M':
766 return PlUser::GENDER_MALE;
767 default:
768 $page->trigError("La ligne $line n'a pas été ajoutée car le sexe $sex n'est pas pris en compte.");
769 return null;
1f53925a 770 }
e02d9fbb 771 }
1f53925a 772
e02d9fbb
SJ
773 private static function formatBirthDate($birthDate)
774 {
16714428
RB
775 // strtotime believes dd/mm/yyyy to be an US date (i.e mm/dd/yyyy), and
776 // dd-mm-yyyy to be a normal date (i.e dd-mm-yyyy)...
777 return date("Y-m-d", strtotime(str_replace('/', '-', $birthDate)));
e02d9fbb
SJ
778 }
779
780 function handler_add_accounts(&$page, $action = null, $promo = null)
781 {
782 $page->changeTpl('admin/add_accounts.tpl');
783
784 if (Env::has('add_type') && Env::has('people')) {
e02d9fbb
SJ
785 $lines = explode("\n", Env::t('people'));
786 $separator = Env::t('separator');
787 $promotion = Env::i('promotion');
94590511 788 $nameTypes = DirEnum::getOptions(DirEnum::NAMETYPES);
e02d9fbb
SJ
789 $nameTypes = array_flip($nameTypes);
790
791 if (Env::t('add_type') == 'promo') {
792 $type = 'x';
94590511 793 $eduSchools = DirEnum::getOptions(DirEnum::EDUSCHOOLS);
e02d9fbb 794 $eduSchools = array_flip($eduSchools);
94590511 795 $eduDegrees = DirEnum::getOptions(DirEnum::EDUDEGREES);
e02d9fbb 796 $eduDegrees = array_flip($eduDegrees);
e02d9fbb
SJ
797 switch (Env::t('edu_type')) {
798 case 'X':
799 $degreeid = $eduDegrees[Profile::DEGREE_X];
800 $entry_year = $promotion;
801 $grad_year = $promotion + 3;
802 $promo = 'X' . $promotion;
d9e99995 803 $hrpromo = $promotion;
e02d9fbb
SJ
804 break;
805 case 'M':
806 $degreeid = $eduDegrees[Profile::DEGREE_M];
807 $grad_year = $promotion;
808 $entry_year = $promotion - 2;
809 $promo = 'M' . $promotion;
d9e99995
FB
810 $hrpromo = $promo;
811 $type = 'master';
e02d9fbb
SJ
812 break;
813 case 'D':
814 $degreeid = $eduDegrees[Profile::DEGREE_D];
815 $grad_year = $promotion;
816 $entry_year = $promotion - 3;
817 $promo = 'D' . $promotion;
d9e99995
FB
818 $hrpromo = $promo;
819 $type = 'phd';
e02d9fbb
SJ
820 break;
821 default:
822 $page->killError("La formation n'est pas reconnue:" . Env::t('edu_type') . '.');
823 }
824
7f55b0d6 825 XDB::startTransaction();
e02d9fbb 826 foreach ($lines as $line) {
d9e99995 827 if ($infos = self::formatNewUser($page, $line, $separator, $hrpromo, 6)) {
cb0c8b1c
SJ
828 $sex = self::formatSex($page, $infos[3], $line);
829 if (!is_null($sex)) {
4452750b
SJ
830 $fullName = $infos[1] . ' ' . $infos[0];
831 $directoryName = $infos[0] . ' ' . $infos[1];
cb0c8b1c
SJ
832 $birthDate = self::formatBirthDate($infos[2]);
833 $xorgId = Profile::getXorgId($infos[4]);
834 if (is_null($xorgId)) {
835 $page->trigError("La ligne $line n'a pas été ajoutée car le matricule École est mal renseigné.");
836 continue;
837 }
838
839 XDB::execute('INSERT INTO profiles (hrpid, xorg_id, ax_id, birthdate_ref, sex)
840 VALUES ({?}, {?}, {?}, {?}, {?})',
841 $infos['hrid'], $xorgId, $infos[5], $birthDate, $sex);
842 $pid = XDB::insertId();
843 XDB::execute('INSERT INTO profile_name (pid, name, typeid)
d9e99995
FB
844 VALUES ({?}, {?}, {?}),
845 ({?}, {?}, {?}),
846 ({?}, {?}, {?}),
847 ({?}, {?}, {?})',
848 $pid, $infos[0], $nameTypes['name_ini'],
849 $pid, $infos[0], $nameTypes['lastname'],
850 $pid, $infos[1], $nameTypes['firstname_ini'],
851 $pid, $infos[1], $nameTypes['firstname']);
cb0c8b1c
SJ
852 XDB::execute('INSERT INTO profile_display (pid, yourself, public_name, private_name,
853 directory_name, short_name, sort_name, promo)
854 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
4452750b 855 $pid, $infos[1], $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo);
cb0c8b1c
SJ
856 XDB::execute('INSERT INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags)
857 VALUES ({?}, {?}, {?}, {?}, {?}, {?})',
858 $pid, $eduSchools[Profile::EDU_X], $degreeid, $entry_year, $grad_year, 'primary');
4452750b 859 XDB::execute('INSERT INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex)
d9e99995
FB
860 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
861 $infos['hrid'], $type, 0, 'pending', $fullName, $directoryName, $infos[1], $sex);
cb0c8b1c
SJ
862 $uid = XDB::insertId();
863 XDB::execute('INSERT INTO account_profiles (uid, pid, perms)
864 VALUES ({?}, {?}, {?})',
865 $uid, $pid, 'owner');
bedc4295 866 Profile::rebuildSearchTokens($pid, false);
cb0c8b1c 867 }
e02d9fbb
SJ
868 }
869 }
7f55b0d6 870 XDB::commit();
e02d9fbb
SJ
871 } else if (Env::t('add_type') == 'account') {
872 $type = Env::t('type');
4029afb0 873 $newAccounts = array();
e02d9fbb 874 foreach ($lines as $line) {
cb0c8b1c
SJ
875 if ($infos = self::formatNewUser($page, $line, $separator, $type, 4)) {
876 $sex = self::formatSex($page, $infos[3], $line);
877 if (!is_null($sex)) {
4452750b
SJ
878 $fullName = $infos[1] . ' ' . $infos[0];
879 $directoryName = $infos[0] . ' ' . $infos[1];
d9e99995
FB
880 XDB::execute('INSERT INTO accounts (hruid, type, is_admin, state,
881 email, full_name, directory_name,
882 display_name, sex)
883 VALUES ({?}, {?}, {?}, {?},
884 {?}, {?}, {?}, {?}, {?})',
885 $infos['hrid'], $type, 0, 'pending',
886 $infos[2], $fullName, $directoryName,
887 $infos[1], $sex);
4029afb0 888 $newAccounts[$infos['hrid']] = $infos[1] . ' ' . $infos[0];
cb0c8b1c 889 }
e02d9fbb
SJ
890 }
891 }
4029afb0
SJ
892 if (!empty($newAccounts)) {
893 $page->assign('newAccounts', $newAccounts);
894 }
e02d9fbb
SJ
895 } else if (Env::t('add_type') == 'ax_id') {
896 $type = 'x';
897 foreach ($lines as $line) {
cb0c8b1c 898 if ($infos = self::formatNewUser($page, $line, $separator, $promotion, 3)) {
e02d9fbb
SJ
899 XDB::execute('UPDATE profiles
900 SET ax_id = {?}
901 WHERE hrpid = {?}',
902 $infos[2], $infos['hrid']);
903 }
904 }
905 }
906
cb0c8b1c
SJ
907 $errors = $page->nb_errs();
908 if ($errors == 0) {
e02d9fbb
SJ
909 $page->trigSuccess("L'opération a été effectuée avec succès.");
910 } else {
cb0c8b1c
SJ
911 $page->trigSuccess('L\'opération a été effectuée avec succès, sauf pour '
912 . (($errors == 1) ? 'l\'erreur signalée' : "les $errors erreurs signalées") . ' ci-dessus.');
e02d9fbb
SJ
913 }
914 } else if (Env::has('add_type')) {
915 $res = XDB::query('SELECT type
916 FROM account_types');
917 $page->assign('account_types', $res->fetchColumn());
918 $page->assign('add_type', Env::s('add_type'));
1f53925a 919 }
1f53925a 920 }
921
7c5200a5
VZ
922 function handler_homonyms(&$page, $op = 'list', $target = null)
923 {
86f0a6af 924 $page->changeTpl('admin/homonymes.tpl');
46f272fe 925 $page->setTitle('Administration - Homonymes');
191711d5 926 $this->load("homonyms.inc.php");
74c55fd6 927
86f0a6af 928 if ($target) {
191711d5
FB
929 $user = User::getSilent($target);
930 if (!$user || !($loginbis = select_if_homonyme($user))) {
931 $target = 0;
86f0a6af 932 } else {
191711d5 933 $page->assign('user', $user);
86f0a6af 934 $page->assign('loginbis',$loginbis);
935 }
936 }
74c55fd6 937
839a80cf
VZ
938 $page->assign('op', $op);
939 $page->assign('target', $target);
74c55fd6 940
86f0a6af 941 // on a un $target valide, on prepare les mails
942 if ($target) {
86f0a6af 943 // on examine l'op a effectuer
944 switch ($op) {
945 case 'mail':
40d428d8
VZ
946 S::assert_xsrf_token();
947
191711d5
FB
948 send_warning_homonyme($user, $loginbis);
949 switch_bestalias($user, $loginbis);
86f0a6af 950 $op = 'list';
191711d5 951 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.');
86f0a6af 952 break;
839a80cf 953
86f0a6af 954 case 'correct':
40d428d8
VZ
955 S::assert_xsrf_token();
956
191711d5 957 switch_bestalias($user, $loginbis);
32b3ac78
FB
958 XDB::execute("UPDATE aliases
959 SET type = 'homonyme', expire=NOW()
960 WHERE alias = {?}", $loginbis);
00ba8a74
SJ
961 XDB::execute('INSERT IGNORE INTO homonyms (homonyme_id, uid)
962 VALUES ({?}, {?})', $target, $target);
191711d5 963 send_robot_homonyme($user, $loginbis);
86f0a6af 964 $op = 'list';
191711d5 965 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.');
86f0a6af 966 break;
967 }
968 }
74c55fd6 969
86f0a6af 970 if ($op == 'list') {
971 $res = XDB::iterator(
32b3ac78 972 "SELECT a.alias AS homonyme, s.alias AS forlife,
e84223d4
PC
973 IF(h.homonyme_id = s.uid, a.expire, NULL) AS expire,
974 IF(h.homonyme_id = s.uid, a.type, NULL) AS type, ac.uid
86f0a6af 975 FROM aliases AS a
1bf36cd1
SJ
976 LEFT JOIN homonyms AS h ON (h.homonyme_id = a.uid)
977 INNER JOIN aliases AS s ON (s.uid = h.uid AND s.type = 'a_vie')
fe13bc1d 978 INNER JOIN accounts AS ac ON (ac.uid = a.uid)
32b3ac78
FB
979 WHERE a.type = 'homonyme' OR a.expire != ''
980 ORDER BY a.alias, forlife");
86f0a6af 981 $hnymes = Array();
982 while ($tab = $res->next()) {
983 $hnymes[$tab['homonyme']][] = $tab;
984 }
1bf36cd1 985 $page->assign_by_ref('hnymes', $hnymes);
86f0a6af 986 }
987 }
74c55fd6 988
32b3ac78
FB
989 function handler_deaths(&$page, $promo = 0, $validate = false)
990 {
86f0a6af 991 $page->changeTpl('admin/deces_promo.tpl');
46f272fe 992 $page->setTitle('Administration - Deces');
74c55fd6 993
dcefa8f7
FB
994 if (!$promo) {
995 $promo = Env::t('promo', 'X1923');
996 }
997 $page->assign('promo', $promo);
998 if (!$promo) {
999 return;
1000 }
74c55fd6 1001
40d428d8
VZ
1002 if ($validate) {
1003 S::assert_xsrf_token();
1004
f198bf30 1005 $res = XDB::iterRow('SELECT p.pid, pd.directory_name, p.deathdate
dcefa8f7
FB
1006 FROM profiles AS p
1007 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
1008 WHERE pd.promo = {?}', $promo);
1009 while (list($pid, $name, $death) = $res->next()) {
f198bf30 1010 $val = Env::v('death_' . $pid);
71497fb8 1011 if ($val == $death) {
e61326ed
VZ
1012 continue;
1013 }
1014
71497fb8
SJ
1015 if (empty($val)) {
1016 $val = null;
1017 }
dcefa8f7
FB
1018 XDB::execute('UPDATE profiles
1019 SET deathdate = {?}, deathdate_rec = NOW()
f198bf30 1020 WHERE pid = {?}', $val, $pid);
71497fb8
SJ
1021
1022 $page->trigSuccess('Édition du décès de ' . $name . ' (' . ($val ? $val : 'ressuscité') . ').');
1023 if ($val && ($death == '0000-00-00' || empty($death))) {
438b7a0c 1024 $profile = Profile::get($pid);
6150f591
SJ
1025 $profile->clear();
1026 $profile->owner()->clear(false);
e61326ed 1027 }
86f0a6af 1028 }
86f0a6af 1029 }
74c55fd6 1030
f198bf30 1031 $res = XDB::iterator('SELECT p.pid, pd.directory_name, p.deathdate
dcefa8f7
FB
1032 FROM profiles AS p
1033 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
1034 WHERE pd.promo = {?}
1035 ORDER BY pd.sort_name', $promo);
71497fb8 1036 $page->assign('profileList', $res);
86f0a6af 1037 }
74c55fd6 1038
32b3ac78
FB
1039 function handler_dead_but_active(&$page)
1040 {
1c48c2a9 1041 $page->changeTpl('admin/dead_but_active.tpl');
46f272fe 1042 $page->setTitle('Administration - Décédés');
1c48c2a9
VZ
1043
1044 $res = XDB::iterator(
e46cf8c4 1045 "SELECT a.hruid, pd.promo, p.ax_id, pd.directory_name, p.deathdate, DATE(MAX(s.start)) AS last
fe13bc1d
FB
1046 FROM accounts AS a
1047 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
1048 INNER JOIN profiles AS p ON (p.pid = ap.pid)
1049 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
6586a74f 1050 LEFT JOIN log_sessions AS s ON (s.uid = a.uid AND suid = 0)
e46cf8c4 1051 WHERE a.state = 'active' AND p.deathdate IS NOT NULL
dcefa8f7 1052 GROUP BY a.uid
e46cf8c4 1053 ORDER BY pd.promo, pd.sort_name");
1c48c2a9
VZ
1054 $page->assign('dead', $res);
1055 }
1056
e654517d 1057 function handler_validate(&$page, $action = 'list', $id = null)
1058 {
764b894d 1059 $page->changeTpl('admin/validation.tpl');
46f272fe 1060 $page->setTitle('Administration - Valider une demande');
5b8c317d 1061 $page->addCssLink('nl.css');
e654517d 1062
5b8c317d 1063 if ($action == 'edit' && !is_null($id)) {
ed5b9703 1064 $page->assign('preview_id', $id);
5b8c317d
SJ
1065 } else {
1066 $page->assign('preview_id', null);
ed5b9703 1067 }
1068
86f0a6af 1069 if(Env::has('uid') && Env::has('type') && Env::has('stamp')) {
40d428d8
VZ
1070 S::assert_xsrf_token();
1071
20d7932b 1072 $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp'));
343e22c2
FB
1073 if ($req) {
1074 $req->handle_formu();
1075 } else {
1076 $page->trigWarning('La validation a déjà été effectuée.');
1077 }
86f0a6af 1078 }
74c55fd6 1079
cfb96867 1080 $r = XDB::iterator('SHOW COLUMNS FROM requests_answers');
1081 while (($a = $r->next()) && $a['Field'] != 'category');
1082 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
74c55fd6 1083
cfb96867 1084 $hidden = array();
257ae408
SJ
1085 $res = XDB::query('SELECT hidden_requests
1086 FROM requests_hidden
1087 WHERE uid = {?}', S::v('uid'));
e0d7c076 1088 $hide_requests = $res->fetchOneCell();
cfb96867 1089 if (Post::has('hide')) {
74c55fd6 1090 $hide = array();
1091 foreach ($categories as $cat)
cfb96867 1092 if (!Post::v($cat)) {
1093 $hidden[$cat] = 1;
1094 $hide[] = $cat;
1095 }
e0d7c076 1096 $hide_requests = join(',', $hide);
00ba8a74
SJ
1097 XDB::query('INSERT INTO requests_hidden (uid, hidden_requests)
1098 VALUES ({?}, {?})
1099 ON DUPLICATE KEY UPDATE hidden_requests = VALUES(hidden_requests)',
e0d7c076
SJ
1100 S::v('uid'), $hide_requests);
1101 } elseif ($hide_requests) {
1102 foreach (explode(',', $hide_requests) as $hide_type)
cfb96867 1103 $hidden[$hide_type] = true;
1104 }
1105 $page->assign('hide_requests', $hidden);
74c55fd6 1106
90df2530
FB
1107 // Update the count of item to validate here... useful in development configuration
1108 // where several copies of the site use the same DB, but not the same "dynamic configuration"
ebfdf077
FB
1109 global $globals;
1110 $globals->updateNbValid();
7b094a73 1111 $page->assign('vit', Validate::iterate());
e33b29e5 1112 $page->assign('isAdmin', S::admin());
86f0a6af 1113 }
e654517d 1114
32b3ac78
FB
1115 function handler_validate_answers(&$page, $action = 'list', $id = null)
1116 {
46f272fe 1117 $page->setTitle('Administration - Réponses automatiques de validation');
a7de4ef7 1118 $page->assign('title', 'Gestion des réponses automatiques');
e18888f4 1119 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
a7de4ef7 1120 $table_editor->describe('category','catégorie',true);
e18888f4 1121 $table_editor->describe('title','titre',true);
1122 $table_editor->describe('answer','texte',false);
1123 $table_editor->apply($page, $action, $id);
1124 }
32b3ac78
FB
1125
1126 function handler_skins(&$page, $action = 'list', $id = null)
1127 {
46f272fe 1128 $page->setTitle('Administration - Skins');
e7ae7df9 1129 $page->assign('title', 'Gestion des skins');
1130 $table_editor = new PLTableEditor('admin/skins','skins','id');
1131 $table_editor->describe('name','nom',true);
1132 $table_editor->describe('skin_tpl','nom du template',true);
1133 $table_editor->describe('auteur','auteur',false);
1134 $table_editor->describe('comment','commentaire',true);
1135 $table_editor->describe('date','date',false);
1136 $table_editor->describe('ext','extension du screenshot',false);
1137 $table_editor->apply($page, $action, $id);
74c55fd6 1138 }
669cb0e0 1139
32b3ac78
FB
1140 function handler_postfix_blacklist(&$page, $action = 'list', $id = null)
1141 {
46f272fe 1142 $page->setTitle('Administration - Postfix : Blacklist');
e7ae7df9 1143 $page->assign('title', 'Blacklist de postfix');
1144 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true);
1145 $table_editor->describe('reject_text','Texte de rejet',true);
1146 $table_editor->describe('email','email',true);
1147 $table_editor->apply($page, $action, $id);
74c55fd6 1148 }
32b3ac78
FB
1149
1150 function handler_postfix_whitelist(&$page, $action = 'list', $id = null)
1151 {
46f272fe 1152 $page->setTitle('Administration - Postfix : Whitelist');
e7ae7df9 1153 $page->assign('title', 'Whitelist de postfix');
1154 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true);
1155 $table_editor->describe('email','email',true);
1156 $table_editor->apply($page, $action, $id);
74c55fd6 1157 }
32b3ac78
FB
1158
1159 function handler_mx_broken(&$page, $action = 'list', $id = null)
1160 {
46f272fe 1161 $page->setTitle('Administration - MX Défaillants');
a7de4ef7 1162 $page->assign('title', 'MX Défaillant');
ccdbc270 1163 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true);
1164 $table_editor->describe('host', 'Masque', true);
1165 $table_editor->describe('state', 'Niveau', true);
a7de4ef7 1166 $table_editor->describe('text', 'Description du problème', false);
ccdbc270 1167 $table_editor->apply($page, $action, $id);
1168 }
32b3ac78
FB
1169
1170 function handler_logger_actions(&$page, $action = 'list', $id = null)
1171 {
46f272fe 1172 $page->setTitle('Administration - Actions');
e7ae7df9 1173 $page->assign('title', 'Gestion des actions de logger');
6586a74f 1174 $table_editor = new PLTableEditor('admin/logger/actions','log_actions','id');
a7de4ef7 1175 $table_editor->describe('text','intitulé',true);
e7ae7df9 1176 $table_editor->describe('description','description',true);
1177 $table_editor->apply($page, $action, $id);
74c55fd6 1178 }
32b3ac78 1179
8f2104cb
FB
1180 function handler_downtime(&$page, $action = 'list', $id = null)
1181 {
46f272fe 1182 $page->setTitle('Administration - Coupures');
e7ae7df9 1183 $page->assign('title', 'Gestion des coupures');
06f4daf9 1184 $table_editor = new PLTableEditor('admin/downtime','downtimes','id');
e7ae7df9 1185 $table_editor->describe('debut','date',true);
a7de4ef7 1186 $table_editor->describe('duree','durée',false);
1187 $table_editor->describe('resume','résumé',true);
1188 $table_editor->describe('services','services affectés',true);
e7ae7df9 1189 $table_editor->describe('description','description',false);
1190 $table_editor->apply($page, $action, $id);
74c55fd6 1191 }
bc0903c7 1192
8338711c
FB
1193 function handler_accounts(PlPage $page)
1194 {
1195 $page->changeTpl('admin/accounts.tpl');
1196 $page->setTitle('Administration - Comptes');
1197 $page->addJsLink('password.js');
1198
1199 if (Post::has('create_account')) {
1200 S::assert_xsrf_token();
1201 $firstname = Post::t('firstname');
1202 $lastname = strtoupper(Post::t('lastname'));
e8c61abe 1203 $sex = Post::s('sex');
8338711c 1204 $email = Post::t('email');
67cff520
FB
1205 $type = Post::s('type');
1206 $login = PlUser::makeHrid($firstname, $lastname, $type);
8338711c
FB
1207 if (!isvalid_email($email)) {
1208 $page->trigError("Invalid email address: $email");
1209 } else if (strlen(Post::s('pwhash')) != 40) {
1210 $page->trigError("Invalid password hash");
1211 } else {
1212 $full_name = $firstname . ' ' . $lastname;
1213 $directory_name = $lastname . ' ' . $firstname;
1214 XDB::execute("INSERT INTO accounts (hruid, type, state, password,
1215 registration_date, email, full_name,
1216 display_name, sex, directory_name)
67cff520
FB
1217 VALUES ({?}, {?}, 'active', {?}, NOW(), {?}, {?}, {?}, {?}, {?})",
1218 $login, $type, Post::s('pwhash'), $email, $full_name, $full_name, $sex,
8338711c
FB
1219 $directory_name);
1220 }
1221 }
1222
67cff520
FB
1223 $uf = new UserFilter(new UFC_AccountType('ax', 'school', 'fx'));
1224 $page->assign('users', $uf->iterUsers());
8338711c
FB
1225
1226 }
1227
aab2ffdd 1228 function handler_account_types(&$page, $action = 'list', $id = null)
8f2104cb
FB
1229 {
1230 $page->setTitle('Administration - Types de comptes');
1231 $page->assign('title', 'Gestion des types de comptes');
1232 $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true);
1233 $table_editor->describe('type', 'Catégorie', true);
1234 $table_editor->describe('perms', 'Permissions associées', true);
1235 $table_editor->apply($page, $action, $id);
1236 }
1237
8f201b69 1238 function handler_wiki(&$page, $action = 'list', $wikipage = null, $wikipage2 = null)
bc0903c7 1239 {
84fc72ff 1240 if (S::hasAuthToken()) {
a2b461ce 1241 $page->setRssLink('Changement Récents',
2ab3486b 1242 '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::user()->token);
a2b461ce 1243 }
e61326ed 1244
3aec1c21 1245 // update wiki perms
40d428d8
VZ
1246 if ($action == 'update') {
1247 S::assert_xsrf_token();
1248
3aec1c21 1249 $perms_read = Post::v('read');
8f201b69 1250 $perms_edit = Post::v('edit');
3aec1c21 1251 if ($perms_read || $perms_edit) {
8f201b69
FB
1252 foreach ($_POST as $wiki_page => $val) {
1253 if ($val == 'on') {
1254 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1255 if ($wp->setPerms($perms_read ? $perms_read : $wp->readPerms(),
1256 $perms_edit ? $perms_edit : $wp->writePerms())) {
1257 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1258 } else {
1259 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1260 }
1261 }
3aec1c21 1262 }
1263 }
8f201b69
FB
1264 } else if ($action != 'list' && !empty($wikipage)) {
1265 $wp = new PlWikiPage($wikipage);
40d428d8
VZ
1266 S::assert_xsrf_token();
1267
8f201b69
FB
1268 if ($action == 'delete') {
1269 if ($wp->delete()) {
1270 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1271 } else {
1272 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1273 }
1274 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1275 if ($changedLinks = $wp->rename($wikipage2)) {
1276 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1277 if (is_numeric($changedLinks)) {
1278 $s .= $changedLinks.' lien'.(($changedLinks>1)?'s ont été modifiés.':' a été modifié.');
1279 }
1280 $page->trigSuccess($s);
1281 } else {
1282 $page->trigError("Impossible de déplacer la page ".$wikipage);
9162f4ed 1283 }
9162f4ed 1284 }
1285 }
74c55fd6 1286
8f201b69 1287 $perms = PlWikiPage::permOptions();
74c55fd6 1288
3aec1c21 1289 // list wiki pages and their perms
8f201b69 1290 $wiki_pages = PlWikiPage::listPages();
3aec1c21 1291 ksort($wiki_pages);
bc0903c7 1292 $wiki_tree = array();
1293 foreach ($wiki_pages as $file => $desc) {
1294 list($cat, $name) = explode('.', $file);
1295 if (!isset($wiki_tree[$cat])) {
1296 $wiki_tree[$cat] = array();
1297 }
1298 $wiki_tree[$cat][$name] = $desc;
1299 }
1300
3aec1c21 1301 $page->changeTpl('admin/wiki.tpl');
bc0903c7 1302 $page->assign('wiki_pages', $wiki_tree);
3aec1c21 1303 $page->assign('perms_opts', $perms);
1304 }
5480a216 1305
1306 function handler_ipwatch(&$page, $action = 'list', $ip = null)
eaf30d86 1307 {
5480a216 1308 $page->changeTpl('admin/ipwatcher.tpl');
eaf30d86 1309
5480a216 1310 $states = array('safe' => 'Ne pas surveiller',
c339246f 1311 'unsafe' => 'Surveiller les inscriptions',
a7de4ef7 1312 'dangerous' => 'Surveiller tous les accès',
5480a216 1313 'ban' => 'Bannir cette adresse');
1314 $page->assign('states', $states);
1315
1316 switch (Post::v('action')) {
e61326ed 1317 case 'create':
5480a216 1318 if (trim(Post::v('ipN')) != '') {
40d428d8 1319 S::assert_xsrf_token();
61c98f4b
FB
1320 Xdb::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1321 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1322 ip_to_uint(trim(Post::v('ipN'))), ip_to_uint(trim(Post::v('maskN'))),
1323 Post::v('stateN'), S::i('uid'), Post::v('descriptionN'));
eaf30d86
PH
1324 };
1325 break;
1326
e61326ed 1327 case 'edit':
40d428d8 1328 S::assert_xsrf_token();
eaf30d86 1329 Xdb::execute('UPDATE ip_watch
61c98f4b 1330 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
9797734d 1331 WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'),
61c98f4b 1332 ip_to_uint(Post::v('maskN')), ip_to_uint(Post::v('ipN')));
5480a216 1333 break;
eaf30d86 1334
e61326ed 1335 default:
5480a216 1336 if ($action == 'delete' && !is_null($ip)) {
40d428d8
VZ
1337 S::assert_xsrf_token();
1338 Xdb::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
5480a216 1339 }
1340 }
1341 if ($action != 'create' && $action != 'edit') {
1342 $action = 'list';
1343 }
1344 $page->assign('action', $action);
1345
1346 if ($action == 'list') {
9797734d
FB
1347 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1348 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1349 IF(w.ip = s.ip, s.host, s.forward_host)),
32b3ac78 1350 w.mask, w.detection, w.state, a.hruid
fe13bc1d 1351 FROM ip_watch AS w
6586a74f
FB
1352 LEFT JOIN log_sessions AS s ON (s.ip = w.ip)
1353 LEFT JOIN log_sessions AS s2 ON (s2.forward_ip = w.ip)
fe13bc1d 1354 LEFT JOIN accounts AS a ON (a.uid = s.uid)
32b3ac78
FB
1355 GROUP BY w.ip, a.hruid
1356 ORDER BY w.state, w.ip, a.hruid";
5480a216 1357 $it = Xdb::iterRow($sql);
1358
1359 $table = array();
1360 $props = array();
90c614cd 1361 while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) {
9797734d 1362 $ip = uint_to_ip($ip);
61c98f4b 1363 $mask = uint_to_ip($mask);
5480a216 1364 if (count($props) == 0 || $props['ip'] != $ip) {
1365 if (count($props) > 0) {
1366 $table[] = $props;
1367 }
1368 $props = array('ip' => $ip,
61c98f4b 1369 'mask' => $mask,
5480a216 1370 'host' => $host,
1371 'detection' => $date,
1372 'state' => $state,
90c614cd 1373 'users' => array($hruid));
5480a216 1374 } else {
90c614cd 1375 $props['users'][] = $hruid;
5480a216 1376 }
1377 }
1378 if (count($props) > 0) {
1379 $table[] = $props;
1380 }
1381 $page->assign('table', $table);
1382 } elseif ($action == 'edit') {
61c98f4b 1383 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
32b3ac78 1384 a1.hruid AS edit, a2.hruid AS hruid, s.host
fe13bc1d
FB
1385 FROM ip_watch AS w
1386 LEFT JOIN accounts AS a1 ON (a1.uid = w.uid)
6586a74f 1387 LEFT JOIN log_sessions AS s ON (w.ip = s.ip)
fe13bc1d 1388 LEFT JOIN accounts AS a2 ON (a2.uid = s.uid)
5480a216 1389 WHERE w.ip = {?}
32b3ac78
FB
1390 GROUP BY a2.hruid
1391 ORDER BY a2.hruid";
9797734d 1392 $it = Xdb::iterRow($sql, ip_to_uint($ip));
5480a216 1393
1394 $props = array();
90c614cd 1395 while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) {
5480a216 1396 if (count($props) == 0) {
1397 $props = array('ip' => $ip,
61c98f4b 1398 'mask' => uint_to_ip($mask),
5480a216 1399 'host' => $host,
1400 'detection' => $detection,
1401 'state' => $state,
1402 'last' => $last,
1403 'description' => $description,
1404 'edit' => $edit,
90c614cd 1405 'users' => array($hruid));
5480a216 1406 } else {
90c614cd 1407 $props['users'][] = $hruid;
5480a216 1408 }
1409 }
1410 $page->assign('ip', $props);
1411 }
1412 }
eaf30d86 1413
04148a2c 1414 function handler_icons(&$page)
f141945d 1415 {
1416 $page->changeTpl('admin/icons.tpl');
1417 $dh = opendir('../htdocs/images/icons');
1418 if (!$dh) {
a7d35093 1419 $page->trigError('Dossier des icones introuvables.');
f141945d 1420 }
1421 $icons = array();
1422 while (($file = readdir($dh)) !== false) {
1423 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1424 array_push($icons, substr($file, 0, -4));
1425 }
1426 }
1427 sort($icons);
1428 $page->assign('icons', $icons);
04148a2c 1429 }
fd1ce8c5 1430
8338711c 1431 function handler_account_watch(&$page)
fd1ce8c5
FB
1432 {
1433 $page->changeTpl('admin/accounts.tpl');
32b3ac78
FB
1434 $page->assign('disabled', XDB::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch,
1435 a.state = \'disabled\' AS disabled, a.comment
1436 FROM accounts AS a
1437 WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags)
1438 ORDER BY a.hruid'));
1439 $page->assign('admins', XDB::iterator('SELECT a.hruid
1440 FROM accounts AS a
1441 WHERE a.is_admin
1442 ORDER BY a.hruid'));
fd1ce8c5 1443 }
4d336f59
SJ
1444
1445 function handler_jobs(&$page, $id = -1)
1446 {
1447 $page->changeTpl('admin/jobs.tpl');
1448
1449 if (Env::has('search')) {
308bbdb0
SJ
1450 $res = XDB::query("SELECT id, name, acronym
1451 FROM profile_job_enum
1452 WHERE name LIKE CONCAT('%', {?}, '%') OR acronym LIKE CONCAT('%', {?}, '%')",
4d336f59
SJ
1453 Env::t('job'), Env::t('job'));
1454
1455 if ($res->numRows() <= 20) {
1456 $page->assign('jobs', $res->fetchAllAssoc());
1457 } else {
1458 $page->trigError("Il y a trop d'entreprises correspondant à ton choix. Affine-le !");
1459 }
1460
1461 $page->assign('askedJob', Env::v('job'));
1462 return;
1463 }
1464
1465 if (Env::has('edit')) {
1466 S::assert_xsrf_token();
1467 $selectedJob = Env::has('selectedJob');
1468
0b6c8b36 1469 Phone::deletePhones(0, Phone::LINK_COMPANY, $id);
781a24bc 1470 Address::deleteAddresses(null, Address::LINK_COMPANY, $id);
4d336f59 1471 if (Env::has('change')) {
e954a945
SJ
1472 if (Env::has('newJobId') && Env::i('newJobId') > 0) {
1473 XDB::execute('UPDATE profile_job
1474 SET jobid = {?}
1475 WHERE jobid = {?}',
1476 Env::i('newJobId'), $id);
1477 XDB::execute('DELETE FROM profile_job_enum
1478 WHERE id = {?}',
1479 $id);
1480
1481 $page->trigSuccess("L'entreprise a bien été remplacée.");
1482 } else {
1483 $page->trigError("L'entreprise n'a pas été remplacée car l'identifiant fourni n'est pas valide.");
1484 }
4d336f59
SJ
1485 } else {
1486 XDB::execute('UPDATE profile_job_enum
1487 SET name = {?}, acronym = {?}, url = {?}, email = {?},
1488 NAF_code = {?}, AX_code = {?}, holdingid = {?}
1489 WHERE id = {?}',
1490 Env::t('name'), Env::t('acronym'), Env::t('url'), Env::t('email'),
e4fb72eb
SJ
1491 (Env::t('NAF_code') == 0 ? null : Env::t('NAF_code')),
1492 (Env::i('AX_code') == 0 ? null : Env::t('AX_code')),
1493 (Env::i('holdingId') == 0 ? null : Env::t('holdingId')), $id);
4d336f59 1494
0b6c8b36
SJ
1495 $phone = new Phone(array('display' => Env::v('tel'), 'link_id' => $id, 'id' => 0, 'type' => 'fixed',
1496 'link_type' => Phone::LINK_COMPANY, 'pub' => 'public'));
1497 $fax = new Phone(array('display' => Env::v('fax'), 'link_id' => $id, 'id' => 1, 'type' => 'fax',
1498 'link_type' => Phone::LINK_COMPANY, 'pub' => 'public'));
c32bed90 1499 $address = new Address(array('jobid' => $id, 'type' => Address::LINK_COMPANY, 'text' => Env::t('address')));
0b6c8b36
SJ
1500 $phone->save();
1501 $fax->save();
a710dfd7 1502 $address->save();
63596a65 1503
4d336f59
SJ
1504 $page->trigSuccess("L'entreprise a bien été mise à jour.");
1505 }
1506 }
1507
1508 if (!Env::has('change') && $id != -1) {
63596a65
SJ
1509 $res = XDB::query("SELECT e.id, e.name, e.acronym, e.url, e.email, e.NAF_code, e.AX_code,
1510 h.id AS holdingId, h.name AS holdingName, h.acronym AS holdingAcronym,
1511 t.display_tel AS tel, f.display_tel AS fax, a.text AS address
1512 FROM profile_job_enum AS e
1513 LEFT JOIN profile_job_enum AS h ON (e.holdingid = h.id)
9483a7c7
SJ
1514 LEFT JOIN profile_phones AS t ON (t.pid = e.id AND t.link_type = 'hq' AND t.tel_id = 0)
1515 LEFT JOIN profile_phones AS f ON (f.pid = e.id AND f.link_type = 'hq' AND f.tel_id = 1)
63596a65
SJ
1516 LEFT JOIN profile_addresses AS a ON (a.jobid = e.id AND a.type = 'hq')
1517 WHERE e.id = {?}",
4d336f59
SJ
1518 $id);
1519
1520 if ($res->numRows() == 0) {
1521 $page->trigError('Auncune entreprise ne correspond à cet identifiant.');
1522 } else {
1523 $page->assign('selectedJob', $res->fetchOneAssoc());
1524 }
1525 }
1526 }
4d5946ac
SJ
1527
1528 function handler_profile(&$page)
1529 {
1530 $page->changeTpl('admin/profile.tpl');
1531
1532 if (Post::has('checked')) {
1533 S::assert_xsrf_token();
1534 $res = XDB::iterator('SELECT DISTINCT(pm.pid), pd.public_name
1535 FROM profile_modifications AS pm
1536 INNER JOIN profile_display AS pd ON (pm.pid = pd.pid)
1537 WHERE pm.type = \'self\'');
1538
1539 while ($profile = $res->next()) {
1540 if (Post::has('checked_' . $profile['pid'])) {
1541 XDB::execute('DELETE FROM profile_modifications
1542 WHERE type = \'self\' AND pid = {?}', $profile['pid']);
1543
1544 $page->trigSuccess('Profil de ' . $profile['public_name'] . ' vérifié.');
1545 }
1546 }
1547 }
1548
1549 $res = XDB::iterator('SELECT p.hrpid, pm.pid, pd.directory_name, GROUP_CONCAT(pm.field SEPARATOR \', \') AS field
1550 FROM profile_modifications AS pm
1551 INNER JOIN profiles AS p ON (pm.pid = p.pid)
1552 INNER JOIN profile_display AS pd ON (pm.pid = pd.pid)
1553 WHERE pm.type = \'self\'
1554 GROUP BY pd.directory_name
1555 ORDER BY pd.directory_name');
1556 $page->assign('updates', $res);
1557 }
86f0a6af 1558}
1559
a7de4ef7 1560// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
86f0a6af 1561?>