]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bacula-web/jobs.php
bacula-web: Removed useless lang.php file
[bacula/bacula] / gui / bacula-web / jobs.php
index 4ac5305fa25a9d6c8ac3adac813082ee000ab60c..5fb6fafbdbb79d44e282f18a7d3b17ee6699d5c9 100644 (file)
@@ -1,29 +1,13 @@
 <?php
-/* 
-+-------------------------------------------------------------------------+
-| Copyright (C) 2004 Juan Luis Francés Jiménez                            |
-|                                                                         |
-| This program is free software; you can redistribute it and/or           |
-| modify it under the terms of the GNU General Public License             |
-| as published by the Free Software Foundation; either version 2          |
-| of the License, or (at your option) any later version.                  |
-|                                                                         |
-| This program is distributed in the hope that it will be useful,         |
-| but WITHOUT ANY WARRANTY; without even the implied warranty of          |
-| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
-| GNU General Public License for more details.                            |
-+-------------------------------------------------------------------------+ 
-*/
   session_start();
-  require ("paths.php");
-  require($smarty_path."Smarty.class.php");
-  include "classes.inc.php";
+  require_once ("paths.php");
+  require_once ($smarty_path."Smarty.class.php");
+  require_once ("bweb.inc.php");
+  require_once ("config.inc.php");  
 
   $smarty = new Smarty();     
   $dbSql = new Bweb();
 
-  require("lang.php");
-
   // Smarty configuration
   $smarty->compile_check = true;
   $smarty->debugging = false;
   $smarty->compile_dir = "./templates_c";
   $smarty->config_dir     = "./configs";
   
-  // Get the last 10 failed jobs
+  // Jobs list
   $query          = "";
-  $failed_jobs = array();
+  $last_jobs = array();
+  
+  // Job Status list
+  $job_status = array( 'Any', 'Waiting', 'Running', 'Completed', 'Failed', 'Canceled' );
+  $smarty->assign( 'job_status', $job_status );
+  
+  // Jobs per page
+  $jobs_per_page = array( 25,50,75,100,150 );
+  $smarty->assign( 'jobs_per_page', $jobs_per_page );
+
+  // Global variables
+  $job_level = array( 'D' => 'Diff', 'I' => 'Incr', 'F' => 'Full' );
   
-  switch( $dbSql->driver ) 
-  {
-       case 'mysql':
-               $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 ";
-               $query .= "FROM Job ";
-               $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
-               $query .= "WHERE Job.JobStatus = 'f' ";
-               //$query .= "WHERE Job.EndTime BETWEEN <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 ";
-               $query .= "ORDER BY Job.EndTime DESC ";  
-               $query .= "LIMIT 10";
-       break;
-       
-       case 'pgsql':
-               $query  = "select (Job.EndTime - Job.StartTime ) AS elapsed, Job.Name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus ";
-               $query .= "FROM Job ";
-               $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
-               $query .= "WHERE EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second' ";
-               $query .= "ORDER BY Job.EndTime DESC";
-               $query .= "LIMIT 10";
-       break;
+  $query .= "SELECT Job.JobId, Job.Name AS Job_name, Job.StartTime, Job.EndTime, Job.Level, Job.JobBytes, Job.JobFiles, Pool.Name, Job.JobStatus, Pool.Name AS Pool_name, Status.JobStatusLong ";
+  $query .= "FROM Job ";
+  $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
+  $query .= "LEFT JOIN Status ON Job.JobStatus = Status.JobStatus ";
+  
+  // Filter by status
+  if( isset( $_POST['status'] ) ) {
+       switch( strtolower( $_POST['status'] ) )
+       {
+               case 'running':
+                       $query .= "WHERE Job.JobStatus = 'R' ";
+               break;
+               case 'waiting':
+                       $query .= "WHERE Job.JobStatus IN ('F','S','M','m','s','j','c','d','t','C') ";
+               break;
+               case 'completed':
+                       $query .= "WHERE Job.JobStatus = 'T' ";
+               break;
+               case 'failed':
+                       $query .= "WHERE Job.JobStatus IN ('f','E') ";
+               break;
+               case 'canceled':
+                       $query .= "WHERE Job.JobStatus = 'A' ";
+               break;
+       }
   }
+  
+  // order by
+  $query .= "ORDER BY Job.JobId DESC ";
+  
+  // Determine how many jobs to display
+  if( isset($_POST['jobs_per_page']) )
+       $query .= "LIMIT " . $_POST['jobs_per_page'];
+  else
+       $query .= "LIMIT 25 ";
+  
+  //echo $query . '<br />';
+  
   $jobsresult = $dbSql->db_link->query( $query );
   
   if( PEAR::isError( $jobsresult ) ) {
          die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() );
   }else {
          while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) {
-               array_push( $failed_jobs, $job);
+               
+               // Determine icon for job status
+               switch( $job['JobStatus'] ) {
+                       case 'R':
+                               $job['Job_icon'] = "running.png";
+                       break;
+                       case 'T':
+                               $job['Job_icon'] = "s_ok.png";
+                       break;
+                       case 'A':
+                       case 'f':
+                       case 'E':
+                               $job['Job_icon'] = "s_error.gif";
+                       break;
+                       case 'F':
+                       case 'S':
+                       case 'M':
+                       case 'm':
+                       case 's':
+                       case 'j':
+                       case 'c':
+                       case 'd':
+                       case 't':
+                       case 'C':
+                               $job['Job_icon'] = "waiting.png";
+                       break;
+               } // end switch
+               
+               // Odd or even row
+               if( count($last_jobs) % 2)
+                       $job['Job_classe'] = 'odd';
+               
+               // Elapsed time for the job
+               if( $job['StartTime'] == '0000-00-00 00:00:00' )
+                       $job['elapsed_time'] = 'N/A';
+               elseif( $job['EndTime'] == '0000-00-00 00:00:00' )
+                       $job['elapsed_time'] = $dbSql->Get_ElapsedTime( strtotime($job['StartTime']), mktime() );
+               else
+                       $job['elapsed_time'] = $dbSql->Get_ElapsedTime( strtotime($job['StartTime']), strtotime($job['EndTime']) );
+
+               // Job Level
+        $job['Level'] = $job_level[ $job['Level'] ];
+               
+               // Job Size
+               $job['JobBytes'] = $dbSql->human_file_size( $job['JobBytes'] );
+
+               array_push( $last_jobs, $job);
          }
   }
-  $smarty->assign( 'failed_jobs', $failed_jobs );
+  $smarty->assign( 'last_jobs', $last_jobs );
+  
+  // Count jobs
+  if( isset( $_POST['status'] ) )
+       $total_jobs = $dbSql->CountJobs( ALL, $_POST['status'] );
+  else
+       $total_jobs = $dbSql->CountJobs( ALL );
+  
+  $smarty->assign( 'total_jobs', $total_jobs );
   
+  // Process and display the template 
   $smarty->display('jobs.tpl');
 ?>