| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2011 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 | { |
| 26 | global $globals; |
| 27 | |
| 28 | // $membres' structure is the following: $sortKey => $key => $listMember |
| 29 | $membres = array(); |
| 30 | |
| 31 | foreach($members as $member) { |
| 32 | $user = User::getSilent($member); |
| 33 | if (!$user) { |
| 34 | $membres[0][$member] = array('name' => null, 'email' => $member, 'category' => null, 'uid' => null, 'lost' => null, 'hasProfile' => null); |
| 35 | } else { |
| 36 | $hasProfile = $user->hasProfile(); |
| 37 | $uid = $user->id(); |
| 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'; |
| 43 | } |
| 44 | $membres[$key][$name] = array('name' => $name, 'email' => $member, 'category' => $category, |
| 45 | 'uid' => $uid, 'lost' => $user->lost, 'hasProfile' => $hasProfile); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | ksort($membres); |
| 50 | foreach($membres as &$membre) { |
| 51 | uksort($membre, 'strcasecmp'); |
| 52 | } |
| 53 | return $membres; |
| 54 | } |
| 55 | |
| 56 | // }}} |
| 57 | // {{{ list_extract_member |
| 58 | |
| 59 | function _list_extract_member($member) |
| 60 | { |
| 61 | return $member[1]; |
| 62 | } |
| 63 | |
| 64 | function list_extract_members($members) |
| 65 | { |
| 66 | return array_map('_list_extract_member', $members); |
| 67 | } |
| 68 | |
| 69 | // }}} |
| 70 | // {{{ function list_sort_members |
| 71 | |
| 72 | function list_sort_members($members, $tri_promo = true) |
| 73 | { |
| 74 | $m = list_extract_members($members); |
| 75 | return list_sort_owners($m, $tri_promo); |
| 76 | } |
| 77 | |
| 78 | // }}} |
| 79 | // {{{ function list_fetch_basic_info |
| 80 | |
| 81 | function list_fetch_basic_info($members) |
| 82 | { |
| 83 | $res = array(); |
| 84 | foreach ($members as $member) { |
| 85 | $user = User::getSilent($member); |
| 86 | if (!$user) { |
| 87 | $res[] = $member . ';;'; |
| 88 | } else { |
| 89 | $res[] = $user->lastName() . ';' . $user->firstName() . ';' . $user->promo(); |
| 90 | } |
| 91 | } |
| 92 | return $res; |
| 93 | } |
| 94 | |
| 95 | // }}} |
| 96 | // {{{ function list_header_decode |
| 97 | |
| 98 | function _list_header_decode($charset, $c, $str) { |
| 99 | $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str); |
| 100 | $s = iconv($charset, 'UTF-8', $s); |
| 101 | return str_replace('_', ' ', $s); |
| 102 | } |
| 103 | |
| 104 | function list_header_decode($value) { |
| 105 | if (!$value) { |
| 106 | return "[pas de sujet]"; |
| 107 | } |
| 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 | // }}} |
| 113 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 114 | ?> |