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