/
index.php
115 lines (112 loc) · 3.47 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
<?php
ini_set('display_errors', "1");
ini_set('error_reporting', E_ALL);
$error = '';
/*** include the init.php file ***/
include_once('library/init.php');
$route = '';
$hasUser = true;
try{
try{
$route = $varChecker->getValue('rt');
$router = new Router(trim($route,'/'));
}catch(DataException $e){
$module = $dRep->getModule('index');
$router = new Router($module->getRoute());
}
/*** find the module we are looking for ***/
/*** check if this is a customer **/
/*** redirect to login if we dont have customer and are not trying to access a module where anon access is allowed **/
$fido = new Guarddog();
try{
$customer = $fido->CheckCustomer();
}catch(DataException $e){
if($router->getControllername() != ''){
$module = $dRep->getModule($router->getControllername());
if(!$module->AllowAnonomousAccess()){
throw new CustomerException('wrongcustomer');
}
$hasUser = false;
}else{
throw new CustomerException('nocustomer');
}
}
/*** check if we have a user **/
if(!isset($module) || (isset($module) && !$module->AllowAnonomousAccess())){
$INK_User = $fido->CheckUser();
try{
$fido->ResolveUserSite();
}
catch(SiteException $e)
{
//need to find module with no site
$module = $dRep->getModule(array('cmsIndex' => 2));
}
//we have user, check if we have a site, if not, redirect
}
if(isset($module)){
if(!isset($router) || strpos(strtolower($router->getControllername()), strtolower($module->getRoute())) === false){
//make sure we can access actions on the allowed module by not defaulting to index
$router = new Router($module->getRoute());
}
}
$controller = $router->LoadController($dRep);
if($hasUser){
$controller->setUser($INK_User);
}
/*** run the controller ***/
$router->RunController($hasUser);
//print out the page
$router->printHtml($hasUser);
}catch(AccessException $e){
$message['css'] = 'hidden';
$message['text'] = '';
$message['icon'] = '';
if(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) !== false){
try{
if($e->getMessage() == 'logout'){
$fido->kill();
}
include_once('controllers/message.controller.php');
$messageController = new MessageController($dRep);
$message = $messageController->getLoginMessage($e);
}catch(Exception $e){
$message['css'] = 'error-box';
$message['text'] = $e->getMessage();
}
}
include_once('view/login/login.php');
}catch(PDOException $e){
print_r($e);
}catch(DataException $e){
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
echo json_encode(array('error' => $e->getMessage(), 'elements' => implode(',', $e->getElements())));
}else{
echo 'Message: '.$e->getMessage();
echo '<br/>';
echo 'Error code: '.$e->getCode();
echo '<br/>';
echo 'Error happened in file: '.$e->getFile();
echo '<br/>';
echo 'Line number: '.$e->getLine();
echo '<br/>';
echo 'Trace number: '.$e->getTraceAsString();
//include some error file
}
}catch(Exception $e){
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
echo json_encode(array('error' => $e->getMessage()));
}else{
echo 'Message: '.$e->getMessage();
echo '<br/>';
echo 'Error code: '.$e->getCode();
echo '<br/>';
echo 'Error happened in file: '.$e->getFile();
echo '<br/>';
echo 'Line number: '.$e->getLine();
echo '<br/>';
echo 'Trace number: '.$e->getTraceAsString();
//include some error file
}
}
?>