2 /********************************************************************************
3 * include/groups.inc.php : class for group lists
4 * ------------------------
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
10 /** class for group lists
13 define ( 'BANANA_GROUP_ALL', 0 );
14 define ( 'BANANA_GROUP_SUB', 1 );
15 define ( 'BANANA_GROUP_NEW', 2 );
19 var $overview = Array();
28 function BananaGroups($_type = BANANA_GROUP_SUB
) {
32 $desc = $banana->nntp
->xgtitle();
36 if (empty($this->overview
) && $_type == BANANA_GROUP_SUB
) {
37 $this->type
= BANANA_GROUP_ALL
;
48 if ($this->type
== BANANA_GROUP_NEW
) {
49 $list = $banana->nntp
->newgroups($banana->profile
['lastnews']);
51 $list = $banana->nntp
->liste();
52 if ($this->type
== BANANA_GROUP_SUB
) {
54 foreach ($banana->profile
['subscribe'] as $g) {
55 if (isset($list[$g])) {
56 $mylist[$g] = $list[$g];
63 foreach ($list as $g=>$l) {
64 $this->overview
[$g][0] = isset($desc[$g]) ?
$desc[$g] : '-';
65 $this->overview
[$g][1] = $l[0];
67 ksort($this->overview
);
71 * @param date INTEGER date of last update
73 function update($_date) {
75 $serverdate = $banana->nntp
->date();
76 if (!$serverdate) $serverdate=time();
77 $newlist = $banana->nntp
->newgroups($_date);
78 if (!$newlist) return false
;
79 $this->date
= $serverdate;
80 foreach (array_keys($newlist) as $g) {
81 $groupstat = $banana->nntp
->group($g);
82 $groupdesc = $banana->nntp
->xgtitle($g);
83 $this->overview
[$g][0]=($groupdesc?
$groupdesc:"-");
84 $this->overview
[$g][1]=$groupstat[0];
89 function to_html($show_form = false
)
92 if (empty($this->overview
)) {
96 $html = '<table class="bicol banana_group" cellspacing="0" cellpadding="2">'."\n";
97 $html .= '<tr><th>'._b_('Total').'</th><th>';
99 $html .= _b_('Abo.').'</th><th>';
100 } elseif ($this->type
== BANANA_GROUP_SUB
) {
101 $html .= _b_('Nouveaux').'</th><th>';
103 $html .= _b_('Nom').'</th><th>'._b_('Description').'</th></tr>'."\n";
106 foreach ($this->overview
as $g => $d) {
108 $ginfo = $banana->nntp
->group($g);
109 $new = count($banana->nntp
->newnews($banana->profile
['lastnews'],$g));
111 $html .= '<tr class="'.($b ?
'pair' : 'impair').'">'."\n";
112 $html .= "<td class='all'>{$ginfo[0]}</td>";
114 $html .= '<td class="new"><input type="checkbox" name="subscribe[]" value="'.$g.'"';
115 if (in_array($g, $banana->profile
['subscribe'])) {
116 $html .= ' checked="checked"';
119 } elseif ($this->type
== BANANA_GROUP_SUB
) {
120 $html .= '<td class="new">'.($new ?
$new : '-').'</td>';
122 $html .= '<td class="grp">' . makeHREF(Array('group' => $g), $g) . '</td><td class="dsc">' . $d[0] . '</td></tr>';
128 return '<form method="post" action="' . htmlentities(makeLink(Array())) . '">'
129 . '<div class="center"><input type="submit" value="Valider" name="validsubs" /></div>'
130 . $html . '<div class="center"><input type="submit" value="Valider" name="validsubs" /></div></form>';
137 // vim:set et sw=4 sts=4 ts=4