]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bacula-web/jobs.php
bacula-web: Modified usage of Get_ElapsedTime() function to TimeUtils::Get_Elapsed_Time()
[bacula/bacula] / gui / bacula-web / jobs.php
index cc41205559a5c3283a88039c43fa4db10e9f268d..721e98a590cc71d55fc3a38884834960863ae6b4 100644 (file)
@@ -1,36 +1,39 @@
 <?php
+/* 
++-------------------------------------------------------------------------+
+| Copyright 2010-2011, Davide Franco                                             |
+|                                                                         |
+| 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_once ("paths.php");
-  require_once ($smarty_path."Smarty.class.php");
-  require_once ("bweb.inc.php");
-  require_once ("config.inc.php");  
+  include_once( 'config.inc.php' );
 
-  $smarty = new Smarty();     
   $dbSql = new Bweb();
-
-  require("lang.php");
-
-  // Smarty configuration
-  $smarty->compile_check = true;
-  $smarty->debugging = false;
-  $smarty->force_compile = true;
-
-  $smarty->template_dir = "./templates";
-  $smarty->compile_dir = "./templates_c";
-  $smarty->config_dir     = "./configs";
-  
   // Jobs list
   $query          = "";
   $last_jobs = array();
   
   // Job Status list
   $job_status = array( 'Any', 'Waiting', 'Running', 'Completed', 'Failed', 'Canceled' );
-  $smarty->assign( 'job_status', $job_status );
+  $dbSql->tpl->assign( 'job_status', $job_status );
   
+  // Jobs per page
+  $jobs_per_page = array( 25,50,75,100,150 );
+  $dbSql->tpl->assign( 'jobs_per_page', $jobs_per_page );
+
   // Global variables
   $job_level = array( 'D' => 'Diff', 'I' => 'Incr', 'F' => 'Full' );
   
-  $query .= "SELECT Job.JobId, Job.Name AS Job_name, Job.StartTime, Job.EndTime, Job.Level, Job.JobBytes, Pool.Name, Job.JobStatus, Pool.Name AS Pool_name, Status.JobStatusLong ";
+  $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 ";
                        $query .= "WHERE Job.JobStatus = 'R' ";
                break;
                case 'waiting':
-                       $query .= "WHERE Job.JobStatus IN ('F','S','M','m','s','j','c','d','t','C','R') ";
+                       $query .= "WHERE Job.JobStatus IN ('F','S','M','m','s','j','c','d','t','p','C') ";
                break;
                case 'completed':
-                       $query .= "WHERE Job.JobStatus = 'T' ";
+                       $query .= "WHERE Job.JobStatus IN ('T', 'E') ";
                break;
                case 'failed':
                        $query .= "WHERE Job.JobStatus = 'f' ";
   $query .= "ORDER BY Job.JobId DESC ";
   
   // Determine how many jobs to display
-  if( isset($_POST['limit']) )
-       $query .= "LIMIT " . $_POST['limit'];
+  if( isset($_POST['jobs_per_page']) )
+       $query .= "LIMIT " . $_POST['jobs_per_page'];
   else
-       $query .= "LIMIT 20 ";
+       $query .= "LIMIT 25 ";
   
   //echo $query . '<br />';
   
                
                // Determine icon for job status
                switch( $job['JobStatus'] ) {
-                       case 'R':
+                       case J_RUNNING:
                                $job['Job_icon'] = "running.png";
                        break;
-                       case 'T':
-                               $job['Job_icon'] = "s_ok.png";
+                       case J_COMPLETED:
+                               $job['Job_icon'] = "ok.png";
+                       break;
+                       case J_CANCELED:
+                               $job['Job_icon'] = "canceled.png";
                        break;
-                       case 'A':
-                       case 'f':
-                       case 'E':
-                               $job['Job_icon'] = "s_error.gif";
+                       case J_COMPLETED_ERROR:
+                               $job['Job_icon'] = "warning.png";
                        break;
-                       case 'F':
-                       case 'S':
-                       case 'M':
-                       case 'm':
-                       case 's':
-                       case 'j':
-                       case 'c':
-                       case 'd':
-                       case 't':
-                       case 'C':
+                       case J_FATAL:
+                               $job['Job_icon'] = "error.png";
+                       break;
+                       case J_WAITING_CLIENT:
+                       case J_WAITING_SD:
+                       case J_WAITING_MOUNT_MEDIA:
+                       case J_WAITING_NEW_MEDIA:
+                       case J_WAITING_STORAGE_RES:
+                       case J_WAITING_JOB_RES:
+                       case J_WAITING_CLIENT_RES:
+                       case J_WAITING_MAX_JOBS:
+                       case J_WAITING_START_TIME:
+                       case J_NOT_RUNNING:
                                $job['Job_icon'] = "waiting.png";
                        break;
                } // end switch
                        $job['Job_classe'] = 'odd';
                
                // Elapsed time for the job
-               if( $job['StartTime'] == '0000-00-00 00:00:00' )
+               $start = $job['StartTime'];
+               $end   = $job['EndTime'];
+
+               if( $start == '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() );
+               elseif( $end == '0000-00-00 00:00:00' )
+                       $job['elapsed_time'] = TimeUtils::Get_Elapsed_Time( strtotime($start), mktime() ); 
                else
-                       $job['elapsed_time'] = $dbSql->Get_ElapsedTime( strtotime($job['StartTime']), strtotime($job['EndTime']) );
+                       $job['elapsed_time'] = TimeUtils::Get_Elapsed_Time( strtotime($start), strtotime($end) ); 
 
                // Job Level
-        $job['Level'] = $job_level[ $job['Level'] ];
+               $job['Level'] = $job_level[ $job['Level'] ];
                
                // Job Size
-               $job['JobBytes'] = $dbSql->human_file_size( $job['JobBytes'] );
+               $job['JobBytes'] = Utils::Get_Human_Size( $job['JobBytes'] );
 
                array_push( $last_jobs, $job);
          }
   }
-  $smarty->assign( 'last_jobs', $last_jobs );
+  $dbSql->tpl->assign( 'last_jobs', $last_jobs );
   
   // Count jobs
   if( isset( $_POST['status'] ) )
   else
        $total_jobs = $dbSql->CountJobs( ALL );
   
-  $smarty->assign( 'total_jobs', $total_jobs );
+  $dbSql->tpl->assign( 'total_jobs', $total_jobs );
   
   // Process and display the template 
-  $smarty->display('jobs.tpl');
+  $dbSql->tpl->display('jobs.tpl');
 ?>