-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinternships.php
More file actions
141 lines (133 loc) · 7.51 KB
/
Copy pathinternships.php
File metadata and controls
141 lines (133 loc) · 7.51 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
<?php
require_once("includes/auth.php");
require_role(['admin', 'staff']);
include("config.php");
// ลบข้อมูลการฝึกงาน (POST + CSRF แทน GET link เดิม)
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['delete_internship_id'])) {
verify_csrf();
$internship_id = intval($_POST['delete_internship_id']);
$stmt = $conn->prepare("DELETE FROM internships WHERE internship_id = ?");
$stmt->bind_param('i', $internship_id);
$stmt->execute();
$stmt->close();
flash_set('success', 'ลบข้อมูลการฝึกงานเรียบร้อยแล้ว');
header("Location: internships.php");
exit();
}
$page_title = "จัดการการฝึกงาน";
include("includes/header.php");
$flash = flash_get();
// ดึงข้อมูลการฝึกงานทั้งหมด
$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
ORDER BY i.start_date DESC";
$result = mysqli_query($conn, $sql);
?>
<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 class="page-header-actions">
<a href="internship_form.php" class="btn btn-primary"><?php echo icon('plus', ['class'=>'icon-sm']); ?> เพิ่มข้อมูลการฝึกงาน</a>
</div>
</div>
<?php if($flash): ?>
<div class="alert alert-<?php echo $flash['type'] === 'success' ? 'success' : 'error'; ?>" role="alert">
<?php echo icon($flash['type'] === 'success' ? 'check-circle' : 'alert-triangle'); ?>
<span><?php echo htmlspecialchars($flash['message']); ?></span>
</div>
<?php endif; ?>
<?php
$sql_stats = "SELECT status, COUNT(*) as count FROM internships GROUP BY status";
$result_stats = mysqli_query($conn, $sql_stats);
$stats = ['กำลังฝึกงาน' => 0, 'ฝึกงานเสร็จสิ้น' => 0, 'ยกเลิกการฝึกงาน' => 0];
while($stat = mysqli_fetch_assoc($result_stats)) {
$stats[$stat['status']] = $stat['count'];
}
?>
<div class="stat-grid" style="grid-template-columns: repeat(3, 1fr);">
<div class="stat-card stat-warning">
<div class="stat-value"><?php echo number_format($stats['กำลังฝึกงาน']); ?></div>
<div class="stat-label">กำลังฝึกงาน</div>
</div>
<div class="stat-card stat-success">
<div class="stat-value"><?php echo number_format($stats['ฝึกงานเสร็จสิ้น']); ?></div>
<div class="stat-label">ฝึกงานเสร็จสิ้น</div>
</div>
<div class="stat-card stat-danger">
<div class="stat-value"><?php echo number_format($stats['ยกเลิกการฝึกงาน']); ?></div>
<div class="stat-label">ยกเลิกการฝึกงาน</div>
</div>
</div>
<?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 class="col-center">การจัดการ</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>
<strong><?php echo htmlspecialchars($row['first_name'] . ' ' . $row['last_name']); ?></strong>
<br><span class="text-muted fs-helper">ปีการศึกษา <?php echo $row['academic_year']; ?></span>
</td>
<td><?php echo htmlspecialchars($row['student_id']); ?></td>
<td><?php echo htmlspecialchars($row['company_name']); ?></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>
<td class="col-center">
<div class="btn-group" style="justify-content: center;">
<a href="internship_form.php?id=<?php echo $row['internship_id']; ?>" class="btn btn-secondary btn-sm" aria-label="แก้ไขข้อมูลการฝึกงานของ <?php echo htmlspecialchars($row['first_name']); ?>" title="แก้ไขข้อมูล"><?php echo icon('edit-2', ['class'=>'icon-sm']); ?></a>
<form method="POST" action="" style="display:inline;">
<?php echo csrf_field(); ?>
<input type="hidden" name="delete_internship_id" value="<?php echo $row['internship_id']; ?>">
<button type="submit" class="btn btn-outline-danger btn-sm" aria-label="ลบข้อมูลการฝึกงานของ <?php echo htmlspecialchars($row['first_name']); ?>" title="ลบข้อมูล"
data-confirm-title="ลบข้อมูลการฝึกงาน"
data-confirm-desc="คุณต้องการลบข้อมูลการฝึกงานนี้หรือไม่? การลบนี้ไม่สามารถย้อนกลับได้"
data-confirm-label="ลบข้อมูล" data-confirm-danger="1">
<?php echo icon('trash-2', ['class'=>'icon-sm']); ?>
</button>
</form>
</div>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="empty-state">
<?php echo icon('briefcase'); ?>
<h3>ยังไม่มีข้อมูลการฝึกงาน</h3>
<p>เพิ่มข้อมูลการฝึกงานรายการแรกเพื่อเริ่มติดตามความคืบหน้า</p>
<a href="internship_form.php" class="btn btn-primary">เพิ่มข้อมูลการฝึกงาน</a>
</div>
<?php endif; ?>
<?php include("includes/footer.php"); ?>