]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/JobRunList.php
baculum: Update copyright dates
[bacula/bacula] / gui / baculum / protected / Portlets / JobRunList.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.TActiveDataGrid');
21 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
22 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
23 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
24 Prado::using('System.Web.UI.ActiveControls.TCallback');
25 Prado::using('Application.Portlets.ISlideWindow');
26 Prado::using('Application.Portlets.Portlets');
27
28 class JobRunList extends Portlets implements ISlideWindow {
29
30         public $ID;
31         public $buttonID;
32         public $windowTitle;
33         public $oldDirector;
34         private $jobStates;
35         private $jobTypes = array(
36                 'B' => 'Backup',
37                 'M' => 'Migrated',
38                 'V' => 'Verify',
39                 'R' => 'Restore',
40                 'I' => 'Internal',
41                 'D' => 'Admin',
42                 'A' => 'Archive',
43                 'C' => 'Copy',
44                 'g' => 'Migration'
45         );
46
47         public function setID($id) {
48                 $this->ID = $id;
49         }
50
51         public function getID($hideAutoID = true) {
52                 return $this->ID;
53         }
54
55         public function setButtonID($id) {
56                 $this->buttonID = $id;
57         }
58
59         public function getButtonID() {
60                 return $this->buttonID;
61         }
62
63         public function setWindowTitle($param) {
64                 $this->windowTitle = $param;
65         }
66
67         public function getWindowTitle() {
68                 return $this->windowTitle;
69         }
70
71         public function onLoad($param) {
72                 parent::onLoad($param);
73                 $this->prepareData();
74         }
75
76         public function prepareData($forceReload = false) {
77                 $allowedButtons = array('JobRunBtn');
78                 if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) {
79                         if(in_array($this->getPage()->CallBackEventTarget->ID, $allowedButtons) || $forceReload) {
80                                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);
81                                 $jobTasks = $this->Application->getModule('api')->get($params)->output;
82                                 $jobs = $this->prepareJobs($jobTasks);
83                                 $isDetailView = $_SESSION['view' . $this->getPage()->JobRunWindow->ID] == 'details';
84
85                                 if($isDetailView === true) {
86                                         $this->RepeaterShow->Visible = false;
87                                         $this->DataGridShow->Visible = true;
88                                         $this->DataGrid->DataSource = $jobs;
89                                         $this->DataGrid->dataBind();
90                                 } else {
91                                         $this->RepeaterShow->Visible = true;
92                                         $this->DataGridShow->Visible = false;
93                                         $this->Repeater->DataSource = $jobs;
94                                         $this->Repeater->dataBind();
95                                 }
96                         }
97                 }
98         }
99
100         private function prepareJobs($jobTasks) {
101                 $jobs = array();
102                 foreach($jobTasks as $director => $tasks) {
103                         for($i = 0; $i < count($tasks); $i++) {
104                                 $jobs[] = array('name' => $tasks[$i], 'director' => $director);
105                         }
106                 }
107                 return $jobs;
108         }
109
110         public function sortDataGrid($sender, $param) {
111                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);
112                 $data = $this->Application->getModule('api')->get($params)->output;
113                 $data = $this->prepareJobs($data);
114                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
115                 $this->DataGrid->dataBind();
116         }
117
118         public function configure($sender, $param) {
119                 if($this->Page->IsCallBack) {
120                         $this->getPage()->JobRunConfiguration->configure($param->CallbackParameter);
121                 }
122         }
123 }
124 ?>