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