CMXX - Include updated/by on multiple tables and views

This commit is contained in:
“VeLiTi”
2024-12-12 16:19:16 +01:00
parent 5e858fb785
commit e55c7c271d
19 changed files with 102 additions and 53 deletions

View File

@@ -197,16 +197,16 @@ if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) {
// Insert or UPDATE equipment_history item ++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($updateObject_visual == 1){
$sql = "UPDATE equipment_history SET description = '$testdetails' WHERE rowID = ?";
$sql = "UPDATE equipment_history SET description = '$testdetails', updatedby = ? WHERE rowID = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$visualinspectionID]);
$stmt->execute([$user,$visualinspectionID]);
$last_id = $visualinspectionID;
}
else {
// Insert Equipment
$sql = "INSERT INTO equipment_history (equipmentid,type,description,createdby ) VALUES (?,?,?,?)";
$sql = "INSERT INTO equipment_history (equipmentid,type,description,createdby,updatedby) VALUES (?,?,?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$rowID,$historytype,$testdetails,$user]);
$stmt->execute([$rowID,$historytype,$testdetails,$user,$user]);
$last_id = $pdo->lastInsertId();
}
@@ -276,9 +276,9 @@ if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) {
}
//UPDATE equipment_history record
$sql = "UPDATE equipment_history SET type = ? where rowID= ? or rowID= ?";
$sql = "UPDATE equipment_history SET type = ?, updatedby = ? where rowID= ? or rowID= ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$type15,$visualID,$maintenanceID]);
$stmt->execute([$type15,$user,$visualID,$maintenanceID]);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Update productcode on equipment ++++++++++++++++++++++++++
@@ -322,9 +322,9 @@ if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) {
if($total_servicetool != 0){
// Insert historyitem
$sql = "INSERT INTO equipment_history (equipmentid,type,description,createdby) VALUES (?,?,?,?)";
$sql = "INSERT INTO equipment_history (equipmentid,type,description,createdby,updatedby) VALUES (?,?,?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$rowID_servicetool,$historytype,$testdetails,$user]);
$stmt->execute([$rowID_servicetool,$historytype,$testdetails,$user,$user]);
//Update status to InUse
$sql = "UPDATE equipment SET status = ? $whereclause";
$stmt = $pdo->prepare($sql);

View File

@@ -156,16 +156,16 @@ if (!isset($criterias['productrowid']) && isset($criterias['sn']) && $criterias[
//check if current version is send and update the equipment record
if(isset($criterias['version']) && $criterias['version'] !=''){
$sql = 'UPDATE equipment SET sw_version = ? WHERE serialnumber = ? ';
$sql = 'UPDATE equipment SET sw_version = ?, updatedby = ? WHERE serialnumber = ? ';
$stmt = $pdo->prepare($sql);
$stmt->execute([$criterias['version'],$criterias['sn']]);
$stmt->execute([$criterias['version'],$username,$criterias['sn']]);
}
//check if current version is send and update the equipment record
if(isset($criterias['hw_version']) && $criterias['hw_version'] !=''){
$sql = 'UPDATE equipment SET hw_version = ? WHERE serialnumber = ? ';
$sql = 'UPDATE equipment SET hw_version = ?, updatedby = ? WHERE serialnumber = ? ';
$stmt = $pdo->prepare($sql);
$stmt->execute([$criterias['hw_version'],$criterias['sn']]);
$stmt->execute([$criterias['hw_version'],$username,$criterias['sn']]);
}
//GET PRODUCTCODE, SW_VERSION_UPGRADE, HW_VERSION from equipment SN

View File

@@ -125,9 +125,9 @@ switch ($action) {
$firmware_account_send = 1;
//create history
// Prepare queries
$sql = 'INSERT INTO equipment_history (equipmentid, type, description, created, createdby) VALUES (?,?,?,?,?)';
$sql = 'INSERT INTO equipment_history (equipmentid, type, description, created, createdby,updatedby) VALUES (?,?,?,?,?,?)';
$stmt = $pdo->prepare($sql);
$stmt->execute([$rowID['rowID'],$type9,$description,$timestamp,$post_content['email']]);
$stmt->execute([$rowID['rowID'],$type9,$description,$timestamp,$post_content['email'],$post_content['email']]);
//GET PARTNER DETAILS OF EQUIPMENT
$partner_equipment = getrowID($dbname,'accounthierarchy','equipment','rowID="'.$rowID['rowID'].'"');
@@ -193,9 +193,9 @@ switch ($action) {
// --------------------------------------------
// Update equipment record warranty_date, partnerhierarchy, status equipment
// --------------------------------------------
$sql = 'UPDATE equipment SET status = ?, warranty_date = ?, accounthierarchy = ? WHERE rowID = ?';
$sql = 'UPDATE equipment SET status = ?, warranty_date = ?, accounthierarchy = ?,updatedby = ? WHERE rowID = ?';
$stmt = $pdo->prepare($sql);
$stmt->execute(['4',$warranty_extended,$partnerhierarchy,$rowID['rowID']]);
$stmt->execute(['4',$warranty_extended,$partnerhierarchy,$username,$rowID['rowID']]);
//Add warranty to changelog
$warranty_user = $post_content['email'] ?? 'system';
@@ -232,9 +232,9 @@ switch ($action) {
// --------------------------------------------
$firmware_account_send = 1;
//create history
$sql = 'INSERT INTO equipment_history (equipmentid, type, description, created, createdby) VALUES (?,?,?,?,?)';
$sql = 'INSERT INTO equipment_history (equipmentid, type, description, created, createdby, updatedby) VALUES (?,?,?,?,?,?)';
$stmt = $pdo->prepare($sql);
$stmt->execute([$rowID['rowID'],$type9,$description,$timestamp,$post_content['email']]);
$stmt->execute([$rowID['rowID'],$type9,$description,$timestamp,$post_content['email'],$post_content['email']]);
//GET PARTNER DETAILS OF EQUIPMENT
$partner_equipment = getrowID($dbname,'accounthierarchy','equipment','rowID="'.$rowID['rowID'].'"');
@@ -299,9 +299,9 @@ switch ($action) {
// --------------------------------------------
// Update equipment record warranty_date, partnerhierarchy, status equipment
// --------------------------------------------
$sql = 'UPDATE equipment SET status = ?, warranty_date = ?, accounthierarchy = ? WHERE rowID = ?';
$sql = 'UPDATE equipment SET status = ?, warranty_date = ?, accounthierarchy = ?, updatedby = ? WHERE rowID = ?';
$stmt = $pdo->prepare($sql);
$stmt->execute(['4',$warranty_extended,$partnerhierarchy,$rowID['rowID']]);
$stmt->execute(['4',$warranty_extended,$partnerhierarchy,$username,$rowID['rowID']]);
//Add warranty to changelog
$warranty_user = $post_content['email'] ?? 'system';

View File

@@ -58,6 +58,8 @@ if (isset($post_content['ignore_list'])){
$post_content['ignore_list'] = array_filter($post_content['ignore_list'], 'strlen');
}
$post_content['updatedby'] = $username;
if ($id != ''){
//DEFINE ACCOUNTHIERARCHY
@@ -121,9 +123,9 @@ if ($id != ''){
if (count($response) != 0){
$id_removed_user = $response[0]['id'];
//Remove serviceflag from user
$sql = 'UPDATE users SET service = "" WHERE id = ? ';
$sql = 'UPDATE users SET service = "", updatedby = ? WHERE id = ? ';
$stmt = $pdo->prepare($sql);
$stmt->execute([$id_removed_user]);
$stmt->execute([$username,$id_removed_user]);
}
}
}
@@ -189,11 +191,11 @@ if (isset($post_content['assigned_users'])){
if (count($response) != 0){
$id_exist_user = $response[0]['id'];
$generate_service = bin2hex(random_bytes(25));
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
$sql = 'UPDATE users SET service = ? , updatedby = ? WHERE id = ? ';
$stmt = $pdo->prepare($sql);
if (isset($post_content['status']) && $post_content['status'] != 2){
//Add serviceflag from user
$stmt->execute([$generate_service,$id_exist_user]);
$stmt->execute([$generate_service,$username,$id_exist_user]);
}
else {
//Remove serviceflag from user when status is Closed

View File

@@ -155,9 +155,11 @@ foreach ($account as $key => $value){
// CREATE ACCOUNTHIERARCHY JSON FROM ACCOUNT ARRAY
$accounthierarchy = json_encode($account, JSON_UNESCAPED_UNICODE);
$post_content['updatedby'] = $username;
//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE
if ($command == 'update'){
//RESET WARRANTY AND SERVICE DATES WHEN STATUS IS CHANGED TO SEND(3)
if (isset($post_content['status']) && $post_content['status'] == 3 && $equipment_data['status'] != 3)
{

View File

@@ -21,6 +21,8 @@ $clause = '';
$clause_insert ='';
$input_insert = '';
$post_content['updatedby'] = $username;
//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE
if ($command == 'update' && !isset($post_content['delete'])){

View File

@@ -15,6 +15,8 @@ $owner_user = 0;
$id = $post_content['id'] ?? ''; //check for rowID
$command = ($post_content['reset'])? 'reset' : ''; // change command to reset
$post_content['updatedby'] = $username;
//GET EXISTING USER DATA
if ($id != ''){
//Define Query
@@ -25,9 +27,9 @@ $owner_user = (($user_data['username'] == $username)? 1 : 0);
if ($command != 'reset' && $owner_user === 1 && $post_content['language']){
$sql = 'UPDATE users SET language = ? WHERE id = ? ';
$sql = 'UPDATE users SET language = ?, updatedby = ? WHERE id = ? ';
$stmt = $pdo->prepare($sql);
$stmt->execute([$post_content['language'],$id]);
$stmt->execute([$post_content['language'],$username,$id]);
}
if ($command == 'reset' && $owner_user === 1){
@@ -36,9 +38,9 @@ $owner_user = (($user_data['username'] == $username)? 1 : 0);
$payload = array('username'=>$user_data['username'], 'exp'=>(time() + 1800));
$resetkey = generate_jwt($headers, $payload);
//STEP 2- Store resetkey
$sql = 'UPDATE users SET resetkey = ? WHERE id = ? ';
$sql = 'UPDATE users SET resetkey = ?, updatedby = ? WHERE id = ? ';
$stmt = $pdo->prepare($sql);
$stmt->execute([$resetkey,$id]);
$stmt->execute([$resetkey,$username,$id]);
//STEP 3 - Send to user
include_once './assets/mail/email_template_reset.php';
send_mail($user_data['email'],$subject,$message,'','');

View File

@@ -46,6 +46,8 @@ $clause = '';
$clause_insert ='';
$input_insert = '';
$post_content['updatedby'] = $username;
//GET EXISTING USER DATA
if ($id != '' && $command != 'reset'){
//Define Query
@@ -130,9 +132,9 @@ $location_new = (($post_content['location'] != '' && $post_content['location'] !
$payload = array('username'=>$user_data['username'], 'exp'=>(time() + 1800));
$resetkey = generate_jwt($headers, $payload);
//STEP 2- Store resetkey
$sql = 'UPDATE users SET resetkey = ? WHERE id = ? '.$whereclause.'';
$sql = 'UPDATE users SET resetkey = ?, updatedby = ? WHERE id = ? '.$whereclause.'';
$stmt = $pdo->prepare($sql);
$stmt->execute([$resetkey,$id]);
$stmt->execute([$resetkey,$username,$id]);
//STEP 3 - Send to user
include_once './assets/mail/email_template_reset.php';
send_mail($user_data['email'],$subject,$message,'','');

View File

@@ -155,16 +155,16 @@ if (!isset($criterias['productrowid']) && isset($criterias['sn']) && $criterias[
//check if current version is send and update the equipment record
if(isset($criterias['version']) && $criterias['version'] !=''){
$sql = 'UPDATE equipment SET sw_version = ? WHERE serialnumber = ? ';
$sql = 'UPDATE equipment SET sw_version = ?, updatedby = ? WHERE serialnumber = ? ';
$stmt = $pdo->prepare($sql);
$stmt->execute([$criterias['version'],$criterias['sn']]);
$stmt->execute([$criterias['version'],$username,$criterias['sn']]);
}
//check if current version is send and update the equipment record
if(isset($criterias['hw_version']) && $criterias['hw_version'] !=''){
$sql = 'UPDATE equipment SET hw_version = ? WHERE serialnumber = ? ';
$sql = 'UPDATE equipment SET hw_version = ?, updatedby = ? WHERE serialnumber = ? ';
$stmt = $pdo->prepare($sql);
$stmt->execute([$criterias['hw_version'],$criterias['sn']]);
$stmt->execute([$criterias['hw_version'],$username,$criterias['sn']]);
}
//GET PRODUCTCODE, SW_VERSION_UPGRADE, HW_VERSION from equipment SN

View File

@@ -58,6 +58,8 @@ if (isset($post_content['ignore_list'])){
$post_content['ignore_list'] = array_filter($post_content['ignore_list'], 'strlen');
}
$post_content['updatedby'] = $username;
if ($id != ''){
//DEFINE ACCOUNTHIERARCHY
@@ -121,9 +123,9 @@ if ($id != ''){
if (count($response) != 0){
$id_removed_user = $response[0]['id'];
//Remove serviceflag from user
$sql = 'UPDATE users SET service = "" WHERE id = ? ';
$sql = 'UPDATE users SET service = "", updatedby = ? WHERE id = ? ';
$stmt = $pdo->prepare($sql);
$stmt->execute([$id_removed_user]);
$stmt->execute([$username,$id_removed_user]);
}
}
}

View File

@@ -155,9 +155,11 @@ foreach ($account as $key => $value){
// CREATE ACCOUNTHIERARCHY JSON FROM ACCOUNT ARRAY
$accounthierarchy = json_encode($account, JSON_UNESCAPED_UNICODE);
$post_content['updatedby'] = $username;
//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE
if ($command == 'update'){
//RESET WARRANTY AND SERVICE DATES WHEN STATUS IS CHANGED TO SEND(3)
if (isset($post_content['status']) && $post_content['status'] == 3 && $equipment_data['status'] != 3)
{

View File

@@ -183,16 +183,16 @@ if (isset($post_content['sn']) && isset($post_content['payload'])){
// Insert or UPDATE equipment_history item ++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if ($updateObject_visual == 1){
$sql = "UPDATE equipment_history SET description = '$testdetails' WHERE rowID = ?";
$sql = "UPDATE equipment_history SET description = '$testdetails', updatedby = ? WHERE rowID = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$visualinspectionID]);
$stmt->execute([$user,$visualinspectionID]);
$last_id = $visualinspectionID;
}
else {
// Insert Equipment
$sql = "INSERT INTO equipment_history (equipmentid,type,description,createdby ) VALUES (?,?,?,?)";
$sql = "INSERT INTO equipment_history (equipmentid,type,description,createdby,updatedby ) VALUES (?,?,?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$rowID,$historytype,$testdetails,$user]);
$stmt->execute([$rowID,$historytype,$testdetails,$user,$user]);
$last_id = $pdo->lastInsertId();
}
@@ -262,9 +262,9 @@ if (isset($post_content['sn']) && isset($post_content['payload'])){
}
//UPDATE equipment_history record
$sql = "UPDATE equipment_history SET type = ? where rowID= ? or rowID= ?";
$sql = "UPDATE equipment_history SET type = ?, updatedby = ? where rowID= ? or rowID= ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$type15,$visualID,$maintenanceID]);
$stmt->execute([$type15,$user,$visualID,$maintenanceID]);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Update productcode on equipment ++++++++++++++++++++++++++
@@ -308,9 +308,9 @@ if (isset($post_content['sn']) && isset($post_content['payload'])){
if($total_servicetool != 0){
// Insert historyitem
$sql = "INSERT INTO equipment_history (equipmentid,type,description,createdby) VALUES (?,?,?,?)";
$sql = "INSERT INTO equipment_history (equipmentid,type,description,createdby,updatedby) VALUES (?,?,?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$rowID_servicetool,$historytype,$testdetails,$user]);
$stmt->execute([$rowID_servicetool,$historytype,$testdetails,$user,$user]);
//Update status to InUse
$sql = "UPDATE equipment SET status = ? $whereclause";
$stmt = $pdo->prepare($sql);
@@ -353,6 +353,8 @@ else {
$clause_insert ='';
$input_insert = '';
$post_content['updatedby'] = $username;
//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE
if ($command == 'update' && !isset($post_content['delete'])){

View File

@@ -46,6 +46,8 @@ $clause = '';
$clause_insert ='';
$input_insert = '';
$post_content['updatedby'] = $username;
//GET EXISTING USER DATA
if ($id != '' && $command != 'reset'){
//Define Query
@@ -130,9 +132,9 @@ $location_new = ((isset($post_content['location']) && $post_content['location']
$payload = array('username'=>$user_data['username'], 'exp'=>(time() + 1800));
$resetkey = generate_jwt($headers, $payload);
//STEP 2- Store resetkey
$sql = 'UPDATE users SET resetkey = ? WHERE id = ? '.$whereclause.'';
$sql = 'UPDATE users SET resetkey = ?, updatedby = ? WHERE id = ? '.$whereclause.'';
$stmt = $pdo->prepare($sql);
$stmt->execute([$resetkey,$id]);
$stmt->execute([$resetkey,$username,$id]);
//STEP 3 - Send to user
include_once './assets/mail/email_template_reset.php';
send_mail($user_data['email'],$subject,$message,'','');