Initial import
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
$page_title = 'เพิ่มนักศึกษา';
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
require_once __DIR__ . '/../includes/header.php';
|
||||
|
||||
$curricula = getCurricula();
|
||||
$faculties = getFacultyList();
|
||||
$message = '';
|
||||
$error = '';
|
||||
$advisor_curriculum_id = isAdvisor() ? getCurrentUserCurriculumId() : null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$student_code = trim($_POST['student_code'] ?? '');
|
||||
$name_th = trim($_POST['name_th'] ?? '');
|
||||
$name_en = trim($_POST['name_en'] ?? '');
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$curriculum_id = $advisor_curriculum_id ?: intval($_POST['curriculum_id'] ?? 0);
|
||||
$faculty = trim($_POST['faculty'] ?? '');
|
||||
$graduated_institution = trim($_POST['graduated_institution'] ?? '');
|
||||
$previous_qualification = trim($_POST['previous_qualification'] ?? '');
|
||||
$enrollment_year = intval($_POST['enrollment_year'] ?? date('Y'));
|
||||
|
||||
if (empty($student_code) || empty($name_th) || empty($curriculum_id)) {
|
||||
$error = 'กรุณากรอกข้อมูลให้ครบถ้วน (รหัสนักศึกษา, ชื่อ-นามสกุล, สาขาวิชา)';
|
||||
} else {
|
||||
try {
|
||||
$advisor_id = isAdvisor() ? getCurrentUserId() : null;
|
||||
$stmt = getDB()->prepare("INSERT INTO students (student_code, name_th, name_en, email, faculty, graduated_institution, curriculum_id, enrollment_year, advisor_id, previous_qualification) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$student_code, $name_th, $name_en, $email, $faculty, $graduated_institution, $curriculum_id, $enrollment_year, $advisor_id, $previous_qualification ?: null]);
|
||||
$message = 'เพิ่มนักศึกษาสำเร็จ';
|
||||
echo "<script>window.location.href='view.php?id=" . getDB()->lastInsertId() . "';</script>";
|
||||
exit;
|
||||
} catch (PDOException $e) {
|
||||
if ($e->getCode() == 23000) {
|
||||
$error = 'รหัสนักศึกษานี้มีอยู่ในระบบแล้ว';
|
||||
} else {
|
||||
$error = 'เกิดข้อผิดพลาด: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="card">
|
||||
<div class="card-header bg-success text-white">
|
||||
<h4 class="mb-0"><i class="bi bi-person-plus"></i> เพิ่มนักศึกษาใหม่</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-success"><?= htmlspecialchars($message) ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
|
||||
<?php endif; ?>
|
||||
<form method="POST" class="row g-3">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">รหัสนักศึกษา <span class="text-danger">*</span></label>
|
||||
<input type="text" name="student_code" class="form-control" required maxlength="20">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<label class="form-label">ชื่อ-นามสกุล (ภาษาไทย) <span class="text-danger">*</span></label>
|
||||
<input type="text" name="name_th" class="form-control" required>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">ชื่อ-นามสกุล (ภาษาอังกฤษ)</label>
|
||||
<input type="text" name="name_en" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">อีเมล</label>
|
||||
<input type="email" name="email" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">สาขาวิชา <span class="text-danger">*</span></label>
|
||||
<?php if ($advisor_curriculum_id): ?>
|
||||
<input type="text" class="form-control" value="<?php foreach($curricula as $c) { if ($c['id'] == $advisor_curriculum_id) { echo htmlspecialchars($c['code'] . ' - ' . $c['name_th']); break; } } ?>" disabled>
|
||||
<input type="hidden" name="curriculum_id" value="<?= $advisor_curriculum_id ?>">
|
||||
<?php else: ?>
|
||||
<select name="curriculum_id" class="form-select" required>
|
||||
<option value="">-- เลือกสาขาวิชา --</option>
|
||||
<?php foreach ($curricula as $c): ?>
|
||||
<option value="<?= $c['id'] ?>" data-faculty="<?= $c['code'] == 'DT' ? '12' : '12' ?>"><?= htmlspecialchars($c['code']) ?> - <?= htmlspecialchars($c['name_th']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">คณะ</label>
|
||||
<select name="faculty" class="form-select">
|
||||
<option value="">-- เลือกคณะ --</option>
|
||||
<option value="คณะนวัตกรรมดิจิทัลเทคโนโลยี">คณะนวัตกรรมดิจิทัลเทคโนโลยี (12)</option>
|
||||
<option value="คณะบริหารธุรกิจ">คณะบริหารธุรกิจ (11)</option>
|
||||
<option value="คณะศึกษาศาสตร์และศิลปศาสตร์">คณะศึกษาศาสตร์และศิลปศาสตร์ (13)</option>
|
||||
<option value="คณะบัญชี">คณะบัญชี (14)</option>
|
||||
<option value="คณะนิติศาสตร์และรัฐศาสตร์">คณะนิติศาสตร์และรัฐศาสตร์ (15)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">ชื่อสถาบันที่จบ</label>
|
||||
<input type="text" name="graduated_institution" class="form-control" placeholder="ชื่อสถานศึกษาเดิม">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">วุฒิเดิม</label>
|
||||
<select name="previous_qualification" class="form-select">
|
||||
<option value="">-- เลือกวุฒิเดิม --</option>
|
||||
<option value="ม.6 (กศน,สกร)">ม.6 (กศน,สกร)</option>
|
||||
<option value="ปวช.3">ปวช.3</option>
|
||||
<option value="ปวส.2">ปวส.2</option>
|
||||
<option value="ปริญญาตรีใบที่ 2">ปริญญาตรีใบที่ 2</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">ปีการศึกษาที่เข้าศึกษา</label>
|
||||
<input type="number" name="enrollment_year" class="form-control" value="<?= date('Y') + 543 ?>" min="2569" step="1">
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-success"><i class="bi bi-save"></i> บันทึก</button>
|
||||
<a href="list.php" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> กลับ</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php require_once __DIR__ . '/../includes/footer.php'; ?>
|
||||
Reference in New Issue
Block a user