|
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/user/ | |
|
Path: /home2/outerorb/assetradar.outerorbittech.com/user/report_issue.php
Size: 3.69 KB
Permissions: 0666
<?php
// Log all errors and exceptions
set_error_handler(function($errno, $errstr, $errfile, $errline) {
error_log(date('Y-m-d H:i:s') . " - ERROR [$errno] $errstr in $errfile on line $errline\n", 3, __DIR__ . '/../error.log');
return false;
});
set_exception_handler(function($ex) {
error_log(date('Y-m-d H:i:s') . ' - EXCEPTION: ' . $ex->getMessage() . "\n", 3, __DIR__ . '/../error.log');
});
require_once __DIR__ . '/../inc/auth.php';
require_once __DIR__ . '/../functions.php';
require_login();
$u = current_user();
if ($u['role_slug'] === 'admin') header('Location: ' . BASE_URL . 'admin/dashboard.php');
if ($u['role_slug'] === 'tl') header('Location: ' . BASE_URL . 'tl/dashboard.php');
$item_id = isset($_REQUEST['item_id']) ? (int)$_REQUEST['item_id'] : 0;
$item = $mysqli->query('SELECT * FROM items WHERE id=' . $item_id)->fetch_assoc();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
verify_csrf();
if (!$item) {
$error = 'Invalid item selected.';
} else {
$issue_type = $_POST['issue_type'];
$desc = $_POST['description'];
$status = 'Pending';
try {
$stmt = $mysqli->prepare('INSERT INTO tickets (item_id, user_id, item_name, issue_type, description, status, created_at) VALUES (?,?,?,?,?,?,NOW())');
if (!$stmt) throw new Exception('Prepare failed: ' . $mysqli->error);
$stmt->bind_param('iissss', $item_id, $_SESSION['user_id'], $item['item_name'], $issue_type, $desc, $status);
if ($stmt->execute()) {
// insert log
$mysqli->query("INSERT INTO logs (user_id, action, created_at) VALUES (".(int)$_SESSION['user_id'].", 'Reported issue for item {$item_id}', NOW())");
// Multi-level notification: agent, TL, admin
$ticket_id = $stmt->insert_id;
$agent_id = $_SESSION['user_id'];
// Always use agent's team for TL notification
$agent_row = $mysqli->query('SELECT team_id FROM users WHERE id=' . (int)$agent_id)->fetch_assoc();
$team_id = $agent_row ? (int)$agent_row['team_id'] : 0;
$msg = 'New ticket #'.$ticket_id.' reported by '.htmlspecialchars($item['item_name']);
notify_team_and_admins($agent_id, $team_id, $msg, [], $ticket_id);
// Set success flag and redirect
$_SESSION['issue_reported'] = true;
header('Location: ' . BASE_URL . 'user/dashboard.php?success=1');
exit;
} else {
throw new Exception('Execute failed: ' . $stmt->error);
}
} catch (Exception $ex) {
$error = $ex->getMessage();
error_log(date('Y-m-d H:i:s') . ' - report_issue.php: ' . $error . "\n", 3, __DIR__ . '/../error.log');
}
}
}
?>
<?php include __DIR__ . '/../inc/header.php'; ?>
<?php include __DIR__ . '/user_menu.php'; ?>
<div class="card p-3 card-hero">
<h5>Report Issue for <?php echo esc($item['item_name'].' ('.$item['asset_tag'].')'); ?></h5>
<?php if (!empty($error)): ?><div class="alert alert-danger"><?php echo esc($error); ?></div><?php endif; ?>
<?php if ($item): ?>
<form method="post">
<?php echo csrf_field(); ?>
<div class="mb-3"><label>Issue Type</label>
<select name="issue_type" class="form-control">
<option>Not Working</option>
<option>Broken</option>
<option>Needs Replacement</option>
<option>Slow / Performance</option>
<option>Other</option>
</select>
</div>
<div class="mb-3"><label>Description</label><textarea class="form-control" name="description" required></textarea></div>
<button class="btn btn-primary">Submit</button>
</form>
<?php else: ?>
<div class="alert alert-warning">No item selected or item not found.</div>
<?php endif; ?>
</div>
<?php include __DIR__ . '/../inc/footer.php'; ?>