]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved php and html code
authorDavide Franco <bacula-dev@dflc.ch>
Mon, 29 Nov 2010 16:37:46 +0000 (17:37 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:39:41 +0000 (14:39 +0200)
 - New Get_BackupJob_Names function in Bweb classe
 - New GetLastErrorJobs() and GetLastJobs() function in Bweb classe
 - Improved Last completed and failed jobs in index.php
 - Some html and css fixes in last_run_report.tpl

gui/bacula-web/classes.inc.php
gui/bacula-web/config.inc.php [new file with mode: 0644]
gui/bacula-web/index.php
gui/bacula-web/templates/last_run_report.tpl

index e4241174eeee49ee188eb281cf1b01c9d34aeaec..ec853ecabd6659022e76682466f452009858aaae 100644 (file)
@@ -356,30 +356,87 @@ class Bweb extends DB {
                
                public function GetLastJobs( $delay = LAST_DAY )
                {
+                       $query          = "";
+                       $start_date = "";
+                       $end_date       = "";
+                       
+                       // Interval calculation
+                       $end_date   = mktime();
+                       $start_date = $end_date - $delay;
+                       
+                       $start_date = date( "Y-m-d H:m:s", $start_date );
+                       $end_date   = date( "Y-m-d H:m:s", $end_date );
+                       
                        switch( $this->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'";
+                                       $query  = 'SELECT COUNT(JobId) AS completed_jobs ';
+                                       $query .= 'FROM Job ';
+                                       $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+                                       $query .= "AND JobStatus = 'T'";
                                break;
                        }
                
-                       $lastjobstatus = $this->db_link->query( $query );
+                       $jobs = $this->db_link->query( $query );
                
                        if (PEAR::isError( $lastjobstatus ) ) {
-                               die( "Unable to get last job status from catalog<br />" . $status->getMessage() );
+                               die( "Unable to get last completed jobs status from catalog<br />" . $status->getMessage() );
                        }else {
-                               //echo "numrows = " . $lastjobstatus->numRows() . "<br />";
-                               return $lastjobstatus->numRows();
+                               return $jobs->fetchRow();
                        }
                } // end function GetLastJobStatus()
                
+               public function GetLastErrorJobs( $delay = LAST_DAY )
+               {
+                       $query          = "";
+                       $start_date = "";
+                       $end_date       = "";
+                       
+                       // Interval calculation
+                       $end_date   = mktime();
+                       $start_date = $end_date - $delay;
+                       
+                       $start_date = date( "Y-m-d H:m:s", $start_date );
+                       $end_date   = date( "Y-m-d H:m:s", $end_date );
+                       
+                       //echo "start date: $start_date <br />";
+                       //echo "end date: $end_date <br />";
+                       
+                       switch( $this->driver )
+                       {
+                               default:
+                                       $query  = 'SELECT COUNT(JobId) AS failed_jobs ';
+                                       $query .= 'FROM Job ';
+                                       $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+                                       $query .= "AND JobStatus = 'f'";
+                               break;
+                       }                               
+                       $result = $this->db_link->query( $query );
+                       
+                       if (PEAR::isError( $result ) ) {
+                               die( "Unable to get last failed jobs status from catalog<br />query = $query <br />" . $result->getMessage() );
+                       }else {
+                               return $result->fetchRow( DB_FETCHMODE_ASSOC );
+                       } // end if else
+               } // end function GetLastErrorJobs
+               
+               public function Get_BackupJob_Names()
+               {
+                       $query          = "SELECT Name FROM Job GROUP BY Name";
+                       $backupjobs = array();
+                       
+                       $result = $this->db_link->query( $query );
+                       
+                       if (PEAR::isError( $result ) ) {
+                               die("Unable to get BackupJobs list from catalog" );
+                       }else{
+                               while( $backupjob = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {
+                                       array_push( $backupjobs, $backupjob["Name"] );
+                               }
+                               return $backupjobs;
+                       }
+               }
+               
 } // end class Bweb
 
 class BGraph {
@@ -712,3 +769,4 @@ class BCreateGraph extends BGraph {
 }//end class
 
 ?>
+
diff --git a/gui/bacula-web/config.inc.php b/gui/bacula-web/config.inc.php
new file mode 100644 (file)
index 0000000..6d7c742
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+ define( 'LAST_DAY', 86400 );
+ define( 'LAST_WEEK', 604800 );
+ define( 'LAST_MONTH', 2678400 );
+?>
index e3591c24503077e18fcdfeab5f1b5c5951a1c900..538f62b75300f909dc9fca8211eabf5b25103538 100644 (file)
@@ -131,66 +131,32 @@ $smarty->assign('clientes_totales',$nb_clients["nb_client"] );
         $tmp = $last24bytes->fetchRow();        
 }*/
 
-// report_select.tpl & last_run_report.tpl
-$res = $dbSql->db_link->query("select Name from Job group by Name");
+// Backup Job list for report.tpl and last_run_report.tpl
+$smarty->assign( 'total_name_jobs', $dbSql->Get_BackupJob_Names() );
+
+/*$res = $dbSql->db_link->query("select Name from Job group by Name");
 
 $a_jobs = array();
-while ( $tmp = $res->fetchRow() )
+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();
+*/
 
 // Get volumes list (volumes.tpl)
 $smarty->assign('pools',$dbSql->GetVolumeList() );
 
-// Last job status (default is last 24 hours)
-$smarty->assign( 'lastjobs', $dbSql->GetLastJobs() );
+// Completed jobs number
+$failed_jobs = $dbSql->GetLastJobs();
+$smarty->assign( 'completed_jobs', $failed_jobs['completed_jobs'] );
+
+// Failed jobs number (last_run_report.tpl)
+$failed_jobs = $dbSql->GetLastErrorJobs();
+$smarty->assign( 'failed_jobs', $failed_jobs['failed_jobs'] );
 
 // 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() ) {
-                       echo "status nomrow -> " . $status->numRows() . "<br />";
-                       while ( $res = $status->fetchRow() ) {
-                               array_push($tmp, $res);
-                       }
-            
-                       $smarty->assign('errors_array',$tmp);
-        }else {
-                       //echo "status pas marche ...<br />";
-               }
-        $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")
index bec4bb180ae3d96dff7e1c3bb497e174f57c0d70..0797434b466f5e32cda8f53f844455f26fb2573b 100644 (file)
@@ -2,27 +2,19 @@
 
 <div class="box">
        <p class="title">Last 24 hours status</p>
-<!--   
-<table width=100% align=center {if !$status }background="style/images/backlast.gif"{else}background="style/images/backlastred.gif" {/if} style="background-repeat:no-repeat" height=178px border=0 cellspacing=0 cellpadding=0>
- <tr>
-       <td colspan=2 align=center style="font-size: 12px; font-weight: bold; background-repeat: repeat" background="style/images/bg6.png" height=25>
-               {t}Status from last 24h{/t}
-       </td>
- </tr>
--->
 {* {if $mode == "Lite" && $smarty.get.Full_popup != "yes"} *}
 <table>
  <tr>
-       <td class="label">Failed jobs</td> <td class="info">{$jobserror}</td>
+       <td class="label">Failed jobs</td> <td class="info">{$failed_jobs}</td>
  </tr>
  <tr>
-       <td class="label">Completed jobs</td> <td class="info">{$total_jobs}</td>
+       <td class="label">Completed jobs</td> <td class="info">{$completed_jobs}</td>
  </tr> 
  <tr>
-       <td class="label">Backup elapsed time</td> <td class="info">{$totalElapsed}</td>
+       <td class="label">Elapsed time</td> <td class="info">{$totalElapsed}</td>
  </tr>
  <tr>
-       <td class="label">Transferred bytes</td> <td class="info">{$bytes_totales}</td>
+       <td class="label">Transferred Bytes</td> <td class="info">{$bytes_totales}</td>
  </tr> 
  <tr>
        <td colspan=2 align=center>