]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Class/BaculumPage.php
baculum: Tweak add comments
[bacula/bacula] / gui / baculum / protected / Class / BaculumPage.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 Marcin Haba
7  *
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.
11  *
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.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23 /**
24  * Base pages module.
25  * The module contains methods that are common for all pages (wizards, main
26  * page and error pages).
27  *
28  * @author Marcin Haba <marcin.haba@bacula.pl>
29  */
30 class BaculumPage extends TPage {
31
32         public function onPreInit($param) {
33                 parent::onPreInit($param);
34                 $this->Application->getGlobalization()->Culture = $this->getLanguage();
35                 $this->setURLPrefixForSubdir();
36         }
37
38         /**
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.
44          *
45          * @access public
46          * @return string currently set language short name
47          */
48         public function getLanguage() {
49                 if (isset($_SESSION['language']) && !empty($_SESSION['language'])) {
50                         $language =  $_SESSION['language'];
51                 } else {
52                         $language = $this->getModule('configuration')->getLanguage();
53                         $_SESSION['language'] = $language;
54                 }
55                 return $language;
56         }
57
58         /**
59          * Shortcut method for getting application modules instances by
60          * module name.
61          *
62          * @access public
63          * @param string $name application module name
64          * @return object module class instance
65          */
66         public function getModule($name) {
67                 return $this->Application->getModule($name);
68         }
69
70         /**
71          * Redirection to a page.
72          * Page name is given in PRADO notation with "dot", for example: (Home.SomePage).
73          *
74          * @access public
75          * @param string $page_name page name to redirect
76          * @param array $params HTTP GET method parameters in associative array
77          * @return none
78          */
79         public function goToPage($page_name, $params = null) {
80                 $url = $this->Service->constructUrl($page_name, $params, false);
81                 $this->Response->redirect($url);
82         }
83
84         /**
85          * Redirection to default page defined in application config.
86          *
87          * @access public
88          * @param array $params HTTP GET method parameters in associative array
89          * @return none
90          */
91         public function goToDefaultPage($params = null) {
92                 $this->goToPage($this->Service->DefaultPage, $params);
93         }
94
95         /**
96          * Set prefix when Baculum is running in document root subdirectory.
97          * For example:
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/
103          *
104          * @access private
105          * @return none
106          */
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);
112                 }
113         }
114
115         /**
116          * Get full document root directory path.
117          * Symbolic links in document root path are translated to full paths.
118          *
119          * @access private
120          * return string full document root directory path
121          */
122         private function getFullDocumentRoot() {
123                 $root_dir = array();
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));
129                         } else {
130                                 $root_dir[] = $dirs[$i];
131                         }
132                 }
133
134                 $root_dir = implode('/', $root_dir);
135                 return $root_dir;
136         }
137 }
138 ?>