3 * Bacula® - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2015 Marcin Haba
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.
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.
17 * Bacula® is a registered trademark of Kern Sibbald.
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');
26 class VolumesTools extends Portlets {
28 public $labelVolumePattern = '^[0-9a-zA-Z\-_]+$';
29 public $slotsPattern = '^[0-9\-\,]+$';
30 public $drivePattern = '^[0-9]+$';
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;
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();
47 $pools = $this->Application->getModule('api')->get(array('pools'))->output;
49 foreach($pools as $pool) {
50 $poolsList[$pool->poolid] = $pool->name;
52 $this->PoolLabel->dataSource = $poolsList;
53 $this->PoolLabel->dataBind();
57 public function labelVolume($sender, $param) {
58 if($this->LabelNameValidator->isValid === false) {
61 $cmd = array('label');
62 if($this->Barcodes->Checked == true) {
64 $cmd[] = 'slots="' . $this->SlotsLabel->Text . '"';
66 $cmd[] = 'volume="' . $this->LabelName->Text . '"';
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);
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);
84 public function updateSlotsScan($sender, $param) {
85 $cmd = array('update');
86 $cmd[] = 'slots="' . $this->SlotsUpdateSlotsScan->Text . '"';
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);
94 public function setBarcodes($sender, $param) {
95 $this->LabelNameField->Display = $sender->Checked === false ? 'Dynamic' : 'None';
96 $this->BarcodeSlotsField->Display = $sender->Checked === true ? 'Dynamic' : 'None';
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';
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';
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';
117 public function labelNameValidator($sender, $param) {
119 if($this->LabelVolume->Checked === true && $this->Barcodes->Checked === false) {
120 $isValid = preg_match('/'. $this->labelVolumePattern . '/', $this->LabelName->Text) === 1;
122 $param->setIsValid($isValid);
125 public function slotsLabelValidator($sender, $param) {
127 if($this->LabelVolume->Checked === true && $this->Barcodes->Checked === true) {
128 $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsLabel->Text) === 1;
130 $param->setIsValid($isValid);
133 public function driveLabelValidator($sender, $param) {
135 if($this->LabelVolume->Checked === true) {
136 $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveLabel->Text) === 1;
138 $param->setIsValid($isValid);
141 public function slotsUpdateSlotsValidator($sender, $param) {
143 if($this->UpdateSlots->Checked === true) {
144 $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsUpdateSlots->Text) === 1;
146 $param->setIsValid($isValid);
149 public function driveUpdateSlotsValidator($sender, $param) {
151 if($this->UpdateSlots->Checked === true) {
152 $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveUpdateSlots->Text) === 1;
154 $param->setIsValid($isValid);
157 public function slotsUpdateSlotsScanValidator($sender, $param) {
159 if($this->UpdateSlotsScan->Checked === true) {
160 $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsUpdateSlotsScan->Text) === 1;
162 $param->setIsValid($isValid);
165 public function driveUpdateSlotsScanValidator($sender, $param) {
167 if($this->UpdateSlotsScan->Checked === true) {
168 $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveUpdateSlotsScan->Text) === 1;
170 $param->setIsValid($isValid);