-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.php
78 lines (65 loc) · 2.64 KB
/
app.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
<?php
if(!session_id()) session_start();
define('APP_PATH', realpath(dirname(__FILE__)));
// load in the model class
require_once(APP_PATH.'/lib/php_orm/lib/model.php');
// load in the templating engine
require_once(APP_PATH.'/lib/php_template/lib/template.php');
// load in the controller class
require_once(APP_PATH.'/lib/controller.php');
// load in any helpers
require_once(APP_PATH.'/lib/helpers/crypt.php');
require_once(APP_PATH.'/lib/helpers/flash.php');
require_once(APP_PATH.'/lib/helpers/sessions.php');
// load in all of the models
require_once(APP_PATH.'/app/models/parkinglot.php');
require_once(APP_PATH.'/app/models/comment.php');
require_once(APP_PATH.'/app/models/user.php');
require_once(APP_PATH.'/app/models/role.php');
require_once(APP_PATH.'/app/models/parkingspace.php');
require_once(APP_PATH.'/app/models/announcement.php');
require_once(APP_PATH.'/app/models/associations.php');
require_once(APP_PATH.'/app/controllers/parkinglots.php');
require_once(APP_PATH.'/app/controllers/users.php');
require_once(APP_PATH.'/app/controllers/main.php');
require_once(APP_PATH.'/app/controllers/sessions.php');
require_once(APP_PATH.'/app/controllers/admin.php');
$db = new Database();
// credentials for mysql - this is the only place you need to change them
$db->setup("localhost", "root", "", "ParkingManagementSystem");
Model::setDB($db);
// what resource are they trying to reach?
$routes = array(
'GET:/index' => 'Main::index',
'GET:/signup' => 'Users::signup',
'POST:/signup' => 'Users::create',
'POST:/login' => 'Sessions::login',
'GET:/logout' => 'Sessions::logout',
'GET:/dashboard' => 'Users::dashboard',
'GET:/parkinglots' => 'ParkingLots::index',
'GET:/get_lots' => 'ParkingLots::get_lots',
'GET:/get_lot' => 'ParkingLots::get_lot',
'GET:/admin' => 'Admin::index',
'POST:/create_announcement' => 'ParkingLots::create_announcement',
'GET:/user_list' => 'Admin::user_list',
'GET:/reset_password' => 'Admin::reset_password',
'GET:/destroy_user' => 'Admin::destroy_user',
'GET:/make_admin' => 'Admin::make_admin',
'GET:/update_spot_state' => 'ParkingLots::update_spot_state',
'GET:/remove_admin' => 'Admin::remove_admin',
'POST:/add_comment' => 'ParkingLots::add_comment'
);
// routing stuff
if(isset($_SERVER['PATH_INFO']) && isset($_SERVER['REQUEST_METHOD'])) {
$route = $_SERVER['REQUEST_METHOD'].":".$_SERVER['PATH_INFO'];
error_log("Route: ".$route);
if(isset($routes[$route])) {
if(is_callable($routes[$route])) {
call_user_func($routes[$route]);
} else {
print "An unknown error occured - Code 101";
}
} else {
print "Route not found for $route";
}
}