]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/Portlets/JobList.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / protected / Web / 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.Web.Portlets.ISlideWindow');
28 Prado::using('Application.Web.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                 $misc = $this->Application->getModule('misc');
67                 $this->jobLevels = $misc->getJobLevels();
68                 $this->jobStates = $misc->getJobState();
69                 $this->jobTypes = $misc->getJobType();
70                 $this->runningJobStates = $misc->getRunningJobStates();
71         }
72
73         public function prepareData($sender, $param) {
74                 $params = $this->getUrlParams('jobs', $this->getPage()->JobWindow->ID);
75                 $jobs = $this->Application->getModule('api')->get($params);
76                 $isDetailView = $_SESSION['view' . $this->getPage()->JobWindow->ID] == 'details';
77                 if($isDetailView === true) {
78                         $this->RepeaterShow->Visible = false;
79                         $this->DataGridShow->Visible = true;
80                         $this->DataGrid->DataSource = $this->Application->getModule('misc')->objectToArray($jobs->output);
81                         $this->DataGrid->dataBind();
82                 } else {
83                         $this->RepeaterShow->Visible = true;
84                         $this->DataGridShow->Visible = false;
85                         $this->Repeater->DataSource = $jobs->output;
86                         $this->Repeater->dataBind();
87                 }
88         }
89
90         public function sortDataGrid($sender, $param) {
91                 $params = $this->getUrlParams('jobs', $this->getPage()->JobWindow->ID);
92                 $data = $this->Application->getModule('api')->get($params)->output;
93                 $data = $this->Application->getModule('misc')->objectToArray($data);
94                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
95                 $this->DataGrid->dataBind();
96         }
97
98         public function configure($sender, $param) {
99                 if($this->Page->IsCallBack) {
100                         $this->getPage()->JobConfiguration->configure($param->CallbackParameter);
101                 }
102         }
103
104         public function run_again($sender, $param) {
105                 if($this->Page->IsCallBack) {
106                         $this->getPage()->JobConfiguration->run_again(null, $param->CallbackParameter);
107                 }
108         }
109
110         public function executeAction($action) {
111                 $params = explode(';', $this->CheckedValues->Value);
112                 $commands = array();
113                 switch($action) {
114                         case 'delete': {
115                                 for($i = 0; $i < count($params); $i++) {
116                                         $cmd = array('delete');
117                                         $cmd[] = 'jobid="' . $params[$i] . '"';
118                                         $cmd[] = 'yes';
119                                         $cmd[] = PHP_EOL;
120                                         $commands[] = implode(' ', $cmd);
121                                 }
122                                 $this->getPage()->Console->CommandLine->Text = implode(' ', $commands);
123                                 $this->getPage()->Console->sendCommand(null, null);
124                                 break;
125                         }
126                 }
127                 $this->CheckedValues->Value = "";
128         }
129
130         public function formatJobName($name) {
131                 if (strlen($name) > 24) {
132                         $name = substr($name, 0, 10) . '...' . substr($name, -11);
133                 }
134                 return $name;
135         }
136
137         public function getJobStatusLetter($job) {
138                 $statusLetter = '';
139                 if (array_key_exists('jobstatus', $job)) {
140                         $errors = intval($job['joberrors']);
141                         if ($job['jobstatus'] === 'T' && $errors > 0) {
142                                 $job['jobstatus'] = 'W';
143                         }
144                         $statusLetter = $job['jobstatus'];
145                 }
146                 return $statusLetter;
147         }
148
149         public function getJobStatusValue($job) {
150                 $statusValue = '';
151                 $jobLetter = $this->getJobStatusLetter($job);
152                 if (array_key_exists($jobLetter, $this->jobStates)) {
153                         $statusValue = $this->jobStates[$jobLetter]['value'];
154                 }
155                 return $statusValue;
156         }
157
158         public function getJobStatusDescription($job) {
159                 $statusDescription = '';
160                 $jobLetter = $this->getJobStatusLetter($job);
161                 if (array_key_exists($jobLetter, $this->jobStates)) {
162                         $statusDescription = $this->jobStates[$jobLetter]['description'];
163                 }
164                 return $statusDescription;
165         }
166 }
167 ?>