This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
/
page_options.php
112 lines (102 loc) · 3.96 KB
/
page_options.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
<?php
/**
* File defines the PageOptionsController PageController class
* @package PageController
*/
/**
*/
$current_dir = dirname (__FILE__);
require_once ($current_dir . DIRECTORY_SEPARATOR . "shared" . DIRECTORY_SEPARATOR . "bootstrap.php");
require_once (joinPath (INCLUDES_DIR, "models", "Page.php"));
require_once (joinPath (INCLUDES_DIR, "Session.php"));
/**
* ADMIN PAGE. Interface to administer page data
*
* Read in pages from the database. Displays an interface to administer page data
* for allowing bulk deletion of pages, deletion of a single
* page, links to editing each page entry. Available to admins only
* @package PageController
*/
class PageOptionsController implements Controller {
/**
* PageTemplate object used to render page
* @access protected
* @var PageTemplate
*/
protected $template;
/**
* Constructor. Create instance of PageTemplate using default index_tpl.php file
* @access public
*/
public function __construct () {
$this->template = new PageTemplate ();
}
/**
* Run method with main page logic
*
* Read in pages from the database. Populate template and display an interface to
* administer page data for allowing bulk deletion of pages, deletion of a single
* page, links to editing each page entry. Available to admins only
* @access public
*/
public function run () {
$PAGINATION_LIMIT = 10;
$session = Session::getInstance ();
$user = $session->getUser ();
if (!$user || !$user->isAdmin ()) {
$session->setMessage ("Do not have permission to access", Session::MESSAGE_ERROR);
header ("Location: " . BASE_URL);
return;
}
$page = (isset ($_GET["page"]) && is_numeric ($_GET["page"])) ? intval ($_GET["page"]) : 1;
if ($page < 1) {
$page = 1;
}
$action = isset ($_GET["action"]) ? trim ($_GET["action"]) : "";
$pageDAO = PageDAO::getInstance ();
$page_array = $paginator_page = null;
$content_title = "Page Options";
if (!empty ($_POST) && !empty ($_POST["ids"]) && !empty ($_POST["action"])) {
$action = isset ($_POST["action"]) ? trim ($_POST["action"]) : "";
if (!strcmp ($action, "delete") == 0) {
header ("Location: " . BASE_URL);
return;
}
$status = $pageDAO->deleteByIds ($_POST["ids"]);
if ($status) {
$session->setMessage ("Selected pages deleted");
header ("Location: {$_SERVER["PHP_SELF"]}");
return;
}
else {
$session->setMessage ("Deletion failed", Session::MESSAGE_ERROR);
header ("Location: {$_SERVER["PHP_SELF"]}");
return;
}
}
else if (strcmp ($action, "delete") == 0 && !empty ($_GET["ids"])) {
$content_title = "Delete Pages";
$page_array = $pageDAO->allByIds ($_GET["ids"]);
}
else if (strcmp ($action, "delete") == 0) {
}
else {
$count = $pageDAO->count ();
$paginator = new Paginator ($count, $PAGINATION_LIMIT);
$paginator_page = $paginator->getPage ($page);
$page_array = $pageDAO->all (array ("limit" => $paginator_page));
}
$this->template->render (array (
"title" => "Admin - {$content_title}",
"main_page" => "page_options_tpl.php",
"session" => $session,
"page_array" => $page_array,
"paginator_page" => $paginator_page,
"action" => $action,
"content_title" => $content_title,
));
}
}
$controller = new PageOptionsController ();
$controller->run ();
?>