From: <unl...@us...> - 2002-08-14 03:39:09
|
Update of /cvsroot/meshdb/www/deal In directory usw-pr-cvs1:/tmp/cvs-serv11076 Modified Files: index.php Log Message: Commit the NEW code layout, base system for the to-be re-written deal system. Some major changes here. Database Abstraction Templating, etc.. The system is broken up into multiple files. Index: index.php =================================================================== RCS file: /cvsroot/meshdb/www/deal/index.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- index.php 10 Aug 2002 14:10:59 -0000 1.3 +++ index.php 14 Aug 2002 03:39:06 -0000 1.4 @@ -1,467 +1,65 @@ -<? - include "../db2/config.php"; - - #CVS comment - function quote($s) { - if ($s == "") return "null"; - else return "'".mysql_escape_string($s)."'"; - } - - /* - * This is the crypt of a special password that allows - * any entry to be deleted - */ - $override = quote("WBd2KrCxDrnRU"); - - if ($op == "deletedeal" && !isset($PHP_AUTH_USER)) { - $id = intval($id); - Header("WWW-Authenticate: Basic realm=\"MeshRetailPricesDelete$id\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "<html><body><p>Enter the password stored when the deal entry was created, or the special override password. The username is ignored.</p></body></html>\n"; - exit; - } - - $db = mysql_connect($MYSQLHOST, $MYSQLUSER, $MYSQLPASS); - mysql_select_db($MYSQLDB, $db) or die(mysql_error($db)); - - if ($op == "deletedeal") { - $id = intval($id); - if ($password == "null") { - $result = mysql_query("DELETE FROM deal" - ." WHERE id = $id AND keypass is null" - , $db) - or die(mysql_error($db)); - } else { - $password = quote($PHP_AUTH_PW); - $result = mysql_query("DELETE FROM deal" - ." WHERE id = $id AND (keypass = encrypt($password, keypass) OR $override = encrypt($password, $override))" - , $db) - or die(mysql_error($db)); - } - if (mysql_affected_rows($db) == 0) { - Header("WWW-Authenticate: Basic realm=\"MeshRetailPricesDelete$id\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "<html><body><h1>Password incorrect</h1><p>Enter the password stored when deal number $id was created, or the special override password. The username is ignored.</p></body></html>\n"; - exit; - } - } - -?> - -<html> -<head> -<link rel="stylesheet" href="../style.css" type="text/css"> -<title>Retail prices database</title> -<style type="text/css"> - td.minqty { text-align: right; } - td.unitprice { text-align: right; - font-weight: bold; } - td.expires { text-align: center; } - td.delete { text-align: center; } - td.delete a { color: red; } - td.note { font-style: italic; - font-family: Helvetica; - font-size: smaller; - text-align: center; } -</style> -</head> -<body> -<img align=center src="../img/mesh-small.gif" - width=107 height=68 alt="Brisbane Mesh"> -<h1>Retail prices database</h1> - -<? - - if ($op == "newdeal") { - $vendorid = intval($vendorid); - $productid = intval($productid); - $minqty = intval($minqty); - $unitprice = doubleval($unitprice); - $expirein = intval($expirein); - $note = quote($note); - $spotter = quote($spotter); - $password = quote($password); - $url = quote($url); - - $result = mysql_query("SELECT count(*) FROM vendor WHERE id=$vendorid", $db) or die(mysql_error($db)); - $row = mysql_fetch_row($result); - if (intval($row[0]) != 1) - die("invalid vendorid $vendorid"); - - $result = mysql_query("SELECT count(*) FROM product WHERE id=$productid", $db) or die(mysql_error($db)); - $row = mysql_fetch_row($result); - if (intval($row[0]) != 1) - die("invalid productid $productid"); - - if ($spotter == "null") - die("spotter name cannot be empty"); - - if ($unitprice <= 0) - die("unitprice must be a positive number"); - if ($minqty <= 0) - die("minqty must be a positive integer"); - if ($expirein <= 0) - die("expirein must be a positive integer"); - if ($expirein > 365) - $expirein = 365; - if ($url != "null" && !parse_url($url)) - die("invalid url"); - - $result = mysql_query("INSERT INTO deal SET" - ." vendorid=$vendorid" - .", productid=$productid" - .", minqty=$minqty" - .", unitprice=$unitprice" - .", spotted=NOW()" - .", expires=DATE_ADD(NOW(), INTERVAL $expirein DAY)" - .", spotter=$spotter" - .", note=$note" - .", url=$url" - .($password == "null" - ? "" - : ", keypass=encrypt($password)") - , $db) or die(mysql_error($db)); - } - - if ($op == "newvendor") { - $nameh = htmlspecialchars($name); - $name = quote($name); - $url = quote($url); - if ($name == "null") - die("vendor name cannot be empty"); - if ($url == "null" || $url == "'http://'") - die("vendor url cannot be empty"); - - $result = mysql_query("SELECT * FROM vendor WHERE" - ." name=$name"); - if (mysql_num_rows($result) > 0) - die("Already a vendor with that name!"); - - $result = mysql_query("INSERT INTO vendor SET" - ." name=$name, url=$url" - , $db) or die(mysql_error($db)); - - echo "<p>New vendor $nameh added</p>"; - } - - if ($op == "newproduct") { - $nameh = htmlspecialchars($name); - $class = quote($class); - $name = quote($name); - $url = quote($url); - $manuf = quote($manuf); - $description = quote($description); - if ($class == "null") - die("product class cannot be empty"); - if ($name == "null") - die("product name cannot be empty"); - if ($url == "null" || $url == "'http://'") - die("product url cannot be empty"); - if ($manuf == "null") - die("manufacturer cannot be empty"); - - $result = mysql_query("SELECT * FROM product WHERE" - ." name=$name AND class=$class AND manuf=$manuf"); - if (mysql_num_rows($result) > 0) - die("Already a product with that name, class and manufacturer!"); - - $result = mysql_query("INSERT INTO product SET" - ." name=$name, url=$url, class=$class, manuf=$manuf" - .", description=$description" - , $db) or die(mysql_error($db)); - - echo "<p>New product $nameh added</p>"; - } -?> - -<p> -This is a user-contributed database of component prices that people have -spotted in Australia. -If you know of a great deal, or the price of a -component that other people might be interested in, add it! -</p> - -<p>See also: -<ul> -<li><a href="http://www.wireless.org.au/tib/">The Incredible Bulk</a> - - bulk orders organised by Melbourne Wireless -</ul> -</p> - -<p> -The table below is sorted by class, and then by price. -</p> - -<table> -<tr><th class="major" colspan=10>Current Deals</th></tr> -<tr> -<? $cols = array("class","item","oem","unitprice","minqty","vendor", - "spotter","expires","note"); - foreach ($cols as $col) { ?> - <th class="minor"><?=$col?></th> -<? } ?> - <th class="minor">delete</th> - </tr> -<? - $result = mysql_query("SELECT " - ." deal.id AS id" - .", product.class AS class" - .", product.name AS item" - .", product.url AS producturl" - .", product.manuf AS oem" - .", unitprice" - .", minqty" - .", vendor.name AS vendor" - .", vendor.url AS vendorurl" - .", spotter" - .", DATE_FORMAT(expires, '%e %b') AS expires" - .", note" - .", deal.url AS url" - .", TO_DAYS(deal.expires - NOW()) AS days_left" - ." FROM product, vendor, deal" - ." WHERE product.id = deal.productid" - .(!$noexpire?" AND deal.expires > NOW()": "") - ." AND vendor.id = deal.vendorid" - ." ORDER BY class, unitprice, expires" - , $db) or die(mysql_error($db)); - $lastclass = ""; - while ($row = mysql_fetch_assoc($result)) { ?> - <tr> -<? - foreach($cols as $col) { ?> -<td class="<?=$col?>"><? - $v = htmlspecialchars($row[$col]); - if ($col == "unitprice") { - $v = sprintf("$%.2f", $row[$col]); - if ($row["url"]) - $v = "<a href=\"".$row["url"]."\">".$v."</a>"; - } - if ($col == "item") { - $u = htmlspecialchars($row["producturl"]); ?> - <a href="<?=$u?>"><?=$v?></a> -<? } - else if ($col == "vendor") { - $u = htmlspecialchars($row["vendorurl"]); ?> - <a href="<?=$u?>"><?=$v?></a> -<? } - else if ($col == "class") { - if ($v != $lastclass) { - $lastclass = $v; - echo $v; - } else { - echo """; - } - } - else if ($col == "expires" && $row["days_left"] <= 0) { - echo "<font color=\"red\">$v</font>"; - } - else { - echo $v; - } ?></td> -<? } ?> - <td class="delete"><a href="index.php?op=deletedeal&id=<?=$row["id"]?>">x</a></td> - </tr> -<? } ?> -</table> - -<? if (!$noexpire) { ?> -<p><a href="?noexpire=1">Show expired deals as well</a>.</p> -<? } ?> - -<h2>Add a new deal</h2> - -<form method=post> - -<p> -So, you've spotted a deal that's not in the table above. -Please enter all the details into the form below. -When you submit, it will appear above. -</p> - -<table> - - <tr><th>Vendor:</th> - <td><select name="vendorid"> - <option value=""></option> -<? - $result = mysql_query("SELECT id, name FROM vendor WHERE url IS NOT NULL ORDER BY name", $db) - or die(mysql_error($db)); - while ($row = mysql_fetch_assoc($result)) { ?> - <option value="<?=$row["id"]?>"><?=$row["name"]?></option> -<? } ?> - </select> (<a href="#addvendor">Add vendor to list</a>)</td></tr> - - <tr><th>Product:</th> - <td><select name="productid"> - <option value=""></option> -<? - $curclass = ""; - $result = mysql_query("SELECT id, class, manuf, name FROM product WHERE url IS NOT NULL ORDER BY class, manuf, name", $db) - or die(mysql_error($db)); - while ($row = mysql_fetch_assoc($result)) { - if ($curclass != $row["class"]) { - $curclass = $row["class"]; ?> - <option value="class">=== <?=$curclass?> ===</option> -<? } ?> - <option value="<?=$row["id"]?>"><?=htmlspecialchars($row["manuf"].' '.$row["name"])?></option> -<? } ?> - </select> (<a href="#addproduct">Add product to list</a>)</td></tr> - - <tr><th>Unit price (AUD$):</th> - <td><input name="unitprice"> - <br><i>include GST and estimated shipping cost!</i></td></tr> +<?php +/*************************************************************************** + * index.php + * ------------------- + * begin : Sunday, Jun 24, 2002 + * copyright : (C) 2002 The meshDB Group + * email : unl...@us... + * notes : Deals with index page. + * + * $Id$ + * + * + ***************************************************************************/ - <tr><th>Minimum Qty:</th> - <td><input name="minqty" value="1"></td></tr> +/*************************************************************************** + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + ***************************************************************************/ - <tr><th>Spotter (you):</th> - <td><input name="spotter"></td></tr> +// Page Init +define('IN_MESHDB', true); - <tr><th>Expires:</th> - <td><select name="expirein"> - <option value="1">tomorrow</option> - <option value="7">in 1 week</option> - <option value="14">in 2 weeks</option> - <option value="21">in 3 weeks</option> - <option value="31" selected>in 1 month</option> - <option value="62">in 2 months</option> - <option value="182">in 6 months</option> - <option value="365">in 1 year (are you sure?)</option> - </select></td></tr> +include('./extension.inc'); +include('./common.'.$phpEx); - <tr><th>URL:</th> - <td><input name="note"> - <br><i> - an optional URL to a web page describing the sale offer - </i></td></tr> - <tr><th>Special notes:</th> - <td><input name="note"></td></tr> +// +// Include Header +// +include('./includes/page_header.'.$phpEx); - <tr><th>Password:</th> - <td><input name="password" type=password><br> - <i>(used when deleting)</i></td></tr> - <tr><td></td> - <td><input type=hidden name="op" value="newdeal"> - <input type=submit value="Create deal"></td> - </table> -</form> -<hr> + // + // Start Body + // + $template->set_filenames(array( + 'index' => 'index_page.tpl') + ); + -<h2><a name="addvendor">Add vendor</a></h2> -<form method=post> -<p> -A vendor is someone who sells things to the public. (Some people call them retailers.) -Use this form to add to the list of known vendors. -</p> -<table> - <tr><th>Vendor's short name:</th> - <td><input name="name"></td></tr> - <tr><th>URL to vendor's details:</th> - <td><input name="url" value="http://"><br> - <i>This URL should show contact details for the vendor</i> - </td></tr> - <tr><td></td> - <td><input type=hidden name="op" value="newvendor"> - <input type=submit value="Add vendor"></td> -</table> -</form> + // Assign variables in template values + $template->assign_vars(array( + 'MESSAGE' => 'Welcome to admin via templates', + 'MESSAGE2' => 'foo bar!', + 'MESSAGE3' => $foo) + ); -<table><tr><th class="major">Known vendors</th></tr> - <tr><th class="minor">name</th></tr> -<? - $result = mysql_query("SELECT name, url FROM vendor WHERE url IS NOT NULL ORDER BY name", $db) - or die(mysql_error($db)); - $comma = ""; - while ($row = mysql_fetch_assoc($result)) { ?> -<tr><td><a href="<?=htmlspecialchars($row["url"])?>"><?=htmlspecialchars($row["name"])?></a></td></tr> -<? } ?> -</table> -<hr> + // End Body + $template->pparse('index'); -<h2><a name="addproduct">Add product</a></h2> -<form method=post> -<p> -Use this form to add to the list of known products. -Please only add gear to do with low-cost wireless networking activities. -(i.e. I cull entries regarding CPUs, digital cameras etc.) -</p> -<table> - <tr><th>Product class:</th> - <td><select name="class"> -<? - $classes = array("card", "AP", "adaptor", "periph", "cable", "antenna", "diy", "other"); - foreach ($classes as $class) { ?> - <option value="<?=$class?>"><?=$class?></option> -<? } ?> - </select></td></tr> - <tr><th>Manufacturer (OEM):</th> - <td><input name="manuf"><br> - <i>Try to use a single word for the OEM/manufacturer (eg IBM)</i> - </td></tr> - <tr><th>Product short name:</th> - <td><input name="name"><br> - <i>Try to use the manufacturer's unique product code (eg MA401)</i> - </td></tr> - <tr><th>Product long name:</th> - <td><input name="description"><br> - <i>Product's packaging name, without manufacturer name (eg NetBlaster II)</i> - </td></tr> - <tr><th>URL to product details:</th> - <td><input name="url" value="http://"><br> - <i>This URL should show the original manufacturer's technical - specs on the actual device</i> - </td></tr> - <tr><td></td> - <td><input type=hidden name="op" value="newproduct"> - <input type=submit value="Add product"></td> - </table></form> + +// +// Include Footer +// +include('./includes/page_tail.'.$phpEx); -<table><tr><th class="major" colspan=4>Known products</th></tr> -<tr><th class="minor">class</th> - <th class="minor">oem</th> - <th class="minor">name</th> - <th class="minor">description</th> -</tr> -<? - $result = mysql_query("SELECT id, name, manuf, url, class, description FROM product WHERE url IS NOT NULL ORDER BY class, manuf, name", $db) - or die(mysql_error($db)); - $lastclass = "?"; - while ($row = mysql_fetch_assoc($result)) { - $class = htmlspecialchars($row["class"]); - $oem = htmlspecialchars($row["manuf"]); - $url = htmlspecialchars($row["url"]); - $name = htmlspecialchars($row["name"]); - $desc = htmlspecialchars($row["description"]); - if ($class == $lastclass) - $class = " "; - else - $lastclass = $class; - ?> - <tr><td><?=$class?></td> - <td><?=$oem?></td> - <td><a href="<?=$row["url"]?>"><?=$row["name"]?></a></td> - <td><?=$desc?></td> - </tr> -<? } - if ($class != "") { echo "</p>\n"; } ?> -</table> - -<hr> -<p> -<a href="..">Brisbane Mesh</a> -<br> -Any questions? Did you stuff something up? Is something wrong? -Contact <a href="mailto:d+meshretail@itee.uq.edu.au">David Leonard</a>. -Periodically, he goes through this page and tidies up anyway, but -is happier if you send him a note when you notice something's gone awry. -</p> - -</body> -</html> |