|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/assetradar.outerorbittech.com/admin/ | |
|
Path: /home2/outerorb/assetradar.outerorbittech.com/admin/assign_item.php
Size: 2.49 KB
Permissions: 0666
<?php
require_once __DIR__ . '/../inc/auth.php';
require_once __DIR__ . '/../config.php';
require_login();
$u = current_user();
require_admin();
$item_id = $_GET['item_id'] ?? null;
if (!$item_id) {
header('Location: inventory.php');
exit;
}
// Fetch item details
$stmt = $mysqli->prepare('SELECT i.*, c.name as category_name, u.name as assigned_name FROM items i LEFT JOIN categories c ON i.category_id=c.id LEFT JOIN users u ON i.assigned_to=u.id WHERE i.id = ? LIMIT 1');
$stmt->bind_param('i', $item_id);
$stmt->execute();
$res = $stmt->get_result();
$item = $res->fetch_assoc();
if (!$item) {
die('Item not found.');
}
// Fetch all users for assignment dropdown
$users_res = $mysqli->query('SELECT id, name FROM users WHERE deleted=0 ORDER BY name ASC');
$users = [];
while ($row = $users_res->fetch_assoc()) {
$users[] = $row;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$new_assigned_to = $_POST['assigned_to'] ?? null;
if ($new_assigned_to === null) {
$error = 'Please select a user to assign.';
} else {
$update_stmt = $mysqli->prepare('UPDATE items SET assigned_to = ? WHERE id = ?');
$update_stmt->bind_param('ii', $new_assigned_to, $item_id);
if ($update_stmt->execute()) {
header('Location: inventory.php?msg=Item assigned successfully');
exit;
} else {
$error = 'Failed to update assignment: ' . $mysqli->error;
}
}
}
include __DIR__ . '/../inc/header.php';
include __DIR__ . '/admin_menu.php';
?>
<div class="card p-3 card-hero">
<h5>Assign/Transfer Item: <?php echo htmlspecialchars($item['item_name']); ?></h5>
<?php if (!empty($error)): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form method="post" action="">
<div class="mb-3">
<label for="assigned_to" class="form-label">Assign To</label>
<select id="assigned_to" name="assigned_to" class="form-select" required>
<option value="">Select user</option>
<?php foreach ($users as $user): ?>
<option value="<?php echo $user['id']; ?>" <?php echo ($item['assigned_to'] == $user['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($user['name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-primary">Assign</button>
<a href="inventory.php" class="btn btn-secondary ms-2">Cancel</a>
</form>
</div>
<?php include __DIR__ . '/../inc/footer.php'; ?>