This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
263 lines (215 loc) · 7.44 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
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
<?php
session_start();
date_default_timezone_set('America/Chicago');
////////////////
//Base URL editing
////////////////
#removes extra slashes
$url = preg_replace('/(\/+)/', '/', $_SERVER['REQUEST_URI']);
#gets base directory
$base_dir = str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['PHP_SELF']));
#remove the directory path we don't want
$request = str_replace($base_dir . "/", "", $url);
#split the path by '/'
$params = explode("/", $request);
////////////////
//Testing purposes
////////////////
#comment if pages aren't changing headers
//print_r($params);
//shows all errors
//require_once('errors.php');
////////////////
//primary pages
////////////////
$login = "login";
$logout = "logout";
$dashboard = "dashboard";
$orders = "orders";
$transactions = "transactions";
$settings = "settings";
$accounts = "accounts";
#keeps users from requesting any file they want
$primary_pages = array(
$login,
$logout,
$dashboard,
$orders,
$transactions,
$settings,
$accounts
);
//connection to database
require('core/connection.php');
require_once('functions/backend-functions.php');
////////////////
//URL forwarding
////////////////
#makes sure page accessing is within primary pages array
if (in_array($params[0], $primary_pages)) {
#Login page
if ($params[0] == $login) {
//if user is logged in already, send to DASHBOARD TODO
if (isset($_SESSION['logged_user'])) {
//should change to dashboard when ready
header("location: " . $base_dir . "/orders/all");
}
//only includes if user is submitting login details
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
require_once('scripts/login-scripts.php');
}
require_once('functions/login-functions.php');
require_once('views/login.php');
exit();
}
//Require session for logged in users
require_once('php/session.php');
#Logout page
if ($params[0] == $logout) {
include_once('scripts/logout-scripts.php');
exit();
}
#Dashboard page
if ($params[0] == $dashboard) {
include_once('core/header.php');
include_once('views/dashboard.php');
include_once('core/footer.php');
exit();
}
////////////////
//orders history get actions
////////////////
$all = 'all';
$client = 'client';
$retail = 'retail';
$add = 'add';
$view = 'view';
$edit = 'edit';
$delete = 'delete';
$orders_history = array(
$all,
$client,
$retail
);
$orders_functions = array(
$add,
$view,
$edit,
$delete
);
if ($params[0] == $orders) {
//checks if in order_history array
if (in_array($params[1], $orders_history)) {
//gets order type (client, retail, all) from given parameters
$getOrderType = $params[1];
include_once('scripts/orders-scripts.php');
include_once('functions/orders-functions.php');
include_once(getHeaderPath());
include_once('orders.php');
include_once(getFooterPath());
} else if (in_array($params[1], $orders_functions)) {
if ($params[1] == $add) {
if (isPostRequest()) {
include_once('scripts/add-order-scripts.php');
}
include_once(getHeaderPath());
include_once('views/add-order.php');
include_once(getFooterPath());
} else if ($params[1] == $view) {
include_once('scripts/view-order-scripts.php');
//checks to see if order is found
if ($result->num_rows == 0) {
$_SESSION['order_not_found'] = true;
header('Location: '. $base_dir .'/orders/all');
}
include_once(getHeaderPath());
include_once('views/view-order.php');
include_once('modals/orders-modal.php');
include_once(getFooterPath());
} else if ($params[1] == $edit && $params[2]) {
include_once('scripts/edit-order-scripts.php');
//checks to see if order is found
if ($result->num_rows == 0) {
$_SESSION['order_not_found'] = true;
header('Location: '. $base_dir .'/orders/all');
}
include_once(getHeaderPath());
include_once('views/edit-order.php');
include_once('modals/orders-modal.php');
include_once(getFooterPath());
} else if ($params[1] == $delete) {
if (!isPostRequest()) {
include_once('scripts/delete-order-scripts.php');
}
}
} else {
header("location: " . $base_dir . "/orders/all");
}
exit;
}
#Settings page
if ($params[0] == $settings) {
//check if in array
if ($params[1] == "general") {
if (isPostRequest()) {
include_once('scripts/settings-general-scripts.php');
}
include_once('functions/settings/general-functions.php');
include_once(getHeaderPath());
include_once('views/settings/settings-general.php');
include_once(getFooterPath());
} else if ($params[1] == "password") {
if (isPostRequest()) {
include_once('scripts/settings/password-scripts.php');
exit;
}
include_once('functions/settings/password-functions.php');
include_once(getHeaderPath());
include_once('views/settings/settings-password.php');
include_once(getFooterPath());
} else if ($params[1] == "users") {
if ($params[2] == "create") {
include_once('scripts/settings/users-create-scripts.php');
exit;
}
if ($params[2] == "edit") {
include_once('scripts/settings/users-edit-scripts.php');
exit;
}
if ($params[2] == "delete") {
include_once('scripts/settings/users-delete-scripts.php');
exit;
}
if ($params[2] == "get") {
include_once('scripts/settings/users-get-scripts.php');
exit;
}
include_once('functions/settings/users-functions.php');
include_once('scripts/settings-users-scripts.php');
include_once(getHeaderPath());
include_once('views/settings/settings-users.php');
include_once('modals/users-modal.php');
include_once(getFooterPath());
} else if ($params[1] == "advanced") {
if (isPostRequest()) {
// include_once('scripts/settings/password-scripts.php');
exit;
}
// include_once('functions/settings/password-functions.php');
include_once(getHeaderPath());
include_once('views/settings/settings-advanced.php');
include_once(getFooterPath());
}
exit;
}
} else if (!$params[0]) {
if (isset($_SESSION['logged_user'])) {
//should change to dashboard when ready
header("location: " . $base_dir . "/orders/all");
}
require_once('functions/login-functions.php');
require_once('views/login.php');
} else {
print_r($params);
include("404.php");
}