-
Notifications
You must be signed in to change notification settings - Fork 1
/
home_action.php
159 lines (134 loc) · 5.17 KB
/
home_action.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
require 'db_connect.php';
$save_message_other = "";
$save_message_bday = "";
$save_message_anni = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require 'db_connect.php';
$event_type = $_POST['event_type'];
$save_message_other = "";
$save_message_bday = "";
$save_message_anni = "";
if ($event_type == 'other_event') {
$e_name = $_POST['event_name'];
$event_type = $_POST['event_type'];
$e_date = $_POST['event_date'];
$e_msg = $_POST['event_msg'];
$e_is_edited = $_POST['is_event_edited'];
$edited_event_id = NULL;
if ($e_is_edited == 'true') {
$edited_event_id = $_POST['edited_event_id'];
}
if (strlen($e_name) > 0 && strlen($e_msg) > 0) {
$e_date = date("Y-m-d", strtotime($e_date));
if ($conn) {
$e_name = quote_smart($e_name, $conn);
$e_date = quote_smart($e_date, $conn);
$e_msg = quote_smart($e_msg, $conn);
if ($e_is_edited == 'true') {
$SQL = "UPDATE scheduled_events set e_date=" . $e_date . ",e_name=" . $e_name . ",e_message=" . $e_msg . " WHERE e_id='" . $edited_event_id . "'";
}
else {
$SQL = "INSERT INTO scheduled_events (e_name, e_message, e_date) VALUES (" . $e_name . "," . $e_msg . "," . $e_date . ")";
}
$result = mysqli_query($conn, $SQL);
$save_message_other = get_save_message($result);
mysqli_close($conn);
}
} else {
$save_message_other = "Event name or message can not be empty.";
}
$response_array['status'] = 'success';
echo $save_message_other;
} else if ($event_type == 'birthday') {
$e_msg = $_POST['event_msg'];
if (strlen($e_msg) > 0) {
if ($conn) {
$e_msg = quote_smart($e_msg, $conn);
$SQL = "SELECT * FROM fixed_events WHERE e_name='birthday'";
$result = mysqli_query($conn, $SQL);
if (mysqli_num_rows($result) > 0) {
$SQL = "UPDATE fixed_events SET e_message = " . $e_msg . " WHERE e_name='birthday'";
$result = mysqli_query($conn, $SQL);
$save_message_bday = get_save_message($result);
} else {
$SQL = "INSERT INTO fixed_events (e_name, e_message) VALUES ('birthday'," . $e_msg . ")";
$result = mysqli_query($conn, $SQL);
$save_message_bday = get_save_message($result);
}
}
} else {
$save_message_bday = "Event message can not be empty.";
}
echo $save_message_bday;
} else if ($event_type == 'anniversary') {
$e_msg = $_POST['event_msg'];
if (strlen($e_msg) > 0) {
if ($conn) {
$e_msg = quote_smart($e_msg, $conn);
$SQL = "SELECT * FROM fixed_events WHERE e_name='anniversary'";
$result = mysqli_query($conn, $SQL);
if (mysqli_num_rows($result) > 0) {
$SQL = "UPDATE fixed_events SET e_message = " . $e_msg . " WHERE e_name='anniversary'";
$result = mysqli_query($conn, $SQL);
$save_message_anni = get_save_message($result);
} else {
$SQL = "INSERT INTO fixed_events (e_name, e_message) VALUES ('anniversary'," . $e_msg . ")";
$result = mysqli_query($conn, $SQL);
$save_message_anni = get_save_message($result);
}
}
} else {
$save_message_anni = "Event message can not be empty.";
}
echo $save_message_anni;
}
}
function get_save_message($result) {
if ($result == 'true') {
return 'Event saved successfully.';
} else {
return 'Error while saving the event.';
}
}
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$event_type = $_GET['event_type'];
if ($event_type == 'birthday') {
echo get_bday_message($conn);
} else if ($event_type == 'anniversary') {
echo get_anni_message($conn);
}
}
function get_bday_message($conn) {
if ($conn) {
$SQL = "SELECT e_message FROM fixed_events WHERE e_name='birthday'";
$result = mysqli_query($conn, $SQL);
$rows = mysqli_fetch_all($result, MYSQLI_NUM);
if (mysqli_num_rows($result) > 0) {
return $rows[0][0];
} else {
return "";
}
}
}
function get_anni_message($conn) {
$SQL = "SELECT e_message FROM fixed_events WHERE e_name='anniversary'";
$result = mysqli_query($conn, $SQL);
$rows = mysqli_fetch_all($result, MYSQLI_NUM);
if (mysqli_num_rows($result) > 0) {
return $rows[0][0];
} else {
return "";
}
}
//Removing escape chars to insert into db
function quote_smart($value, $conn) {
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
if (!is_numeric($value)) {
$value = "'" . mysqli_real_escape_string($conn, $value) . "'";
}
return $value;
}
?>