Files
assetmgt/products_software_assignments.php
“VeLiTi” 18469fe958 Refactor authorization checks to use 'permissions' instead of 'profile' in multiple files
- Updated authorization checks in product management, product attributes, configurations, software, and user management files to use 'permissions' for consistency.
- Ensured that all relevant pages correctly check user permissions for read, update, delete, and create actions.
- Adjusted session variable references to align with the new permissions structure across various modules.
2026-01-20 15:00:00 +01:00

171 lines
6.2 KiB
PHP

<?php
defined(page_security_key) or exit;
$page = 'products_software_assignments';
//Check if allowed
if (isAllowed($page,$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$update_allowed = isAllowed($page ,$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'U');
$delete_allowed = isAllowed($page ,$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['authorization']['permissions'],$_SESSION['authorization']['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();
?>