-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetevents.php
More file actions
75 lines (68 loc) · 1.83 KB
/
getevents.php
File metadata and controls
75 lines (68 loc) · 1.83 KB
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
<?php
require 'database.php';
header("Content-Type: application/json");
// session cookie http only
ini_set("session.cookie_httponly", 1);
session_start();
$user_id = $_SESSION['user_id'];
$date = $_POST['date'];
$category = $_POST['category'];
// If category that was passed is * get all events and igonre category
if ($category == "*"){
$stmt = $mysqli->prepare("select title, description, date, time, event_id, category from events where events.user_id=? and date=?");
if(!$stmt){
echo json_encode(array(
"success" => false,
"message" => $mysqli->error,
));
exit;
}
$stmt->bind_param('is', $user_id, $date);
}
// If category was selected then only get results of certain category
else {
$stmt = $mysqli->prepare("select title, description, date, time, event_id, category from events where events.user_id=? and date=? and category=?");
if(!$stmt){
echo json_encode(array(
"success" => false,
"message" => $mysqli->error,
));
exit;
}
$stmt->bind_param('iss', $user_id, $date, $category);
}
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$data = array();
// Make an array of all the resulting events that will be included in the jsonData
// that is passed back
while($row = $result->fetch_assoc()){
array_push($data, array(
"title" => $row['title'],
"description" => $row['description'],
"date" => $row['date'],
"time" => $row['time'],
"event_id" => $row['event_id'],
"category" => $row['category']
));
}
echo json_encode(array(
"success" => true,
"exists" => true,
"events" => $data
// "title" => $row['title'],
// "description" => $row['description'],
// "date" => $row['date'],
// "time" => $row['time']
));
exit;
}
else {
echo json_encode(array(
"success" => true,
"exists" => false
));
}
$stmt->close();
?>