diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-05-18 12:36:04 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-05-18 12:36:04 +0200 |
| commit | fba23ca163517597b67f4674f721d919470f3697 (patch) | |
| tree | 9e9f634b59369323dc2e09e74a1c932173a1d7ac /productedit.php | |
| parent | b47ab953744b4beceaa0e25395c2cad819ccb113 (diff) | |
| download | Catalog-fba23ca163517597b67f4674f721d919470f3697.tar.gz Catalog-fba23ca163517597b67f4674f721d919470f3697.zip | |
Add functionality for changing, deleting and adding data
Diffstat (limited to 'productedit.php')
| -rw-r--r-- | productedit.php | 129 |
1 files changed, 129 insertions, 0 deletions
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"> </div> + <button type="submit"> + <?php + echo ucfirst($type); + ?> + </button> + <button type="reset"> + Reset + </button> + </form> +</body> +</html>
\ No newline at end of file |
