summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-05-18 12:36:04 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-05-18 12:36:04 +0200
commitfba23ca163517597b67f4674f721d919470f3697 (patch)
tree9e9f634b59369323dc2e09e74a1c932173a1d7ac
parentb47ab953744b4beceaa0e25395c2cad819ccb113 (diff)
downloadCatalog-fba23ca163517597b67f4674f721d919470f3697.tar.gz
Catalog-fba23ca163517597b67f4674f721d919470f3697.zip
Add functionality for changing, deleting and adding data
-rw-r--r--categories.php14
-rw-r--r--categoryedit.php75
-rw-r--r--productedit.php129
-rw-r--r--products.php14
4 files changed, 227 insertions, 5 deletions
diff --git a/categories.php b/categories.php
index f141e3e..651eb58 100644
--- a/categories.php
+++ b/categories.php
@@ -22,7 +22,7 @@ if(isset($_SESSION['username']))
}
else
{
- echo "<dt><a href=\"login.html\">Login</a></dt>";
+ echo "<dt><a href=\"login.php\">Login</a></dt>";
}
?>
</dl>
@@ -41,11 +41,19 @@ else
if(isset($username))
{
echo "<td><a href=\"categoryedit.php?modify={$category->getId()}\">Edit</a></td>";
- echo "<td><a href=\"categoryedit.php?delete={$category->getId()}\">Delete</a></td>";
+ echo "<td><a href=\"categoryedit.php?delete={$category->getId()}\" onClick=\"return confirm('Confirm deletion.')\">Delete</a></td>";
}
echo "</tr>";
}
-
+ if(isset($username))
+ {
+ echo "<tr>";
+ echo "<td></td>";
+ echo "<td></td>";
+ echo "<td></td>";
+ echo "<td><a href=\"categoryedit.php?add={$category->getId()}\">Add</a></td>";
+ echo "</tr>";
+ }
?>
</table>
<div class="spacer"></div>
diff --git a/categoryedit.php b/categoryedit.php
new file mode 100644
index 0000000..7a1bf59
--- /dev/null
+++ b/categoryedit.php
@@ -0,0 +1,75 @@
+<?php
+ session_start();
+ if(!isset($_SESSION['username']))
+ {
+ header('Location: categories.php');
+ }
+
+ require_once('vendor.inc.php');
+
+ if(isset($_GET['delete']))
+ {
+ $category = CategoryQuery::create()->findOneById($_GET['delete']);
+ }
+ if(isset($_GET['modify']))
+ {
+ $type = 'modify';
+ $category = CategoryQuery::create()->findOneById($_GET['modify']);
+ }
+ if(isset($_GET['add']))
+ {
+ $type = "add";
+ $category = new Category();
+ }
+ if(!is_object($category))
+ {
+ header('Location: categories.php');
+ }
+ if(isset($_GET['delete']))
+ {
+ $category->delete();
+ header('Location: categories.php');
+ }
+ if(isset($_POST['name']) && isset($_POST['desc']))
+ {
+ $category->setName($_POST['name']);
+ $category->setDescription($_POST['desc']);
+ $category->save();
+ header('Location: categories.php');
+ }
+?>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Category</title>
+<link rel="stylesheet" type="text/css" href="styles/style.css">
+</head>
+<body>
+ <a href="categories.php" accesskey="b"><em>B</em>ack</a>
+ <form action="categoryedit.php?<?php echo "{$type}={$category->getId()}" ?>" method="post">
+ <h1>Category</h1>
+ <div class="row">
+ <label for="name"><u>N</u>ame:</label> <input class="formw" type="text"
+ placeholder="Name" id="name" name="name" accesskey="n"
+ maxlength="100" value="<?php echo $category->getName(); ?>">
+ </div>
+ <div class="row">
+ <label for="desc"><u>D</u>escription:</label>
+ <textarea class="formw" placeholder="Description" id="desc" name="desc"
+ accesskey="d" maxlength="1000"><?php echo $category->getDescription(); ?></textarea>
+ </div>
+ <div class="spacer">
+ &nbsp;
+ </div>
+ <button type="submit">
+ <?php
+ echo ucfirst($type);
+ ?>
+ </button>
+ <button type="reset">
+ Reset
+ </button>
+ </form>
+</body>
+</html> \ No newline at end of file
diff --git a/productedit.php b/productedit.php
new file mode 100644
index 0000000..c2b33fa
--- /dev/null
+++ b/productedit.php
@@ -0,0 +1,129 @@
+<?php
+ session_start();
+ if(isset($_GET['catid']))
+ {
+ $catid = $_GET['catid'];
+ }
+ else
+ {
+ header('Location: categories.php');
+ }
+ if(!isset($_SESSION['username']))
+ {
+ header("Location: product.php?id={$catid}");
+ }
+
+ require_once('vendor.inc.php');
+
+ if(isset($_GET['delete']))
+ {
+ $product = ProductQuery::create()->findOneById($_GET['delete']);
+ }
+ if(isset($_GET['modify']))
+ {
+ $type = 'modify';
+ $product = ProductQuery::create()->findOneById($_GET['modify']);
+ }
+ if(isset($_GET['add']))
+ {
+ $type = "add";
+ $product = new Product();
+ }
+ if(!is_object($product))
+ {
+ header("Location: products.php?id={$catid}");
+ }
+ if(isset($_GET['delete']))
+ {
+ $product->delete();
+ header("Location: products.php?id={$catid}");
+ }
+ if(isset($_POST['name']) && isset($_POST['price']) && isset($_POST['width']) && isset($_POST['height']) && isset($_POST['desc']) && isset($_POST['cat']))
+ {
+ $product->setName($_POST['name']);
+ $product->setPrice($_POST['price']);
+ $product->setWidth($_POST['width']);
+ $product->setHeight($_POST['height']);
+ $product->setDescription($_POST['desc']);
+
+ if(is_array($_POST['cat']))
+ {
+ $catCollect = new Propel\Runtime\Collection\Collection();
+ foreach ($_POST['cat'] as $categoryID)
+ {
+ $catCollect->set($categoryID, CategoryQuery::create()->findOneById($categoryID));
+ }
+ $product->setCategories($catCollect);
+ }
+ $product->save();
+ header("Location: products.php?id={$catid}");
+ }
+?>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Production</title>
+<link rel="stylesheet" type="text/css" href="styles/style.css">
+</head>
+<body>
+ <a href="products.php?id=<?php echo $catid; ?>" accesskey="b"><em>B</em>ack</a>
+ <form action="productedit.php?<?php echo "{$type}={$product->getId()}" ?>&catid=<?php echo $catid; ?>" method="post">
+ <h1>Product</h1>
+ <div class="row">
+ <label for="name"><u>N</u>ame:</label>
+ <input class="formw" type="text"
+ placeholder="Name" id="name" name="name" accesskey="n"
+ maxlength="100" value="<?php echo $product->getName(); ?>">
+ </div>
+ <div class="row">
+ <label for="price"><u>P</u>rice (Euro):</label>
+ <input class="formw" type="number" step="0.01" min="0"
+ placeholder="Price (Euro)" id="price" name="price" accesskey="p"
+ maxlength="13" value="<?php echo $product->getPrice(); ?>">
+ </div>
+ <div class="row">
+ <label for="width"><u>W</u>idth (mm):</label>
+ <input class="formw" type="number"
+ placeholder="Width (mm)" id="width" name="width" accesskey="w"
+ maxlength="11" value="<?php echo $product->getWidth(); ?>">
+ </div>
+ <div class="row">
+ <label for="height"><u>H</u>eight (mm):</label>
+ <input class="formw" type="number"
+ placeholder="Height (mm)" id="height" name="height" accesskey="h"
+ maxlength="11" value="<?php echo $product->getHeight(); ?>">
+ </div>
+ <div class="row">
+ <label for="desc"><u>D</u>escription:</label>
+ <textarea class="formw" placeholder="Description" id="desc" name="desc"
+ accesskey="d" maxlength="1000"><?php echo $product->getDescription(); ?></textarea>
+ </div>
+ <div class="row">
+ <label for="cat"><u>D</u>escription:</label>
+ <select multiple class="formw" id="cat" name="cat[]">
+ <?php
+ foreach (CategoryQuery::create()->find() as $category)
+ {
+ echo "<option value=\"{$category->getId()}\" ";
+ if($product->getCategories()->contains($category))
+ {
+ echo "selected";
+ }
+ echo ">{$category->getName()}</option>";
+ }
+ ?>
+ </select>
+ </div>
+ <div class="spacer">&nbsp;</div>
+ <button type="submit">
+ <?php
+ echo ucfirst($type);
+ ?>
+ </button>
+ <button type="reset">
+ Reset
+ </button>
+ </form>
+</body>
+</html> \ No newline at end of file
diff --git a/products.php b/products.php
index 7ecb2e0..9f4f6b0 100644
--- a/products.php
+++ b/products.php
@@ -53,10 +53,20 @@ foreach( $products as $product ){
echo "<td>{$product->getDescription()}</td>";
if(isset($username))
{
- echo "<td><a href=\"productedit.php?modify={$product->getId()}\">Edit</a></td>";
- echo "<td><a href=\"productedit.php?delete={$product->getId()}\">Delete</a></td>";
+ echo "<td><a href=\"productedit.php?modify={$product->getId()}&catid={$id}\">Edit</a></td>";
+ echo "<td><a href=\"productedit.php?delete={$product->getId()}&catid={$id}\" onClick=\"return confirm('Confirm deletion.')\">Delete</a></td>";
}
echo "</tr>";
+
+}
+if(isset($username))
+{
+ echo "<tr>";
+ echo "<td></td>";
+ echo "<td></td>";
+ echo "<td></td>";
+ echo "<td><a href=\"productedit.php?add={$category->getId()}&catid={$id}\">Add</a></td>";
+ echo "</tr>";
}
?>
</table>