Initial commit

This commit is contained in:
“VeLiTi”
2024-03-15 12:43:10 +01:00
commit 670b00eeab
424 changed files with 216891 additions and 0 deletions

BIN
api/v0/.DS_Store vendored Normal file

Binary file not shown.

64
api/v0/authorization.php Normal file
View File

@@ -0,0 +1,64 @@
<?php
defined($security_key) or exit;
//ini_set('display_errors', '1');
//ini_set('display_startup_errors', '1');
//error_reporting(E_ALL);
//------------------------------------------
// Get user_details
//------------------------------------------
$user_credentials = json_decode($input,true);
$username = $user_credentials['username'];
$password = $user_credentials['password'];
if (!empty($username) && !empty($password)) {
$username = strip_tags(trim($username));
$password = strip_tags(trim($password));
$conn = new mysqli($db,$dbuser,$dbpw,$dbname_users);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, username, password, service FROM users WHERE username='$username'";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
while ($row = $result->fetch_assoc()) {
if (password_verify($password, $row['password'])) {
if(empty($row['service'])){
echo 'No service account found';
http_response_code(401);
}
else {
$service = $row['service'];
$jwt = createCommunicationToken($service);
$logindate = date('Y-m-d H:i:s');
$id = $row['id'];
$sql1 = "UPDATE users SET lastlogin = '$logindate' WHERE id='$id'";
$conn->query($sql1);
echo json_encode(array('token' => $jwt));
}
}
else
{
http_response_code(203);
}
}
}
else {
http_response_code(203);
}
$conn->close();
}
else {
http_response_code(400);
}
?>

328
api/v0/get/application.php Normal file
View File

@@ -0,0 +1,328 @@
<?php
//defined($security_key) or exit;
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
//------------------------------------------
// Application related calls
//------------------------------------------
$action = $request[2];
// Connect to DB
$pdo = dbConnect($dbname);
function checkSerial($serialinput){
//Check Serialnumber used
if (preg_match('/^[^-]*-[^-]*$/', $serialinput)){
$check=explode('-', $serialinput);
$productrowid = strip_tags(trim($check[0]));
$rowID= strip_tags(trim($check[1]));
$whereclause = 'WHERE rowID = "'.$rowID.'"';
}
else
{
$serialnumberhelper = strip_tags(trim($serialinput));
$whereclause = 'WHERE serialnumber = "'.$serialnumberhelper.'"';
}
return $whereclause;
}
//////// - ACTIONS - API - //////////////////
switch ($action){
case 'validateSerial':
if (isset($_GET['sn']) && $_GET['sn'] != ''){
//Get Productcode
$idcheck = "-";
$whereclause = checkSerial($_GET['sn']);
$sql = "SELECT count(rowID) as rowID from equipment $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute();
//Get results
$messages = $stmt->fetch();
if ($messages[0] == 1) {
echo json_encode(array('SN'=> TRUE));
}
else {
echo json_encode(array('SN'=> FALSE));
}
}
elseif (isset($_GET['esm']) && $_GET['esm'] != '') {
//FILTER ESM Number
$filter1 = 'ESM":"'.$_GET['esm'].'","SN":';
//BUILD SQL
$whereclause = "WHERE description like '%$filter1%'";
$sql = "SELECT rowID from history $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute();
//Get results
$messages = $stmt->fetch();
if ($messages[0] > 0) {
echo json_encode(array('ESM'=> TRUE));
}
else {
echo json_encode(array('ESM'=> FALSE));
}
}
else {
http_response_code(400);
}
break;
case 'getProducts':
$sql = "SELECT * FROM products";
$stmt = $pdo->prepare($sql);
$stmt->execute();
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($messages);
break;
case 'getEquipmentHistory':
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Return all when nothing specified +++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$whereclause = '';
$sn_found = 0;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Check SN +++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (isset($_GET['sn']) && $_GET['sn'] != '') {
//Get Productcode
$sn = strip_tags(trim($_GET['sn']));
$sn_found = 1; //indicates SN is found
$whereclause = 'WHERE h.description like "%historycreated%SN%:%'.$sn.'%" and h.type !="SRIncluded"';
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Check Filter ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Type Filter
if (isset($_GET['type']) && $_GET['type'] != ''){
switch ($_GET['type']) {
case 'latest':
if ($sn_found == 1){
$whereclause .= ' AND h.rowID in (Select MAX(h.rowID) AS row_ID FROM history h GROUP BY h.equipmentid)';
}
else
{
$whereclause = "WHERE h.rowID in (Select MAX(h.rowID) AS row_ID FROM history h WHERE h.description like '%historycreated%' GROUP BY h.equipmentid)";
}
break;
default:
$filtertype = strip_tags(trim($_GET['type']));
$whereclause .= ' AND type="'.$filtertype.'"';
break;
}
}
if ($whereclause == ''){
$whereclause = "WHERE h.description like '%historycreated%'";
}
//Start DATE Filter
if ((isset($_GET['start']) && $_GET['start'] != '') && (isset($_GET['end']) && $_GET['end'] != '')){
$start_range = strip_tags(trim($_GET['start']));
$end_range = strip_tags(trim($_GET['end']));
}
else {
$end_range = date("Y-m-d", strtotime("+ 1 days")); //default data range
$start_range = date("Y-m-d", strtotime("-270 days")); //default data range
}
$whereclause .= " AND h.created BETWEEN '$start_range' and '$end_range'";
//END DATE Filter
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Execute query & return+++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$pdo = dbConnect($dbname);
$sql = "SELECT h.rowID, h.description from history h $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute();
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
$number = count($messages);
$i = 1;
echo '[';
foreach ($messages as $message){
$add_object = json_decode($message['description']);
$add_object->historyID = $message['rowID'];
if ($i < $number){
echo json_encode($add_object);
echo ',';
} else {
echo json_encode($add_object);
}
$i++;
}
echo ']';
break;
case 'serviceInit':
include './settings/systemservicetool.php';
echo json_encode($init);
break;
case 'getQuestions':
//build allowed_response
if (isset($_GET['type']) && $_GET['type'] != ''){
include './settings/systemservicetool.php';
//build questions
switch ($_GET['type']) {
case 'visual':
$arrayQuestions = $arrayQuestions_visual;
break;
case 'final':
$arrayQuestions = $arrayQuestions_finalize;
break;
}
//Return JSON
echo json_encode($arrayQuestions);
}
else {
http_response_code(400);
}
break;
case 'firmwareUpdate':
if (isset($_GET['sn']) && $_GET['sn'] != '' && isset($_GET['hw_version']) && $_GET['hw_version'] != '' && isset($_GET['sw_version']) && $_GET['sw_version'] != '') {
include './settings/settings.php';
//Clean input data
$hw_device_send = strip_tags(trim($_GET['hw_version']));
$sw_device_send = strip_tags(trim($_GET['sw_version']));
//Check exceptions
if (in_array($_GET['sn'],$serialnumber_exceptions)){
//Serialnumber found in exceptions include exception file
include './settings/systemfirmware_exceptions.php';
}
else
{
//Serialnumber not found in exceptions include standard firmware
include './settings/systemfirmware.php';
}
//Include Firmware
if (isset(${'Firmwarename' . $hw_device_send}) && isset(${'Firmware' . $hw_device_send})){
$firmwarename = ${'Firmwarename' . $hw_device_send};
$firmware = ${'Firmware' . $hw_device_send};
echo json_encode(array("hw_version"=> $hw_device_send, "HEX_FW"=> $firmwarename, "Firmware" => $firmware));
}
else
{
http_response_code(404);
}
}
else {
http_response_code(400);
}
break;
case 'validateSoftware':
if (isset($_GET['version']) && $_GET['version'] != '') {
//Clean input data
$version = strip_tags(trim($_GET['version']));
//Include Firmware
include './settings/systemfirmware.php';
if ($service_tool_version == $version){
//Version equal No Update = 0
echo json_encode(array("update"=> 0));
}
else {
//Version not equal Update = 1
echo json_encode(array("update"=> 1));
}
}
else {
http_response_code(400);
}
break;
case 'getSoftware':
include './settings/systemservicetool.php';
echo json_encode(array("url"=> $software_url));
break;
case 'getfirmwareCommunication':
if (isset($_GET['hw_version']) && $_GET['hw_version'] != ''){
$target = $_GET['target'] ?? '0';
$hw_device_send = strip_tags(trim($_GET['hw_version']));
$filter1 = 'soldto":"';
$filter2 = '","shipto';
$filter3 = 'shipto":"';
$filter4 = '","location';
$whereclause = "WHERE e.hw_version='$hw_device_send' AND c.type_1='1' AND c.status='1'";
//get target
switch ($target) {
case '0': // Both
$onclause ="SUBSTRING_INDEX(SUBSTRING_INDEX(e.accounthierarchy, '$filter1', -1),'$filter2',1) = c.partnerID or SUBSTRING_INDEX(SUBSTRING_INDEX(e.accounthierarchy, '$filter3', -1),'$filter4',1) = c.partnerID";
break;
case '1': // SoldTO only
$onclause ="SUBSTRING_INDEX(SUBSTRING_INDEX(e.accounthierarchy, '$filter1', -1),'$filter2',1) = c.partnerID";
break;
case '2': // ShipTO only
$onclause =" SUBSTRING_INDEX(SUBSTRING_INDEX(e.accounthierarchy, '$filter3', -1),'$filter4',1) = c.partnerID";
break;
}
$pdo = dbConnect($dbname);
$sql = "SELECT e.sw_version, c.email from equipment e join communication c on $onclause $whereclause group by c.email";
$stmt = $pdo->prepare($sql);
$stmt->execute();
//Get results
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($result) {
echo json_encode(array("firmware_scope"=> count($result)));
}
else {
echo json_encode(array("firmware_scope"=> '0'));
}
}
else {
http_response_code(400);
}
break;
}
// end switch

View File

@@ -0,0 +1,64 @@
<?php
defined($security_key) or exit;
//ini_set('display_errors', '1');
//ini_set('display_startup_errors', '1');
//error_reporting(E_ALL);
//------------------------------------------
// Get user_details
//------------------------------------------
$user_credentials = json_decode($input,true);
$username = $user_credentials['username'];
$password = $user_credentials['password'];
if (!empty($username) && !empty($password)) {
$username = strip_tags(trim($username));
$password = strip_tags(trim($password));
$conn = new mysqli($db,$dbuser,$dbpw,$dbname_users);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, username, password, service FROM users WHERE username='$username'";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
while ($row = $result->fetch_assoc()) {
if (password_verify($password, $row['password'])) {
if(empty($row['service'])){
echo 'No service account found';
http_response_code(401);
}
else {
$service = $row['service'];
$jwt = createCommunicationToken($service);
$logindate = date('Y-m-d H:i:s');
$id = $row['id'];
$sql1 = "UPDATE users SET lastlogin = '$logindate' WHERE id='$id'";
$conn->query($sql1);
echo json_encode(array('token' => $jwt));
}
}
else
{
http_response_code(203);
}
}
}
else {
http_response_code(203);
}
$conn->close();
}
else {
http_response_code(400);
}
?>

View File

@@ -0,0 +1,29 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// Get user_details based on securitykey
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname_users);
//Define Query
$stmt = $pdo->prepare('SELECT * FROM users WHERE service = ? OR userkey = ?');
//Excute Query
$stmt->execute([$userkey, $userkey]);
//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'];
$servicekey = $user_data['service'];
$partner = json_decode($partnerhierarchy);
//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']]);
?>

346
api/v0/post/application.php Normal file
View File

@@ -0,0 +1,346 @@
<?php
//defined($security_key) or exit;
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//------------------------------------------
// Application related calls
//------------------------------------------
$action = $request[2];
$post_content = json_decode($input,true);
//SET PARAMETERS FOR QUERY
$id = $post_content['rowID'] ?? ''; //check for rowID
$command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT
$date = date('Y-m-d H:i:s');
// Connect to DB
$pdo = dbConnect($dbname);
function checkSerial($serialinput){
//Check Serialnumber used
if (preg_match('/^[^-]*-[^-]*$/', $serialinput)){
$check=explode('-', $serialinput);
$productrowid = strip_tags(trim($check[0]));
$rowID= strip_tags(trim($check[1]));
$whereclause = 'WHERE rowID = "'.$rowID.'"';
}
else
{
$serialnumberhelper = strip_tags(trim($serialinput));
$whereclause = 'WHERE serialnumber = "'.$serialnumberhelper.'"';
}
return $whereclause;
}
if ($action == 'createHistory'){
if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) {
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Action defaults (0=No 1=Yes) +++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$equipmentUpdate = 0; //equipment update
$servicetoolHistoryUpdate = 0; // service tool history update
$equipmentCreate = 0; //Create equipment when serialnumber not Found
$equipmentProductUpdate = 0; //update equipment with productcode
$equipmentUpdate_status = 0; //update equipment with status
$equipmentServiceDate = 0; //update equipment with service date
$historyUpdate_type = 0; //update type of history
$updateObject_visual = 0; //update visual inspection object
$sendServiceReport = 0; //send service report via email
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//SET DEFAULT PARAMETERS
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$user = $username;
$account = $partnerhierarchy; //string
$current_date = date("Y-m-d");
$input_type = $post_content['type'];
$testdetails = json_encode($post_content['testdetails']);
$serial = $post_content['sn'];
$productrowid = 0; //default product for equipment create
$sn_service = $post_content['testdetails']['external_device_sn'] ?? '';
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Define action based on historytype
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
switch ($input_type){
case 1: //Bootloader
$historytype = ${'HistoryType_'.$input_type};
$equipmentCreate = 1;
$equipmentUpdate = 1;
$equipmentServiceDate = 1;
break;
case 2: //Firmware
$historytype = ${'HistoryType_'.$input_type};
$equipmentCreate = 1;
$equipmentUpdate = 1;
$servicetoolHistoryUpdate = 1;
break;
case 3: //Serialnumber
$historytype = ${'HistoryType_'.$input_type};
$equipmentProductUpdate = 1;
$equipmentUpdate_status = 1;
$equipmentServiceDate = 1;
break;
case 4://Visual
$historytype = ${'HistoryType_'.$input_type};
break;
case 5://Maintenance_Test
$historytype = ${'HistoryType_'.$input_type};
$equipmentUpdate = 0;
$servicetoolHistoryUpdate = 1;
break;
case 6://Assembly_Test
$historytype = ${'HistoryType_'.$input_type};
$equipmentUpdate = 0;
$equipmentUpdate_status = 1;
break;
case 7://ProductNumber
$historytype = ${'HistoryType_'.$input_type};
$equipmentProductUpdate = 1;
$equipmentUpdate_status = 1;
break;
case 8://Visual
$historytype = ${'HistoryType_'.$input_type};
//Check for existing visualinspectionID
if (isset($post_content['testdetails']['serviceReport']['visualinspection_id']) && $post_content['testdetails']['serviceReport']['visualinspection_id'] != 0) {
$updateObject_visual = 1;
$visualinspectionID = $post_content['testdetails']['serviceReport']['visualinspection_id'];
}
break;
case 9://ServiceReport
$historytype = ${'HistoryType_'.$input_type};
$historyUpdate_type = 1;
$servicetoolHistoryUpdate = 1;
$equipmentServiceDate = 1;
//Check if servicereport comes from ServiceTool else inhouse
if (isset($post_content['testdetails']['serviceReport'])) {
$sendServiceReport = 1;
$testObject = array(
"final" => $post_content['testdetails']['serviceReport']['questionItems'],
"maintenance_test" => $post_content['testdetails']['serviceReport']['maintenance_id'],
"visualinspection" => $post_content['testdetails']['serviceReport']['visualinspection_id'],
"serialnumber" => $post_content['sn'],
"external_device_sn" => $post_content['testdetails']['external_device_sn']
);
$testdetails = json_encode($testObject);
}
break;
case 11: //car_test
$historytype = 'CarTest';
$equipmentCreate = 1;
break;
case 'firmware': //update from Portal
$historytype = $HistoryType_2;
$equipmentUpdate = 1;
$servicetoolHistoryUpdate = 1;
$sn_service = $post_content['sn_service'];
break;
default:
$historytype = 'Other';
break;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Connect to DB
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$pdo = dbConnect($dbname);
//Get whereclause based on serialnumber
$whereclause = checkSerial($serial);
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//CHECK if EQUIPMENT EXISTS
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$sql = "SELECT count(rowID) as total, rowID FROM equipment $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$total = $stmt->fetchAll(PDO::FETCH_ASSOC);
$total_equipment = $total[0]['total'];
$rowID = $total[0]['rowID'] ?? '';
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Create equipment when not exist +++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($equipmentCreate == 1 && $total_equipment == 0){
$sql = 'INSERT INTO equipment (productrowid,created,createdby,status,accounthierarchy,serialnumber,service_date,warranty_date) VALUES (?,?,?,?,?,?,?,?)';
$stmt = $pdo->prepare($sql);
$stmt->execute([$productrowid,$date,$user,$status0,$account,$serial,$current_date,$current_date]);
$rowID = $pdo->lastInsertId();
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Insert or update history item ++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($updateObject_visual == 1){
$sql = "UPDATE history SET description = '$testdetails' WHERE rowID = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$visualinspectionID]);
$last_id = $visualinspectionID;
}
else {
// Insert Equipment
$sql = "INSERT INTO history (equipmentid,type,description,createdby ) VALUES (?,?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$rowID,$historytype,$testdetails,$user]);
$last_id = $pdo->lastInsertId();
}
// Return ID
echo json_encode(array('historyID'=> $last_id));
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Specials below ++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Update HW and SW on equipment ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($equipmentUpdate == 1){
//get HW + SW from PortalAPI
if ($post_content['type'] == 'firmware'){
$test = json_decode($post_content['testdetails']);
$hw_version = $test->HW;
$sw_version = $test->HEX_FW;
}
else {
//GET HW + SW from object
$hw_version = $post_content['testdetails']['logdetails']['HW'];
$sw_version = $post_content['testdetails']['logdetails']['HEX_FW'];
}
//Update Equipment record
$sql = "UPDATE equipment SET hw_version = ?, sw_version = ? $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute([$hw_version,$sw_version]);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Update equipment status ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($equipmentUpdate_status == 1){
if ($historytype == $HistoryType_6){$update_status = $status1;}
if ($historytype == $HistoryType_3 && $sn_service != 'Portal'){$update_status = $status0;}
if ($historytype == $HistoryType_7 && $sn_service == 'Portal'){$update_status = $status2;}
//Update Equipment record
$sql = "UPDATE equipment SET status = ? $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute([$update_status]);
//UPDATE CHANGELOG
changelog($dbname,'equipment',$rowID,'status',$update_status,$user);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Update history type ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($historyUpdate_type == 1){
//Check if servicereport comes from ServiceTool else inhouse
if (isset($post_content['testdetails']['serviceReport'])) {
$maintenanceID = $post_content['testdetails']['serviceReport']['maintenance_id'];
$visualID = $post_content['testdetails']['serviceReport']['visualinspection_id'];
}else {
$maintenanceID = $post_content['testdetails']['maintenance_test'];
$visualID = $post_content['testdetails']['visualinspection'];
}
//Update history record
$sql = "UPDATE history SET type = ? where rowID= ? or rowID= ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$type15,$visualID,$maintenanceID]);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Update productcode on equipment ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($equipmentProductUpdate == 1 && isset($post_content['testdetails']['logdetails']['PN'])){
//GET PN from object
$getPN = $post_content['testdetails']['logdetails']['PN'];
$pn2 = preg_replace("/[^0-9]/","",$getPN);
$PN = ltrim($pn2, "0");
//Update Equipment record
$sql = "UPDATE equipment SET productrowid = ? $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute([$PN]);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Update equipment service date ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($equipmentServiceDate == 1){
//Update Equipment record
$sql = "UPDATE equipment SET service_date = ? $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute([$current_date]);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Update history of service tool ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($servicetoolHistoryUpdate == 1 && !empty($sn_service)){
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//CHECK if EQUIPMENT EXISTS
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$whereclause = checkSerial($sn_service);
$sql = "SELECT count(rowID) as total, rowID FROM equipment $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$total = $stmt->fetchAll(PDO::FETCH_ASSOC);
$total_servicetool = $total[0]['total'];
$rowID_servicetool = $total[0]['rowID'];
if($total_servicetool != 0){
// Insert historyitem
$sql = "INSERT INTO history (equipmentid,type,description,createdby) VALUES (?,?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$rowID_servicetool,$historytype,$testdetails,$user]);
//Update status to InUse
$sql = "UPDATE equipment SET status = ? $whereclause";
$stmt = $pdo->prepare($sql);
$stmt->execute(['4']);
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// sendServiceReport ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($sendServiceReport == 1){
//GET STORED SERVICE REPORT
$sql = 'SELECT h.rowID as historyID, h.type, h.description, h.created, h.createdby FROM history h WHERE rowID = ?';
$pdo = dbConnect($dbname);
$stmt = $pdo->prepare($sql);
$stmt->execute([$last_id]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $result){
$result = json_decode(json_encode($result));
$servicereport = serviceReport($result, 'email');
generatedPDF($servicereport,$last_id,$user);
}
}
}
else
{
http_response_code(400); //Payload not valid
}
}
?>