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