From 4addcb20e123871754e8a3a34e29a5e65da1cfd4 Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Wed, 22 Dec 2010 11:44:06 +0100 Subject: [PATCH] bacula-web: Internal code improvments and Jobs number result in jobs page - Added info in jobs page result - Improved CountJobs function in bweb.inc.php (jobs number returned directly - Adapted CountJobs function call in index.php and jobs.php --- gui/bacula-web/bweb.inc.php | 54 ++++++++++++++++++++----------- gui/bacula-web/index.php | 6 ++-- gui/bacula-web/jobs.php | 7 ++++ gui/bacula-web/templates/jobs.tpl | 3 ++ 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php index 3b5fc635c5..2d584c30ce 100644 --- a/gui/bacula-web/bweb.inc.php +++ b/gui/bacula-web/bweb.inc.php @@ -342,36 +342,52 @@ class Bweb extends DB { return $volumes; } // end function GetVolumeList() - public function CountJobs( $delay = LAST_DAY, $status ) + public function CountJobs( $delay = LAST_DAY, $status = 'any' ) { - $query = "SELECT COUNT(JobId) AS job_nb FROM Job "; + $query = "SELECT COUNT(JobId) AS job_nb FROM Job "; + $where_delay = ""; + $where_status = ""; // Interval condition for SQL query - $end_date = mktime(); - $start_date = $end_date - $delay; + if( $delay != ALL ) { + $end_date = mktime(); + $start_date = $end_date - $delay; - $start_date = date( "Y-m-d H:i:s", $start_date ); - $end_date = date( "Y-m-d H:i:s", $end_date ); + $start_date = date( "Y-m-d H:i:s", $start_date ); + $end_date = date( "Y-m-d H:i:s", $end_date ); - $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' "; + $where_delay = "WHERE EndTime BETWEEN '$start_date' AND '$end_date' "; + } - // Job Status for SQL query - switch( $status ) - { - case 'completed': - $query .= "AND JobStatus = 'T' "; - break; - case 'failed': - $query .= "AND JobStatus = 'f' "; - break; - } // end switch + if( $status != 'any' ) { + switch( $status ) + { + case 'completed': + $where_status = "JobStatus = 'T' "; + break; + case 'failed': + $where_status = "JobStatus = 'f' "; + break; + case 'canceled': + $where_status = "JobStatus = 'A' "; + break; + } // end switch + } + if( !empty($where_delay) ) + $query = $query . $where_delay . 'AND ' . $where_status; + else { + if( !empty($where_status) ) + $query = $query . 'WHERE ' . $where_status; + } + $jobs = $this->db_link->query( $query ); if (PEAR::isError( $jobs ) ) { - die( "Unable to get last $status jobs number from catalog
" . $status->getMessage() ); + die( "Unable to get last $status jobs number from catalog
" . $jobs->getMessage() ); }else { - return $jobs->fetchRow( DB_FETCHMODE_ASSOC ); + $jobs = $jobs->fetchRow( DB_FETCHMODE_ASSOC ); + return $jobs['job_nb']; } } diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index 6bc8e73d20..cb54d310bf 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -100,12 +100,10 @@ $smarty->assign('pools', $dbSql->GetVolumeList() ); //$smarty->assign( 'completed_jobs', $completed_jobs['completed_jobs'] ); // Last 24 hours completed jobs number (last_run_report.tpl) -$completed_jobs = $dbSql->CountJobs( LAST_DAY, 'completed' ); -$smarty->assign( 'completed_jobs', $completed_jobs['job_nb'] ); +$smarty->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) ); // Last 24 hours failed jobs number (last_run_report.tpl) -$failed_jobs = $dbSql->CountJobs( LAST_DAY, 'failed' ); -$smarty->assign( 'failed_jobs', $failed_jobs['job_nb'] ); +$smarty->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) ); // Last 24 hours elapsed time (last_run_report.tpl) $smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() ); diff --git a/gui/bacula-web/jobs.php b/gui/bacula-web/jobs.php index 07bc885a49..c26d85f568 100644 --- a/gui/bacula-web/jobs.php +++ b/gui/bacula-web/jobs.php @@ -121,6 +121,13 @@ } $smarty->assign( 'last_jobs', $last_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'); ?> diff --git a/gui/bacula-web/templates/jobs.tpl b/gui/bacula-web/templates/jobs.tpl index b1d7ce8df5..c7b2ad77b9 100644 --- a/gui/bacula-web/templates/jobs.tpl +++ b/gui/bacula-web/templates/jobs.tpl @@ -85,6 +85,9 @@
+
+ {$total_jobs} jobs found + Jobs / Page