PHP:GWItems
From Devicenull's Code
This managed a list of the items I had in Guild Wars, and was quite handy
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head><title>Devicenull's Item List</title></head> <body> <?php require("adodb\adodb.inc.php"); $sql = NewADOConnection('mysql://x@y@localhost/gw_items'); if (!($sql->_errorCode == false)) die("Unable to connect to SQL server: ".$sql->_errorMsg); $gip = array("192.168.1.2","192.168.1.3","192.168.1.6","127.0.0.1"); $ip = $_SERVER['REMOTE_ADDR']; $isgood = array_search($ip,$gip); $basequery = "SELECT * FROM items RIGHT JOIN cat ON items.cid = cat.cid RIGHT JOIN colors ON items.lid = colors.lid WHERE cat.cid = items.cid AND colors.lid = items.lid"; if ($_POST['action'] == 'add') { $cat = $_POST['cat']; $color = $_POST['color']; $name = $_POST['name']; $damage = $_POST['damage']; $price = $_POST['price']; $bonus = $_POST['bonus']; if (empty($price)) $price = 0; if (empty($name) | $cat == -1) { echo '<font color="red">You forgot to include the name</font>'; die(); } $bonus = str_ireplace("\n","<br>",$bonus); $query = "INSERT INTO items VALUES('',$cat,$color,'$name','$bonus','$damage',$price)"; $sql->Execute($query); $res = $sql->Execute($basequery." ORDER BY items.id"); dispTable($res); } else if ($_GET['action'] == 'modprice') { $id = $_GET['id']; $price = $_GET['price']; $query = "UPDATE items SET price=$price WHERE id=$id"; $sql->Execute($query); $query = $basequery.' ORDER BY id'; $res = $sql->Execute($query); if ($res && $res->numRows() > 0) { dispTable($res); } $res->Close(); } else if ($_GET['action'] == 'delete') { $id = $_GET['id']; echo 'Delete Item? <br> <a href="./items.php?action=dodelete&id='.$id.'">Yes</a> <a href="./items.php">No</a>'; } else if ($_GET['action'] == "dodelete") { $id = $_GET['id']; $query = "DELETE FROM items WHERE id=$id"; $sql->Execute($query); $query = $basequery.' ORDER BY id'; $res = $sql->Execute($query); if ($res && $res->numRows() > 0) { dispTable($res); } $res->Close(); } else if ($_GET['action'] == 'filter') { $cat = $_GET['cat']; $color = $_GET['color']; $name = $_GET['name']; $damage = $_GET['damage']; $query = $basequery.' '; if ($cat != -1) $query .= "AND (items.cid == $cat) "; if ($color != -1) $query .= "AND (items.color = $color) "; if (!empty($damage)) $query .= "AND (items.damage LIKE '%$damage%') "; if (!empty($name)) $query .= "AND (items.name LIKE '%$name%') "; $query .= " ORDER BY id"; $res = $sql->Execute($query); if ($res && $res->numRows() > 0) dispTable($res); } else { $query = $basequery.' ORDER BY id'; $res = $sql->Execute($query); if ($res && $res->numRows() > 0) { dispTable($res); } $res->Close(); } function makePrice($price) { if ($price < 1000) return $price.'<b>g</b>'; $plat = (int)($price/1000); $price -= $plat*1000; return $plat.'<b>p</b> '.$price.'<b>g</b>'; } function dispPriceForm($id) { echo '<input type="hidden" name="action" value="modprice">'; echo '<input type="hidden" name="id" value="'.$id.'">'; echo '<input type="text" name="price" size="5">'; echo '<input type="submit" name="Go" value="Go">'; } function dispTable($res) { global $isgood; if (!$res) return; echo '<a href="./items.php">View All</a>'; echo '<!--Begin Item Table-->'; echo '<table>'; echo '<tr> <td width="50px">Type</td> <td width="50px">Color</td> <td width="150px">Name</td> <td width="50px">Damage</td> <td width="250px">Bonus</td> <td width="100px">Price</td>'; if ($isgood != false) echo '<td width="100px">Change Price</td><td width="15px"> </td>'; echo '</tr>'; for ($i=0;$i<$res->numRows();$i++) { if ($i % 3 == 0) echo '<tr bgcolor="#3399FF">'; else if ($i % 3 == 1) echo '<tr bgcolor="#99FF00">'; else echo '<tr bgcolor="#FF9900">'; echo '<td>'.$res->Fields("cname").'</td>'; echo '<td>'.$res->Fields("lname").'</td>'; echo '<td>'.$res->Fields("name").'</td>'; echo '<td>'.$res->Fields("damage").'</td>'; echo '<td>'.$res->Fields("bonus").'</td>'; echo '<td>'.makePrice($res->Fields("price")).'</td>'; if ($isgood != false) { echo '<form action="items.php" method="GET" display="inline">'; echo '<td align="center">'; dispPriceForm($res->Fields("id")); echo '</td>'; echo '</form>'; echo '<td><a href="./items.php?action=delete&id='.$res->Fields("id").'"><img src="delete.gif" border=0></a></td>'; } echo '<tr>'; $res->moveNext(); } echo '</table>'; echo '<!--End Item Table-->'; } ?> <form action="items.php" method="GET"> <input type="hidden" name="action" value="filter"> <!--Choose Item Type--> <b>Type: </b> <select name="cat"> <option value="-1">All</value> <?php $res = $sql->Execute("SELECT * from cat ORDER BY cid"); for ($i=0;$i<$res->numRows();$i++) { echo '<option value="'.$res->Fields("cid").'">'.$res->Fields("cname").'</option>'; $res->moveNext(); } $res->Close(); ?> </select> <!--Choose Item Color--> <b>Color: </b> <select name="color"> <option value="-1">All</value> <?php $res = $sql->Execute("SELECT * from colors ORDER BY lid"); for ($i=0;$i<$res->numRows();$i++) { echo '<option value="'.$res->Fields("lid").'">'.$res->Fields("lname").'</option>'; $res->moveNext(); } $res->Close(); ?> </select> <b>Name: </b><input type="text" name="name" maxlength="255" width="25"> <b>Damage: </b><input type="text" name="damage" maxlength="255" width="10"> <input type="submit" name="Search" value="Search"> </form> <hr height="3px"> <?php if ($isgood != false) { //We can add stuff ///////////////////////////////////////////////////////////////////////////////////////////////////// ?> <form action="items.php" method="POST"> <input type="hidden" name="action" value="add"> <table> <!--Choose Item Type--> <tr> <td><b>Type: </b></td> <td> <select name="cat"> <?php $res = $sql->Execute("SELECT * from cat ORDER BY cid"); for ($i=0;$i<$res->numRows();$i++) { echo '<option value="'.$res->Fields("cid").'">'.$res->Fields("cname").'</option>'; $res->moveNext(); } $res->Close(); ?> </select> </td> </tr> <!--Choose Item Color--> <tr> <td><b>Color: </b></td> <td> <select name="color"> <?php $res = $sql->Execute("SELECT * from colors ORDER BY lid"); for ($i=0;$i<$res->numRows();$i++) { echo '<option value="'.$res->Fields("lid").'">'.$res->Fields("lname").'</option>'; $res->moveNext(); } $res->Close(); ?> </select> </td> </tr> <tr> <td><b>Name: </b></td> <td><input type="text" name="name" maxlength="255" width="50"></td> </tr> <tr> <td><b>Damage: </b></td> <td><input type="text" name="damage" maxlength="255" width="25"></td> </tr> <tr> <td><b>Bonus: </b></td> <td><textarea rows="6" cols="32" name="bonus" maxlength="255" ></textarea></td> </tr> <tr> <td><b>Price: </b><br>Use 2400 instead of 2p 400g</td> <td><input type="text" name="price" maxlength="255" width="25"></td> </tr> <tr> <td></td> <td><input type="submit" name="Add" value="Add"></td> </tr> </table> </form> <?php }////////////////////////////////////////////////////////////////////////////////////////////////////////////////// else { echo "Bad IP, can't add stuff"; } ?> </body> </html>