Fix references to undefined variable.
[platal.git] / modules / lists / lists.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
9f5bd98e 3 * Copyright (C) 2003-2010 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
cb8a8977
FB
24function list_sort_owners(&$members, $tri_promo = true)
25{
0337d704 26 global $globals;
27
28 $membres = Array();
42a50827 29
0337d704 30 foreach($members as $mem) {
cb8a8977
FB
31 $user = User::getSilent($mem);
32 if (!$user) {
b73bc04b 33 $membres[0][] = array('l' => $mem, 'p' => (!$tri_promo ? 'inconnue' : null));
0337d704 34 } else {
cb8a8977
FB
35 $uid = $user->id();
36 $nom = $user->fullName(); # XXX: Get a notion of 'last name' here, I want to sort user by lastnames
37 $promo = $user->promo();
38 if (!$promo) {
39 $promo = 'non-X';
40 }
41 $broken = false; # XXX: fill it with the good value if the user has no valid email
b73bc04b
FB
42 $key = $tri_promo ? ($promo != 'non-X' ? $promo : 0) : strtoupper(@$nom{0});
43 if ($tri_promo) {
44 $promo = null;
0337d704 45 }
b75ef9b2 46 $membres[$key][$nom.$mem] = Array('n' => $nom, 'l' => $mem, 'p' => $promo, 'x' => $uid, 'b' => $broken);
0337d704 47 }
48 }
42a50827 49
0337d704 50 ksort($membres);
51 foreach($membres as $key=>$val) ksort($membres[$key]);
52 return $membres;
53}
54
55// }}}
b73bc04b
FB
56// {{{ list_extract_member
57
58function _list_extract_member($member)
59{
60 return $member[1];
61}
62
63function list_extract_members($members)
64{
65 return array_map('_list_extract_member', $members);
66}
67
68// }}}
0337d704 69// {{{ function list_sort_members
70
cd994096 71function list_sort_members($members, $tri_promo = true)
b73bc04b 72{
cd994096
FB
73 $m = list_extract_members($members);
74 return list_sort_owners($m, $tri_promo);
b73bc04b
FB
75}
76
77// }}}
b73bc04b
FB
78
79function list_fetch_names($members)
80{
81 $res = array();
82 foreach ($members as $member) {
cb8a8977
FB
83 $user = User::getSilent($member);
84 if (!$user) {
85 $res[] = $member;
86 } else {
87 $res[] = $user->fullName();
88 }
b73bc04b
FB
89 }
90 return $res;
0337d704 91}
92
93// }}}
0cc4c07d 94// {{{ function list_header_decode
95
96function _list_header_decode($charset, $c, $str) {
97 $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str);
493b6abe 98 $s = iconv($charset, 'UTF-8', $s);
0cc4c07d 99 return str_replace('_', ' ', $s);
100}
101
102function list_header_decode($value) {
5fb22b39 103 if (!$value) {
104 return "[pas de sujet]";
105 }
0cc4c07d 106 $val = preg_replace('/(=\?[^?]*\?[BQbq]\?[^?]*\?=) (=\?[^?]*\?[BQbq]\?[^?]*\?=)/', '\1\2', $value);
107 return preg_replace('/=\?([^?]*)\?([BQbq])\?([^?]*)\?=/e', '_list_header_decode("\1", "\2", "\3")', $val);
108}
109
110// }}}
a7de4ef7 111// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 112?>