~davidstrauss/drupal/195416-per-connection-prefixes

« back to all changes in this revision

Viewing changes to webboard.php

  • Committer: dries
  • Date: 2000-05-18 19:51:59 UTC
  • Revision ID: vcs-imports@canonical.com-20000518195159-c63e8ca79202a10c
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<? 
 
2
 
 
3
include "functions.inc";
 
4
include "theme.inc";
 
5
 
 
6
$theme->header();
 
7
 
 
8
### parameters:
 
9
$timeout = 70000;
 
10
$width = "100%";
 
11
 
 
12
#####
 
13
# Syntax.......: text2html(number);
 
14
# Description..: Converst ascii text into HTML.
 
15
#
 
16
function text2html($text) {
 
17
  return nl2br(stripslashes(trim($text)));
 
18
}
 
19
 
 
20
function displayThread($id, $current = 0) {
 
21
  global $PHP_SELF, $timeout, $new, $theme;
 
22
  
 
23
  $query = "SELECT * FROM webboard WHERE topic_id = $id";
 
24
  $result = mysql_query($query);
 
25
 
 
26
  if (mysql_num_rows($result)) {
 
27
    ### fields from MySQL table:
 
28
    $author = text2html(mysql_result($result, 0, "author"));
 
29
    $subject = text2html(mysql_result($result, 0, "subject"));
 
30
    $create_dt = mysql_result($result, 0, "create_dt");
 
31
    $date = date("D, M d - H:i:s", $create_dt);
 
32
 
 
33
    ### highlight current post:
 
34
    if ($id == $current) print "<FONT COLOR=\"$theme->hlcolor2\">";
 
35
 
 
36
    print "<UL>\n";
 
37
 
 
38
    ### indicate new post:
 
39
    if (time() - $create_dt > $timeout) print " <LI><A HREF=\"$PHP_SELF?display=$id\">$subject</A> by <B>$author</B> ($date)</LI>\n";
 
40
    else print " <LI><A HREF=\"$PHP_SELF?display=$id\">$subject</A> by <B>$author</B> ($date) &nbsp; <FONT COLOR=\"$theme->hlcolor2\">new</FONT></LI>\n";
 
41
 
 
42
    ### highlight current post:
 
43
    if ($id == $current)  print "</FONT>";
 
44
  }
 
45
 
 
46
  $query = "SELECT DISTINCT topic_id FROM webboard WHERE parent_id = $id ORDER BY create_dt ASC";
 
47
  $result = mysql_query($query);
 
48
  
 
49
  ### recursive call to process childeren:
 
50
  while ($row = mysql_fetch_object($result)) displayThread($row->topic_id, $current);
 
51
 
 
52
  print "</UL>\n";
 
53
}
 
54
 
 
55
 
 
56
#####
 
57
# Syntax.......: displayThreadedOverview(id)
 
58
# Description..: Displays all 'child'-posts of the 'root'-post specified by
 
59
#                start_id.  The posts are displayed in a typical threaded 
 
60
#                style.
 
61
#
 
62
function displayThreadedOverview($id = 0) {
 
63
  global $PHP_SELF, $active, $timeout, $new, $width, $theme;
 
64
   
 
65
 
 
66
  $current = getCurrentPosts();
 
67
  $total = getTotalPosts();
 
68
 
 
69
  $query = "SELECT DISTINCT root_id FROM webboard WHERE parent_id = $id ORDER BY create_dt DESC";
 
70
  $result = mysql_query($query);
 
71
 
 
72
  print "<TABLE BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"4\" WIDTH=\"$width\">\n";
 
73
  print " <TR BGCOLOR=\"$theme->bgcolor1\"><TD>\n";
 
74
  print "  <TABLE BORDER=\"0\" CELLPADDING=\"4\" WIDTH=\"100%\">\n";
 
75
  print "   <TR>\n";
 
76
  print "    <TD ALIGN=\"left\"><FONT COLOR=\"$theme->fgcolor1\" SIZE=\"+1\"><B>Threaded overview</B></FONT></TD>\n";
 
77
  print "    <TD ALIGN=\"right\">[ <A NAME=\"top\"><A HREF=\"#post\"><FONT COLOR=\"$theme->hlcolor1\">post</FONT></A></A> | <A HREF=\"$PHP_SELF?threaded=0\"><FONT COLOR=\"$theme->hlcolor1\">chronological</FONT></A> ]</FONT></TD>\n";
 
78
  print "   </TR>\n";
 
79
  print "  </TABLE>\n";
 
80
  print " </TD></TR>\n";
 
81
 
 
82
  while ($row = mysql_fetch_object($result)) {
 
83
    print " <TR><TD BGCOLOR=\"$theme->bgcolor2\">\n";
 
84
    displayThread($row->root_id);
 
85
    print " </TD></TR>\n";
 
86
  }
 
87
 
 
88
  print " <TR BGCOLOR=\"$theme->bgcolor1\"><TD>\n";
 
89
  print "  <TABLE BORDER=\"0\" CELLPADDING=\"4\" WIDTH=\"100%\">\n";
 
90
  print "   <TR>\n";
 
91
  print "    <TD ALIGN=\"left\"><FONT COLOR=\"$theme->fgcolor1\"[ <A HREF=\"javascript: history.back()\"><FONT COLOR=\"$theme->hlcolor1\">back</FONT></A> | <A HREF=\"/\"><FONT COLOR=\"$theme->hlcolor1\">home</FONT></A> | <A NAME=\"post\"><A HREF=\"#top\"><FONT COLOR=\"$theme->hlcolor1\">top</FONT></A></A> ]</FONT></TD>\n";
 
92
  print "    <TD ALIGN=\"center\"><FONT COLOR=\"$theme->fgcolor1\">[ current: $current | total: $total ]</FONT></TD>\n";
 
93
  print "    <TD ALIGN=\"right\"><FONT COLOR=\"$theme->fgcolor1\">[ <A HREF=\"$PHP_SELF?threaded=0\"><FONT COLOR=\"$theme->hlcolor1\">chronological</FONT></A> | <A HREF=\"$PHP_SELF?threaded=1\"><FONT COLOR=\"$theme->hlcolor1\">threaded</FONT></A> ]</FONT></TD>\n";
 
94
  print "   </TR>\n";
 
95
  print "  </TABLE>\n";
 
96
  print " </TD></TR>\n";
 
97
  print "</TABLE>\n"; 
 
98
}
 
99
 
 
100
 
 
101
#####
 
102
# Syntax.......: displayChronologicalOverview
 
103
# Description..: Displays all 'child'-posts of the 'root'-post specified by
 
104
#                start_id.  The posts are displayed chronological in a
 
105
#                typical mailing-list alike style.
 
106
#
 
107
function displayChronologicalOverview($id = 0) {
 
108
  global $PHP_SELF, $theme, $timeout, $width;
 
109
 
 
110
  $query = "SELECT DISTINCT topic_id, subject, message, author, create_dt FROM webboard ORDER BY create_dt DESC";
 
111
  $result = mysql_query($query);
 
112
 
 
113
  $current = getCurrentPosts();
 
114
  $total = getTotalPosts();
 
115
 
 
116
  print "<TABLE BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"4\" WIDTH=\"$width\">\n";
 
117
  print " <TR BGCOLOR=\"$theme->bgcolor1\"><TD COLSPAN=\"3\">\n";
 
118
  print " <TABLE BORDER=\"0\" CELLPADDING=\"4\" WIDTH=\"100%\">\n";
 
119
  print "  <TR>\n";
 
120
  print "   <TD ALIGN=\"left\"><FONT COLOR=\"$theme->fgcolor1\" SIZE=\"+1\"><B>Chronological overview</B></FONT></TD>\n"; 
 
121
  print "   <TD ALIGN=\"right\"><FONT COLOR=\"$theme->fgcolor1\"[ <A NAME=\"top\"><A HREF=\"#post\"><FONT COLOR=\"$theme->hlcolor1\">post</FONT></A></A> | <A HREF=\"$PHP_SELF?threaded=1\"><FONT COLOR=\"$theme->hlcolor1\">threaded</FONT></A> ]</FONT></TD>\n";
 
122
  print "  </TR>\n";
 
123
  print " </TABLE>\n";
 
124
  print " </TD></TR>\n";
 
125
 
 
126
  while ($row = mysql_fetch_row($result)) {
 
127
    list($topic_id, $subject, $message, $author, $create_dt) = $row;
 
128
    $subject = text2html($subject);
 
129
    $author = text2html($author);
 
130
    $date = date("d/m/y - h:i:s", $create_dt);
 
131
 
 
132
    ### indicate new post:
 
133
    if (time() - $create_dt > $timeout) print "<TR><TD BGCOLOR=\"$theme->bgcolor2\"><A HREF=\"$PHP_SELF?display=$topic_id\">$subject</A></TD><TD BGCOLOR=\"$theme->bgcolor2\">$author</TD><TD BGCOLOR=\"$theme->bgcolor2\" NOWRAP>$date</TD><TD></TD></TR>\n";
 
134
    else print "<TR><TD BGCOLOR=\"$theme->bgcolor2\"><A HREF=\"$PHP_SELF?display=$topic_id\">$subject</A></TD><TD BGCOLOR=\"$$theme->bgcolor2\">$author</TD><TD BGCOLOR=\"$theme->bgcolor2\" NOWRAP>$date</TD><TD><FONT COLOR=\"$theme->hlcolor2\">new</FONT></TD></TR>\n";
 
135
  }
 
136
  
 
137
  print " <TR BGCOLOR=\"$theme->bgcolor1\"><TD COLSPAN=\"3\">\n";
 
138
  print "  <TABLE BORDER=\"0\" CELLPADDING=\"4\" WIDTH=\"100%\">\n";
 
139
  print "   <TR>\n";
 
140
  print "    <TD ALIGN=\"left\"><FONT COLOR=\"$theme->fgcolor1\"[ <A HREF=\"javascript: history.back()\"><FONT COLOR=\"$theme->hlcolor1\">back</FONT></A> | <A HREF=\"/\"><FONT COLOR=\"$theme->hlcolor1\">home</FONT></A> | <A NAME=\"post\"><A HREF=\"#top\"><FONT COLOR=\"$theme->hlcolor1\">top</FONT></A></A> ]</FONT></TD>\n";
 
141
  print "    <TD ALIGN=\"center\"><FONT COLOR=\"$theme->fgcolor1\"[ current: $current | total: $total ]</FONT></TD>\n";
 
142
  print "    <TD ALIGN=\"right\"><FONT COLOR=\"$theme->fgcolor1\"[ <A HREF=\"$PHP_SELF?threaded=0\"><FONT COLOR=\"$theme->hlcolor1\">chronological</FONT></A> | <A HREF=\"$PHP_SELF?threaded=1\"><FONT COLOR=\"$theme->hlcolor1\">threaded</FONT></A> ]</FONT></TD>\n";
 
143
  print "   </TR>\n";
 
144
  print "  </TABLE>\n";
 
145
  print " </TD></TR>\n";
 
146
  print "</TABLE>\n"; 
 
147
}
 
148
 
 
149
#####
 
150
# Syntax.......: getRecentThreads
 
151
# Description..: 
 
152
#
 
153
function getRecentThreads($number = 5, $filename = "webboard.php") {
 
154
  global $timeout, $theme;
 
155
 
 
156
  $query = "SELECT * FROM webboard WHERE parent_id = 0 ORDER BY create_dt DESC LIMIT $number";
 
157
  $result = mysql_query($query);
 
158
  
 
159
  $rval = "<UL>\n";
 
160
 
 
161
  while ($object = mysql_fetch_object($result)) {
 
162
    ### fields from MySQL table:
 
163
    $topic_id = $object->topic_id;
 
164
    $author = text2html($object->author);
 
165
    $subject = text2html($object->subject);
 
166
    $create_dt = $object->create_dt;
 
167
    $date = date("d/m/y - h:i:s", $create_dt);
 
168
    $size = getThreadSize($object->topic_id);
 
169
 
 
170
    ### indicate new post:
 
171
    if (time() - $create_dt > $timeout) $rval .= " <LI><A HREF=\"$filename?display=$topic_id\">$subject</A> by <B>$author</B> ($date) [$size]</LI>\n";
 
172
    else $rval .= " <LI><A HREF=\"$filename?display=$topic_id\">$subject</A> by <B>$author</B> ($date) [$size] &nbsp; <FONT COLOR=\"$theme->hlcolor2\">new</FONT></LI>\n";
 
173
  }
 
174
 
 
175
  $rval .= "</UL>\n";
 
176
 
 
177
  return $rval;
 
178
}
 
179
 
 
180
#####
 
181
# Syntax.......:
 
182
# Description..:
 
183
#
 
184
function displayAdminOverview($id = 0) {
 
185
  global $PHP_SELF;
 
186
 
 
187
  $query = "SELECT DISTINCT t.topic_id, t.parent_id, t.root_id, t.subject, t.message, t.author, t.hostname, t.create_dt FROM webboard t, webboard r WHERE t.parent_id = $id ORDER BY create_dt DESC";
 
188
  $result = mysql_query($query);
 
189
 
 
190
  print "<UL>\n";    
 
191
  while ($row = mysql_fetch_row($result)) {
 
192
    list($topic_id, $parent_id, $root_id, $subject, $message, $author, $hostname, $create_dt) = $row;
 
193
    $date = date("D, M d - H:i:s", $create_dt);
 
194
    print " <LI><INPUT TYPE=\"checkbox\" NAME=\"delete\" VALUE=\"$topic_id\"> <A HREF=\"$PHP_SELF?display=$topic_id\">$subject</A> by <B>$author</B> ($date)\n";
 
195
    displayAdminOverview($topic_id);
 
196
  }
 
197
  print "</UL>\n";
 
198
}
 
199
 
 
200
#####
 
201
# Syntax.......: displayMessage(id)
 
202
# Description..:
 
203
#
 
204
function displayMessage($id = 0) {
 
205
  global $PHP_SELF, $theme, $width;
 
206
 
 
207
  $query = "SELECT * FROM webboard WHERE topic_id = $id";
 
208
  $result = mysql_query($query);
 
209
 
 
210
  if (mysql_num_rows($result)) {
 
211
    ### fields from MySQL table:
 
212
    $author = text2html(mysql_result($result, 0, "author"));
 
213
    $subject = text2html(mysql_result($result, 0, "subject"));
 
214
    $message = text2html(mysql_result($result, 0, "message"));
 
215
    $hostname = text2html(mysql_result($result, 0, "hostname"));
 
216
    $date = date("l, F d - h:i:s A", mysql_result($result, 0, "create_dt"));
 
217
    $topic_id = mysql_result($result, 0, "topic_id");
 
218
    $root_id = mysql_result($result, 0, "root_id");
 
219
 
 
220
    ### previous and next posts:
 
221
    $prev_msg = getPrevPost($topic_id);
 
222
    $next_msg = getNextPost($topic_id);
 
223
 
 
224
    ### previous and next threads:
 
225
    $next_thread = getNextThread($root_id);
 
226
    $prev_thread = getPrevThread($root_id);
 
227
 
 
228
    ### generate output table:
 
229
    print "<TABLE BORDER=\"0\" CELLPADDING=\"4\" WIDTH=\"$width\">\n";
 
230
    print " <TR BGCOLOR=\"$theme->bgcolor1\"><TD COLSPAN=\"2\"><TABLE BORDER=\"0\" WIDTH=\"100%\"><TR><TD><FONT COLOR=\"$theme->fgcolor1\"><A NAME=\"top\">Current message</A></FONT></TD><TD ALIGN=\"right\"><FONT COLOR=\"$theme->fgcolor1\">[ <A HREF=\"$PHP_SELF?display=$prev_msg\"><FONT COLOR=\"$theme->hlcolor1\">previous message</FONT></A> | <A HREF=\"$PHP_SELF?display=$next_msg\"><FONT COLOR=\"$theme->hlcolor1\">next message</FONT></A> ]</FONT></TD></TR></TABLE></TD></TR>\n";
 
231
    print " <TR BGCOLOR=\"$theme->bgcolor2\"><TD COLSPAN=\"2\">Subject: <B>$subject</B></TD></TR>\n";
 
232
    print " <TR BGCOLOR=\"$theme->bgcolor2\"><TD><FONT COLOR=\"$theme->hlcolor2\">by <B>$author</B> on $date</FONT></TD><TD ALIGN=\"right\">Hostname/IP: $hostname</TD></TR>\n";
 
233
    print " <TR BGCOLOR=\"$theme->bgcolor2\"><TD COLSPAN=\"2\">$message</TD></TR>\n";
 
234
    print " <TR><TD COLSPAN=\"2\"></TD></TR>\n";
 
235
    print " <TR BGCOLOR=\"$theme->bgcolor1\"><TD COLSPAN=\"2\"><TABLE BORDER=\"0\" WIDTH=\"100%\"><TR><TD><FONT COLOR=\"$theme->fgcolor1\">Current thread</FONT></TD><TD ALIGN=\"right\"><FONT COLOR=\"$theme->fgcolor1\">[ <A HREF=\"$PHP_SELF?display=$prev_thread\"><FONT COLOR=\"$theme->hlcolor1\">previous thread</FONT></A> | <A HREF=\"$PHP_SELF?display=$next_thread\"><FONT COLOR=\"$theme->hlcolor1\">next thread</FONT></A> ]</FONT></TD></TR></TABLE></TD></TR>\n";
 
236
    print " <TR BGCOLOR=\"$theme->bgcolor2\"><TD COLSPAN=\"2\">\n";    
 
237
    displayThread($root_id, $id);
 
238
    print " </TD></TR>\n";
 
239
    print " <TR BGCOLOR=\"$theme->bgcolor2\"><TD COLSPAN=\"2\"></TD></TR>\n";    
 
240
    print " <TR BGCOLOR=\"$theme->bgcolor1\"><TD COLSPAN=\"2\">\n";
 
241
    print "  <TABLE BORDER=\"0\" CELLPADDING=\"4\" WIDTH=\"100%\">\n";
 
242
    print "   <TR>\n";
 
243
    print "    <TD ALIGN=\"left\"><FONT COLOR=\"$theme->fgcolor1\">[ <A HREF=\"javascript: history.back()\"><FONT COLOR=\"$theme->hlcolor1\">back</FONT></A> | <A HREF=\"/\"><FONT COLOR=\"$theme->hlcolor1\">home</FONT></A> | <A HREF=\"#top\"><FONT COLOR=\"$theme->hlcolor1\">top</FONT></A> ]</FONT></TD>\n";
 
244
    print "    <TD ALIGN=\"center\">&nbsp;</TD>\n";
 
245
    print "    <TD ALIGN=\"right\"><FONT COLOR=\"$theme->fgcolor1\">[ <A HREF=\"$PHP_SELF?threaded=0\"><FONT COLOR=\"$theme->hlcolor1\">chronological</FONT></A> | <A HREF=\"$PHP_SELF?threaded=1\"><FONT COLOR=\"$theme->fgcolor1\">threaded</FONT></A> ]</FONT></TD>\n";
 
246
    print "   </TR>\n";
 
247
    print "  </TABLE>\n";
 
248
    print " </TD></TR>\n";
 
249
    print "</TABLE>\n"; 
 
250
    print "<BR><BR>\n"; 
 
251
  }
 
252
  else {
 
253
    print "<P><B>Error:</B> no such message in database.  The message you are looking for might have expired and does no longer exsist, or might have been explicitly removed by the webboard administrator.</P>";
 
254
  }
 
255
}
 
256
 
 
257
#####
 
258
# Syntax.......: printForm(id)
 
259
# Description..:
 
260
#
 
261
function printForm($id = 0, $author = "", $signature = "") {
 
262
  global $PHP_SELF;
 
263
 
 
264
  ### initialize variables:
 
265
  $parent_id = 0;
 
266
  $root_id = 0;
 
267
 
 
268
  if ($id) {
 
269
    $query = "SELECT * FROM webboard WHERE topic_id = $id";
 
270
    $result = mysql_query($query);
 
271
 
 
272
    if (mysql_num_rows($result)) {
 
273
      ### fields from MySQL table:
 
274
      $subject = text2html(mysql_result($result, 0, "subject"));
 
275
      $subject = "Re: $subject";
 
276
      $parent_id = $id;
 
277
      $root_id = mysql_result($result, 0, "root_id");
 
278
    }
 
279
  }
 
280
 
 
281
  print "<FORM METHOD=\"post\" ACTION=\"$PHP_SELF?post\">\n";
 
282
  print " <TABLE BORDER=\"0\" CELLSPACING=\"10\">\n";
 
283
  print "  <TR><TD ALIGN=\"right\" VALIGN=\"top\">Author:</TD><TD>$author</TD></TR>\n";
 
284
  print "  <TR><TD ALIGN=\"right\" VALIGN=\"top\">Subject:</TD><TD><INPUT TYPE=\"text\" NAME=\"subject\" MAXLENGTH=\"75\" SIZE=\"50\" VALUE=\"$subject\"></TD></TR>\n";
 
285
  print "  <TR><TD ALIGN=\"right\" VALIGN=\"top\">Message:</TD><TD><TEXTAREA NAME=\"message\" COLS=\"45\" ROWS=\"10\" WRAP=\"virtual\">$signature</TEXTAREA></TR>\n";
 
286
  print "  <TR>\n";
 
287
  print "   <TD ALIGN=\"center\" COLSPAN=\"2\">\n";
 
288
  print "    <INPUT TYPE=\"hidden\" NAME=\"author\" VALUE=\"$author\">\n";
 
289
  print "    <INPUT TYPE=\"hidden\" NAME=\"parent_id\" VALUE=\"$parent_id\">\n";
 
290
  print "    <INPUT TYPE=\"hidden\" NAME=\"root_id\" VALUE=\"$root_id\">\n";
 
291
  print "    <INPUT TYPE=\"submit\" NAME=\"post\" VALUE=\"Post message\">\n";
 
292
  print "   </TD>\n";
 
293
  print "  </TR>\n";
 
294
  print " </TABLE>\n";
 
295
  print "</FORM>\n";
 
296
}
 
297
 
 
298
/*
 
299
#####
 
300
# Syntax.......: fixQuotes(text)
 
301
# Description..:
 
302
#
 
303
function fixQuotes ($what = "") {
 
304
  $what = ereg_replace("'","''",$what);
 
305
  $counter = 0;
 
306
  while (eregi("\\\\'", $what) && $counter < 10) { $what = ereg_replace("\\\\'","'",$what); }
 
307
  return $what;
 
308
}
 
309
*/
 
310
 
 
311
#####
 
312
# Syntax.......: postMessage(subject, author, message, parent_id, root_id, html_tags)
 
313
# Description..:
 
314
#
 
315
function postMessage ($subject="[no subject]", $author = "Anonymous Chicken", $message, $parent_id = 0, $root_id = 0, $html_tags = "0") {
 
316
 
 
317
  if ($html_tags) {
 
318
    $subject = fixQuotes($subject);
 
319
    $message = fixQuotes($message);
 
320
    $author = fixQuotes($author);
 
321
    $date = time();
 
322
  }
 
323
  else {
 
324
    $subject = fixQuotes(strip_tags($subject));
 
325
    $message = fixQuotes(strip_tags($message));
 
326
    $author = fixQuotes(strip_tags($author));
 
327
    $date = time();
 
328
  }
 
329
 
 
330
  ### [NT]-feature:
 
331
  if (!$message) $subject .= "&nbsp; [NT]";
 
332
 
 
333
  ### 'Anonymous Chicken'-feature:
 
334
  if (!$author) $author = "Anonymous Chicken";
 
335
 
 
336
  ### insert new post:
 
337
  $query = "INSERT INTO webboard (subject, message, parent_id, root_id, author, hostname, create_dt) VALUES ('$subject', '$message', $parent_id, $root_id, '$author', '".getenv("REMOTE_ADDR")."', $date)";
 
338
 
 
339
  $result = mysql_query($query);
 
340
 
 
341
  if (!$result) {
 
342
    print "<P><B>Error:</B> failed to perform query!</P>\n";
 
343
  }
 
344
 
 
345
  $result = mysql_query("select last_insert_id()");
 
346
  list($topic_id) = mysql_fetch_array($result);
 
347
 
 
348
  if (isset($topic_id) && ($topic_id > 0)) {
 
349
    if ($root_id == 0) {
 
350
       $root_id = $topic_id;
 
351
       mysql_query("UPDATE webboard SET root_id=$topic_id WHERE topic_id = $topic_id AND root_id=0");
 
352
    }
 
353
  }
 
354
  else {
 
355
    print "<P><B>Error:</B> failed to perform query!</P>\n";
 
356
  }
 
357
 
 
358
  return $topic_id;
 
359
}
 
360
 
 
361
#####
 
362
# Syntax.......: getTotalPosts()
 
363
# Description..: Returns the total number of posts that have passed the
 
364
#                weboard.
 
365
#
 
366
function getTotalPosts() {
 
367
  $query = "SELECT MAX(topic_id) FROM webboard";
 
368
  $result = mysql_query($query);
 
369
  if ($result) return mysql_result($result, 0);
 
370
}
 
371
 
 
372
 
 
373
function getThreadSize($id) {
 
374
  $query = "SELECT * FROM webboard WHERE parent_id = $id";
 
375
  $result = mysql_query($query);
 
376
  $size = 1;
 
377
  while ($thread = mysql_fetch_object($result)) { 
 
378
    $size += getThreadSize($thread->topic_id);
 
379
  }
 
380
  return $size;
 
381
}
 
382
 
 
383
#####
 
384
# Syntax.......: getNextPost()
 
385
# Description..: Returns the next post.
 
386
#
 
387
function getNextPost($id) {
 
388
  ### Resolve root_id of $id:
 
389
  $query = "SELECT root_id FROM webboard WHERE topic_id = $id";
 
390
  $result = mysql_query($query);
 
391
  $root_id = mysql_result($result, 0);
 
392
  
 
393
  ### Resolve next message:
 
394
  $query = "SELECT topic_id FROM webboard WHERE root_id = $root_id AND topic_id > $id ORDER BY create_dt";
 
395
  $result = mysql_query($query);
 
396
  if (mysql_num_rows($result)) return mysql_result($result, 0);
 
397
  else return 0;
 
398
}
 
399
 
 
400
#####
 
401
# Syntax.......: getPrevPost()
 
402
# Description..: Returns the next post.
 
403
#
 
404
function getPrevPost($id) {
 
405
  ### Resolve root_id of $id:
 
406
  $query = "SELECT root_id FROM webboard WHERE topic_id = $id";
 
407
  $result = mysql_query($query);
 
408
  $root_id = mysql_result($result, 0);
 
409
  
 
410
  ### Resolve next message:
 
411
  $query = "SELECT topic_id FROM webboard WHERE root_id = $root_id AND topic_id < $id ORDER BY create_dt DESC";
 
412
  $result = mysql_query($query);
 
413
  if (mysql_num_rows($result)) return mysql_result($result, 0);
 
414
  else return 0;
 
415
}
 
416
 
 
417
#####
 
418
# Syntax.......: getNextThread(root_id)
 
419
# Description..: Returns the next thread.
 
420
#
 
421
function getNextThread($root_id) {
 
422
  $query = "SELECT root_id FROM webboard WHERE root_id > $root_id ORDER BY root_id";  
 
423
  $result = mysql_query($query);
 
424
  if (mysql_num_rows($result)) return mysql_result($result, 0);
 
425
  else return 0;
 
426
}
 
427
 
 
428
#####
 
429
# Syntax.......: getPrevThread(root_id)
 
430
# Description..: Returns the previous thread.
 
431
#
 
432
function getPrevThread($root_id) {
 
433
  $query = "SELECT root_id FROM webboard WHERE root_id < $root_id ORDER BY root_id DESC";
 
434
  $result = mysql_query($query);
 
435
  if (mysql_num_rows($result)) return mysql_result($result, 0);
 
436
  else return 0;
 
437
}
 
438
 
 
439
#####
 
440
# Syntax.......: getCurrentPosts()
 
441
# Description..: Returns the total number of current/active posts.
 
442
#
 
443
function getCurrentPosts() {
 
444
  $query = "SELECT COUNT(topic_id) FROM webboard";
 
445
  $result = mysql_query($query);
 
446
  if ($result) return mysql_result($result, 0);
 
447
}
 
448
 
 
449
#####
 
450
# Syntax.......: deleteThread(id)
 
451
# Description..: Deletes a thread including all child threads.
 
452
#
 
453
function deleteThread($id) {
 
454
  ### delete thread:
 
455
  $query = "SELECT topic_id FROM webboard WHERE parent_id = $id";
 
456
  $result = mysql_query($query);
 
457
 
 
458
  while ($post = mysql_fetch_object($result)) {
 
459
    deleteThread($post->topic_id);
 
460
  }
 
461
 
 
462
  ### delete individual post:
 
463
  $query = "DELETE FROM webboard WHERE topic_id = $id";
 
464
  $result = mysql_query($query);
 
465
}
 
466
 
 
467
#####
 
468
# Syntax.......: expireThread(timout)
 
469
# Description..: Checks for expired threads and automatically deletes 
 
470
#                them (if any).
 
471
#
 
472
function expireThread($expire, $number = 40) {
 
473
  $query = "SELECT root_id, MAX(create_dt) FROM webboard GROUP BY root_id";
 
474
  $result = mysql_query($query);
 
475
 
 
476
  while (getCurrentPosts() > $number && $result && $row = mysql_fetch_row($result)) {
 
477
    list($root_id, $create_dt) = $row;
 
478
    if (time() - $create_dt > $expire) deleteThread($root_id);
 
479
  }  
 
480
}
 
481
 
 
482
 
 
483
function displayForm($id = "0") {
 
484
  global $anonymous, $login, $support, $subscribe, $bgcolor2, $bgcolor3, $cookie;
 
485
 
 
486
  if ($cookie[1]) printForm($id, $cookie[1]);
 
487
  else printForm($id, $anonymous);
 
488
}
 
489
 
 
490
 
 
491
 
 
492
$id = $display;
 
493
 
 
494
if ($id) {
 
495
  displayMessage($id);
 
496
  displayForm($id);
 
497
}
 
498
else if ($section == "policy") {
 
499
  themebox("Webboard policy", "<P>Webboards are normally used to post notices, hints, questions and such.  Messages ideally should be written such that others can read them and get some value in them.</P><P>Everyday we see posts from people who choose to swear, insult and threaten users on the webboard.  Therefor we track all IP addresses of people posting: we know who comes, what they look at, how long they stay and - last but not least - we have a valid e-mail address.  Please do not use profanity.  Everyone is entitled to their opinion, but refrain from posting insults.</P><P>If you are a webboard user and see an offensive post or are being victimed by someone on the webboard, please contact us immediately at <A HREF=\"mailto:info@projectx.mx.dk\">info@projectx.mx.dk</A>.</P><P>We do take our webboard policy serious and we won't hesitate to e-mail the internet provider of the abuser to advise them of the situation.  In addition we will block an abusers ProjectX account, his IP or even its entire ISP: as each internet user is assigned a unique IP address on the net, we can track people down and then 'screen' them out when they try to return.  In most cases it means blocking entire address blocks or even ISPs.</P><P>Think before you post.</P><P ALIGN=\"right\">[ <A HREF=\"javascript: history.back()\">back</A> ]</P>", 500);
 
500
}
 
501
else if ($post) {
 
502
  $id = postMessage($subject, $author, $message, $parent_id, $root_id, 1); 
 
503
  print "<P><FONT SIZE=\"+1\">Your message has been posted:</FONT></P>\n";
 
504
  displayMessage($id);
 
505
  displayForm($id);
 
506
}
 
507
else if (isset($threaded) && ($threaded == 0)) {
 
508
  displayChronologicalOverview();
 
509
  displayForm(); 
 
510
}
 
511
else if ($delete) {
 
512
  ### check permissions:
 
513
  if ($admin) {
 
514
    ### delete thread:
 
515
    deleteThread($delete);
 
516
    print "<FORM ACTION=\"$PHP_SELF?delete=1\" METHOD=\"POST\">\n";
 
517
    displayAdminOverview(0);
 
518
    print "<INPUT TYPE=\"submit\" VALUE=\"Delete\">\n";
 
519
    print "</FORM>\n";
 
520
  }
 
521
  else displayBox("Failed", "You don't have permission to access this section.");
 
522
}
 
523
else if ($section == "webboard") {
 
524
  ### display administrator overview:
 
525
  print "<FORM ACTION=\"$PHP_SELF?delete=1\" METHOD=\"POST\">\n";
 
526
  displayAdminOverview(0);
 
527
  print "<INPUT TYPE=\"submit\" VALUE=\"Delete\">\n";     
 
528
  print "</FORM>\n";
 
529
}
 
530
else {
 
531
  displayThreadedOverview();
 
532
  displayForm();
 
533
}
 
534
 
 
535
### Check to see if a certain thread has expired:
 
536
if (time() % 20 == 0) { 
 
537
  expireThread(302400);  // 604800 = 7 days
 
538
}
 
539
 
 
540
### Close connection with MySQL server/database:
 
541
mysql_close();
 
542
 
 
543
$theme->footer();
 
544
 
 
545
?>
 
 
b'\\ No newline at end of file'