<?php
require_once '../includes/functions.php';
if (!is_logged_in()) {
redirect('/login.php');
}
require_once '../includes/header.php';
$user_id = $_SESSION['user_id'];
// ثبت گزارش جدید
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']) && $_POST['action'] == 'add_report') {
$subject1 = trim($_POST['subject1']);
$subject2 = trim($_POST['subject2']);
$report_text = trim($_POST['report_text']);
$image_path = null;
if (empty($subject1) || empty($subject2) || empty($report_text)) {
set_message("لطفاً تمام فیلدهای الزامی را پر کنید.", "error");
} else {
// آپلود تصویر
if (isset($_FILES['report_image']) && $_FILES['report_image']['error'] == UPLOAD_ERR_OK) {
$target_dir = UPLOAD_DIR;
if (!is_dir($target_dir)) mkdir($target_dir, 0777, true);
$image_name = basename($_FILES['report_image']['name']);
$imageFileType = strtolower(pathinfo($image_name, PATHINFO_EXTENSION));
$target_file = $target_dir . 'report_' . uniqid() . '.' . $imageFileType;
$uploadOk = 1;
$check = getimagesize($_FILES['report_image']['tmp_name']);
if ($check === false) $uploadOk = 0;
if ($_FILES['report_image']['size'] > 5000000) $uploadOk = 0;
if(!in_array($imageFileType, ["jpg","jpeg","png","gif"])) $uploadOk = 0;
if ($uploadOk == 1) {
if (move_uploaded_file($_FILES['report_image']['tmp_name'], $target_file)) {
$image_path = str_replace(SITE_ROOT, '/', $target_file);
}
}
}
$stmt = $mysqli->prepare("INSERT INTO reports (user_id, subject1, subject2, report_text, image_path) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("issss", $user_id, $subject1, $subject2, $report_text, $image_path);
if ($stmt->execute()) {
set_message("گزارش با موفقیت ثبت شد.", "success");
redirect('/user/reports.php');
} else {
set_message("خطا در ثبت گزارش: " . $mysqli->error, "error");
}
$stmt->close();
}
}
// جستجو
$search_text = $_GET['search_text'] ?? '';
$search_subject1 = $_GET['search_subject1'] ?? '';
$search_subject2 = $_GET['search_subject2'] ?? '';
$query = "SELECT * FROM reports WHERE user_id = ?";
$params = [$user_id];
$types = "i";
if (!empty($search_text)) {
$query .= " AND report_text LIKE ?";
$params[] = "%$search_text%";
$types .= "s";
}
if (!empty($search_subject1)) {
$query .= " AND subject1 LIKE ?";
$params[] = "%$search_subject1%";
$types .= "s";
}
if (!empty($search_subject2)) {
$query .= " AND subject2 LIKE ?";
$params[] = "%$search_subject2%";
$types .= "s";
}
$query .= " ORDER BY created_at DESC";
$stmt = $mysqli->prepare($query);
$stmt->bind_param($types, ...$params);
$stmt->execute();
$result = $stmt->get_result();
$reports = [];
while ($row = $result->fetch_assoc()) $reports[] = $row;
$stmt->close();
?>
<div class="container" style="max-width:900px;">
<h2 class="modern-title"><i class="fa fa-clipboard-list"></i> گزارشهای من</h2>
<!-- فرم ثبت گزارش -->
<div class="modern-card">
<form action="reports.php" method="POST" enctype="multipart/form-data" class="modern-form">
<input type="hidden" name="action" value="add_report">
<div class="modern-form-row">
<div class="modern-form-group">
<label>موضوع 1 <span class="required">*</span></label>
<input type="text" name="subject1" required>
</div>
<div class="modern-form-group">
<label>موضوع 2 <span class="required">*</span></label>
<input type="text" name="subject2" required>
</div>
</div>
<div class="modern-form-group">
<label>متن گزارش <span class="required">*</span></label>
<textarea name="report_text" rows="3" required></textarea>
</div>
<div class="modern-form-group">
<label>تصویر (اختیاری)</label>
<input type="file" name="report_image" accept="image/*">
</div>
<div class="modern-form-actions">
<button type="submit" class="modern-btn modern-btn-primary"><i class="fa fa-plus"></i> ثبت گزارش</button>
</div>
</form>
</div>
<!-- فرم جستجو -->
<div class="modern-card modern-search-card">
<form action="reports.php" method="GET" class="modern-form modern-form-inline">
<input type="text" name="search_text" placeholder="جستجو در متن..." value="<?php echo htmlspecialchars($search_text); ?>">
<input type="text" name="search_subject1" placeholder="موضوع 1..." value="<?php echo htmlspecialchars($search_subject1); ?>">
<input type="text" name="search_subject2" placeholder="موضوع 2..." value="<?php echo htmlspecialchars($search_subject2); ?>">
<button type="submit" class="modern-btn modern-btn-secondary"><i class="fa fa-search"></i> جستجو</button>
<?php if ($search_text || $search_subject1 || $search_subject2): ?>
<a href="reports.php" class="modern-btn modern-btn-light"><i class="fa fa-times"></i> پاک کردن</a>
<?php endif; ?>
</form>
</div>
<!-- لیست گزارشها -->
<div class="modern-list">
<?php if (!empty($reports)): ?>
<?php foreach ($reports as $report): ?>
<div class="modern-report-card">
<div class="modern-report-header">
<span class="modern-badge modern-badge-blue"><?php echo htmlspecialchars($report['subject1']); ?></span>
<span class="modern-badge modern-badge-green"><?php echo htmlspecialchars($report['subject2']); ?></span>
<span class="modern-report-date">
<i class="fa fa-calendar"></i>
<?php echo convert_to_jalali(date('Y-m-d', strtotime($report['created_at']))); ?>
<i class="fa fa-clock"></i>
<?php echo date('H:i', strtotime($report['created_at'])); ?>
</span>
</div>
<div class="modern-report-body">
<p><?php echo nl2br(htmlspecialchars($report['report_text'])); ?></p>
<?php if (!empty($report['image_path'])): ?>
<div class="modern-report-image">
<a href="<?php echo htmlspecialchars($report['image_path']); ?>" target="_blank">
<img src="<?php echo htmlspecialchars($report['image_path']); ?>" alt="تصویر گزارش">
</a>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="modern-empty">
<i class="fa fa-info-circle"></i>
<?php if ($search_text || $search_subject1 || $search_subject2): ?>
هیچ گزارشی با معیار جستجوی شما یافت نشد.
<?php else: ?>
هنوز گزارشی ثبت نکردهاید.
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
<!-- فونت آیکون FontAwesome (در صورت نیاز) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<style>
/* Modern Material Design for Reports */
.modern-title {
font-size: 1.7rem;
color: #1976d2;
margin-bottom: 1.5rem;
display: flex;
align-items: center;
gap: 10px;
}
.modern-card {
background: #fff;
border-radius: 12px;
box-shadow: 0 2px 12px rgba(25, 118, 210, 0.07);
padding: 1.5rem 1.2rem;
margin-bottom: 1.5rem;
}
.modern-form-row {
display: flex;
gap: 1rem;
}
.modern-form-group {
flex: 1;
margin-bottom: 1rem;
}
.modern-form-group label {
font-weight: 500;
color: #333;
margin-bottom: 0.3rem;
display: block;
}
.modern-form-group input[type="text"],
.modern-form-group textarea,
.modern-form-group input[type="file"] {
width: 100%;
padding: 0.7rem 0.9rem;
border: 1.5px solid #e3e3e3;
border-radius: 6px;
font-size: 1rem;
background: #f7f9fa;
transition: border 0.2s;
}
.modern-form-group input[type="text"]:focus,
.modern-form-group textarea:focus {
border-color: #1976d2;
background: #fff;
}
.modern-form-actions {
text-align: left;
}
.modern-btn {
padding: 0.6rem 1.3rem;
border: none;
border-radius: 6px;
font-size: 1rem;
font-family: inherit;
cursor: pointer;
transition: background 0.2s;
margin-left: 0.5rem;
display: inline-block;
}
.modern-btn-primary {
background: #1976d2;
color: #fff;
}
.modern-btn-primary:hover { background: #1256a3; }
.modern-btn-secondary {
background: #43a047;
color: #fff;
}
.modern-btn-secondary:hover { background: #2e7031; }
.modern-btn-light {
background: #e3e3e3;
color: #333;
}
.modern-btn-light:hover { background: #cfd8dc; }
.required { color: #e53935; }
.modern-form-inline {
display: flex;
gap: 0.7rem;
flex-wrap: wrap;
align-items: center;
}
.modern-search-card {
background: #f5f7fa;
box-shadow: none;
border: 1px solid #e3e3e3;
}
.modern-list {
margin-top: 1.5rem;
}
.modern-report-card {
background: #fff;
border-radius: 10px;
box-shadow: 0 1px 6px rgba(25, 118, 210, 0.06);
margin-bottom: 1.2rem;
padding: 1.2rem 1rem;
transition: box-shadow 0.2s;
}
.modern-report-card:hover {
box-shadow: 0 4px 16px rgba(25, 118, 210, 0.13);
}
.modern-report-header {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 0.7rem;
flex-wrap: wrap;
}
.modern-badge {
display: inline-block;
padding: 0.3em 0.9em;
border-radius: 5px;
font-size: 0.95em;
font-weight: 500;
margin-left: 0.3em;
}
.modern-badge-blue { background: #1976d2; color: #fff; }
.modern-badge-green { background: #43a047; color: #fff; }
.modern-report-date {
margin-right: auto;
color: #888;
font-size: 0.95em;
display: flex;
align-items: center;
gap: 5px;
}
.modern-report-body p {
margin: 0 0 0.7em 0;
color: #222;
font-size: 1.05em;
}
.modern-report-image img {
max-width: 180px;
max-height: 120px;
border-radius: 7px;
border: 1px solid #e3e3e3;
margin-top: 0.5em;
background: #fafafa;
}
.modern-empty {
text-align: center;
color: #888;
font-size: 1.1em;
padding: 2.5em 0;
}
@media (max-width: 700px) {
.modern-form-row { flex-direction: column; }
.modern-form-inline { flex-direction: column; gap: 0.5rem; }
.modern-title { font-size: 1.2rem; }
.modern-card, .modern-search-card { padding: 1rem 0.5rem; }
}
</style>
<?php require_once '../includes/footer.php'; ?>