aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-06-01 18:20:05 +0200
committerlonkaars <loek@pipeframe.xyz>2023-06-01 18:20:05 +0200
commit2197faf27421f3df01d7ae6618ddf12873dca3bb (patch)
treeaa92526fec25bc563b3174161dd6b5b5ca3b9bad
parentc2b5ab68a84bf830f64e9c4e39f92b24c085c7e6 (diff)
admin-promo done
-rw-r--r--lib/promo.php13
-rw-r--r--public/admin-promo.php98
-rw-r--r--public/admin.css6
-rw-r--r--public/index.php12
4 files changed, 117 insertions, 12 deletions
diff --git a/lib/promo.php b/lib/promo.php
new file mode 100644
index 0000000..ae200fa
--- /dev/null
+++ b/lib/promo.php
@@ -0,0 +1,13 @@
+<?php
+
+function promobuff2str($price_buff, $count_buff) {
+ if ($count_buff == 1) return ((1-$price_buff)*100)."% korting";
+ if ($count_buff <= 4) {
+ for ($i = $count_buff-1; $i > 0; $i--)
+ if (abs((($i/$count_buff)-$price_buff)/$price_buff) < 0.001)
+ return $i."+".($count_buff - $i)." gratis";
+ }
+ return ((1-$price_buff)*100)."% korting per ".$count_buff."-pack";
+}
+
+?>
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&shy;menig&shy;vuldigings&shy;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>
diff --git a/public/admin.css b/public/admin.css
index bc1d821..8adeb79 100644
--- a/public/admin.css
+++ b/public/admin.css
@@ -34,9 +34,13 @@ table td {
border: 2px solid var(--bg-alt);
}
+table td input { width: 100%; }
+
.order-table td:nth-child(1) { text-align: center; }
.order-table td:nth-child(3) { text-align: right; }
.order-table td:nth-child(4) { text-align: right; }
.order-table td select,
-.order-table td input { width: 100%; }
+.promo-table td:nth-child(1) { text-align: center; }
+.promo-table td:nth-child(3) { text-align: right; }
+.promo-table td:nth-child(4) { text-align: right; }
diff --git a/public/index.php b/public/index.php
index fecf624..3540692 100644
--- a/public/index.php
+++ b/public/index.php
@@ -1,16 +1,6 @@
<!DOCTYPE html>
<?php require "../lib/db.php"; ?>
-<?php
-function promobuff2str($price_buff, $count_buff) {
- if ($count_buff == 1) return ((1-$price_buff)*100)."% korting";
- if ($count_buff <= 4) {
- for ($i = $count_buff-1; $i > 0; $i--)
- if (abs((($i/$count_buff)-$price_buff)/$price_buff) < 0.001)
- return $i."+".($count_buff - $i)." gratis";
- }
- return ((1-$price_buff)*100)."% korting per ".$count_buff."-pack";
-}
-?>
+<?php require "../lib/promo.php"; ?>
<html>
<head>
<?php include 'head.php' ?>