3 * Bacula(R) - 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 original author of Bacula is Kern Sibbald, with contributions
10 * from many 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 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
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');
29 class VolumesTools extends Portlets {
31 public $labelVolumePattern = '^[0-9a-zA-Z\-_]+$';
32 public $slotsPattern = '^[0-9\-\,]+$';
33 public $drivePattern = '^[0-9]+$';
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;
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();
50 $pools = $this->Application->getModule('api')->get(array('pools'))->output;
52 foreach($pools as $pool) {
53 $poolsList[$pool->poolid] = $pool->name;
55 $this->PoolLabel->dataSource = $poolsList;
56 $this->PoolLabel->dataBind();
60 public function labelVolume($sender, $param) {
61 if($this->LabelNameValidator->isValid === false) {
64 $cmd = array('label');
65 if($this->Barcodes->Checked == true) {
67 $cmd[] = 'slots="' . $this->SlotsLabel->Text . '"';
69 $cmd[] = 'volume="' . $this->LabelName->Text . '"';
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);
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);
87 public function updateSlotsScan($sender, $param) {
88 $cmd = array('update');
89 $cmd[] = 'slots="' . $this->SlotsUpdateSlotsScan->Text . '"';
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);
97 public function setBarcodes($sender, $param) {
98 $this->LabelNameField->Display = $sender->Checked === false ? 'Dynamic' : 'None';
99 $this->BarcodeSlotsField->Display = $sender->Checked === true ? 'Dynamic' : 'None';
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';
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';
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';
120 public function labelNameValidator($sender, $param) {
122 if($this->LabelVolume->Checked === true && $this->Barcodes->Checked === false) {
123 $isValid = preg_match('/'. $this->labelVolumePattern . '/', $this->LabelName->Text) === 1;
125 $param->setIsValid($isValid);
128 public function slotsLabelValidator($sender, $param) {
130 if($this->LabelVolume->Checked === true && $this->Barcodes->Checked === true) {
131 $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsLabel->Text) === 1;
133 $param->setIsValid($isValid);
136 public function driveLabelValidator($sender, $param) {
138 if($this->LabelVolume->Checked === true) {
139 $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveLabel->Text) === 1;
141 $param->setIsValid($isValid);
144 public function slotsUpdateSlotsValidator($sender, $param) {
146 if($this->UpdateSlots->Checked === true) {
147 $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsUpdateSlots->Text) === 1;
149 $param->setIsValid($isValid);
152 public function driveUpdateSlotsValidator($sender, $param) {
154 if($this->UpdateSlots->Checked === true) {
155 $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveUpdateSlots->Text) === 1;
157 $param->setIsValid($isValid);
160 public function slotsUpdateSlotsScanValidator($sender, $param) {
162 if($this->UpdateSlotsScan->Checked === true) {
163 $isValid = preg_match('/' . $this->slotsPattern . '/', $this->SlotsUpdateSlotsScan->Text) === 1;
165 $param->setIsValid($isValid);
168 public function driveUpdateSlotsScanValidator($sender, $param) {
170 if($this->UpdateSlotsScan->Checked === true) {
171 $isValid = preg_match('/' . $this->drivePattern . '/', $this->DriveUpdateSlotsScan->Text) === 1;
173 $param->setIsValid($isValid);