CIM88 - Changelog en reporting
This commit is contained in:
141
api/v1/get/changelog.php
Normal file
141
api/v1/get/changelog.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Changelog
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
$whereclause = '';
|
||||
$clause = '';
|
||||
|
||||
//Check for $_GET variables and build up clause
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
//GET VARIABLES FROM URL
|
||||
$requests = explode("&", $get_content);
|
||||
//Check for keys and values
|
||||
foreach ($requests as $y){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$criterias[$v[0]] = $v[1];
|
||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='between' || $v[0] =='totals' || $v[0] =='reporttype' || $v[0] =='download' || $v[0] =='list'|| $v[0] =='success_msg'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
//build up search
|
||||
$clause .= ' AND (c.objectID like :'.$v[0].')';
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
if (isset($criterias['between']) && $criterias['between'] !=''){
|
||||
//ADD BETWEEN STATEMENT IF BETWEEN IS IN URL
|
||||
//BETWEEN delim ||
|
||||
$clause .= ' AND (c.created BETWEEN :start AND :end)';
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
$whereclause .= $clause;
|
||||
}
|
||||
}
|
||||
//Define Query
|
||||
if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM changelog c '.$whereclause;
|
||||
}
|
||||
elseif(isset($criterias['download']) && $criterias['download'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT * FROM changelog c '.$whereclause;
|
||||
}
|
||||
elseif(isset($criterias['reporttype']) && $criterias['reporttype'] !=''){
|
||||
|
||||
//SQL BASED ON REPORTTYPE
|
||||
// 1 = Totals
|
||||
// 2 = All
|
||||
switch ($criterias['reporttype']) {
|
||||
case 1:
|
||||
$sql = "SELECT count(distinct(c.objectID)) as total, DAY(c.created) as DoW , WEEK (c.created) as WoW, c.object_value FROM changelog c LEFT JOIN equipment e ON c.objectID = e.rowID $whereclause GROUP BY DoW ORDER BY WoW, DoW";
|
||||
break;
|
||||
case 2:
|
||||
$sql = "SELECT distinct(c.objectID) as objectID, DAY(c.created) as DoW , WEEK (c.created) as WoW, c.object_value, e.serialnumber FROM changelog c LEFT JOIN equipment e ON c.objectID = e.rowID $whereclause ORDER BY WoW, DoW";
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
//SQL for Paging
|
||||
$sql = "SELECT c.*,e.* FROM changelog c LEFT JOIN equipment e ON c.objectID = e.rowID $whereclause ORDER BY c.rowID DESC LIMIT :page,:num_changelog";
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//Bind to query
|
||||
if (str_contains($whereclause, ':condition')){
|
||||
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($whereclause, $key_condition)){
|
||||
if ($key == 'search'){
|
||||
$search_value = '%'.$value.'%';
|
||||
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
|
||||
}
|
||||
else {
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
//CHECK IF BETWEEN STATEMENT IS SENT
|
||||
if (str_contains($whereclause, ':start') && str_contains($whereclause, ':end')){
|
||||
//DATES ARE DELIM WITH ||
|
||||
$dates = explode("||", $value);
|
||||
$stmt->bindValue('start', $dates[0], PDO::PARAM_STR);
|
||||
$stmt->bindValue('end', $dates[1], PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// Debuglog
|
||||
//------------------------------------------
|
||||
if (debug){
|
||||
$message = $date.';'.$sql.';'.$username;
|
||||
debuglog($message);
|
||||
}
|
||||
|
||||
//Add paging details
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
elseif ($criterias['reporttype']){
|
||||
//Excute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
else {
|
||||
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||
$stmt->bindValue('page', ($current_page - 1) * $page_rows_changelog, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_changelog', $page_rows_changelog, PDO::PARAM_INT);
|
||||
|
||||
//Excute Query
|
||||
$stmt->execute();
|
||||
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_DECODE
|
||||
//------------------------------------------
|
||||
$messages = generate_payload($messages);
|
||||
//Send results
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
@@ -91,12 +91,42 @@ if(isset($get_content) && $get_content!=''){
|
||||
//build up accounthierarchy
|
||||
$clause .= ' AND e.accounthierarchy like :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'productcode') {
|
||||
//build up accounthierarchy
|
||||
$clause .= ' AND p.productcode = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'firmware') {
|
||||
//Include systemfirwmare
|
||||
include './settings/systemfirmware.php';
|
||||
//build up search
|
||||
$clause .= ' AND e.status != 5 AND e.sw_version not like "'.substr($FirmwarenameR06, 0, -4).'%"';
|
||||
}
|
||||
elseif ($v[0] == 'serialnumber') {
|
||||
//build up serialnumber
|
||||
//check if multiple serialnumbers are provided
|
||||
if (str_contains($v[1], ',')){
|
||||
$inputs = explode(",",$v[1]);
|
||||
$new_querystring = ''; //empty querystring
|
||||
$x=0;
|
||||
foreach($inputs as $input){
|
||||
//create key
|
||||
$new_key = $v[0].'_'.$x;
|
||||
//inject new key/value to array
|
||||
$criterias[$new_key] = $input;
|
||||
$new_querystring .= ':'.$new_key.',';
|
||||
$x++;
|
||||
}
|
||||
//remove obsolete last character from new_querystring
|
||||
$new_querystring = substr($new_querystring,0, -1);
|
||||
//add new_querystring to clause
|
||||
$clause .= ' AND e.serialnumber IN ('.$new_querystring.')';
|
||||
//remove original key/value from array
|
||||
unset($criterias[$v[0]]);
|
||||
}
|
||||
else {
|
||||
$clause .= ' AND e.serialnumber IN (:'.$v[0].')';
|
||||
}
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
|
||||
19
api/v1/post/debug.php
Normal file
19
api/v1/post/debug.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// DEBUG
|
||||
//------------------------------------------
|
||||
|
||||
//CONTENT FROM API (POST)
|
||||
$post_content = json_decode(decode_payload($input),true);
|
||||
|
||||
//ADD POST CONTENT TO DEBUG LOG
|
||||
|
||||
//------------------------------------------
|
||||
// Debuglog
|
||||
//------------------------------------------
|
||||
if (debug){
|
||||
$message = $date.';'.$post_content.';'.$username;
|
||||
debuglog($message);
|
||||
}
|
||||
Reference in New Issue
Block a user