diff options
Diffstat (limited to 'public/products.php')
-rw-r--r-- | public/products.php | 88 |
1 files changed, 70 insertions, 18 deletions
diff --git a/public/products.php b/public/products.php index da337ad..ce0ada5 100644 --- a/public/products.php +++ b/public/products.php @@ -13,6 +13,34 @@ function product_template($product) { EOF; } ?> +<?php $cat_id = $_GET['c']; ?> +<?php function categories_recursive($id = null) { + global $cursor, $cat_id; + if ($id === null) { + $res = $cursor->query("select id, name, parent from category where parent is null"); + } else { + $statement = $cursor->prepare("select id, name, parent from category where parent = ?"); + $statement->bind_param("i", $id); + $statement->execute(); + $res = $statement->get_result(); + } + if (!mysqli_num_rows($res)) return; + echo '<div class="sub">'; + $categories = $res->fetch_all(MYSQLI_ASSOC); + foreach ($categories as $category) { + // php is een hele mooie programmeertaal die heel fijn werkt + echo "<a href='?c="; + echo $category["id"]; + echo "' class='"; + echo "category "; + if ($category["id"] == $cat_id) echo "current "; + echo "'>"; + echo $category["name"]; + echo "</a>"; + categories_recursive($category["id"]); + } + echo '</div>'; +} ?> <html> <head> <?php include 'head.php' ?> @@ -22,25 +50,49 @@ EOF; <body> <?php include 'navbar.php' ?> <div class="main limwidth"> - <h2>lijst met producten:</h2> - <?php do { - if (($user_privileges & PRIVILEGE_ADMIN) == 0) break; - echo <<<"EOF" - <div class="center"> - <form action="/admin-product.php" method="get" class="d-ib"> - <input type="submit" value="Nieuw product toevoegen" class="button filled"> - </form> - <form action="/admin-category.php" method="get" class="d-ib"> - <input type="submit" value="Nieuwe categorie toevoegen" class="button filled"> - </form> + <div class="twocolumn"> + <div class="left"> + <h2>Filters</h2> + <h3>Categorieën</h3> + <div class="categories"> + <a href="?">Reset</a> + <?php categories_recursive() ?> </div> - EOF; - } while (false); ?> - <div class="products"> - <?php - $res = $cursor->query("select id, image, price, name from webs.product"); - while ($product = $res->fetch_object()) product_template($product); - ?> + </div> + <div class="right"> + <?php + $id = $_GET['c']; + echo "<h2>Producten"; + if ($id !== null) echo " in categorie $id"; + echo "</h2>"; + ?> + <?php do { + if (($user_privileges & PRIVILEGE_ADMIN) == 0) break; + echo <<<"EOF" + <div class="center"> + <form action="/admin-product.php" method="get" class="d-ib"> + <input type="submit" value="Nieuw product toevoegen" class="button filled"> + </form> + <form action="/admin-category.php" method="get" class="d-ib"> + <input type="submit" value="Nieuwe categorie toevoegen" class="button filled"> + </form> + </div> + EOF; + } while (false); ?> + <div class="products"> + <?php + if ($id === null) { + $res = $cursor->query("select id, image, price, name from webs.product"); + } else { + $statement = $cursor->prepare("select id, image, price, name from webs.product where category = ?"); + $statement->bind_param("i", $id); + $statement->execute(); + $res = $statement->get_result(); + } + while ($product = $res->fetch_object()) product_template($product); + ?> + </div> + </div> </div> </div> <?php include 'footer.php' ?> |