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) { |
575dd9be | 30 | list($m, $dom) = explode('@',$mem); |
0337d704 | 31 | if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) { |
0e5ec860 VZ |
32 | $res = XDB::query('SELECT prenom, IF(nom_usage="", nom, nom_usage), promo, |
33 | (e.uid IS NULL AND FIND_IN_SET("googleapps", u.mail_storage) = 0) | |
ce835419 FB |
34 | FROM auth_user_md5 AS u |
35 | INNER JOIN aliases AS a ON u.user_id = a.id | |
0e5ec860 | 36 | LEFT JOIN emails AS e ON (e.flags = "active" AND e.uid = u.user_id) |
ce835419 FB |
37 | WHERE a.alias = {?} |
38 | GROUP BY u.user_id', $m); | |
39 | if(list($prenom, $nom, $promo, $broken) = $res->fetchOneRow()) { | |
0337d704 | 40 | $key = $tri_promo ? $promo : strtoupper($nom{0}); |
ce835419 | 41 | $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m, 'p' => (!$tri_promo ? $promo : null), 'b' => $broken); |
0337d704 | 42 | } else { |
ce835419 | 43 | $membres[0][] = Array('l' => $mem, 'b' => $broken); |
0337d704 | 44 | } |
45 | } else { | |
dc2073c3 | 46 | $res = XDB::query('SELECT m2.uid, |
47 | IF(m2.origine="X", u.prenom, m1.prenom) AS prenom, | |
48 | IF(m2.origine="X", u.nom, m1.nom) AS nom, | |
ce835419 FB |
49 | IF(m2.origine="X", u.promo, "non-X") AS promo, |
50 | 0 | |
8040946c | 51 | FROM groupex.membres AS m1 |
52 | LEFT JOIN groupex.membres AS m2 ON(m1.email=m2.email AND m2.asso_id={?}) | |
dc2073c3 | 53 | LEFT JOIN auth_user_md5 AS u ON(m2.origine = "X" AND m2.uid = u.user_id) |
8040946c | 54 | WHERE m1.email={?}', $globals->asso('id'), $mem); |
dc2073c3 | 55 | if (list($uid, $prenom, $nom, $promo) = $res->fetchOneRow()) { |
56 | $key = $tri_promo ? ($promo != 'non-X' ? $promo : 0) : strtoupper($nom{0}); | |
57 | if ($tri_promo) { | |
58 | $promo = null; | |
59 | } | |
60 | $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $mem, 'x' => $uid, 'p' => $promo); | |
0337d704 | 61 | } else { |
30fc8ee7 | 62 | $membres[0][] = Array('l' => $mem, 'p' => (!$tri_promo ? 'non-X' : null)); |
0337d704 | 63 | } |
64 | } | |
65 | } | |
42a50827 | 66 | |
0337d704 | 67 | ksort($membres); |
68 | foreach($membres as $key=>$val) ksort($membres[$key]); | |
69 | return $membres; | |
70 | } | |
71 | ||
72 | // }}} | |
73 | // {{{ function list_sort_members | |
74 | ||
75 | function list_sort_members(&$members, $tri_promo = true) { | |
89460d9c | 76 | $member_list = array_map(create_function('$arr', 'return $arr[1];'), $members); |
77 | return list_sort_owners($member_list, $tri_promo); | |
0337d704 | 78 | } |
79 | ||
80 | // }}} | |
0cc4c07d | 81 | // {{{ function list_header_decode |
82 | ||
83 | function _list_header_decode($charset, $c, $str) { | |
84 | $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str); | |
493b6abe | 85 | $s = iconv($charset, 'UTF-8', $s); |
0cc4c07d | 86 | return str_replace('_', ' ', $s); |
87 | } | |
88 | ||
89 | function list_header_decode($value) { | |
5fb22b39 | 90 | if (!$value) { |
91 | return "[pas de sujet]"; | |
92 | } | |
0cc4c07d | 93 | $val = preg_replace('/(=\?[^?]*\?[BQbq]\?[^?]*\?=) (=\?[^?]*\?[BQbq]\?[^?]*\?=)/', '\1\2', $value); |
94 | return preg_replace('/=\?([^?]*)\?([BQbq])\?([^?]*)\?=/e', '_list_header_decode("\1", "\2", "\3")', $val); | |
95 | } | |
96 | ||
97 | // }}} | |
a7de4ef7 | 98 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 99 | ?> |