]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/jobs.php
fba9becf79635456a005ea8a7e2fc511e831abc9
[bacula/bacula] / gui / bacula-web / jobs.php
1 <?php
2   session_start();
3   require_once ("paths.php");
4   require_once ($smarty_path."Smarty.class.php");
5   require_once ("bweb.inc.php");
6   require_once ("config.inc.php");  
7
8   $smarty = new Smarty();     
9   $dbSql = new Bweb();
10
11   require("lang.php");
12
13   // Smarty configuration
14   $smarty->compile_check = true;
15   $smarty->debugging = false;
16   $smarty->force_compile = true;
17
18   $smarty->template_dir = "./templates";
19   $smarty->compile_dir = "./templates_c";
20   $smarty->config_dir     = "./configs";
21   
22   // Global variables
23   $job_status = array( 'D' => 'Diff', 'I' => 'Incr', 'F' => 'Full' );
24
25   // Running jobs
26   $running_jobs = array();
27   
28   $query  = "SELECT Job.JobId, Job.JobStatus, Status.JobStatusLong, Job.Name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name AS Pool_name ";
29   $query .= "FROM Job ";
30   $query .= "JOIN Status ON Job.JobStatus = Status.JobStatus ";
31   $query .= "LEFT JOIN Pool ON Job.PoolId = Pool.PoolId ";
32   $query .= "WHERE Job.JobStatus IN ('F','S','M','m','s','j','c','d','t','C','R')";
33   $query .= "ORDER BY JobId";
34   
35   $jobsresult = $dbSql->db_link->query( $query );
36   
37   if( PEAR::isError( $jobsresult ) ) {
38           echo "SQL query = $query <br />";
39           die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() );
40   }else {
41           while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) {
42         
43                 // Elapsed time for this job
44                 $elapsed = 'N/A';
45                 if( $job['JobStatus'] == 'R' )
46                         $job['elapsed_time'] = $dbSql->Get_ElapsedTime( strtotime($job['StartTime']), time() );
47                 else
48                         $job['elapsed_time'] = 'N/A';
49                         
50                 // Odd or even row
51                 if( count($running_jobs) % 2)
52                         $job['Job_classe'] = 'odd';
53
54                 // Job Status
55                 $job['Level'] = $job_status[ $job['Level'] ];
56                 
57                 array_push( $running_jobs, $job);
58           }
59   }
60   
61   $smarty->assign( 'running_jobs', $running_jobs );
62   
63   // Get the last jobs list
64   $query           = "";
65   $last_jobs = array();
66   
67   $query .= "SELECT Job.JobId, Job.Name AS Job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus, Pool.Name AS Pool_name, Status.JobStatusLong ";
68   $query .= "FROM Job ";
69   $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
70   $query .= "LEFT JOIN Status ON Job.JobStatus = Status.JobStatus ";
71   
72   // Filter by status
73   if( isset( $_POST['status'] ) ) {
74         switch( $_POST['status'] )
75         {
76                 case 'completed':
77                         $query .= "WHERE Job.JobStatus = 'T' ";
78                 break;
79                 case 'failed':
80                         $query .= "WHERE Job.JobStatus = 'f' ";
81                 break;
82                 case 'canceled':
83                         $query .= "WHERE Job.JobStatus = 'A' ";
84                 break;
85         }
86   }
87   
88   $query .= "ORDER BY Job.EndTime DESC ";
89   
90   // Determine how many jobs to display
91   if( isset($_POST['limit']) )
92         $query .= "LIMIT " . $_POST['limit'];
93   else
94         $query .= "LIMIT 20 ";
95   
96   $jobsresult = $dbSql->db_link->query( $query );
97   
98   if( PEAR::isError( $jobsresult ) ) {
99           echo "SQL query = $query <br />";
100           die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() );
101   }else {
102           while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) {
103                 // Determine icon for job
104                 if( $job['JobStatus'] == 'T' )
105                         $job['Job_icon'] = "s_ok.gif";
106                 else
107                         $job['Job_icon'] = "s_error.gif";
108                 
109                 // Odd or even row
110                 if( count($last_jobs) % 2)
111                         $job['Job_classe'] = 'odd';
112                 
113                 // Elapsed time for this job
114                 $job['elapsed_time'] = $dbSql->Get_ElapsedTime( strtotime($job['StartTime']), strtotime($job['EndTime']) );
115
116                 // Job Status
117                 $job['Level'] = $job_status[ $job['Level'] ];
118
119                 array_push( $last_jobs, $job);
120           }
121   }
122   $smarty->assign( 'last_jobs', $last_jobs );
123   
124   if( isset( $_POST['status'] ) )
125         $total_jobs = $dbSql->CountJobs( ALL, $_POST['status'] );
126   else
127         $total_jobs = $dbSql->CountJobs( ALL );
128   
129   $smarty->assign( 'total_jobs', $total_jobs );
130   
131   // Process and display the template 
132   $smarty->display('jobs.tpl');
133 ?>