]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bacula-web/backupjob-report.php
bacula-web: Replaced Get_human_file_size() function by Utils::Get_Human_Size
[bacula/bacula] / gui / bacula-web / backupjob-report.php
index 26a1b2308d81a90badca2f0b82e8e74fcd4a6d17..fd9f4391f07b6741095b07d58c2cfa5bf7ed0ed6 100644 (file)
-<?php
-  session_start();
-  require_once ("paths.php");
-  require_once ($smarty_path."Smarty.class.php");
-  require_once ("bweb.inc.php");
-  require_once ("config.inc.php");  
+<?php\r
+/* 
++-------------------------------------------------------------------------+
+| 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();\r
+  include_once( 'config.inc.php' );
+\r
+  $dbSql = new Bweb();\r
+\r
+  $backupjob_name              = "";
+  $backupjob_bytes             = 0;
+  $backupjob_files             = 0;
+\r
+  $days                                = array();
+  $days_stored_bytes   = array();
+  $days_stored_files   = array();
 
-  $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";
-
-  $backupjob_name = "";
-  
-  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 " );
-       
-  $smarty->assign('backupjob_name', $backupjob_name );
-       
-  // Last 7 days stored Bytes graph
-  $data  = array();
-  $graph = new BGraph( "graph2.png" );
-  $days  = array();
-
-  // Get the last 7 days interval (start and end)
-  for( $c = 6 ; $c >= 0 ; $c-- ) {
-         $today = ( mktime() - ($c * LAST_DAY) );
-         array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );
-  }
-
-  $days_stored_bytes = array();
-
-  foreach( $days as $day ) {
-    array_push( $days_stored_bytes, $dbSql->GetStoredBytesByJob( $backupjob_name, $day['start'], $day['end'] ) );
-  }
-
-  $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
-  $graph->SetGraphSize( 400, 230 );
-
-  $graph->Render();
-  $smarty->assign('graph_stored_bytes', $graph->Get_Image_file() );    
-  
+  // ===============================================================
+  // Get Backup Job name from GET or POST\r
+  // ===============================================================
+  if( isset( $_POST["backupjob_name"] ) )\r
+    $backupjob_name = $_POST["backupjob_name"];\r
+  elseif( isset( $_GET["backupjob_name"] ) )\r
+       $backupjob_name = $_GET["backupjob_name"];\r
+  else\r
+       die( "Please specify a backup job name " );\r
+\r
+  // Get the last 7 days interval (start and end)\r
+  for( $c = 6 ; $c >= 0 ; $c-- ) {\r
+         $today = ( mktime() - ($c * LAST_DAY) );\r
+         array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );\r
+  }\r
   
-  // Process and display the template 
-  $smarty->display('backupjob-report.tpl'); 
+  // Generate Backup Job report period string\r
+  $backupjob_period = "From " . date( "Y-m-d", mktime()-LAST_WEEK ) . " to " . date( "Y-m-d", mktime() );\r
   
-?>
\ No newline at end of file
+  // ===============================================================
+  // Last 7 days stored Bytes graph\r
+  // ===============================================================  
+  $graph = new BGraph( "graph2.png" );\r
+\r
+  foreach( $days as $day )\r
+    array_push( $days_stored_bytes, $dbSql->GetStoredBytesByJob( $backupjob_name, $day['start'], $day['end'] ) );\r
\r
+  // Calculate total bytes for this period\r
+  foreach( $days_stored_bytes as $day )\r
+       $backupjob_bytes += $day[1];\r
+       \r
+  $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );\r
+  $graph->SetGraphSize( 400, 230 );\r
+\r
+  $graph->Render();\r
+  $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() );        
+  \r
+  // ===============================================================
+  // Getting last 7 days stored files graph\r
+  // ===============================================================
+  $graph = new BGraph("graph3.png" );\r
+  \r
+  foreach( $days as $day )\r
+    array_push( $days_stored_files, $dbSql->GetStoredFilesByJob( $backupjob_name, $day['start'], $day['end'] ) );\r
+\r
+  // Calculate total files for this period     \r
+  foreach( $days_stored_files as $day )\r
+       $backupjob_files += $day[1];\r
+  \r
+  $graph->SetData( $days_stored_files, 'bars', 'text-data' );\r
+  $graph->SetGraphSize( 400, 230 );\r
+\r
+  $graph->Render();\r
+  $dbSql->tpl->assign('graph_stored_files', $graph->Get_Image_file() );
+\r
+  // Last 10 jobs\r
+  $query    = "SELECT JobId, Level, JobFiles, JobBytes, JobStatus, EndTime, Name ";  \r
+  $query   .= "FROM Job ";\r
+  $query   .= "WHERE Name = '$backupjob_name' ";\r
+  $query   .= "ORDER BY EndTime DESC ";\r
+  $query   .= "LIMIT 10 ";\r
+  \r
+  $jobs                = array();\r
+  $joblevel = array( 'I' => 'Incr', 'D' => 'Diff', 'F' => 'Full' );\r
+  $result      = $dbSql->db_link->query( $query );\r
+  \r
+  if( ! PEAR::isError( $result ) )\r
+  {\r
+       while( $job = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {\r
+               $job['Level'] = $joblevel[ $job['Level'] ];\r
+               array_push( $jobs, $job);\r
+       }               
+  }else\r
+       die( "Unable to get last jobs from catalog " . $result->getMessage() );\r
+    \r
+  $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 );
+  \r
+  // Process and display the template \r
+  $dbSql->tpl->display('backupjob-report.tpl'); 
+  \r
+?>\r