-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex2.php
63 lines (58 loc) · 1.69 KB
/
index2.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
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (isset($_POST['logout'])) {
session_destroy();
header("Location: index.php");
exit();
}
if (!isset($_SESSION['user'])) {
header("Location: login.php");
exit();
}
require_once("php/publication.php");
$activepub = null;
if (isset($_SESSION['document'])) {
$activepub = Publications::byId($_SESSION['document']);
}
function action_list() {
$actions = array();
foreach(glob(__DIR__."/blocks/*.inc.php") as $includefile) {
$actions[] = str_replace(__DIR__."/blocks/", "", str_replace(".inc.php", "", $includefile));
}
return $actions;
}
function action_allowed($action) {
return in_array($action, action_list());
}
function action_include($action) {
if (!action_allowed($action)) {
echo "Forbidden";
} else {
include(__DIR__."/blocks/".$action.".inc.php");
}
}
global $active_action;
$active_action = "none";
if (isset($_GET) && !empty($_GET["action"]) and action_allowed($_GET["action"])) {
$active_action = $_GET["action"];
} else if (isset($_POST) && !empty($_POST["action"]) and action_allowed($_POST["action"])) {
$active_action = $_POST["action"];
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// handle data processing for the given action, render view if action id contains ".ui"
if (strpos($active_action, ".ui") === false) {
action_include($active_action);
} else {
include("blocks/header.php");
action_include($active_action);
include("blocks/footer.php");
}
} else {
// render the view part of the action
include("blocks/header.php");
action_include($active_action);
include("blocks/footer.php");
}
?>