forked from mitchgre/gregsList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutler.php
executable file
·290 lines (248 loc) · 9.05 KB
/
butler.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/*
This file acts as a middle manager between the browser (javascript) and gregsList's php members:
engineer.php contains utility functions
concierge.php contains guest tracking functions
accountant.php contains functions to add/remove data from the database
"Life is the art of drawing sufficient conclusions from insufficient premises."
-- Samuel Butler
*/
//require "./credentials.php";
require "./engineer.php"; // utitlity functions
require "./concierge.php"; // guest registry functions
require "./accountant.php"; // guest record functions
/*
Clear everything with the concierge before proceeding.
*/
conciergeStatus();
function conciergeStatus()
{
$status = clearUser();
if ($status === "user cleared.")
{
$userId = getUserId($_POST["user"]);
parseInputs($userId);
}
else
echo $status;
}
/*
Interface with the accountant.php file
*/
function parseInputs($user)
{
if (isset($_POST['func']))
{
$func = $_POST['func'];
// getters ===============================
if ($func === "getGoals")
{
echo json_encode(getGoals($user));
}
if ($func === "getIndustries")
{
echo json_encode(getIndustries($user));
}
if ($func === "getLocations")
{
echo json_encode(getLocations($user));
}
if ($func === "getPostings")
{
getPostings($user);
}
if ($func === "getContacts")
{
echo json_encode(getContacts($user));
}
if ($func === "getSchedules")
{
echo json_encode(getSchedules($user));
}
if ($func === "getCompanies")
{
echo getCompanies($user);
}
if ($func === "getBlogId")
{
echo json_encode(
getBlogId(
$user,
$_POST['title'],
$_POST['text']
));
}
if ($func === "getBlog")
{
echo json_encode(getBlog($user));
}
if ($func === "getNotesOnPosting")
{
$postingId = $_POST['postingId'];
echo json_encode(getNotesOnPosting($user,$postingId));
}
// inserters ===============================
if ($func === "insertGoal")
{
if ( isset($_POST["goal"]) && $_POST["goal"] !== '')
echo json_encode(insertGoal($user,$_POST["goal"]));
}
if ($func === "insertIndustry")
{
if ( isset($_POST["industry"]) && $_POST["industry"] !== '')
echo json_encode(insertIndustry($user,$_POST["industry"]));
}
if ($func === "insertCompany")
{
$url = urldecode($_POST["url"]);
$companyName = $_POST["company"];
insertCompany($user,$companyName);
}
if ($func === "insertLocation")
{
if ( isset($_POST["location"]) && $_POST["location"] !== '')
echo json_encode(insertLocation($user,$_POST["location"]));
}
if ($func === "insertPosting")
{
echo json_encode(insertPosting($user));
}
if ($func === "insertContact")
{
// more complex. will be responsible for getting $_POST
echo json_encode(insertContact($user));
}
if ($func === "insertSchedule")
{
// more complex. will be responsible for getting $_POST
// echo json_encode(insertSchedule($user));
echo insertSchedule($user);
}
if ($func === "addSchedule")
{
// more complex. will be responsible for getting $_POST
// echo json_encode(insertSchedule($user));
// echo "adding ZSchecdule";
$name = $_POST["name"];
$description = $_POST["description"];
$contact = $_POST["contact"];
$start = $_POST["start"];
$end = $_POST["end"];
// addSchedule($name,$description,$contact,$start,$end)
if (addSchedule($name,$description,$contact,$start,$end) )
{
$scheduleId = getScheduleId(
$name,
$description,$contact,
$start,$end);
if ( $scheduleId > 0 )
{
// echo $scheduleId;
// insert schedule id and user id to user_schedule
$query = "insert into user_schedule ";
$query .= "(user,schedule) ";
$query .= "values ( $user, ";
$query .= "$scheduleId ) ";
//return $query;
echo booleanEcho($query);
}
else
echo "error getting schedule id.";
}
else
echo "error inserting schedule.";
}
if ($func === "insertBlog")
{
echo json_encode(insertBlog($user));
}
if ($func === "insertNotesPostingUser")
{
// insertBlog, then insertNotesPostingUser
$noteId = insertBlog($user);
// $noteId = $_POST["noteId"];
$postingId = $_POST["postingId"];
echo json_encode(
insertNotesPostingUser($noteId,$postingId,$user));
}
// removers ===============================
if ($func === "removeGoal")
{
// url is the id for user_goals
if ( isset($_POST["url"]) && $_POST["url"] !== '')
echo json_encode(removeGoal($user,$_POST["url"]));
}
if ($func === "removeIndustry")
{
// url is the id for user_industries
if ( isset($_POST["url"]) && $_POST["url"] !== '')
echo json_encode(removeIndustry($user,$_POST["url"]));
}
if ($func === "removeLocation")
{
// url is the id for locations
if ( isset($_POST["url"]) && $_POST["url"] !== '')
echo json_encode(removeLocation($user,$_POST["url"]));
}
if ($func === "removeContact")
{
// url is the id for user_contacts
if ( isset($_POST["url"]) && $_POST["url"] !== '')
echo json_encode(removeUserContact($user,$_POST["url"]));
}
if ($func === "removePosting")
{
if ( isset($_POST["url"]) && $_POST["url"] !== '')
removePosting($user,$_POST["url"]);
}
if ($func === "removeCompany")
{
$companyId = $_POST["url"]; // companyID is stored here
removeCompany($user,$companyId);
}
if ($func === "removeSchedule")
{
$scheduleId = $_POST["url"]; // scheduleID is stored here
echo json_encode(removeSchedule($user,$scheduleId));
}
if ($func === "removeBlog")
{
$userNoteId = $_POST["url"];
// need to get noteId from userNoteId
$noteId = getNoteIdFromUserNoteId($userNoteId);
if ( removeNoteUser($user,$userNoteId) === true )
{
if ( removeNote( $noteId ) === true )
{
echo json_encode(true);
}
else
{
echo json_encode("Error removing from notes.");
}
}
else
{
echo json_encode("Error removing from NoteUser.");
}
}
// updaters ===============================
if ($func === "updateGoal")
{
echo json_encode(updateGoal($user));
}
if ($func === "updateIndustry")
{
echo json_encode(updateIndustry($user));
}
if ($func === "updatePosting")
{
updatePosting($user); // returns on its own
}
if ($func === "updateContact")
{
echo json_encode(updateContact($user));
}
}
}
?>