| Server IP : 104.21.80.248 / Your IP : 172.71.28.156 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Inetpub/www/pr/ |
Upload File : |
<?php
include 'functions.php';
check_login('user');
if(isset($_POST['save_meeting'])) {
$topic = mysqli_real_escape_string($conn, $_POST['topic']);
$room = mysqli_real_escape_string($conn, $_POST['room']);
$date_type = $_POST['date_type'];
// ตรวจสอบเงื่อนไขวันที่
if($date_type == 'single') {
$start_date = $_POST['single_date'];
$end_date = $_POST['single_date']; // วันเดียว ใช้เริ่มต้นและสิ้นสุดเป็นวันเดียวกัน
} else {
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
}
$user_id = $_SESSION['user_id'];
$created = date('Y-m-d H:i:s');
// บันทึกข้อมูลหลักลงตาราง meeting_requests
$sql = "INSERT INTO meeting_requests (user_id, topic, room, date_type, start_date, end_date, status, created_at)
VALUES ('$user_id', '$topic', '$room', '$date_type', '$start_date', '$end_date', 'pending', '$created')";
if(mysqli_query($conn, $sql)) {
$mreq_id = mysqli_insert_id($conn);
// อัปโหลดไฟล์ที่แนบมา (รองรับทุกไฟล์)
if(isset($_FILES['mfiles'])) {
$total_files = count($_FILES['mfiles']['name']);
for($i=0; $i<$total_files; $i++) {
if($_FILES['mfiles']['name'][$i] != "") {
$original_name = $_FILES['mfiles']['name'][$i];
$ext = pathinfo($original_name, PATHINFO_EXTENSION);
// ระบบความปลอดภัยพื้นฐาน: แม้จะให้โหลดทุกไฟล์ แต่จะบล็อกไฟล์ .php และไฟล์รันระบบไม่ให้แฮ็กเกอร์รันคำสั่งได้
$blocked_exts = array('php', 'php3', 'php4', 'php5', 'phtml', 'exe', 'sh', 'js');
if(in_array(strtolower($ext), $blocked_exts)) {
$ext = $ext . "_safe";
}
$new_name = "MEET_" . time() . "_$i." . $ext;
if(!is_dir('uploads')) mkdir('uploads');
if(move_uploaded_file($_FILES['mfiles']['tmp_name'][$i], "uploads/" . $new_name)){
$original_name_escape = mysqli_real_escape_string($conn, $original_name);
$sql_file = "INSERT INTO meeting_files (mreq_id, filename, original_name)
VALUES ('$mreq_id', '$new_name', '$original_name_escape')";
mysqli_query($conn, $sql_file);
}
}
}
}
echo "<script>alert('บันทึกความต้องการขึ้นจอห้องประชุมเรียบร้อยแล้ว'); window.location='dashboard.php';</script>";
} else {
echo "<script>alert('เกิดข้อผิดพลาด: " . mysqli_error($conn) . "');</script>";
}
}
echo get_header("เพิ่มรูปภาพขึ้นจอห้องประชุม");
?>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card shadow-sm border-0 border-top border-primary border-4">
<div class="card-body p-4">
<h4 class="mb-4 text-primary"><i class="bi bi-projector"></i> แจ้งความต้องการขึ้นจอห้องประชุม</h4>
<form method="post" enctype="multipart/form-data">
<div class="mb-3">
<label class="form-label fw-bold">หัวข้อการประชุม <span class="text-danger">*</span></label>
<input type="text" name="topic" class="form-control" placeholder="เช่น การประชุมคณะกรรมการบริหาร..." required>
</div>
<div class="mb-3">
<label class="form-label fw-bold">ห้องประชุม <span class="text-danger">*</span></label>
<select name="room" class="form-select" required>
<option value="">-- กรุณาเลือกห้องประชุม --</option>
<option value="ห้องประชุมใหญ่">ห้องประชุมใหญ่</option>
<option value="ห้องประชุมกลาง">ห้องประชุมกลาง</option>
<option value="ห้องประชุมเล็ก">ห้องประชุมเล็ก</option>
</select>
</div>
<div class="mb-4">
<label class="form-label fw-bold">เลือกรูปหรือไฟล์ประชาสัมพันธ์ <span class="text-danger">*</span></label>
<input type="file" name="mfiles[]" class="form-control" multiple required>
<small class="text-muted"><i class="bi bi-info-circle"></i> สามารถเลือกได้หลายไฟล์ และรองรับไฟล์ทุกชนิด (เช่น .jpg, .png, .pdf, .docx, .mp4)</small>
</div>
<div class="card bg-light border-0 mb-4 p-3">
<label class="form-label fw-bold d-block mb-3">รูปแบบวันที่ต้องการแสดง <span class="text-danger">*</span></label>
<div class="mb-3">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="date_type" id="date_single" value="single" checked onchange="toggleDateUI('single')">
<label class="form-check-label" for="date_single">วันเดียว</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="date_type" id="date_multiple" value="multiple" onchange="toggleDateUI('multiple')">
<label class="form-check-label" for="date_multiple">หลายวัน</label>
</div>
</div>
<div class="mb-2" id="div_single">
<label class="form-label">เลือกวันที่ <span class="text-danger">*</span></label>
<input type="date" name="single_date" id="single_date" class="form-control" required>
</div>
<div class="row mb-2" id="div_multiple" style="display:none;">
<div class="col-md-6 mb-2">
<label class="form-label">วันที่เริ่มต้น <span class="text-danger">*</span></label>
<input type="date" name="start_date" id="start_date" class="form-control">
</div>
<div class="col-md-6 mb-2">
<label class="form-label">วันที่สิ้นสุด <span class="text-danger">*</span></label>
<input type="date" name="end_date" id="end_date" class="form-control">
</div>
</div>
</div>
<div class="d-grid gap-2">
<button type="submit" name="save_meeting" class="btn btn-primary btn-lg"><i class="bi bi-save"></i> บันทึกข้อมูล</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
// ฟังก์ชันสลับกล่องวันที่ (วันเดียว / หลายวัน)
function toggleDateUI(type) {
if(type === 'single') {
// แสดงวันเดียว ซ่อนหลายวัน
document.getElementById('div_single').style.display = 'block';
document.getElementById('div_multiple').style.display = 'none';
// สลับ Required เพื่อให้ฟอร์ม Validate ถูกต้อง
document.getElementById('single_date').required = true;
document.getElementById('start_date').required = false;
document.getElementById('end_date').required = false;
} else if(type === 'multiple') {
// แสดงหลายวัน ซ่อนวันเดียว
document.getElementById('div_single').style.display = 'none';
document.getElementById('div_multiple').style.display = 'flex';
// สลับ Required
document.getElementById('single_date').required = false;
document.getElementById('start_date').required = true;
document.getElementById('end_date').required = true;
}
}
</script>
<?php echo get_footer(); ?>