Commit | Line | Data |
---|---|---|
86f0a6af | 1 | <?php |
2 | /*************************************************************************** | |
fc34b3d1 | 3 | * Copyright (C) 2003-2011 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( | |
bfe9f4c7 | 27 | 'phpinfo' => $this->make_hook('phpinfo', AUTH_PASSWD, 'admin'), |
93e38398 | 28 | 'get_rights' => $this->make_hook('get_rights', AUTH_COOKIE, 'admin'), |
b47cc6f0 | 29 | 'set_skin' => $this->make_hook('set_skin', AUTH_COOKIE, 'admin'), |
bfe9f4c7 SJ |
30 | 'admin' => $this->make_hook('default', AUTH_PASSWD, 'admin'), |
31 | 'admin/dead-but-active' => $this->make_hook('dead_but_active', AUTH_PASSWD, 'admin'), | |
32 | 'admin/deaths' => $this->make_hook('deaths', AUTH_PASSWD, 'admin'), | |
33 | 'admin/downtime' => $this->make_hook('downtime', AUTH_PASSWD, 'admin'), | |
34 | 'admin/homonyms' => $this->make_hook('homonyms', AUTH_PASSWD, 'admin'), | |
35 | 'admin/logger' => $this->make_hook('logger', AUTH_PASSWD, 'admin'), | |
36 | 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_PASSWD, 'admin'), | |
37 | 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_PASSWD, 'admin'), | |
38 | 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_PASSWD, 'admin'), | |
39 | 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_PASSWD, 'admin'), | |
40 | 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_PASSWD, 'admin'), | |
41 | 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_PASSWD, 'admin'), | |
42 | 'admin/skins' => $this->make_hook('skins', AUTH_PASSWD, 'admin'), | |
43 | 'admin/user' => $this->make_hook('user', AUTH_PASSWD, 'admin'), | |
44 | 'admin/add_accounts' => $this->make_hook('add_accounts', AUTH_PASSWD, 'admin'), | |
45 | 'admin/validate' => $this->make_hook('validate', AUTH_PASSWD, 'admin,edit_directory'), | |
46 | 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_PASSWD, 'admin'), | |
47 | 'admin/wiki' => $this->make_hook('wiki', AUTH_PASSWD, 'admin'), | |
48 | 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_PASSWD, 'admin'), | |
49 | 'admin/icons' => $this->make_hook('icons', AUTH_PASSWD, 'admin'), | |
50 | 'admin/geocoding' => $this->make_hook('geocoding', AUTH_PASSWD, 'admin'), | |
51 | 'admin/accounts' => $this->make_hook('accounts', AUTH_PASSWD, 'admin'), | |
52 | 'admin/account/watch' => $this->make_hook('account_watch', AUTH_PASSWD, 'admin'), | |
53 | 'admin/account/types' => $this->make_hook('account_types', AUTH_PASSWD, 'admin'), | |
54 | 'admin/xnet_without_group' => $this->make_hook('xnet_without_group', AUTH_PASSWD, 'admin'), | |
55 | 'admin/jobs' => $this->make_hook('jobs', AUTH_PASSWD, 'admin,edit_directory'), | |
56 | 'admin/profile' => $this->make_hook('profile', AUTH_PASSWD, 'admin,edit_directory'), | |
57 | 'admin/phd' => $this->make_hook('phd', AUTH_PASSWD, 'admin'), | |
58 | 'admin/add_secondary_edu' => $this->make_hook('add_secondary_edu', AUTH_PASSWD, 'admin') | |
86f0a6af | 59 | ); |
60 | } | |
61 | ||
26ba053e | 62 | function handler_phpinfo($page) |
5f9a40b4 | 63 | { |
64 | phpinfo(); | |
65 | exit; | |
66 | } | |
67 | ||
26ba053e | 68 | function handler_get_rights($page) |
866bd535 FB |
69 | { |
70 | if (S::suid()) { | |
71 | $page->kill('Déjà en SUID'); | |
72 | } | |
20b087ff FB |
73 | S::assert_xsrf_token(); |
74 | $level = Post::s('account_type'); | |
75 | if ($level != 'admin') { | |
76 | $user = User::getSilentWithUID(S::user()->id()); | |
77 | $user->is_admin = false; | |
78 | $types = DirEnum::getOptions(DirEnum::ACCOUNTTYPES); | |
79 | if (!empty($types[$level])) { | |
80 | $user->setPerms($types[$level]); | |
81 | } | |
82 | S::set('suid_startpage', $_SERVER['HTTP_REFERER']); | |
83 | Platal::session()->startSUID($user); | |
84 | } | |
85 | if (!empty($_SERVER['HTTP_REFERER'])) { | |
86 | http_redirect($_SERVER['HTTP_REFERER']); | |
87 | } else { | |
88 | pl_redirect('/'); | |
89 | } | |
866bd535 FB |
90 | } |
91 | ||
26ba053e | 92 | function handler_set_skin($page) |
b47cc6f0 FB |
93 | { |
94 | S::assert_xsrf_token(); | |
95 | S::set('skin', Post::s('change_skin')); | |
96 | if (!empty($_SERVER['HTTP_REFERER'])) { | |
97 | http_redirect($_SERVER['HTTP_REFERER']); | |
98 | } else { | |
99 | pl_redirect('/'); | |
100 | } | |
101 | } | |
102 | ||
26ba053e | 103 | function handler_default($page) |
86f0a6af | 104 | { |
105 | $page->changeTpl('admin/index.tpl'); | |
46f272fe | 106 | $page->setTitle('Administration'); |
86f0a6af | 107 | } |
108 | ||
26ba053e | 109 | function handler_postfix_delayed($page) |
86f0a6af | 110 | { |
111 | $page->changeTpl('admin/postfix_delayed.tpl'); | |
46f272fe | 112 | $page->setTitle('Administration - Postfix : Retardés'); |
86f0a6af | 113 | |
114 | if (Env::has('del')) { | |
115 | $crc = Env::v('crc'); | |
116 | XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc); | |
6bb2f79a | 117 | $page->trigSuccess($crc . " verra tous ses emails supprimés !"); |
86f0a6af | 118 | } elseif (Env::has('ok')) { |
119 | $crc = Env::v('crc'); | |
120 | XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc); | |
6bb2f79a | 121 | $page->trigSuccess($crc . " a le droit de passer !"); |
86f0a6af | 122 | } |
123 | ||
124 | $sql = XDB::iterator( | |
125 | "SELECT crc, nb, update_time, create_time, | |
77fcaa3f SJ |
126 | FIND_IN_SET('del', p.release) AS del, |
127 | FIND_IN_SET('ok', p.release) AS ok | |
128 | FROM postfix_mailseen AS p | |
86f0a6af | 129 | WHERE nb >= 30 |
77fcaa3f | 130 | ORDER BY p.release != ''"); |
86f0a6af | 131 | |
132 | $page->assign_by_ref('mails', $sql); | |
133 | } | |
86f0a6af | 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 | ||
26ba053e | 284 | function handler_logger($page, $action = null, $arg = null) { |
441e9e98 | 285 | if ($action == 'session') { |
286 | ||
287 | // we are viewing a session | |
bdbda592 | 288 | $res = XDB::query("SELECT ls.*, a.hruid AS username, sa.hruid AS suer |
6586a74f | 289 | FROM log_sessions AS ls |
bdbda592 FB |
290 | INNER JOIN accounts AS a ON (a.uid = ls.uid) |
291 | LEFT JOIN accounts AS sa ON (sa.uid = ls.suid) | |
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 | ||
c8ab90e7 | 304 | } else { |
441e9e98 | 305 | $loguser = $action == 'user' ? $arg : Env::v('loguser'); |
c8ab90e7 RB |
306 | |
307 | if ($loguser) { | |
308 | $user = User::get($loguser); | |
309 | $loguid = $user->id(); | |
310 | } else { | |
311 | $loguid = null; | |
312 | } | |
441e9e98 | 313 | |
314 | if ($loguid) { | |
315 | $year = Env::i('year'); | |
316 | $month = Env::i('month'); | |
317 | $day = Env::i('day'); | |
318 | } else { | |
319 | $year = Env::i('year', intval(date('Y'))); | |
320 | $month = Env::i('month', intval(date('m'))); | |
321 | $day = Env::i('day', intval(date('d'))); | |
322 | } | |
323 | ||
324 | if (!$year) | |
325 | $month = 0; | |
326 | if (!$month) | |
327 | $day = 0; | |
328 | ||
329 | // smarty assignments | |
330 | // retrieve available years | |
331 | $page->assign('years', $this->_getYears()); | |
332 | $page->assign('year', $year); | |
333 | ||
334 | // retrieve available months for the current year | |
335 | $page->assign('months', $this->_getMonths($year)); | |
336 | $page->assign('month', $month); | |
337 | ||
338 | // retrieve available days for the current year and month | |
339 | $page->assign('days', $this->_getDays($year, $month)); | |
340 | $page->assign('day', $day); | |
341 | ||
342 | $page->assign('loguser', $loguser); | |
343 | // smarty assignments | |
344 | ||
345 | if ($loguid || $year) { | |
346 | ||
347 | // get the requested sessions | |
348 | $where = $this->_makeWhere($year, $month, $day, $loguid); | |
504ccd57 | 349 | $select = "SELECT s.id, s.start, s.uid, |
bdbda592 | 350 | a.hruid as username |
6586a74f | 351 | FROM log_sessions AS s |
bdbda592 | 352 | INNER JOIN accounts AS a ON (a.uid = s.uid) |
441e9e98 | 353 | $where |
354 | ORDER BY start DESC"; | |
355 | $res = XDB::iterator($select); | |
356 | ||
357 | $sessions = array(); | |
358 | while ($mysess = $res->next()) { | |
359 | $mysess['events'] = array(); | |
360 | $sessions[$mysess['id']] = $mysess; | |
361 | } | |
362 | array_reverse($sessions); | |
363 | ||
364 | // attach events | |
365 | $sql = "SELECT s.id, a.text | |
6586a74f FB |
366 | FROM log_sessions AS s |
367 | LEFT JOIN log_events AS e ON(e.session=s.id) | |
368 | INNER JOIN log_actions AS a ON(a.id=e.action) | |
441e9e98 | 369 | $where"; |
370 | ||
371 | $res = XDB::iterator($sql); | |
372 | while ($event = $res->next()) { | |
373 | array_push($sessions[$event['id']]['events'], $event['text']); | |
374 | } | |
375 | $page->assign_by_ref('sessions', $sessions); | |
376 | } else { | |
c8ab90e7 | 377 | $page->assign('msg_nofilters', "Sélectionner une année et/ou un utilisateur"); |
441e9e98 | 378 | } |
86f0a6af | 379 | } |
380 | ||
8b1f8e12 | 381 | $page->changeTpl('admin/logger-view.tpl'); |
86f0a6af | 382 | |
46f272fe | 383 | $page->setTitle('Administration - Logs des sessions'); |
86f0a6af | 384 | } |
385 | ||
26ba053e | 386 | function handler_user($page, $login = false) |
f97f90f0 | 387 | { |
84270653 | 388 | global $globals; |
1412adb2 | 389 | $page->changeTpl('admin/user.tpl'); |
f9743cf1 | 390 | $page->setTitle('Administration - Compte'); |
86f0a6af | 391 | |
0c02607e | 392 | if (S::suid()) { |
6bb2f79a | 393 | $page->kill("Déjà en SUID !!!"); |
86f0a6af | 394 | } |
395 | ||
d5fbeef6 | 396 | // Loads the user identity using the environment. |
1ac65dd4 PC |
397 | if ($login) { |
398 | $user = User::get($login); | |
399 | } | |
400 | if (empty($user)) { | |
8338711c | 401 | pl_redirect('admin/accounts'); |
2ff7e020 VZ |
402 | } |
403 | ||
a8a11a70 | 404 | $listClient = new MMList(S::user()); |
4f903ea6 FB |
405 | $login = $user->login(); |
406 | $registered = ($user->state != 'pending'); | |
86f0a6af | 407 | |
4f903ea6 FB |
408 | // Form processing |
409 | if (!empty($_POST)) { | |
410 | S::assert_xsrf_token(); | |
411 | if (Post::has('uid') && Post::i('uid') != $user->id()) { | |
412 | $page->kill('Une erreur s\'est produite'); | |
413 | } | |
86f0a6af | 414 | } |
415 | ||
d5fbeef6 | 416 | // Handles specific requests (AX sync, su, ...). |
9bef113f | 417 | if(Post::has('log_account')) { |
d5fbeef6 | 418 | pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m')); |
86f0a6af | 419 | } |
420 | ||
a19178e9 | 421 | if(Post::has('su_account') && $registered) { |
866bd535 | 422 | if (!Platal::session()->startSUID($user)) { |
83752d10 | 423 | $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login()); |
f97f90f0 | 424 | } else { |
d5fbeef6 | 425 | pl_redirect(""); |
eaf30d86 | 426 | } |
d5fbeef6 | 427 | } |
86f0a6af | 428 | |
40965e32 SJ |
429 | // Handles account deletion. |
430 | if (Post::has('account_deletion_confirmation')) { | |
431 | $uid = $user->id(); | |
432 | $name = $user->fullName(); | |
4cd83ff8 | 433 | $profile = $user->profile(); |
879d38da | 434 | if ($profile && Post::b('clear_profile')) { |
4cd83ff8 FB |
435 | $user->profile()->clear(); |
436 | } | |
40965e32 | 437 | $user->clear(true); |
879d38da FB |
438 | $page->trigSuccess("L'utilisateur $name ($uid) a bien été désinscrit."); |
439 | if (Post::b('erase_account')) { | |
440 | XDB::execute('DELETE FROM accounts | |
441 | WHERE uid = {?}', | |
442 | $uid); | |
443 | $page->trigSuccess("L'utilisateur $name ($uid) a été supprimé de la base de données"); | |
444 | } | |
40965e32 SJ |
445 | } |
446 | ||
f9743cf1 | 447 | // Account Form {{{ |
ca6980dc | 448 | require_once 'emails.inc.php'; |
83752d10 | 449 | $to_update = array(); |
4f903ea6 | 450 | if (Post::has('disable_weak_access')) { |
83752d10 | 451 | $to_update['weak_password'] = null; |
4f903ea6 | 452 | } else if (Post::has('update_account')) { |
aef87266 | 453 | if (!$user->hasProfile()) { |
b7753795 SJ |
454 | $name_update = false; |
455 | if (Post::s('lastname') != $user->lastname) { | |
456 | $to_update['lastname'] = Post::s('lastname'); | |
457 | $name_update = true; | |
458 | } | |
459 | if (Post::s('type') != 'virtual' && Post::s('firstname') != $user->firstname) { | |
460 | $to_update['firstname'] = Post::s('firstname'); | |
461 | $name_update = true; | |
462 | } | |
463 | if ($name_update) { | |
464 | if (Post::s('type') != 'virtual') { | |
465 | $to_update['full_name'] = Post::s('firstname') . ' ' . Post::s('lastname'); | |
466 | $to_update['directory_name'] = mb_strtoupper(Post::s('lastname')) . ' ' . Post::s('firstname'); | |
467 | } else { | |
468 | $to_update['full_name'] = Post::s('lastname'); | |
469 | $to_update['directory_name'] = mb_strtoupper(Post::s('lastname')); | |
470 | } | |
aef87266 SJ |
471 | } |
472 | if (Post::s('display_name') != $user->displayName()) { | |
473 | $to_update['display_name'] = Post::s('display_name'); | |
474 | } | |
d081acb2 | 475 | } |
4f903ea6 FB |
476 | if (Post::s('sex') != ($user->isFemale() ? 'female' : 'male')) { |
477 | $to_update['sex'] = Post::s('sex'); | |
aef87266 SJ |
478 | if ($user->hasProfile()) { |
479 | XDB::execute('UPDATE profiles | |
480 | SET sex = {?} | |
481 | WHERE pid = {?}', | |
482 | Post::s('sex'), $user->profile()->id()); | |
483 | } | |
83752d10 | 484 | } |
2477a631 SJ |
485 | if (!Post::blank('pwhash')) { |
486 | $to_update['password'] = Post::s('pwhash'); | |
3168041b | 487 | require_once 'googleapps.inc.php'; |
1549059d VZ |
488 | $account = new GoogleAppsAccount($user); |
489 | if ($account->active() && $account->sync_password) { | |
2477a631 | 490 | $account->set_password(Post::s('pwhash')); |
1549059d | 491 | } |
83752d10 | 492 | } |
4f903ea6 FB |
493 | if (!Post::blank('weak_password')) { |
494 | $to_update['weak_password'] = Post::s('weak_password'); | |
83752d10 | 495 | } |
4f903ea6 FB |
496 | if (Post::i('token_access', 0) != ($user->token_access ? 1 : 0)) { |
497 | $to_update['token'] = Post::i('token_access') ? rand_url_id(16) : null; | |
83752d10 | 498 | } |
fcdbb3bf SJ |
499 | if (Post::i('skin') != $user->skin) { |
500 | $to_update['skin'] = Post::i('skin'); | |
83752d10 | 501 | if ($to_update['skin'] == 0) { |
7cfaf494 | 502 | $to_update['skin'] = null; |
83752d10 FB |
503 | } |
504 | } | |
4f903ea6 FB |
505 | if (Post::s('state') != $user->state) { |
506 | $to_update['state'] = Post::s('state'); | |
83752d10 | 507 | } |
4f903ea6 FB |
508 | if (Post::i('is_admin', 0) != ($user->is_admin ? 1 : 0)) { |
509 | $to_update['is_admin'] = Post::b('is_admin'); | |
83752d10 | 510 | } |
4f903ea6 FB |
511 | if (Post::s('type') != $user->type) { |
512 | $to_update['type'] = Post::s('type'); | |
83752d10 | 513 | } |
4f903ea6 | 514 | if (Post::i('watch', 0) != ($user->watch ? 1 : 0)) { |
83752d10 | 515 | $to_update['flags'] = new PlFlagset(); |
4f903ea6 | 516 | $to_update['flags']->addFlag('watch', Post::i('watch')); |
83752d10 | 517 | } |
4f903ea6 FB |
518 | if (Post::t('comment') != $user->comment) { |
519 | $to_update['comment'] = Post::blank('comment') ? null : Post::t('comment'); | |
83752d10 | 520 | } |
8a41e7f9 SJ |
521 | $new_email = strtolower(Post::t('email')); |
522 | if (require_email_update($user, $new_email)) { | |
523 | $to_update['email'] = $new_email; | |
524 | $listClient->change_user_email($user->forlifeEmail(), $new_email); | |
525 | update_alias_user($user->forlifeEmail(), $new_email); | |
a8a11a70 | 526 | } |
83752d10 FB |
527 | } |
528 | if (!empty($to_update)) { | |
01f78cbb SJ |
529 | $res = XDB::query('SELECT * |
530 | FROM accounts | |
531 | WHERE uid = {?}', $user->id()); | |
532 | $oldValues = $res->fetchAllAssoc(); | |
533 | $oldValues = $oldValues[0]; | |
534 | ||
83752d10 | 535 | $set = array(); |
01f78cbb | 536 | $diff = array(); |
83752d10 | 537 | foreach ($to_update as $k => $value) { |
01f78cbb SJ |
538 | $value = XDB::format('{?}', $value); |
539 | $set[] = $k . ' = ' . $value; | |
540 | $diff[$k] = array($oldValues[$k], trim($value, "'")); | |
541 | unset($oldValues[$k]); | |
83752d10 | 542 | } |
a8a11a70 FB |
543 | XDB::rawExecute('UPDATE accounts |
544 | SET ' . implode(', ', $set) . ' | |
545 | WHERE uid = ' . XDB::format('{?}', $user->id())); | |
83752d10 FB |
546 | $page->trigSuccess('Données du compte mise à jour avec succès'); |
547 | $user = User::getWithUID($user->id()); | |
01f78cbb SJ |
548 | |
549 | /* Formats the $diff and send it to the site administrators. The rules are the folowing: | |
550 | * -formats: password, token, weak_password | |
551 | */ | |
552 | foreach (array('password', 'token', 'weak_password') as $key) { | |
553 | if (isset($diff[$key])) { | |
554 | $diff[$key] = array('old value', 'new value'); | |
555 | } else { | |
556 | $oldValues[$key] = 'old value'; | |
557 | } | |
558 | } | |
559 | ||
560 | $mail = new PlMailer('admin/useredit.mail.tpl'); | |
561 | $mail->assign('admin', S::user()->hruid); | |
562 | $mail->assign('hruid', $user->hruid); | |
563 | $mail->assign('diff', $diff); | |
564 | $mail->assign('oldValues', $oldValues); | |
565 | $mail->send(); | |
83752d10 | 566 | } |
f9743cf1 | 567 | // }}} |
4f903ea6 | 568 | |
f9743cf1 | 569 | // Profile form {{{ |
4f903ea6 FB |
570 | if (Post::has('add_profile') || Post::has('del_profile') || Post::has('owner')) { |
571 | if (Post::i('del_profile', 0) != 0) { | |
f9743cf1 FB |
572 | XDB::execute('DELETE FROM account_profiles |
573 | WHERE uid = {?} AND pid = {?}', | |
4f903ea6 FB |
574 | $user->id(), Post::i('del_profile')); |
575 | } else if (!Post::blank('new_profile')) { | |
576 | $profile = Profile::get(Post::t('new_profile')); | |
f9743cf1 | 577 | if (!$profile) { |
4f903ea6 | 578 | $page->trigError('Le profil ' . Post::t('new_profile') . ' n\'existe pas'); |
f9743cf1 FB |
579 | } else { |
580 | XDB::execute('INSERT IGNORE INTO account_profiles (uid, pid) | |
581 | VALUES ({?}, {?})', | |
582 | $user->id(), $profile->id()); | |
583 | } | |
584 | } | |
585 | XDB::execute('UPDATE account_profiles | |
586 | SET perms = IF(pid = {?}, CONCAT(perms, \',owner\'), REPLACE(perms, \'owner\', \'\')) | |
587 | WHERE uid = {?}', | |
4f903ea6 | 588 | Post::i('owner'), $user->id()); |
f9743cf1 | 589 | } |
f9743cf1 FB |
590 | // }}} |
591 | ||
4f903ea6 | 592 | // Email forwards form {{{ |
4f903ea6 FB |
593 | $redirect = ($registered ? new Redirect($user) : null); |
594 | if (Post::has('add_fwd')) { | |
595 | $email = Post::t('email'); | |
f4dda5fb | 596 | if (!isvalid_email_redirection($email, $user)) { |
4f903ea6 FB |
597 | $page->trigError("Email non valide: $email"); |
598 | } else { | |
599 | $redirect->add_email($email); | |
600 | $page->trigSuccess("Ajout de $email effectué"); | |
601 | } | |
602 | } else if (!Post::blank('del_fwd')) { | |
603 | $redirect->delete_email(Post::t('del_fwd')); | |
604 | } else if (!Post::blank('activate_fwd')) { | |
afc337ee | 605 | $redirect->modify_one_email(Post::t('activate_fwd'), true); |
4f903ea6 | 606 | } else if (!Post::blank('deactivate_fwd')) { |
afc337ee | 607 | $redirect->modify_one_email(Post::t('deactivate_fwd'), false); |
4f903ea6 FB |
608 | } else if (Post::has('disable_fwd')) { |
609 | $redirect->disable(); | |
610 | } else if (Post::has('enable_fwd')) { | |
611 | $redirect->enable(); | |
612 | } else if (!Post::blank('clean_fwd')) { | |
613 | $redirect->clean_errors(Post::t('clean_fwd')); | |
614 | } | |
615 | // }}} | |
d5fbeef6 | 616 | |
4f903ea6 FB |
617 | // Email alias form {{{ |
618 | if (Post::has('add_alias')) { | |
619 | // Splits new alias in user and fqdn. | |
620 | $alias = Env::t('email'); | |
621 | if (strpos($alias, '@') !== false) { | |
622 | list($alias, $domain) = explode('@', $alias); | |
623 | } else { | |
f036c896 | 624 | $domain = $user->mainEmailDomain(); |
4f903ea6 | 625 | } |
84270653 | 626 | |
4f903ea6 FB |
627 | // Checks for alias' user validity. |
628 | if (!preg_match('/[-a-z0-9\.]+/s', $alias)) { | |
629 | $page->trigError("'$alias' n'est pas un alias valide"); | |
630 | } | |
86f0a6af | 631 | |
4f903ea6 FB |
632 | // Eventually adds the alias to the right domain. |
633 | if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) { | |
634 | $req = new AliasReq($user, $alias, 'Admin request', false); | |
635 | if ($req->commit()) { | |
b284e2fa | 636 | $page->trigSuccess("Nouvel alias '$alias@$domain' attribué."); |
4f903ea6 | 637 | } else { |
b284e2fa | 638 | $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué."); |
4f903ea6 | 639 | } |
f036c896 | 640 | } elseif ($domain == $user->mainEmailDomain()) { |
b284e2fa | 641 | XDB::execute('INSERT INTO email_source_account (email, uid, domain, type, flags) |
f036c896 | 642 | SELECT {?}, {?}, id, \'alias\', \'\' |
b284e2fa SJ |
643 | FROM email_virtual_domains |
644 | WHERE name = {?}', | |
f036c896 | 645 | $alias, $user->id(), $domain); |
4f903ea6 FB |
646 | $page->trigSuccess("Nouvel alias '$alias' ajouté"); |
647 | } else { | |
f036c896 | 648 | $page->trigError("Le domaine '$domain' n'est pas valide pour cet utilisateur."); |
4f903ea6 FB |
649 | } |
650 | } else if (!Post::blank('del_alias')) { | |
b284e2fa SJ |
651 | $delete_alias = Post::t('del_alias'); |
652 | list($email, $domain) = explode('@', $delete_alias); | |
653 | XDB::execute('DELETE s | |
654 | FROM email_source_account AS s | |
655 | INNER JOIN email_virtual_domains AS m ON (s.domain = m.id) | |
656 | INNER JOIN email_virtual_domains AS d ON (d.aliasing = m.id) | |
f036c896 | 657 | WHERE s.email = {?} AND s.uid = {?} AND d.name = {?} AND type != \'forlife\'', |
b284e2fa SJ |
658 | $email, $user->id(), $domain); |
659 | XDB::execute('UPDATE email_redirect_account AS r | |
660 | INNER JOIN email_virtual_domains AS m ON (m.name = {?}) | |
661 | INNER JOIN email_virtual_domains AS d ON (d.aliasing = m.id) | |
662 | SET r.rewrite = \'\' | |
663 | WHERE r.uid = {?} AND r.rewrite = CONCAT({?}, \'@\', d.name)', | |
664 | $domain, $user->id(), $email); | |
4f903ea6 | 665 | fix_bestalias($user); |
b284e2fa | 666 | $page->trigSuccess("L'alias '$delete_alias' a été supprimé"); |
4f903ea6 | 667 | } else if (!Post::blank('best')) { |
b284e2fa SJ |
668 | $best_alias = Post::t('best'); |
669 | // First delete the bestalias flag from all this user's emails. | |
670 | XDB::execute("UPDATE email_source_account | |
4f903ea6 | 671 | SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ',')) |
fe13bc1d | 672 | WHERE uid = {?}", $user->id()); |
b284e2fa SJ |
673 | // Then gives the bestalias flag to the given email. |
674 | list($email, $domain) = explode('@', $best_alias); | |
f067a3d6 SJ |
675 | XDB::execute("UPDATE email_source_account |
676 | SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias') | |
677 | WHERE uid = {?} AND email = {?}", $user->id(), $email); | |
b284e2fa | 678 | |
4f903ea6 FB |
679 | // As having a non-null bestalias value is critical in |
680 | // plat/al's code, we do an a posteriori check on the | |
681 | // validity of the bestalias. | |
682 | fix_bestalias($user); | |
683 | } | |
684 | // }}} | |
669cb0e0 | 685 | |
83353c71 FB |
686 | // OpenId form {{{ |
687 | if (Post::has('del_openid')) { | |
864957c1 | 688 | XDB::execute('DELETE FROM account_auth_openid |
83353c71 FB |
689 | WHERE id = {?}', Post::i('del_openid')); |
690 | } | |
691 | // }}} | |
692 | ||
4f903ea6 FB |
693 | // Forum form {{{ |
694 | if (Post::has('b_edit')) { | |
695 | XDB::execute("DELETE FROM forum_innd | |
696 | WHERE uid = {?}", $user->id()); | |
697 | if (Env::v('write_perm') != "" || Env::v('read_perm') != "" || Env::v('commentaire') != "" ) { | |
698 | XDB::execute("INSERT INTO forum_innd | |
699 | SET ipmin = '0', ipmax = '4294967295', | |
700 | write_perm = {?}, read_perm = {?}, | |
701 | comment = {?}, priority = '200', uid = {?}", | |
702 | Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $user->id()); | |
703 | } | |
704 | } | |
705 | // }}} | |
86f0a6af | 706 | |
86f0a6af | 707 | |
b7bad73e | 708 | $page->addJsLink('jquery.ui.xorg.js'); |
669cb0e0 | 709 | |
d5fbeef6 VZ |
710 | // Displays last login and last host information. |
711 | $res = XDB::query("SELECT start, host | |
6586a74f | 712 | FROM log_sessions |
d5fbeef6 VZ |
713 | WHERE uid = {?} AND suid = 0 |
714 | ORDER BY start DESC | |
715 | LIMIT 1", $user->id()); | |
716 | list($lastlogin,$host) = $res->fetchOneRow(); | |
717 | $page->assign('lastlogin', $lastlogin); | |
718 | $page->assign('host', $host); | |
719 | ||
1d889ac4 | 720 | // Display mailing lists |
a8a11a70 | 721 | $page->assign('mlists', $listClient->get_all_user_lists($user->forlifeEmail())); |
1d889ac4 | 722 | |
d5fbeef6 | 723 | // Display active aliases. |
06a548e5 | 724 | $page->assign('virtuals', $user->emailGroupAliases()); |
b284e2fa SJ |
725 | $aliases = XDB::iterator("SELECT CONCAT(s.email, '@', d.name) AS email, (s.type = 'forlife') AS forlife, |
726 | (s.email REGEXP '\\\\.[0-9]{2}$') AS hundred_year, | |
727 | FIND_IN_SET('bestalias', s.flags) AS bestalias, s.expire, | |
08d33afc | 728 | (s.type = 'alias_aux') AS alias |
b284e2fa SJ |
729 | FROM email_source_account AS s |
730 | INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) | |
731 | WHERE s.uid = {?} | |
732 | ORDER BY !alias, s.email", | |
08d33afc | 733 | $user->id()); |
b284e2fa | 734 | $page->assign('aliases', $aliases); |
8f2104cb FB |
735 | $page->assign('account_types', XDB::iterator('SELECT * FROM account_types ORDER BY type')); |
736 | $page->assign('skins', XDB::iterator('SELECT id, name FROM skins ORDER BY name')); | |
f9743cf1 FB |
737 | $page->assign('profiles', XDB::iterator('SELECT p.pid, p.hrpid, FIND_IN_SET(\'owner\', ap.perms) AS owner |
738 | FROM account_profiles AS ap | |
739 | INNER JOIN profiles AS p ON (ap.pid = p.pid) | |
740 | WHERE ap.uid = {?}', $user->id())); | |
83353c71 | 741 | $page->assign('openid', XDB::iterator('SELECT id, url |
864957c1 FB |
742 | FROM account_auth_openid |
743 | WHERE uid = {?}', $user->id())); | |
d5fbeef6 VZ |
744 | |
745 | // Displays email redirection and the general profile. | |
746 | if ($registered && $redirect) { | |
747 | $page->assign('emails', $redirect->emails); | |
748 | } | |
749 | ||
d5fbeef6 | 750 | $page->assign('user', $user); |
aef87266 | 751 | $page->assign('hasProfile', $user->hasProfile()); |
d5fbeef6 VZ |
752 | |
753 | // Displays forum bans. | |
754 | $res = XDB::query("SELECT write_perm, read_perm, comment | |
7d15f750 | 755 | FROM forum_innd |
d5fbeef6 VZ |
756 | WHERE uid = {?}", $user->id()); |
757 | $bans = $res->fetchOneAssoc(); | |
758 | $page->assign('bans', $bans); | |
86f0a6af | 759 | } |
1f53925a | 760 | |
e02d9fbb | 761 | private static function getHrid($firstname, $lastname, $promo) |
7c5200a5 | 762 | { |
e02d9fbb | 763 | if ($firstname != null && $lastname != null && $promo != null) { |
69fc05dd | 764 | return User::makeHrid($firstname, $lastname, $promo); |
7c5200a5 | 765 | } |
f6eacab0 | 766 | return null; |
7c5200a5 VZ |
767 | } |
768 | ||
26ba053e | 769 | private static function formatNewUser($page, $infosLine, $separator, $promo, $size) |
1f53925a | 770 | { |
e02d9fbb | 771 | $infos = explode($separator, $infosLine); |
cb0c8b1c SJ |
772 | if (sizeof($infos) > $size || sizeof($infos) < 2) { |
773 | $page->trigError("La ligne $infosLine n'a pas été ajoutée."); | |
e02d9fbb | 774 | return false; |
1f53925a | 775 | } |
776 | ||
16714428 | 777 | $infos = array_map('trim', $infos); |
e02d9fbb SJ |
778 | $hrid = self::getHrid($infos[1], $infos[0], $promo); |
779 | $res1 = XDB::query('SELECT COUNT(*) | |
780 | FROM accounts | |
781 | WHERE hruid = {?}', $hrid); | |
782 | $res2 = XDB::query('SELECT COUNT(*) | |
783 | FROM profiles | |
784 | WHERE hrpid = {?}', $hrid); | |
785 | if (is_null($hrid) || $res1->fetchOneCell() > 0 || $res2->fetchOneCell() > 0) { | |
981fce7b | 786 | $page->trigError("La ligne $infosLine n'a pas été ajoutée: une entrée similaire existe déjà"); |
e02d9fbb SJ |
787 | return false; |
788 | } | |
789 | $infos['hrid'] = $hrid; | |
790 | return $infos; | |
791 | } | |
792 | ||
26ba053e | 793 | private static function formatSex($page, $sex, $line) |
e02d9fbb SJ |
794 | { |
795 | switch ($sex) { | |
796 | case 'F': | |
f0a52f1b | 797 | return 'female'; |
e02d9fbb | 798 | case 'M': |
f0a52f1b | 799 | return 'male'; |
e02d9fbb SJ |
800 | default: |
801 | $page->trigError("La ligne $line n'a pas été ajoutée car le sexe $sex n'est pas pris en compte."); | |
802 | return null; | |
1f53925a | 803 | } |
e02d9fbb | 804 | } |
1f53925a | 805 | |
e02d9fbb SJ |
806 | private static function formatBirthDate($birthDate) |
807 | { | |
16714428 RB |
808 | // strtotime believes dd/mm/yyyy to be an US date (i.e mm/dd/yyyy), and |
809 | // dd-mm-yyyy to be a normal date (i.e dd-mm-yyyy)... | |
810 | return date("Y-m-d", strtotime(str_replace('/', '-', $birthDate))); | |
e02d9fbb SJ |
811 | } |
812 | ||
26ba053e | 813 | function handler_add_accounts($page, $action = null, $promo = null) |
e02d9fbb SJ |
814 | { |
815 | $page->changeTpl('admin/add_accounts.tpl'); | |
816 | ||
817 | if (Env::has('add_type') && Env::has('people')) { | |
89aba52d | 818 | static $titles = array('male' => 'M', 'female' => 'MLLE'); |
e02d9fbb SJ |
819 | $lines = explode("\n", Env::t('people')); |
820 | $separator = Env::t('separator'); | |
821 | $promotion = Env::i('promotion'); | |
e02d9fbb SJ |
822 | |
823 | if (Env::t('add_type') == 'promo') { | |
94590511 | 824 | $eduSchools = DirEnum::getOptions(DirEnum::EDUSCHOOLS); |
e02d9fbb | 825 | $eduSchools = array_flip($eduSchools); |
94590511 | 826 | $eduDegrees = DirEnum::getOptions(DirEnum::EDUDEGREES); |
e02d9fbb | 827 | $eduDegrees = array_flip($eduDegrees); |
e02d9fbb SJ |
828 | switch (Env::t('edu_type')) { |
829 | case 'X': | |
830 | $degreeid = $eduDegrees[Profile::DEGREE_X]; | |
831 | $entry_year = $promotion; | |
832 | $grad_year = $promotion + 3; | |
833 | $promo = 'X' . $promotion; | |
d9e99995 | 834 | $hrpromo = $promotion; |
f0a52f1b | 835 | $type = 'x'; |
e02d9fbb SJ |
836 | break; |
837 | case 'M': | |
838 | $degreeid = $eduDegrees[Profile::DEGREE_M]; | |
839 | $grad_year = $promotion; | |
840 | $entry_year = $promotion - 2; | |
841 | $promo = 'M' . $promotion; | |
d9e99995 FB |
842 | $hrpromo = $promo; |
843 | $type = 'master'; | |
e02d9fbb SJ |
844 | break; |
845 | case 'D': | |
846 | $degreeid = $eduDegrees[Profile::DEGREE_D]; | |
847 | $grad_year = $promotion; | |
848 | $entry_year = $promotion - 3; | |
d60d2d1f | 849 | $promo = 'D (en cours)'; |
0768c6d7 | 850 | $hrpromo = 'D' . $promotion; |
d9e99995 | 851 | $type = 'phd'; |
e02d9fbb SJ |
852 | break; |
853 | default: | |
d60d2d1f | 854 | $page->killError("La formation n'est pas reconnue : " . Env::t('edu_type') . '.'); |
e02d9fbb SJ |
855 | } |
856 | ||
7f55b0d6 | 857 | XDB::startTransaction(); |
e02d9fbb | 858 | foreach ($lines as $line) { |
d9e99995 | 859 | if ($infos = self::formatNewUser($page, $line, $separator, $hrpromo, 6)) { |
cb0c8b1c SJ |
860 | $sex = self::formatSex($page, $infos[3], $line); |
861 | if (!is_null($sex)) { | |
4452750b SJ |
862 | $fullName = $infos[1] . ' ' . $infos[0]; |
863 | $directoryName = $infos[0] . ' ' . $infos[1]; | |
cb0c8b1c | 864 | $birthDate = self::formatBirthDate($infos[2]); |
f0a52f1b SJ |
865 | if ($type == 'x') { |
866 | $xorgId = Profile::getXorgId($infos[4]); | |
2209fb9c | 867 | } elseif (isset($infos[4])) { |
f0a52f1b | 868 | $xorgId = trim($infos[4]); |
2209fb9c SJ |
869 | } else { |
870 | $xorgId = 0; | |
f0a52f1b | 871 | } |
cb0c8b1c SJ |
872 | if (is_null($xorgId)) { |
873 | $page->trigError("La ligne $line n'a pas été ajoutée car le matricule École est mal renseigné."); | |
874 | continue; | |
875 | } | |
876 | ||
89aba52d SJ |
877 | XDB::execute('INSERT INTO profiles (hrpid, xorg_id, ax_id, birthdate_ref, sex, title) |
878 | VALUES ({?}, {?}, {?}, {?}, {?}, {?})', | |
879 | $infos['hrid'], $xorgId, (isset($infos[5]) ? $infos[5] : null), | |
880 | $birthDate, $sex, $titles[$sex]); | |
cb0c8b1c | 881 | $pid = XDB::insertId(); |
0e1dfbad SJ |
882 | XDB::execute('INSERT INTO profile_public_names (pid, lastname_initial, lastname_main, firstname_initial, firstname_main) |
883 | VALUES ({?}, {?}, {?}, {?}, {?})', | |
884 | $pid, $infos[0], $infos[0], $infos[1], $infos[1]); | |
cb0c8b1c SJ |
885 | XDB::execute('INSERT INTO profile_display (pid, yourself, public_name, private_name, |
886 | directory_name, short_name, sort_name, promo) | |
887 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', | |
4452750b | 888 | $pid, $infos[1], $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo); |
7733ade1 SJ |
889 | XDB::execute('INSERT INTO profile_education (id, pid, eduid, degreeid, entry_year, grad_year, promo_year, flags) |
890 | VALUES (100, {?}, {?}, {?}, {?}, {?}, {?}, \'primary\')', | |
891 | $pid, $eduSchools[Profile::EDU_X], $degreeid, $entry_year, $grad_year, $promotion); | |
6b6e4ff2 SJ |
892 | XDB::execute('INSERT INTO accounts (hruid, type, is_admin, state, full_name, directory_name, |
893 | display_name, lastname, firstname, sex) | |
894 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', | |
895 | $infos['hrid'], $type, 0, 'pending', $fullName, $directoryName, | |
896 | $infos[1], $infos[0], $infos[1], $sex); | |
cb0c8b1c SJ |
897 | $uid = XDB::insertId(); |
898 | XDB::execute('INSERT INTO account_profiles (uid, pid, perms) | |
899 | VALUES ({?}, {?}, {?})', | |
900 | $uid, $pid, 'owner'); | |
bedc4295 | 901 | Profile::rebuildSearchTokens($pid, false); |
cb0c8b1c | 902 | } |
e02d9fbb SJ |
903 | } |
904 | } | |
7f55b0d6 | 905 | XDB::commit(); |
e02d9fbb SJ |
906 | } else if (Env::t('add_type') == 'account') { |
907 | $type = Env::t('type'); | |
4029afb0 | 908 | $newAccounts = array(); |
e02d9fbb | 909 | foreach ($lines as $line) { |
cb0c8b1c SJ |
910 | if ($infos = self::formatNewUser($page, $line, $separator, $type, 4)) { |
911 | $sex = self::formatSex($page, $infos[3], $line); | |
912 | if (!is_null($sex)) { | |
4452750b SJ |
913 | $fullName = $infos[1] . ' ' . $infos[0]; |
914 | $directoryName = $infos[0] . ' ' . $infos[1]; | |
6b6e4ff2 SJ |
915 | XDB::execute('INSERT INTO accounts (hruid, type, is_admin, state, email, full_name, directory_name, |
916 | display_name, lastname, firstname, sex) | |
917 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', | |
918 | $infos['hrid'], $type, 0, 'pending', $infos[2], $fullName, $directoryName, | |
919 | $infos[1], $infos[0], $infos[1], $sex); | |
4029afb0 | 920 | $newAccounts[$infos['hrid']] = $infos[1] . ' ' . $infos[0]; |
cb0c8b1c | 921 | } |
e02d9fbb SJ |
922 | } |
923 | } | |
4029afb0 SJ |
924 | if (!empty($newAccounts)) { |
925 | $page->assign('newAccounts', $newAccounts); | |
926 | } | |
e02d9fbb SJ |
927 | } else if (Env::t('add_type') == 'ax_id') { |
928 | $type = 'x'; | |
929 | foreach ($lines as $line) { | |
cb0c8b1c | 930 | if ($infos = self::formatNewUser($page, $line, $separator, $promotion, 3)) { |
e02d9fbb SJ |
931 | XDB::execute('UPDATE profiles |
932 | SET ax_id = {?} | |
933 | WHERE hrpid = {?}', | |
934 | $infos[2], $infos['hrid']); | |
935 | } | |
936 | } | |
937 | } | |
938 | ||
cb0c8b1c SJ |
939 | $errors = $page->nb_errs(); |
940 | if ($errors == 0) { | |
e02d9fbb SJ |
941 | $page->trigSuccess("L'opération a été effectuée avec succès."); |
942 | } else { | |
cb0c8b1c SJ |
943 | $page->trigSuccess('L\'opération a été effectuée avec succès, sauf pour ' |
944 | . (($errors == 1) ? 'l\'erreur signalée' : "les $errors erreurs signalées") . ' ci-dessus.'); | |
e02d9fbb SJ |
945 | } |
946 | } else if (Env::has('add_type')) { | |
947 | $res = XDB::query('SELECT type | |
948 | FROM account_types'); | |
949 | $page->assign('account_types', $res->fetchColumn()); | |
950 | $page->assign('add_type', Env::s('add_type')); | |
1f53925a | 951 | } |
1f53925a | 952 | } |
953 | ||
26ba053e | 954 | function handler_homonyms($page, $op = 'list', $target = null) |
7c5200a5 | 955 | { |
86f0a6af | 956 | $page->changeTpl('admin/homonymes.tpl'); |
46f272fe | 957 | $page->setTitle('Administration - Homonymes'); |
191711d5 | 958 | $this->load("homonyms.inc.php"); |
74c55fd6 | 959 | |
86f0a6af | 960 | if ($target) { |
4371e993 SJ |
961 | $user = User::getSilentWithUID($target); |
962 | if (!$user || !($loginbis = select_if_homonym($user))) { | |
191711d5 | 963 | $target = 0; |
86f0a6af | 964 | } else { |
191711d5 | 965 | $page->assign('user', $user); |
86f0a6af | 966 | $page->assign('loginbis',$loginbis); |
967 | } | |
968 | } | |
74c55fd6 | 969 | |
839a80cf VZ |
970 | $page->assign('op', $op); |
971 | $page->assign('target', $target); | |
74c55fd6 | 972 | |
4371e993 | 973 | // When we have a valid target, prepare emails. |
86f0a6af | 974 | if ($target) { |
4371e993 | 975 | // Examine what operation needs to be performed. |
86f0a6af | 976 | switch ($op) { |
977 | case 'mail': | |
40d428d8 VZ |
978 | S::assert_xsrf_token(); |
979 | ||
da2fff38 | 980 | send_warning_homonym($user, $loginbis); |
86f0a6af | 981 | $op = 'list'; |
191711d5 | 982 | $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.'); |
86f0a6af | 983 | break; |
839a80cf | 984 | |
86f0a6af | 985 | case 'correct': |
40d428d8 VZ |
986 | S::assert_xsrf_token(); |
987 | ||
da2fff38 SJ |
988 | fix_homonym($user, $loginbis); |
989 | send_robot_homonym($user, $loginbis); | |
86f0a6af | 990 | $op = 'list'; |
191711d5 | 991 | $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.'); |
86f0a6af | 992 | break; |
993 | } | |
994 | } | |
74c55fd6 | 995 | |
86f0a6af | 996 | if ($op == 'list') { |
4371e993 SJ |
997 | // Retrieves homonyms that are already been fixed. |
998 | $res = XDB::iterator('SELECT o.email AS homonym, f.email AS forlife, o.expire, f.uid | |
999 | FROM email_source_other AS o | |
1000 | INNER JOIN homonyms_list AS h ON (o.hrmid = h.hrmid) | |
1001 | INNER JOIN email_source_account AS f ON (h.uid = f.uid AND f.type = \'forlife\') | |
f036c896 SJ |
1002 | WHERE o.expire IS NOT NULL |
1003 | ORDER BY homonym, forlife'); | |
4371e993 SJ |
1004 | $homonyms = array(); |
1005 | while ($item = $res->next()) { | |
1006 | $homonyms[$item['homonym']][] = $item; | |
1007 | } | |
1008 | $page->assign_by_ref('homonyms', $homonyms); | |
1009 | ||
1010 | // Retrieves homonyms that needs to be fixed. | |
1011 | $res = XDB::iterator('SELECT e.email AS homonym, f.email AS forlife, e.expire, e.uid, (e.expire < NOW()) AS urgent | |
1012 | FROM email_source_account AS e | |
1013 | INNER JOIN homonyms_list AS l ON (e.uid = l.uid) | |
1014 | INNER JOIN homonyms_list AS h ON (l.hrmid = h.hrmid) | |
1015 | INNER JOIN email_source_account AS f ON (h.uid = f.uid AND f.type = \'forlife\') | |
f036c896 SJ |
1016 | WHERE e.expire IS NOT NULL |
1017 | ORDER BY homonym, forlife'); | |
4371e993 SJ |
1018 | $homonyms_to_fix = array(); |
1019 | while ($item = $res->next()) { | |
1020 | $homonyms_to_fix[$item['homonym']][] = $item; | |
1021 | } | |
1022 | $page->assign_by_ref('homonyms_to_fix', $homonyms_to_fix); | |
86f0a6af | 1023 | } |
da2fff38 SJ |
1024 | |
1025 | if ($op == 'correct-conf') { | |
1026 | $page->assign('robot_mail_text', get_robot_mail_text($user, $loginbis)); | |
1027 | } | |
1028 | ||
1029 | if ($op == 'mail-conf') { | |
1030 | $page->assign('warning_mail_text', get_warning_mail_text($user, $loginbis)); | |
1031 | } | |
86f0a6af | 1032 | } |
74c55fd6 | 1033 | |
26ba053e | 1034 | function handler_deaths($page, $promo = 0, $validate = false) |
32b3ac78 | 1035 | { |
86f0a6af | 1036 | $page->changeTpl('admin/deces_promo.tpl'); |
46f272fe | 1037 | $page->setTitle('Administration - Deces'); |
74c55fd6 | 1038 | |
dcefa8f7 FB |
1039 | if (!$promo) { |
1040 | $promo = Env::t('promo', 'X1923'); | |
1041 | } | |
1042 | $page->assign('promo', $promo); | |
1043 | if (!$promo) { | |
1044 | return; | |
1045 | } | |
74c55fd6 | 1046 | |
40d428d8 VZ |
1047 | if ($validate) { |
1048 | S::assert_xsrf_token(); | |
1049 | ||
f198bf30 | 1050 | $res = XDB::iterRow('SELECT p.pid, pd.directory_name, p.deathdate |
dcefa8f7 FB |
1051 | FROM profiles AS p |
1052 | INNER JOIN profile_display AS pd ON (p.pid = pd.pid) | |
1053 | WHERE pd.promo = {?}', $promo); | |
1054 | while (list($pid, $name, $death) = $res->next()) { | |
f198bf30 | 1055 | $val = Env::v('death_' . $pid); |
71497fb8 | 1056 | if ($val == $death) { |
e61326ed VZ |
1057 | continue; |
1058 | } | |
1059 | ||
71497fb8 SJ |
1060 | if (empty($val)) { |
1061 | $val = null; | |
1062 | } | |
dcefa8f7 FB |
1063 | XDB::execute('UPDATE profiles |
1064 | SET deathdate = {?}, deathdate_rec = NOW() | |
f198bf30 | 1065 | WHERE pid = {?}', $val, $pid); |
71497fb8 SJ |
1066 | |
1067 | $page->trigSuccess('Édition du décès de ' . $name . ' (' . ($val ? $val : 'ressuscité') . ').'); | |
1068 | if ($val && ($death == '0000-00-00' || empty($death))) { | |
438b7a0c | 1069 | $profile = Profile::get($pid); |
6150f591 SJ |
1070 | $profile->clear(); |
1071 | $profile->owner()->clear(false); | |
e61326ed | 1072 | } |
86f0a6af | 1073 | } |
86f0a6af | 1074 | } |
74c55fd6 | 1075 | |
f198bf30 | 1076 | $res = XDB::iterator('SELECT p.pid, pd.directory_name, p.deathdate |
dcefa8f7 FB |
1077 | FROM profiles AS p |
1078 | INNER JOIN profile_display AS pd ON (p.pid = pd.pid) | |
1079 | WHERE pd.promo = {?} | |
1080 | ORDER BY pd.sort_name', $promo); | |
71497fb8 | 1081 | $page->assign('profileList', $res); |
86f0a6af | 1082 | } |
74c55fd6 | 1083 | |
26ba053e | 1084 | function handler_dead_but_active($page) |
32b3ac78 | 1085 | { |
1c48c2a9 | 1086 | $page->changeTpl('admin/dead_but_active.tpl'); |
46f272fe | 1087 | $page->setTitle('Administration - Décédés'); |
1c48c2a9 VZ |
1088 | |
1089 | $res = XDB::iterator( | |
e46cf8c4 | 1090 | "SELECT a.hruid, pd.promo, p.ax_id, pd.directory_name, p.deathdate, DATE(MAX(s.start)) AS last |
fe13bc1d FB |
1091 | FROM accounts AS a |
1092 | INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms)) | |
1093 | INNER JOIN profiles AS p ON (p.pid = ap.pid) | |
1094 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
6586a74f | 1095 | LEFT JOIN log_sessions AS s ON (s.uid = a.uid AND suid = 0) |
e46cf8c4 | 1096 | WHERE a.state = 'active' AND p.deathdate IS NOT NULL |
dcefa8f7 | 1097 | GROUP BY a.uid |
e46cf8c4 | 1098 | ORDER BY pd.promo, pd.sort_name"); |
1c48c2a9 VZ |
1099 | $page->assign('dead', $res); |
1100 | } | |
1101 | ||
26ba053e | 1102 | function handler_validate($page, $action = 'list', $id = null) |
e654517d | 1103 | { |
764b894d | 1104 | $page->changeTpl('admin/validation.tpl'); |
46f272fe | 1105 | $page->setTitle('Administration - Valider une demande'); |
84163d58 | 1106 | $page->addCssLink('nl.Polytechnique.org.css'); |
e654517d | 1107 | |
5b8c317d | 1108 | if ($action == 'edit' && !is_null($id)) { |
ed5b9703 | 1109 | $page->assign('preview_id', $id); |
5b8c317d SJ |
1110 | } else { |
1111 | $page->assign('preview_id', null); | |
ed5b9703 | 1112 | } |
1113 | ||
86f0a6af | 1114 | if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { |
40d428d8 VZ |
1115 | S::assert_xsrf_token(); |
1116 | ||
20d7932b | 1117 | $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); |
343e22c2 FB |
1118 | if ($req) { |
1119 | $req->handle_formu(); | |
1120 | } else { | |
1121 | $page->trigWarning('La validation a déjà été effectuée.'); | |
1122 | } | |
86f0a6af | 1123 | } |
74c55fd6 | 1124 | |
cfb96867 | 1125 | $r = XDB::iterator('SHOW COLUMNS FROM requests_answers'); |
1126 | while (($a = $r->next()) && $a['Field'] != 'category'); | |
1127 | $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1)))); | |
74c55fd6 | 1128 | |
cfb96867 | 1129 | $hidden = array(); |
257ae408 SJ |
1130 | $res = XDB::query('SELECT hidden_requests |
1131 | FROM requests_hidden | |
1132 | WHERE uid = {?}', S::v('uid')); | |
e0d7c076 | 1133 | $hide_requests = $res->fetchOneCell(); |
cfb96867 | 1134 | if (Post::has('hide')) { |
74c55fd6 | 1135 | $hide = array(); |
1136 | foreach ($categories as $cat) | |
cfb96867 | 1137 | if (!Post::v($cat)) { |
1138 | $hidden[$cat] = 1; | |
1139 | $hide[] = $cat; | |
1140 | } | |
e0d7c076 | 1141 | $hide_requests = join(',', $hide); |
00ba8a74 SJ |
1142 | XDB::query('INSERT INTO requests_hidden (uid, hidden_requests) |
1143 | VALUES ({?}, {?}) | |
1144 | ON DUPLICATE KEY UPDATE hidden_requests = VALUES(hidden_requests)', | |
e0d7c076 SJ |
1145 | S::v('uid'), $hide_requests); |
1146 | } elseif ($hide_requests) { | |
1147 | foreach (explode(',', $hide_requests) as $hide_type) | |
cfb96867 | 1148 | $hidden[$hide_type] = true; |
1149 | } | |
1150 | $page->assign('hide_requests', $hidden); | |
74c55fd6 | 1151 | |
90df2530 FB |
1152 | // Update the count of item to validate here... useful in development configuration |
1153 | // where several copies of the site use the same DB, but not the same "dynamic configuration" | |
ebfdf077 FB |
1154 | global $globals; |
1155 | $globals->updateNbValid(); | |
7b094a73 | 1156 | $page->assign('vit', Validate::iterate()); |
e33b29e5 | 1157 | $page->assign('isAdmin', S::admin()); |
86f0a6af | 1158 | } |
e654517d | 1159 | |
26ba053e | 1160 | function handler_validate_answers($page, $action = 'list', $id = null) |
32b3ac78 | 1161 | { |
46f272fe | 1162 | $page->setTitle('Administration - Réponses automatiques de validation'); |
a7de4ef7 | 1163 | $page->assign('title', 'Gestion des réponses automatiques'); |
e18888f4 | 1164 | $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id'); |
a7de4ef7 | 1165 | $table_editor->describe('category','catégorie',true); |
e18888f4 | 1166 | $table_editor->describe('title','titre',true); |
47f51789 | 1167 | $table_editor->describe('answer','texte',false, true); |
e18888f4 | 1168 | $table_editor->apply($page, $action, $id); |
1169 | } | |
32b3ac78 | 1170 | |
26ba053e | 1171 | function handler_skins($page, $action = 'list', $id = null) |
32b3ac78 | 1172 | { |
46f272fe | 1173 | $page->setTitle('Administration - Skins'); |
e7ae7df9 | 1174 | $page->assign('title', 'Gestion des skins'); |
1175 | $table_editor = new PLTableEditor('admin/skins','skins','id'); | |
1176 | $table_editor->describe('name','nom',true); | |
1177 | $table_editor->describe('skin_tpl','nom du template',true); | |
47f51789 | 1178 | $table_editor->describe('auteur','auteur',false, true); |
e7ae7df9 | 1179 | $table_editor->describe('comment','commentaire',true); |
47f51789 RB |
1180 | $table_editor->describe('date','date',false, true); |
1181 | $table_editor->describe('ext','extension du screenshot',false, true); | |
e7ae7df9 | 1182 | $table_editor->apply($page, $action, $id); |
74c55fd6 | 1183 | } |
669cb0e0 | 1184 | |
26ba053e | 1185 | function handler_postfix_blacklist($page, $action = 'list', $id = null) |
32b3ac78 | 1186 | { |
46f272fe | 1187 | $page->setTitle('Administration - Postfix : Blacklist'); |
e7ae7df9 | 1188 | $page->assign('title', 'Blacklist de postfix'); |
1189 | $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); | |
1190 | $table_editor->describe('reject_text','Texte de rejet',true); | |
1191 | $table_editor->describe('email','email',true); | |
1192 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 1193 | } |
32b3ac78 | 1194 | |
26ba053e | 1195 | function handler_postfix_whitelist($page, $action = 'list', $id = null) |
32b3ac78 | 1196 | { |
46f272fe | 1197 | $page->setTitle('Administration - Postfix : Whitelist'); |
e7ae7df9 | 1198 | $page->assign('title', 'Whitelist de postfix'); |
1199 | $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true); | |
1200 | $table_editor->describe('email','email',true); | |
1201 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 1202 | } |
32b3ac78 | 1203 | |
26ba053e | 1204 | function handler_mx_broken($page, $action = 'list', $id = null) |
32b3ac78 | 1205 | { |
46f272fe | 1206 | $page->setTitle('Administration - MX Défaillants'); |
a7de4ef7 | 1207 | $page->assign('title', 'MX Défaillant'); |
ccdbc270 | 1208 | $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true); |
1209 | $table_editor->describe('host', 'Masque', true); | |
1210 | $table_editor->describe('state', 'Niveau', true); | |
47f51789 | 1211 | $table_editor->describe('text', 'Description du problème', false, true); |
ccdbc270 | 1212 | $table_editor->apply($page, $action, $id); |
1213 | } | |
32b3ac78 | 1214 | |
26ba053e | 1215 | function handler_logger_actions($page, $action = 'list', $id = null) |
32b3ac78 | 1216 | { |
46f272fe | 1217 | $page->setTitle('Administration - Actions'); |
e7ae7df9 | 1218 | $page->assign('title', 'Gestion des actions de logger'); |
6586a74f | 1219 | $table_editor = new PLTableEditor('admin/logger/actions','log_actions','id'); |
a7de4ef7 | 1220 | $table_editor->describe('text','intitulé',true); |
e7ae7df9 | 1221 | $table_editor->describe('description','description',true); |
1222 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 1223 | } |
32b3ac78 | 1224 | |
26ba053e | 1225 | function handler_downtime($page, $action = 'list', $id = null) |
8f2104cb | 1226 | { |
46f272fe | 1227 | $page->setTitle('Administration - Coupures'); |
e7ae7df9 | 1228 | $page->assign('title', 'Gestion des coupures'); |
06f4daf9 | 1229 | $table_editor = new PLTableEditor('admin/downtime','downtimes','id'); |
e7ae7df9 | 1230 | $table_editor->describe('debut','date',true); |
47f51789 | 1231 | $table_editor->describe('duree','durée',false, true); |
a7de4ef7 | 1232 | $table_editor->describe('resume','résumé',true); |
1233 | $table_editor->describe('services','services affectés',true); | |
47f51789 | 1234 | $table_editor->describe('description','description',false, true); |
e7ae7df9 | 1235 | $table_editor->apply($page, $action, $id); |
74c55fd6 | 1236 | } |
bc0903c7 | 1237 | |
a7fada4f SJ |
1238 | private static function isCountryIncomplete(array &$item) |
1239 | { | |
1240 | $warning = false; | |
1241 | foreach (array('worldRegion', 'country', 'capital', 'phonePrefix', 'licensePlate', 'countryPlain') as $field) { | |
1242 | if ($item[$field] == '') { | |
1243 | $item[$field . '_warning'] = true; | |
1244 | $warning = true; | |
1245 | } | |
1246 | } | |
1247 | if (is_null($item['belongsTo'])) { | |
1248 | foreach (array('nationality', 'nationalityEn') as $field) { | |
1249 | if ($item[$field] == '') { | |
1250 | $item[$field . '_warning'] = true; | |
1251 | $warning = true; | |
1252 | } | |
1253 | } | |
1254 | } | |
1255 | return $warning; | |
1256 | } | |
1257 | ||
846bfc83 SJ |
1258 | private static function updateCountry(array $item) |
1259 | { | |
1260 | XDB::execute('UPDATE geoloc_countries | |
1261 | SET countryPlain = {?} | |
1262 | WHERE iso_3166_1_a2 = {?}', | |
1263 | mb_strtoupper(replace_accent($item['country'])), $item['iso_3166_1_a2']); | |
1264 | } | |
1265 | ||
a7fada4f SJ |
1266 | private static function isLanguageIncomplete(array &$item) |
1267 | { | |
1268 | if ($item['language'] == '') { | |
1269 | $item['language_warning'] = true; | |
1270 | return true; | |
1271 | } | |
1272 | return false; | |
1273 | } | |
1274 | ||
846bfc83 SJ |
1275 | private static function updateLanguage(array $item) {} |
1276 | ||
2a1cd4ab | 1277 | function handler_geocoding($page, $category = null, $action = null, $id = null) |
a7fada4f SJ |
1278 | { |
1279 | // Warning, this handler requires the following packages: | |
1280 | // * pkg-isocodes | |
1281 | // * isoquery | |
1282 | ||
1283 | static $properties = array( | |
1284 | 'country' => array( | |
1285 | 'name' => 'pays', | |
1286 | 'isocode' => '3166', | |
1287 | 'table' => 'geoloc_countries', | |
1288 | 'id' => 'iso_3166_1_a2', | |
1289 | 'main_fields' => array('iso_3166_1_a3', 'iso_3166_1_num', 'countryEn'), | |
1290 | 'other_fields' => array('worldRegion', 'country', 'capital', 'nationality', 'nationalityEn', | |
846bfc83 | 1291 | 'phonePrefix', 'phoneFormat', 'licensePlate', 'belongsTo') |
a7fada4f SJ |
1292 | ), |
1293 | 'language' => array( | |
1294 | 'name' => 'langages', | |
1295 | 'isocode' => '639', | |
1296 | 'table' => 'profile_langskill_enum', | |
1297 | 'id' => 'iso_639_2b', | |
1298 | 'main_fields' => array('iso_639_2t', 'iso_639_1', 'language_en'), | |
1299 | 'other_fields' => array('language') | |
1300 | ||
1301 | ) | |
1302 | ); | |
a7fada4f | 1303 | |
846bfc83 | 1304 | if (is_null($category) || !array_key_exists($category, $properties)) { |
a7fada4f SJ |
1305 | pl_redirect('admin'); |
1306 | } | |
1307 | ||
846bfc83 SJ |
1308 | $data = $properties[$category]; |
1309 | ||
1310 | if ($action == 'edit' || $action == 'add') { | |
1311 | $main_fields = array_merge(array($data['id']), $data['main_fields']); | |
1312 | $all_fields = array_merge($main_fields, $data['other_fields']); | |
1313 | ||
1314 | if (is_null($id)) { | |
1315 | if (Post::has('new_id')) { | |
1316 | $id = Post::v('new_id'); | |
1317 | } else { | |
1318 | pl_redirect('admin/geocoding/' . $category); | |
1319 | } | |
1320 | } | |
1321 | ||
1322 | $list = array(); | |
1323 | exec('isoquery --iso=' . $data['isocode'] . ' ' . $id, $list); | |
1324 | if (count($list) == 1) { | |
1325 | $array = explode("\t", $list[0]); | |
1326 | foreach ($main_fields as $i => $field) { | |
1327 | $iso[$field] = $array[$i]; | |
1328 | } | |
1329 | } else { | |
1330 | $iso = array(); | |
1331 | } | |
1332 | ||
1333 | if ($action == 'add') { | |
1334 | if (Post::has('new_id')) { | |
1335 | S::assert_xsrf_token(); | |
1336 | } | |
1337 | ||
1338 | if (count($iso)) { | |
1339 | $item = $iso; | |
1340 | } else { | |
1341 | $item = array($data['id'] => $id); | |
1342 | } | |
1343 | XDB::execute('INSERT INTO ' . $data['table'] . '(' . implode(', ', array_keys($item)) . ') | |
1344 | VALUES ' . XDB::formatArray($item)); | |
1345 | $page->trigSuccess($id . ' a bien été ajouté à la base.'); | |
1346 | } elseif ($action == 'edit') { | |
1347 | if (Post::has('edit')) { | |
1348 | S::assert_xsrf_token(); | |
1349 | ||
1350 | $item = array(); | |
1351 | $set = array(); | |
1352 | foreach ($all_fields as $field) { | |
1353 | $item[$field] = Post::t($field); | |
1354 | $set[] = $field . XDB::format(' = {?}', ($item[$field] ? $item[$field] : null)); | |
1355 | } | |
1356 | XDB::execute('UPDATE ' . $data['table'] . ' | |
1357 | SET ' . implode(', ', $set) . ' | |
1358 | WHERE ' . $data['id'] . ' = {?}', | |
1359 | $id); | |
1360 | call_user_func_array(array('self', 'update' . ucfirst($category)), array($item)); | |
1361 | $page->trigSuccess($id . ' a bien été mis à jour.'); | |
1362 | } elseif (Post::has('del')) { | |
1363 | S::assert_xsrf_token(); | |
1364 | ||
1365 | XDB::execute('DELETE FROM ' . $data['table'] . ' | |
1366 | WHERE ' . $data['id'] . ' = {?}', | |
1367 | $id); | |
1368 | $page->trigSuccessRedirect($id . ' a bien été supprimé.', 'admin/geocoding/' . $category); | |
1369 | } else { | |
1370 | $item = XDB::fetchOneAssoc('SELECT * | |
1371 | FROM ' . $data['table'] . ' | |
1372 | WHERE ' . $data['id'] . ' = {?}', | |
1373 | $id); | |
1374 | } | |
1375 | } | |
1376 | ||
1377 | $page->changeTpl('admin/geocoding_edit.tpl'); | |
1378 | $page->setTitle('Administration - ' . ucfirst($data['name'])); | |
1379 | $page->assign('category', $category); | |
1380 | $page->assign('name', $data['name']); | |
1381 | $page->assign('all_fields', $all_fields); | |
1382 | $page->assign('id', $id); | |
1383 | $page->assign('iso', $iso); | |
1384 | $page->assign('item', $item); | |
1385 | return; | |
1386 | } | |
a7fada4f SJ |
1387 | |
1388 | $page->changeTpl('admin/geocoding.tpl'); | |
1389 | $page->setTitle('Administration - ' . ucfirst($data['name'])); | |
846bfc83 | 1390 | $page->assign('category', $category); |
a7fada4f SJ |
1391 | $page->assign('name', $data['name']); |
1392 | $page->assign('id', $data['id']); | |
1393 | $page->assign('main_fields', $data['main_fields']); | |
1394 | $page->assign('all_fields', array_merge($data['main_fields'], $data['other_fields'])); | |
1395 | ||
1396 | // First build the list provided by the iso codes. | |
1397 | $list = array(); | |
1398 | exec('isoquery --iso=' . $data['isocode'], $list); | |
1399 | ||
1400 | foreach ($list as $key => $item) { | |
1401 | $array = explode("\t", $item); | |
1402 | unset($list[$key]); | |
1403 | $list[$array[0]] = array(); | |
1404 | foreach ($data['main_fields'] as $i => $field) { | |
1405 | $list[$array[0]][$field] = $array[$i + 1]; | |
1406 | } | |
1407 | } | |
1408 | ksort($list); | |
1409 | ||
1410 | // Retrieve all data from the database. | |
1411 | $db_list = XDB::rawFetchAllAssoc('SELECT * | |
1412 | FROM ' . $data['table'] . ' | |
1413 | ORDER BY ' . $data['id'], | |
1414 | $data['id']); | |
1415 | ||
1416 | // Sort both iso and database data into 5 categories: | |
1417 | // $missing: data from the iso list not in the database, | |
1418 | // $non_existing: data from the database not in the iso list, | |
1419 | // $erroneous: data that differ on main fields, | |
1420 | // $incomplete: data with empty fields in the data base, | |
1421 | // $remaining: remaining correct and complete data from the database. | |
1422 | ||
1423 | $missing = $non_existing = $erroneous = $incomplete = $remaining = array(); | |
1424 | foreach (array_keys($list) as $id) { | |
1425 | if (!array_key_exists($id, $db_list)) { | |
1426 | $missing[$id] = $list[$id]; | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | foreach ($db_list as $id => $item) { | |
1431 | if (!array_key_exists($id, $list)) { | |
1432 | $non_existing[$id] = $item; | |
1433 | } else { | |
1434 | $error = false; | |
1435 | foreach ($data['main_fields'] as $field) { | |
1436 | if ($item[$field] != $list[$id][$field]) { | |
1437 | $item[$field . '_error'] = true; | |
1438 | $error = true; | |
1439 | } | |
1440 | } | |
1441 | if ($error == true) { | |
1442 | $erroneous[$id] = $item; | |
846bfc83 | 1443 | } elseif (call_user_func_array(array('self', 'is' . ucfirst($category) . 'Incomplete'), array(&$item))) { |
a7fada4f SJ |
1444 | $incomplete[$id] = $item; |
1445 | } else { | |
1446 | $remaining[$id] = $item; | |
1447 | } | |
1448 | } | |
1449 | } | |
1450 | ||
1451 | $page->assign('lists', array( | |
1452 | 'manquant' => $missing, | |
1453 | 'disparu' => $non_existing, | |
1454 | 'erroné' => $erroneous, | |
1455 | 'incomplet' => $incomplete, | |
1456 | 'restant' => $remaining | |
1457 | )); | |
1458 | } | |
1459 | ||
8338711c FB |
1460 | function handler_accounts(PlPage $page) |
1461 | { | |
1462 | $page->changeTpl('admin/accounts.tpl'); | |
1463 | $page->setTitle('Administration - Comptes'); | |
8338711c FB |
1464 | |
1465 | if (Post::has('create_account')) { | |
1466 | S::assert_xsrf_token(); | |
1467 | $firstname = Post::t('firstname'); | |
6b6e4ff2 | 1468 | $lastname = mb_strtoupper(Post::t('lastname')); |
e8c61abe | 1469 | $sex = Post::s('sex'); |
8338711c | 1470 | $email = Post::t('email'); |
67cff520 FB |
1471 | $type = Post::s('type'); |
1472 | $login = PlUser::makeHrid($firstname, $lastname, $type); | |
8338711c FB |
1473 | if (!isvalid_email($email)) { |
1474 | $page->trigError("Invalid email address: $email"); | |
1475 | } else if (strlen(Post::s('pwhash')) != 40) { | |
1476 | $page->trigError("Invalid password hash"); | |
1477 | } else { | |
1478 | $full_name = $firstname . ' ' . $lastname; | |
1479 | $directory_name = $lastname . ' ' . $firstname; | |
1480 | XDB::execute("INSERT INTO accounts (hruid, type, state, password, | |
1481 | registration_date, email, full_name, | |
6b6e4ff2 SJ |
1482 | display_name, sex, directory_name, |
1483 | lastname, firstname) | |
1484 | VALUES ({?}, {?}, 'active', {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
67cff520 | 1485 | $login, $type, Post::s('pwhash'), $email, $full_name, $full_name, $sex, |
6b6e4ff2 | 1486 | $directory_name, $lastname, $firstname); |
8338711c FB |
1487 | } |
1488 | } | |
1489 | ||
67cff520 FB |
1490 | $uf = new UserFilter(new UFC_AccountType('ax', 'school', 'fx')); |
1491 | $page->assign('users', $uf->iterUsers()); | |
8338711c FB |
1492 | |
1493 | } | |
1494 | ||
26ba053e | 1495 | function handler_account_types($page, $action = 'list', $id = null) |
8f2104cb FB |
1496 | { |
1497 | $page->setTitle('Administration - Types de comptes'); | |
1498 | $page->assign('title', 'Gestion des types de comptes'); | |
1499 | $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true); | |
1500 | $table_editor->describe('type', 'Catégorie', true); | |
1501 | $table_editor->describe('perms', 'Permissions associées', true); | |
1502 | $table_editor->apply($page, $action, $id); | |
1503 | } | |
1504 | ||
26ba053e | 1505 | function handler_wiki($page, $action = 'list', $wikipage = null, $wikipage2 = null) |
bc0903c7 | 1506 | { |
84fc72ff | 1507 | if (S::hasAuthToken()) { |
a2b461ce | 1508 | $page->setRssLink('Changement Récents', |
2ab3486b | 1509 | '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::user()->token); |
a2b461ce | 1510 | } |
e61326ed | 1511 | |
3aec1c21 | 1512 | // update wiki perms |
40d428d8 VZ |
1513 | if ($action == 'update') { |
1514 | S::assert_xsrf_token(); | |
1515 | ||
3aec1c21 | 1516 | $perms_read = Post::v('read'); |
8f201b69 | 1517 | $perms_edit = Post::v('edit'); |
3aec1c21 | 1518 | if ($perms_read || $perms_edit) { |
8f201b69 FB |
1519 | foreach ($_POST as $wiki_page => $val) { |
1520 | if ($val == 'on') { | |
1521 | $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page)); | |
1522 | if ($wp->setPerms($perms_read ? $perms_read : $wp->readPerms(), | |
1523 | $perms_edit ? $perms_edit : $wp->writePerms())) { | |
1524 | $page->trigSuccess("Permission de la page $wiki_page mises à jour"); | |
1525 | } else { | |
1526 | $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour"); | |
1527 | } | |
1528 | } | |
3aec1c21 | 1529 | } |
1530 | } | |
8f201b69 FB |
1531 | } else if ($action != 'list' && !empty($wikipage)) { |
1532 | $wp = new PlWikiPage($wikipage); | |
40d428d8 VZ |
1533 | S::assert_xsrf_token(); |
1534 | ||
8f201b69 FB |
1535 | if ($action == 'delete') { |
1536 | if ($wp->delete()) { | |
1537 | $page->trigSuccess("La page ".$wikipage." a été supprimée."); | |
1538 | } else { | |
1539 | $page->trigError("Impossible de supprimer la page ".$wikipage."."); | |
1540 | } | |
1541 | } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) { | |
1542 | if ($changedLinks = $wp->rename($wikipage2)) { | |
1543 | $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.'; | |
1544 | if (is_numeric($changedLinks)) { | |
1545 | $s .= $changedLinks.' lien'.(($changedLinks>1)?'s ont été modifiés.':' a été modifié.'); | |
1546 | } | |
1547 | $page->trigSuccess($s); | |
1548 | } else { | |
1549 | $page->trigError("Impossible de déplacer la page ".$wikipage); | |
9162f4ed | 1550 | } |
9162f4ed | 1551 | } |
1552 | } | |
74c55fd6 | 1553 | |
8f201b69 | 1554 | $perms = PlWikiPage::permOptions(); |
74c55fd6 | 1555 | |
3aec1c21 | 1556 | // list wiki pages and their perms |
8f201b69 | 1557 | $wiki_pages = PlWikiPage::listPages(); |
3aec1c21 | 1558 | ksort($wiki_pages); |
bc0903c7 | 1559 | $wiki_tree = array(); |
1560 | foreach ($wiki_pages as $file => $desc) { | |
1561 | list($cat, $name) = explode('.', $file); | |
1562 | if (!isset($wiki_tree[$cat])) { | |
1563 | $wiki_tree[$cat] = array(); | |
1564 | } | |
1565 | $wiki_tree[$cat][$name] = $desc; | |
1566 | } | |
1567 | ||
3aec1c21 | 1568 | $page->changeTpl('admin/wiki.tpl'); |
bc0903c7 | 1569 | $page->assign('wiki_pages', $wiki_tree); |
3aec1c21 | 1570 | $page->assign('perms_opts', $perms); |
1571 | } | |
5480a216 | 1572 | |
26ba053e | 1573 | function handler_ipwatch($page, $action = 'list', $ip = null) |
eaf30d86 | 1574 | { |
5480a216 | 1575 | $page->changeTpl('admin/ipwatcher.tpl'); |
eaf30d86 | 1576 | |
5480a216 | 1577 | $states = array('safe' => 'Ne pas surveiller', |
c339246f | 1578 | 'unsafe' => 'Surveiller les inscriptions', |
a7de4ef7 | 1579 | 'dangerous' => 'Surveiller tous les accès', |
5480a216 | 1580 | 'ban' => 'Bannir cette adresse'); |
1581 | $page->assign('states', $states); | |
1582 | ||
1583 | switch (Post::v('action')) { | |
e61326ed | 1584 | case 'create': |
5480a216 | 1585 | if (trim(Post::v('ipN')) != '') { |
40d428d8 | 1586 | S::assert_xsrf_token(); |
61c98f4b FB |
1587 | Xdb::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description) |
1588 | VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})', | |
1589 | ip_to_uint(trim(Post::v('ipN'))), ip_to_uint(trim(Post::v('maskN'))), | |
1590 | Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); | |
eaf30d86 PH |
1591 | }; |
1592 | break; | |
1593 | ||
e61326ed | 1594 | case 'edit': |
40d428d8 | 1595 | S::assert_xsrf_token(); |
eaf30d86 | 1596 | Xdb::execute('UPDATE ip_watch |
61c98f4b | 1597 | SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?} |
9797734d | 1598 | WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), |
61c98f4b | 1599 | ip_to_uint(Post::v('maskN')), ip_to_uint(Post::v('ipN'))); |
5480a216 | 1600 | break; |
eaf30d86 | 1601 | |
e61326ed | 1602 | default: |
5480a216 | 1603 | if ($action == 'delete' && !is_null($ip)) { |
40d428d8 VZ |
1604 | S::assert_xsrf_token(); |
1605 | Xdb::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip)); | |
5480a216 | 1606 | } |
1607 | } | |
1608 | if ($action != 'create' && $action != 'edit') { | |
1609 | $action = 'list'; | |
1610 | } | |
1611 | $page->assign('action', $action); | |
1612 | ||
1613 | if ($action == 'list') { | |
9797734d FB |
1614 | $sql = "SELECT w.ip, IF(s.ip IS NULL, |
1615 | IF(w.ip = s2.ip, s2.host, s2.forward_host), | |
1616 | IF(w.ip = s.ip, s.host, s.forward_host)), | |
32b3ac78 | 1617 | w.mask, w.detection, w.state, a.hruid |
fe13bc1d | 1618 | FROM ip_watch AS w |
6586a74f FB |
1619 | LEFT JOIN log_sessions AS s ON (s.ip = w.ip) |
1620 | LEFT JOIN log_sessions AS s2 ON (s2.forward_ip = w.ip) | |
fe13bc1d | 1621 | LEFT JOIN accounts AS a ON (a.uid = s.uid) |
32b3ac78 FB |
1622 | GROUP BY w.ip, a.hruid |
1623 | ORDER BY w.state, w.ip, a.hruid"; | |
5480a216 | 1624 | $it = Xdb::iterRow($sql); |
1625 | ||
1626 | $table = array(); | |
1627 | $props = array(); | |
90c614cd | 1628 | while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) { |
9797734d | 1629 | $ip = uint_to_ip($ip); |
61c98f4b | 1630 | $mask = uint_to_ip($mask); |
5480a216 | 1631 | if (count($props) == 0 || $props['ip'] != $ip) { |
1632 | if (count($props) > 0) { | |
1633 | $table[] = $props; | |
1634 | } | |
1635 | $props = array('ip' => $ip, | |
61c98f4b | 1636 | 'mask' => $mask, |
5480a216 | 1637 | 'host' => $host, |
1638 | 'detection' => $date, | |
1639 | 'state' => $state, | |
90c614cd | 1640 | 'users' => array($hruid)); |
5480a216 | 1641 | } else { |
90c614cd | 1642 | $props['users'][] = $hruid; |
5480a216 | 1643 | } |
1644 | } | |
1645 | if (count($props) > 0) { | |
1646 | $table[] = $props; | |
1647 | } | |
1648 | $page->assign('table', $table); | |
1649 | } elseif ($action == 'edit') { | |
61c98f4b | 1650 | $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask, |
32b3ac78 | 1651 | a1.hruid AS edit, a2.hruid AS hruid, s.host |
fe13bc1d FB |
1652 | FROM ip_watch AS w |
1653 | LEFT JOIN accounts AS a1 ON (a1.uid = w.uid) | |
6586a74f | 1654 | LEFT JOIN log_sessions AS s ON (w.ip = s.ip) |
fe13bc1d | 1655 | LEFT JOIN accounts AS a2 ON (a2.uid = s.uid) |
5480a216 | 1656 | WHERE w.ip = {?} |
32b3ac78 FB |
1657 | GROUP BY a2.hruid |
1658 | ORDER BY a2.hruid"; | |
9797734d | 1659 | $it = Xdb::iterRow($sql, ip_to_uint($ip)); |
5480a216 | 1660 | |
1661 | $props = array(); | |
90c614cd | 1662 | while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) { |
5480a216 | 1663 | if (count($props) == 0) { |
1664 | $props = array('ip' => $ip, | |
61c98f4b | 1665 | 'mask' => uint_to_ip($mask), |
5480a216 | 1666 | 'host' => $host, |
1667 | 'detection' => $detection, | |
1668 | 'state' => $state, | |
1669 | 'last' => $last, | |
1670 | 'description' => $description, | |
1671 | 'edit' => $edit, | |
90c614cd | 1672 | 'users' => array($hruid)); |
5480a216 | 1673 | } else { |
90c614cd | 1674 | $props['users'][] = $hruid; |
5480a216 | 1675 | } |
1676 | } | |
1677 | $page->assign('ip', $props); | |
1678 | } | |
1679 | } | |
eaf30d86 | 1680 | |
26ba053e | 1681 | function handler_icons($page) |
f141945d | 1682 | { |
1683 | $page->changeTpl('admin/icons.tpl'); | |
1684 | $dh = opendir('../htdocs/images/icons'); | |
1685 | if (!$dh) { | |
a7d35093 | 1686 | $page->trigError('Dossier des icones introuvables.'); |
f141945d | 1687 | } |
1688 | $icons = array(); | |
1689 | while (($file = readdir($dh)) !== false) { | |
1690 | if (strlen($file) > 4 && substr($file,-4) == '.gif') { | |
1691 | array_push($icons, substr($file, 0, -4)); | |
1692 | } | |
1693 | } | |
1694 | sort($icons); | |
1695 | $page->assign('icons', $icons); | |
04148a2c | 1696 | } |
fd1ce8c5 | 1697 | |
26ba053e | 1698 | function handler_account_watch($page) |
fd1ce8c5 FB |
1699 | { |
1700 | $page->changeTpl('admin/accounts.tpl'); | |
32b3ac78 FB |
1701 | $page->assign('disabled', XDB::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch, |
1702 | a.state = \'disabled\' AS disabled, a.comment | |
1703 | FROM accounts AS a | |
1704 | WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags) | |
1705 | ORDER BY a.hruid')); | |
1706 | $page->assign('admins', XDB::iterator('SELECT a.hruid | |
1707 | FROM accounts AS a | |
1708 | WHERE a.is_admin | |
1709 | ORDER BY a.hruid')); | |
fd1ce8c5 | 1710 | } |
4d336f59 | 1711 | |
d6efb578 SJ |
1712 | function handler_xnet_without_group($page) |
1713 | { | |
1714 | $page->changeTpl('admin/xnet_without_group.tpl'); | |
1715 | $page->assign('accounts', XDB::iterator('SELECT a.hruid, a.state | |
1716 | FROM accounts AS a | |
1717 | LEFT JOIN group_members AS m ON (a.uid = m.uid) | |
1718 | WHERE a.type = \'xnet\' AND m.uid IS NULL | |
1719 | ORDER BY a.state, a.hruid')); | |
1720 | } | |
1721 | ||
26ba053e | 1722 | function handler_jobs($page, $id = -1) |
4d336f59 SJ |
1723 | { |
1724 | $page->changeTpl('admin/jobs.tpl'); | |
1725 | ||
1726 | if (Env::has('search')) { | |
308bbdb0 SJ |
1727 | $res = XDB::query("SELECT id, name, acronym |
1728 | FROM profile_job_enum | |
1729 | WHERE name LIKE CONCAT('%', {?}, '%') OR acronym LIKE CONCAT('%', {?}, '%')", | |
4d336f59 SJ |
1730 | Env::t('job'), Env::t('job')); |
1731 | ||
1732 | if ($res->numRows() <= 20) { | |
1733 | $page->assign('jobs', $res->fetchAllAssoc()); | |
1734 | } else { | |
1735 | $page->trigError("Il y a trop d'entreprises correspondant à ton choix. Affine-le !"); | |
1736 | } | |
1737 | ||
1738 | $page->assign('askedJob', Env::v('job')); | |
1739 | return; | |
1740 | } | |
1741 | ||
1742 | if (Env::has('edit')) { | |
1743 | S::assert_xsrf_token(); | |
1744 | $selectedJob = Env::has('selectedJob'); | |
1745 | ||
0b6c8b36 | 1746 | Phone::deletePhones(0, Phone::LINK_COMPANY, $id); |
781a24bc | 1747 | Address::deleteAddresses(null, Address::LINK_COMPANY, $id); |
4d336f59 | 1748 | if (Env::has('change')) { |
e954a945 SJ |
1749 | if (Env::has('newJobId') && Env::i('newJobId') > 0) { |
1750 | XDB::execute('UPDATE profile_job | |
1751 | SET jobid = {?} | |
1752 | WHERE jobid = {?}', | |
1753 | Env::i('newJobId'), $id); | |
1754 | XDB::execute('DELETE FROM profile_job_enum | |
1755 | WHERE id = {?}', | |
1756 | $id); | |
1757 | ||
1758 | $page->trigSuccess("L'entreprise a bien été remplacée."); | |
1759 | } else { | |
1760 | $page->trigError("L'entreprise n'a pas été remplacée car l'identifiant fourni n'est pas valide."); | |
1761 | } | |
4d336f59 SJ |
1762 | } else { |
1763 | XDB::execute('UPDATE profile_job_enum | |
1764 | SET name = {?}, acronym = {?}, url = {?}, email = {?}, | |
1765 | NAF_code = {?}, AX_code = {?}, holdingid = {?} | |
1766 | WHERE id = {?}', | |
1767 | Env::t('name'), Env::t('acronym'), Env::t('url'), Env::t('email'), | |
e4fb72eb SJ |
1768 | (Env::t('NAF_code') == 0 ? null : Env::t('NAF_code')), |
1769 | (Env::i('AX_code') == 0 ? null : Env::t('AX_code')), | |
1770 | (Env::i('holdingId') == 0 ? null : Env::t('holdingId')), $id); | |
4d336f59 | 1771 | |
0b6c8b36 SJ |
1772 | $phone = new Phone(array('display' => Env::v('tel'), 'link_id' => $id, 'id' => 0, 'type' => 'fixed', |
1773 | 'link_type' => Phone::LINK_COMPANY, 'pub' => 'public')); | |
1774 | $fax = new Phone(array('display' => Env::v('fax'), 'link_id' => $id, 'id' => 1, 'type' => 'fax', | |
1775 | 'link_type' => Phone::LINK_COMPANY, 'pub' => 'public')); | |
c32bed90 | 1776 | $address = new Address(array('jobid' => $id, 'type' => Address::LINK_COMPANY, 'text' => Env::t('address'))); |
0b6c8b36 SJ |
1777 | $phone->save(); |
1778 | $fax->save(); | |
a710dfd7 | 1779 | $address->save(); |
63596a65 | 1780 | |
4d336f59 SJ |
1781 | $page->trigSuccess("L'entreprise a bien été mise à jour."); |
1782 | } | |
1783 | } | |
1784 | ||
1785 | if (!Env::has('change') && $id != -1) { | |
63596a65 SJ |
1786 | $res = XDB::query("SELECT e.id, e.name, e.acronym, e.url, e.email, e.NAF_code, e.AX_code, |
1787 | h.id AS holdingId, h.name AS holdingName, h.acronym AS holdingAcronym, | |
1788 | t.display_tel AS tel, f.display_tel AS fax, a.text AS address | |
1789 | FROM profile_job_enum AS e | |
1790 | LEFT JOIN profile_job_enum AS h ON (e.holdingid = h.id) | |
9483a7c7 SJ |
1791 | LEFT JOIN profile_phones AS t ON (t.pid = e.id AND t.link_type = 'hq' AND t.tel_id = 0) |
1792 | LEFT JOIN profile_phones AS f ON (f.pid = e.id AND f.link_type = 'hq' AND f.tel_id = 1) | |
63596a65 SJ |
1793 | LEFT JOIN profile_addresses AS a ON (a.jobid = e.id AND a.type = 'hq') |
1794 | WHERE e.id = {?}", | |
4d336f59 SJ |
1795 | $id); |
1796 | ||
1797 | if ($res->numRows() == 0) { | |
1798 | $page->trigError('Auncune entreprise ne correspond à cet identifiant.'); | |
1799 | } else { | |
1800 | $page->assign('selectedJob', $res->fetchOneAssoc()); | |
1801 | } | |
1802 | } | |
1803 | } | |
4d5946ac | 1804 | |
26ba053e | 1805 | function handler_profile($page) |
4d5946ac SJ |
1806 | { |
1807 | $page->changeTpl('admin/profile.tpl'); | |
1808 | ||
1809 | if (Post::has('checked')) { | |
1810 | S::assert_xsrf_token(); | |
1811 | $res = XDB::iterator('SELECT DISTINCT(pm.pid), pd.public_name | |
1812 | FROM profile_modifications AS pm | |
1813 | INNER JOIN profile_display AS pd ON (pm.pid = pd.pid) | |
1814 | WHERE pm.type = \'self\''); | |
1815 | ||
1816 | while ($profile = $res->next()) { | |
1817 | if (Post::has('checked_' . $profile['pid'])) { | |
1818 | XDB::execute('DELETE FROM profile_modifications | |
1819 | WHERE type = \'self\' AND pid = {?}', $profile['pid']); | |
1820 | ||
1821 | $page->trigSuccess('Profil de ' . $profile['public_name'] . ' vérifié.'); | |
1822 | } | |
1823 | } | |
1824 | } | |
1825 | ||
1826 | $res = XDB::iterator('SELECT p.hrpid, pm.pid, pd.directory_name, GROUP_CONCAT(pm.field SEPARATOR \', \') AS field | |
1827 | FROM profile_modifications AS pm | |
1828 | INNER JOIN profiles AS p ON (pm.pid = p.pid) | |
1829 | INNER JOIN profile_display AS pd ON (pm.pid = pd.pid) | |
1830 | WHERE pm.type = \'self\' | |
1831 | GROUP BY pd.directory_name | |
1832 | ORDER BY pd.directory_name'); | |
1833 | $page->assign('updates', $res); | |
1834 | } | |
d60d2d1f SJ |
1835 | |
1836 | function handler_phd($page, $promo = null, $validate = false) | |
1837 | { | |
1838 | $page->changeTpl('admin/phd.tpl'); | |
1839 | $eduDegrees = DirEnum::getOptions(DirEnum::EDUDEGREES); | |
1840 | $eduDegrees = array_flip($eduDegrees); | |
1841 | ||
1842 | if (is_null($promo)) { | |
1843 | $promo_list = XDB::fetchColumn('SELECT DISTINCT(grad_year) | |
1844 | FROM profile_education | |
1845 | WHERE FIND_IN_SET(\'primary\', flags) AND NOT FIND_IN_SET(\'completed\', flags) AND degreeid = {?} | |
1846 | ORDER BY grad_year', | |
1847 | $eduDegrees[Profile::DEGREE_D]); | |
1848 | $page->assign('promo_list', $promo_list); | |
1849 | $page->assign('nothing', count($promo_list) == 0); | |
1850 | return; | |
1851 | } | |
1852 | ||
1853 | if ($validate) { | |
1854 | S::assert_xsrf_token(); | |
1855 | ||
1856 | $list = XDB::iterator('SELECT pe.pid, pd.directory_name | |
1857 | FROM profile_education AS pe | |
1858 | INNER JOIN profile_display AS pd ON (pe.pid = pd.pid) | |
1859 | WHERE FIND_IN_SET(\'primary\', pe.flags) AND NOT FIND_IN_SET(\'completed\', pe.flags) | |
1860 | AND pe.degreeid = {?} AND pe.grad_year = {?}', | |
1861 | $eduDegrees[Profile::DEGREE_D], $promo); | |
1862 | while ($res = $list->next()) { | |
1863 | $pid = $res['pid']; | |
1864 | $name = $res['directory_name']; | |
1865 | if (Post::b('completed_' . $pid)) { | |
1866 | $grad_year = Post::t('grad_year_' . $pid); | |
1867 | XDB::execute('UPDATE profile_education | |
1868 | SET flags = \'primary,completed\', grad_year = {?} | |
1869 | WHERE FIND_IN_SET(\'primary\', flags) AND pid = {?}', | |
1870 | $grad_year, $pid); | |
1871 | XDB::execute('UPDATE profile_display | |
1872 | SET promo = {?} | |
1873 | WHERE pid = {?}', | |
1874 | 'D' . $grad_year, $pid); | |
1875 | $page->trigSuccess("Promotion de $name validée."); | |
1876 | } | |
1877 | } | |
1878 | } | |
1879 | ||
1880 | $list = XDB::iterator('SELECT pe.pid, pd.directory_name | |
1881 | FROM profile_education AS pe | |
1882 | INNER JOIN profile_display AS pd ON (pe.pid = pd.pid) | |
1883 | WHERE FIND_IN_SET(\'primary\', pe.flags) AND NOT FIND_IN_SET(\'completed\', pe.flags) | |
1884 | AND pe.degreeid = {?} AND pe.grad_year = {?} | |
1885 | ORDER BY pd.directory_name', | |
1886 | $eduDegrees[Profile::DEGREE_D], $promo); | |
1887 | $page->assign('list', $list); | |
1888 | $page->assign('promo', $promo); | |
1889 | } | |
edc03014 SJ |
1890 | |
1891 | function handler_add_secondary_edu($page) | |
1892 | { | |
1893 | $page->changeTpl('admin/add_secondary_edu.tpl'); | |
1894 | ||
1895 | if (!(Post::has('verify') || Post::has('add'))) { | |
1896 | return; | |
1897 | } elseif (!Post::has('people')) { | |
1898 | $page->trigWarning("Aucune information n'a été fournie."); | |
1899 | return; | |
1900 | } | |
1901 | ||
1902 | require_once 'name.func.inc.php'; | |
1903 | $lines = explode("\n", Post::t('people')); | |
1904 | $separator = Post::t('separator'); | |
1905 | $degree = Post::v('degree'); | |
1906 | $promotion = Post::i('promotion'); | |
1907 | $schoolsList = array_flip(DirEnum::getOptions(DirEnum::EDUSCHOOLS)); | |
1908 | $degreesList = array_flip(DirEnum::getOptions(DirEnum::EDUDEGREES)); | |
1909 | $edu_id = $schoolsList[Profile::EDU_X]; | |
1910 | $degree_id = $degreesList[$degree]; | |
1911 | ||
1912 | $res = array( | |
1913 | 'incomplete' => array(), | |
1914 | 'empty' => array(), | |
1915 | 'multiple' => array(), | |
1916 | 'already' => array(), | |
1917 | 'new' => array() | |
1918 | ); | |
1919 | $old_pids = array(); | |
1920 | $new_pids = array(); | |
1921 | foreach ($lines as $line) { | |
1922 | $line = trim($line); | |
1923 | $line_array = explode($separator, $line); | |
1924 | array_walk($line_array, 'trim'); | |
1925 | if (count($line_array) != 3) { | |
1926 | $page->trigError("La ligne « $line » est incomplète."); | |
1927 | $res['incomplete'][] = $line; | |
1928 | continue; | |
1929 | } | |
1930 | $cond = new PFC_And(new UFC_NameTokens(split_name_for_search($line_array[0]), array(), false, false, Profile::LASTNAME)); | |
1931 | $cond->addChild(new UFC_NameTokens(split_name_for_search($line_array[1]), array(), false, false, Profile::FIRSTNAME)); | |
1932 | $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, $line_array[2])); | |
1933 | $uf = new UserFilter($cond); | |
1934 | $pid = $uf->getPIDs(); | |
1935 | $count = count($pid); | |
1936 | if ($count == 0) { | |
1937 | $page->trigError("La ligne « $line » ne correspond à aucun profil existant."); | |
1938 | $res['empty'][] = $line; | |
1939 | continue; | |
1940 | } elseif ($count > 1) { | |
1941 | $page->trigError("La ligne « $line » correspond à plusieurs profils existant."); | |
1942 | $res['multiple'][] = $line; | |
1943 | continue; | |
1944 | } else { | |
1945 | $count = XDB::fetchOneCell('SELECT COUNT(*) AS count | |
1946 | FROM profile_education | |
1947 | WHERE pid = {?} AND eduid = {?} AND degreeid = {?}', | |
1948 | $pid, $edu_id, $degree_id); | |
1949 | if ($count == 1) { | |
1950 | $res['already'][] = $line; | |
1951 | $old_pids[] = $pid[0]; | |
1952 | } else { | |
1953 | $res['new'][] = $line; | |
1954 | $new_pids[] = $pid[0]; | |
1955 | } | |
1956 | } | |
1957 | } | |
1958 | ||
1959 | $display = array(); | |
1960 | foreach ($res as $type => $res_type) { | |
1961 | if (count($res_type) > 0) { | |
1962 | $display = array_merge($display, array('--------------------' . $type . ':'), $res_type); | |
1963 | } | |
1964 | } | |
1965 | $page->assign('people', implode("\n", $display)); | |
1966 | $page->assign('promotion', $promotion); | |
1967 | $page->assign('degree', $degree); | |
1968 | ||
1969 | if (Post::has('add')) { | |
1970 | $entry_year = $promotion - Profile::educationDuration($degree); | |
1971 | ||
1972 | if (Post::b('force_addition')) { | |
1973 | $pids = array_unique(array_merge($old_pids, $new_pids)); | |
1974 | } else { | |
1975 | $pids = array_unique($new_pids); | |
1976 | ||
1977 | // Updates years. | |
24b02786 SJ |
1978 | if (count($old_pids)) { |
1979 | XDB::execute('UPDATE profile_education | |
1980 | SET entry_year = {?}, grad_year = {?}, promo_year = {?} | |
1981 | WHERE pid IN {?} AND eduid = {?} AND degreeid = {?}', | |
1982 | $entry_year, $promotion, $promotion, $old_pids, $edu_id, $degree_id); | |
1983 | } | |
edc03014 SJ |
1984 | } |
1985 | ||
1986 | // Precomputes values common to all users. | |
1987 | $select = XDB::format('MAX(id) + 1, pid, {?}, {?}, {?}, {?}, {?}, \'secondary\'', | |
1988 | $edu_id, $degree_id, $entry_year, $promotion, $promotion ); | |
1989 | XDB::startTransaction(); | |
1990 | foreach ($pids as $pid) { | |
1991 | XDB::execute('INSERT INTO profile_education (id, pid, eduid, degreeid, entry_year, grad_year, promo_year, flags) | |
1992 | SELECT ' . $select . ' | |
1993 | FROM profile_education | |
e26ac9a3 SJ |
1994 | WHERE pid = {?} |
1995 | GROUP BY pid', | |
edc03014 SJ |
1996 | $pid); |
1997 | } | |
1998 | XDB::commit(); | |
1999 | } | |
2000 | ||
2001 | } | |
86f0a6af | 2002 | } |
2003 | ||
a7de4ef7 | 2004 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
86f0a6af | 2005 | ?> |