- 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.
171 lines
6.1 KiB
PHP
171 lines
6.1 KiB
PHP
<?php
|
|
defined(page_security_key) or exit;
|
|
|
|
$page = 'products_software_assignments';
|
|
//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');
|
|
|
|
// Get product details
|
|
$productrowid = $_GET['productrowid'] ?? '';
|
|
if (empty($productrowid)) {
|
|
header('location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$api_url = '/v2/products/'.$productrowid;
|
|
$product_response = ioServer($api_url,'');
|
|
if (!empty($product_response)){
|
|
$product = json_decode($product_response);
|
|
if (is_array($product) && count($product) > 0) {
|
|
$product = $product[0];
|
|
} else {
|
|
$product = null;
|
|
}
|
|
} else {
|
|
$product = null;
|
|
}
|
|
|
|
// Get assigned software versions
|
|
$api_url = '/v2/products_software_assignment/product_id='.$productrowid;
|
|
$assigned_response = ioServer($api_url,'');
|
|
if (!empty($assigned_response)){$assigned = json_decode($assigned_response,true);}else{$assigned = [];}
|
|
$assigned_ids = array_column($assigned, 'software_version_id');
|
|
|
|
// Get all software versions
|
|
$api_url = '/v2/products_software_versions/list';
|
|
$versions_response = ioServer($api_url,'');
|
|
if (!empty($versions_response)){$versions = json_decode($versions_response,true);}else{$versions = [];}
|
|
|
|
// Get all upgrade paths
|
|
$api_url = '/v2/products_software_upgrade_paths/list';
|
|
$paths_response = ioServer($api_url,'');
|
|
if (!empty($paths_response)){$paths = json_decode($paths_response,true);}else{$paths = [];}
|
|
|
|
// Handle form submission
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit'])) {
|
|
$selected_versions = $_POST['versions'] ?? [];
|
|
|
|
// Delete existing assignments not in selected
|
|
foreach ($assigned as $assign) {
|
|
if (!in_array($assign['software_version_id'], $selected_versions)) {
|
|
$payload = json_encode(['rowID' => $assign['rowID'], 'delete' => true], JSON_UNESCAPED_UNICODE);
|
|
ioServer('/v2/products_software_assignment', $payload);
|
|
}
|
|
}
|
|
|
|
// Add new assignments
|
|
foreach ($selected_versions as $version_id) {
|
|
if (!in_array($version_id, $assigned_ids)) {
|
|
$payload = json_encode(['product_id' => $productrowid, 'software_version_id' => $version_id], JSON_UNESCAPED_UNICODE);
|
|
ioServer('/v2/products_software_assignment', $payload);
|
|
}
|
|
}
|
|
|
|
header('Location: index.php?page=products_software_assignments&productrowid='.$productrowid.'&success_msg=1');
|
|
exit;
|
|
}
|
|
|
|
// Handle success messages
|
|
if (isset($_GET['success_msg'])) {
|
|
if ($_GET['success_msg'] == 1) {
|
|
$success_msg = 'Software assignments updated successfully.';
|
|
}
|
|
}
|
|
|
|
template_header('Software Assignments', 'products_software_assignments', 'manage');
|
|
|
|
$view = '
|
|
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
|
<h2 class="responsive-width-100">Software Assignments for ' . ($product ? (($product->productcode ?? 'Unknown') . ' - ' . (${$product->productname} ?? $product->productname)) : 'Product not found') . '</h2>
|
|
<a href="index.php?page=product&rowID='.$productrowid.'" class="btn alt mar-right-2">back</a>
|
|
</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 .= '
|
|
<form action="" method="post">
|
|
<div class="content-block">
|
|
<div class="block-header">
|
|
<i class="fa-solid fa-bars fa-sm"></i>Select Software Versions
|
|
</div>
|
|
<div class="table">
|
|
<table class="sortable">
|
|
<thead>
|
|
<tr>
|
|
<th><input type="checkbox" id="selectAll"></th>
|
|
<th>Name</th>
|
|
<th>Version</th>
|
|
<th>HW Version</th>
|
|
<th>Status</th>
|
|
<th>Upgrade Paths</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>';
|
|
|
|
foreach ($versions as $version) {
|
|
$checked = in_array($version['rowID'], $assigned_ids) ? 'checked' : '';
|
|
$upgrade_paths = [];
|
|
foreach ($paths as $path) {
|
|
if ($path['from_version_id'] == $version['rowID'] || $path['to_version_id'] == $version['rowID']) {
|
|
$from_ver = '';
|
|
$to_ver = '';
|
|
foreach ($versions as $v) {
|
|
if ($v['rowID'] == $path['from_version_id']) $from_ver = $v['version'];
|
|
if ($v['rowID'] == $path['to_version_id']) $to_ver = $v['version'];
|
|
}
|
|
$upgrade_paths[] = $from_ver . ' → ' . $to_ver . ' (' . $path['price'] . ' ' . $path['currency'] . ')';
|
|
}
|
|
}
|
|
$paths_str = implode('<br>', $upgrade_paths);
|
|
|
|
$view .= '<tr>
|
|
<td><input type="checkbox" name="versions[]" value="'.$version['rowID'].'" '.$checked.'></td>
|
|
<td>'.$version['name'].'</td>
|
|
<td>'.$version['version'].'</td>
|
|
<td>'.$version['hw_version'].'</td>
|
|
<td>'.(($version['status'] == 1) ? 'Active' : 'Inactive').'</td>
|
|
<td>'.$paths_str.'</td>
|
|
</tr>';
|
|
}
|
|
|
|
$view .= '
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
|
<input type="submit" name="submit" value="Save Assignments" class="btn">
|
|
</div>
|
|
</form>
|
|
';
|
|
|
|
$view .= '
|
|
<script>
|
|
document.getElementById("selectAll").addEventListener("change", function() {
|
|
var checkboxes = document.querySelectorAll("input[name=\"versions[]\"]");
|
|
for (var checkbox of checkboxes) {
|
|
checkbox.checked = this.checked;
|
|
}
|
|
});
|
|
</script>
|
|
';
|
|
|
|
//OUTPUT
|
|
echo $view;
|
|
|
|
template_footer();
|
|
?>
|