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; } diff --git a/other/order.php b/other/order.php new file mode 100644 index 0000000..2dc15ef --- /dev/null +++ b/other/order.php @@ -0,0 +1,93 @@ +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(); + $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(); + echo($content_grabbed); + + echo("

QR for item {$id}

\n"); + echo("\n"); +} + +// Print the overview +existing_purchase_reminders(); + +echo("\n\n\n"); +echo(html_footer()); + +?> 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)