-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
151 lines (128 loc) · 4.69 KB
/
index.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
<?php
include_once('secrets.inc.php');
include_once('config.inc.php');
include_once('functions.inc.php');
include_once('debug.inc.php');
include_once('database.inc.php');
$user_id = $_POST['user_id'];
$user_name = $_POST['user_name'];
$text = $_POST['text'];
if (!preg_match('/^(create|list|attend|status|modify|help)/i', $text, $matches)) {
echo "Unknown command, try again suckahr!";
exit;
}
$command = strtolower($matches[1]);
switch ($command) {
case 'create':
$event_owner = $user_name;
if (preg_match('/^create ([\d\w]+) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2}) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2}) (.*)$/i', $text, $matches)) {
$event_name = $matches[1];
$event_time = $matches[2];
$event_rvsp_time = $matches[3];
$event_note = $matches[4];
} else if (preg_match('/^create ([\d\w]+) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2}) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2})$/i', $text, $matches)) {
$event_name = $matches[1];
$event_time = $matches[2];
$event_rvsp_time = $matches[3];
} else if (preg_match('/^create ([\d\w]+) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2})$/i', $text, $matches)) {
$event_name = $matches[1];
$event_time = $matches[2];
$event_rvsp_time = NULL;
} else {
echo "error";
}
$now = time();
$event_ts = datetime_to_unix($event_time);
if ($now > $event_ts) {
echo "You cannot create an event in the past - dumbass!";
exit;
}
if ($event_rvsp_time) {
$event_rvsp_ts = datetime_to_unix($event_rvsp_time);
if ($now > $event_rvsp_ts) {
echo "You cannot create an event with rvsp in the past - stupid!";
exit;
}
if ($event_ts < $event_rvsp_ts) {
echo "You cannot create an event with rvsp after the event - you son of a biaaaach!";
exit;
}
}
if (!dbCreateEvent($db, $event_name, $event_owner, $event_ts, $event_rvsp_ts, $event_note)) {
echo "Error creating event!";
exit;
} else {
echo 'Congratulations! You have just created an event (' . $event_name . ') on ' . my_date($event_ts);
echo "\n";
}
break;
case 'list':
dbListEvents($db);
break;
case 'help':
echo '*List of commands*:' . "\n\n";
echo '*' . $_POST['command'] . ' help* - this view' . "\n\n";
echo '*' . $_POST['command'] . ' create NameOfEvent YYYY-MM-DD HH:mm [YYYY-MM-DD HH:mm]* - create an event (RSVP optional)' . "\n\n";
echo '*' . $_POST['command'] . ' attend NameOfEvent [NumberOfAttendees [Text]]* - attend an event (number of attendees and text are optional)' . "\n\n";
echo '*' . $_POST['command'] . ' list* - list all open events' . "\n\n";
echo '*' . $_POST['command'] . ' status NameOfEvent* - show status for an event' . "\n\n";
break;
case 'attend':
$attendee_name = NULL;
$event_name = NULL;
$attendee_number = NULL;
$attendee_text = NULL;
if (preg_match('/^attend ([\w\d]+) ([\d]+) (.*)$/', $text, $matches)) {
$attendee_name = $user_name;
$event_name = $matches[1];
$attendee_number = $matches[2];
$attendee_text = $matches[3];
} else if (preg_match('/^attend ([\w\d]+) ([\d]+)$/', $text, $matches)) {
$attendee_name = $user_name;
$event_name = $matches[1];
$attendee_number = $matches[2];
} else if (preg_match('/^attend ([\w\d]+)$/', $text, $matches)) {
$attendee_name = $user_name;
$event_name = $matches[1];
} else {
echo "Fuckoff shit brain!";
exit;
}
if (dbAttendEvent($db, $event_name, $attendee_name, $attendee_number, $attendee_text)) {
echo "success";
} else {
echo "failure";
}
break;
case 'status':
if (preg_match('/^status ([\w\d]+)$/', $text, $matches)) {
dbEventStatus($db, $matches[1]);
} else {
echo "Prick!";
}
break;
case 'modify':
$event_owner = $user_name;
$event_name = NULL;
$event_time = NULL;
$event_rsvp_time = NULL;
$event_note = NULL;
if (preg_match('/^modify ([\d\w]+) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2}) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2}) (.*)$/i', $text, $matches)) {
$event_name = $matches[1];
$event_time = $matches[2];
$event_rsvp_time = $matches[3];
$event_note = $matches[4];
} else if (preg_match('/^create ([\d\w]+) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2}) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2})$/i', $text, $matches)) {
$event_name = $matches[1];
$event_time = $matches[2];
$event_rsvp_time = $matches[3];
} else if (preg_match('/^create ([\d\w]+) ([\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2})$/i', $text, $matches)) {
$event_name = $matches[1];
$event_time = $matches[2];
} else {
echo "Nothing to change!";
}
dbModifyEvent($db, $event_name, $event_owner, datetime_to_unix($event_time), datetime_to_unix($event_rsvp_time), $event_note);
break;
}
// /feedme create CCC 2015-12-17 19:00 2015-12-16 16:00