CIM88 - Changelog en reporting
This commit is contained in:
105
api/v2/authorization.php
Normal file
105
api/v2/authorization.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Get user_details
|
||||
//------------------------------------------
|
||||
$user_credentials = json_decode($input,true);
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
$username = $user_credentials['username'] ?? '';
|
||||
//Define Query
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = ?');
|
||||
//Excute Query
|
||||
$stmt->execute([$username]);
|
||||
|
||||
//SETUP SQL FOR LOGIN_COUNT
|
||||
$sql_login = 'UPDATE users SET login_count = ? WHERE id = ?';
|
||||
|
||||
// Check if username exists. Verify user exists then verify
|
||||
if ($stmt->rowCount() == 1) {
|
||||
$user_data = $stmt->fetch();
|
||||
$permission = userRights($user_data['view']);
|
||||
$profile = getProfile($user_data['settings'],$permission);
|
||||
$password = $user_credentials['password'];
|
||||
|
||||
if ($user_data['login_count'] < 5){
|
||||
if (array_key_exists('resetkey', $user_credentials)){
|
||||
|
||||
if ($user_credentials['resetkey'] == ''){
|
||||
//Reset procedure
|
||||
//STEP 1.A- Create resetkey
|
||||
$headers = array('alg'=>'HS256','typ'=>'JWT');
|
||||
$payload = array('username'=>$user_data['username'], 'exp'=>(time() + 1800));
|
||||
$resetkey = generate_jwt($headers, $payload);
|
||||
//STEP 1.B Store in DB
|
||||
$sql = 'UPDATE users SET resetkey = ? WHERE id = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$resetkey,$user_data['id']]);
|
||||
//STEP 2- Send to user
|
||||
include_once './assets/mail/email_template_reset.php';
|
||||
send_mail($user_data['email'],$subject,$message,'','');
|
||||
//STEP 3- Update Login count
|
||||
$login_attempt = $user_data['login_count'] + 1;
|
||||
$stmt_login = $pdo->prepare($sql_login);
|
||||
$stmt_login->execute([$login_attempt, $user_data['id']]);
|
||||
}
|
||||
|
||||
} else { //STANDARD LOGIN
|
||||
if (password_verify($password, $user_data['password'])) {
|
||||
$token = createCommunicationToken($user_data['userkey']);
|
||||
|
||||
//RETURN JWT AND CLIENTSECRET
|
||||
$user = array(
|
||||
'clientID' => $user_data['id'],
|
||||
'token' => $token,
|
||||
'clientsecret' => $user_data['userkey']
|
||||
);
|
||||
|
||||
//Reset login count after succesfull attempt
|
||||
$login_attempt = 0;
|
||||
$stmt_login = $pdo->prepare($sql_login);
|
||||
$stmt_login->execute([$login_attempt, $user_data['id']]);
|
||||
|
||||
//Encrypt results
|
||||
$messages = $user;
|
||||
//Send results
|
||||
print_r($messages);
|
||||
|
||||
}
|
||||
else {
|
||||
//Update Login count with failed attempt
|
||||
$login_attempt = $user_data['login_count'] + 1;
|
||||
$stmt_login = $pdo->prepare($sql_login);
|
||||
$stmt_login->execute([$login_attempt, $user_data['id']]);
|
||||
//Send Response
|
||||
http_response_code(403); //Not authorized
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//User is blocked & send error
|
||||
$messages = '1';
|
||||
//------------------------------------------
|
||||
//Send results
|
||||
//------------------------------------------
|
||||
echo $messages;
|
||||
}
|
||||
} elseif (array_key_exists('resetkey', $user_credentials)) {
|
||||
if ($user_credentials['resetkey'] != ''){
|
||||
//UPDATE PASSWORD BASED ON RESETKEY
|
||||
$password = $user_credentials['password'];
|
||||
$passwordvalid = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $pdo->prepare('UPDATE users SET password = ? WHERE resetkey = ? ');
|
||||
$stmt->execute([$passwordvalid, $user_credentials['resetkey']]);
|
||||
|
||||
//
|
||||
} else {
|
||||
http_response_code(403);//Not authorized
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
http_response_code(403);//Not authorized
|
||||
}
|
||||
|
||||
?>
|
||||
141
api/v2/get/changelog.php
Normal file
141
api/v2/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 = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
//Send results
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
304
api/v2/get/equipments.php
Normal file
304
api/v2/get/equipments.php
Normal file
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Equipments
|
||||
//------------------------------------------
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//Get user_rights from users.php
|
||||
$partner = json_decode($partnerhierarchy);
|
||||
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '2':
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
||||
break;
|
||||
default:
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
||||
break;
|
||||
}
|
||||
//------------------------------------------
|
||||
//NEW ARRAY
|
||||
//------------------------------------------
|
||||
$criterias = [];
|
||||
$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] =='products' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='success_msg' || $v[0] =='download' || $v[0] =='sort'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'equipmentid') {
|
||||
//build up search
|
||||
$clause .= ' AND e.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'servicedate') {
|
||||
//build up service coverage
|
||||
$clause .= ' AND e.service_date <= :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'warrantydate') {
|
||||
//build up warranty coverage
|
||||
$clause .= ' AND e.warranty_date >= :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'historyid') {
|
||||
//build up history ID
|
||||
$clause .= ' AND h.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'type') {
|
||||
//build up history ID
|
||||
$clause .= ' AND h.type = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'h_equipmentid') {
|
||||
//build up search
|
||||
$clause .= ' AND h.equipmentid = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'status') {
|
||||
//Update status based on status
|
||||
$clause .= ' AND e.'.$v[0].' = :'.$v[0];
|
||||
$status = $v[1];
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
//build up search
|
||||
$clause .= ' AND (serialnumber like :'.$v[0].' OR e.rowID like :'.$v[0].')';
|
||||
}
|
||||
elseif ($v[0] == 'partnerid') {
|
||||
//build up accounthierarchy
|
||||
$clause .= ' AND e.accounthierarchy like :'.$v[0];
|
||||
}
|
||||
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].')';
|
||||
}
|
||||
}
|
||||
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).'%"';
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
$whereclause .= $clause;
|
||||
}
|
||||
}
|
||||
if (isset($criterias['download']) && $criterias['download'] ==''){
|
||||
//Request for download
|
||||
$sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY equipmentID';
|
||||
}
|
||||
elseif (isset($criterias['totals']) && $criterias['totals'] =='' && !isset($criterias['type'])){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.'';
|
||||
}
|
||||
elseif (isset($criterias['products']) && $criterias['products'] ==''){
|
||||
//Request for all products in equipment view
|
||||
$sql = 'SELECT distinct(p.productcode), p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY p.productcode';
|
||||
}
|
||||
elseif (isset($criterias['totals']) && $criterias['totals'] =='' && isset($criterias['type'])){
|
||||
//Request for total rows for history reports
|
||||
$sql ='SELECT count(*) as count from history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.'';
|
||||
}
|
||||
elseif (isset($criterias['history']) && $criterias['history'] != ''){
|
||||
|
||||
//History INDICATOR
|
||||
/*
|
||||
0 Show All
|
||||
1 Created DESC, LIMIT 5
|
||||
*/
|
||||
|
||||
switch ($criterias['history']) {
|
||||
case 1:
|
||||
$sort = ' ORDER BY h.created DESC LIMIT 0,'.$page_rows_equipment_servicereporst;
|
||||
break;
|
||||
|
||||
default:
|
||||
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||
$start_page = ($current_page - 1) * $page_rows_history;
|
||||
$sort = ' ORDER BY h.created DESC LIMIT '.$start_page.','.$page_rows_history;
|
||||
break;
|
||||
}
|
||||
//request history
|
||||
$sql ='SELECT h.rowID as historyID, e.rowID as equipmentID, h.equipmentid as h_equipmentid, e.serialnumber, h.type, h.description, h.created, h.createdby from history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.$sort;
|
||||
}
|
||||
else {
|
||||
// GET SORT INDICATOR
|
||||
$sort_indicator = $criterias['sort'] ?? '';
|
||||
|
||||
/*
|
||||
1 Serialnumber ASC
|
||||
2 Serialnumber DESC
|
||||
3 Status ASC
|
||||
4 Status DESC
|
||||
5 Warranty ASC
|
||||
6 Warranty DESC
|
||||
7 Service ASC
|
||||
8 Service DESC
|
||||
9 Latest ASC
|
||||
10 Latest DESC
|
||||
*/
|
||||
|
||||
switch ($sort_indicator){
|
||||
case 1:
|
||||
$sort = ' e.serialnumber ASC ';
|
||||
break;
|
||||
case 2:
|
||||
$sort = ' e.serialnumber DESC ';
|
||||
break;
|
||||
case 3:
|
||||
$sort = ' e.status ASC ';
|
||||
break;
|
||||
case 4:
|
||||
$sort = ' e.status DESC ';
|
||||
break;
|
||||
case 5:
|
||||
$sort = ' e.warranty_date ASC ';
|
||||
break;
|
||||
case 6:
|
||||
$sort = ' e.warranty_date DESC ';
|
||||
break;
|
||||
case 7:
|
||||
$sort = ' e.service_date ASC ';
|
||||
break;
|
||||
case 8:
|
||||
$sort = ' e.service_date DESC ';
|
||||
break;
|
||||
case 9:
|
||||
$sort = ' e.created DESC ';
|
||||
break;
|
||||
case 10:
|
||||
$sort = ' e.created ASC ';
|
||||
break;
|
||||
default:
|
||||
$sort = ' equipmentID ';
|
||||
break;
|
||||
}
|
||||
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_products';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//------------------------------------------
|
||||
//Bind to query
|
||||
//------------------------------------------
|
||||
if (str_contains($whereclause, ':status')){
|
||||
$stmt->bindValue('status', $status, PDO::PARAM_INT);
|
||||
}
|
||||
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);
|
||||
}
|
||||
elseif ($key == 'partnerid'){
|
||||
$search_value = '%"_"'.$value.'-%';
|
||||
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
|
||||
}
|
||||
elseif ($key == 'p'){
|
||||
//Do nothing (bug)
|
||||
}
|
||||
else {
|
||||
$stmt->bindValue($key, $value, 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 ((isset($criterias['history']) && $criterias['history'] !='') || (isset($criterias['products']) && $criterias['products'] =='') || (isset($criterias['download']) && $criterias['download'] =='')){
|
||||
//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_equipment, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_products', $page_rows_equipment, PDO::PARAM_INT);
|
||||
//Excute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
//------------------------------------------
|
||||
//JSON_DECODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
//------------------------------------------
|
||||
//Send results
|
||||
//------------------------------------------
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
40
api/v2/get/user_credentials.php
Normal file
40
api/v2/get/user_credentials.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Get user_details based on securitykey
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
//Define Query
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE service = ? OR userkey = ?');
|
||||
//Translate userkey to cliensecret
|
||||
$clientsecret = $userkey;
|
||||
//Excute Query
|
||||
$stmt->execute([$clientsecret, $clientsecret]);
|
||||
// Check if username exists.
|
||||
if ($stmt->rowCount() == 1) {
|
||||
//Get results
|
||||
$user_data = $stmt->fetch();
|
||||
//Define User data
|
||||
$partnerhierarchy = $user_data['partnerhierarchy'];
|
||||
$permission = userRights($user_data['view']);
|
||||
$profile= getProfile($user_data['settings'],$permission);
|
||||
$username = $user_data['username'];
|
||||
$useremail = $user_data['email'];
|
||||
$servicekey = $user_data['service'];
|
||||
$language = $user_data['language'];
|
||||
$partner = json_decode($partnerhierarchy);
|
||||
$clientsecret = $user_data['userkey'];
|
||||
|
||||
//Update Lastlogin
|
||||
$logindate = date('Y-m-d H:i:s');
|
||||
$stmt = $pdo->prepare('UPDATE users SET lastlogin = ? WHERE id = ?');
|
||||
//Excute Query
|
||||
$stmt->execute([$logindate, $user_data['id']]);
|
||||
} else
|
||||
{
|
||||
http_response_code(403);//Not authorized
|
||||
}
|
||||
|
||||
?>
|
||||
19
api/v2/post/debug.php
Normal file
19
api/v2/post/debug.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// DEBUG
|
||||
//------------------------------------------
|
||||
|
||||
//CONTENT FROM API (POST)
|
||||
$post_content = json_decode($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