From 6e6e695bb6f792a5a539ed9edffb66be36830bf0 Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Fri, 22 Feb 2019 00:10:56 +0100 Subject: [PATCH] add better found_item_form --- ajax.php | 81 ++++++++++++- templates/found_item.php | 242 +++++++++++++++++++++++++++++++++++++++ templates/sidebar.php | 11 ++ templates/table.php | 44 +++++++ 4 files changed, 376 insertions(+), 2 deletions(-) create mode 100644 templates/found_item.php diff --git a/ajax.php b/ajax.php index c12817e..b80c2fc 100644 --- a/ajax.php +++ b/ajax.php @@ -12,6 +12,8 @@ function hasval($var){ return isset($var) && !empty($var); } +$successmsg = "added one item"; + switch($_GET["action"]) { case "add_featurerequest": if (hasval($_POST["title"]) && hasval($_POST["desc"])) { @@ -65,14 +67,89 @@ switch($_GET["action"]) { case "get_stats"; echo json_encode(array("status"=>"ok","stats"=>get_stats())); break; + case "delete_found_item": + if(hasval($_POST["id"])) { + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("UPDATE found_items SET del = 1 WHERE id = ?"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("i", $_POST["id"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + $successmsg = "one item deleted"; + }else{ + $errormsg = "id not set"; + } + break; + case "delete_lost_item": + if(hasval($_POST["id"])) { + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("UPDATE lost_items SET del = 1 WHERE id = ?"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("i", $_POST["id"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + $successmsg = "one item deleted"; + }else{ + $errormsg = "id not set"; + } + break; + case "add_found_item": + if (hasval($_POST["was"])) { + /* Prepared statement, stage 1: prepare */ + if (!($stmt = $mysqli->prepare("INSERT INTO found_items(was) VALUES (?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("s", $_POST["was"])) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + $item_id = $mysqli->insert_id; + + if(isset($_FILES["image"])){ + if(!file_exists ( "upload/")){ + mkdir("upload/"); + } + + $hash = md5($_FILES['image']['name'].time()); + if(move_uploaded_file($_FILES['image']['tmp_name'], "upload/".$hash)){ + if (!($stmt = $mysqli->prepare("INSERT INTO files(hash, item_id) VALUES (?, ?)"))) { + $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; + } + if (!$stmt->bind_param("si", $hash, $item_id)) { + $errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; + } + if (!$stmt->execute()) { + $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; + } + $successmsg = "upload ok"; + }else{ + $errormsg = "upload failed"; + } + }else{ + $errormsg = "upload failed"; + } + }else{ + $errormsg = "all values have to be set"; + } + break; default: $errormsg = "action unknown"; break; } if(empty($errormsg)) - echo json_encode(array("get"=>$_GET,"post"=>$_POST,"status"=>"ok","message"=>"added one item")); + echo json_encode(array("get"=>$_GET,"post"=>$_POST,"files"=>$_FILES,"status"=>"ok","message"=>$successmsg)); else - echo json_encode(array("get"=>$_GET,"post"=>$_POST,"status"=>"error","message"=>$errormsg)); + echo json_encode(array("get"=>$_GET,"post"=>$_POST,"files"=>$_FILES,"status"=>"error","message"=>$errormsg)); ?> \ No newline at end of file diff --git a/templates/found_item.php b/templates/found_item.php new file mode 100644 index 0000000..67d7919 --- /dev/null +++ b/templates/found_item.php @@ -0,0 +1,242 @@ + + + + + +
+ + + + + + + + + + +
+
+ + Insert Item into DB +
+
+
+ + + +
+ +
+ +
+
+
+ + + +
+
+ +
+ +
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/sidebar.php b/templates/sidebar.php index 2dc28b0..a9c48c0 100644 --- a/templates/sidebar.php +++ b/templates/sidebar.php @@ -14,6 +14,17 @@ Dashboard + + + + + + + + + + +