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,'','');

View File

@@ -2283,7 +2283,7 @@ $messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->execute([$carbrand,$cartype,$header,$questions,$datapoints,$nametester,$accounthierarchy]);
//MARK HISTORY ITEM FOR DELETATION
$sql = 'UPDATE equipment_history SET type = "delete" WHERE rowID = '.$message['rowID'];
$sql = 'UPDATE equipment_history SET type = "delete", updatedby = "system" WHERE rowID = '.$message['rowID'];
$stmt = $pdo->prepare($sql);
//Excute Query
$stmt->execute();
@@ -2477,9 +2477,9 @@ foreach ($messages as $message){
//Validate if contract end date is in the past change contact status to closed and set users to not active
if (date("Y-m-d") > $end_date){
//Contract expired -> change status to closed (2)
$sql = 'UPDATE contracts SET status = ? WHERE rowID = ?';
$sql = 'UPDATE contracts SET status = ?, updatedby = ? WHERE rowID = ?';
$stmt = $pdo->prepare($sql);
$stmt->execute([2,$message['rowID']]);
$stmt->execute([2,"system",$message['rowID']]);
//CHECK FOR ASSIGNED USER END SET SERVICE TO INACTIVE
foreach (json_decode($message['assigned_users']) as $user_assigned){

View File

@@ -351,6 +351,14 @@ $view .= '<div class="content-block">
<td style="width:25%;">'.$general_createdby.'</td>
<td>'.$responses->createdby.'</td>
</tr>
<tr>
<td style="width:25%;">'.$general_updated.'</td>
<td>'.getRelativeTime($responses->updated).'</td>
</tr>
<tr>
<td style="width:25%;">'.$general_updatedby.'</td>
<td>'.$responses->updatedby.'</td>
</tr>
</table>
</div>
</div>

View File

@@ -24,6 +24,8 @@ $contract = [
'contract_details' => '',
'created' => '',
'createdby' => '',
'updated' => '',
'updatedby' => '',
'billing_plan' => '',
'pricing' => '',
'reference' => '',
@@ -276,7 +278,11 @@ $view .= '<div class="content-block tab-content">
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$contract['created'].'" readonly>
<label for="">'.$general_createdby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$contract['createdby'].'" readonly>
<input id="name" type="hidden" name="rowID" value="'.$contract['rowID'].'" readonly>
<label for="productcode">'.$general_updated.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.$contract['updated'].'" readonly>
<label for="productcode">'.$general_updatedby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$contract['updatedby'].'" readonly>
<input id="name" type="hidden" name="rowID" value="'.$contract['rowID'].'" readonly>
</div>
</div>';

View File

@@ -360,6 +360,10 @@ $view .= '<div class="content-block">
<td style="width:25%;">'.$general_created.'</td>
<td>'.getRelativeTime($responses->created).'</td>
</tr>
<tr>
<td style="width:25%;">'.$general_updated.'</td>
<td>'.getRelativeTime($responses->updated).'</td>
</tr>
</table>
</div>
</div>

View File

@@ -34,7 +34,9 @@ $equipment = [
'service_date' => $date,
'warranty_date' => $date,
'order_ref' => '',
'geolocation' => []
'geolocation' => [],
'updated' =>'',
'updatedby' =>''
];
$equipment_ID = $_GET['equipmentID'] ?? '';
@@ -264,6 +266,10 @@ $view .= '<div class="content-block tab-content">
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$equipment['created'].'" readonly>
<label for="productcode">'.$general_createdby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$equipment['createdby'].'" readonly>
<label for="productcode">'.$general_updated.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.$equipment['updated'].'" readonly>
<label for="productcode">'.$general_updatedby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$equipment['updatedby'].'" readonly>
<label for="productcode">'.$equipment_label11.'</label>
<input id="name" type="text" name="order_ref" placeholder="'.$equipment_label11.'" value="'.$equipment['order_ref'].'">
<label for="productcode">'.$equipment_label12.'</label>

View File

@@ -23,6 +23,9 @@ $user = [
'settings' => '',
'userkey' => 1,
'created' => '',
'createdby' => '',
'updated' => '',
'updatedby' => '',
'lastlogin' => '',
'language' => 'US',
'login_count' => 0
@@ -300,6 +303,10 @@ $view .= '<div class="content-block tab-content">
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$user['created'].'" readonly>
<label for="">'.$User_lastlogin.'</label>
<input id="name" type="text" name="" placeholder="'.$User_lastlogin.'" value="'.$user['lastlogin'].'" readonly>
<label for="productcode">'.$general_updated.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.$equipment['updated'].'" readonly>
<label for="productcode">'.$general_updatedby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$equipment['updatedby'].'" readonly>
<label for="">'.$User_pw_login_count.'</label>
'.$login_count.'
</div>