File: Index.pm

package info (click to toggle)
sporum 1.8b1-3.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,108 kB
  • ctags: 676
  • sloc: perl: 14,300; makefile: 52
file content (283 lines) | stat: -rw-r--r-- 8,250 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package Templates::Index;

use SmallPigVars qw($config);
use SPDB;
use Templates::Default;

use strict;
use vars qw(@ISA $template);

@ISA = qw(Templates::Default);

my $lang;

sub new{
  my ($class, $spcgi, $spdb, $pagetype) = @_;

  $template = Templates::Default->new($spcgi, $spdb, $pagetype);

  $template->{'STATE'} = $spcgi->{'STATE'};
  $template->{'spdb'} = $spdb || SPDB->new;
  
  $template->{'title'} = "";
  $template->{'refresh'} = "";

  bless $template, $class;

  $template->initialize();
  
  return $template;
}

#########################################################################
# --- Sun Dec 19 23:06:10 PST 1999
# ---
sub initialize{
  my ($template) = @_;
  
  my $pagefiles = {};
  $pagefiles->{'default'} = "default.temp";

  $template->{'pagefiles'} = $pagefiles;

  my $pagesubs = {};
  $pagesubs->{'default'} = \&whole;
  
  $template->{'pagesubs'} = $pagesubs;

  $lang = $template->{'lang'};
}

#########################################################################
# --- pagesubs
# ---
sub whole{
  $template->SUPER::print_standard_index();
  $template->print_iconbar(); 
  $template->print_space();
  $template->print_forums_list(); 
  $template->print_adjust_font();
}

sub print_iconbar{
  my ($template) = @_;
  my ($STATE, $spdb) = map{ $template->{$_} } qw(STATE spdb);
  my $theme = $template->{'theme'};

  my $userstatus = $STATE->{'userstatus'};
  my $DBH = $spdb->{'dbh'};

  my ($sp, $mp, $se);

  if($userstatus ne "anon"){
      $sp = qq|<img alt="$lang->{'show_new_posts'}" border=0 src="$theme->{'imagesdir'}/$theme->{'shownewposts_image'}">|;
      $mp = qq|<img alt="$lang->{'mark_all_threads3'}" border=0 src="$theme->{'imagesdir'}/$theme->{'markallposts_image'}">|;
      $sp = qq|<a href="$config->{'cgidir'}/index.cgi?op=shownewposts">$sp</a>|;
      $mp = qq|<a href="$config->{'cgidir'}/index.cgi?op=markallthreads">$mp</a>|;
  }
  else{
      $sp = qq|<img alt="$lang->{'show_new_posts'} ($lang->{'disabled'})" border=0 src="$theme->{'imagesdir'}/$theme->{'shownewposts_image'}">|;
      $mp = qq|<img alt="$lang->{'mark_all_threads3'} ($lang->{'disabled'})" border=0 src="$theme->{'imagesdir'}/$theme->{'markallposts_image'}">|;
  }

  $se = qq|<a href="$config->{'cgidir'}/search.cgi"><img alt="$lang->{'search'}" border=0 src="$theme->{'imagesdir'}/$theme->{'search_image'}"></a>|;

  $template->print_block_start($theme->{'dhdrcolor'}, $theme->{'dhdrcolor'});
  print qq|<TR><TD ALIGN="left">$sp&nbsp;$mp&nbsp;&nbsp;$se</TD>|;
  $template->print_block_end();
}

sub print_forums_list{
  my ($STATE, $spdb) = map{ $template->{$_} } qw(STATE spdb);
  my $DBH = $spdb->{'dbh'};
  my $theme = $template->{'theme'};
  
  $template->SUPER::print_block_start();

  my ($view, $lastlogon, $uid, $username, $userstatus, $op, $nps) = 
      map{ $STATE->{$_} } 
  qw(view lastlogon uid username userstatus op nps);
  my $lastlogonq = $DBH->quote($lastlogon);
  
  my ($cats) = $spdb->db_select_many_new(1, "catid, cattitle",
					 "Cats",
					 "", 
					 "ORDER BY catorder");

  # --- print btitle
  print btitle();

  # --- if there is no categories
  unless($cats){
      print  "<TR><TD colspan=4>$lang->{'no_categories'}</TD></TR>"
  }
  else{
  # --- loop through all the categories
  my $has_board = 0;
  while (my ($catid, $cattitle) = $cats->fetchrow_array){      
      my $catidq = $DBH->quote($catid);
      
      my $select = "B.sid, title, commentcount,  
                    date_format(lastmod, \"$config->{date_format}\"),
                    introtext, active, sorder";
      my $where = " B.sid=BC.sid AND BC.catid=$catidq ";
    
      # --- only public forum visible for anon
      $where .= "AND level>=60 AND active=1 "
	  if($userstatus eq "anon");
    
      # --- user forum visible for ruser, gmem, mod
      $where .= "AND level>=48 AND active=1 "
	  if($userstatus eq "ruser" ||
	     $userstatus =~ /gmem/ ||
	     $userstatus =~ /mod/);

      my ($boards, $from);
      $from .= " Boards AS B, BoardBelongToCat AS BC";

      # --- select public and user forums
      ($boards) = $spdb->db_select_many(1, 
					$select, 
					$from, 
					$where);
      
      # --- if user is a moderator in group private forums
      if($userstatus =~ /mod/){
	  $where = "BC.sid=M.sid AND uid=$uid AND active=1 AND
                    (level=32) AND B.sid=M.sid AND
                    BC.catid=$catidq ";
	  $from = "Boards AS B, BoardBelongToCat AS BC, Moderators AS M";
	  my ($boards1) = 
	      $spdb->db_select_many(1, $select, $from, $where);
	  unshift @$boards, @$boards1 if $boards1;      
      }
      
      # --- if user is a group mem in group private forums
      if($userstatus =~ /gmem/){
	  $where = "BC.sid=M.sid AND uid=$uid AND active=1 AND
                    (level=32) AND B.sid=M.sid AND
                    BC.catid=$catidq ";
	  $from = "Boards AS B, BoardBelongToCat AS BC, GroupMems AS M";
	  my ($boards1) = 
	      $spdb->db_select_many(1, $select, $from, $where);
	  unshift @$boards, @$boards1 if $boards1;      
      }    

      # --- sort the boards by sorder
      @$boards = sort { $a->[6] <=> $b->[6]; } @$boards if $boards;

      # --- no forums
      if(!$boards){
	  print qq| 
<TR BGCOLOR=$theme->{'lhdrcolor'}>
  <TD COLSPAN=4>
    <B>$cattitle</B>
  </TD>
</TR>  
<TR BGCOLOR=$theme->{'boxbgcolor'}>
  <TD WIDTH=10 BGCOLOR=$theme->{'lhdrcolor'}>&nbsp;
</TD><TD COLSPAN=3>
  $lang->{'no_forums'}</TD>
</TR>
<TR BGCOLOR=$theme->{'dhdrcolor'}><TD WIDTH=10></TD>
  <TD COLSPAN=3></TD></TR>
      | if $config->{'display_no_forums'} eq "yes";

      }
      # --- has forums
      else {
	  $has_board = 1;
    # --- display cattitle
	print qq!
<TR BGCOLOR=$theme->{'lhdrcolor'}>
  <TD CLASS=lbheader2 COLSPAN=4>
    <B>$cattitle</B>
  </TD>
      </TR>  
	  !;
	  
	  my $cnt = 0;
	  
	  foreach (@$boards) {
	      my ($sid, $title, $commentcount, $lastmod, $introtext) = @$_;
	      
	      $lastmod =~ s/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/$lang->{$1}/ig;
	      
	      my $sidq = $DBH->quote($sid);
	      $cnt++;
	      $lastmod = $lang->{'no_posts'} unless $lastmod;
	      
	      my $newpost;
	      
	      # --- deal with the cookie
	      if($userstatus ne "anon" && $lastlogon) {
		  my $cnt1 = $template->count_new_posts($sid, $nps);
		  
		  $newpost = "<b><FONT class=\"caution\">($cnt1 $lang->{'new'})</FONT></B>" 
		      if $cnt1;
	      }# --- end dealing with cookie
		  
		  # --- encode sid
		  my $sid1 = $template->url_encode($sid);
	      # --- deal with url and posts
	      my ($url, $tmp);
	      $url = "comments.cgi?op=topicslist&page=1&sid=$sid1&view=$view";
	      
	      $tmp = "<B>$title</B>";
	      $tmp = "<a href=\"$config->{'cgidir'}/$url\">$tmp</a>"
		  if($commentcount || (!$commentcount));
	      print bcontent($tmp, $commentcount, $newpost, 
			     $lastmod, $introtext, $sid, $uid);
	  }
	  unless($cnt){
	      print qq| 
<TR><TD WIDTH=10>&nbsp;</TD><TD COLSPAN=3>$lang->{'no_forums'}</TD></TR> 
    |;
	  }
      }
  } # --- end cats

  $spdb->db_handler_done($cats);

  } 
  $template->SUPER::print_block_end();
}

sub btitle{
  my $theme = $template->{'theme'};
  my $ret = qq| 
<TR BGCOLOR=$theme->{'dhdrcolor'} CELLPADDING=2>
  <TD WIDTH=$theme->{'empty_w'}>&nbsp;</TD>
  <TD CLASS=bheader2 WIDTH=$theme->{'forums_w'}>$lang->{'forums'}</TD>
  <TD WIDTH=$theme->{'posts_w'} CLASS=bheader2>$lang->{'posts'}</TD>
  <TD WIDTH=$theme->{'lastpost_w'} CLASS=bheader2>$lang->{'lastpost'}</TD>
</TR>
    |;
  return $ret;
}

sub bcontent{
  my ($title, $cnt, $np, $lastmod, $intro) = @_;
  my $theme = $template->{'theme'};
  my $ret .= qq!
<TR BGCOLOR=$theme->{'llhdrcolor'}>
  <TD WIDTH=$theme->{'empty_w'} BGCOLOR=$theme->{'lhdrcolor'}>&nbsp;</TD>
  <TD WIDTH=$theme->{'forums_w'}>$title</TD>
  <TD WIDTH=$theme->{'posts_w'}>$cnt $np</TD>
  <TD WIDTH=$theme->{'lastpost_w'}>$lastmod</TD></TR>
<TR BGCOLOR=$theme->{'llhdrcolor'}>
  <TD WIDTH=$theme->{'empty_w'} BGCOLOR=$theme->{'lhdrcolor'}>&nbsp;</TD>
  <TD WIDTH=$theme->{'forums_w'}>$intro</TD>
  <TD WIDTH=$theme->{'posts_w'}>&nbsp;</TD>
  <TD WIDTH=$theme->{'lastpost_w'}>&nbsp;</TD>
</TR>
<TR BGCOLOR=$theme->{'dhdrcolor'}><TD WIDTH=10></TD>
  <TD COLSPAN=3>
</TD></TR>
  !;	
  return $ret;
}

return 1;