first reimport from platal
[platal.git] / htdocs / admin / homonymes.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
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 require_once("xorg.inc.php");
23 new_admin_page('admin/homonymes.tpl');
24 require_once("homonymes.inc.php");
25
26 $op = Env::get('op', 'list');
27 $target = Env::getInt('target');
28
29 if ($target) {
30 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
31 $target=0;
32 } else {
33 $page->assign('nom',$nom);
34 $page->assign('prenom',$prenom);
35 $page->assign('forlife',$forlife);
36 $page->assign('loginbis',$loginbis);
37 }
38 }
39
40 $page->assign('op',$op);
41 $page->assign('target',$target);
42 $page->assign('baseurl',$globals->baseurl);
43
44 // on a un $target valide, on prepare les mails
45 if ($target) {
46
47 // on examine l'op a effectuer
48 switch ($op) {
49 case 'mail':
50 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
51 switch_bestalias($target, $loginbis);
52 $op = 'list';
53 break;
54 case 'correct':
55 switch_bestalias($target, $loginbis);
56 $globals->xdb->execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
57 $globals->xdb->execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
58 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
59 $op = 'list';
60 break;
61 }
62 }
63
64 if ($op == 'list') {
65 $res = $globals->xdb->iterator(
66 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
67 promo,prenom,nom,
68 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
69 IF(h.homonyme_id=s.id, a.type, NULL) AS type
70 FROM aliases AS a
71 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
72 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
73 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
74 WHERE a.type='homonyme' OR a.expire!=''
75 ORDER BY a.alias,promo");
76 $hnymes = Array();
77 while ($tab = $res->next()) {
78 $hnymes[$tab['homonyme']][] = $tab;
79 }
80 $page->assign_by_ref('hnymes',$hnymes);
81 }
82
83 $page->run();
84 ?>