]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/Portlets/VolumesTools.php
baculum: Fix redundant loading users portlet
[bacula/bacula] / gui / baculum / protected / Web / Portlets / VolumesTools.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.TActivePanel');
24 Prado::using('System.Web.UI.ActiveControls.TActiveRadioButton');
25 Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
26 Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList');
27 Prado::using('Application.Web.Portlets.Portlets');
28
29 class VolumesTools extends Portlets {
30
31         public $labelVolumePattern = '^[0-9a-zA-Z\-_]+$';
32         public $slotsPattern = '^[0-9\-\,]+$';
33         public $drivePattern = '^[0-9]+$';
34
35         public function onLoad($param) {
36                 parent::onLoad($param);
37                 if(!$this->getPage()->IsPostBack) {
38                         $storages = $this->Application->getModule('api')->get(array('storages'))->output;
39                         $storagesList = array();
40                         foreach($storages as $storage) {
41                                 $storagesList[$storage->storageid] = $storage->name;
42                         }
43                         $this->StorageLabel->dataSource = $storagesList;
44                         $this->StorageLabel->dataBind();
45                         $this->StorageUpdateSlots->dataSource = $storagesList;
46                         $this->StorageUpdateSlots->dataBind();
47                         $this->StorageUpdateSlotsScan->dataSource = $storagesList;
48                         $this->StorageUpdateSlotsScan->dataBind();
49
50                         $pools = $this->Application->getModule('api')->get(array('pools'))->output;
51                         $poolsList = array();
52                         foreach($pools as $pool) {
53                                 $poolsList[$pool->poolid] = $pool->name;
54                         }
55                         $this->PoolLabel->dataSource = $poolsList;
56                         $this->PoolLabel->dataBind();
57                 }
58         }
59
60         public function labelVolume($sender, $param) {
61                 if($this->LabelNameValidator->isValid === false) {
62                         return;
63                 }
64                 $cmd = array('label');
65                 if($this->Barcodes->Checked == true) {
66                         $cmd[] = 'barcodes';
67                         $cmd[] = 'slots="' . $this->SlotsLabel->Text . '"';
68                 } else {
69                         $cmd[] = 'volume="' . $this->LabelName->Text . '"';
70                         $cmd[] = 'slot="' . $this->SlotsLabel->Text . '"';
71                 }
72                 $cmd[] = 'drive="' . $this->DriveLabel->Text . '"';
73                 $cmd[] = 'storage="'. $this->StorageLabel->SelectedItem->Text . '"';
74                 $cmd[] = 'pool="'. $this->PoolLabel->SelectedItem->Text . '"';
75                 $this->getPage()->Console->CommandLine->Text = implode(' ', $cmd);
76                 $this->getPage()->Console->sendCommand($sender, $param);
77         }
78
79         public function updateSlots($sender, $param) {
80                 $cmd = array('update');
81                 $cmd[] = 'slots="' . $this->SlotsUpdateSlots->Text . '"';
82                 $cmd[] = 'drive="' . $this->DriveUpdateSlots->Text . '"';
83                 $cmd[] = 'storage="'. $this->StorageUpdateSlots->SelectedItem->Text . '"';
84                 $this->getPage()->Console->CommandLine->Text = implode(' ', $cmd);
85                 $this->getPage()->Console->sendCommand($sender, $param);
86         }
87
88         public function updateSlotsScan($sender, $param) {
89                 $cmd = array('update');
90                 $cmd[] = 'slots="' . $this->SlotsUpdateSlotsScan->Text . '"';
91                 $cmd[] = 'scan';
92                 $cmd[] = 'drive="' . $this->DriveUpdateSlotsScan->Text . '"';
93                 $cmd[] = 'storage="'. $this->StorageUpdateSlotsScan->SelectedItem->Text . '"';
94                 $this->getPage()->Console->CommandLine->Text = implode(' ', $cmd);
95                 $this->getPage()->Console->sendCommand($sender, $param);
96         }
97
98         public function setBarcodes($sender, $param) {
99                 $this->LabelNameField->Display = $sender->Checked === false ? 'Dynamic' : 'None';
100                 $this->BarcodeSlotsField->Display = $sender->Checked === true ? 'Dynamic' : 'None';
101         }
102
103         public function setLabelVolume($sender, $param) {
104                 $this->Labeling->Display = $sender->Checked === true ? 'Dynamic' : 'None';
105                 $this->UpdatingSlots->Display = 'None';
106                 $this->UpdatingSlotsScan->Display = 'None';
107         }
108
109         public function setUpdateSlots($sender, $param) {
110                 $this->UpdatingSlots->Display = $sender->Checked === true ? 'Dynamic' : 'None';
111                 $this->Labeling->Display = 'None';
112                 $this->UpdatingSlotsScan->Display = 'None';
113         }
114
115         public function setUpdateSlotsScan($sender, $param) {
116                 $this->UpdatingSlotsScan->Display = $sender->Checked === true ? 'Dynamic' : 'None';
117                 $this->UpdatingSlots->Display = 'None';
118                 $this->Labeling->Display = 'None';
119         }
120
121         public function labelNameValidator($sender, $param) {
122                 $isValid = true;
123                 if($this->LabelVolume->Checked === true && $this->Barcodes->Checked === false) {
124                         $isValid = preg_match('/'. $this->labelVolumePattern . '/', $this->LabelName->Text) === 1;
125                 }
126                 $param->setIsValid($isValid);
127         }
128
129         public function slotsLabelValidator($sender, $param) {
130                 $isValid = true;
131                 if($this->LabelVolume->Checked === true && $this->Barcodes->Checked === true) {
132                         $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsLabel->Text) === 1;
133                 }
134                 $param->setIsValid($isValid);
135         }
136
137         public function driveLabelValidator($sender, $param) {
138                 $isValid = true;
139                 if($this->LabelVolume->Checked === true) {
140                         $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveLabel->Text) === 1;
141                 }
142                 $param->setIsValid($isValid);
143         }
144
145         public function slotsUpdateSlotsValidator($sender, $param) {
146                 $isValid = true;
147                 if($this->UpdateSlots->Checked === true) {
148                         $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsUpdateSlots->Text) === 1;
149                 }
150                 $param->setIsValid($isValid);
151         }
152
153         public function driveUpdateSlotsValidator($sender, $param) {
154                 $isValid = true;
155                 if($this->UpdateSlots->Checked === true) {
156                         $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveUpdateSlots->Text) === 1;
157                 }
158                 $param->setIsValid($isValid);
159         }
160
161         public function slotsUpdateSlotsScanValidator($sender, $param) {
162                 $isValid = true;
163                 if($this->UpdateSlotsScan->Checked === true) {
164                         $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsUpdateSlotsScan->Text) === 1;
165                 }
166                 $param->setIsValid($isValid);
167         }
168
169         public function driveUpdateSlotsScanValidator($sender, $param) {
170                 $isValid = true;
171                 if($this->UpdateSlotsScan->Checked === true) {
172                         $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveUpdateSlotsScan->Text) === 1;
173                 }
174                 $param->setIsValid($isValid);
175         }
176 }
177
178 ?>