Viewing file: msgboardmma.phtml (5.57 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
require("ax.inc");
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_list($conn, $table) { global $PHP_SELF, $HTTP_GET_VARS;
disp_preamble("MMA Message Board","");
$query = "select oid,name,email,url,subject,date from ".$table." order by date desc;"; $result = pg_Exec($conn, $query);
$rows=pg_numrows($result);
if ($rows==0) { echo "<p align=center>There are no messages onboard.</p>"; } else { echo "Here are the posted messages, newest first:</p>\n";
echo "<table width=\"95%\">\n"; echo "<tr>"; echo "<th align=left width=\"50%\">Subject"; echo "<th align=left width=\"15%\">Date"; echo "<th align=left width=\"35%\">Name"; echo "</tr>\n";
for($row=0;$row<$rows;$row++) { $obj=pg_fetch_array($result,$row); if ($obj[name]=="") $obj[name]="(unknown poster)"; if ($obj[subject]=="") $obj[name]="(no subject given)"; echo "<tr>"; echo "<td><a href=\"".$PHP_SELF."?disp=".$obj["oid"]."\">".$obj["subject"]; echo "<td>".substr($obj["date"],0,10); echo "<td>".$obj[name]; echo"</tr>\n"; } echo "</table>\n"; }
new_message("","",""); }
function disp_message($name,$email,$url,$subject,$date,$text) { 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," wrote:<br>\n"; //disp_person($name,$email,$url); //echo " wrote on ".substr($date,0,10)." regarding ".$subject.":<br>\n"; echo "<table width=\"80%\">\n"; echo "<tr><td>\n"; echo nl2br(htmlentities($text)); echo "</table>\n"; new_message($name,$subject,$text); }
function new_message($name,$subject,$text) { global $PHP_SELF, $HTTP_COOKIE_VARS;
echo "<form method=post url=\"".$PHP_SELF."\">\n"; echo "<table border>\n"; echo "<tr><td align=right>Name:<td><input type=text name=\"fields[name]\" size=40 value=\"".$HTTP_COOKIE_VARS[name]."\">\n"; echo "<tr><td align=right>Email address:<td><input type=text name=\"fields[email]\" size=40 value=\"".$HTTP_COOKIE_VARS[email]."\">\n"; echo "<tr><td align=right>URL:<td><input type=text name=\"fields[url]\" size=40 value=\"".$HTTP_COOKIE_VARS[url]."\">\n"; if ($subject!="") if (substr($subject,0,3)!="Re:") $subject="Re: ".$subject; echo "<tr><td align=right>Subject:<td><input type=text name=\"fields[subject]\" size=40 value=\"".$subject."\">\n"; echo "<tr><td align=right>Text:<td><textarea name=\"fields[text]\" rows=20 cols=80 wrap=on>\n"; if ($text!="") { if ($name=="") $name="An unknown poster"; echo $name." wrote:\n"; $arr =split("\n|\r|\r\n",$text); while (list($key,$val) = each($arr)) { echo "> ".htmlentities($val)."\n"; } } echo "</textarea>\n"; echo "<tr><td><td><input type=submit name=action value=send><input type=submit name=action value=cancel>\n"; echo "</table>\n"; echo "</form>\n"; }
function handle_table($conn,$table) { global $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_COOKIE_VARS;
if (isset($HTTP_POST_VARS[action])) {
switch ($HTTP_POST_VARS[action]) { case "send": unset($k); unset($v); while ($a=each($HTTP_POST_VARS[fields])) { if ($a[value]!="") { $k[]=$a[key]; $v[]="'".$a[value]."'"; } } if ($HTTP_POST_VARS[fields][name]!=$HTTP_COOKIE_VARS[name]) setcookie("name",$HTTP_POST_VARS[fields][name],time()+3650*86400); if ($HTTP_POST_VARS[fields][email]!=$HTTP_COOKIE_VARS[email]) setcookie("email",$HTTP_POST_VARS[fields][email],time()+3650*86400); if ($HTTP_POST_VARS[fields][url]!=$HTTP_COOKIE_VARS[url]) setcookie("url",$HTTP_POST_VARS[fields][url],time()+3650*86400); if (sizeof($k)==0) { echo "Empty form - not inserting."; exit(); } if (pg_exec($conn,"insert into ".$table." (date,".join($k,", ").") VALUES (now(),".join($v,", ").");")) { header("HTTP/1.0 303 See Other"); header("Location: http://www.lettera.hu/~bandit/AX/msgboardmma"); disp_preamble("MMA Message Board","Message accepted"); echo "Your message has been successfully submitted to the message board.<br>\n"; echo "Use the 'back' button of your browser, or click on the link to get back to the <a href=\"http://www.lettera.hu/~bandit/AX/msgboardmma\">MMA Message Board</a>\n"; exit(); } else { disp_preamble("MMA Message Board",""); echo "Your message could not be posted due to an error.<br>\n"; echo "We would be glad, if you could <a href=\"mailto:axcontact@yahoo.com\">inform us</a> if the problem persists.<br>\n"; echo "We apologize."; }; break; default: header("Location: http://www.lettera.hu/~bandit/AX/msgboardmma"); exit(); } } else if (isset($HTTP_GET_VARS[disp])) { $result=pg_exec($conn,"select * from ".$table." where oid=".$HTTP_GET_VARS[disp].";"); if (pg_numrows($result)>0) { disp_preamble("MMA Message Board","Message ".$HTTP_GET_VARS[disp]); $obj=pg_fetch_array($result,0); disp_message($obj["name"],$obj[email],$obj[url],$obj[subject],$obj[date],$obj[text]); unset($HTTP_GET_VARS); } else { disp_preamble("MMA Message Board","Message ".$HTTP_GET_VARS[disp]." - not found"); echo "We could not find this message.<br>Either it was removed since bookmarked, or we still have bugs in the message board.<br>If it persist, please <a href=\"mailto:axcontact@yahoo.com\">mail us</a> a bug report. We apologize."; } } else disp_list($conn,$table); } ?> <? handle_table(pg_connect("","","","","ax"),"msgboardmma"); disp_tail(); ?>
|