]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/JobRunList.php
baculum: Improve stability by replace framework session calls to raw PHP sessions
[bacula/bacula] / gui / baculum / protected / Portlets / JobRunList.php
1 <?php\r
2 /**\r
3  * Bacula® - The Network Backup Solution\r
4  * Baculum - Bacula web interface\r
5  *\r
6  * Copyright (C) 2013-2014 Marcin Haba\r
7  *\r
8  * The main author of Baculum is Marcin Haba.\r
9  * The main author of Bacula is Kern Sibbald, with contributions from many\r
10  * others, a complete list can be found in the file AUTHORS.\r
11  *\r
12  * You may use this file and others of this release according to the\r
13  * license defined in the LICENSE file, which includes the Affero General\r
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and\r
15  * terms pursuant to its AGPLv3 Section 7.\r
16  *\r
17  * Bacula® is a registered trademark of Kern Sibbald.\r
18  */\r
19  \r
20 Prado::using('System.Web.UI.ActiveControls.TActiveDataGrid');\r
21 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');\r
22 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');\r
23 Prado::using('System.Web.UI.ActiveControls.TActivePanel');\r
24 Prado::using('System.Web.UI.ActiveControls.TCallback');\r
25 Prado::using('Application.Portlets.Portlets');\r
26 \r
27 class JobRunList extends Portlets {
28 \r
29         public $ShowID, $windowTitle, $oldDirector;\r
30 \r
31         private $jobTypes = array('B' => 'Backup', 'M' => 'Migrated', 'V' => 'Verify', 'R' => 'Restore', 'I' => 'Internal', 'D' => 'Admin', 'A' => 'Archive', 'C' => 'Copy', 'g' => 'Migration');\r
32 \r
33         private $jobStates;\r
34         \r
35         public function onLoad($param) {
36                 parent::onLoad($param);\r
37                 $this->prepareData();\r
38         }\r
39 \r
40         public function setWindowTitle($param) {\r
41                 $this->windowTitle = $param;\r
42         }\r
43 \r
44         public function prepareData($forceReload = false) {\r
45                 $allowedButtons = array('JobRunBtn');\r
46                 if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) {\r
47                         if(in_array($this->getPage()->CallBackEventTarget->ID, $allowedButtons) || $forceReload) {\r
48                                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);\r
49                                 $jobTasks = $this->Application->getModule('api')->get($params)->output;\r
50                                 $jobs = $this->prepareJobs($jobTasks);\r
51                                 $isDetailView = $_SESSION['view' . $this->getPage()->JobRunWindow->ID] == 'details';\r
52                                 $this->RepeaterShow->Visible = !$isDetailView;\r
53                                 $this->Repeater->DataSource = $isDetailView === false ? $jobs : array();\r
54                                 $this->Repeater->dataBind();\r
55                                 $this->DataGridShow->Visible = $isDetailView;\r
56                                 $this->DataGrid->DataSource = $isDetailView === true ? $jobs : array();\r
57                                 $this->DataGrid->dataBind();\r
58                         }\r
59                 }\r
60         }\r
61  \r
62         private function prepareJobs($jobTasks) {
63                 $jobs = array();\r
64                 foreach($jobTasks as $director => $tasks) {\r
65                         for($i = 0; $i < count($tasks); $i++) {\r
66                                 $jobs[] = array('name' => $tasks[$i], 'director' => $director);\r
67                         }\r
68                 }\r
69                 return $jobs;
70         }\r
71  \r
72     public function sortDataGrid($sender, $param) {\r
73                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);\r
74                 $data = $this->Application->getModule('api')->get($params)->output;\r
75                 $data = $this->prepareJobs($data);\r
76                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);\r
77                 $this->DataGrid->dataBind();\r
78         }\r
79 \r
80         public function setShowID($ShowID) {\r
81                 $this->ShowID = $this->getMaster()->ShowID = $ShowID;\r
82         }\r
83 \r
84         public function getShowID() {\r
85                 return $this->ShowID;\r
86         }\r
87 \r
88         public function configure($sender, $param) {\r
89                 if($this->Page->IsCallBack) {\r
90                         $this->getPage()->JobRunConfiguration->configure($param->CallbackParameter);\r
91                 }\r
92         }\r
93 }\r
94 ?>