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