]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/Portlets/VolumeList.php
b723837d3b85e6db19746ca37d08173ae18dd6ae
[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;
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 prepareData($sender, $param) {
66                 $params = $this->getUrlParams(array('volumes', 'withpools'), $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         protected function sortData($data, $key, $id) {
84                 if($this->getSortOrder($id) == parent::SORT_DESC) {
85                         if($key == 'pool') {
86                                 $key = 'name';
87                                 $compare = create_function('$a,$b','if ($a["pool"]["'.$key.'"] == $b["pool"]["'.$key.'"]) {return 0;}else {return ($a["pool"]["'.$key.'"] < $b["pool"]["'.$key.'"]) ? 1 : -1;}');
88                         } else {
89                                 $compare = create_function('$a,$b','if ($a["'.$key.'"] == $b["'.$key.'"]) {return 0;}else {return ($a["'.$key.'"] < $b["'.$key.'"]) ? 1 : -1;}');
90                         }
91                 } else {
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                 }
99                 usort($data,$compare);
100                 return $data;
101         }
102
103         public function sortDataGrid($sender, $param) {
104                 $params = $this->getUrlParams(array('volumes', 'withpools'), $this->getPage()->VolumeWindow->ID);
105                 $data = $this->Application->getModule('api')->get($params)->output;
106                 $data = $this->Application->getModule('misc')->objectToArray($data);
107                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
108                 $this->DataGrid->dataBind();
109         }
110
111         public function configure($sender, $param) {
112                 if($this->Page->IsCallBack) {
113                         $this->getPage()->VolumeConfiguration->configure($param->CallbackParameter);
114                 }
115         }
116
117         public function executeAction($action) {
118                 $params = explode(';', $this->CheckedValues->Value);
119                 $commands = array();
120                 switch($action) {
121                         case 'prune': {
122                                 for($i = 0; $i < count($params); $i++) {
123                                         $cmd = array('prune');
124                                         $cmd[] = 'volume="' . $params[$i] . '"';
125                                         $cmd[] = 'yes';
126                                         $cmd[] = PHP_EOL;
127                                         $commands[] = implode(' ', $cmd);
128                                 }
129                                 $this->getPage()->Console->CommandLine->Text = implode(' ', $commands);
130                                 $this->getPage()->Console->sendCommand(null, null);
131                                 break;
132                         }
133                         case 'purge': {
134                                 for($i = 0; $i < count($params); $i++) {
135                                         $cmd = array('purge');
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 'delete': {
146                                 for($i = 0; $i < count($params); $i++) {
147                                         $cmd = array('delete');
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                 }
158                 $this->CheckedValues->Value = "";
159         }
160
161         public function formatVolumeField($name) {
162                 if (strlen($name) > 20) {
163                         $name = substr($name, 0, 7) . '...' . substr($name, -10);
164                 }
165                 return $name;
166         }
167 }
168 ?>