Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
0337d704 | 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 | ||
0337d704 | 22 | // {{{ function list_sort_owners |
23 | ||
24 | function list_sort_owners(&$members, $tri_promo = true) { | |
25 | global $globals; | |
26 | ||
27 | $membres = Array(); | |
42a50827 | 28 | |
0337d704 | 29 | foreach($members as $mem) { |
b73bc04b FB |
30 | list($m, $dom) = explode('@', $mem); |
31 | $info = list_fetch_name($mem); | |
cd994096 | 32 | if (!isset($info['uid']) || is_null($info['uid'])) { |
b73bc04b | 33 | $membres[0][] = array('l' => $mem, 'p' => (!$tri_promo ? 'inconnue' : null)); |
0337d704 | 34 | } else { |
b73bc04b FB |
35 | $uid = $info['uid']; |
36 | $nom = $info['nom']; | |
37 | $prenom = $info['prenom']; | |
38 | $promo = $info['promo']; | |
39 | $broken = $info['lost']; | |
40 | $key = $tri_promo ? ($promo != 'non-X' ? $promo : 0) : strtoupper(@$nom{0}); | |
41 | if ($tri_promo) { | |
42 | $promo = null; | |
0337d704 | 43 | } |
b73bc04b | 44 | $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m, 'p' => $promo, 'x' => $uid, 'b' => $broken); |
0337d704 | 45 | } |
46 | } | |
42a50827 | 47 | |
0337d704 | 48 | ksort($membres); |
49 | foreach($membres as $key=>$val) ksort($membres[$key]); | |
50 | return $membres; | |
51 | } | |
52 | ||
53 | // }}} | |
b73bc04b FB |
54 | // {{{ list_extract_member |
55 | ||
56 | function _list_extract_member($member) | |
57 | { | |
58 | return $member[1]; | |
59 | } | |
60 | ||
61 | function list_extract_members($members) | |
62 | { | |
63 | return array_map('_list_extract_member', $members); | |
64 | } | |
65 | ||
66 | // }}} | |
0337d704 | 67 | // {{{ function list_sort_members |
68 | ||
cd994096 | 69 | function list_sort_members($members, $tri_promo = true) |
b73bc04b | 70 | { |
cd994096 FB |
71 | $m = list_extract_members($members); |
72 | return list_sort_owners($m, $tri_promo); | |
b73bc04b FB |
73 | } |
74 | ||
75 | // }}} | |
76 | // {{{ function list_fetch_names | |
77 | ||
78 | function list_fetch_name($member) | |
79 | { | |
80 | global $globals; | |
81 | list($m, $dom) = explode('@', $member); | |
82 | if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) { | |
83 | $res = XDB::query('SELECT u.user_id AS uid, prenom AS prenom, IF(nom_usage="", nom, nom_usage) AS nom, | |
84 | promo AS promo, | |
85 | (e.uid IS NULL AND FIND_IN_SET("googleapps", u.mail_storage) = 0) AS lost | |
86 | FROM auth_user_md5 AS u | |
87 | INNER JOIN aliases AS a ON u.user_id = a.id | |
88 | LEFT JOIN emails AS e ON (e.flags = "active" AND e.uid = u.user_id) | |
89 | WHERE a.alias = {?} | |
90 | GROUP BY u.user_id', $m); | |
91 | } else { | |
92 | $res = XDB::query('SELECT m2.uid AS uid, | |
93 | IF(m2.origine="X", u.prenom, m1.prenom) AS prenom, | |
94 | IF(m2.origine="X", u.nom, m1.nom) AS nom, | |
95 | IF(m2.origine="X", u.promo, "non-X") AS promo, | |
96 | 0 AS lost | |
97 | FROM groupex.membres AS m1 | |
98 | LEFT JOIN groupex.membres AS m2 ON(m1.email=m2.email AND m2.asso_id={?}) | |
99 | LEFT JOIN auth_user_md5 AS u ON(m2.origine = "X" AND m2.uid = u.user_id) | |
100 | WHERE m1.email={?}', $globals->asso('id'), $member); | |
101 | } | |
102 | if ($res->numRows() == 0) { | |
103 | return array('email' => $member); | |
104 | } else { | |
105 | return array_merge(array('email' => $member), $res->fetchOneAssoc()); | |
106 | } | |
107 | } | |
108 | ||
109 | function list_fetch_names($members) | |
110 | { | |
111 | $res = array(); | |
112 | foreach ($members as $member) { | |
113 | $res[] = list_fetch_name($member); | |
114 | } | |
115 | return $res; | |
0337d704 | 116 | } |
117 | ||
118 | // }}} | |
0cc4c07d | 119 | // {{{ function list_header_decode |
120 | ||
121 | function _list_header_decode($charset, $c, $str) { | |
122 | $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str); | |
493b6abe | 123 | $s = iconv($charset, 'UTF-8', $s); |
0cc4c07d | 124 | return str_replace('_', ' ', $s); |
125 | } | |
126 | ||
127 | function list_header_decode($value) { | |
5fb22b39 | 128 | if (!$value) { |
129 | return "[pas de sujet]"; | |
130 | } | |
0cc4c07d | 131 | $val = preg_replace('/(=\?[^?]*\?[BQbq]\?[^?]*\?=) (=\?[^?]*\?[BQbq]\?[^?]*\?=)/', '\1\2', $value); |
132 | return preg_replace('/=\?([^?]*)\?([BQbq])\?([^?]*)\?=/e', '_list_header_decode("\1", "\2", "\3")', $val); | |
133 | } | |
134 | ||
135 | // }}} | |
a7de4ef7 | 136 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 137 | ?> |