6382e7d04a85a12fb2ec9e5e700ba91ebb98a5a1
[platal.git] / modules / lists / lists.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 // {{{ function list_sort_owners
23
24 function list_sort_owners(&$members, $tri_promo = true) {
25 global $globals;
26
27 $membres = Array();
28
29 foreach($members as $mem) {
30 list($m, $dom) = explode('@',$mem);
31 if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) {
32 $res = XDB::query('SELECT prenom,IF(nom_usage="", nom, nom_usage), promo
33 FROM auth_user_md5 AS u
34 INNER JOIN aliases AS a ON u.user_id = a.id
35 WHERE a.alias = {?}', $m);
36 if(list($prenom, $nom, $promo) = $res->fetchOneRow()) {
37 $key = $tri_promo ? $promo : strtoupper($nom{0});
38 $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m, 'p' => (!$tri_promo ? $promo : null));
39 } else {
40 $membres[0][] = Array('l' => $mem);
41 }
42 } else {
43 $res = XDB::query('SELECT prenom, nom FROM groupex.membres WHERE email={?}', $mem);
44 if (list($prenom, $nom) = $res->fetchOneRow()) {
45 $key = $tri_promo ? 0 : strtoupper($nom{0});
46 $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $mem, 'p' => (!$tri_promo ? 'non-X' : null));
47 } else {
48 $membres[0][] = Array('l' => $mem);
49 }
50 }
51 }
52
53 ksort($membres);
54 foreach($membres as $key=>$val) ksort($membres[$key]);
55 return $membres;
56 }
57
58 // }}}
59 // {{{ function list_sort_members
60
61 function list_sort_members(&$members, $tri_promo = true) {
62 $member_list = array_map(create_function('$arr', 'return $arr[1];'), $members);
63 return list_sort_owners($member_list, $tri_promo);
64 }
65
66 // }}}
67 // {{{ function list_header_decode
68
69 function _list_header_decode($charset, $c, $str) {
70 $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str);
71 $s = iconv($charset, 'iso-8859-15', $s);
72 return str_replace('_', ' ', $s);
73 }
74
75 function list_header_decode($value) {
76 $val = preg_replace('/(=\?[^?]*\?[BQbq]\?[^?]*\?=) (=\?[^?]*\?[BQbq]\?[^?]*\?=)/', '\1\2', $value);
77 return preg_replace('/=\?([^?]*)\?([BQbq])\?([^?]*)\?=/e', '_list_header_decode("\1", "\2", "\3")', $val);
78 }
79
80 // }}}
81 ?>