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