From fba23ca163517597b67f4674f721d919470f3697 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Mon, 18 May 2015 12:36:04 +0200 Subject: Add functionality for changing, deleting and adding data --- categories.php | 14 ++++-- categoryedit.php | 75 ++++++++++++++++++++++++++++++++ productedit.php | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ products.php | 14 +++++- 4 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 categoryedit.php create mode 100644 productedit.php 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 "
Login
"; + echo "
Login
"; } ?> @@ -41,11 +41,19 @@ else if(isset($username)) { echo "getId()}\">Edit"; - echo "getId()}\">Delete"; + echo "getId()}\" onClick=\"return confirm('Confirm deletion.')\">Delete"; } echo ""; } - + if(isset($username)) + { + echo ""; + echo ""; + echo ""; + echo ""; + echo "getId()}\">Add"; + echo ""; + } ?>
diff --git a/categoryedit.php b/categoryedit.php new file mode 100644 index 0000000..7a1bf59 --- /dev/null +++ b/categoryedit.php @@ -0,0 +1,75 @@ +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'); + } +?> + + + + +Category + + + + Back +
getId()}" ?>" method="post"> +

Category

+
+ +
+
+ + +
+
+   +
+ + +
+ + \ 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 @@ +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}"); + } +?> + + + + +Production + + + + Back +
getId()}" ?>&catid=" method="post"> +

Product

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
 
+ + +
+ + \ 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 "{$product->getDescription()}"; if(isset($username)) { - echo "getId()}\">Edit"; - echo "getId()}\">Delete"; + echo "getId()}&catid={$id}\">Edit"; + echo "getId()}&catid={$id}\" onClick=\"return confirm('Confirm deletion.')\">Delete"; } echo ""; + +} +if(isset($username)) +{ + echo ""; + echo ""; + echo ""; + echo ""; + echo "getId()}&catid={$id}\">Add"; + echo ""; } ?> -- cgit v1.2.3-70-g09d2