2018-12-27 04:23:10 +00:00
< ? php
/**
* Created by PhpStorm .
* User : jedi
* Date : 12 / 27 / 18
* Time : 2 : 49 AM
*/
2018-12-27 07:27:47 +00:00
include " backend.php " ;
2018-12-27 04:23:10 +00:00
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 ;
2018-12-27 20:31:06 +00:00
if ( $_SERVER [ 'PHP_AUTH_PW' ] != " findetalles " )
2018-12-27 04:23:10 +00:00
return false ;
return true ;
}
2018-12-28 00:24:31 +00:00
function get_founditems ( $onlyUnmatched = false ){
2018-12-27 04:23:10 +00:00
global $mysqli ;
2018-12-28 00:24:31 +00:00
if ( $onlyUnmatched ) {
2019-02-22 12:26:57 +00:00
$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 " );
2018-12-28 00:24:31 +00:00
} else {
2019-02-22 12:26:57 +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 WHERE files.item_id = found_items.id AND found_items.del = 0 GROUP BY files.item_id ORDER BY found_items.id ASC " );
2018-12-28 00:24:31 +00:00
}
2018-12-27 04:23:10 +00:00
$ret = array ();
while ( $row = $res -> fetch_assoc ()) {
$ret [] = $row ;
}
return $ret ;
}
2018-12-28 00:24:31 +00:00
function get_lostitems ( $onlyUnmatched = false ){
2018-12-27 07:52:14 +00:00
global $mysqli ;
2018-12-28 00:24:31 +00:00
if ( $onlyUnmatched ) {
2019-02-21 23:02:28 +00:00
$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 " );
2018-12-28 00:24:31 +00:00
} else {
2019-02-21 23:02:28 +00:00
$res = $mysqli -> query ( " SELECT * FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC " );
2018-12-28 00:24:31 +00:00
}
2018-12-27 07:52:14 +00:00
$ret = array ();
while ( $row = $res -> fetch_assoc ()) {
$ret [] = $row ;
}
return $ret ;
}
2019-02-22 12:26:57 +00:00
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 ;
}
2018-12-27 18:51:29 +00:00
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 ;
2019-02-21 23:02:28 +00:00
2019-02-22 12:53:53 +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 " );
2019-02-21 23:02:28 +00:00
$ret [ " graph " ] = array ();
2019-02-22 12:53:53 +00:00
while ( $res && $row = $res -> fetch_assoc ()) {
2019-02-21 23:02:28 +00:00
$ret [ " graph " ][] = $row ;
}
$res = $mysqli -> query ( " SELECT COUNT(*) AS c FROM lost_items WHERE lost_items.del = 0 ORDER BY id ASC " );
2019-02-22 12:53:53 +00:00
if ( $res && $row = $res -> fetch_assoc ()) {
2018-12-27 18:51:29 +00:00
$ret [ " lost " ] = $row [ " c " ];
}
2019-02-21 23:02:28 +00:00
$res = $mysqli -> query ( " SELECT COUNT(*) AS c FROM found_items WHERE found_items.del = 0 ORDER BY id ASC " );
2019-02-22 12:53:53 +00:00
if ( $res && $row = $res -> fetch_assoc ()) {
2018-12-27 18:51:29 +00:00
$ret [ " found " ] = $row [ " c " ];
}
$res = $mysqli -> query ( " SELECT COUNT(*) AS c FROM matches ORDER BY id ASC " );
2019-02-22 12:53:53 +00:00
if ( $res && $row = $res -> fetch_assoc ()) {
2018-12-27 18:51:29 +00:00
$ret [ " match " ] = $row [ " c " ];
}
2018-12-29 20:56:33 +00:00
$ret [ " unmatched " ] = $ret [ " found " ] + $ret [ " lost " ] - 2 * $ret [ " match " ];
2018-12-27 18:51:29 +00:00
return $ret ;
}
2018-12-27 19:52:35 +00:00
if ( file_exists ( " currentgithash " ))
$hash = file_get_contents ( " currentgithash " );
2018-12-27 07:27:47 +00:00
$page = isset ( $_GET [ " page " ]) ? $_GET [ " page " ] : " dashboard " ;
2018-12-27 04:23:10 +00:00
if ( ! auth ()) {
header ( 'WWW-Authenticate: Basic realm="C3CLOC"' );
header ( 'HTTP/1.0 401 Unauthorized' );
2018-12-27 07:27:47 +00:00
include " templates/404.php " ;
2018-12-27 04:23:10 +00:00
exit ;
} else {
2018-12-27 07:27:47 +00:00
include " templates/page.php " ;
2018-12-27 04:23:10 +00:00
}
?>