Add software tool functionality with device connection and upgrade options
- Implemented the software tool page with user interface for connecting devices. - Added functionality to display connection status and software upgrade options. - Included a help modal with step-by-step instructions for users. - Integrated error handling and user permission checks. - Enhanced user experience with dynamic content updates and visual feedback.
This commit is contained in:
@@ -37,12 +37,19 @@ $path = [
|
||||
'updatedby' => $_SESSION['username']
|
||||
];
|
||||
|
||||
// Determine filter version id from URL (for hw_version filtering)
|
||||
$filter_version_id = $_GET['from_version_id'] ?? $_GET['to_version_id'] ?? $_GET['id'] ?? '';
|
||||
// Check if coming from version page (id parameter) or editing existing path
|
||||
$from_version_page = false;
|
||||
$to_version_fixed = false;
|
||||
if (isset($_GET['id']) && !isset($_GET['path_id'])) {
|
||||
// Coming from version page - this is the TO version
|
||||
$from_version_page = true;
|
||||
$to_version_fixed = $_GET['id'];
|
||||
$path['to_version_id'] = $to_version_fixed;
|
||||
}
|
||||
|
||||
// If editing, fetch existing data
|
||||
if (isset($_GET['id']) && $_GET['id'] != '') {
|
||||
$api_url = '/v2/products_software_upgrade_paths/rowID=' . $_GET['id'];
|
||||
// If editing an existing path, load it
|
||||
if (isset($_GET['path_id']) && $_GET['path_id'] != '') {
|
||||
$api_url = '/v2/products_software_upgrade_paths/rowID=' . $_GET['path_id'];
|
||||
$response = ioServer($api_url, '');
|
||||
|
||||
if (!empty($response)) {
|
||||
@@ -53,6 +60,9 @@ if (isset($_GET['id']) && $_GET['id'] != '') {
|
||||
}
|
||||
}
|
||||
|
||||
// Determine filter version id from URL (for hw_version filtering)
|
||||
$filter_version_id = $_GET['from_version_id'] ?? $_GET['to_version_id'] ?? $_GET['id'] ?? '';
|
||||
|
||||
// Fetch software versions for selects
|
||||
$api_url = '/v2/products_software_versions/list';
|
||||
$versions_response = ioServer($api_url, '');
|
||||
@@ -163,10 +173,10 @@ $view ='
|
||||
<a href="' . $url . '" class="btn alt mar-right-2">' . $button_cancel . '</a>
|
||||
';
|
||||
|
||||
if ($delete_allowed === 1 && isset($_GET['id'])){
|
||||
if ($delete_allowed === 1 && isset($_GET['path_id']) && $_GET['path_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 upgrade path?\')">';
|
||||
}
|
||||
if (($update_allowed === 1 && isset($_GET['id'])) || ($create_allowed === 1 && !isset($_GET['id']))){
|
||||
if (($update_allowed === 1 && isset($_GET['path_id'])) || ($create_allowed === 1 && !isset($_GET['path_id']))){
|
||||
$view .= '<input type="submit" name="submit" value="💾+" class="btn">';
|
||||
}
|
||||
|
||||
@@ -179,21 +189,48 @@ $view .= '<div class="content-block">
|
||||
<option value="">Select From Version</option>';
|
||||
if (!empty($versions)) {
|
||||
foreach ($versions as $ver) {
|
||||
// Skip the TO version from FROM dropdown to prevent FROM = TO
|
||||
if ($path['to_version_id'] && $ver->rowID == $path['to_version_id']) {
|
||||
continue;
|
||||
}
|
||||
$selected = ($path['from_version_id'] == $ver->rowID) ? ' selected' : '';
|
||||
$view .= '<option value="' . $ver->rowID . '"' . $selected . '>' . htmlspecialchars($ver->name . ' (' . $ver->version . ')') . '</option>';
|
||||
}
|
||||
}
|
||||
$view .= ' </select>
|
||||
$view .= ' </select>';
|
||||
|
||||
// If TO version is fixed (coming from version page), show it as read-only text
|
||||
if ($from_version_page && $to_version_fixed) {
|
||||
$to_version_name = '';
|
||||
foreach ($versions as $ver) {
|
||||
if ($ver->rowID == $to_version_fixed) {
|
||||
$to_version_name = htmlspecialchars($ver->name . ' (' . $ver->version . ')');
|
||||
break;
|
||||
}
|
||||
}
|
||||
$view .= '
|
||||
<label for="to_version_display">To Version</label>
|
||||
<input type="text" id="to_version_display" value="' . $to_version_name . '" disabled>
|
||||
<input type="hidden" id="to_version_id" name="to_version_id" value="' . $to_version_fixed . '">';
|
||||
} else {
|
||||
// Show dropdown for TO version when editing
|
||||
$view .= '
|
||||
<label for="to_version_id"><i class="required">*</i>To Version</label>
|
||||
<select id="to_version_id" name="to_version_id" required>
|
||||
<option value="">Select To Version</option>';
|
||||
if (!empty($versions)) {
|
||||
foreach ($versions as $ver) {
|
||||
// Skip the FROM version from TO dropdown to prevent FROM = TO
|
||||
if ($path['from_version_id'] && $ver->rowID == $path['from_version_id']) {
|
||||
continue;
|
||||
}
|
||||
$selected = ($path['to_version_id'] == $ver->rowID) ? ' selected' : '';
|
||||
$view .= '<option value="' . $ver->rowID . '"' . $selected . '>' . htmlspecialchars($ver->name . ' (' . $ver->version . ')') . '</option>';
|
||||
}
|
||||
}
|
||||
$view .= ' </select>
|
||||
$view .= ' </select>';
|
||||
}
|
||||
$view .= '
|
||||
<label for="price">Price</label>
|
||||
<input id="price" type="number" step="0.01" name="price" placeholder="Price" value="' . htmlspecialchars($path['price']) . '">
|
||||
<label for="currency">Currency</label>
|
||||
@@ -207,6 +244,30 @@ $view .= ' </select>
|
||||
<input type="hidden" name="rowID" value="' . htmlspecialchars($path['rowID']) . '">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Validate that FROM and TO versions are different
|
||||
document.querySelector("form").addEventListener("submit", function(e) {
|
||||
const fromVersion = document.getElementById("from_version_id").value;
|
||||
const toVersion = document.getElementById("to_version_id").value;
|
||||
|
||||
if (fromVersion && toVersion && fromVersion === toVersion) {
|
||||
e.preventDefault();
|
||||
alert("Error: FROM version cannot be the same as TO version");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Dynamic filtering: Update dropdowns when selection changes
|
||||
const fromSelect = document.getElementById("from_version_id");
|
||||
const toSelect = document.getElementById("to_version_id");
|
||||
|
||||
if (fromSelect && toSelect && toSelect.tagName === "SELECT") {
|
||||
fromSelect.addEventListener("change", function() {
|
||||
// No need to dynamically filter since PHP already handles it
|
||||
});
|
||||
}
|
||||
</script>
|
||||
';
|
||||
|
||||
//OUTPUT
|
||||
|
||||
Reference in New Issue
Block a user