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