From 6dd8041fe4799697e3d9920f2f3d8efbe475c853 Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Sat, 2 Mar 2019 02:19:17 +0100 Subject: [PATCH] add new matching page --- ajax.php | 38 ++++++++++++++++ templates/found_item_table.php | 2 +- templates/match.php | 81 ++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 templates/match.php diff --git a/ajax.php b/ajax.php index 07ca083..f37e2e0 100644 --- a/ajax.php +++ b/ajax.php @@ -85,6 +85,44 @@ switch($_GET["action"]) { $errormsg = "all values have to be set"; } break; + case "add_match": + $successmsg = "one match added"; + if (hasval($_POST["found_id"]) && hasval($_POST["lost_id"])) { + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("INSERT INTO matches(f_id, l_id) VALUES (?, ?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("ii", $_POST["found_id"], $_POST["lost_id"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + }else if (hasval($_POST["found_id"]) && hasval($_POST["ticket_id"])) { + if (!($stmt = $mysqli->prepare("INSERT INTO lost_items(was) VALUES (?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("s", $_POST["ticket_id"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + $lost_id = $mysqli->insert_id; + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("INSERT INTO matches(f_id, l_id) VALUES (?, ?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("ii", $_POST["found_id"], $lost_id)) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + }else{ + $errormsg = "all values have to be set"; + } + break; case "get_stats"; echo json_encode(array("status"=>"ok","stats"=>get_stats())); break; diff --git a/templates/found_item_table.php b/templates/found_item_table.php index 1682c77..a07aaf8 100644 --- a/templates/found_item_table.php +++ b/templates/found_item_table.php @@ -55,7 +55,7 @@
- + /" class="btn btn-outline-success" title="match"> +
+ + + + + + + + + + + +