Viewing file: msgboard_old-1.phtml (7.44 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
require('ax2.inc');
/* actions:
- new topic "Create!" - new message (in a topic) - display topic list - display messages (on a topic)
*/
function new_topic($conn) { global $text, $topic;
if ($text=="") { disp_preamble("The Ax Discussion Board","Topic creation - empty text"); echo "You haven't specified a topic!</p>\n"; } else { $result=pg_exec($conn,"select nextval ('msgboard topics_id_seq');"); $obj=pg_Fetch_Array($result,0); $topic=$obj[0]; if (pg_exec($conn,"insert into \"msgboard topics\" (text, id, modified, expired) values ('".addslashes($text)."',".addslashes($topic).",now(),'f');")) { //disp_preamble("The Ax Discussion Board","Topic creation successful"); //echo "Your topic '".htmlentities($text)."' was successfully created."; display_thread($conn,$topic); } else { disp_preamble("The Ax Discussion Board","Topic creation failed"); error("Your topic could not be created due to an error."); disp_tail(); } }
}
function new_message($conn) { global $HTTP_COOKIE_VARS, $REMOTE_ADDR; global $topic,$name,$email,$url,$subject,$text,$msgtype;
if ($HTTP_COOKIE_VARS[name]!=$name) setcookie("name",$name,time()+3650*86400); if ($HTTP_COOKIE_VARS[email]!=$email) setcookie("email",$email,time()+3650*86400); if ($HTTP_COOKIE_VARS[url]!=$url) setcookie("url",$url,time()+3650*86400); if ($HTTP_COOKIE_VARS[msgtype]!=$msgtype) setcookie("msgtype",$msgtype,time()+3650*86400); if ($msgtype!="HTML") $text=htmlentities($text); if (pg_exec($conn,"insert into \"msgboard messages\" (topic,name,email,url,subject,date,expired,text,ipaddr) values (".addslashes($topic).",'".addslashes($name)."','".addslashes($email)."','".addslashes($url)."','".addslashes($subject)."',now(),'f','".addslashes($text)."','".addslashes($REMOTE_ADDR)."');")) { pg_exec($conn,"update \"msgboard topics\" set modified=now() where id=".$topic.";"); display_thread($conn,$topic); } else { disp_preamble("The Ax Discussion Board","Message creation failed"); error("Your message could not be posted due to an error."); disp_tail(); } }
function disp_new_topic_form() { echo "<form method=post>\n"; echo "Create a new topic: <input type=text name=text maxlength=50>\n"; echo "<input type=submit name=action value=\"Create!\">\n"; echo "</form>\n"; }
function display_topics($conn) { global $PHP_SELF;
$result=pg_exec($conn,"select topic,count(*) from \"msgboard messages\" where expired<>'t' group by topic;");
$rows=pg_numrows($result); for($row=0;$row<$rows;$row++) { $obj=pg_fetch_array($result,$row); $darab[$obj[topic]]=$obj[count]; }
$result=pg_exec($conn,"select *, date_part('epoch',modified::datetime) from \"msgboard topics\" where expired<>'t' order by modified desc;"); if (!$result) { disp_preamble("The Ax Discussion Board","Error listing topics"); error("An error occured while listing the topics."); disp_tail(); exit(); } disp_preamble("The Ax Discussion Board","List of topics"); $timeresult=pg_exec('select current_timestamp;'); $obj=pg_fetch_array($timeresult,0); echo "Is <b>",substr($obj[0],0,19),"</b> your local time? If not, click <a href=\"tzset?back=msgboard\">here</a> to set your timezone!</p>";
$rows=pg_numrows($result); if ($rows==0) {echo "<p align=center>There are no topics onboard.</p>";} else { echo "<table>\n"; echo "<tr><th>Topic<th>Messages<th>Last modified</tr>\n"; for($row=0;$row<$rows;$row++) { echo "<tr>"; $obj=pg_fetch_array($result,$row); echo "<td><a href=\"".$PHP_SELF."?action=dispthread&topic=".$obj[id]."&junk=".urlencode($obj[date_part])."\">".htmlentities($obj[text])."</a></td>\n"; echo "<td align=right>".$darab[$obj[id]]."</td>\n"; echo "<td>".substr($obj[modified],0,19)."</td>\n"; echo "</tr>\n"; } echo "</table>"; } disp_new_topic_form(); disp_tail(); }
function display_thread($conn,$topic) { global $name,$email,$url,$PHP_SELF;
$result=pg_exec("select * from \"msgboard topics\" where id=".$topic.";"); if (pg_numrows($result)==0) { disp_preamble("The Ax Discussion Board","Topic ".$topic." not found"); echo "<p align=center><a href=\"".$PHP_SELF."\">[Back to topic list]</a></p>"; error("We could not find this topic.<br>Either it was removed since bookmarked, or we still have bugs in the message board."); disp_tail(); exit(); } $obj=pg_fetch_array($result,0); disp_preamble("The Ax Discussion Board","Topic '".htmlentities($obj[text])."'"); echo "<p align=center><a href=\"".$PHP_SELF."\">[Back to topic list]</a></p>"; $result=pg_exec("select * from \"msgboard messages\" where topic=".$topic." and expired<>'t' order by date;"); if (!$result) { disp_preamble("The Ax Discussion Board","Error listing thread '".$obj[text]."'"); echo "<p align=center><a href=\"".$PHP_SELF."\">[Back to topic list]</a></p>"; error("An error occured while listing the messages in this thread."); disp_tail(); exit(); } $rows=pg_numrows($result); if ($rows==0) { echo "There are no messages in this thread.</p>\n"; } else { for ($row=0;$row<$rows;$row++) { $obj=pg_fetch_array($result,$row); disp_message($obj[name],$obj[email],$obj[url],$obj[subject],$obj[date],$obj[text]); } } disp_new_message_form(); echo "<p align=center><a href=\"".$PHP_SELF."\">[Back to topic list]</a></p>"; disp_tail(); }
function disp_person($name,$email,$url) { if ($name=="") { echo "An unknown poster"; } else { if ($email!="") echo "<a href=\"mailto:".$email."\">"; echo $name; if ($email!="") echo "</a>"; if ($url!="") echo " (<a href=\"".$url."\">".$url."</a>)"; } }
function disp_message($name,$email,$url,$subject,$date,$text) { echo "<font color=#4A7DB7>\n"; echo $subject,"<br>\n"; echo $name,"<br>\n"; echo $email,"<br>\n"; echo $url,"<br>\n"; //echo substr($date,0,10),"<br>\n"; echo "</p>"; echo $name," writes:</p>\n"; echo "</font>"; //disp_person($name,$email,$url); //echo " wrote on ".substr($date,0,10)." regarding ".$subject.":<br>\n"; //echo "<pre>\n"; echo "<font color=#FEFFD2>\n"; // #408080 echo(nl2br($text)); echo "</font>"; //echo "</pre>\n"; echo "<hr>\n"; }
function disp_new_message_form() { global $name,$email,$url,$topic,$msgtype;
echo "<form method=post url=\"".$PHP_SELF."\">\n"; echo "<input type=hidden name=topic value=".$topic.">\n"; echo "<table>\n"; echo "<tr><td align=right>Name:<td><input type=text name=\"name\" size=40 value=\"".$name."\">\n"; echo "<tr><td align=right>Email address:<td><input type=text name=\"email\" size=40 value=\"".$email."\">\n"; echo "<tr><td align=right>URL:<td><input type=text name=\"url\" size=40 value=\"".$url."\">\n"; echo "<tr><td align=right>Subject:<td><input type=text name=\"subject\" size=40 value=\"".$subject."\">\n"; echo "<tr><td align=right>Message type:<td><input type=radio name=msgtype value=plain"; if ($msgtype!="HTML") echo " checked"; echo ">Plain text <input type=radio name=msgtype value=HTML"; if ($msgtype=="HTML") echo " checked"; echo ">HTML\n"; echo "<tr><td align=right>Text:<td><textarea name=\"text\" rows=20 cols=80 wrap=soft>\n"; echo "</textarea>\n"; echo "<tr><td><td><input type=submit name=action value=\"Send!\">\n"; echo "</table>\n"; echo "</form>\n"; }
function handle_table($conn) { global $action, $timezone, $topic;
switch ($action) { case "Create!" : new_topic($conn); break; case "Send!" : new_message($conn); break; case "dispthread" : display_thread($conn,$topic); break; default : pg_exec($conn,"set time zone '$timezone';"); display_topics($conn); break; } } handle_table(pg_connect("","","","","ax")); ?>
|