]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/Portlets/VolumeList.php
Make out of freespace non-fatal for removable devices -- i.e. behaves like tape
[bacula/bacula] / gui / baculum / protected / Web / Portlets / VolumeList.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 Kern Sibbald
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.TActiveDataGrid');
24 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
25 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
26 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
27 Prado::using('System.Web.UI.ActiveControls.TActiveHiddenField');
28 Prado::using('System.Web.UI.ActiveControls.TCallback');
29 Prado::using('Application.Web.Portlets.ISlideWindow');
30 Prado::using('Application.Web.Portlets.Portlets');
31
32 class VolumeList extends Portlets implements ISlideWindow {
33
34         public $ID;
35         public $buttonID;
36         public $windowTitle;
37         public $pools = array();
38         public $old_pool;
39
40         public function setID($id) {
41                 $this->ID = $id;
42         }
43
44         public function getID($hideAutoID = true) {
45                 return $this->ID;
46         }
47
48         public function setButtonID($id) {
49                 $this->buttonID = $id;
50         }
51
52         public function getButtonID() {
53                 return $this->buttonID;
54         }
55
56         public function setWindowTitle($param) {
57                 $this->windowTitle = $param;
58         }
59
60         public function getWindowTitle() {
61                 return $this->windowTitle;
62         }
63
64         public function prepareData($sender, $param) {
65                 $this->setPoolList();
66                 $params = $this->getUrlParams(array('volumes'), $this->getPage()->VolumeWindow->ID);
67                 $volumes = $this->Application->getModule('api')->get($params);
68                 $isDetailView = $_SESSION['view' . $this->getPage()->VolumeWindow->ID] == 'details';
69                 if($isDetailView === true) {
70                         $this->RepeaterShow->Visible = false;
71                         $this->DataGridShow->Visible = true;
72                         $this->DataGrid->DataSource = $this->Application->getModule('misc')->objectToArray($volumes->output);
73                         $this->DataGrid->dataBind();
74
75                 } else {
76                         $this->Repeater->DataSource = $volumes->output;
77                         $this->Repeater->dataBind();
78                         $this->RepeaterShow->Visible = true;
79                         $this->DataGridShow->Visible = false;
80                 }
81         }
82
83         private function setPoolList() {
84                 $pools = $this->Application->getModule('api')->get(array('pools'));
85                 for ($i = 0; $i < count($pools->output); $i++) {
86                         $this->pools[$pools->output[$i]->poolid] = $pools->output[$i]->name;
87                 }
88         }
89
90         protected function sortData($data, $key, $id) {
91                 if($this->getSortOrder($id) == parent::SORT_DESC) {
92                         if($key == 'pool') {
93                                 $key = 'name';
94                                 $compare = create_function('$a,$b','if ($a["pool"]["'.$key.'"] == $b["pool"]["'.$key.'"]) {return 0;}else {return ($a["pool"]["'.$key.'"] < $b["pool"]["'.$key.'"]) ? 1 : -1;}');
95                         } else {
96                                 $compare = create_function('$a,$b','if ($a["'.$key.'"] == $b["'.$key.'"]) {return 0;}else {return ($a["'.$key.'"] < $b["'.$key.'"]) ? 1 : -1;}');
97                         }
98                 } else {
99                         if($key == 'pool') {
100                                 $key = 'name';
101                                 $compare = create_function('$a,$b','if ($a["pool"]["'.$key.'"] == $b["pool"]["'.$key.'"]) {return 0;}else {return ($a["pool"]["'.$key.'"] > $b["pool"]["'.$key.'"]) ? 1 : -1;}');
102                         } else {
103                                 $compare = create_function('$a,$b','if ($a["'.$key.'"] == $b["'.$key.'"]) {return 0;}else {return ($a["'.$key.'"] > $b["'.$key.'"]) ? 1 : -1;}');
104                         }
105                 }
106                 usort($data,$compare);
107                 return $data;
108         }
109
110         public function sortDataGrid($sender, $param) {
111                 $params = $this->getUrlParams(array('volumes'), $this->getPage()->VolumeWindow->ID);
112                 $data = $this->Application->getModule('api')->get($params)->output;
113                 $data = $this->Application->getModule('misc')->objectToArray($data);
114                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
115                 $this->DataGrid->dataBind();
116         }
117
118         public function configure($sender, $param) {
119                 if($this->Page->IsCallBack) {
120                         $this->getPage()->VolumeConfiguration->configure($param->CallbackParameter);
121                 }
122         }
123
124         public function executeAction($action) {
125                 $params = explode(';', $this->CheckedValues->Value);
126                 $commands = array();
127                 switch($action) {
128                         case 'prune': {
129                                 for($i = 0; $i < count($params); $i++) {
130                                         $cmd = array('prune');
131                                         $cmd[] = 'volume="' . $params[$i] . '"';
132                                         $cmd[] = 'yes';
133                                         $cmd[] = PHP_EOL;
134                                         $commands[] = implode(' ', $cmd);
135                                 }
136                                 $this->getPage()->Console->CommandLine->Text = implode(' ', $commands);
137                                 $this->getPage()->Console->sendCommand(null, null);
138                                 break;
139                         }
140                         case 'purge': {
141                                 for($i = 0; $i < count($params); $i++) {
142                                         $cmd = array('purge');
143                                         $cmd[] = 'volume="' . $params[$i] . '"';
144                                         $cmd[] = 'yes';
145                                         $cmd[] = PHP_EOL;
146                                         $commands[] = implode(' ', $cmd);
147                                 }
148                                 $this->getPage()->Console->CommandLine->Text = implode(' ', $commands);
149                                 $this->getPage()->Console->sendCommand(null, null);
150                                 break;
151                         }
152                         case 'delete': {
153                                 for($i = 0; $i < count($params); $i++) {
154                                         $cmd = array('delete');
155                                         $cmd[] = 'volume="' . $params[$i] . '"';
156                                         $cmd[] = 'yes';
157                                         $cmd[] = PHP_EOL;
158                                         $commands[] = implode(' ', $cmd);
159                                 }
160                                 $this->getPage()->Console->CommandLine->Text = implode(' ', $commands);
161                                 $this->getPage()->Console->sendCommand(null, null);
162                                 break;
163                         }
164                 }
165                 $this->CheckedValues->Value = "";
166         }
167
168         public function formatVolumeField($name) {
169                 if (strlen($name) > 20) {
170                         $name = substr($name, 0, 7) . '...' . substr($name, -10);
171                 }
172                 return $name;
173         }
174 }
175 ?>