Files
assetmgt/equipment.php
“VeLiTi” 884d2a3366 Enhance product links and translations; update styles and add registration modal
- Updated product links in rma.php and rma_manage.php to include icons for better UX.
- Improved German, Spanish, Dutch, Polish, Portuguese, and US translations with new phrases for software licenses and user information prompts.
- Refactored CSS to remove redundant styles and added new styles for a registration modal, enhancing the overall UI.
- Introduced JavaScript variables for user information prompts in softwaretool.php for better localization support.
2026-01-12 15:59:46 +01:00

701 lines
29 KiB
PHP

<?php
defined(page_security_key) or exit;
if (debug && debug_id == $_SESSION['id']){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
include_once './assets/functions.php';
include_once './settings/settings_redirector.php';
//SET ORIGIN FOR NAVIGATION
$_SESSION['prev_origin_equipment'] = $_SERVER['REQUEST_URI'];
$page = 'equipment';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$page_manage = 'equipment_manage';
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
$update_allowed_edit = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'U');
$delete_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'C');
$view_product = isAllowed('product' ,$_SESSION['profile'],$_SESSION['permission'],'R');
$view_history = isAllowed('history' ,$_SESSION['profile'],$_SESSION['permission'],'C');
$view_contracts = isAllowed('contracts' ,$_SESSION['profile'],$_SESSION['permission'],'R');
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API FOR General information
$api_url = '/v2/equipments/'.$GET_VALUES;
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses);}else{$responses = null;}
$responses = $responses[0];
//CALL TO API FOR RELATED
$api_url = '/v2/media/rowID='.$responses->product_media;
$media_responses = ioServer($api_url,'');
//Decode Payload
if (!empty($media_responses)){$media_responses = json_decode($media_responses,true);}else{$media_responses = null;}
$media_responses = $media_responses[0] ?? '';
//CALL TO API FOR History
$api_url = '/v2/equipments/equipmentID='.$responses->equipmentID.'&type=ServiceReport&history=1';
$history = ioServer($api_url,'');
//Decode Payload
if (!empty($history)){$history = json_decode($history);}else{$history = null;}
//CALL TO API FOR EQUIPMENT DATA
$api_url = '/v1/equipment_data/equipmentid='.$responses->equipmentID;
$equipment_data = ioServer($api_url,'');
//Decode Payload
if (!empty($equipment_data )){$equipment_data = decode_payload($equipment_data );}else{$equipment_data = null;}
//CALL TO API FOR CUSTOMER AND WARRANTY DATA (type = customer,Warranty in history)
$api_url = '/v2/history/equipmentID='.$responses->equipmentID.'&type=customer,Warranty';
$registration_data = ioServer($api_url,'');
//Decode Payload
if (!empty($registration_data)){$registration_data = json_decode($registration_data);}else{$registration_data = null;}
// Separate customer and warranty data
$latest_customer = null;
$latest_warranty = null;
if (is_array($registration_data) && count($registration_data) > 0) {
foreach ($registration_data as $record) {
if ($record->type === 'Customer' && $latest_customer === null) {
$latest_customer = $record;
}
if ($record->type === 'Warranty' && $latest_warranty === null) {
$latest_warranty = $record;
}
}
}
//GET PRODUCTS_SOFTWARE
$api_url = '/v1/products_software/productrowid='.$responses->productrowid.'&status=1';
$products_software = ioServer($api_url,'');
//Decode Payload
if (!empty($products_software)){$products_software = decode_payload($products_software);}else{$products_software = null;}
//------------------------------
//Variables
//------------------------------
$status_text = 'status'.$responses->status.'_text';
$warrantydate = warrantyStatus($responses->warranty_date);
$service_date_due = serviceStatus($responses->service_date);
$firmware_status = availableFirmware($responses->sw_version, $responses->sw_version_latest);
//Calculate Healthindex based on last test
$total_score = assetHealthIndex($_SESSION['profile'],$_SESSION['permission'],$equipment_data,0);
//GetPartnerDetails
$partner_data = json_decode($responses->accounthierarchy);
$salesid = getPartnerName($partner_data->salesid) ?? $not_specified;
$soldto = getPartnerName($partner_data->soldto) ?? '-';
$shipto = getPartnerName($partner_data->shipto) ?? '-';
$location = getPartnerName($partner_data->location) ?? '-';
if (isset($partner_data->section)){$section = getPartnerName($partner_data->section) ?? '-';} else {$section = '-';}
//Check if productcode is 0 and status
if ($responses->productcode == 0 && $responses->status == 0) {$location = $product_location_raw;}
if ($responses->productcode == 0 && $responses->status == 1) {$location = $product_location_SFG;}
if ($responses->productcode == 0 && $responses->status == 2) {$location = $product_location_FG;}
if ($update_allowed === 1){
if (isset($_POST['description'])) {
//GET ALL POST DATA
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
//API call
$responses = ioServer('/v1/history', $payload);
if ($responses === 'NOK'){
} else {
header('Location: index.php?page=equipment&equipmentID='.$_POST['equipmentid'].'&success_msg=2');
exit;
}
}
}
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = $message_eq_1;
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_eq_2;
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_eq_3;
}
}
template_header('Asset', 'asset', 'view');
$view = '
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">'.$view_asset_h2.' - '.$responses->equipmentID.'</h2>
<a href="index.php?page='.$_SESSION['origin'].'&p='.$_SESSION['p'].$_SESSION['status'].$_SESSION['sort'].$_SESSION['search'].$_SESSION['firmware'].$_SESSION['servicedate'].$_SESSION['warrantydate'].$_SESSION['partnerid'].'" class="btn alt mar-right-2">←</a>
<a href="index.php?page=history&equipmentID='.$responses->equipmentID.'" class="btn"><i class="fa-solid fa-clock-rotate-left"></i></a>
';
//------------------------------------
//CHECK IF USER IS ALSO CREATOR OF RECORD THEN OVERRIDE UPDATE_ALLOWED_EDIT
//------------------------------------
$equipment_owner = (($responses->createdby == $_SESSION['username'])? 1 : 0);
//------------------------------------
//
//------------------------------------
if ($update_allowed_edit === 1 || $equipment_owner === 1){
$view .= '<a href="index.php?page=equipment_manage&equipmentID='.$responses->equipmentID.'" class="btn">✏️</a>';
}
$view .= '</div>';
if (isset($success_msg)){
$view .= ' <div class="msg success">
<i class="fas fa-check-circle"></i>
<p>'.$success_msg.'</p>
<i class="fas fa-times"></i>
</div>';
}
$view .= '<div class="content-block-wrapper">';
$view .= ' <div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-circle-info"></i></i>'.$view_asset_information.'
</div>
<div class="order-detail">
<h3>'.$equipment_label3.'</h3>
<p><span class="status id'.$responses->status.'">'.$$status_text.'</span></p>
</div>
<div class="order-detail">
<h3>'.$view_asset_data_ranking.'</h3>
<p><span class="'.(($total_score >= 85) ?'' : (($total_score <= 50)? 'status disabled' : 'id2')).'">'.$total_score.'</span></p>
</div>
<div class="order-detail">
<h3>'.$equipment_label2.'</h3>
<p>'.$responses->serialnumber.'</p>
</div>
<div class="order-detail">
<h3>'.$equipment_label10.'</h3>
<p>'.$responses->equipmentID.'</p>
</div>
<div class="order-detail">
<h3>'.$product_code.'</h3>
<p>'.(($view_product == 1)? '<a href="index.php?page=product&rowID='.$responses->productrowid.'" class="link-with-icon">'.$responses->productcode.' <i class="fa-solid fa-up-right-from-square"></i></a>':$responses->productcode).'</p>
</div>
<div class="order-detail">
<h3>'.$product_name.'</h3>
<p>'.(($view_product == 1)? '<a href="index.php?page=product&rowID='.$responses->productrowid.'" class="link-with-icon">'.(${$responses->productname} ?? $responses->productname).' <i class="fa-solid fa-up-right-from-square"></i></a>':(${$responses->productname} ?? $responses->productname)).'</p>
</div>';
if (!empty($media_responses['full_path'])){
$view .='
<div class="order-detail">
<img style="border-radius: 4px;height: 200px;margin: auto;" src="'.$media_responses['full_path'].'" alt="">
</div>
';
}
$view .='
</div>
';
$view .='<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-user fa-sm"></i>'.$view_asset_partners.'
</div>
<div class="order-detail">
<h3>'.$general_salesid.'</h3>
<p>'.$salesid.'</p>
</div>
<div class="order-detail">
<h3>'.$general_soldto.'</h3>
<p>'.$soldto.'</p>
</div>
<div class="order-detail">
<h3>'.$general_shipto.'</h3>
<p>'.$shipto.'</p>
</div>
<div class="order-detail">
<h3>'.$general_location.'</h3>
<p>'.$location.'</p>
</div>
<div class="order-detail">
<h3>'.$general_section.'</h3>
<p>'.$section.'</p>
</div>
<div class="order-detail">
<h3>'.(($latest_customer || $latest_warranty) ? '<a href="#" onclick="showCustomerModal(); return false;" class="link-with-icon">'.($register_title ?? 'Registration').' <i class="fa-solid fa-up-right-from-square"></i></a>' : '').'</h3>
</div>
</div>';
$view .= '</div>';
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$view_asset_details.'
</div>
<div class="table order-table">
<table>
<tr>
<td style="width:25%;">'.$warranty_status.'</td>
<td>'.$warrantydate.'</td>
</tr>
<tr>
<td style="width:25%;">'.$service_status.'</td>
<td>'.$service_date_due.'</td>
</tr>
<tr>
<td style="width:25%;">'.$software_status.'</td>
<td>'.$firmware_status.'</td>
</tr>
<tr>
<td style="width:25%;">'.$equipment_label5.'</td>
<td>'.$responses->hw_version.'</td>
</tr>
<tr>
<td style="width:25%;">'.$equipment_label6.'</td>
<td>'.$responses->sw_version.'</td>
</tr>';
//Check if license is attached
if (!empty($responses->sw_version_license)) {
$view .= '<tr>
<td style="width:25%;">'.($equipment_license ?? 'License').'</td>
<td>'.$responses->sw_version_license;
// Check if license is active
$current_date = date('Y-m-d H:i:s');
$is_active = false;
if (!empty($responses->license_status) && $responses->license_status == 1) {
$starts_at = $responses->starts_at ?? null;
$expires_at = $responses->expires_at ?? null;
if ($starts_at && $expires_at) {
if ($current_date >= $starts_at && $current_date <= $expires_at) {
$is_active = true;
}
} elseif ($starts_at && !$expires_at) {
if ($current_date >= $starts_at) {
$is_active = true;
}
} elseif (!$starts_at && $expires_at) {
if ($current_date <= $expires_at) {
$is_active = true;
}
} elseif (!$starts_at && !$expires_at) {
$is_active = true;
}
}
if ($is_active) {
$view .= ' / '.$enabled ?? 'Active';
} else {
$view .= ' / '.$disabled ?? 'Inactive';
}
$view .= '</td>
</tr>';
}
//SHOW ONLY SW_UPGRADE WHEN SET
if (isset($products_software) && $products_software !=''){
foreach ($products_software as $products_soft){
if ($products_soft->rowID == $responses->sw_version_upgrade){
$view .= ' <tr>
<td style="width:25%;">'.($equipment_sw_version_upgrade ?? 'sw_version_upgrade').'</td>
<td>'.$products_soft->version.'</td>
</tr>';
}
}
}
$view .= ' </table>
</div>
</div>
';
//SHOW LOCATION BASED ON GEOLOCATION
if (!empty($responses->geolocation) || $responses->geolocation != ''){
$geolocation = json_decode($responses->geolocation,true);
if ($geolocation[1] != ''){
$view .= '<div class="content-block">
<div id="map" style="height:300px;z-index: 0;">
</div>
<script>
// initialize Leaflet
var map = L.map(\'map\').setView({lon: '.$geolocation[1].', lat: '.$geolocation[0].'}, 10);
//Add TSS Avatar to MAP
var TSSemp = L.icon({
iconUrl: \'./assets/images/EP.png\',
iconSize: [50, 50], // size of the icon
});
L.marker(['.$geolocation[0].','.$geolocation[1].'], {icon: TSSemp}).addTo(map);
// add the OpenStreetMap tiles
L.tileLayer(\'https://tile.openstreetmap.org/{z}/{x}/{y}.png\', {
maxZoom: 19,
attribution: \'&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>\'
}).addTo(map);
// show the scale bar on the lower left corner
L.control.scale({imperial: true, metric: true}).addTo(map);
</script>
</div>
';
}
}
//Get all related service events
if (isAllowed('servicereports',$_SESSION['profile'],$_SESSION['permission'],'R') === 1){
$service_events = serviceEvents($history,$page);
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$view_asset_servicereport.'
</div>
<div class="table order-table">'.$service_events.'</div>
</div>
';
}
//Show equipment_data when available and allowed
if (isAllowed('equipment_data',$_SESSION['profile'],$_SESSION['permission'],'R') === 1 && !empty($equipment_data)){
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.($view_asset_data_text ?? '').'
</div>
<div class="table">
<table>
<thead>
<tr>
<th>'.$view_asset_data_rowID.'</th>
<th>'.$view_asset_data_historyid.'</th>
<th>'.$view_asset_data_ranking.'</th>
</tr>
</thead>
<tbody>';
foreach ($equipment_data as $data){
$view .= '<tr onclick="window.location.href=\'index.php?page=equipment_data&equipmentID='.$responses->equipmentID.'&rowID='.$data->rowID.'\'" style="cursor: pointer;">
<td>'.$data->rowID.'</td>
<td>'.(($view_history == 1)? '<a href="index.php?page=history&equipmentID='.$responses->equipmentID.'&historyid='.$data->historyid.'" class="link-with-icon">'.$data->historyid.' <i class="fa-solid fa-up-right-from-square"></i></a>':$data->historyid).'</td>
<td><span class=" '.(($data->healthindex >= 85) ?'' : (($data->healthindex <= 50)? 'status disabled' : 'id2')).'.">'.$data->healthindex.'</span></td>
</tr>';
}
$view .= '
</tbody>
</table>
</div>
';
$view .= '
</div>
';
}
if ($update_allowed === 1){
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$view_asset_notes.'
</div>
<form action="" method="post">
<textarea id="description" name="description" placeholder="'.$view_asset_notes.'" style="width: 100%;height: 150px;background: var(--color-gray);border: none;" onchange="this.form.submit();"></textarea>
<input type="hidden" name="equipmentid" value="'.$responses->equipmentID.'">
<input type="hidden" name="type" value="'.$type16.'">
</form>
</div>
';
}
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$tab3.'
</div>
<div class="table order-table">
<table>
<tr>
<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>
';
//DISPLAY RELATED COMMUNICATION RECORDS
$soldto_id = explode("-",$partner_data->soldto) ?? '';
$shipto_id = explode("-",$partner_data->shipto) ?? '';
$partner_users_id = ($shipto_id[0] != '')? $shipto_id[0] : (($soldto_id[0] != '')? $soldto_id[0] : 1);
$view_communication = '';
if ($partner_users_id != 1 && ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4)){
$view_communication = ' <a href="index.php?page=communications&partnerid='.$partner_users_id.'" class="btn">'.$button_partner_assigned_communication.'</a>';
}
//DISPLAY RELATED USERS
$view_users ='';
if ($partner_users_id != 1 && ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4)){
$view_users = ' <a href="index.php?page=users&partnerid='.$partner_users_id.'" class="btn">'.$button_partner_assigned_users.'</a>';
}
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$view_asset_actions.'
</div>
'.$view_communication.'
'.$view_users.'
';
if ($update_allowed === 1){
$view .='<a href="index.php?page=firmwaretool&equipmentID='.$responses->equipmentID.'" class="btn">'.$button_firmware.'</a>';
}
$view .='</div>';
//OUTPUT
echo $view;
// Add customer data modal if data exists
if ($latest_customer || $latest_warranty) {
$customer_payload = $latest_customer ? json_decode($latest_customer->description, true) : null;
$warranty_payload = $latest_warranty ? json_decode($latest_warranty->description, true) : null;
echo '
<div id="customerModal" class="reg-modal">
<div class="reg-modal-content">
<div class="reg-modal-header">
<h3>'.($register_title ?? 'Registration').'</h3>
<button onclick="closeCustomerModal()" class="reg-modal-close">&times;</button>
</div>
<!-- Tabs -->
<div class="reg-tabs">
<a href="#" class="reg-tab-link active" onclick="switchTab(event, \'warrantyTab\')">'.($warranty_status ?? 'Warranty').'</a>
<a href="#" class="reg-tab-link" onclick="switchTab(event, \'registrationTab\')">'.($register_title ?? 'Product Registration').'</a>
</div>
<!-- Warranty Tab Content -->
<div id="warrantyTab" class="reg-tab-content" style="display: block;">
<div class="reg-fields">';
if ($warranty_payload) {
// Check if warranty is still active
$warranty_end_date = $warranty_payload['end_date'] ?? null;
$warranty_display = '-';
$warranty_payload['createdby'] = $latest_warranty->createdby ?? '-';
if ($warranty_end_date) {
$end_date_obj = new DateTime(substr($warranty_end_date, 0, 10)); // Extract date part (YYYY-MM-DD)
$current_date_obj = new DateTime(date('Y-m-d'));
if ($end_date_obj >= $current_date_obj) {
// Warranty is still active
$warranty_display = ($warranty_recent ?? 'Active') . ' - ' . htmlspecialchars($warranty_end_date);
} else {
// Warranty has expired
$warranty_display = ($warranty_outdated_text ?? 'Expired');
}
}
echo '
<div class="reg-field">
<label>'.($warranty_status ?? 'Status').'</label>
<p>'.$warranty_display.'</p>
</div>
<div class="reg-field">
<label>'.($account_name ?? 'Organization').'</label>
<p>'.htmlspecialchars($warranty_payload['organization'] ?? '-').'</p>
</div>
<div class="reg-field">
<label>'.($account_email ?? 'Email').'</label>
<p onclick="copyToClipboard(\''.htmlspecialchars($warranty_payload['createdby'] ?? '').'\')"; class="reg-field-email" title="Click to copy">
<i class="fa-solid fa-envelope"></i> '.htmlspecialchars($warranty_payload['createdby'] ?? '-').'
</p>
</div>
<div class="reg-field">
<label>Phone</label>
<p>'.htmlspecialchars($warranty_payload['phone'] ?? '-').'</p>
</div>
<div class="reg-field-group">
<div class="reg-field">
<label>'.($shipping_city ?? 'City').'</label>
<p>'.htmlspecialchars($warranty_payload['city'] ?? '-').'</p>
</div>
<div class="reg-field">
<label>'.($shipping_country ?? 'Country').'</label>
<p>'.htmlspecialchars($warranty_payload['country'] ?? '-').'</p>
</div>
</div>
<div class="reg-field">
<label>'.($general_created ?? 'Registered').'</label>
<p>'.getRelativeTime($latest_warranty->created).'</p>
</div>';
} else {
echo '
<div class="reg-empty-state">
<i class="fa-solid fa-shield-halved"></i>
<p>No warranty information available</p>
</div>';
}
echo '
</div>
</div>
<!-- Product Registration Tab Content -->
<div id="registrationTab" class="reg-tab-content" style="display: none;">
<div class="reg-fields">
<div class="reg-field">
<label>'.($account_name ?? 'Name').'</label>
<p>'.htmlspecialchars($customer_payload['name'] ?? '-').'</p>
</div>
<div class="reg-field">
<label>'.($account_email ?? 'Email').'</label>
<p onclick="copyToClipboard(\''.htmlspecialchars($customer_payload['email'] ?? '').'\')"; class="reg-field-email" title="Click to copy">
<i class="fa-solid fa-envelope"></i> '.htmlspecialchars($customer_payload['email'] ?? '-').'
</p>
</div>
<div class="reg-field">
<label>'.($shipping_address ?? 'Address').'</label>
<p>'.htmlspecialchars($customer_payload['address'] ?? '-').'</p>
</div>
<div class="reg-field-group">
<div class="reg-field">
<label>'.($shipping_city ?? 'City').'</label>
<p>'.htmlspecialchars($customer_payload['city'] ?? '-').'</p>
</div>
<div class="reg-field">
<label>'.($shipping_zip ?? 'Postal Code').'</label>
<p>'.htmlspecialchars($customer_payload['postal'] ?? '-').'</p>
</div>
</div>
<div class="reg-field">
<label>'.($shipping_country ?? 'Country').'</label>
<p>'.htmlspecialchars($customer_payload['country'] ?? '-').'</p>
</div>
<div class="reg-field">
<label>'.($general_created ?? 'Registered').'</label>
<p>'.getRelativeTime($latest_customer->created).'</p>
</div>
</div>
</div>
</div>
</div>
<script>
function switchTab(event, tabId) {
event.preventDefault();
// Hide all tab contents
const tabContents = document.querySelectorAll(".reg-tab-content");
tabContents.forEach(function(content) {
content.style.display = "none";
});
// Remove active class from all tab links
const tabLinks = document.querySelectorAll(".reg-tab-link");
tabLinks.forEach(function(link) {
link.classList.remove("active");
});
// Show selected tab content
document.getElementById(tabId).style.display = "block";
// Add active class to clicked tab
event.currentTarget.classList.add("active");
}
function showCustomerModal() {
const modal = document.getElementById("customerModal");
if (modal) {
modal.style.display = "flex";
}
}
function closeCustomerModal() {
const modal = document.getElementById("customerModal");
if (modal) {
modal.style.display = "none";
}
}
function copyToClipboard(text) {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(function() {
// Show temporary success message
const originalText = event.target.innerHTML;
event.target.innerHTML = \'<i class="fa-solid fa-check"></i> Copied!\';
event.target.style.background = \'#d4edda\';
setTimeout(function() {
event.target.innerHTML = originalText;
event.target.style.background = \'#f8f9fa\';
}, 2000);
}).catch(function(err) {
console.error(\'Failed to copy: \', err);
fallbackCopyToClipboard(text);
});
} else {
fallbackCopyToClipboard(text);
}
}
function fallbackCopyToClipboard(text) {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.left = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand(\'copy\');
const originalText = event.target.innerHTML;
event.target.innerHTML = \'<i class="fa-solid fa-check"></i> Copied!\';
event.target.style.background = \'#d4edda\';
setTimeout(function() {
event.target.innerHTML = originalText;
event.target.style.background = \'#f8f9fa\';
}, 2000);
} catch (err) {
console.error(\'Fallback copy failed: \', err);
alert(\'Failed to copy email\');
}
document.body.removeChild(textArea);
}
// Close modal on background click
document.addEventListener("click", function(e) {
const modal = document.getElementById("customerModal");
if (modal && e.target === modal) {
closeCustomerModal();
}
});
</script>
';
}
template_footer()
?>