- Implemented API endpoint for managing software versions in `products_software_versions.php`. - Created management page for software version assignments in `products_software_assignments.php`. - Developed upgrade paths management functionality in `products_software_upgrade_paths_manage.php`. - Enhanced software version details page in `products_software_version.php`. - Added form handling and validation for software version creation and updates in `products_software_version_manage.php`. - Introduced pagination and filtering for software versions in `products_software_versions.php`. - Implemented success message handling for CRUD operations across various pages.
216 lines
7.8 KiB
PHP
216 lines
7.8 KiB
PHP
<?php
|
|
defined(page_security_key) or exit;
|
|
|
|
// Fallback translations
|
|
if (!isset($button_cancel)) $button_cancel = 'Cancel';
|
|
|
|
$page = 'products_software_upgrade_paths_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');
|
|
|
|
// Determine redirect URL
|
|
if (isset($_GET['id'])) {
|
|
$url = 'index.php?page=products_software_version&rowID=' . $_GET['id'];
|
|
} else {
|
|
$url = 'index.php?page=products_software_versions';
|
|
}
|
|
|
|
// Default input values
|
|
$path = [
|
|
'rowID' => '',
|
|
'from_version_id' => '',
|
|
'to_version_id' => '',
|
|
'price' => '',
|
|
'currency' => 'USD',
|
|
'description' => '',
|
|
'is_active' => 1,
|
|
'created' => '',
|
|
'createdby' => $_SESSION['username'],
|
|
'updated' => '',
|
|
'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'] ?? '';
|
|
|
|
// If editing, fetch existing data
|
|
if (isset($_GET['id']) && $_GET['id'] != '') {
|
|
$api_url = '/v2/products_software_upgrade_paths/rowID=' . $_GET['id'];
|
|
$response = ioServer($api_url, '');
|
|
var_dump($response);
|
|
if (!empty($response)) {
|
|
$existing = json_decode($response);
|
|
if (!empty($existing)) {
|
|
$path = (array) $existing[0];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch software versions for selects
|
|
$api_url = '/v2/products_software_versions/list';
|
|
$versions_response = ioServer($api_url, '');
|
|
$all_versions = [];
|
|
if (!empty($versions_response)) {
|
|
$all_versions = json_decode($versions_response);
|
|
}
|
|
|
|
// Determine hw_version for filtering
|
|
$filter_hw_version = null;
|
|
$selected_versions = [];
|
|
|
|
if (!empty($path['from_version_id'])) {
|
|
$selected_versions[] = $path['from_version_id'];
|
|
$api_url = '/v2/products_software_versions/rowID=' . $path['from_version_id'];
|
|
$response = ioServer($api_url, '');
|
|
if (!empty($response)) {
|
|
$ver = json_decode($response);
|
|
if (!empty($ver)) {
|
|
$filter_hw_version = $ver[0]->hw_version;
|
|
}
|
|
}
|
|
}
|
|
if (!empty($path['to_version_id'])) {
|
|
$selected_versions[] = $path['to_version_id'];
|
|
}
|
|
|
|
if ($filter_hw_version === null && !empty($filter_version_id)) {
|
|
$api_url = '/v2/products_software_versions/rowID=' . $filter_version_id;
|
|
$response = ioServer($api_url, '');
|
|
if (!empty($response)) {
|
|
$ver = json_decode($response);
|
|
if (!empty($ver)) {
|
|
$filter_hw_version = $ver[0]->hw_version;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Filter versions to same hw_version
|
|
$versions = [];
|
|
if ($filter_hw_version !== null) {
|
|
foreach ($all_versions as $ver) {
|
|
if ($ver->hw_version == $filter_hw_version) {
|
|
$versions[] = $ver;
|
|
}
|
|
}
|
|
// Ensure selected versions are included
|
|
foreach ($selected_versions as $sel_id) {
|
|
$found = false;
|
|
foreach ($versions as $ver) {
|
|
if ($ver->rowID == $sel_id) {
|
|
$found = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!$found) {
|
|
// Fetch and add
|
|
$api_url = '/v2/products_software_versions/rowID=' . $sel_id;
|
|
$response = ioServer($api_url, '');
|
|
if (!empty($response)) {
|
|
$ver = json_decode($response);
|
|
if (!empty($ver)) {
|
|
$versions[] = $ver[0];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$versions = $all_versions;
|
|
}
|
|
|
|
// Handle form submission
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
$data = [
|
|
'rowID' => $_POST['rowID'] ?? '',
|
|
'from_version_id' => $_POST['from_version_id'] ?? '',
|
|
'to_version_id' => $_POST['to_version_id'] ?? '',
|
|
'price' => $_POST['price'] ?? '',
|
|
'currency' => $_POST['currency'] ?? 'USD',
|
|
'description' => $_POST['description'] ?? '',
|
|
'is_active' => isset($_POST['is_active']) ? 1 : 0
|
|
];
|
|
|
|
// Handle delete
|
|
if (isset($_POST['delete'])) {
|
|
$data['delete'] = true;
|
|
}
|
|
|
|
// Call API
|
|
$api_url = '/v2/products_software_upgrade_paths/';
|
|
$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 upgrade path.';
|
|
}
|
|
}
|
|
|
|
template_header('Upgrade Path', 'products_software_upgrade_paths_manage', 'manage');
|
|
|
|
$view ='
|
|
<form action="" method="post">
|
|
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
|
<h2 class="responsive-width-100">'.(isset($_GET['id']) ? 'Edit' : 'Create').' Upgrade Path</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="Delete" 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']))){
|
|
$view .= '<input type="submit" name="submit" value="Save" class="btn">';
|
|
}
|
|
|
|
$view .= '</div>';
|
|
|
|
$view .= '<div class="content-block">
|
|
<div class="form responsive-width-100">
|
|
<label for="from_version_id"><i class="required">*</i>From Version</label>
|
|
<select id="from_version_id" name="from_version_id" required>
|
|
<option value="">Select From Version</option>';
|
|
if (!empty($versions)) {
|
|
foreach ($versions as $ver) {
|
|
$selected = ($path['from_version_id'] == $ver->rowID) ? ' selected' : '';
|
|
$view .= '<option value="' . $ver->rowID . '"' . $selected . '>' . htmlspecialchars($ver->name . ' (' . $ver->version . ')') . '</option>';
|
|
}
|
|
}
|
|
$view .= ' </select>
|
|
<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) {
|
|
$selected = ($path['to_version_id'] == $ver->rowID) ? ' selected' : '';
|
|
$view .= '<option value="' . $ver->rowID . '"' . $selected . '>' . htmlspecialchars($ver->name . ' (' . $ver->version . ')') . '</option>';
|
|
}
|
|
}
|
|
$view .= ' </select>
|
|
<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>
|
|
<input id="currency" type="text" name="currency" placeholder="Currency" value="' . htmlspecialchars($path['currency']) . '">
|
|
<label for="description">Description</label>
|
|
<textarea id="description" name="description" placeholder="Description">' . htmlspecialchars($path['description']) . '</textarea>
|
|
<label class="checkbox">
|
|
<input type="checkbox" name="is_active" value="1" ' . ($path['is_active'] ? 'checked' : '') . '>
|
|
<span>Active</span>
|
|
</label>
|
|
<input type="hidden" name="rowID" value="' . htmlspecialchars($path['rowID']) . '">
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
//OUTPUT
|
|
echo $view;
|
|
|
|
template_footer();
|
|
?>
|