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