]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/VolumesTools.php
baculum: Assign Baculum copyright to Kern Sibbald
[bacula/bacula] / gui / baculum / protected / 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.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                 }
71                 $cmd[] = 'drive="' . $this->DriveLabel->Text . '"';
72                 $cmd[] = 'storage="'. $this->StorageLabel->SelectedItem->Text . '"';
73                 $cmd[] = 'pool="'. $this->PoolLabel->SelectedItem->Text . '"';
74                 $this->getPage()->Console->CommandLine->Text = implode(' ', $cmd);
75                 $this->getPage()->Console->sendCommand($sender, $param);
76         }
77
78         public function updateSlots($sender, $param) {
79                 $cmd = array('update');
80                 $cmd[] = 'slots="' . $this->SlotsUpdateSlots->Text . '"';
81                 $cmd[] = 'drive="' . $this->DriveUpdateSlots->Text . '"';
82                 $cmd[] = 'storage="'. $this->StorageUpdateSlots->SelectedItem->Text . '"';
83                 $this->getPage()->Console->CommandLine->Text = implode(' ', $cmd);
84                 $this->getPage()->Console->sendCommand($sender, $param);
85         }
86
87         public function updateSlotsScan($sender, $param) {
88                 $cmd = array('update');
89                 $cmd[] = 'slots="' . $this->SlotsUpdateSlotsScan->Text . '"';
90                 $cmd[] = 'scan';
91                 $cmd[] = 'drive="' . $this->DriveUpdateSlotsScan->Text . '"';
92                 $cmd[] = 'storage="'. $this->StorageUpdateSlotsScan->SelectedItem->Text . '"';
93                 $this->getPage()->Console->CommandLine->Text = implode(' ', $cmd);
94                 $this->getPage()->Console->sendCommand($sender, $param);
95         }
96
97         public function setBarcodes($sender, $param) {
98                 $this->LabelNameField->Display = $sender->Checked === false ? 'Dynamic' : 'None';
99                 $this->BarcodeSlotsField->Display = $sender->Checked === true ? 'Dynamic' : 'None';
100         }
101
102         public function setLabelVolume($sender, $param) {
103                 $this->Labeling->Display = $sender->Checked === true ? 'Dynamic' : 'None';
104                 $this->UpdatingSlots->Display = 'None';
105                 $this->UpdatingSlotsScan->Display = 'None';
106         }
107
108         public function setUpdateSlots($sender, $param) {
109                 $this->UpdatingSlots->Display = $sender->Checked === true ? 'Dynamic' : 'None';
110                 $this->Labeling->Display = 'None';
111                 $this->UpdatingSlotsScan->Display = 'None';
112         }
113
114         public function setUpdateSlotsScan($sender, $param) {
115                 $this->UpdatingSlotsScan->Display = $sender->Checked === true ? 'Dynamic' : 'None';
116                 $this->UpdatingSlots->Display = 'None';
117                 $this->Labeling->Display = 'None';
118         }
119
120         public function labelNameValidator($sender, $param) {
121                 $isValid = true;
122                 if($this->LabelVolume->Checked === true && $this->Barcodes->Checked === false) {
123                         $isValid = preg_match('/'. $this->labelVolumePattern . '/', $this->LabelName->Text) === 1;
124                 }
125                 $param->setIsValid($isValid);
126         }
127
128         public function slotsLabelValidator($sender, $param) {
129                 $isValid = true;
130                 if($this->LabelVolume->Checked === true && $this->Barcodes->Checked === true) {
131                         $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsLabel->Text) === 1;
132                 }
133                 $param->setIsValid($isValid);
134         }
135
136         public function driveLabelValidator($sender, $param) {
137                 $isValid = true;
138                 if($this->LabelVolume->Checked === true) {
139                         $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveLabel->Text) === 1;
140                 }
141                 $param->setIsValid($isValid);
142         }
143
144         public function slotsUpdateSlotsValidator($sender, $param) {
145                 $isValid = true;
146                 if($this->UpdateSlots->Checked === true) {
147                         $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsUpdateSlots->Text) === 1;
148                 }
149                 $param->setIsValid($isValid);
150         }
151
152         public function driveUpdateSlotsValidator($sender, $param) {
153                 $isValid = true;
154                 if($this->UpdateSlots->Checked === true) {
155                         $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveUpdateSlots->Text) === 1;
156                 }
157                 $param->setIsValid($isValid);
158         }
159
160         public function slotsUpdateSlotsScanValidator($sender, $param) {
161                 $isValid = true;
162                 if($this->UpdateSlotsScan->Checked === true) {
163                         $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsUpdateSlotsScan->Text) === 1;
164                 }
165                 $param->setIsValid($isValid);
166         }
167
168         public function driveUpdateSlotsScanValidator($sender, $param) {
169                 $isValid = true;
170                 if($this->UpdateSlotsScan->Checked === true) {
171                         $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveUpdateSlotsScan->Text) === 1;
172                 }
173                 $param->setIsValid($isValid);
174         }
175 }
176
177 ?>