-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtools.php
63 lines (50 loc) · 1.14 KB
/
tools.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
<?php
spl_autoload_register(function($name) {
$dir = "model";
if (strpos($name,"Controller") !== FALSE)
$dir = "controller";
$path = $dir."/".strtolower($name).".php";
if(file_exists($path)){
include_once $path;
}else{
(new SiteController())->render("index");
}
});
function get_role(){
if(isset($_SESSION["user"])){
return $_SESSION["user"]["idrole"];
}
return -999;
}
function parametersExist($parameters) {
$tmp = array_filter(parameters(), function($var){return $var != null;} );
$intersect = array_intersect($parameters, array_keys($tmp));
return count($intersect) == count($parameters);
}
function get_id(){
if(isset($_SESSION["user"]["idinternaluser"])){
return $_SESSION["user"]["idinternaluser"];
}
}
function is_student(){
return get_role() == 1;
}
function is_teacher(){
return get_role() == 2;
}
function is_admin(){
return get_role() == 3;
}
function is_visitor(){
return get_role() == -999;
}
function go_back(){
if (isset($_SERVER['HTTP_REFERER']))
return header('Location: ' . $_SERVER['HTTP_REFERER']);
return header('Location: .');
}
function id_or_back($data){
if(!isset($data['id'])){
go_back();
}
}