-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
88 lines (77 loc) · 2.84 KB
/
index.php
File metadata and controls
88 lines (77 loc) · 2.84 KB
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
<?php
require 'autoload.php';
$App = new App;
$App->checkAuth($_SESSION,$db);
$App->view($route);
class App {
public $errorPage = "client/pages/404/index.php";
public $headerComponent = "client/components/header.php";
public $footerComponent = "client/components/footer.php";
public $userRole = "user";
public $session;
public $isAuth = false;
public $userName = '';
public $login;
public $pageTitles = [
NULL => "ATAO - Главная",
'contacts' => 'ATAO - Контакты',
'about' => 'ATAO - О нас',
'profile' => 'АТАО - Профиль',
'disciplines' => 'АТАО - Блоки дисциплин',
'edit-users' => 'АТАО - Редактор пользователей',
'edit-disciplines' => 'АТАО - Редактор дисциплин',
'my-grades' => 'АТАО - Мои оценки',
'groups' => 'ATAO - Группы'
];
public function checkAuth($sessionInfo, $db) {
$this->session = $sessionInfo;
if(isset($this->session['username'])) {
$this->isAuth = true;
$this->login = $this->session['username'];
$login = $this->login;
$query = $db->query("SELECT `user_type`,`user_name` FROM `users` WHERE `login` = '$login'")->fetch_assoc();
$this->userRole = $query['user_type'];
$this->userName = $query['user_name'];
}
}
private function setPageTitle($pageName) {
return ($this->pageTitles[$pageName]) ? $this->pageTitles[$pageName] : "ATAO";
}
public function view($pageName) {
$pageTitle = $this->setPageTitle($pageName);
$isAuth = $this->isAuth;
$userRole = $this->userRole;
$userName = $this->userName;
$pageActive = $pageName;
$login = $this->login;
$routes = [
'profile' => 'needAuth',
'edit-users' => 'needAuth',
'edit-disciplines' => 'needAuth',
'my-grades' => 'needAuth',
'disciplines' => 'needAuth',
'groups' => 'needAuth'
];
require($this->headerComponent);
//main page
($pageName == NULL) ? $this->fileName = "client/pages/index/index.php" : $this->fileName = "client/pages/$pageName/index.php";
//profile
if ($routes[$pageName]) {
if ($routes[$pageName] == 'needAuth') {
if ($isAuth) {
$this->fileName = "client/pages/$pageName/index.php";
} else {
$this->fileName = "client/pages/index/index.php";
}
}
}
//public pages
if(file_exists($this->fileName)) {
require "$this->fileName";
} else {
require "$this->errorPage";
}
require "$this->footerComponent";
}
}
?>