Bug 335 suppression sans validation du statut orange. Rajout de quelques tests supplé...
[platal.git] / htdocs / carnet / mescontacts.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_skinned_page("carnet/mescontacts.tpl",AUTH_COOKIE);
24 require_once("applis.func.inc.php");
25
26 $uid = Session::getInt('uid');
27 $user = Env::get('user');
28
29 switch (Env::get('action')) {
30 case 'retirer':
31 if (preg_match('/^\d+$/', $user)) {
32 if ($globals->xdb->execute('DELETE FROM contacts WHERE uid = {?} AND contact = {?}', $uid, $user))
33 {
34 $page->trig("Contact retiré !");
35 }
36 } else {
37 if ($globals->xdb->execute(
38 'DELETE FROM contacts
39 USING contacts AS c
40 INNER JOIN aliases AS a ON (c.contact=a.id and a.type!="homonyme")
41 WHERE c.uid = {?} AND a.alias={?}', $uid, $user))
42 {
43 $page->trig("Contact retiré !");
44 }
45 }
46 break;
47
48 case 'ajouter':
49 require_once('user.func.inc.php');
50 if (($login = get_user_login($user)) !== false) {
51 if ($globals->xdb->execute(
52 'INSERT INTO contacts (uid, contact)
53 SELECT {?}, id
54 FROM aliases
55 WHERE alias = {?}', $uid, $login))
56 {
57 $page->trig('Contact ajouté !');
58 } else {
59 $page->trig('Contact déjà dans la liste !');
60 }
61 }
62 }
63
64 if(Get::get('trombi')) {
65 require_once('trombi.inc.php');
66 function getList($offset,$limit) {
67 global $globals;
68 $uid = Session::getInt('uid');
69 $res = $globals->xdb->query("SELECT COUNT(*) FROM contacts WHERE uid = {?}", $uid);
70 $total = $res->fetchOneCell();
71
72 $order = Get::get('order');
73 $orders = Array(
74 'nom' => 'nom DESC, u.prenom, u.promo',
75 'promo' => 'promo DESC, nom, u.prenom',
76 'last' => 'u.date DESC, nom, u.prenom, promo');
77 if ($order != 'promo' && $order != 'last')
78 $order = 'nom';
79 $order = $orders[$order];
80 if (Get::get('inv') == '')
81 $order = str_replace(" DESC,", ",", $order);
82
83 $res = $globals->xdb->query("
84 SELECT u.prenom, IF(u.nom_usage='',u.nom,u.nom_usage) AS nom, a.alias AS forlife, u.promo
85 FROM contacts AS c
86 INNER JOIN auth_user_md5 AS u ON (u.user_id = c.contact)
87 INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
88 WHERE c.uid = {?}
89 ORDER BY $order
90 LIMIT {?}, {?}", $uid, $offset*$limit, $limit);
91 $list = $res->fetchAllAssoc();
92
93 return Array($total, $list);
94 }
95
96 $trombi = new Trombi('getList');
97 $trombi->setNbRows(4);
98 $page->assign_by_ref('trombi',$trombi);
99
100 $order = Get::get('order');
101 if ($order != 'promo' && $order != 'last')
102 $order = 'nom';
103 $page->assign('order', $order);
104 $page->assign('inv', Get::get('inv'));
105 } else {
106
107 $order = Get::get('order');
108 $orders = Array(
109 'nom' => 'sortkey DESC, a.prenom, a.promo',
110 'promo' => 'promo DESC, sortkey, a.prenom',
111 'last' => 'a.date DESC, sortkey, a.prenom, promo');
112 if ($order != 'promo' && $order != 'last')
113 $order = 'nom';
114 $page->assign('order', $order);
115 $page->assign('inv', Get::get('inv'));
116 $order = $orders[$order];
117 if (Get::get('inv') == '')
118 $order = str_replace(" DESC,", ",", $order);
119
120 $sql = "SELECT contact AS id,
121 a.*, l.alias AS forlife,
122 1 AS inscrit,
123 a.perms != 'pending' AS wasinscrit,
124 a.deces != 0 AS dcd, a.deces, a.matricule_ax, FIND_IN_SET('femme', a.flags) AS sexe,
125 e.entreprise, es.label AS secteur, ef.fonction_fr AS fonction,
126 IF(n.nat='',n.pays,n.nat) AS nat, n.a2 AS iso3166,
127 ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type,
128 ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type,
129 adr.city, gp.a2, gp.pays AS countrytxt, gr.name AS region,
130 IF(a.nom_usage<>'',a.nom_usage,a.nom) AS sortkey
131 FROM contacts AS c
132 INNER JOIN auth_user_md5 AS a ON (a.user_id = c.contact)
133 INNER JOIN aliases AS l ON (a.user_id = l.id AND l.type='a_vie')
134 LEFT JOIN entreprises AS e ON (e.entrid = 0 AND e.uid = a.user_id)
135 LEFT JOIN emploi_secteur AS es ON (e.secteur = es.id)
136 LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id)
137 LEFT JOIN geoloc_pays AS n ON (a.nationalite = n.a2)
138 LEFT JOIN applis_ins AS ai0 ON (a.user_id = ai0.uid AND ai0.ordre = 0)
139 LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid)
140 LEFT JOIN applis_ins AS ai1 ON (a.user_id = ai1.uid AND ai1.ordre = 1)
141 LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid)
142 LEFT JOIN adresses AS adr ON (a.user_id = adr.uid AND FIND_IN_SET('active', adr.statut))
143 LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
144 LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)
145 WHERE c.uid = $uid
146 ORDER BY ".$order;
147
148 $page->assign_by_ref('citer', $globals->xdb->iterator($sql));
149 }
150
151 $page->run();
152
153 // vim:set et sw=4 sts=4 sws=4:
154 ?>