]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/JobRunConfiguration.php
baculum: Update copyright dates
[bacula/bacula] / gui / baculum / protected / Portlets / JobRunConfiguration.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('Application.Portlets.Portlets');
22
23 class JobRunConfiguration extends Portlets {
24
25         const DEFAULT_JOB_PRIORITY = 10;
26
27         public $jobToVerify = array('C', 'O', 'd');
28
29         public $verifyOptions = array('jobname' => 'Verify by Job Name', 'jobid' => 'Verify by JobId');
30
31         public function configure($jobname) {
32                 $this->JobName->Text = $jobname;
33                 $this->Estimation->Text = '';
34
35                 $this->Level->dataSource = $this->Application->getModule('misc')->getJobLevels();
36                 $this->Level->dataBind();
37
38                 $this->JobToVerifyOptionsLine->Display = 'None';
39                 $this->JobToVerifyJobNameLine->Display = 'None';
40                 $this->JobToVerifyJobIdLine->Display = 'None';
41                 $this->AccurateLine->Display = 'Dynamic';
42                 $this->EstimateLine->Display = 'Dynamic';
43
44                 $verifyValues = array();
45
46                 foreach($this->verifyOptions as $value => $text) {
47                         $verifyValues[$value] = Prado::localize($text);
48                 }
49
50                 $this->JobToVerifyOptions->dataSource = $verifyValues;
51                 $this->JobToVerifyOptions->dataBind();
52
53                 $jobTasks = $this->Application->getModule('api')->get(array('jobs', 'tasks'))->output;
54
55                 $jobsAllDirs = array();
56                 foreach($jobTasks as $director => $tasks) {
57                         $jobsAllDirs = array_merge($jobsAllDirs, $tasks);
58                 }
59
60                 $this->JobToVerifyJobName->dataSource = array_combine($jobsAllDirs, $jobsAllDirs);
61                 $this->JobToVerifyJobName->dataBind();
62
63                 $clients = $this->Application->getModule('api')->get(array('clients'))->output;
64                 $clientsList = array();
65                 foreach($clients as $client) {
66                         $clientsList[$client->clientid] = $client->name;
67                 }
68                 $this->Client->dataSource = $clientsList;
69                 $this->Client->dataBind();
70
71                 $filesetsAll = $this->Application->getModule('api')->get(array('filesets'))->output;
72                 $filesetsList = array();
73                 foreach($filesetsAll as $director => $filesets) {
74                         $filesetsList = array_merge($filesets, $filesetsList);
75                 }
76                 $this->FileSet->dataSource = array_combine($filesetsList, $filesetsList);
77                 $this->FileSet->dataBind();
78
79                 $pools = $this->Application->getModule('api')->get(array('pools'))->output;
80                 $poolList = array();
81                 foreach($pools as $pool) {
82                         $poolList[$pool->poolid] = $pool->name;
83                 }
84                 $this->Pool->dataSource = $poolList;
85                 $this->Pool->dataBind();
86
87                 $storages = $this->Application->getModule('api')->get(array('storages'))->output;
88                 $storagesList = array();
89                 foreach($storages as $storage) {
90                         $storagesList[$storage->storageid] = $storage->name;
91                 }
92                 $this->Storage->dataSource = $storagesList;
93                 $this->Storage->dataBind();
94
95                 $this->Priority->Text = self::DEFAULT_JOB_PRIORITY;
96         }
97
98         public function run_job($sender, $param) {
99                 if($this->PriorityValidator->IsValid === false) {
100                         return false;
101                 }
102                 $params = array();
103                 $params['name'] = $this->JobName->Text;
104                 $params['level'] = $this->Level->SelectedValue;
105                 $params['fileset'] = $this->FileSet->SelectedValue;
106                 $params['clientid'] = $this->Client->SelectedValue;
107                 $params['storageid'] = $this->Storage->SelectedValue;
108                 $params['poolid'] = $this->Pool->SelectedValue;
109                 $params['priority'] = $this->Priority->Text;
110
111                 if (in_array($this->Level->SelectedItem->Value, $this->jobToVerify)) {
112                         $verifyVals = $this->getVerifyVals();
113                         if ($this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobname']) {
114                                 $params['verifyjob'] = $this->JobToVerifyJobName->SelectedValue;
115                         } elseif ($this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobid']) {
116                                 $params['jobid'] = $this->JobToVerifyJobId->Text;
117                         }
118                 }
119
120                 $result = $this->Application->getModule('api')->create(array('jobs', 'run'), $params)->output;
121                 $this->Estimation->Text = implode(PHP_EOL, $result);
122         }
123
124         public function estimate($sender, $param) {
125                 $params = array();
126                 $params['name'] = $this->JobName->Text;
127                 $params['level'] = $this->Level->SelectedValue;
128                 $params['fileset'] = $this->FileSet->SelectedValue;
129                 $params['clientid'] = $this->Client->SelectedValue;
130                 $params['accurate'] = (integer)$this->Accurate->Checked;
131                 $result = $this->Application->getModule('api')->create(array('jobs', 'estimate'), $params)->output;
132                 $this->Estimation->Text = implode(PHP_EOL, $result);
133         }
134
135         public function priorityValidator($sender, $param) {
136                 $isValid = preg_match('/^[0-9]+$/', $this->Priority->Text) === 1 && $this->Priority->Text > 0;
137                 $param->setIsValid($isValid);
138         }
139
140         public function jobIdToVerifyValidator($sender, $param) {
141                 $verifyVals = $this->getVerifyVals();
142                 if(in_array($this->Level->SelectedValue, $this->jobToVerify) && $this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobid']) {
143                         $isValid = preg_match('/^[0-9]+$/',$this->JobToVerifyJobId->Text) === 1 && $this->JobToVerifyJobId->Text > 0;
144                 } else {
145                         $isValid = true;
146                 }
147                 $param->setIsValid($isValid);
148                 return $isValid;
149         }
150
151         private function getVerifyVals() {
152                 $verifyOpt = array_keys($this->verifyOptions);
153                 $verifyVals = array_combine($verifyOpt, $verifyOpt);
154                 return $verifyVals;
155         }
156 }
157 ?>