forked from rpiambulance/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.add_game.php
106 lines (84 loc) · 2.85 KB
/
.add_game.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
<?php
require_once ".db_config.php";
require_once ".gcal.php";
// empty response
$response = null;
//array to hold errors
$errors = array();
// Google Calendar Object
$googleCalendar = new GoogleCalendar();
// array to pass back data
$data = array();
// Get the input ===============================================================
$formData = file_get_contents('php://input');
$input = json_decode($formData, true);
$event_name = $input['event_name'];
$event_location = $input['event_location'];
$start_time = $input['startstamp'];
$end_time = $input['endstamp'];
$date = $input['datestamp'];
$type = $input['type'];
$ees = 0;
$mode = $input['mode'];
if($mode == 'edit') {
$id = $input['id'];
}
if ($type == '3') {
$ees = 0;
}
else{
$ees = 1;
}
try {
$connection = new PDO("mysql:host=$dhost;dbname=$dname", $duser, $dpassword);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!isset($dname)) {
$dname = 'ambulanc_web';
}
// Selecting Database
$connection->exec("USE `$dname`");
if($mode == 'add') {
$statement = $connection->query("SELECT MAX(id) as max FROM games");
$logid = $statement->fetchAll(PDO::FETCH_ASSOC)[0]['max'] + 1;
$statement = $connection->prepare("INSERT INTO games(id, `date`, start, `end`, description, location, ees, hide) VALUES (:logid, :date, :start_time, :end_time, :event_name, :event_location, :ees, 0)");
$statement->bindParam(":logid", $logid);
$statement->bindParam(":date", $date);
$statement->bindParam(":start_time", $start_time);
$statement->bindParam(":end_time", $end_time);
$statement->bindParam(":event_name", $event_name);
$statement->bindParam(":event_location", $event_location);
$statement->bindParam(":ees", $ees);
$result = $statement->execute();
} else if ($mode == "edit") {
$statement = $connection->prepare("UPDATE games SET
`date`=:date,
`start`=:start_time,
`end`=:end_time,
`description`=:event_name,
`location`=:event_location,
`hide`=0
WHERE id=:id");
$statement->bindParam(":id", $id);
$statement->bindParam(":date", $date);
$statement->bindParam(":start_time", $start_time);
$statement->bindParam(":end_time", $end_time);
$statement->bindParam(":event_name", $event_name);
$statement->bindParam(":event_location", $event_location);
$result = $statement->execute();
}
if($result) {
$data['success'] = true;
if ($mode == 'add') {
$googleCalendar->createEvent($event_name, $date . 'T' . $start_time, $date . 'T' . $end_time, $event_location, $logid, true);
} else {
$googleCalendar->updateEvent($event_name, $date . 'T' . $start_time, $date . 'T' . $end_time, $event_location, $id, true);
}
} else {
$data['success'] = false;
}
} catch(PDOException $e) {
$data['success'] = false;
$data['error'] = $e;
}
echo(json_encode($data));
?>