]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/jobs.php
bacula-web: Added running jobs in jobs page
[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   // Running jobs
23   $running_jobs = array();
24   
25   $query  = "SELECT Job.JobId, Job.JobStatus, Status.JobStatusLong, Job.Name, Job.StartTime, Job.Level, Pool.Name AS Pool_name ";
26   $query .= "FROM Job ";
27   $query .= "JOIN Status ON Job.JobStatus = Status.JobStatus ";
28   $query .= "LEFT JOIN Pool ON Job.PoolId = Pool.PoolId ";
29   $query .= "WHERE Job.JobStatus IN ('F','S','M','m','s','j','c','d','t','C','R')";
30   
31   $jobsresult = $dbSql->db_link->query( $query );
32   
33   if( PEAR::isError( $jobsresult ) ) {
34           echo "SQL query = $query <br />";
35           die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() );
36   }else {
37           while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) {
38                 $elapsed = 'N/A';
39                 
40                 if( $job['JobStatus'] == 'R') {
41                         $elapsed = mktime() - strtotime($job['StartTime']);
42                         if( $elapsed > 3600 )
43                                 $elapsed = date( "H:i:s", $elapsed );
44                         elseif( $elapsed > 86400 )
45                                 $elapsed = date( "d day(s) i:s", $elapsed );
46                         else
47                                 $elapsed = date( "i:s", $elapsed );
48                 }
49                 $job['elapsed_time'] = $elapsed;
50                 
51                 array_push( $running_jobs, $job);
52           }
53   }
54   
55   $smarty->assign( 'running_jobs', $running_jobs );
56   
57   // Get the last jobs list
58   $query           = "";
59   $last_jobs = array();
60   
61   switch( $dbSql->driver ) 
62   {
63         case 'mysql':
64                 $query  = "SELECT SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) ) AS elapsed, ";
65         break;
66         case 'pgsql':
67                 $query  = "SELECT (Job.EndTime - Job.StartTime ) AS elapsed, "; 
68         break;
69   }
70   
71   $query .= "Job.JobId, Job.Name AS Job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus, Pool.Name AS Pool_name, Status.JobStatusLong ";
72   $query .= "FROM Job ";
73   $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
74   $query .= "LEFT JOIN Status ON Job.JobStatus = Status.JobStatus ";
75   $query .= "ORDER BY Job.EndTime DESC ";
76   $query .= "LIMIT 20";
77   
78   $jobsresult = $dbSql->db_link->query( $query );
79   
80   if( PEAR::isError( $jobsresult ) ) {
81           echo "SQL query = $query <br />";
82           die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() );
83   }else {
84           while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) {
85                 if( $job['JobStatus'] == 'T' )
86                         $job['Job_icon'] = "s_ok.gif";
87                 else
88                         $job['Job_icon'] = "s_error.gif";
89                         
90                 array_push( $last_jobs, $job);
91           }
92   }
93   $smarty->assign( 'last_jobs', $last_jobs );
94   
95   // Process and display the template 
96   $smarty->display('jobs.tpl');
97 ?>