]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/jobs.php
a16564109046a87be93c54b755a4c00364584d44
[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 ("classes.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   // Get the last 10 failed jobs
23   $query           = "";
24   $failed_jobs = array();
25   
26   switch( $dbSql->driver ) 
27   {
28         case 'mysql':
29                 $query  = "SELECT SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) ) AS elapsed, Job.JobId, Job.Name AS job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name AS pool_name, Job.JobStatus ";
30                 $query .= "FROM Job ";
31                 $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
32                 $query .= "WHERE Job.JobStatus = 'f' ";
33                 //$query .= "WHERE Job.EndTime BETWEEN <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 ";
34                 $query .= "ORDER BY Job.EndTime DESC ";  
35                 $query .= "LIMIT 10";
36  
37         break;
38         
39         case 'pgsql':
40                 $query  = "SELECT (Job.EndTime - Job.StartTime ) AS elapsed, Job.Name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus ";
41                 $query .= "FROM Job ";
42                 $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
43                 $query .= "WHERE Job.JobStatus = 'f' ";
44                 //$query .= "WHERE EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second' AND ";
45                 $query .= "ORDER BY Job.EndTime DESC";
46                 $query .= "LIMIT 10";
47         break;
48   }
49   $jobsresult = $dbSql->db_link->query( $query );
50   
51   if( PEAR::isError( $jobsresult ) ) {
52           echo "SQL query = $query <br />";
53           die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() );
54   }else {
55           while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) {
56                 array_push( $failed_jobs, $job);
57           }
58   }
59   $smarty->assign( 'failed_jobs', $failed_jobs );
60   
61   // Get the last completed jobs (last 24 hours)
62   $query           = "";
63   $completed_jobs = array();
64   
65   // Interval calculation
66   $end_date   = mktime();
67   $start_date = $end_date - LAST_DAY;
68                         
69   $start_date = date( "Y-m-d H:m:s", $start_date );
70   $end_date   = date( "Y-m-d H:m:s", $end_date );
71   
72   switch( $dbSql->driver ) 
73   {
74         case 'mysql':
75                 $query  = "SELECT SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) ) AS elapsed, Job.JobId, Job.Name AS job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name AS pool_name, Job.JobStatus ";
76                 $query .= "FROM Job ";
77                 $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
78                 $query .= "WHERE Job.JobStatus = 'T' AND ";
79                 $query .= "Job.EndTime BETWEEN '$start_date' AND '$end_date' ";
80                 $query .= "ORDER BY Job.EndTime DESC ";  
81                 
82         break;
83         
84         case 'pgsql':
85                 $query  = "SELECT (Job.EndTime - Job.StartTime ) AS elapsed, Job.Name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus ";
86                 $query .= "FROM Job ";
87                 $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
88                 $query .= "WHERE EndTime BETWEEN '$start_date' and '$end_date' ";
89                 $query .= "ORDER BY Job.EndTime DESC";
90         break;
91   }
92   $jobsresult = $dbSql->db_link->query( $query );
93   
94   if( PEAR::isError( $jobsresult ) ) {
95           echo "SQL query = $query <br />";
96           die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() );
97   }else {
98           while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) {
99                 array_push( $completed_jobs, $job);
100           }
101   }
102   $smarty->assign( 'completed_jobs', $completed_jobs );
103   
104   $smarty->display('jobs.tpl');
105 ?>