categories page converted. getting tired.

This commit is contained in:
Ryan Walberg 2012-11-17 03:04:18 +00:00
parent ab7d49d757
commit de147ad95a
2 changed files with 143 additions and 98 deletions

View file

@ -58,10 +58,10 @@ if ($action == "delete") {
exit;
}
else if ($action == "edit") {
$query = "SELECT category FROM {$OPT["table_prefix"]}categories WHERE categoryid = " . $_GET["categoryid"];
$query = "SELECT category FROM {$OPT["table_prefix"]}categories WHERE categoryid = " . addslashes($_GET["categoryid"]);
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
if ($row = mysql_fetch_array($rs,MYSQL_ASSOC)) {
$category = htmlspecialchars($row["category"]);
if ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
$category = $row["category"];
}
mysql_free_result($rs);
}
@ -92,102 +92,33 @@ else {
exit;
}
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Gift Registry - Manage Categories</title>
<link href="styles.css" type="text/css" rel="stylesheet" />
</head>
<body>
<?php
if (isset($message)) {
echo "<span class=\"message\">" . $message . "</span>";
$query = "SELECT c.categoryid, c.category, COUNT(itemid) AS itemsin " .
"FROM {$OPT["table_prefix"]}categories c " .
"LEFT OUTER JOIN {$OPT["table_prefix"]}items i ON i.category = c.categoryid " .
"GROUP BY c.categoryid, category " .
"ORDER BY category";
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
$categories = array();
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
$categories[] = $row;
}
mysql_free_result($rs);
$query = "SELECT categoryid, category " .
"FROM {$OPT["table_prefix"]}categories ";
$query .= " ORDER BY category";
$categories = mysql_query($query) or die("Could not query: " . mysql_error());
if ($OPT["show_helptext"]) {
?>
<p class="helptext">
Here you can specify categories <strong>of your own</strong>, like &quot;Motorcycle stuff&quot; or &quot;Collectibles&quot;. This will help you categorize your gifts.<br />
Warning: deleting a category will uncategorize all items that used that category.
</p>
<?php
define('SMARTY_DIR',str_replace("\\","/",getcwd()).'/includes/Smarty-3.1.12/libs/');
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();
$smarty->assign('action', $action);
$smarty->assign('categories', $categories);
$smarty->assign('categoryid', addslashes($_GET["categoryid"]));
if (isset($message)) {
$smarty->assign('message', $message);
}
$smarty->assign('category', $category);
if (isset($category_error)) {
$smarty->assign('category_error', $category_error);
}
$smarty->assign('haserror', $haserror);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $OPT);
$smarty->display('categories.tpl');
?>
<p>
<table class="partbox" cellspacing="0" cellpadding="2">
<tr class="partboxtitle">
<td colspan="2" align="center">Categories</td>
</tr>
<tr>
<th class="colheader">Category</th>
</tr>
<?php
$i = 0;
while ($row = mysql_fetch_array($categories,MYSQL_ASSOC)) {
?>
<tr class="<?php echo (!($i++ % 2)) ? "evenrow" : "oddrow" ?>">
<td><?php echo htmlspecialchars($row["category"]); ?></td>
<td align="right">
<a href="categories.php?action=edit&categoryid=<?php echo $row["categoryid"]; ?>">Edit</a>
/
<a href="categories.php?action=delete&categoryid=<?php echo $row["categoryid"]; ?>">Delete</a>
</td>
</tr>
<?php
}
mysql_free_result($categories);
?>
</table>
</p>
<p>
<a href="categories.php">Add a new category</a> / <a href="index.php">Back to main</a>
</p>
<form name="category" method="get" action="categories.php">
<?php
if ($action == "edit" || (isset($haserror) && $action == "update")) {
?>
<input type="hidden" name="categoryid" value="<?php echo $_GET["categoryid"]; ?>">
<input type="hidden" name="action" value="update">
<?php
}
else if ($action == "" || (isset($haserror) && $action == "insert")) {
?>
<input type="hidden" name="action" value="insert">
<?php
}
?>
<div align="center">
<TABLE class="partbox">
<tr class="partboxtitle">
<td align="center" colspan="2"><?php echo ($action == "edit" ? "Edit Category '" . $category . "'" : "Add New Category"); ?></td>
</tr>
<TR valign="top">
<TD>Category</TD>
<TD>
<input name="category" type="text" value="<?php echo $category; ?>" maxlength="255" size="50"/>
<?php
if (isset($category_error)) {
?><br /><font color="red"><?php echo $category_error ?></font><?php
}
?>
</TD>
</TR>
</TABLE>
</div>
<P>
<div align="center">
<input type="submit" value="<?php if ($action == "" || $action == "insert") echo "Add"; else echo "Update"; ?>"/>
<input type="button" value="Cancel" onClick="document.location.href='categories.php';">
</div>
</P>
</form>
<table border="1">
</table>
</body>
</html>

View file

@ -0,0 +1,114 @@
{*
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gift Registry - Manage Categories</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
{include file='navbar.tpl' isadmin=$isadmin}
<div class="container" style="padding-top: 60px;">
{if isset($message)}
<div class="row">
<div class="span12">
<div class="alert alert-block">{$message|escape:'htmlall'}</div>
</div>
</div>
{/if}
{if $opt.show_helptext}
<div class="row">
<div class="span12">
<div class="alert alert-info">
Here you can specify categories <strong>of your own</strong>, like &quot;Motorcycle stuff&quot; or &quot;Collectibles&quot;. This will help you categorize your gifts.
Warning: deleting a category will uncategorize all items that used that category.
</div>
</div>
</div>
{/if}
<div class="row">
<div class="span12">
<div class="well">
<h3>Categories</h3>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Category</th>
<th># Items</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{foreach from=$categories item=row}
<tr>
<td>{$row.category|escape:'htmlall'}</td>
<td>{$row.itemsin}</td>
<td>
<a href="categories.php?action=edit&categoryid={$row.categoryid}#catform"><img src="images/write_obj.gif" border="0" title="Edit Category" alt="Edit Category" /></a>
/
<a href="categories.php?action=delete&categoryid={$row.categoryid}"><img src="images/remove.gif" border="0" title="Delete Category" alt="Delete Category" /></a>
</td>
</tr>
{/foreach}
</tbody>
</table>
<h5><a href="categories.php">Add a new category</a></h5>
</div>
</div>
</div>
<a name="catform">
<div class="row">
<div class="span12">
<form name="category" method="get" action="categories.php" class="well form-horizontal">
{if $action == "edit" || (isset($haserror) && $action == "update")}
<input type="hidden" name="categoryid" value="{$categoryid}">
<input type="hidden" name="action" value="update">
{elseif $action == "" || (isset($haserror) && $action == "insert")}
<input type="hidden" name="action" value="insert">
{/if}
<fieldset>
<legend>{if $action == "edit"}Edit Category '{$category|escape:'htmlall'}'{else}Add Category{/if}</legend>
<div class="control-group {if isset($category_error)}warning{/if}">
<label class="control-label" for="category">Category name</label>
<div class="controls">
<input id="category" name="category" type="text" class="input-xlarge" value="{$category|escape:'htmlall'}" maxlength="255">
{if isset($category_error)}
<span class="help-inline">{$category_error|escape:'htmlall'}</span>
{/if}
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">{if $action == "" || $action == "insert"}Add{else}Update{/if}</button>
<button type="button" class="btn" onClick="document.location.href='categories.php';">Cancel</button>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>