forked from gabolinno/dominos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
97 lines (84 loc) · 4.08 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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use exceptions\BaseException;
use exceptions\NotFoundException;
require_once './vendor/autoload.php';
//AUTOCOMPLETE
spl_autoload_register(function ($class){
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php";
require_once $class;
});
set_exception_handler("handleExceptions");
session_start();
$fileNotFoundFlag = false;
$controllerName = isset($_GET["target"]) ? $_GET["target"] : "base";
$methodName = isset($_GET["action"]) ? $_GET["action"] : "baseFunc";
$controllerClassName = "\\controller\\" . ucfirst($controllerName) . "Controller";
function handleExceptions(Exception $exception){
$status = $exception instanceof BaseException ? $exception->getStatusCode() : 500;
$msg = $exception->getMessage();
$html = " <!doctype html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\"
content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\">
<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">
<title>ERROR </title>
<link rel=\"stylesheet\" href=\"styles/styles.css\">
<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css\">
<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js\"></script>
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js\"></script>
<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js\"></script>
<link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.6.3/css/all.css\" integrity=\"sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/\" crossorigin=\"anonymous\">
</head>
<body>
<div id=\"main_header\" class=\"nav navbar\">
<a class=\"navbar pull-left navbar-left\" href=\"index.php\"><img src=\"uploads/dominos_logo.svg\"></a>
<a href=\"index.php?target=user&action=main\"><button class=\"navbar btn btn-light\">Back to main </button></a>
</div>
<div class=\"container text-center center\">
<h2 class=\"font-weight-bold text-center\">ERROR: $status </h2>
<h3 class=\"font-weight-bold text-center\">$msg </h3>
<div id=\"error_img\" >
</div>
</div>
<div>
</div>
</body>
</html>";
http_response_code($status);
echo $html;
}
if (class_exists($controllerClassName)){
$controller = new $controllerClassName();
if (isset($_SESSION["logged_user"])) {
if($controllerName == "base" && $methodName == "baseFunc"){
$controller->$methodName();
die();
}
} if (method_exists($controller,$methodName)){
if (!($controllerName == "user" && in_array($methodName,array("userExists","main","login","register","forgotPassword","resetPassword", "changePassword")))){
if (!isset($_SESSION["logged_user"])){
header("Location: index.php?target=user&action=main");
die();
}
}
if (isset($_SESSION["logged_user"]) && in_array($methodName,array("userExists", "main","login", "register", "forgotPassword", "resetPassword", "changePassword"))) {
header("Location: index.php?target=pizza&action=showAll");
die();
} else {
$controller->$methodName();
}
}else{
$fileNotFoundFlag = true;
}
}else{
$fileNotFoundFlag = true;
}
if ($fileNotFoundFlag){
throw new NotFoundException("File not found!");
}
?>