3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 Kern Sibbald
8 * The main author of Baculum is Marcin Haba.
9 * The original author of Bacula is Kern Sibbald, with contributions
10 * from many others, a complete list can be found in the file AUTHORS.
12 * You may use this file and others of this release according to the
13 * license defined in the LICENSE file, which includes the Affero General
14 * Public License, v3.0 ("AGPLv3") and some additional permissions and
15 * terms pursuant to its AGPLv3 Section 7.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
25 * The module contains methods that are common for all pages (wizards, main
26 * page and error pages).
28 * @author Marcin Haba <marcin.haba@bacula.pl>
30 class BaculumPage extends TPage {
32 public function onPreInit($param) {
33 parent::onPreInit($param);
34 $this->Application->getGlobalization()->Culture = $this->getLanguage();
35 $this->setURLPrefixForSubdir();
39 * Get curently set language short name (for example: en, pl).
40 * If language short name is not set in session then the language value
41 * is taken from Baculum config file, saved in session and returned.
42 * If the language setting is set in session, then the value from
43 * session is returned.
46 * @return string currently set language short name
48 public function getLanguage() {
49 if (isset($_SESSION['language']) && !empty($_SESSION['language'])) {
50 $language = $_SESSION['language'];
52 $language = $this->getModule('configuration')->getLanguage();
53 $_SESSION['language'] = $language;
59 * Shortcut method for getting application modules instances by
63 * @param string $name application module name
64 * @return object module class instance
66 public function getModule($name) {
67 return $this->Application->getModule($name);
71 * Redirection to a page.
72 * Page name is given in PRADO notation with "dot", for example: (Home.SomePage).
75 * @param string $page_name page name to redirect
76 * @param array $params HTTP GET method parameters in associative array
79 public function goToPage($page_name, $params = null) {
80 $url = $this->Service->constructUrl($page_name, $params, false);
81 $this->Response->redirect($url);
85 * Redirection to default page defined in application config.
88 * @param array $params HTTP GET method parameters in associative array
91 public function goToDefaultPage($params = null) {
92 $this->goToPage($this->Service->DefaultPage, $params);
96 * Set prefix when Baculum is running in document root subdirectory.
98 * web server document root: /var/www/
99 * Baculum directory /var/www/baculum/
100 * URL prefix: /baculum/
101 * In this case to base url is added '/baculum/' such as:
102 * http://localhost:9095/baculum/
107 private function setURLPrefixForSubdir() {
108 $full_document_root = preg_replace('#(\/)$#', '', $this->getFullDocumentRoot());
109 $url_prefix = str_replace($full_document_root, '', APPLICATION_DIRECTORY);
110 if (!empty($url_prefix)) {
111 $this->Application->getModule('friendly-url')->setUrlPrefix($url_prefix);
116 * Get full document root directory path.
117 * Symbolic links in document root path are translated to full paths.
120 * return string full document root directory path
122 private function getFullDocumentRoot() {
124 $dirs = explode('/', $_SERVER['DOCUMENT_ROOT']);
125 for($i = 0; $i < count($dirs); $i++) {
126 $document_root_part = implode('/', $root_dir) . '/' . $dirs[$i];
127 if (is_link($document_root_part)) {
128 $root_dir = array(readlink($document_root_part));
130 $root_dir[] = $dirs[$i];
134 $root_dir = implode('/', $root_dir);