add multifile support

This commit is contained in:
/jedi/ 2019-03-02 02:16:37 +01:00
parent 34cf28a2b2
commit c11edf96c9
4 changed files with 70 additions and 44 deletions

View file

@ -1,5 +1,6 @@
<?php <?php
function auth(){ function auth()
{
if (!isset($_SERVER['PHP_AUTH_USER'])) if (!isset($_SERVER['PHP_AUTH_USER']))
return false; return false;
if (!isset($_SERVER['PHP_AUTH_PW'])) if (!isset($_SERVER['PHP_AUTH_PW']))
@ -11,21 +12,33 @@ function auth(){
return true; return true;
} }
function get_founditems($onlyUnmatched = false){ function get_founditems($onlyUnmatched = false)
{
global $mysqli; global $mysqli;
if ($onlyUnmatched) { /*if ($onlyUnmatched) {
$res = $mysqli->query("SELECT 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"); $res = $mysqli->query("SELECT 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 { } 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"); $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");
}*/
if ($onlyUnmatched) {
$res = $mysqli->query("SELECT found_items.* FROM found_items LEFT JOIN matches ON found_items.id = matches.f_id WHERE found_items.del = 0 AND matches.f_id IS NULL ORDER BY found_items.id DESC");
} else {
$res = $mysqli->query("SELECT found_items.* FROM found_items WHERE found_items.del = 0 ORDER BY found_items.id ASC");
} }
$ret = array(); $ret = array();
while ($row = $res->fetch_assoc()) { while ($res && $row = $res->fetch_assoc()) {
$ret[] = $row; $ret[$row["id"]] = $row;
$ret[$row["id"]]["hash"] = "deprecated";
}
$res = $mysqli->query("SELECT files.* FROM files, found_items WHERE found_items.del = 0 AND found_items.id=files.item_id");
while ($res && $row = $res->fetch_assoc()) {
$ret[$row["item_id"]]["files"][] = $row;
} }
return $ret; return $ret;
} }
function get_lostitems($onlyUnmatched = false){ function get_lostitems($onlyUnmatched = false)
{
global $mysqli; global $mysqli;
if ($onlyUnmatched) { 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"); $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");
@ -33,73 +46,77 @@ function get_lostitems($onlyUnmatched = false){
$res = $mysqli->query("SELECT * FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC"); $res = $mysqli->query("SELECT * FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC");
} }
$ret = array(); $ret = array();
while ($row = $res->fetch_assoc()) { while ($res && $row = $res->fetch_assoc()) {
$ret[] = $row; $ret[] = $row;
} }
return $ret; return $ret;
} }
function get_founditem($id){ function get_founditem($id)
{
global $mysqli; global $mysqli;
$res = $mysqli->query("SELECT * FROM found_items, files WHERE MD5(found_items.id) = '" . md5($id) . "' AND found_items.id = files.item_id ORDER BY files.id DESC"); $res = $mysqli->query("SELECT * FROM found_items, files WHERE MD5(found_items.id) = '" . md5($id) . "' AND found_items.id = files.item_id ORDER BY files.id DESC");
if ($row = $res->fetch_assoc()) { if ($res && $row = $res->fetch_assoc()) {
return $row; return $row;
} else { } else {
return false; return false;
} }
} }
function get_founditem_by_uid($uid){ function get_founditem_by_uid($uid)
{
global $mysqli; global $mysqli;
$res = $mysqli->query("SELECT * FROM found_items, files WHERE MD5(found_items.uid) = '" . md5($uid) . "' AND found_items.id = files.item_id ORDER BY files.id DESC"); $res = $mysqli->query("SELECT * FROM found_items, files WHERE MD5(found_items.uid) = '" . md5($uid) . "' AND found_items.id = files.item_id ORDER BY files.id DESC");
if ($row = $res->fetch_assoc()) { if ($res && $row = $res->fetch_assoc()) {
return $row; return $row;
} else { } else {
return false; return false;
} }
} }
function get_matches(){ function get_matches()
{
global $mysqli; 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 " $res = $mysqli->query("SELECT matches.id AS id, matches.f_id as f_id, matches.l_id as l_id, lost_items.was as l_desc, found_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;"); . "FROM lost_items, found_items, matches WHERE lost_items.id = matches.l_id and found_items.id = matches.f_id ORDER BY matches.id ASC;");
$ret = array(); $ret = array();
while ($row = $res->fetch_assoc()) { while ($res && $row = $res->fetch_assoc()) {
$ret[] = $row; $ret[] = $row;
} }
return $ret; return $ret;
} }
function get_stats(){ function get_stats()
{
global $mysqli; global $mysqli;
$ret = array(); $ret = array();
$ret["lost"] = 0; $ret["lost"] = 0;
$ret["found"] = 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");
$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(); $ret["graph"] = array();
while ($row = $res->fetch_assoc()) { while ($res && $row = $res->fetch_assoc()) {
$ret["graph"][] = $row; $ret["graph"][] = $row;
} }
$res = $mysqli->query("SELECT COUNT(*) AS c FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC"); $res = $mysqli->query("SELECT COUNT(*) AS c FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC");
if ($row = $res->fetch_assoc()) { if ($res && $row = $res->fetch_assoc()) {
$ret["lost"] = $row["c"]; $ret["lost"] = $row["c"];
} }
$res = $mysqli->query("SELECT COUNT(*) AS c FROM found_items WHERE found_items.del = 0 ORDER BY id ASC"); $res = $mysqli->query("SELECT COUNT(*) AS c FROM found_items WHERE found_items.del = 0 ORDER BY id ASC");
if ($row = $res->fetch_assoc()) { if ($res && $row = $res->fetch_assoc()) {
$ret["found"] = $row["c"]; $ret["found"] = $row["c"];
} }
$res = $mysqli->query("SELECT COUNT(*) AS c FROM matches ORDER BY id ASC"); $res = $mysqli->query("SELECT COUNT(*) AS c FROM matches ORDER BY id ASC");
if ($row = $res->fetch_assoc()) { if ($res && $row = $res->fetch_assoc()) {
$ret["match"] = $row["c"]; $ret["match"] = $row["c"];
} }
$ret["unmatched"] = $ret["found"] + $ret["lost"] - 2 * $ret["match"]; $ret["unmatched"] = $ret["found"] + $ret["lost"] - 2 * $ret["match"];
return $ret; return $ret;
} }
?> ?>

View file

@ -21,7 +21,7 @@
<input type="text" class="form-control" readonly> <input type="text" class="form-control" readonly>
</div> </div>
</div> </div>
<img id='img-upload' src="/upload/<?php echo $item["hash"]; ?>"/> <img id='img-upload' src="/upload/<?php echo $item["files"][0]["hash"]; ?>"/>
</div> </div>
<p><button type="submit" class="form-control" onclick="edit_found_item(); return false;">Save</button></p> <p><button type="submit" class="form-control" onclick="edit_found_item(); return false;">Save</button></p>
</form> </form>

View file

@ -43,9 +43,15 @@
<td><?php echo $item["wo"]; ?></td> <td><?php echo $item["wo"]; ?></td>
<td><?php echo $item["container"];?></td> <td><?php echo $item["container"];?></td>
<td> <td>
<button class="btn btn-link" data-toggle="modal" data-target="#exampleModal_picture" onclick="show_picture('<?php echo $item["hash"]; ?>')"> <?php
<img style="height: 48px;" src="/thumb/<?php echo $item["hash"]; ?>"> if(isset($item["files"])){
?>
<button class="btn btn-link" data-toggle="modal" data-target="#exampleModal_picture" onclick="show_picture('<?php echo $item["files"][0]["hash"]; ?>')">
<img style="height: 48px;" src="/thumb/<?php echo $item["files"][0]["hash"]; ?>">
</button> </button>
<?php
}
?>
</td> </td>
<!--<td><img style="height: 48px;" src="/upload/<?php echo $item["hash"]; ?>"></td>--> <!--<td><img style="height: 48px;" src="/upload/<?php echo $item["hash"]; ?>"></td>-->
<td> <td>

View file

@ -47,14 +47,17 @@
<script> <script>
function fill_edit_form(id, was, wann, wo, hash, container) { function fill_edit_form(item) {
document.getElementById('id').value = item.id;
document.getElementById('id').value = id; document.getElementById('was').value = item.was;
document.getElementById('was').value = was; document.getElementById('wann').value = item.wann;
document.getElementById('wann').value = wann; document.getElementById('wo').value = item.wo;
document.getElementById('wo').value = wo; document.getElementById('container').value = item.container;
document.getElementById('container').value = container; if(item.files&&item.files.length>0){
document.getElementById('img-upload').src = "/upload/"+hash; document.getElementById('img-upload').src = "/upload/"+item.files[0].hash;
}else{
document.getElementById('img-upload').src = "";
}
} }