Defaultly uses the address given by the user; allows bigger differences between the...
[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) {
aa7cb883 33 $membres[0][] = array('l' => $mem, 'p' => (!$tri_promo ? 'inconnue' : null), 'n' => null, 'x' => null, 'b' => null);
0337d704 34 } else {
cb8a8977 35 $uid = $user->id();
aa720387 36 $nom = $user->directoryName();
cb8a8977
FB
37 $promo = $user->promo();
38 if (!$promo) {
39 $promo = 'non-X';
40 }
b73bc04b
FB
41 $key = $tri_promo ? ($promo != 'non-X' ? $promo : 0) : strtoupper(@$nom{0});
42 if ($tri_promo) {
43 $promo = null;
0337d704 44 }
aa7cb883 45 $membres[$key][$nom.$mem] = array('n' => $nom, 'l' => $mem, 'p' => $promo, 'x' => $uid, 'b' => $user->lost);
0337d704 46 }
47 }
42a50827 48
0337d704 49 ksort($membres);
50 foreach($membres as $key=>$val) ksort($membres[$key]);
51 return $membres;
52}
53
54// }}}
b73bc04b
FB
55// {{{ list_extract_member
56
57function _list_extract_member($member)
58{
59 return $member[1];
60}
61
62function list_extract_members($members)
63{
64 return array_map('_list_extract_member', $members);
65}
66
67// }}}
0337d704 68// {{{ function list_sort_members
69
cd994096 70function list_sort_members($members, $tri_promo = true)
b73bc04b 71{
cd994096
FB
72 $m = list_extract_members($members);
73 return list_sort_owners($m, $tri_promo);
b73bc04b
FB
74}
75
76// }}}
b73bc04b
FB
77
78function list_fetch_names($members)
79{
80 $res = array();
81 foreach ($members as $member) {
cb8a8977
FB
82 $user = User::getSilent($member);
83 if (!$user) {
84 $res[] = $member;
85 } else {
86 $res[] = $user->fullName();
87 }
b73bc04b
FB
88 }
89 return $res;
0337d704 90}
91
92// }}}
0cc4c07d 93// {{{ function list_header_decode
94
95function _list_header_decode($charset, $c, $str) {
96 $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str);
493b6abe 97 $s = iconv($charset, 'UTF-8', $s);
0cc4c07d 98 return str_replace('_', ' ', $s);
99}
100
101function list_header_decode($value) {
5fb22b39 102 if (!$value) {
103 return "[pas de sujet]";
104 }
0cc4c07d 105 $val = preg_replace('/(=\?[^?]*\?[BQbq]\?[^?]*\?=) (=\?[^?]*\?[BQbq]\?[^?]*\?=)/', '\1\2', $value);
106 return preg_replace('/=\?([^?]*)\?([BQbq])\?([^?]*)\?=/e', '_list_header_decode("\1", "\2", "\3")', $val);
107}
108
109// }}}
a7de4ef7 110// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 111?>