From 33ec4480d6981418feca7d3252ffb1ba264e6cd6 Mon Sep 17 00:00:00 2001 From: Katharina Date: Fri, 22 Feb 2019 15:30:43 +0100 Subject: [PATCH] Implement Popup Window for Edit Found Items --- ajax.php | 74 ++++++++++++- functions.php | 93 ++++++++++++++++ index.php | 92 +--------------- templates/table.php | 250 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 406 insertions(+), 103 deletions(-) create mode 100644 functions.php diff --git a/ajax.php b/ajax.php index 405b7b6..943eb5a 100644 --- a/ajax.php +++ b/ajax.php @@ -7,6 +7,7 @@ */ include "backend.php"; +include "functions.php"; function hasval($var){ return isset($var) && !empty($var); @@ -102,10 +103,10 @@ switch($_GET["action"]) { } break; case "edit_found_item": - if(hasval($_POST["id"]) && hasval($_POST["was"]) && hasval($_POST["wann"])) { + if(hasval($_POST["id"]) && hasval($_POST["was"])) { /* Prepared statement, stage 1: prepare */ $was=$_POST["was"]; - if (!($stmt = $mysqli->prepare("UPDATE found_items SET was=?, wo=?, `date`=? WHERE id = ?"))) { + if (!($stmt = $mysqli->prepare("UPDATE found_items SET was=?, wo=?, wann=? WHERE id = ?"))) { $errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; } if (!$stmt->bind_param("sssi", $_POST["was"] , $_POST["wo"], $_POST["wann"], $_POST["id"])) { @@ -115,7 +116,9 @@ switch($_GET["action"]) { $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; } - if(isset($_FILES["image"])){ + $successmsg = "one item edited"; + + if(isset($_FILES["image"])&& hasval($_FILES["image"]["tmp_name"])){ if(!file_exists ( "upload/")){ mkdir("upload/"); } @@ -132,11 +135,11 @@ switch($_GET["action"]) { $errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error; } $successmsg = "one item edited"; + }else{ $errormsg = "upload failed"; } }else{ - $errormsg = "upload failed"; } @@ -179,12 +182,73 @@ switch($_GET["action"]) { $errormsg = "upload failed"; } }else{ - $errormsg = "upload failed"; } }else{ $errormsg = "all values have to be set"; } break; + case "get_found_table": + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDwaswannwofoto
IDwaswannwofoto
"> +
+ + + + +
+
+ query("SELECT distinct found_items.*, files.hash FROM (SELECT files.* from files ORDER BY files.id DESC LIMIT 100000) as files, found_items LEFT JOIN matches ON found_items.id = matches.f_id WHERE found_items.del = 0 AND files.item_id = found_items.id AND matches.f_id IS NULL GROUP BY files.item_id ORDER BY found_items.id DESC"); + } else { + $res = $mysqli->query("SELECT found_items.*, files.hash FROM (SELECT files.* from files ORDER BY files.id DESC LIMIT 100000) as files, found_items WHERE files.item_id = found_items.id AND found_items.del = 0 GROUP BY files.item_id ORDER BY found_items.id ASC"); + } + $ret = array(); + while ($row = $res->fetch_assoc()) { + $ret[] = $row; + } + return $ret; +} + +function get_lostitems($onlyUnmatched = false){ + global $mysqli; + if ($onlyUnmatched) { + $res = $mysqli->query("SELECT lost_items.* FROM lost_items LEFT JOIN matches ON lost_items.id = matches.l_id WHERE lost_items.del = 0 AND matches.l_id IS NULL ORDER BY lost_items.id DESC"); + } else { + $res = $mysqli->query("SELECT * FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC"); + } + $ret = array(); + while ($row = $res->fetch_assoc()) { + $ret[] = $row; + } + return $ret; +} + +function get_founditem($id){ + global $mysqli; + + $res = $mysqli->query("SELECT * FROM found_items, files WHERE found_items.id = $id AND found_items.id = files.item_id ORDER BY files.id DESC"); + + $ret = array(); + while ($row = $res->fetch_assoc()) { + $ret[] = $row; + } + return $ret; +} + +function get_matches(){ + global $mysqli; + $res = $mysqli->query("SELECT matches.id AS id, matches.f_id as f_id, matches.l_id as l_id, lost.was as l_desc, items.was as f_desc " + ."FROM lost, items, matches WHERE lost.id = matches.l_id and items.id = matches.f_id ORDER BY matches.id ASC;"); + $ret = array(); + while ($row = $res->fetch_assoc()) { + $ret[] = $row; + } + return $ret; +} + +function get_stats(){ + global $mysqli; + $ret = array(); + $ret["lost"]=0; + $ret["found"]=0; + + + + $res = $mysqli->query("select hour(date) as h, day(date) as d, count(date) as c from items group by h, d order by d, h"); + $ret["graph"] = array(); + while ($row = $res->fetch_assoc()) { + $ret["graph"][] = $row; + } + $res = $mysqli->query("SELECT COUNT(*) AS c FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC"); + if ($row = $res->fetch_assoc()) { + $ret["lost"] = $row["c"]; + } + $res = $mysqli->query("SELECT COUNT(*) AS c FROM found_items WHERE found_items.del = 0 ORDER BY id ASC"); + if ($row = $res->fetch_assoc()) { + $ret["found"] = $row["c"]; + } + $res = $mysqli->query("SELECT COUNT(*) AS c FROM matches ORDER BY id ASC"); + if ($row = $res->fetch_assoc()) { + $ret["match"] = $row["c"]; + } + $ret["unmatched"] = $ret["found"] + $ret["lost"] - 2 * $ret["match"]; + return $ret; +} +?> \ No newline at end of file diff --git a/index.php b/index.php index b26617c..a0a63df 100644 --- a/index.php +++ b/index.php @@ -7,98 +7,8 @@ */ include "backend.php"; +include "functions.php"; -function auth(){ - if(!isset($_SERVER['PHP_AUTH_USER'])) - return false; - if(!isset($_SERVER['PHP_AUTH_PW'])) - return false; - if($_SERVER['PHP_AUTH_USER']!="c3cloc") - return false; - if($_SERVER['PHP_AUTH_PW']!="findetalles") - return false; - return true; -} - -function get_founditems($onlyUnmatched = false){ - global $mysqli; - if ($onlyUnmatched) { - $res = $mysqli->query("SELECT distinct found_items.*, files.hash FROM (SELECT files.* from files ORDER BY files.id DESC LIMIT 100000) as files, found_items LEFT JOIN matches ON found_items.id = matches.f_id WHERE found_items.del = 0 AND files.item_id = found_items.id AND matches.f_id IS NULL GROUP BY files.item_id ORDER BY found_items.id DESC"); - } else { - $res = $mysqli->query("SELECT found_items.*, files.hash FROM (SELECT files.* from files ORDER BY files.id DESC LIMIT 100000) as files, found_items WHERE files.item_id = found_items.id AND found_items.del = 0 GROUP BY files.item_id ORDER BY found_items.id ASC"); - } - $ret = array(); - while ($row = $res->fetch_assoc()) { - $ret[] = $row; - } - return $ret; -} - -function get_lostitems($onlyUnmatched = false){ - global $mysqli; - if ($onlyUnmatched) { - $res = $mysqli->query("SELECT lost_items.* FROM lost_items LEFT JOIN matches ON lost_items.id = matches.l_id WHERE lost_items.del = 0 AND matches.l_id IS NULL ORDER BY lost_items.id DESC"); - } else { - $res = $mysqli->query("SELECT * FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC"); - } - $ret = array(); - while ($row = $res->fetch_assoc()) { - $ret[] = $row; - } - return $ret; -} - -function get_founditem($id){ - global $mysqli; - - $res = $mysqli->query("SELECT * FROM found_items, files WHERE found_items.id = $id AND found_items.id = files.item_id ORDER BY files.id DESC"); - - $ret = array(); - while ($row = $res->fetch_assoc()) { - $ret[] = $row; - } - return $ret; -} - -function get_matches(){ - global $mysqli; - $res = $mysqli->query("SELECT matches.id AS id, matches.f_id as f_id, matches.l_id as l_id, lost.was as l_desc, items.was as f_desc " - ."FROM lost, items, matches WHERE lost.id = matches.l_id and items.id = matches.f_id ORDER BY matches.id ASC;"); - $ret = array(); - while ($row = $res->fetch_assoc()) { - $ret[] = $row; - } - return $ret; -} - -function get_stats(){ - global $mysqli; - $ret = array(); - $ret["lost"]=0; - $ret["found"]=0; - - - - $res = $mysqli->query("select hour(date) as h, day(date) as d, count(date) as c from found_items group by h, d order by d, h"); - $ret["graph"] = array(); - while ($res && $row = $res->fetch_assoc()) { - $ret["graph"][] = $row; - } - $res = $mysqli->query("SELECT COUNT(*) AS c FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC"); - if ($res && $row = $res->fetch_assoc()) { - $ret["lost"] = $row["c"]; - } - $res = $mysqli->query("SELECT COUNT(*) AS c FROM found_items WHERE found_items.del = 0 ORDER BY id ASC"); - if ($res && $row = $res->fetch_assoc()) { - $ret["found"] = $row["c"]; - } - $res = $mysqli->query("SELECT COUNT(*) AS c FROM matches ORDER BY id ASC"); - if ($res && $row = $res->fetch_assoc()) { - $ret["match"] = $row["c"]; - } - $ret["unmatched"] = $ret["found"] + $ret["lost"] - 2 * $ret["match"]; - return $ret; -} if(file_exists("currentgithash")) $hash = file_get_contents("currentgithash"); diff --git a/templates/table.php b/templates/table.php index 79d1143..5f27512 100644 --- a/templates/table.php +++ b/templates/table.php @@ -6,7 +6,11 @@ * Time: 4:48 AM */ ?> - +
@@ -27,13 +31,86 @@ A simple success alert—check it out!
+ + + + + + + + +
Data Table Example
-
+
@@ -60,15 +137,19 @@ foreach( get_founditems(true) as $item){ ?> - + - + + @@ -100,11 +181,30 @@ + +
">