Fix group description processing
[banana.git] / banana / groups.inc.php
CommitLineData
93d9186d 1<?php
2/********************************************************************************
3* include/groups.inc.php : class for group lists
4* ------------------------
5*
6* This file is part of the banana distribution
7* Copyright: See COPYING files that comes with this distribution
8********************************************************************************/
9
10/** class for group lists
11 */
12
65d96b1f 13define ( 'BANANA_GROUP_ALL', 0 );
14define ( 'BANANA_GROUP_SUB', 1 );
15define ( 'BANANA_GROUP_NEW', 2 );
16
d4c19591 17class BananaGroups {
18 /** group list */
65d96b1f 19 var $overview = Array();
d4c19591 20 /** last update */
21 var $date;
93d9186d 22
65d96b1f 23 var $type;
24
d4c19591 25 /** constructor
d4c19591 26 */
27
65d96b1f 28 function BananaGroups($_type = BANANA_GROUP_SUB) {
2dbc0167 29 global $banana;
65d96b1f 30
31 $this->type = $_type;
d81ff988 32 $this->load();
65d96b1f 33
d81ff988 34 if (empty($this->overview) && $_type == BANANA_GROUP_SUB) {
35 $this->type = BANANA_GROUP_ALL;
36 $this->load();
37 }
38 }
39
40 /** Load overviews
41 */
42 function load()
43 {
44 global $banana;
45
53e1ec45 46 $desc = $banana->nntp->xgtitle();
d81ff988 47 if ($this->type == BANANA_GROUP_NEW) {
2dbc0167 48 $list = $banana->nntp->newgroups($banana->profile['lastnews']);
d4c19591 49 } else {
2dbc0167 50 $list = $banana->nntp->liste();
d81ff988 51 if ($this->type == BANANA_GROUP_SUB) {
65d96b1f 52 $mylist = Array();
2dbc0167 53 foreach ($banana->profile['subscribe'] as $g) {
54 if (isset($list[$g])) {
55 $mylist[$g] = $list[$g];
56 }
57 }
58 $list = $mylist;
59 }
8f98c1e8 60 }
2dbc0167 61
7e12aea5 62 foreach ($list as $g=>$l) {
2dbc0167 63 $this->overview[$g][0] = isset($desc[$g]) ? $desc[$g] : '-';
64 $this->overview[$g][1] = $l[0];
8f98c1e8 65 }
65d96b1f 66 ksort($this->overview);
93d9186d 67 }
93d9186d 68
d4c19591 69 /** updates overview
d4c19591 70 * @param date INTEGER date of last update
71 */
2dbc0167 72 function update($_date) {
73 global $banana;
74 $serverdate = $banana->nntp->date();
d4c19591 75 if (!$serverdate) $serverdate=time();
2dbc0167 76 $newlist = $banana->nntp->newgroups($_date);
d4c19591 77 if (!$newlist) return false;
78 $this->date = $serverdate;
79 foreach (array_keys($newlist) as $g) {
2dbc0167 80 $groupstat = $banana->nntp->group($g);
81 $groupdesc = $banana->nntp->xgtitle($g);
d4c19591 82 $this->overview[$g][0]=($groupdesc?$groupdesc:"-");
83 $this->overview[$g][1]=$groupstat[0];
84 }
85 return true;
93d9186d 86 }
65d96b1f 87
958c7ab3 88 function to_html($show_form = false)
65d96b1f 89 {
90 global $banana;
91 if (empty($this->overview)) {
92 return;
93 }
94
95 $html = '<table class="bicol banana_group" cellspacing="0" cellpadding="2">'."\n";
96 $html .= '<tr><th>'._b_('Total').'</th><th>';
958c7ab3 97 if ($show_form) {
98 $html .= _b_('Abo.').'</th><th>';
99 } elseif ($this->type == BANANA_GROUP_SUB) {
65d96b1f 100 $html .= _b_('Nouveaux').'</th><th>';
101 }
102 $html .= _b_('Nom').'</th><th>'._b_('Description').'</th></tr>'."\n";
103
104 $b = true;
105 foreach ($this->overview as $g => $d) {
106 $b = !$b;
107 $ginfo = $banana->nntp->group($g);
108 $new = count($banana->nntp->newnews($banana->profile['lastnews'],$g));
109
110 $html .= '<tr class="'.($b ? 'pair' : 'impair').'">'."\n";
111 $html .= "<td class='all'>{$ginfo[0]}</td>";
958c7ab3 112 if ($show_form) {
113 $html .= '<td class="new"><input type="checkbox" name="subscribe[]" value="'.$g.'"';
114 if (in_array($g, $banana->profile['subscribe'])) {
115 $html .= ' checked="checked"';
116 }
117 $html .= ' /></td>';
118 } elseif ($this->type == BANANA_GROUP_SUB) {
65d96b1f 119 $html .= '<td class="new">'.($new ? $new : '-').'</td>';
120 }
0eb1e7ef 121 $html .= '<td class="grp">' . makeHREF(Array('group' => $g), $g) . '</td><td class="dsc">' . $d[0] . '</td></tr>';
65d96b1f 122 }
958c7ab3 123
65d96b1f 124 $html .= '</table>';
125
958c7ab3 126 if ($show_form) {
33adc9f6 127 return '<form method="post" action="' . htmlentities(makeLink(Array())) . '">'
d5588318 128 . '<div class="center"><input type="submit" value="Valider" name="validsubs" /></div>'
a80c6fda 129 . $html . '<div class="center"><input type="submit" value="Valider" name="validsubs" /></div></form>';
958c7ab3 130 }
131
65d96b1f 132 return $html;
133 }
93d9186d 134}
135
d5588318 136// vim:set et sw=4 sts=4 ts=4
93d9186d 137?>