-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
198 lines (181 loc) · 9.99 KB
/
Copy pathsearch.php
File metadata and controls
198 lines (181 loc) · 9.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
require_once("includes/auth.php");
require_role(['admin', 'staff']);
include("config.php");
$page_title = "ค้นหาข้อมูล";
include("includes/header.php");
// ดึงรายการปีการศึกษา
$years_sql = "SELECT DISTINCT academic_year FROM students ORDER BY academic_year DESC";
$years_result = mysqli_query($conn, $years_sql);
// ดึงรายการจังหวัด
$provinces_sql = "SELECT DISTINCT province FROM companies ORDER BY province ASC";
$provinces_result = mysqli_query($conn, $provinces_sql);
// ดึงรายการบริษัท
$companies_sql = "SELECT company_id, company_name FROM companies ORDER BY company_name ASC";
$companies_result = mysqli_query($conn, $companies_sql);
// สร้าง SQL Query (ใช้ prepared statement แทน string concatenation)
$where_conditions = [];
$params = [];
$types = '';
$search_performed = false;
if(isset($_GET['search'])) {
$search_performed = true;
if(!empty($_GET['academic_year'])) {
$where_conditions[] = "s.academic_year = ?";
$params[] = intval($_GET['academic_year']);
$types .= 'i';
}
if(!empty($_GET['province'])) {
$where_conditions[] = "c.province = ?";
$params[] = $_GET['province'];
$types .= 's';
}
if(!empty($_GET['company_id'])) {
$where_conditions[] = "c.company_id = ?";
$params[] = intval($_GET['company_id']);
$types .= 'i';
}
if(!empty($_GET['status'])) {
$where_conditions[] = "i.status = ?";
$params[] = $_GET['status'];
$types .= 's';
}
}
// สร้าง SQL Query หลัก
$sql = "SELECT i.*,
s.student_id, s.first_name, s.last_name, s.academic_year,
c.company_name, c.province
FROM internships i
JOIN students s ON i.student_id = s.student_id
JOIN companies c ON i.company_id = c.company_id";
if(!empty($where_conditions)) {
$sql .= " WHERE " . implode(" AND ", $where_conditions);
}
$sql .= " ORDER BY i.start_date DESC";
$result = null;
if($search_performed) {
$stmt = $conn->prepare($sql);
if($types !== '') {
$stmt->bind_param($types, ...$params);
}
$stmt->execute();
$result = $stmt->get_result();
}
?>
<div class="breadcrumb">
<a href="index.php"><?php echo icon('home', ['class'=>'icon-sm']); ?> หน้าหลัก</a>
<span class="sep">/</span><span class="current">ค้นหาข้อมูล</span>
</div>
<div class="page-header"><div><h1>ค้นหาข้อมูลการฝึกงาน</h1></div></div>
<div class="filter-bar">
<form method="GET" action="">
<div class="form-grid">
<div class="gc-3">
<label class="form-label" for="academic_year">ปีการศึกษา</label>
<select id="academic_year" name="academic_year" class="input">
<option value="">ทั้งหมด</option>
<?php while($year = mysqli_fetch_assoc($years_result)): ?>
<option value="<?php echo htmlspecialchars($year['academic_year']); ?>"
<?php echo (isset($_GET['academic_year']) && $_GET['academic_year'] == $year['academic_year']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($year['academic_year']); ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="gc-3">
<label class="form-label" for="province">จังหวัด</label>
<select id="province" name="province" class="input">
<option value="">ทั้งหมด</option>
<?php while($prov = mysqli_fetch_assoc($provinces_result)): ?>
<option value="<?php echo htmlspecialchars($prov['province']); ?>"
<?php echo (isset($_GET['province']) && $_GET['province'] == $prov['province']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($prov['province']); ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="gc-3">
<label class="form-label" for="company_id">สถานประกอบการ</label>
<select id="company_id" name="company_id" class="input">
<option value="">ทั้งหมด</option>
<?php while($comp = mysqli_fetch_assoc($companies_result)): ?>
<option value="<?php echo $comp['company_id']; ?>"
<?php echo (isset($_GET['company_id']) && $_GET['company_id'] == $comp['company_id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($comp['company_name']); ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="gc-3">
<label class="form-label" for="status">สถานะ</label>
<select id="status" name="status" class="input">
<option value="">ทั้งหมด</option>
<option value="กำลังฝึกงาน" <?php echo (isset($_GET['status']) && $_GET['status'] == 'กำลังฝึกงาน') ? 'selected' : ''; ?>>กำลังฝึกงาน</option>
<option value="ฝึกงานเสร็จสิ้น" <?php echo (isset($_GET['status']) && $_GET['status'] == 'ฝึกงานเสร็จสิ้น') ? 'selected' : ''; ?>>ฝึกงานเสร็จสิ้น</option>
<option value="ยกเลิกการฝึกงาน" <?php echo (isset($_GET['status']) && $_GET['status'] == 'ยกเลิกการฝึกงาน') ? 'selected' : ''; ?>>ยกเลิกการฝึกงาน</option>
</select>
</div>
</div>
<div class="filter-actions">
<button type="submit" name="search" value="1" class="btn btn-primary btn-sm"><?php echo icon('search', ['class'=>'icon-sm']); ?> ค้นหา</button>
<a href="search.php" class="btn btn-secondary btn-sm"><?php echo icon('rotate-ccw', ['class'=>'icon-sm']); ?> ล้างค่า</a>
</div>
</form>
</div>
<?php if($search_performed): ?>
<p class="result-count">ผลการค้นหา: <strong><?php echo number_format(mysqli_num_rows($result)); ?></strong> รายการ</p>
<?php if(mysqli_num_rows($result) > 0): ?>
<div class="table-wrapper">
<table class="data-table">
<caption class="sr-only">ผลการค้นหาข้อมูลการฝึกงานตามเงื่อนไขที่เลือก</caption>
<thead>
<tr>
<th>นักศึกษา</th>
<th>รหัส</th>
<th>ปีการศึกษา</th>
<th>บริษัท</th>
<th>จังหวัด</th>
<th>วันที่เริ่ม</th>
<th>วันที่สิ้นสุด</th>
<th>สถานะ</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_assoc($result)):
if($row['status'] == 'กำลังฝึกงาน') {
$badge_class = 'badge-warning';
} elseif($row['status'] == 'ฝึกงานเสร็จสิ้น') {
$badge_class = 'badge-success';
} else {
$badge_class = 'badge-danger';
}
?>
<tr>
<td><a href="student_history.php?id=<?php echo $row['student_id']; ?>"><?php echo htmlspecialchars($row['first_name'] . ' ' . $row['last_name']); ?></a></td>
<td><?php echo htmlspecialchars($row['student_id']); ?></td>
<td><?php echo htmlspecialchars($row['academic_year']); ?></td>
<td><a href="company_details.php?id=<?php echo $row['company_id']; ?>"><?php echo htmlspecialchars($row['company_name']); ?></a></td>
<td class="cell-muted"><?php echo htmlspecialchars($row['province']); ?></td>
<td><?php echo date('d/m/Y', strtotime($row['start_date'])); ?></td>
<td><?php echo date('d/m/Y', strtotime($row['end_date'])); ?></td>
<td><span class="badge <?php echo $badge_class; ?>"><?php echo htmlspecialchars($row['status']); ?></span></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="empty-state">
<?php echo icon('search'); ?>
<h3>ไม่พบข้อมูลที่ค้นหา</h3>
<p>กรุณาลองเปลี่ยนเงื่อนไขการค้นหาใหม่</p>
</div>
<?php endif; ?>
<?php else: ?>
<div class="empty-state">
<?php echo icon('search'); ?>
<h3>ระบบค้นหาข้อมูลการฝึกงาน</h3>
<p>เลือกเงื่อนไขการค้นหาที่ต้องการด้านบน แล้วกดปุ่ม "ค้นหา" เพื่อแสดงผลลัพธ์ สามารถเลือกได้หลายเงื่อนไขพร้อมกัน หรือเลือกเพียงเงื่อนไขเดียวก็ได้</p>
</div>
<?php endif; ?>
<?php include("includes/footer.php"); ?>