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