]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/JobList.php
Update ReleaseNotes + ChangeLog
[bacula/bacula] / gui / baculum / protected / Portlets / JobList.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 Kern Sibbald
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.TActiveDataGrid');
24 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
25 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
26 Prado::using('System.Web.UI.ActiveControls.TCallback');
27 Prado::using('Application.Portlets.ISlideWindow');
28 Prado::using('Application.Portlets.Portlets');
29
30 class JobList extends Portlets implements ISlideWindow {
31
32         public $ID;
33         public $buttonID;
34         public $windowTitle;
35         public $jobLevels;
36         public $jobStates;
37         public $runningJobStates;
38         public $jobTypes;
39
40         public function setID($id) {
41                 $this->ID = $id;
42         }
43
44         public function getID($hideAutoID = true) {
45                 return $this->ID;
46         }
47
48         public function setButtonID($id) {
49                 $this->buttonID = $id;
50         }
51
52         public function getButtonID() {
53                 return $this->buttonID;
54         }
55
56         public function setWindowTitle($param) {
57                 $this->windowTitle = $param;
58         }
59
60         public function getWindowTitle() {
61                 return $this->windowTitle;
62         }
63
64         public function onLoad($param) {
65                 parent::onLoad($param);
66                 $allowedButtons = array('JobBtn', 'ReloadJobs', 'Run', 'RunJobAgain');
67                 if($this->Page->IsPostBack || $this->Page->IsCallBack) {
68                         if(in_array($this->getPage()->CallBackEventTarget->ID, $allowedButtons)) {
69                                 $this->prepareData();
70                         }
71                 }
72                 $misc = $this->Application->getModule('misc');
73                 $this->jobLevels = $misc->getJobLevels();
74                 $this->jobStates = $misc->getJobState();
75                 $this->jobTypes = $misc->getJobType();
76                 $this->runningJobStates = $misc->getRunningJobStates();
77         }
78
79         public function prepareData($forceReload = false) {
80                 $allowedButtons = array('JobBtn', 'ReloadJobs', 'Run', 'RunJobAgain');
81                 if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) {
82                         if(in_array($this->getPage()->CallBackEventTarget->ID, $allowedButtons) || $forceReload) {
83                                 $params = $this->getUrlParams('jobs', $this->getPage()->JobWindow->ID);
84                                 $jobs = $this->Application->getModule('api')->get($params);
85                                 $isDetailView = $_SESSION['view' . $this->getPage()->JobWindow->ID] == 'details';
86                                 if($isDetailView === true) {
87                                         $this->RepeaterShow->Visible = false;
88                                         $this->DataGridShow->Visible = true;
89                                         $this->DataGrid->DataSource = $this->Application->getModule('misc')->objectToArray($jobs->output);
90                                         $this->DataGrid->dataBind();
91                                 } else {
92                                         $this->RepeaterShow->Visible = true;
93                                         $this->DataGridShow->Visible = false;
94                                         $this->Repeater->DataSource = $jobs->output;
95                                         $this->Repeater->dataBind();
96                                 }
97                         }
98                 }
99         }
100
101         public function sortDataGrid($sender, $param) {
102                 $params = $this->getUrlParams('jobs', $this->getPage()->JobWindow->ID);
103                 $data = $this->Application->getModule('api')->get($params)->output;
104                 $data = $this->Application->getModule('misc')->objectToArray($data);
105                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
106                 $this->DataGrid->dataBind();
107         }
108
109         public function configure($sender, $param) {
110                 if($this->Page->IsCallBack) {
111                         $this->getPage()->JobConfiguration->configure($param->CallbackParameter);
112                 }
113         }
114
115         public function run_again($sender, $param) {
116                 if($this->Page->IsCallBack) {
117                         $this->getPage()->JobConfiguration->run_again(null, $param->CallbackParameter);
118                 }
119         }
120
121         public function executeAction($action) {
122                 $params = explode(';', $this->CheckedValues->Value);
123                 $commands = array();
124                 switch($action) {
125                         case 'delete': {
126                                 for($i = 0; $i < count($params); $i++) {
127                                         $cmd = array('delete');
128                                         $cmd[] = 'jobid="' . $params[$i] . '"';
129                                         $cmd[] = 'yes';
130                                         $cmd[] = PHP_EOL;
131                                         $commands[] = implode(' ', $cmd);
132                                 }
133                                 $this->getPage()->Console->CommandLine->Text = implode(' ', $commands);
134                                 $this->getPage()->Console->sendCommand(null, null);
135                                 break;
136                         }
137                 }
138                 $this->CheckedValues->Value = "";
139         }
140
141         public function formatJobName($name) {
142                 if (strlen($name) > 24) {
143                         $name = substr($name, 0, 10) . '...' . substr($name, -11);
144                 }
145                 return $name;
146         }
147
148         public function getJobStatusLetter($job) {
149                 $statusLetter = '';
150                 if (array_key_exists('jobstatus', $job)) {
151                         $errors = intval($job['joberrors']);
152                         if ($job['jobstatus'] === 'T' && $errors > 0) {
153                                 $job['jobstatus'] = 'W';
154                         }
155                         $statusLetter = $job['jobstatus'];
156                 }
157                 return $statusLetter;
158         }
159
160         public function getJobStatusValue($job) {
161                 $statusValue = '';
162                 $jobLetter = $this->getJobStatusLetter($job);
163                 if (array_key_exists($jobLetter, $this->jobStates)) {
164                         $statusValue = $this->jobStates[$jobLetter]['value'];
165                 }
166                 return $statusValue;
167         }
168
169         public function getJobStatusDescription($job) {
170                 $statusDescription = '';
171                 $jobLetter = $this->getJobStatusLetter($job);
172                 if (array_key_exists($jobLetter, $this->jobStates)) {
173                         $statusDescription = $this->jobStates[$jobLetter]['description'];
174                 }
175                 return $statusDescription;
176         }
177 }
178 ?>