]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Pages/Home.php
baculum: Add session cache
[bacula/bacula] / gui / baculum / protected / Pages / Home.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2015 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 Prado::using('System.Web.UI.ActiveControls.TActiveButton');
24 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
25 Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList');
26 Prado::using('System.Web.UI.ActiveControls.TActiveCheckBox');
27 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
28
29 class Home extends BaculumPage
30 {
31         public $jobs;
32
33         public $openWindow = null;
34
35         public $windowIds = array('Storage', 'Client', 'Media', 'Pool', 'Job', 'JobRun');
36
37         public function onInit($param) {
38                 parent::onInit($param);
39
40                 if (!$this->IsPostBack && !$this->IsCallBack) {
41                         $this->getModule('api')->initSessionCache(true);
42                 }
43
44                 $isConfigExists = $this->getModule('configuration')->isApplicationConfig();
45                 if($isConfigExists === false) {
46                         $this->goToPage('ConfigurationWizard');
47                 }
48
49                 $appConfig = $this->getModule('configuration')->getApplicationConfig();
50
51                 $this->SettingsWizardBtn->Visible = $this->User->getIsAdmin();
52                 $this->MediaBtn->Visible = $this->User->getIsAdmin();
53                 $this->ClearBvfsCache->Visible = $this->User->getIsAdmin();
54                 $this->Logging->Visible = $this->User->getIsAdmin();
55
56                 if(!$this->IsPostBack && !$this->IsCallBack) {
57                         $this->Logging->Checked = $this->getModule('logging')->isDebugOn();
58                 }
59
60                 if(!$this->IsPostBack && !$this->IsCallBack) {
61                         $directors = $this->getModule('api')->get(array('directors'))->output;
62                         if(!array_key_exists('director', $_SESSION)) {
63                                 $_SESSION['director'] = $directors[0];
64                         }
65                         $this->Director->dataSource = array_combine($directors, $directors);
66                         $this->Director->SelectedValue = $_SESSION['director'];
67                         $this->Director->dataBind();
68                         $this->setJobs();
69                         $this->setClients();
70                         $this->setWindowOpen();
71                 }
72         }
73
74         public function restore($sender, $param) {
75                 $this->goToPage('RestoreWizard');
76         }
77
78         public function configuration($sender, $param) {
79                 $this->goToPage('ConfigurationWizard');
80         }
81
82         public function director($sender, $param) {
83                 $_SESSION['director'] = $this->Director->SelectedValue;
84         }
85
86         public function setDebug($sender, $param) {
87                 if($this->User->getIsAdmin() === true) {
88                         $this->getModule('logging')->enableDebug($this->Logging->Checked);
89                         $this->goToDefaultPage();
90                 }
91         }
92
93         public function clearBvfsCache($sender, $param) {
94                 if($this->User->getIsAdmin() === true) {
95                         $this->getModule('api')->set(array('bvfs', 'clear'), array());
96                 }
97         }
98
99         public function getJobs() {
100                 return json_encode($this->jobs);
101         }
102
103         public function setJobs() {
104                 $this->jobs = $this->getModule('api')->get(array('jobs'));
105                 $jobs = array('@' => Prado::localize('select job'));
106                 foreach($this->jobs->output as $key => $job) {
107                         $jobs[$job->name] = $job->name;
108                 }
109                 $this->Jobs->dataSource = $jobs;
110                 $this->Jobs->dataBind();
111         }
112
113         public function setClients() {
114                 $clients_obj = $this->getModule('api')->get(array('clients'));
115                 $clients = array('@' => Prado::localize('select client'));
116                 foreach($clients_obj->output as $key => $client) {
117                         $clients[$client->clientid] = $client->name;
118                 }
119                 $this->Clients->dataSource = $clients;
120                 $this->Clients->dataBind();
121
122         }
123
124         public function setWindowOpen() {
125                 if (isset($this->Request['open']) && in_array($this->Request['open'], $this->windowIds)) {
126                         $btn = $this->Request['open'] . 'Btn';
127                         $this->openWindow = $this->{$btn}->ClientID;
128                 }
129         }
130 }
131 ?>