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