]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bacula-web/bweb.inc.php
bacula-web: New function Get_ElapsedTime in bweb.inc.php
[bacula/bacula] / gui / bacula-web / bweb.inc.php
index 5bde6b7031cc7d1cfb7582ce2d7a7191ccf69e8a..51f46aed0f66e60344a47b80637634a48d46f4b3 100644 (file)
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+ 
 */
-// Last Err: 11
-define('CONFIG_DIR', "configs");
-define('CONFIG_FILE', "bacula.conf");
-define('BACULA_TYPE_BYTES_FILES', 1);
-define('BACULA_TYPE_FILES_JOBID', 2);
-define('BACULA_TYPE_BYTES_ENDTIME_ALLJOBS', 69);
-
 require_once "paths.php";
 require_once "DB.php";                                                                                                                  // Pear DB
 require_once "config.inc.php";
+require_once "bgraph.inc.php";
 require_once($smarty_path."Config_File.class.php");
 
 if (!function_exists('array_fill')) {                                                                                   // For PHP < 4.2.0 users 
@@ -179,49 +173,39 @@ class Bweb extends DB {
                 $this->EndDate=$EndDateYear."-".$EndDateMonth."-".$EndDateDay." 23:59:59";  // last day full
                 
         }//end function
-        function GetDataVolumes() {
-
-                $volume = array();
-                $res = $this->db_link->query("SELECT Name FROM Pool");
-                while ( $tmp =& $res->fetchRow() ) {
-                        if ($this->driver == "mysql" )
-                                $result = $this->db_link->query("select Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten,FROM_UNIXTIME(UNIX_TIMESTAMP(Media.LastWritten)+Media.VolRetention ) as expire from Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId where Name='$tmp[0]' order by Media.VolumeName");
-                        else if ($this->driver == "pgsql")
-                               $result = $this->db_link->db_query("select Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten, Media.LastWritten + Media.VolRetention * interval '1 second' as expire from Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId where Name='$tmp[0]' order by Media.VolumeName");
-                        while ( $tmp1 = $result->fetchRow() ) {
-                                $pos = array_key_exists($tmp[0],$volume);
-                                if ($pos != FALSE)
-                                        array_push($volume["$tmp[0]"],$tmp1);
-                                else
-                                        $volume += array($tmp[0]=>array($tmp1));
-                        }
-                }
-                
-                $res->free();
-                $result->free();
-                return $volume;
-        }
-        
-               function human_file_size( $size, $decimal = 2 )
+               
+               // Return humanized size with default unit of GB
+               // if auto provide for unit argument, automaticaly decide which unit
+               function human_file_size( $size, $decimal = 2, $unit = 'auto' )
                {
                        $unit_id = 0;
                        $lisible = false;
                        $units = array('B','KB','MB','GB','TB');
                        $hsize = $size;
+
+                       switch( $unit )
+                       {
+                               case 'auto';
+                                       while( !$lisible ) {
+                                               if ( $hsize >= 1024 ) {
+                                                       $hsize    = $hsize / 1024;
+                                                       $unit_id += 1;
+                                               }        
+                                               else {
+                                                       $lisible = true;
+                                               } 
+                                       }
+                               break;
                                
-                       while( !$lisible ) {
-                               if ( $hsize >= 1024 ) {
-                                       $hsize    = $hsize / 1024;
-                                       $unit_id += 1;
-                               } 
-                               else {
-                                       $lisible = true;
-                               } 
-                       } 
-                       // Format human size
+                               default:
+                                       $p = array_search( $unit, $units);
+                                       $hsize = $hsize / pow(1024,$p);
+                               break;
+                       } // end switch
+                       
                        $hsize = sprintf("%." . $decimal . "f", $hsize);
-                       return $hsize . ' ' . $units[$unit_id];
+                       $hsize = $hsize . ' ' . $units[$unit_id];
+                       return $hsize;
                } // end function
 
                
@@ -276,13 +260,13 @@ class Bweb extends DB {
                                // Get the list of pools id
                                $query = "SELECT Pool.poolid, Pool.name FROM Pool ORDER BY Pool.poolid";
                                
-                               $this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
+                               //$this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
                                $pools = $this->db_link->query( $query );
                                
                                if( PEAR::isError( $pools ) )
                                        die("Error: Failed to get pool list <br />SQL Query: $query<br />" . $pools->getMessage() );
                                
-                               while( $pool = $pools->fetchRow() ) {
+                               while( $pool = $pools->fetchRow( DB_FETCHMODE_ASSOC ) ) {
                                        switch( $this->driver )
                                        {
                                                case 'mysql':
@@ -312,7 +296,7 @@ class Bweb extends DB {
                                                break;
                                        } // end switch
                                        
-                                       $this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
+                                       //$this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
                                        $medias = $this->db_link->query( $query );
 
                                        if( PEAR::isError( $medias ) ) {
@@ -325,21 +309,25 @@ class Bweb extends DB {
                                                {
                                                        $volumes[ $pool['name'] ] = array();
                                                }
-                                               while( $media = $medias->fetchRow() ) {
+                                               while( $media = $medias->fetchRow( DB_FETCHMODE_ASSOC ) ) {
                                                        if( $debug ) {
                                                                var_dump( $media );
                                                        }
-
+                                                       // If the pool is empty (no volumes in this pool)
                                                        if( $medias->numRows() == 0 ) {
                                                                if( $debug ) echo "No media in pool " . $pool['name'] . "<br />";
                                                        } else {
-                                                                       if( ($media['lastwritten'] != "0000-00-00 00:00:00") && $media['volstatus'] == 'Full' ) {
-                                                                               // Calculate expiration date
-                                                                               $expire_date     = strtotime($media['lastwritten']) + $media['volretention'];
-                                                                               $media['expire'] = strftime("%Y-%m-%d", $expire_date);
-                                                                               
-                                                                               // Media used size in a more readable format
+                                                                       if( $media['lastwritten'] != "0000-00-00 00:00:00" ) {
+                                                                               // Calculate expiration date if the volume is Full
+                                                                               if( $media['volstatus'] == 'Full' ) {
+                                                                                       $expire_date     = strtotime($media['lastwritten']) + $media['volretention'];
+                                                                                       $media['expire'] = strftime("%Y-%m-%d", $expire_date);
+                                                                               }else {
+                                                                                       $media['expire'] = 'N/A';
+                                                                               }
+                                                                               // Media used bytes in a human format
                                                                                $media['volbytes'] = $this->human_file_size( $media['volbytes'] );
+                                                                               //echo "volume " . $media['volumename'] . 'vol bytes' .$media['volbytes'] . '<br />';
                                                                        } else {
                                                                                $media['lastwritten'] = "N/A";
                                                                                $media['expire']      = "N/A";
@@ -354,71 +342,74 @@ class Bweb extends DB {
                                return $volumes;
         } // end function GetVolumeList()
                
-               public function GetLastJobs( $delay = LAST_DAY )
+               public function CountJobs( $delay = LAST_DAY, $status = 'any' )
                {
-                       $query          = "";
-                       $start_date = "";
-                       $end_date       = "";
+                       $query                  = "SELECT COUNT(JobId) AS job_nb FROM Job ";
+                       $where_delay    = "";
+                       $where_status   = "";
                        
-                       // Interval calculation
-                       $end_date   = mktime();
-                       $start_date = $end_date - $delay;
+                       // Interval condition for SQL query
+                       if( $delay != ALL ) {
+                               $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 );
+                               $start_date  = date( "Y-m-d H:i:s", $start_date );
+                               $end_date    = date( "Y-m-d H:i:s", $end_date );
                        
-                       switch( $this->driver )
-                       {
-                               case 'mysql':
-                                       $query  = 'SELECT COUNT(JobId) AS completed_jobs ';
-                                       $query .= 'FROM Job ';
-                                       $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
-                                       $query .= "AND JobStatus = 'T'";
-                               break;
+                               $where_delay = "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
                        }
-               
+                       
+                       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 completed jobs status from catalog<br />" . $status->getMessage() );
+                               die( "Unable to get last $status jobs number from catalog <br />" . $jobs->getMessage() );
                        }else {
-                               return $jobs->fetchRow();
+                               $jobs = $jobs->fetchRow( DB_FETCHMODE_ASSOC ); 
+                               return $jobs['job_nb'];
                        }
-               } // end function GetLastJobStatus()
+               }
                
-               public function GetLastErrorJobs( $delay = LAST_DAY )
+               // Return the list of Pools in a array
+               public function Get_Pools_List()
                {
-                       $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 );
+                       $pool_list = array();
+                       $result    = "";
                        
-                       //echo "start date: $start_date <br />";
-                       //echo "end date: $end_date <br />";
+                       $query = "SELECT Name, PoolId FROM Pool";
                        
-                       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() );
+                       $result = $this->db_link->query ( $query );
+       
+                       if( PEAR::isError( $result ) ) {
+                               die( "Unable to get the pool list from catalog" );                              
                        }else {
-                               return $result->fetchRow( DB_FETCHMODE_ASSOC );
-                       } // end if else
-               } // end function GetLastErrorJobs
+                               while( $pool = $result->fetchRow(DB_FETCHMODE_ASSOC) ) {
+                                       array_push( $pool_list, array( $pool['Name'] => $pool['PoolId'] ) );
+                               }
+                               return $pool_list;
+                       }
+               }
                
                public function Get_BackupJob_Names()
                {
@@ -437,6 +428,27 @@ class Bweb extends DB {
                        }
                }
                
+               // Return elasped time string for a job
+               function Get_ElapsedTime( $start_time, $end_time ) 
+               { 
+                       $diff = $end_time - $start_time;
+                       
+                       $daysDiff = sprintf("%02d", floor($diff/60/60/24) );
+                       $diff -= $daysDiff*60*60*24;
+                       
+                       $hrsDiff = sprintf("%02d", floor($diff/60/60) );
+                       $diff -= $hrsDiff*60*60;
+                       
+                       $minsDiff = sprintf("%02d", floor($diff/60) );
+                       $diff -= $minsDiff*60;
+                       $secsDiff = sprintf("%02d", $diff );
+                       
+                       if( $daysDiff > 0 )
+                               return $daysDiff . 'day(s) ' . $hrsDiff.':' . $minsDiff . ':' . $secsDiff;
+                       else
+                               return $hrsDiff . ':' . $minsDiff . ':' . $secsDiff;
+               }
+               
                public function Get_ElapsedTime_Job( $delay = LAST_DAY )
                {
                        $query                  = "";
@@ -446,8 +458,8 @@ class Bweb extends DB {
                        $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 );
+                       $start_date = date( "Y-m-d H:i:s", $start_date );
+                       $end_date   = date( "Y-m-d H:i:s", $end_date );
                        
                        switch( $this->driver )
                        {
@@ -466,345 +478,161 @@ class Bweb extends DB {
                                        $total_elapsed += $time['elapsed'];
                                }
                                // Verify if elapsed time is more than 1 day
-                               if ( $total_elapsed > 86400 ) {
-                                       return gmstrftime("%d days %H:%M:%S", $total_elapsed );
+                               if ( $total_elapsed > LAST_DAY ) {
+                                       return date("%d days H:i:s", $total_elapsed );
                                }else {
-                                       return gmstrftime("%H:%M:%S", $total_elapsed );
+                                       return date("H:i:s", $total_elapsed );
                                }
                        }
                }
+               
+               // Return Jobs statistics for a specific interval such as
+               // - Completed jobs number
+               // - Failed jobs number
+               // - Waiting jobs number
+               // The returned values will be used by a Bgraph classe
+               public function GetJobsStatistics( $type = 'completed', $delay = LAST_DAY )
+               {
+                       $query  = "";
+                       $where  = "";
+                       $jobs   = "";
+                       $label  = "";
+                       $res    = "";
                        
+                       // Interval calculation
+                       $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 );
+                       
+                       // Job status
+                       switch( $type )
+                       {
+                               case 'completed':
+                                       $where = "AND JobStatus = 'T' ";
+                                       $label = "Completed";
+                               break;
+                               case 'terminated_errors':
+                                       $where = $interval_where . "JobStatus = 'E' ";
+                                       $label = "Terminated with errors";
+                               break;
+                               case 'failed':
+                                       $where = "AND JobStatus = 'f' ";
+                                       $label = "Failed";
+                               break;
+                               case 'waiting':
+                                       $where = "AND JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
+                                       $label = "Waiting";
+                               break;
+                               case 'created':
+                                       $where = "AND JobStatus = 'C' ";
+                                       $label = "Created but not running";
+                               break;
+                               case 'running':
+                                       $where = "AND JobStatus = 'R' ";
+                                       $label = "Running";
+                               break;
+                               case 'error':
+                                       $where = "AND JobStatus IN ('e','f') ";
+                                       $label = "Errors";
+                               break;
+                       }
+                       
+                       $query  = 'SELECT COUNT(JobId) AS ' . $type . ' ';
+                       $query .= 'FROM Job ';
+                       $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+                       $query .= $where;
                
-} // end class Bweb
-
-class BGraph {
-
-        var $type;
-        var $sizex;
-        var $sizey;
-        var $MarginBottom;
-        var $MarginLeft;
-        var $Leg;
-
-
-        
-        function BShowGraph($datos,$title,$xlabel,$ylabel,$leyenda,$tipo="lines") {
-        
-                global $type;
-        
-                require_once ("external_packages/phplot/phplot.php");
-
-                if ( empty($this->sizex) || empty($this->sizey) ) {    //Default size
-                        $this->sizex = "600";
-                        $this->sizey = "400";
-                }
-                if ( empty($this->MarginBottom) ) {
-                        $this->MarginBottom = 120;
-                }
-                
-                $legend = $leyenda;
-//              $bgcolor = array(222,206,215);      // Background color of graph
-                $bgcolor = array(207,231,231);
-                $fgcolor = array(110,41,57);
-                
-
-                
-                $graph = new PHPlot($this->sizex,$this->sizey,"","");
-
-                if ( !empty($type) )
-                        $graph->setDataType($type);
-
-                $graph->SetDataValues($datos);
-                $graph->SetPlotType($tipo);
-//              $graph->SetUseTTF(1);
-                $graph->SetBackgroundColor($bgcolor);
-
-                $graph->SetLegendPixels(1,20);
-                $graph->SetDataColors(array('SkyBlue','purple','PeachPuff','aquamarine1','#2CB04B','beige','#9F865F','#135568','orchid','navy','red', 'black', 'blue', 'green', 'brown', 'yellow','cyan','orange','#B9F5A7','#AFAFAF'));
-                $graph->SetTitle($title);
-                $graph->SetXLabel($xlabel);
-                $graph->SetYLabel($ylabel);
-                $graph->SetPlotAreaWorld("","","","");
-                
-                if ( count($datos) > 5 )
-                        $graph->SetXDataLabelAngle(90);
-                else
-                        $graph->SetXDataLabelAngle(0);
-               $graph->SetNumXTicks(1);
-//              $graph->SetXDataLabelPos('none');
-//              $graph->SetXTickLabelPos('plotdown');
-                
-//              $graph->SetXGridLabelType("time");
-//              $graph->SetXTimeFormat("%b ") ;
-
-                if ( $this->Leg == 1 ) {
-                        $this->MarginLeftWithLegend($legend);
-                        $graph->SetMarginsPixels($this->MarginLeft,10,35,$this->MarginBottom);
-                        $graph->SetLegend($legend);
+                       $jobs = $this->db_link->query( $query );
+               
+                       if (PEAR::isError( $jobs ) ) {
+                               die( "Unable to get last $type jobs status from catalog<br />" . $status->getMessage() );
+                       }else {
+                               $res = $jobs->fetchRow();
+                               return array( $label , current($res) );
+                       }
+               } // end function GetJobsStatistics()
+               
+               public function GetPoolsStatistics( $pools )
+               {
+                       foreach( $pools as $pool_name => $pool ) {
+                               //var_dump( $pool );
+                               $query = "SELECT COUNT(*) AS nb_vol FROM Media WHERE PoolId = '$pool'";
+                               //echo $query . '<br />';
+                               //echo 'Pool name ' . $pool_name . '<br />';
+                               $result = $this->db_link->query( $query );
+                               
+                               if( PEAR::isError( $result ) ) {
+                                       die("Unable to get volume number from catalog");
+                               }else{
+                                       $nb_vol = $result->fetchRow(DB_FETCHMODE_ASSOC);
+                                       return array( $pool_name, $nb_vol['nb_vol'] );
                                }
-                else
-                        $graph->SetMarginsPixels(90,35,35,$this->MarginBottom);
-//              $graph->SetDataColors(array($fgcolor),array( "black"));
-                $graph->SetFileFormat( "png");
-//              $graph->DoScaleData(1,1);
-//              $graph->DoMovingAverage(1,1,1);
-
-//              FIX ME -- to round y axis.
-                $vtick = strlen (round ($graph->max_y));
-                $res = 1;
-                for ($i=1;$i < $vtick; $i++)
-                        $res = $res*10;
-                if (strlen($graph->max_y-$res) != $vtick )
-                        $res = $res/10;
-                $graph->SetVertTickIncrement($res);
-                $graph->DrawGraph();
-
-        }//end Crear
-
-
-//Estupidez que tengo que cambiar. !!!!!!!!!!!
-        function SetDataType($typ) {
-                
-                global $type;
-                $type = $typ;
-        }
-
-        function MarginLeftWithLegend($clients) {
-                
-                $maxlen = 0;
-                
-                while (next($clients)) {
-                        $tmp = strlen(current($clients));
-                        if ( $tmp > $maxlen )
-                                $maxlen = $tmp;
-                }
-                $this->MarginLeft = $maxlen * 9;
-        }       
-
-}//end class
-
-
-
-
-
-class BCreateGraph extends BGraph {
-
-        var $BD_bacula;
-        var $izquierda;
-        var $derecha;
-        var $StartDate;
-        var $EndDate;
-        var $elapsed;                        // Default elapsed time to show complex graphs
-        
-        
-        
-        function BCreateGraph() {
-        
-                $this->StartDate = "1900-01-01";
-                $this->EndDate = "4000-01-01";
-                $this->elapsed = "86400";                   // 24 hours in seconds.
-                
-         }              
-         
-         
-         
-        function BCreate($server,$tipo_dato,$title,$tipo="bars",$xlabel="",$ylabel="") {
-        
-                global $DB_bacula;
-                global $izquierda;
-                global $derecha;
-                global $clientes;
-        
-                $this->clientes=array();
-                $DB_bacula = new Bweb();
-                $datos = $this->SQLPrepareData($server,$tipo_dato);
-        
-                if ( empty($datos) ) {                       //No data = No stats = Empty graph
-                        header("Content-type: image/png");
-                        $img= @ImageCreate(200,100) or die ("Cannot intialize GD stream");
-                        $bgc= ImageColorAllocate($img, 0, 255,255);
-                        $txc= ImageColorAllocate($img, 0,0,0);
-                        ImageString($img, 5, 4, 4, "No data to process", $txc);
-                        ImagePng($img);
-                        ImageDestroy($img);
-                        return; 
-                }
-        
-                if ( empty ($xlabel) ) {                       // If no label, table names like leyends
-                        $xlabel=$derecha; $ylabel=$izquierda; 
-                } 
-                        
-                $this->SetDataType("text-data");
-                $this->BShowGraph($datos,$title,$xlabel,$ylabel,$this->clientes,$tipo);
-                
-        }
-
-
-        function SQLPrepareData($servidor,$tipo_dato=0) {         // Prepare bytes data from database.
-
-                global $DB_bacula;
-                global $izquierda;
-                global $derecha;
-        
-                if ( $tipo_dato<30 ) {               // Simple graph. Only 2 data 
-        
-                switch ($tipo_dato)
-                                {
-                                case BACULA_TYPE_BYTES_FILES:
-                                        $izquierda="jobbytes";
-                                        $derecha="jobfiles";
-                                        break;
-                                case BACULA_TYPE_FILES_JOBID:
-                                        $izquierda="jobfiles";
-                                        $derecha="jobid";
-                                        break;
-                                default:
-                                        $izquierda="jobbytes";
-                                        $derecha="endtime";
-                                        break;
-                                }
-                        $result = $DB_bacula->db_link->query("select $derecha,$izquierda from Job where Name='$servidor' and EndTime < '$this->EndDate' and EndTime > '$this->StartDate' order by SchedTime asc")
-                                or die ("classes.inc: Error at query: 5");
-                while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) ) {
-                        $whole_result[] = $this->array_merge_php4($row["$derecha"],$row[$izquierda]);
-                }
-                $result->free();
-        } else {                                                // Complex graph. 3 or more data.
-                
-                        switch ( $tipo_dato )
-                                {
-                                case '30':                      // Unused, at this time.
-                                        $result = $DB_bacula->db_link->query("select JobBytes,JobFiles,Jobid from Job where Name='$servidor' order by EndTime asc")
-                                                or die ("classes.inc: Error at query: 6");
-                                        while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) )
-                                                $whole_result[] = array_merge($row["Jobid"],$row["JobFiles"],$row["JobBytes"]);
-                                        $result->free();
-                                        break;
-                                case BACULA_TYPE_BYTES_ENDTIME_ALLJOBS:  // Special: Generic graph from all clientes.
-                                        $i = -1;                         // Counter of number of jobs of one client. SP: Contador del nmero de jobs totales de un cliente.
-                                        $i2 = 0;                         // Counter of number of keys of array. SP: Contador del nmero de valores del array.
-                                        
-                                        if ($DB_bacula->driver == "mysql") {
-                                        $res = $DB_bacula->db_link->query("select Name from Job where UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-$this->elapsed  group by Name order by Name desc")
-                                                or die ("classes.inc: Error at query: 7");
-                                                $resdata = $DB_bacula->db_link->query("select date_format(EndTime,\"%Y-%m-%d\") from Job where UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-$this->elapsed  group by date_format(EndTime, \"%Y-%m-%d\") order by EndTime")
-                                                        or die ("classes.inc: Error at query: 8");
-                                       }
-                                        else if ($DB_bacula->driver == "pgsql") {
-                                               $res = $DB_bacula->db_link->query("select Name from Job where EndTime > now() - 1*interval'$this->elapsed s'  group by Name order by Name desc")
-                                                       or die ("classes.inc: Error at query: 8");
-                                                $resdata = $DB_bacula->db_link->query("select to_char(EndTime,'YY-MM-DD') from Job where EndTime > NOW() - 1*interval'$this->elapsed s'  group by EndTime order by EndTime")
-                                                        or die ("classes.inc: Error at query: 9");
-                                       }
-                                        
-                                       if (PEAR::isError($resdata))
-                                               die("classes.inc: Error at query: 9.1<br>".$resdata->getMessage());
-                                        while ( $tmpdata = $res->fetchRow() )
-                                                array_push($this->clientes,$tmpdata[0]);
-                                                
-//                                      echo "<pre>";
-//                                      print_r ($this->clientes);
-//                                      echo "</pre>";
-                                        
-                                        
-                                        $spr                   = array();                        // Temporal array
-                                        $spr2                  = array();                       // Temporal array
-                                        $whole_result  = array();
-                                        $count                         = 0;
-                                                                               
-                                        while ( $tmpdata = $resdata->fetchRow() ) {
-                                                $count++;
-                                                array_push($spr,$tmpdata[0]);
-                                                if ($DB_bacula->driver == "mysql")
-                                                        $result = $DB_bacula->db_link->query("select date_format(EndTime,\"%Y-%m-%d\"),SUM(JobBytes) as sum,Name as name,count(Name) as Nname from Job WHERE EndTime like '$tmpdata[0]%' group by Name order by Name desc")
-                                                                or die ("classes.inc: Error at query: 10");
-                                                else if ($DB_bacula->driver == "pgsql") {
-                                                       $query = "select to_char(EndTime,'YY-MM-DD'),SUM(JobBytes) as sum,Name,count(Name) as Nname from Job WHERE EndTime like '%$tmpdata[0]%' group by EndTime,Name order by Name desc";
-                                                        $result = $DB_bacula->db_link->query($query)
-                                                                or die ("classes.inc: Error at query: 11");
-                                               }
-                                                while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) ) {
-                                                        $spr2 = array_merge($spr2,array($row["name"]=>$row["sum"]));
-                                                        $i = $result->numRows();
-                                                }
-
-                                        
-//                                              echo "<pre>";
-//                                              print_r ($spr2);
-//                                              echo "</pre>";
-                                                
-                                                reset ($this->clientes);        
-                                               do {
-                                                        if ( $spr2[current($this->clientes)] != NULL)
-                                                                array_push($spr,$spr2[current($this->clientes)]);
-                                                        else
-                                                                array_push($spr,0);
-                                                } while ( next($this->clientes) );
-                                                
-                                                if ( $i2 < $i )
-                                                        $i2 = $i;
-                                                
-                                                if ( $tmpdata[0] != $row["EndTime"] )   
-                                                        array_push($whole_result,$spr);
-                                                
-                                                $spr = array();
-                                                $spr2 = array();
-                                        }
-
-                                        for ( $i = 0; $i < count($whole_result); $i++ ) {  // To equal the arrays so that the graph is not unsquared. SP:Igualamos las matrices para que la gr�ica no se descuadre
-                                                $tmp = count($whole_result[$i]);
-                                                if ( $i2 < $tmp )                // Estupidez?. Check this code later...
-                                                        continue;
-                                                $tmp = $i2 - $tmp;
-                                                for ( $a = 0; $a <= $tmp; $a++ )
-                                                        array_push($whole_result[$i],"0");                                      // Fill the array
-                                        }
-                                        $resdata->free();       
-//                                      echo "DEBUG:<br>";
-//                                      echo "<pre>";
-//                                      print_r ($whole_result);
-//                                      echo "</pre>";  
-                                        break;
-                                
-                                default:
-                                        break;
-                        }
-                }
-//      $result->free();
-          return $whole_result;
-        }//end function
-
-
-
-        //Convert date from mysql to smarty.           THE SAME FUNCTION AT 2 CLASSES. THIS WAY IS BUGGY. TO SOLVE LATER.
-        function PrepareDate($StartDateMonth,$StartDateDay,$StartDateYear,$EndDateMonth,$EndDateDay,$EndDateYear){
-        
-                $this->StartDate = $StartDateYear."-".$StartDateMonth."-".$StartDateDay." 00:00:00";
-                $this->EndDate = $EndDateYear."-".$EndDateMonth."-".$EndDateDay." 23:59:00";
-                
-        }//end function
-
-
-        function array_merge_php4($array1,$array2) {
-            $return=array();
-
-            foreach(func_get_args() as $arg) {
-                if(!is_array($arg)){
-                $arg=array($arg);
-                }
-                    foreach($arg as $key=>$val){
-                            if(!is_int($key)){
-                                $return[$key]=$val;
-                            }else{
-                                $return[]=$val;
-                            }
-                    }
-            }
-        return $return;
-        }
-
-}//end class
-
+                       }
+               }
+               
+               public function GetStoredFiles()
+               {
+                       $nbfiles = 0;
+                       $query = "SELECT COUNT(FilenameId) AS nbfiles FROM Filename";
+                       $result = $this->db_link->query( $query );
+                       
+                       if( !PEAR::isError($result) ) {
+                               $nbfiles = $result->fetchRow(DB_FETCHMODE_ASSOC);
+                               $nbfiles = $nbfiles['nbfiles'];
+                       }else{
+                               die("Unable to get protected files from catalog");
+                       }
+                       return $nbfiles;
+               }
+               
+               public function GetStoredBytes( $delay = LAST_DAY )
+               {
+                       $query = "SELECT SUM(JobBytes) as stored_bytes FROM Job ";
+                       
+                       // Interval calculation
+                       $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 );
+                       
+                       if( $delay != ALL ) {
+                               $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
+                       }
+                       
+                       $result = $this->db_link->query( $query );
+                       
+                       if( PEAR::isError( $result ) ) {
+                               die( "Unable to get Job Bytes from catalog" );
+                       }else{
+                               return $result->fetchRow( DB_FETCHMODE_ASSOC );
+                       }
+               }
+               
+               public function GetStoredBytesByInterval( $start_date, $end_date )
+               {
+                       $query = "SELECT SUM(JobBytes) as stored_bytes, EndTime FROM Job WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
+                       
+                       $result = $this->db_link->query( $query );
+                       
+                       if( PEAR::isError( $result ) ) {
+                               die( "Unable to get Job Bytes from catalog" );
+                       }else{
+                               $stored_bytes = 0;
+                               $tmp = $result->fetchRow( DB_FETCHMODE_ASSOC );
+                               
+                               $day = date( "D d", strtotime($end_date) );
+                               
+                               if( isset( $tmp['stored_bytes'] ) ) {
+                                       $hbytes = $this->human_file_size( $tmp['stored_bytes'], 3, 'GB');
+                                       $hbytes = explode( " ", $hbytes );
+                                       $stored_bytes = $hbytes[0];
+                               }
+                               
+                               return array( $day, $stored_bytes );
+                       }
+               }
+} // end class Bweb
 ?>
-