| 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 | |
| 13 | define ( 'BANANA_GROUP_ALL', 0 ); |
| 14 | define ( 'BANANA_GROUP_SUB', 1 ); |
| 15 | define ( 'BANANA_GROUP_NEW', 2 ); |
| 16 | |
| 17 | class BananaGroups { |
| 18 | /** group list */ |
| 19 | var $overview = Array(); |
| 20 | /** last update */ |
| 21 | var $date; |
| 22 | |
| 23 | var $type; |
| 24 | |
| 25 | /** constructor |
| 26 | */ |
| 27 | |
| 28 | function BananaGroups($_type = BANANA_GROUP_SUB) { |
| 29 | global $banana; |
| 30 | |
| 31 | $this->type = $_type; |
| 32 | $desc = $banana->nntp->xgtitle(); |
| 33 | |
| 34 | if ($_type == BANANA_GROUP_NEW) { |
| 35 | $list = $banana->nntp->newgroups($banana->profile['lastnews']); |
| 36 | } else { |
| 37 | $list = $banana->nntp->liste(); |
| 38 | if ($_type == BANANA_GROUP_SUB) { |
| 39 | $mylist = Array(); |
| 40 | foreach ($banana->profile['subscribe'] as $g) { |
| 41 | if (isset($list[$g])) { |
| 42 | $mylist[$g] = $list[$g]; |
| 43 | } |
| 44 | } |
| 45 | $list = $mylist; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | foreach ($list as $g=>$l) { |
| 50 | $this->overview[$g][0] = isset($desc[$g]) ? $desc[$g] : '-'; |
| 51 | $this->overview[$g][1] = $l[0]; |
| 52 | } |
| 53 | ksort($this->overview); |
| 54 | |
| 55 | if (empty($this->overview) && $_type == BANANA_GROUP_SUB) { |
| 56 | $this = new BananaGroups(BANANA_GROUP_ALL); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** updates overview |
| 61 | * @param date INTEGER date of last update |
| 62 | */ |
| 63 | function update($_date) { |
| 64 | global $banana; |
| 65 | $serverdate = $banana->nntp->date(); |
| 66 | if (!$serverdate) $serverdate=time(); |
| 67 | $newlist = $banana->nntp->newgroups($_date); |
| 68 | if (!$newlist) return false; |
| 69 | $this->date = $serverdate; |
| 70 | foreach (array_keys($newlist) as $g) { |
| 71 | $groupstat = $banana->nntp->group($g); |
| 72 | $groupdesc = $banana->nntp->xgtitle($g); |
| 73 | $this->overview[$g][0]=($groupdesc?$groupdesc:"-"); |
| 74 | $this->overview[$g][1]=$groupstat[0]; |
| 75 | } |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | function to_html($show_form = false) |
| 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>'; |
| 88 | if ($show_form) { |
| 89 | $html .= _b_('Abo.').'</th><th>'; |
| 90 | } elseif ($this->type == BANANA_GROUP_SUB) { |
| 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>"; |
| 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) { |
| 110 | $html .= '<td class="new">'.($new ? $new : '-').'</td>'; |
| 111 | } |
| 112 | $html .= "<td class='grp'><a href='?group=$g'>$g</a></td><td class='dsc'>{$d[0]}</td></tr>"; |
| 113 | } |
| 114 | |
| 115 | $html .= '</table>'; |
| 116 | |
| 117 | if ($show_form) { |
| 118 | return '<form method="post" action="'.$_SERVER['PHP_SELF'].'"><div class="center"><input type="submit" /></div>' |
| 119 | .$html.'<div class="center"><input type="submit" /></div></form>'; |
| 120 | } |
| 121 | |
| 122 | return $html; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | ?> |