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