-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
177 lines (141 loc) · 5.46 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
<?php
/*
*
* Model View Controller FRAMEWORK Application
*
* This is the main entry point for this MVC application
*
*/
//join/start a session between the browser client and Apache web server
session_start();
//load application configuration
include_once 'config/config.php';
include_once 'config/database.php';
//load class library
//Base Classes
include_once 'classlib/BaseClasses/Controller.php';
include_once 'classlib/BaseClasses/Model.php';
include_once 'classlib/BaseClasses/TableEntity.php';
//System Classes
include_once 'classlib/System/Session.php';
include_once 'classlib/System/User.php';
//helper classes
include ('classlib/HelperClasses/HelperHTML.php');
//Database Table Entities
include_once 'classlib/Entities/AttendeeTable.php';
include_once 'classlib/Entities/EventAdminTable.php';
include_once 'classlib/Entities/EventTable.php';
include_once 'classlib/Entities/UserTable.php';
include_once 'classlib/Entities/SportTable.php';
include_once 'classlib/Entities/RecurringTable.php';
include_once 'classlib/Entities/EventTypeTable.php';
//Controller Clases for specific user types
include_once 'controllers/EventAdminController.php';
include_once 'controllers/GeneralController.php';
include_once 'controllers/UserController.php';
//Navigation models
include_once 'models/NavigationEventAdmin.php';
include_once 'models/NavigationGeneral.php';
include_once 'models/NavigationUser.php';
include_once 'models/SideNavUser.php';
include_once 'models/SideNavAdmin.php';
//Page models - Common
include_once 'models/UnderConstruction.php';
include_once 'models/Login.php';
include_once 'models/Register.php';
include_once 'models/AboutUs.php';
include_once 'models/YourEvents.php';
include_once 'models/ViewAllEvents.php';
include_once 'models/EventPage.php';
include_once 'models/Profile.php';
include_once 'models/Home.php';
include_once 'models/EventsDashboard.php';
//Page models - EVENTADMIN
include_once 'models/CreateEvent.php';
include_once 'models/EditEvent.php';
//Page models USER
//attempt to connect to the MySQL Server (with error reporting supression '@')
@$db=new mysqli($DBServer, $DBUser, $DBPass, $DBName, $DBportNr);
//check if there is an error in the connection
if($db->connect_errno){
if (DEBUG_MODE){
$msg = '<h3>Unable to make Database Connection</h3>';
//report on connection issue
$msg.= '<p>There has been a proble making connection to MySQL Server - MySQLi Error message:';
$msg.= '<ul>';
$msg.= '<li>MySQLi Error Number : ' . @$db->connect_errno. '</li>';
$msg.= '<li>MySQLi Error Message : '.@$db->connect_error. '</li>';
$msg.= '</ul>';
}
else{
$msg= '<h4>Oops - something is not working!</h4>';
echo $db->connect_errno;
}
exit($msg); //the script exits here if no database connection can be made
}
@$db->query("SET NAMES 'utf8'"); //make sure database connection is set to support UTF8 characterset
//Create the new session object
$session = new Session();
$session->setChatEnabledState(FALSE);
$user = new User($session, $db, ENCRYPT_PW);
if ($user->getLoggedInState()) {
//load the appropriate controller depending on the user type
//
switch ($user->getUserType()) {
case "USER": //create new LECTURER controller
$controller = new UserController($user, $db);
break;
case "EVENTADMIN": //create new STUDENT controller
$controller = new EventAdminController($user, $db);
break;
default : //create new general/not logged in controller
//unidentified user type - force logout to reset system state
$user->logout();
$controller = new GeneralController($user, $db);
break;
}
} else {
//user is not logged in
//create new general/not logged in controller
$controller = new GeneralController($user, $db);
}
//run the application
$controller->run();
//Debug information
if (DEBUG_MODE) {
//Comment out whichever info you dont want to use.
echo '<section>';
echo '<!-- The Debug SECTION of index.php-->';
echo '<div class="container-fluid" style="background-color: #AA44AA">'; //outer DIV
echo '<h2>Index.php - Debug information</h2><br>';
echo '<section style="background-color: #AAAAAA">';
echo '<pre><h5>SESSION Class</h5>';
$session->getDiagnosticInfo();
echo '</pre>';
echo '</section>';
echo '<section style="background-color: #AAAAAA">';
echo '<pre><h5>USER Class</h5>';
$user->getDiagnosticInfo();
echo '</pre>';
echo '</section>';
echo '<section style="background-color: #AAAAAA" >';
echo '<!-- $_COOKIE ARRAY SECTION -->';
echo '<div class="container-fluid" style="background-color: #AAAAAA">'; //outer DIV
echo '<h3>$_COOKIE Array values</h3>';
echo '<table border=1 style="background-color: #EEEEEE" >';
foreach($_COOKIE as $key=>$value){
echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
echo '</table><hr>';
echo '<!-- END $_COOKIE ARRAY SECTION -->';
echo '</section>';
echo '</section>';
echo '</br>';
echo '</div>';
//controller class debug info
$controller->debug();
};
echo '</body></html>'; //end of HTML Document
//close or release any open connections/resources
//close the DB Connection
$db->close();