Fix many php warnings and notices
[platal.git] / include / lists.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
50a40a33 3 * Copyright (C) 2003-2006 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 lists_xmlrpc
23
24function &lists_xmlrpc($uid, $pass, $fqdn=null)
25{
26 global $globals;
27
2968a0e9 28 $dom = is_null($fqdn) ? $globals->mail->domain : $fqdn;
0337d704 29 $url = "http://$uid:$pass@{$globals->lists->rpchost}:{$globals->lists->rpcport}/$dom";
27cb2301 30 $client = new XmlrpcClient($url);
0337d704 31 return $client;
32}
33
34// }}}
35// {{{ function list_sort_owners
36
37function list_sort_owners(&$members, $tri_promo = true) {
38 global $globals;
39
40 $membres = Array();
42a50827 41
0337d704 42 foreach($members as $mem) {
575dd9be 43 list($m, $dom) = explode('@',$mem);
0337d704 44 if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) {
08cce2ff 45 $res = XDB::query('SELECT prenom,IF(nom_usage="", nom, nom_usage), promo
0337d704 46 FROM auth_user_md5 AS u
47 INNER JOIN aliases AS a ON u.user_id = a.id
48 WHERE a.alias = {?}', $m);
49 if(list($prenom, $nom, $promo) = $res->fetchOneRow()) {
50 $key = $tri_promo ? $promo : strtoupper($nom{0});
8138ece0 51 $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m, 'p' => (!$tri_promo ? $promo : null));
0337d704 52 } else {
53 $membres[0][] = Array('l' => $mem);
54 }
55 } else {
08cce2ff 56 $res = XDB::query('SELECT prenom, nom FROM groupex.membres WHERE email={?}', $mem);
0337d704 57 if (list($prenom, $nom) = $res->fetchOneRow()) {
58 $key = $tri_promo ? 0 : strtoupper($nom{0});
8138ece0 59 $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $mem, 'p' => (!$tri_promo ? 'non-X' : null));
0337d704 60 } else {
61 $membres[0][] = Array('l' => $mem);
62 }
63 }
64 }
42a50827 65
0337d704 66 ksort($membres);
67 foreach($membres as $key=>$val) ksort($membres[$key]);
68 return $membres;
69}
70
71// }}}
72// {{{ function list_sort_members
73
74function list_sort_members(&$members, $tri_promo = true) {
75 $pi1 = create_function('$arr', 'return $arr[1];');
76 return list_sort_owners(array_map($pi1, $members), $tri_promo);
77}
78
79// }}}
0cc4c07d 80// {{{ function list_header_decode
81
82function _list_header_decode($charset, $c, $str) {
83 $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str);
84 $s = iconv($charset, 'iso-8859-15', $s);
85 return str_replace('_', ' ', $s);
86}
87
88function list_header_decode($value) {
89 $val = preg_replace('/(=\?[^?]*\?[BQbq]\?[^?]*\?=) (=\?[^?]*\?[BQbq]\?[^?]*\?=)/', '\1\2', $value);
90 return preg_replace('/=\?([^?]*)\?([BQbq])\?([^?]*)\?=/e', '_list_header_decode("\1", "\2", "\3")', $val);
91}
92
93// }}}
0337d704 94// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
95?>