//แสดงข้อมูลแจ้งเตือน } if ($c > 0) { SetAlert('กรุณาใส่ปัญหา'); //แสดงข้อมูลแจ้งเตือน } } else { //ถ้าว่างทำส่วนนี้ คือ เพิม่ลงฐานข้อมูล $data = array("first_name" => $_POST['first_name'], "last_name" => $_POST['last_name'], "staff_id" => $_SESSION['user_id'], "tel" => $_POST['tel'], "created_at" => DATE_TIME, "updated_at" => DATE_TIME); // insert ข้อมูลลงในตาราง tb_repair โดยฃื่อฟิลด์ และค่าตามตัวแปร array ชื่อ $data if (insert("tb_repair", $data)) { // บันทึกข้อมูลลงตาราง tb_repair if ($_POST['media_id'] != '') { //ถ้ามีรหัสคอมพิวเตอร์ $arrIDMedia = explode(',', $_POST['media_id']); $repair_id = getDataDescLastID("id", 'tb_repair'); foreach ($arrIDMedia as $key => $value) { $data = array("repair_id" => $repair_id, "computer_id" => $value, "status" => '', "problem_description" => $_POST['problem_description'][$key], "created_at" => DATE_TIME, "updated_at" => DATE_TIME, "date_input" => DATE_TIME); insert("tb_repair_list", $data); } } SetAlert('เพิ่ม แก้ไข ข้อมูลสำเร็จ', 'success'); //แสดงข้อมูลแจ้งเตือนถ้าสำเร็จ header('location:' . ADDRESS . 'repair'); die; } } } //ลบคอมพิวเตอร์ if ($_POST['media_id'] != '') { $all_id = '';
<?php if ($_POST['btn_submit'] == 'บันทึกข้อมูล') { //เช็คว่ามีการกดปุ่ม บันทึกข้อมูล if ($_POST['media_id'] == '') { SetAlert('กรุณาเลือกสื่อที่ต้องการจอง'); //แสดงข้อมูลแจ้งเตือน } else { //ถ้าว่างทำส่วนนี้ คือ เพิม่ลงฐานข้อมูล $data = array("people_id" => $_POST['id'], "id_card" => $_POST['id_card'], "booking_date" => DATE, "status" => 'จองอยู่', "comment" => $_POST['comment'], "created_at" => DATE_TIME, "updated_at" => DATE_TIME); // insert ข้อมูลลงในตาราง tb_booking โดยฃื่อฟิลด์ และค่าตามตัวแปร array ชื่อ $data if (insert("tb_booking", $data)) { // บันทึกข้อมูลลงตาราง tb_booking if ($_POST['media_id'] != '') { //ถ้ามีรหัสสื่อ $arrIDMedia = explode(',', $_POST['media_id']); $booking_id = getDataDescLastID("id", 'tb_booking'); foreach ($arrIDMedia as $value) { $data = array("booking_id" => $booking_id, "media_id" => $value, "status" => 'จองอยู่'); insert("tb_booking_list", $data); } } SetAlert('เพิ่ม แก้ไข ข้อมูลสำเร็จ', 'success'); //แสดงข้อมูลแจ้งเตือนถ้าสำเร็จ header('location:' . ADDRESS . 'booking'); die; } } } //ลบสื่อ if ($_POST['media_id'] != '') { $all_id = '';
$rootPath = $_SERVER['DOCUMENT_ROOT']; $thisPath = dirname($_SERVER['PHP_SELF']); $onlyPath = str_replace($rootPath, '', $thisPath); $targetPath = $rootPath . '/' . $onlyPath . '/dist/images/media/'; $ext = explode('.', $_FILES['file_array']['name'][$i]); $extension = $ext[count($ext) - 1]; $rand = mt_rand(1, 100000); $newImage = DATE_TIME_FILE . $rand . "." . $extension; $cdir = getcwd(); // Save the current directory chdir($targetPath); move_uploaded_file($_FILES['file_array']['tmp_name'][$i], $targetPath . $newImage); chdir($cdir); // Restore the old working directory $data = array("image" => $newImage); if (update('tb_computer', $data, 'id = ' . getDataDescLastID('id', 'tb_computer'))) { SetAlert('เพิ่ม แก้ไข ข้อมูลสำเร็จ', 'success'); //แสดงข้อมูลแจ้งเตือนถ้าสำเร็จ header('location:' . ADDRESS . 'computer'); die; } } } } SetAlert('เพิ่ม แก้ไข ข้อมูลสำเร็จ', 'success'); //แสดงข้อมูลแจ้งเตือนถ้าสำเร็จ header('location:' . ADDRESS . 'computer'); die; } // แสดงการแจ้งเตือน Alert(GetAlert('error'));
$rootPath = $_SERVER['DOCUMENT_ROOT']; $thisPath = dirname($_SERVER['PHP_SELF']); $onlyPath = str_replace($rootPath, '', $thisPath); $targetPath = $rootPath . '/' . $onlyPath . '/dist/images/media/'; $ext = explode('.', $_FILES['file_array']['name'][$i]); $extension = $ext[count($ext) - 1]; $rand = mt_rand(1, 100000); $newImage = DATE_TIME_FILE . $rand . "." . $extension; $cdir = getcwd(); // Save the current directory chdir($targetPath); move_uploaded_file($_FILES['file_array']['tmp_name'][$i], $targetPath . $newImage); chdir($cdir); // Restore the old working directory $data = array("image" => $newImage); if (update('tb_media', $data, 'id = ' . getDataDescLastID('id', 'tb_media'))) { SetAlert('เพิ่ม แก้ไข ข้อมูลสำเร็จ', 'success'); //แสดงข้อมูลแจ้งเตือนถ้าสำเร็จ header('location:' . ADDRESS . 'media'); die; } } } } SetAlert('เพิ่ม แก้ไข ข้อมูลสำเร็จ', 'success'); //แสดงข้อมูลแจ้งเตือนถ้าสำเร็จ header('location:' . ADDRESS . 'media'); die; } // แสดงการแจ้งเตือน Alert(GetAlert('error'));
// เพิม่ลงฐานข้อมูล $booking_id = $_POST['id_booking'] != '' ? $_POST['id_booking'] : 0; $data = array("booking_id" => $booking_id, "people_id" => $_POST['id'], "id_card" => $_POST['id_card'], "borrow_date" => DATE, "comment" => $_POST['comment'], "created_at" => DATE_TIME, "updated_at" => DATE_TIME, "staff_id" => $_SESSION['user_id']); // insert ข้อมูลลงในตาราง tb_borrow โดยฃื่อฟิลด์ และค่าตามตัวแปร array ชื่อ $data if (insert("tb_borrow", $data)) { // บันทึกข้อมูลลงตาราง tb_borrow if ($_POST['media_id'] != '') { //ถ้ามีรหัสสื่อ $arrIDMedia = explode(',', $_POST['media_id']); $borrow_id = getDataDescLastID("id", 'tb_borrow'); foreach ($arrIDMedia as $value) { $data = array("borrow_id" => $borrow_id, "media_id" => $value, "borrow_date" => DATE); insert("tb_borrow_list", $data); } } if (getDataDescLastID('booking_id', 'tb_borrow') > 0) { $dataUpdate = array("status" => 'มายืมแล้ว'); update('tb_booking', $dataUpdate, 'id=' . $_POST['id_booking']); //เมื่อทำการยืมแล้วให้ลบข้อมูลที่เคยจองไว้ด้วย update('tb_booking_list', $dataUpdate, 'booking_id=' . $_POST['id_booking']); //เมื่อทำการยืมแล้วให้ลบข้อมูลที่เคยจองไว้ด้วย } SetAlert('เพิ่ม แก้ไข ข้อมูลสำเร็จ', 'success'); //แสดงข้อมูลแจ้งเตือนถ้าสำเร็จ header('location:' . ADDRESS . 'borrow_add'); die; } } } //ลบสื่อ if ($_POST['media_id'] != '') {
// insert ข้อมูลลงในตาราง tb_repair โดยฃื่อฟิลด์ และค่าตามตัวแปร array ชื่อ $data if (insert("tb_repair", $data)) { // บันทึกข้อมูลลงตาราง tb_repair if ($_POST['media_id'] != '') { //ถ้ามีรหัสคอมพิวเตอร์ $arrIDMedia = explode(',', $_POST['media_id']); $repair_id = getDataDescLastID("id", 'tb_repair'); foreach ($arrIDMedia as $key => $value) { $data = array("repair_id" => $repair_id, "computer_id" => $value, "status" => '', "problem_description" => $_POST['problem_description'][$key], "created_at" => DATE_TIME, "updated_at" => DATE_TIME, "date_input" => DATE_TIME); insert("tb_repair_list", $data); // อัพเดรต status คอมพิวเตอร์หากมีการแจ้งปัญหา $dataStatusCpt = array("status" => 'ส่งซ่อม', "updated_at" => DATE_TIME); update("tb_computer", $dataStatusCpt, 'id = ' . $value); } } SetAlert('เพิ่ม แก้ไข ข้อมูลสำเร็จ <br><br> <b>รหัสการแจ้งซ่อม : ' . getDataDescLastID('id', 'tb_repair') . '<br> วันที่แจ้งซ่อม : ' . ShowDate(getDataDescLastID('created_at', 'tb_repair')) . '</b>', 'success'); //แสดงข้อมูลแจ้งเตือนถ้าสำเร็จ header('location:' . ADDRESS . 'repair_add_user'); die; } } } //ลบคอมพิวเตอร์ if ($_POST['media_id'] != '') { $all_id = ''; $arrr = explode(',', $_POST['media_id']); foreach ($arrr as $v) { if ($_POST['delete_id'] != $v) { $all_id .= ',' . $v; } }