Copy over some CSS files used in greenfield.
[bugdar.git] / admin / index.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2013 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 namespace bugdar\admin;
23
24 use \bugdar;
25 use \hoplite\http;
26
27 chdir('../');
28 require_once './includes/init.php';
29
30 require_once HOPLITE_ROOT . '/http/output_filter.php';
31 require_once HOPLITE_ROOT . '/http/response_code.php';
32 require_once HOPLITE_ROOT . '/http/root_controller.php';
33 require_once HOPLITE_ROOT . '/http/url_map.php';
34
35 /**
36 * @implements \hoplite\http\RootControllerDelegate
37 */
38 class FrontController
39 {
40 /** @var \hoplite\http\RootController */
41 private $controller = NULL;
42
43 public function __construct(http\RootController $controller)
44 {
45 $this->controller = $controller;
46 }
47
48 public function WillRouteRequest(http\Request $request, http\Response $response)
49 {
50 // TODO(port): Write a new cookie function.
51 global $funct;
52
53 $cookie = COOKIE_PREFIX . 'adminsession';
54
55 if (can_perform('canadminpanel')) {
56 $stmt = bugdar::$db->Prepare("SELECT * FROM ". TABLE_PREFIX . "adminsession WHERE sessionid = ?");
57 $stmt->Execute(array(bugdar::$input->InputClean('c', $cookie, http\Input::TYPE_STR)));
58 $session = $stmt->FetchObject();
59
60 if ($session && $session->userid == bugdar::$user['userid'] && $session->dateline >= TIMENOW - 3600) {
61 // Renew the cookie.
62 $funct->cookie($cookie, $session->sessionid, false);
63 return;
64 }
65 }
66
67 $funct->cookie($cookie, NULL);
68 $this->LoginPage();
69 }
70
71 public function LoginPage()
72 {
73 $this->controller->StopWithCode(http\ResponseCode::FORBIDDEN);
74 }
75 }
76
77 $controller = new http\RootController($GLOBALS);
78 $controller->set_delegate(new FrontController($controller));
79
80 $url_map = new http\UrlMap($controller);
81 $url_map->set_file_loader(function($name, $value) {
82 require_once BUGDAR_ROOT . '/admin/' . $value;
83 return 'bugdar\\admin\\' . $name . 'Action';
84 });
85 $controller->set_url_map($url_map);
86
87 $url_map->set_map(array(
88 '' => 'home',
89 'fields' => 'fields',
90 ));
91
92 $output_filter = new http\OutputFilter($controller);
93 $controller->set_output_filter($output_filter);
94
95 $controller->Run();