Files
assetmgt/products_software_version_manage.php
“VeLiTi” ec20d44267 Refactor UI elements for consistency and clarity
- Updated action buttons across multiple files to use icons (e.g., "Save" to "💾+", "Delete" to "X").
- Replaced "Cancel" button text with a left arrow (←) for a more intuitive navigation experience.
- Removed unnecessary action columns from tables to streamline the interface.
- Enhanced table rows to be clickable for better user interaction, redirecting to relevant management pages.
- Adjusted font sizes and styles in CSS for improved readability and aesthetics.
- Standardized back button functionality to use a left arrow across various pages.
2025-12-15 17:08:44 +01:00

187 lines
7.3 KiB
PHP

<?php
defined(page_security_key) or exit;
// Fallback translations
if (!isset($button_cancel)) $button_cancel = 'Cancel';
$page = 'products_software_version_manage';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
//
if (isset($_GET['id']) && $_GET['id']!=''){
$url = 'index.php?page=products_software_version&rowID='.$_GET['id'];
} else {
$url = 'index.php?page=products_software_versions';
}
// Default input version values
$version = [
'rowID' => '',
'name' => '',
'version' => '',
'description' => '',
'mandatory' => 0,
'latest' => 0,
'hw_version' => '',
'file_path' => '',
'status' => 1,
'created' => '',
'createdby' => $_SESSION['username'],
'updated' => '',
'updatedby' => $_SESSION['username']
];
// If editing, fetch existing data
if (isset($_GET['id']) && $_GET['id'] != '') {
$api_url = '/v2/products_software_versions/rowID=' . $_GET['id'];
$response = ioServer($api_url, '');
if (!empty($response)) {
$existing = json_decode($response);
if (!empty($existing)) {
$version = (array) $existing[0];
}
}
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//CHECK FOR FILE UPLOAD
$uploaded_file = $_FILES["fileToUpload"]["name"] ?? '';
if ($uploaded_file != '' || !empty($uploaded_file)) {
$extension = strtolower(pathinfo($uploaded_file, PATHINFO_EXTENSION));
$target_dir = dirname(__FILE__) . "/firmware/";
if ($extension == 'hex') {
//READ FILE
$contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
//firmwarename
$firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME);
$commitCode = compareCommitCodes($firmware_name, "");
//IF COMMITCODE IS EMPTY THEN RETURN HEX_FW
$fw_name = ($commitCode != '' || !empty($commitCode)) ? $commitCode : $firmware_name;
//Filename
$input_file = $target_dir . $firmware_name . '.HEX';
//store firmware file
file_put_contents($input_file, $contents);
$_POST['file_path'] = $firmware_name . '.HEX';
$_POST['version'] = $fw_name;
} else {
$target_file = $target_dir . $uploaded_file;
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
$_POST['file_path'] = $uploaded_file;
}
}
$data = [
'rowID' => $_POST['rowID'] ?? '',
'name' => $_POST['name'] ?? '',
'version' => $_POST['version'] ?? '',
'description' => $_POST['description'] ?? '',
'mandatory' => isset($_POST['mandatory']) ? 1 : 0,
'latest' => isset($_POST['latest']) ? 1 : 0,
'hw_version' => $_POST['hw_version'] ?? '',
'file_path' => $_POST['file_path'] ?? '',
'status' => isset($_POST['status']) ? 1 : 0
];
// Handle delete
if (isset($_POST['delete'])) {
$data['delete'] = true;
}
// Call API
$api_url = '/v2/products_software_versions/';
$result = ioServer($api_url, json_encode($data));
if ($result) {
$success = isset($_POST['delete']) ? 3 : (isset($_POST['rowID']) && $_POST['rowID'] != '' ? 2 : 1);
header('Location: ' . $url . '&success_msg=' . $success);
exit;
} else {
$error_msg = 'Failed to save software version.';
}
}
template_header('Software Version', 'products_software_version', 'manage');
$view ='
<form action="" method="post" enctype="multipart/form-data">
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">'.(isset($_GET['id']) ? 'Edit' : 'Create').' Software Version</h2>
<a href="' . $url . '" class="btn alt mar-right-2">' . $button_cancel . '</a>
';
if ($delete_allowed === 1 && isset($_GET['id'])){
$view .= '<input type="submit" name="delete" value="X" class="btn red mar-right-2" onclick="return confirm(\'Are you sure you want to delete this software version?\')">';
}
if (($update_allowed === 1 && isset($_GET['id'])) || ($create_allowed === 1 && !isset($_GET['id']))){
$view .= '<input type="submit" name="submit" value="💾+" class="btn">';
}
$view .= '</div>';
$view .= '<div class="content-block">
<div class="form responsive-width-100">
<label for="status">Status</label>
<select id="status" name="status">
<option value="1" ' . ($version['status'] == 1 ? ' selected' : '') . '>Active</option>
<option value="0" ' . ($version['status'] == 0 ? ' selected' : '') . '>Inactive</option>
</select>
<label for="name"><i class="required">*</i>Name</label>
<input id="name" type="text" name="name" placeholder="Name" value="' . htmlspecialchars($version['name']) . '" required>
<label for="version"><i class="required">*</i>Version</label>
<input id="version" type="text" name="version" placeholder="Version" value="' . htmlspecialchars($version['version']) . '" required>
<label for="description">Description</label>
<textarea id="description" name="description" placeholder="Description">' . htmlspecialchars($version['description']) . '</textarea>
<label for="hw_version">HW Version</label>
<input id="hw_version" type="text" name="hw_version" placeholder="HW Version" value="' . htmlspecialchars($version['hw_version']) . '">
<label for="fileToUpload">Upload File</label>
<input type="file" name="fileToUpload" id="fileToUpload" onchange="updateFields()">
<label for="file_path">File Path</label>
<input id="file_path" type="text" name="file_path" placeholder="File Path" value="' . htmlspecialchars($version['file_path']) . '" readonly>
<label class="checkbox">
<input type="checkbox" name="mandatory" value="1" ' . ($version['mandatory'] ? 'checked' : '') . '>
<span>Mandatory</span>
</label>
<label class="checkbox">
<input type="checkbox" name="latest" value="1" ' . ($version['latest'] ? 'checked' : '') . '>
<span>Latest</span>
</label>
<input type="hidden" name="rowID" value="' . htmlspecialchars($version['rowID']) . '">
</div>
</div>
<script>
function updateFields() {
var fileInput = document.getElementById(\'fileToUpload\');
var file = fileInput.files[0];
if (file) {
var fileName = file.name;
var filePathInput = document.getElementById(\'file_path\');
filePathInput.value = fileName;
var versionInput = document.getElementById(\'version\');
if (!versionInput.value) {
var nameWithoutExt = fileName.replace(/\.[^/.]+$/, "");
versionInput.value = nameWithoutExt;
}
}
}
</script>
';
//OUTPUT
echo $view;
template_footer();
?>