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 |
13 | define ( 'BANANA_GROUP_ALL', 0 ); |
14 | define ( 'BANANA_GROUP_SUB', 1 ); |
15 | define ( 'BANANA_GROUP_NEW', 2 ); |
16 | |
d4c19591 |
17 | class 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; |
32 | $desc = $banana->nntp->xgtitle(); |
33 | |
34 | if ($_type == BANANA_GROUP_NEW) { |
2dbc0167 |
35 | $list = $banana->nntp->newgroups($banana->profile['lastnews']); |
d4c19591 |
36 | } else { |
2dbc0167 |
37 | $list = $banana->nntp->liste(); |
65d96b1f |
38 | if ($_type == BANANA_GROUP_SUB) { |
39 | $mylist = Array(); |
2dbc0167 |
40 | foreach ($banana->profile['subscribe'] as $g) { |
41 | if (isset($list[$g])) { |
42 | $mylist[$g] = $list[$g]; |
43 | } |
44 | } |
45 | $list = $mylist; |
46 | } |
8f98c1e8 |
47 | } |
2dbc0167 |
48 | |
7e12aea5 |
49 | foreach ($list as $g=>$l) { |
2dbc0167 |
50 | $this->overview[$g][0] = isset($desc[$g]) ? $desc[$g] : '-'; |
51 | $this->overview[$g][1] = $l[0]; |
8f98c1e8 |
52 | } |
65d96b1f |
53 | ksort($this->overview); |
54 | |
55 | if (empty($this->overview) && $_type == BANANA_GROUP_SUB) { |
56 | $this = new BananaGroups(BANANA_GROUP_ALL); |
57 | } |
93d9186d |
58 | } |
93d9186d |
59 | |
d4c19591 |
60 | /** updates overview |
d4c19591 |
61 | * @param date INTEGER date of last update |
62 | */ |
2dbc0167 |
63 | function update($_date) { |
64 | global $banana; |
65 | $serverdate = $banana->nntp->date(); |
d4c19591 |
66 | if (!$serverdate) $serverdate=time(); |
2dbc0167 |
67 | $newlist = $banana->nntp->newgroups($_date); |
d4c19591 |
68 | if (!$newlist) return false; |
69 | $this->date = $serverdate; |
70 | foreach (array_keys($newlist) as $g) { |
2dbc0167 |
71 | $groupstat = $banana->nntp->group($g); |
72 | $groupdesc = $banana->nntp->xgtitle($g); |
d4c19591 |
73 | $this->overview[$g][0]=($groupdesc?$groupdesc:"-"); |
74 | $this->overview[$g][1]=$groupstat[0]; |
75 | } |
76 | return true; |
93d9186d |
77 | } |
65d96b1f |
78 | |
958c7ab3 |
79 | function to_html($show_form = false) |
65d96b1f |
80 | { |
81 | global $banana; |
82 | if (empty($this->overview)) { |
83 | return; |
84 | } |
85 | |
86 | $html = '<table class="bicol banana_group" cellspacing="0" cellpadding="2">'."\n"; |
87 | $html .= '<tr><th>'._b_('Total').'</th><th>'; |
958c7ab3 |
88 | if ($show_form) { |
89 | $html .= _b_('Abo.').'</th><th>'; |
90 | } elseif ($this->type == BANANA_GROUP_SUB) { |
65d96b1f |
91 | $html .= _b_('Nouveaux').'</th><th>'; |
92 | } |
93 | $html .= _b_('Nom').'</th><th>'._b_('Description').'</th></tr>'."\n"; |
94 | |
95 | $b = true; |
96 | foreach ($this->overview as $g => $d) { |
97 | $b = !$b; |
98 | $ginfo = $banana->nntp->group($g); |
99 | $new = count($banana->nntp->newnews($banana->profile['lastnews'],$g)); |
100 | |
101 | $html .= '<tr class="'.($b ? 'pair' : 'impair').'">'."\n"; |
102 | $html .= "<td class='all'>{$ginfo[0]}</td>"; |
958c7ab3 |
103 | if ($show_form) { |
104 | $html .= '<td class="new"><input type="checkbox" name="subscribe[]" value="'.$g.'"'; |
105 | if (in_array($g, $banana->profile['subscribe'])) { |
106 | $html .= ' checked="checked"'; |
107 | } |
108 | $html .= ' /></td>'; |
109 | } elseif ($this->type == BANANA_GROUP_SUB) { |
65d96b1f |
110 | $html .= '<td class="new">'.($new ? $new : '-').'</td>'; |
111 | } |
8d99c683 |
112 | $html .= "<td class='grp'><a href='?group=$g'>$g</a></td><td class='dsc'>{$d[0]}</td></tr>"; |
65d96b1f |
113 | } |
958c7ab3 |
114 | |
65d96b1f |
115 | $html .= '</table>'; |
116 | |
958c7ab3 |
117 | if ($show_form) { |
4cc7f778 |
118 | return '<form method="post" action="?"><div class="center"><input type="submit" /></div>' |
958c7ab3 |
119 | .$html.'<div class="center"><input type="submit" /></div></form>'; |
120 | } |
121 | |
65d96b1f |
122 | return $html; |
123 | } |
93d9186d |
124 | } |
125 | |
126 | ?> |