diff options
Diffstat (limited to 'public/admin-promo.php')
-rw-r--r-- | public/admin-promo.php | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/public/admin-promo.php b/public/admin-promo.php new file mode 100644 index 0000000..83103e3 --- /dev/null +++ b/public/admin-promo.php @@ -0,0 +1,98 @@ +<!DOCTYPE html> +<?php require "../lib/login.php"; ?> +<?php if_privileged(PRIVILEGE_ADMIN, "/") ?> +<?php require "../lib/promo.php"; ?> +<?php do { + if ($_SERVER['REQUEST_METHOD'] !== 'POST') break; + if (!$_POST['type']) break; + + switch($_POST['type']) { + case "delete": { + $statement = $cursor->prepare("delete from promotion where id = ?"); + $statement->bind_param("i", $_POST['id']); + $statement->execute(); + break; + } + case "add": { + $statement = $cursor->prepare("insert into webs.promotion (`product`, `price_buff`, `count_buff`) values (?, ?, ?)"); + $statement->bind_param("idi", $_POST['product_id'], $_POST['price_buff'], $_POST['count_buff']); + $statement->execute(); + break; + } + } + + $promo_id = $_POST['id']; + $new_status = $_POST['status']; + if (!$promo_id) break; + if (!$new_status) break; + + $statement = $cursor->prepare("update `promo` set status = ? where id = ?"); + $statement->bind_param("ii", $new_status, $promo_id); + $statement->execute(); +} while (false); ?> +<?php +function promo_template($promo) { + $promo_str = promobuff2str($promo->price_buff, $promo->count_buff); + echo <<<"EOF" + <form method="post"> + <input type="hidden" name="type" value="delete"> + <input type="hidden" name="id" value="$promo->id"> + <tr> + <td>$promo->product_id</td> + <td>$promo->name</td> + <td>$promo->count_buff</td> + <td>$promo->price_buff</td> + <td>$promo_str</td> + <td> + <input type="submit" value="verwijderen"> + </td> + </tr> + </form> + EOF; +} +?> + +<html> +<head> + <?php include 'head.php' ?> + <title>aanbiedingen</title> + <link rel="stylesheet" href="admin.css"> +</head> +<body> + <?php include 'navbar.php' ?> + <div class="main limwidth"> + <h2>aanbieding toevoegen</h2> + <form action="/admin-promo.php" method="post"> + <input type="hidden" name="type" value="add"> + <label for="product_id">Product</label> + <select id="product_id" name="product_id"> + <?php + $res = $cursor->query("select id, name from webs.product"); + while ($c = $res->fetch_object()) echo "<option value='$c->id'>$c->name</option>"; + ?> + </select> + <label for="count_buff">Per aantal</label> + <input id="count_buff" name="count_buff" type="number" min=1 step=1> + <label for="price_buff">Vermenigvuldigingsfactor</label> + <input id="price_buff" name="price_buff" type="number" step="any"> + <input id="submit" type="submit" value="Toevoegen"> + </form> + <h2>huidige aanbiedingen</h2> + <table class="promo-table"> + <tr> + <th>product id</th> + <th>product naam</th> + <th>per aantal</th> + <th>ver­menig­vuldigings­factor</th> + <th>zichtbaar als</th> + <th>verwijderen</th> + </tr> + <?php + $res = $cursor->query("select promotion.id, product.id as product_id, product.name, count_buff, price_buff from promotion join product on product.id = promotion.product"); + while ($promo = $res->fetch_object()) promo_template($promo); + ?> + </table> + </div> + <?php include 'footer.php' ?> +</body> +</html> |