From: Davide Franco Date: Sun, 17 Jul 2011 20:29:20 +0000 (+0200) Subject: bacula-web: bacula-web: Replaced old PEAR code by new CDB class in jobs page X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=dc799d7f84bf730ea9ea7305aabd12eb3da2ee89;p=bacula%2Fbacula bacula-web: bacula-web: Replaced old PEAR code by new CDB class in jobs page - Fixed code indentation --- diff --git a/gui/bacula-web/backupjob-report.php b/gui/bacula-web/backupjob-report.php index 7f55f98110..566f4b2885 100644 --- a/gui/bacula-web/backupjob-report.php +++ b/gui/bacula-web/backupjob-report.php @@ -14,118 +14,119 @@ | GNU General Public License for more details. | +-------------------------------------------------------------------------+ */ - session_start(); - include_once( 'config/global.inc.php' ); - - $dbSql = new Bweb(); - - $backupjob_name = ""; - $backupjob_bytes = 0; - $backupjob_files = 0; - - $days = array(); - $days_stored_bytes = array(); - $days_stored_files = array(); - - // =============================================================== - // Get Backup Job name from GET or POST - // =============================================================== - if( isset( $_POST["backupjob_name"] ) ) - $backupjob_name = $_POST["backupjob_name"]; - elseif( isset( $_GET["backupjob_name"] ) ) - $backupjob_name = $_GET["backupjob_name"]; - else - die( "Please specify a backup job name " ); - - // Generate Backup Job report period string - $backupjob_period = "From " . date( "Y-m-d", (NOW-WEEK) ) . " to " . date( "Y-m-d", NOW ); - - // Calculate total bytes for this period - $backupjob_bytes = $dbSql->getStoredBytes( LAST_WEEK, NOW, $backupjob_name ); - $backupjob_bytes = CUtils::Get_Human_Size( $backupjob_bytes ); - - $backupjob_files = $dbSql->getStoredFiles( LAST_WEEK, NOW, $backupjob_name ); - $backupjob_files = number_format( $backupjob_files, 0, '.', "'"); - - // Get the last 7 days interval (start and end) - $days = CTimeUtils::getLastDaysIntervals( 7 ); - - // =============================================================== - // Last 7 days stored Bytes graph - // =============================================================== - $graph = new CGraph( "graph2.png" ); - - foreach( $days as $day ) { - $stored_bytes = $dbSql->getStoredBytes( $day['start'], $day['end'], $backupjob_name); - $stored_bytes = CUtils::Get_Human_Size( $stored_bytes, 1, 'GB', false ); - $days_stored_bytes[] = array( date("m-d", $day['start']), $stored_bytes ); - } - - $graph->SetData( $days_stored_bytes, 'bars', 'text-data' ); - $graph->SetGraphSize( 400, 230 ); - $graph->SetYTitle( "GB" ); - - $graph->Render(); - $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() ); - - // =============================================================== - // Getting last 7 days stored files graph - // =============================================================== - $graph = new CGraph("graph3.png" ); - - foreach( $days as $day ) { - $stored_files = $dbSql->getStoredFiles( $day['start'], $day['end'], $backupjob_name); - $days_stored_files[] = array( date("m-d", $day['start']), $stored_files ); - } - - $graph->SetData( $days_stored_files, 'bars', 'text-data' ); - $graph->SetGraphSize( 400, 230 ); - $graph->SetYTitle( "Files" ); - - $graph->Render(); - $dbSql->tpl->assign('graph_stored_files', $graph->Get_Image_file() ); - - // Last 10 jobs - $query = "SELECT JobId, Level, JobFiles, JobBytes, JobStatus, StartTime, EndTime, Name "; - $query .= "FROM Job "; - $query .= "WHERE Name = '$backupjob_name' "; - $query .= "ORDER BY EndTime DESC "; - $query .= "LIMIT 10 "; - - $jobs = array(); - $joblevel = array( 'I' => 'Incr', 'D' => 'Diff', 'F' => 'Full' ); - $result = $dbSql->db_link->query( $query ); - - if( ! PEAR::isError( $result ) ) - { - while( $job = $result->fetchRow() ) - { - // Job level description - $job['joblevel'] = $joblevel[ $job['level'] ]; - - // Job execution execution time - $job['elapsedtime'] = CTimeUtils::Get_Elapsed_Time( $job['starttime'], $job['endtime'] ); - - // odd and even row - if( count($jobs) % 2) - $job['row_class'] = 'odd'; - - // Job bytes more easy to read - $job['jobbytes'] = CUtils::Get_Human_Size( $job['jobbytes'] ); - $job['jobfiles'] = number_format($job['jobfiles'], 0 , '.', "'"); - - $jobs[] = $job; - } - }else - $dbSql->TriggerDBError("Unable to get last jobs from catalog", $result); - - $dbSql->tpl->assign('jobs', $jobs ); - $dbSql->tpl->assign('backupjob_name', $backupjob_name ); - $dbSql->tpl->assign('backupjob_period', $backupjob_period ); - $dbSql->tpl->assign('backupjob_bytes', $backupjob_bytes ); - $dbSql->tpl->assign('backupjob_files', $backupjob_files ); - - // Process and display the template - $dbSql->tpl->display('backupjob-report.tpl'); - + session_start(); + include_once( 'config/global.inc.php' ); + + $dbSql = new Bweb(); + + $backupjob_name = ""; + $backupjob_bytes = 0; + $backupjob_files = 0; + + $days = array(); + $days_stored_bytes = array(); + $days_stored_files = array(); + + // =============================================================== + // Get Backup Job name from GET or POST + // =============================================================== + if( isset( $_POST["backupjob_name"] ) ) + $backupjob_name = $_POST["backupjob_name"]; + elseif( isset( $_GET["backupjob_name"] ) ) + $backupjob_name = $_GET["backupjob_name"]; + else + die( "Please specify a backup job name " ); + + // Generate Backup Job report period string + $backupjob_period = "From " . date( "Y-m-d", (NOW-WEEK) ) . " to " . date( "Y-m-d", NOW ); + + // Calculate total bytes for this period + $backupjob_bytes = $dbSql->getStoredBytes( LAST_WEEK, NOW, $backupjob_name ); + $backupjob_bytes = CUtils::Get_Human_Size( $backupjob_bytes ); + + $backupjob_files = $dbSql->getStoredFiles( LAST_WEEK, NOW, $backupjob_name ); + $backupjob_files = number_format( $backupjob_files, 0, '.', "'"); + + // Get the last 7 days interval (start and end) + $days = CTimeUtils::getLastDaysIntervals( 7 ); + + // =============================================================== + // Last 7 days stored Bytes graph + // =============================================================== + $graph = new CGraph( "graph2.png" ); + + foreach( $days as $day ) { + $stored_bytes = $dbSql->getStoredBytes( $day['start'], $day['end'], $backupjob_name); + $stored_bytes = CUtils::Get_Human_Size( $stored_bytes, 1, 'GB', false ); + $days_stored_bytes[] = array( date("m-d", $day['start']), $stored_bytes ); + } + + $graph->SetData( $days_stored_bytes, 'bars', 'text-data' ); + $graph->SetGraphSize( 400, 230 ); + $graph->SetYTitle( "GB" ); + + $graph->Render(); + $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() ); + + // =============================================================== + // Getting last 7 days stored files graph + // =============================================================== + $graph = new CGraph("graph3.png" ); + + foreach( $days as $day ) { + $stored_files = $dbSql->getStoredFiles( $day['start'], $day['end'], $backupjob_name); + $days_stored_files[] = array( date("m-d", $day['start']), $stored_files ); + } + + $graph->SetData( $days_stored_files, 'bars', 'text-data' ); + $graph->SetGraphSize( 400, 230 ); + $graph->SetYTitle( "Files" ); + + $graph->Render(); + $dbSql->tpl->assign('graph_stored_files', $graph->Get_Image_file() ); + + // Last 10 jobs + $query = "SELECT JobId, Level, JobFiles, JobBytes, JobStatus, StartTime, EndTime, Name "; + $query .= "FROM Job "; + $query .= "WHERE Name = '$backupjob_name' "; + $query .= "ORDER BY EndTime DESC "; + $query .= "LIMIT 10 "; + + $jobs = array(); + $joblevel = array( 'I' => 'Incr', 'D' => 'Diff', 'F' => 'Full' ); + + try { + $result = $dbSql->db_link->runQuery( $query ); + + foreach( $result->fetchAll() as $job ) + { + // Job level description + $job['joblevel'] = $joblevel[ $job['level'] ]; + + // Job execution execution time + $job['elapsedtime'] = CTimeUtils::Get_Elapsed_Time( $job['starttime'], $job['endtime'] ); + + // odd and even row + if( count($jobs) % 2) + $job['row_class'] = 'odd'; + + // Job bytes more easy to read + $job['jobbytes'] = CUtils::Get_Human_Size( $job['jobbytes'] ); + $job['jobfiles'] = number_format($job['jobfiles'], 0 , '.', "'"); + + $jobs[] = $job; + } // end while + }catch(PDOExceptin $e) { + CDBError::raiseError($e); + } + + $dbSql->tpl->assign('jobs', $jobs ); + $dbSql->tpl->assign('backupjob_name', $backupjob_name ); + $dbSql->tpl->assign('backupjob_period', $backupjob_period ); + $dbSql->tpl->assign('backupjob_bytes', $backupjob_bytes ); + $dbSql->tpl->assign('backupjob_files', $backupjob_files ); + + // Process and display the template + $dbSql->tpl->display('backupjob-report.tpl'); + ?>