From 19bdc8511b3b22509d2f46d71ef3b7597df0ec15 Mon Sep 17 00:00:00 2001 From: Robert Jensen Date: Fri, 6 Mar 2026 08:06:45 +0100 Subject: [PATCH 1/5] Overiew page for purchase reminders --- other/order.php | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 other/order.php diff --git a/other/order.php b/other/order.php new file mode 100644 index 0000000..d167bb3 --- /dev/null +++ b/other/order.php @@ -0,0 +1,102 @@ +query($query); + + # Start the table + echo("
"); + echo("

Existing ordering items

\n"); + echo("\n"); + echo("\n\n"); + echo("\n\n\n\n"); + echo(""); + + # Loop over alarms + while($row = $result->fetch()) { + + $query = "select unix_timestamp(time), value from dateplots_purchase_reminders where type=" . $row[0] . " order by id desc limit 1"; + // $latest_time = single_sql_value($db, $query, 0); Not really needed for now + $latest_value = single_sql_value($db, $query, 1); + + echo("\n\n\n"); + echo("\n"); + echo("\n"); + echo("\n"); + echo("\n"); + echo("\n"); + echo("\n"); + echo(""); + } + + # End the table + echo("\n\n
IDDescriptionValueActions
{$row[0]}{$row[1]}$latest_valueQRResetOrder
\n"); + echo("
\n"); +} + +function update_value_in_purchase_reminders($value){ + global $db; + global $id; + $query = "INSERT INTO dateplots_purchase_reminders (type, value) values (:i, :v)"; + $stmt = $db->prepare($query); + $stmt->bindValue(':i', $id); + $stmt->bindValue(':v', $value); + $stmt->execute(); +} + +// Handle the given action + +if (($action === '') && ($id > 0)){ + $query = "select unix_timestamp(time), value from dateplots_purchase_reminders where type=" . $id . " order by id desc limit 1"; + // $latest_time = single_sql_value($db, $query, 0); Not really needed for now + $latest_value = single_sql_value($db, $query, 1); + update_value_in_purchase_reminders($latest_value + 1); + echo("

Thank you for your notifying

\n"); +} + +if ($action === 'reset'){ + update_value_in_purchase_reminders(0); + echo("

Thank you for ordering supplies

\n"); +} + +if ($action=='qr'){ + ob_start(); + $command = './qr_generator.py ' . $id; + passthru($command, $return_code); + $content_grabbed=ob_get_contents(); + ob_end_clean(); + echo($content_grabbed); + + echo("

QR for item {$id}

\n"); + echo("\n"); +} + + +// Print the overview + +existing_purchase_reminders(); + + +echo("\n\n\n"); +echo(html_footer()); + +?> From f22260a4613282fde9f889ec8b508720f65dec19 Mon Sep 17 00:00:00 2001 From: Robert Jensen Date: Fri, 6 Mar 2026 08:24:56 +0100 Subject: [PATCH 2/5] Small cleanup, removing debug code --- other/order.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/other/order.php b/other/order.php index d167bb3..f17cc57 100644 --- a/other/order.php +++ b/other/order.php @@ -2,16 +2,10 @@ include("../common_functions_v2.php"); echo(html_header()); -// purchase_reminders -// dateplots_purchase_reminders - $id = intval($_GET["id"] ?? 0); $action = trim(strtolower(htmlspecialchars($_GET["action"] ?? ''))); -//$id = 26; -//$action = 'reset'; -$db = std_db(); -// $db = std_db($user='alarm_user'); +$db = std_db($user='alarm_user'); /** Produces the HTML for the existing purchase_reminders */ @@ -19,7 +13,6 @@ function existing_purchase_reminders(){ global $db; # Get the alarms - // $query = "SELECT * FROM alarm WHERE visible=1 order by id"; $query = "SELECT id, description FROM alarm WHERE description like \"[purchase_reminders]%\""; $result = $db->query($query); @@ -90,12 +83,9 @@ function update_value_in_purchase_reminders($value){ echo("\n"); } - // Print the overview - existing_purchase_reminders(); - echo("\n\n\n"); echo(html_footer()); From a049556433f5e00fa8d3640dbeefc9e3d7adf9b4 Mon Sep 17 00:00:00 2001 From: Robert Jensen Date: Fri, 6 Mar 2026 08:39:00 +0100 Subject: [PATCH 3/5] Create empty row in datepots when a purchase reminder is created --- other/alarms.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/other/alarms.php b/other/alarms.php index b631be3..4a3fb97 100755 --- a/other/alarms.php +++ b/other/alarms.php @@ -425,6 +425,17 @@ function insert_new(){ "trying to insert the new alarm: " . $db->errorInfo(), $alarm=true); } + + // If this is a purchase reminder, insert first dateplot row + if (str_contains($data["description"], "[purchase_reminders]")){ + $query = "INSERT INTO dateplots_purchase_reminders (type, value) values (:i, :v)"; + $stmt = $db->prepare($query); + $stmt->bindValue(':i', $latest_id); + $stmt->bindValue(':v', 0); + $stmt->execute(); + } + + return true; } From 42c48fb85fd4d26b52c6f9c40eebbd13a2ff0c71 Mon Sep 17 00:00:00 2001 From: Robert Jensen Date: Fri, 6 Mar 2026 09:10:05 +0100 Subject: [PATCH 4/5] Add URL to qr_script to prevent hard-coding hostname --- other/order.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/other/order.php b/other/order.php index f17cc57..2dc15ef 100644 --- a/other/order.php +++ b/other/order.php @@ -73,7 +73,8 @@ function update_value_in_purchase_reminders($value){ if ($action=='qr'){ ob_start(); - $command = './qr_generator.py ' . $id; + $url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; + $command = './qr_generator.py ' . $id . ' ' . $url; passthru($command, $return_code); $content_grabbed=ob_get_contents(); ob_end_clean(); From 12416d2743c7f95e55641211f64f2be296c491dc Mon Sep 17 00:00:00 2001 From: Robert Jensen Date: Fri, 6 Mar 2026 09:19:16 +0100 Subject: [PATCH 5/5] QR Generator for the purchace reminder module --- other/qr_generator.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 other/qr_generator.py diff --git a/other/qr_generator.py b/other/qr_generator.py new file mode 100755 index 0000000..8e94ca7 --- /dev/null +++ b/other/qr_generator.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 +import qrcode +import argparse + +from pathlib import Path + + +def make_qr(order_type: int, url: str): + qr = qrcode.QRCode( + version=10, + error_correction=qrcode.constants.ERROR_CORRECT_H, + box_size=20, + border=4, + ) + url = 'http://' + url + '?id={}' + url = url.format(order_type) + qr.add_data(url) + qr.make(fit=True) + img = qr.make_image(fill_color="black", back_color="white") + p = Path.cwd() + + img.save(p.parents[0] / 'figures' / 'qr_{}.png'.format(order_type)) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser('QR generator for cinfdata ordering system') + parser.add_argument('id', type=int) + parser.add_argument('url', type=str) + args = parser.parse_args() + make_qr(args.id, args.url)