This repository has been archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scr_report.php
124 lines (124 loc) · 5.87 KB
/
scr_report.php
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
<?php
require("scr_sql.php");
require("scr_file.php");
$message = "คุณไม่ได้รับอนุญาตให้ใช้งานส่วนนี้!";
$query_error = "เตรียม Query ผิดพลาด โปรดลองใหม่อีกครั้ง หรือติดต่อผู้ดูแลระบบ";
$next_page = "scr_auth.php";
session_start();
if(isset($_SESSION['mode'])){
//user
if($_SESSION['mode']===1){
$next_page = "room_report_list.php";
//add new report
if(isset($_GET['add'])){
if(isset($_POST['room']) && isset($_POST['detail']) && isset($_FILES['photo'])){
if(!empty($_POST['room'])){
//determine date + random number
$this_date = date("YmdHis"); for($i=0;$i<10;$i++){ $this_date.=rand(0,9); }
//determine file
$this_file = "/report_photos/".$this_date;
//file upload
$this_upload = file_upload($_FILES["photo"],$this_file);
switch($this_upload){
//success
default:
//add data
$query = mysqli_prepare($sql,"INSERT INTO tb_report VALUES(?,?,?,?,?)");
if(!$query){
//query prepare error
$message = $query_error;
}
else{
//query
$false = 0;
mysqli_stmt_bind_param($query, 'sssss', $this_date, $_POST['room'], $_POST['detail'], $this_upload, $false);
if(mysqli_stmt_execute($query)){
$message = "เพิ่มข้อมูลเรียบร้อยแล้ว";
}
else{
$message = $query_error;
}
}
break;
//photo does not exist
case "2":
case "5":
$message = "กรุณาอัปโหลดไฟล์รูปภาพ";
break;
//photo name conflict
case "3":
$message = "มีผู้ทำรายการอื่นกำลังดำเนินการอยู่ โปรดลองอีกครั้ง";
break;
//photo too big
case "4":
$message = "ไฟล์ภาพใหญ่เกินไป";
//unexpected error
case "1":
$message = "อัปโหลดผิดพลาด โปรดตรวจสอบการเชื่อมต่อ หรือแจ้งผู้ดูแลระบบ";
break;
}
}
else{
$message = "กรุณาระบุหมายเลขห้อง";
}
}
else{
$message = "ข้อมูลไม่ถูกต้อง";
}
}
//fixed
else if(isset($_GET['fix'])){
if(isset($_GET['date'])){
$query = mysqli_prepare($sql,"DELETE FROM tb_report WHERE report_date=?");
if(!$query){
//query prepare error
$message = $query_error;
}
else{
//query
$false = 0;
mysqli_stmt_bind_param($query, 's',$_GET['date']);
if(mysqli_stmt_execute($query)){
$message = "ลบข้อมูลเรียบร้อยแล้ว";
}
else{
$message = $query_error;
}
}
}
else{
$message = "พารามิเตอร์ไม่ถูกต้อง";
}
}
else{
$message = "คำสั่งไม่ถูกต้อง";
}
}
//admin
else if($_SESSION['mode']===2){
$next_page = "report_list.php";
//fixed
if(isset($_GET['fix'])){
$query = mysqli_prepare($sql,"UPDATE tb_report SET report_fix=1 WHERE report_date=?");
if(!$query){
//query prepare error
$message = $query_error;
}
else{
//query
mysqli_stmt_bind_param($query, 's',$_GET['date']);
if(mysqli_stmt_execute($query)){
$message = "อัปเดตข้อมูลเรียบร้อยแล้ว";
}
else{
$message = $query_error;
}
}
}
else{
$message = "คำสั่งไม่ถูกต้อง";
}
}
}
echo "<script>alert('".$message."');window.open('".$next_page."','_self');</script>";
?>