Viewing file: classifieds.phtml (6.23 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
require("ax.inc");
$conn = pg_connect("","","","","ax");
$lengthlimit=8000; // limit the length of texts in classifieds
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache");
switch ($REQUEST_METHOD) { case "POST" : switch($HTTP_POST_VARS[action]) { case "Suggest category": if (pg_exec($conn,"insert into \"classified categories\" (code,name,description,approved) values (nextval ('classifieds category seq'),'".$fields[name]."','".$fields[description]."',false);")) { disp_preamble("Classifieds","Category submission successful"); echo "Your category has been successfully submitted.<br>\n"; echo "It is not yet visible, but it will be after approval.<br>\n"; echo "Use the 'back' button of your browser to get back to the category listing."; disp_tail(); } else { disp_preamble("Classifieds","Category submission failure"); echo "There was an error while submitting the new category.<br>\n"; echo "We would be glad, if you could <a href=\"mailto:axcontact@yahoo.com\">inform us</a> if the problem persist.<br>\n"; echo "We apologize."; disp_tail(); } break; case "Submit classified": if (strlen($fields[text])>$lengthlimit) { disp_preamble("Classifieds","Submission failure"); echo "The text of your classified is longer than our limit, ".$lengthlimit." characters.<br>\n"; echo "We therefore can not accept it.<br>\n"; echo "We apologize."; disp_tail(); exit(); } unset($k); unset($v); while ($a=each($HTTP_POST_VARS[fields])) { if ($a[value]!="") { $k[]=$a[key]; $v[]=$a[value]; } } if (pg_exec($conn,"insert into classifieds (".join($k,",").",approved,date) values ('".join($v,"','")."',false,now());")) { disp_preamble("Classifieds","Submission successful"); echo "Your classified has been successfully submitted for approval.<br>\n"; echo "It is not yet visible, but it will be after approval.\n"; echo "Use the 'back' button of your browser to get back to the listing."; disp_tail(); } else { disp_preamble("Classifieds","Submission failure"); echo "There was an error while submitting your entry.<br>\n"; echo "We would be glad, if you could <a href=\"mailto:axcontact@yahoo.com\">inform us</a> if the problem persist.<br>\n"; echo "We apologize."; disp_tail(); } break; } break; default : if (isset($HTTP_GET_VARS["category"])) { // displaying category $result=pg_exec("select name from \"classified categories\" where code=".$HTTP_GET_VARS[category].";"); $rows=pg_numrows($result); if ($rows==0) { disp_preamble("Classifieds","Missing category"); echo "This category doesn't exist."; disp_tail(); exit(); } $obj=pg_fetch_array($result,$row); disp_preamble("Classifieds",htmlspecialchars($obj[name])); echo "<p align=center><font size=5>".htmlspecialchars($obj[name])."</font></p>"; $result=pg_exec("select name,email,url,date,text from classifieds where category=".$HTTP_GET_VARS["category"]." and approved=true order by date desc;"); $rows=pg_numrows($result); if ($rows==0) echo "<p>There are no items in this category.</p>\n"; else { echo"<hr>"; for ($row=0;$row<$rows;$row++) { $obj=pg_fetch_array($result,$row); echo "<table>\n"; echo "<tr>"; echo "<th align=right>Name:"; echo "<td>".htmlspecialchars($obj[name])."\n"; echo "<th align=right>Email:"; echo "<td><a href=\"mailto:".$obj[email]."\">".htmlspecialchars($obj[email])."</a>"; echo "<th align=right>URL:"; echo "<td><a href=\"".$obj[url]."\">".htmlspecialchars($obj[url]); echo "<th align=right>Date:"; echo "<td>".htmlspecialchars(substr($obj[date],0,10)); echo "<tr><th align=right>Text:"; echo "<td colspan=7>".nl2br(htmlspecialchars($obj[text])); echo "</table><hr>"; } } echo "<table border>\n"; echo "<caption>Submit a new classified!</caption>\n"; echo "<form method=post>\n"; echo "<input type=hidden name=\"fields[category]\" value=".$HTTP_GET_VARS[category].">\n"; echo "<tr><th align=right>Name:"; echo "<td><input type=text name=\"fields[name]\" size=40>\n"; echo "<tr><th align=right>Email:"; echo "<td><input type=text name=\"fields[email]\" size=40>\n"; echo "<tr><th align=right>URL:"; echo "<td><input type=text name=\"fields[url]\" size=40 value=\"http://\">\n"; echo "<tr><th align=right>Text:"; echo "<td><textarea name=\"fields[text]\" rows=20 cols=80 wrap=on></textarea>\n"; echo "<tr><th><td><input type=submit name=action value=\"Submit classified\">\n"; echo "</form>\n"; echo "</table>\n"; disp_tail(); } else { // displaying category list disp_preamble("Classifieds",""); $result=pg_exec("select code,name,description from \"classified categories\" where approved=true order by name;"); $rows=pg_numrows($result); echo "Choose from the existing categories:\n"; echo "<ul>\n"; for ($row=0;$row<$rows;$row++) { $obj=pg_fetch_array($result,$row); $result1=pg_exec($conn,"select approved,count(approved) from classifieds where category=".$obj[code]." group by approved;"); $approved=0; $unapproved=0; $rows1=pg_numrows($result1); for ($row1=0;$row1<$rows1;$row1++) { unset($a); $a=pg_fetch_row($result1,$row1); switch ($a[0]) { case 'f': $unapproved=$a[1]; break; case 't': $approved=$a[1]; break; } } echo "<li>"; echo "<a href=\"".$PHP_SELF."?category=".urlencode($obj[code])."\">"; echo $obj[name]."</a> (approved:".$approved." waiting: ".$unapproved.")<br>\n"; echo htmlspecialchars($obj[description])."</li>\n"; } echo "</ul>\n"; echo "or\n"; echo "<form method=post>\n"; echo "<table border>\n"; echo "<caption>suggest a new category:</caption>\n"; echo "<tr><th align=right>Name:<td><input type=text name=\"fields[name]\" size=40>\n"; echo "<tr><th align=right>Description:<td><textarea name=\"fields[description]\" rows=15 cols=60 wrap=on></textarea>\n"; echo "<tr><th><td><input type=submit name=action value=\"Suggest category\">\n"; echo "</table>\n"; echo "</form>\n"; disp_tail(); } } ?>
|