diff --git a/api/v0/post/application.php b/api/v0/post/application.php index 95b4408..ffc5840 100644 --- a/api/v0/post/application.php +++ b/api/v0/post/application.php @@ -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); diff --git a/api/v1/get/products_software.php b/api/v1/get/products_software.php index 613ac06..355cf17 100644 --- a/api/v1/get/products_software.php +++ b/api/v1/get/products_software.php @@ -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 diff --git a/api/v1/post/application.php b/api/v1/post/application.php index 79c121d..f39019d 100644 --- a/api/v1/post/application.php +++ b/api/v1/post/application.php @@ -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'; diff --git a/api/v1/post/contracts.php b/api/v1/post/contracts.php index 02e8301..fd0384a 100644 --- a/api/v1/post/contracts.php +++ b/api/v1/post/contracts.php @@ -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 diff --git a/api/v1/post/equipments.php b/api/v1/post/equipments.php index 14c9630..d0a89b9 100644 --- a/api/v1/post/equipments.php +++ b/api/v1/post/equipments.php @@ -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) { diff --git a/api/v1/post/history.php b/api/v1/post/history.php index 6ec61e1..7604d2b 100644 --- a/api/v1/post/history.php +++ b/api/v1/post/history.php @@ -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'])){ diff --git a/api/v1/post/profile.php b/api/v1/post/profile.php index 03aa742..03de6ab 100644 --- a/api/v1/post/profile.php +++ b/api/v1/post/profile.php @@ -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,'',''); diff --git a/api/v1/post/users.php b/api/v1/post/users.php index ba828c3..6a4ccf9 100644 --- a/api/v1/post/users.php +++ b/api/v1/post/users.php @@ -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,'',''); diff --git a/api/v2/get/products_software.php b/api/v2/get/products_software.php index f57ac37..47538d4 100644 --- a/api/v2/get/products_software.php +++ b/api/v2/get/products_software.php @@ -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 diff --git a/api/v2/post/contracts.php b/api/v2/post/contracts.php index 65b28ad..072c2bf 100644 --- a/api/v2/post/contracts.php +++ b/api/v2/post/contracts.php @@ -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]); } } } diff --git a/api/v2/post/equipments.php b/api/v2/post/equipments.php index 2d64baa..612f15b 100644 --- a/api/v2/post/equipments.php +++ b/api/v2/post/equipments.php @@ -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) { diff --git a/api/v2/post/history.php b/api/v2/post/history.php index 80b8ce8..935fd34 100644 --- a/api/v2/post/history.php +++ b/api/v2/post/history.php @@ -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'])){ diff --git a/api/v2/post/users.php b/api/v2/post/users.php index f8e63ca..be1b8ef 100644 --- a/api/v2/post/users.php +++ b/api/v2/post/users.php @@ -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,'',''); diff --git a/assets/functions.php b/assets/functions.php index f15059e..c9f0905 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -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){ diff --git a/contract.php b/contract.php index 7dad873..5cd8482 100644 --- a/contract.php +++ b/contract.php @@ -351,6 +351,14 @@ $view .= '
'.$general_createdby.' '.$responses->createdby.' + + '.$general_updated.' + '.getRelativeTime($responses->updated).' + + + '.$general_updatedby.' + '.$responses->updatedby.' +
diff --git a/contract_manage.php b/contract_manage.php index ca2ce02..7c68f30 100644 --- a/contract_manage.php +++ b/contract_manage.php @@ -24,6 +24,8 @@ $contract = [ 'contract_details' => '', 'created' => '', 'createdby' => '', + 'updated' => '', + 'updatedby' => '', 'billing_plan' => '', 'pricing' => '', 'reference' => '', @@ -276,7 +278,11 @@ $view .= '
- + + + + +
'; diff --git a/equipment.php b/equipment.php index a21f837..67b4876 100644 --- a/equipment.php +++ b/equipment.php @@ -360,6 +360,10 @@ $view .= '
'.$general_created.' '.getRelativeTime($responses->created).' + + '.$general_updated.' + '.getRelativeTime($responses->updated).' +
diff --git a/equipment_manage.php b/equipment_manage.php index b726ede..768deb2 100644 --- a/equipment_manage.php +++ b/equipment_manage.php @@ -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 .= '
+ + + + diff --git a/user.php b/user.php index 7665c57..52bf66a 100644 --- a/user.php +++ b/user.php @@ -23,6 +23,9 @@ $user = [ 'settings' => '', 'userkey' => 1, 'created' => '', + 'createdby' => '', + 'updated' => '', + 'updatedby' => '', 'lastlogin' => '', 'language' => 'US', 'login_count' => 0 @@ -300,6 +303,10 @@ $view .= '
+ + + + '.$login_count.'