c3lf-system-3/functions.php

122 lines
4.4 KiB
PHP
Raw Normal View History

<?php
2019-03-02 01:16:37 +00:00
function auth()
{
if (!isset($_SERVER['PHP_AUTH_USER']))
return false;
2019-03-02 01:16:37 +00:00
if (!isset($_SERVER['PHP_AUTH_PW']))
return false;
2019-03-02 01:16:37 +00:00
if ($_SERVER['PHP_AUTH_USER'] != "c3cloc")
return false;
2019-03-02 01:16:37 +00:00
if ($_SERVER['PHP_AUTH_PW'] != "findetalles")
return false;
return true;
}
2019-03-02 01:16:37 +00:00
function get_founditems($onlyUnmatched = false)
{
global $mysqli;
2019-03-02 01:16:37 +00:00
/*if ($onlyUnmatched) {
2019-02-22 19:47:26 +00:00
$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 {
$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");
2019-03-02 01:16:37 +00:00
}*/
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();
2019-03-02 01:16:37 +00:00
while ($res && $row = $res->fetch_assoc()) {
$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;
}
2019-03-02 01:16:37 +00:00
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();
2019-03-02 01:16:37 +00:00
while ($res && $row = $res->fetch_assoc()) {
$ret[] = $row;
}
return $ret;
}
2019-03-02 01:16:37 +00:00
function get_founditem($id)
{
global $mysqli;
2019-03-02 01:16:37 +00:00
$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");
2019-03-02 01:16:37 +00:00
if ($res && $row = $res->fetch_assoc()) {
2019-02-23 09:43:45 +00:00
return $row;
2019-03-02 01:16:37 +00:00
} else {
2019-02-23 09:43:45 +00:00
return false;
}
}
2019-03-02 01:16:37 +00:00
function get_founditem_by_uid($uid)
{
2019-02-23 09:43:45 +00:00
global $mysqli;
2019-03-02 01:16:37 +00:00
$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");
2019-02-23 09:43:45 +00:00
2019-03-02 01:16:37 +00:00
if ($res && $row = $res->fetch_assoc()) {
2019-02-23 09:43:45 +00:00
return $row;
2019-03-02 01:16:37 +00:00
} else {
2019-02-23 09:43:45 +00:00
return false;
}
}
2019-03-02 01:16:37 +00:00
function get_matches()
{
global $mysqli;
2019-03-02 01:16:37 +00:00
$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, found_items, matches WHERE lost_items.id = matches.l_id and found_items.id = matches.f_id ORDER BY matches.id ASC;");
$ret = array();
2019-03-02 01:16:37 +00:00
while ($res && $row = $res->fetch_assoc()) {
$ret[] = $row;
}
return $ret;
}
2019-03-02 01:16:37 +00:00
function get_stats()
{
global $mysqli;
$ret = array();
2019-03-02 01:16:37 +00:00
$ret["lost"] = 0;
$ret["found"] = 0;
2019-03-02 01:16:37 +00:00
$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();
2019-03-02 01:16:37 +00:00
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");
2019-03-02 01:16:37 +00:00
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");
2019-03-02 01:16:37 +00:00
if ($res && $row = $res->fetch_assoc()) {
$ret["found"] = $row["c"];
}
$res = $mysqli->query("SELECT COUNT(*) AS c FROM matches ORDER BY id ASC");
2019-03-02 01:16:37 +00:00
if ($res && $row = $res->fetch_assoc()) {
$ret["match"] = $row["c"];
}
$ret["unmatched"] = $ret["found"] + $ret["lost"] - 2 * $ret["match"];
return $ret;
}
2019-03-02 01:16:37 +00:00
?>