Happy New Year!
[platal.git] / modules / lists / lists.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
5e1513f6 3 * Copyright (C) 2003-2011 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
8da7bf1d 24function list_sort_owners($members, $tri_promo = true)
cb8a8977 25{
0337d704 26 global $globals;
27
8da7bf1d
SJ
28 // $membres' structure is the following: $sortKey => $key => $listMember
29 $membres = array();
42a50827 30
8da7bf1d
SJ
31 foreach($members as $member) {
32 $user = User::getSilent($member);
cb8a8977 33 if (!$user) {
8da7bf1d 34 $membres[0][$member] = array('name' => null, 'email' => $member, 'category' => null, 'uid' => null, 'lost' => null, 'hasProfile' => null);
0337d704 35 } else {
8da7bf1d 36 $hasProfile = $user->hasProfile();
cb8a8977 37 $uid = $user->id();
8da7bf1d
SJ
38 $name = $user->directoryName();
39 $category = $user->category();
40 $key = $tri_promo ? ($category ? $category : 'AAAAA') : strtoupper($name{0});
41 if (!$category) {
42 $category = 'extérieurs';
cb8a8977 43 }
8da7bf1d
SJ
44 $membres[$key][$name . $member] = array('name' => $name, 'email' => $member, 'category' => $category,
45 'uid' => $uid, 'lost' => $user->lost, 'hasProfile' => $hasProfile);
0337d704 46 }
47 }
42a50827 48
0337d704 49 ksort($membres);
8da7bf1d
SJ
50 foreach($membres as $membre) {
51 ksort($membre);
52 }
0337d704 53 return $membres;
54}
55
56// }}}
b73bc04b
FB
57// {{{ list_extract_member
58
59function _list_extract_member($member)
60{
61 return $member[1];
62}
63
64function list_extract_members($members)
65{
66 return array_map('_list_extract_member', $members);
67}
68
69// }}}
0337d704 70// {{{ function list_sort_members
71
cd994096 72function list_sort_members($members, $tri_promo = true)
b73bc04b 73{
cd994096
FB
74 $m = list_extract_members($members);
75 return list_sort_owners($m, $tri_promo);
b73bc04b
FB
76}
77
78// }}}
b97ecb9d 79// {{{ function list_fetch_basic_info
b73bc04b 80
b97ecb9d 81function list_fetch_basic_info($members)
b73bc04b
FB
82{
83 $res = array();
84 foreach ($members as $member) {
cb8a8977
FB
85 $user = User::getSilent($member);
86 if (!$user) {
b97ecb9d 87 $res[] = $member . ',,';
cb8a8977 88 } else {
b97ecb9d 89 $res[] = $user->forlifeEmail() . ',' . $user->directoryName() . ',' . $user->promo();
cb8a8977 90 }
b73bc04b
FB
91 }
92 return $res;
0337d704 93}
94
95// }}}
0cc4c07d 96// {{{ function list_header_decode
97
98function _list_header_decode($charset, $c, $str) {
99 $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str);
493b6abe 100 $s = iconv($charset, 'UTF-8', $s);
0cc4c07d 101 return str_replace('_', ' ', $s);
102}
103
104function list_header_decode($value) {
5fb22b39 105 if (!$value) {
106 return "[pas de sujet]";
107 }
0cc4c07d 108 $val = preg_replace('/(=\?[^?]*\?[BQbq]\?[^?]*\?=) (=\?[^?]*\?[BQbq]\?[^?]*\?=)/', '\1\2', $value);
109 return preg_replace('/=\?([^?]*)\?([BQbq])\?([^?]*)\?=/e', '_list_header_decode("\1", "\2", "\3")', $val);
110}
111
112// }}}
a7de4ef7 113// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 114?>