]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bacula-web/index.php
bacula-web: Internal code improvments
[bacula/bacula] / gui / bacula-web / index.php
index 3b086eddb2230d7889b489206aac9319239376d7..93a130edff0c8b44da2857a5eada454b3afc02e8 100644 (file)
@@ -17,9 +17,9 @@
 session_start();
 require ("paths.php");
 require($smarty_path."Smarty.class.php");
-include "classes.inc";
+include "bweb.inc.php";
 
-$smarty = new Smarty;     
+$smarty = new Smarty();     
 $dbSql = new Bweb();
 
 require("lang.php");
@@ -101,7 +101,7 @@ $query = "";
        die( "Unable to get Total Job Bytes from catalog" . $last24bytes->getMessage() );
   }else {
        $tmp = $last24bytes->fetchRow();
-       var_dump( $tmp );
+       //var_dump( $tmp );
        // Transfered bytes since last 24 hours
        $smarty->assign('bytes_totales', $dbSql->human_file_size( $tmp[0] ) );
 
@@ -121,67 +121,26 @@ $smarty->assign('bytes_stored', $dbSql->human_file_size($bytes_stored) );
 $nb_clients = $dbSql->Get_Nb_Clients();
 $smarty->assign('clientes_totales',$nb_clients["nb_client"] );
 
-/*if ( empty($tmp[0]) ) {                                                                                                                 // No data for last 24, search last 48
-        if ( $dbSql->driver == "mysql" )
-          $last24bytes = $dbSql->db_link->query("select sum(JobBytes) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-172800" );
-        if ( $dbSql->driver == "pgsql")
-          $last24bytes = $dbSql->db_link->query("select sum(JobBytes) from Job where Endtime <= NOW() and EndTime > NOW()-172800 * interval '1 second'" )
-            or die ("Error query: 4.1");
-        $smarty->assign('when',"yesterday");
-        $tmp = $last24bytes->fetchRow();        
-}*/
-
-// report_select.tpl & last_run_report.tpl
-$res = $dbSql->db_link->query("select Name from Job group by Name");
-
-$a_jobs = array();
-while ( $tmp = $res->fetchRow() )
-        array_push($a_jobs, $tmp[0]);
-$smarty->assign('total_name_jobs',$a_jobs);
-$smarty->assign('time2',( (time())-2678400) );                                                                  // Current time - 1 month. <select> date
-$res->free();
+// Backup Job list for report.tpl and last_run_report.tpl
+$smarty->assign( 'total_name_jobs', $dbSql->Get_BackupJob_Names() );
 
 // Get volumes list (volumes.tpl)
 $smarty->assign('pools',$dbSql->GetVolumeList() );
 
+// Last 24 hours completed jobs number (last_run_report.tpl)
+$completed_jobs = $dbSql->GetLastJobs();
+$smarty->assign( 'completed_jobs', $completed_jobs['completed_jobs'] );
+
+// Last 24 hours failed jobs number (last_run_report.tpl)
+$failed_jobs = $dbSql->GetLastErrorJobs();
+$smarty->assign( 'failed_jobs', $failed_jobs['failed_jobs'] );
+
+// Last 24 hours elapsed time (last_run_report.tpl)
+$smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() );
+
 // last_run_report.tpl
 if ( $mode == "Lite" && $_GET['Full_popup'] == "yes" ) {
-        $tmp = array();
-        switch( $dbSql->driver )
-               {
-                       case 'mysql':
-                               $query  = "SELECT JobId, Name, EndTime, JobStatus";
-                               $query .= "FROM Job ";
-                               $query .= "WHERE EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400 and JobStatus!='T'";
-                       break;
-                       case 'pgsql':
-                               $query  = "SELECT JobId, Name, EndTime, JobStatus ";
-                               $query .= "FROM Job ";
-                               $query .= "WHERE EndTime <= NOW() and EndTime >NOW() - 86400 * interval '1 second' and JobStatus!= 'T'";
-                       break;
-               }
-               
-               $status = $dbSql->db_link->query( $query );
-               
-               if (PEAR::isError( $status ) )
-                       die( "Unable to get last job status from catalog<br />" . $status->getMessage() );
-               
-               /*
-               if ( $dbSql->driver == "mysql" )
-          $status = $dbSql->db_link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 and JobStatus!='T'" )               
-                or die ("Error: query at row 95");
-        if ( $dbSql->driver == "pgsql" )
-          $status = $dbSql->db_link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and EndTime >NOW() - 86400 * interval '1 second' and JobStatus!= 'T'")
-                or die ( "Error: query at row 98" );
-        */
-               $smarty->assign('status', $status->numRows() );
-        if ( $status->numRows() ) {
-                while ( $res = $status->fetchRow() )
-                        array_push($tmp, $res);
-                $smarty->assign('errors_array',$tmp);
-        }
-        $status->free();
-        
+/*
         // Total Elapsed Time. Only for single Job.
         if ( $dbSql->driver == "mysql" )
           $ret = $dbSql->db_link->query("select UNIX_TIMESTAMP(EndTime)-UNIX_TIMESTAMP(StartTime) as elapsed from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-84600")
@@ -199,8 +158,11 @@ if ( $mode == "Lite" && $_GET['Full_popup'] == "yes" ) {
                 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
         $smarty->assign('TotalElapsed',$TotalElapsed);
         $ret->free();
+*/             
+               
 }
 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
+/*
         $tmp1 = array();
         if ( $dbSql->driver == "mysql")
                 $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
@@ -222,8 +184,43 @@ else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
         }
         
         $smarty->assign('clients',$tmp1);
-}  
+*/
+}
+
+// Last 24 hours Job status graph
+$data   = array();  
+$status = array( 'completed', 'completed_errors', 'failed', 'waiting', 'created', 'running', 'error' );
+
+foreach( $status as $job_status ) {
+       array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
+}
+
+$graph = new BGraph( "graph.png" );
+$graph->SetData( $data, 'pie', 'text-data-single' );
+//$graph->SetTitle("Overall jobs status");
+$graph->SetGraphSize( 400, 230 );
+//$graph->SetColors( array('green', 'yellow','red','blue','white','green','red') );
+
+$graph->Render();
+$smarty->assign('graph_jobs', $graph->Get_Image_file() );
+unset($graph);
+
+// Pool and volumes graph
+$data = array();
+$graph = new BGraph( "graph1.png" );
+
+$pools = $dbSql->Get_Pools_List();
+
+foreach( $pools as $pool ) {
+       array_push( $data, $dbSql->GetPoolsStatistics( $pool ) );
+}
+
+$graph->SetData( $data, 'pie', 'text-data-single' );
+$graph->SetGraphSize( 400, 230 );
+
 
+$graph->Render();
+$smarty->assign('graph_pools', $graph->Get_Image_file() );
 
 if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
         $smarty->display('full_popup.tpl');