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