]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/bweb.inc.php
bacula-web: New function GetStoredFiles() in bweb.inc.php
[bacula/bacula] / gui / bacula-web / bweb.inc.php
1 <?php
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004-2005 Juan Luis Frances Jiminez                       |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+ 
16 */
17 // Last Err: 11
18 define('CONFIG_DIR', "configs");
19 define('CONFIG_FILE', "bacula.conf");
20 define('BACULA_TYPE_BYTES_FILES', 1);
21 define('BACULA_TYPE_FILES_JOBID', 2);
22 define('BACULA_TYPE_BYTES_ENDTIME_ALLJOBS', 69);
23
24 require_once "paths.php";
25 require_once "DB.php";                                                                                                                  // Pear DB
26 require_once "config.inc.php";
27 require_once "bgraph.inc.php";
28 require_once($smarty_path."Config_File.class.php");
29
30 if (!function_exists('array_fill')) {                                                                                   // For PHP < 4.2.0 users 
31     require_once('array_fill.func.php');
32 }
33
34 class Bweb extends DB {
35
36     var $StartDate;
37     var $EndDate;
38     var $driver;
39         var $dbs;
40         var $dbs_name;
41         
42         public $db_link;                                                // Database link
43         private $db_dsn;                                                // Data Source Name
44         
45         private $config_file;                                   // Config filename
46         private $config;                                                // Loaded config from bacula.conf
47         private $catalogs = array();                    // Catalog array
48
49     function __construct()
50         {             
51                 $this->catalogs = array();
52                 
53                 // Loading configuration
54                 $this->config_file = getcwd() . '/configs/bacula.conf';
55                 if( !$this->load_config() )
56                         die( "Unable to load configuration");
57                         
58                 //echo "Number of catalog defined " . count($this->catalogs) . "<br />";
59                 
60                 /*
61                 $conf = new Config_File (CONFIG_DIR);
62                 $this->dbs = array();
63
64                 $i = 2;
65                 $sections = $conf->get(CONFIG_FILE,"DATABASE","host");
66                 array_push($this->dbs, "DATABASE");
67
68                 while ( !empty($sections) ) {                
69                         $sections = $conf->get(CONFIG_FILE,"DATABASE".$i,"host");
70                         if ( !empty($sections) )
71                                 array_push($this->dbs,"DATABASE".$i);
72                         $i++;
73                 }
74
75                 if ( $i < 4)
76                         $sec = "DATABASE";
77                 else {
78                         if ( !empty($_POST['sel_database']) ) {
79                                 $_SESSION['DATABASE'] = $_POST['sel_database'];
80                                 $sec = $_POST['sel_database'];
81                         } else {
82                                 if (isset($_SESSION['DATABASE']) )
83                                         $sec = $_SESSION['DATABASE'];
84                                 else
85                                         $sec = "DATABASE";
86                         }
87                 }
88
89         $this->dsn['hostspec'] = $conf->get(CONFIG_FILE,$sec,"host");
90         $this->dsn['username'] = $conf->get(CONFIG_FILE,$sec,"login");
91         $this->dsn['password'] = $conf->get(CONFIG_FILE,$sec,"pass");
92         $this->dsn['database'] = $conf->get(CONFIG_FILE,$sec,"db_name");
93         $this->dsn['phptype']  = $conf->get(CONFIG_FILE,$sec,"db_type");   // mysql, pgsql
94         
95                 if (  $conf->get(CONFIG_FILE,$sec,"db_port") )
96                         $this->dsn[port] = $conf->get(CONFIG_FILE,$sec,"db_port");
97                 */
98                 
99                 // Construct a valid dsn
100         $this->db_dsn['hostspec'] = $this->catalogs[0]["host"];
101         $this->db_dsn['username'] = $this->catalogs[0]["login"];
102                 $this->db_dsn['password'] = $this->catalogs[0]["pass"];
103                 $this->db_dsn['database'] = $this->catalogs[0]["db_name"];
104                 $this->db_dsn['phptype']  = $this->catalogs[0]["db_type"];
105                 
106                                         
107         $this->db_link = $this->connect($this->db_dsn);
108         
109                 if (DB::isError($this->db_link)) {
110                         die($this->db_link->getMessage());
111                 }else {
112                         $this->driver = $this->db_dsn['phptype'];                            
113             register_shutdown_function(array(&$this,'close'));
114                         $this->dbs_name = $this->db_dsn['database'];
115                 }
116         }
117                 
118     function load_config()
119         {
120                 $this->config = parse_ini_file( $this->config_file, true );
121                 
122                 if( !$this->config == false ) {
123                         // Loading database connection information
124                         foreach( $this->config as $parameter => $value )
125                         {
126                                 //echo "Param $parameter = $value <br />";
127                                 if( is_array($value) ){         // Parsing database section
128                                         array_push( $this->catalogs, $value );
129                                 }
130                         }
131                         return true;
132                 }else
133                         return false;
134         }
135         
136         public function get_config_param( $param )
137         {
138                 if( isset( $this->config[$param] ) )
139                         return $this->config[$param];
140                 else
141                         return false;
142         }
143         
144         public function Get_Nb_Catalogs() 
145         {
146                 return count( $this->catalogs );
147         }
148         
149         
150         function close() 
151         {
152                 $this->db_link->disconnect();
153     }      
154
155         
156          
157         function CalculateBytesPeriod($server,$StartDate,$EndPeriod) {   // Bytes transferred in a period.
158
159                 $result =& $this->db_link->query("select SUM(JobBytes) from Job WHERE EndTime < '$EndPeriod' and EndTime > '$StartDate' and Name='$server'")
160                         or die("classes.inc: Error query: 1");
161                 $return =& $result->fetchRow(); 
162                 return $return[0];
163         }//end function
164
165         
166          
167         function CalculateFilesPeriod($server,$StartDate,$EndPeriod) {    // Number of files transferred in a period.
168
169                 $result =& $this->db_link->query("select SUM(JobFiles) from Job WHERE EndTime < '$EndPeriod' and EndTime > '$StartDate' and Name='$server'")
170                         or die("classes.inc: Error query: 2");
171                 $return =& $result->fetchRow();
172                 return $return[0];
173         }//end function 
174
175                  
176
177         function PrepareDate($StartDateMonth,$StartDateDay,$StartDateYear,$EndDateMonth,$EndDateDay,$EndDateYear) {  // Convert date for Smarty. Check if only works with Mysql.
178         
179                 $this->StartDate=$StartDateYear."-".$StartDateMonth."-".$StartDateDay." 00:00:00";
180                 $this->EndDate=$EndDateYear."-".$EndDateMonth."-".$EndDateDay." 23:59:59";  // last day full
181                 
182         }//end function
183                 
184                 // Return humanized size with default unit of GB
185                 // if auto provide for unit argument, automaticaly decide which unit
186                 function human_file_size( $size, $decimal = 2, $unit = 'auto' )
187                 {
188                         $unit_id = 0;
189                         $lisible = false;
190                         $units = array('B','KB','MB','GB','TB');
191                         $hsize = $size;
192
193                         switch( $unit )
194                         {
195                                 case 'auto';
196                                         while( !$lisible ) {
197                                                 if ( $hsize >= 1024 ) {
198                                                         $hsize    = $hsize / 1024;
199                                                         $unit_id += 1;
200                                                 }        
201                                                 else {
202                                                         $lisible = true;
203                                                 } 
204                                         }
205                                 break;
206                                 
207                                 default:
208                                         $p = array_search( $unit, $units);
209                                         $hsize = $hsize / pow(1024,$p);
210                                 break;
211                         } // end switch
212                         
213                         $hsize = sprintf("%." . $decimal . "f", $hsize);
214                         $hsize = $hsize . ' ' . $units[$unit_id];
215                         return $hsize;
216                 } // end function
217
218                 
219                 function GetDbSize() 
220                 {
221                         $database_size = 0;
222                         if ( $this->driver == "mysql") {
223                                 $dbsize = $this->db_link->query("show table status") or die ("classes.inc: Error query: 3");
224                                 
225                                 if ( $dbsize->numRows() ) {
226                                         while ( $res = $dbsize->fetchRow(DB_FETCHMODE_ASSOC) )
227                                                 $database_size += $res["Data_length"];
228                 } else {
229                                         return 0;
230                                 } // end if else
231             } // end if
232             else if ( $this->driver == "pgsql") {
233                                 $dbsize = $this->db_link->query("select pg_database_size('$this->dbs_name')") or die ("classes.inc: Error query: 4");
234                                 
235                                 if (PEAR::isError($dbsize))
236                                         die($dbsize->getMessage());
237                     
238                                 if ( $dbsize->numRows() ) {
239                                         while ( $res = $dbsize->fetchRow() )
240                                                 $database_size += $res[0];
241                 } else {
242                                         return 0;
243                                 }
244             } // end if       
245                                 
246                         $dbsize->free();
247                 
248                         return $this->human_file_size( $database_size );  
249         } // end function GetDbSize()
250                 
251                 public function Get_Nb_Clients()
252                 {
253                         $clients = $this->db_link->query("SELECT COUNT(*) AS nb_client FROM Client");
254                         if( PEAR::isError($clients) )
255                                 die( "Unable to get client number" );
256                         else
257                                 return $clients->fetchRow( DB_FETCHMODE_ASSOC );
258                 }
259
260                 // Return an array of volumes ordered by poolid and volume name
261                 function GetVolumeList() {
262
263                 $volumes   = array();
264                 $query     = "";
265                                 $debug     = false;
266                                 
267                                 // Get the list of pools id
268                                 $query = "SELECT Pool.poolid, Pool.name FROM Pool ORDER BY Pool.poolid";
269                                 
270                                 //$this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
271                                 $pools = $this->db_link->query( $query );
272                                 
273                                 if( PEAR::isError( $pools ) )
274                                         die("Error: Failed to get pool list <br />SQL Query: $query<br />" . $pools->getMessage() );
275                                 
276                                 while( $pool = $pools->fetchRow( DB_FETCHMODE_ASSOC ) ) {
277                                         switch( $this->driver )
278                                         {
279                                                 case 'mysql':
280 /*
281                                                         $query  = "SELECT Media.VolumeName, Media.VolBytes, Media.VolStatus, Pool.Name, Media.MediaType,Media.LastWritten, FROM_UNIXTIME(UNIX_TIMESTAMP(Media.LastWritten)+Media.VolRetention ) AS expire 
282                                                                            FROM Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId WHERE poolid='$pool[0]' 
283                                                                            ORDER BY Media.VolumeName";
284 */
285                                                         $query  = "SELECT Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention
286                                                                            FROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid
287                                                                        WHERE Media.poolid = '". $pool['poolid'] . "' ORDER BY Media.volumename";
288                                                 break;
289                                                 case 'pgsql':
290                                                         $query  = "SELECT media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention
291                                                                            FROM media LEFT JOIN pool ON media.poolid = pool.poolid
292                                                                        WHERE media.poolid = '". $pool['poolid'] . "' ORDER BY media.volumename";
293                                                         /*
294                                                         $query  = "SELECT Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten, Media.LastWritten + Media.VolRetention * interval '1 second' AS expire 
295                                                                            FROM Pool LEFT JOIN Media ON media.poolid=pool.poolid WHERE poolid='$pool[0]' 
296                                                                            ORDER BY Media.VolumeName";
297                                                         */
298                                                 break;
299                                                 case 'sqlite':
300                                                         $query  = "";           // not yet implemented
301                                                 break;
302                                                 default:
303                                                 break;
304                                         } // end switch
305                                         
306                                         //$this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
307                                         $medias = $this->db_link->query( $query );
308
309                                         if( PEAR::isError( $medias ) ) {
310                                                 die( "Failed to get media list for pool $volume[0] <br /> " . $medias->getMessage() );
311                                         }else {
312                                                 if( $debug ) echo "Found " . $medias->numRows() . " medias for pool " . $pool['name'] . " <br />";
313                                         
314                                                 // Create array key for each pool
315                                                 if( !array_key_exists( $pool['name'], $volumes) )
316                                                 {
317                                                         $volumes[ $pool['name'] ] = array();
318                                                 }
319                                                 while( $media = $medias->fetchRow( DB_FETCHMODE_ASSOC ) ) {
320                                                         if( $debug ) {
321                                                                 var_dump( $media );
322                                                         }
323                                                         // If the pool is empty (no volumes in this pool)
324                                                         if( $medias->numRows() == 0 ) {
325                                                                 if( $debug ) echo "No media in pool " . $pool['name'] . "<br />";
326                                                         } else {
327                                                                         if( $media['lastwritten'] != "0000-00-00 00:00:00" ) {
328                                                                                 // Calculate expiration date if the volume is Full
329                                                                                 if( $media['volstatus'] == 'Full' ) {
330                                                                                         $expire_date     = strtotime($media['lastwritten']) + $media['volretention'];
331                                                                                         $media['expire'] = strftime("%Y-%m-%d", $expire_date);
332                                                                                 }else {
333                                                                                         $media['expire'] = 'N/A';
334                                                                                 }
335                                                                                 // Media used bytes in a human format
336                                                                                 $media['volbytes'] = $this->human_file_size( $media['volbytes'] );
337                                                                                 //echo "volume " . $media['volumename'] . 'vol bytes' .$media['volbytes'] . '<br />';
338                                                                         } else {
339                                                                                 $media['lastwritten'] = "N/A";
340                                                                                 $media['expire']      = "N/A";
341                                                                                 $media['volbytes']        = "0 KB";
342                                                                         }                                                               
343                                                                 // Add the media in pool array
344                                                                 array_push( $volumes[ $pool['name']], $media);
345                                                         }
346                                                 } // end while
347                                         } // end if else
348                                 } // end while
349                                 return $volumes;
350         } // end function GetVolumeList()
351                 
352                 public function GetLastJobs( $delay = LAST_DAY )
353                 {
354                         $query          = "";
355                         $start_date = "";
356                         $end_date       = "";
357                         
358                         // Interval calculation
359                         $end_date   = mktime();
360                         $start_date = $end_date - $delay;
361                         
362                         $start_date = date( "Y-m-d H:m:s", $start_date );
363                         $end_date   = date( "Y-m-d H:m:s", $end_date );
364                         
365                         switch( $this->driver )
366                         {
367                                 case 'mysql':
368                                         $query  = 'SELECT COUNT(JobId) AS completed_jobs ';
369                                         $query .= 'FROM Job ';
370                                         $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
371                                         $query .= "AND JobStatus = 'T'";
372                                 break;
373                         }
374                 
375                         $jobs = $this->db_link->query( $query );
376                 
377                         if (PEAR::isError( $jobs ) ) {
378                                 die( "Unable to get last completed jobs status from catalog<br />" . $status->getMessage() );
379                         }else {
380                                 return $jobs->fetchRow( DB_FETCHMODE_ASSOC );
381                         }
382                 } // end function GetLastJobStatus()
383                 
384                 public function GetLastErrorJobs( $delay = LAST_DAY )
385                 {
386                         $query          = "";
387                         
388                         // Interval calculation
389                         $end_date   = mktime();
390                         $start_date = $end_date - $delay;
391                         
392                         $start_date = date( "Y-m-d H:m:s", $start_date );
393                         $end_date   = date( "Y-m-d H:m:s", $end_date );
394                         
395                         //echo "start date: $start_date <br />";
396                         //echo "end date: $end_date <br />";
397                         
398                         switch( $this->driver )
399                         {
400                                 default:
401                                         $query  = 'SELECT COUNT(JobId) AS failed_jobs ';
402                                         $query .= 'FROM Job ';
403                                         $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
404                                         $query .= "AND JobStatus = 'f'";
405                                 break;
406                         }                               
407                         $result = $this->db_link->query( $query );
408                         
409                         if (PEAR::isError( $result ) ) {
410                                 die( "Unable to get last failed jobs status from catalog<br />query = $query <br />" . $result->getMessage() );
411                         }else {
412                                 return $result->fetchRow( DB_FETCHMODE_ASSOC );
413                         } // end if else
414                 } // end function GetLastErrorJobs
415                 
416                 // Return the list of Pools in a array
417                 public function Get_Pools_List()
418                 {
419                         $pool_list = array();
420                         $result    = "";
421                         
422                         $query = "SELECT Name, PoolId FROM Pool";
423                         
424                         $result = $this->db_link->query ( $query );
425         
426                         if( PEAR::isError( $result ) ) {
427                                 die( "Unable to get the pool list from catalog" );                              
428                         }else {
429                                 while( $pool = $result->fetchRow(DB_FETCHMODE_ASSOC) ) {
430                                         array_push( $pool_list, array( $pool['Name'] => $pool['PoolId'] ) );
431                                 }
432                                 return $pool_list;
433                         }
434                 }
435                 
436                 public function Get_BackupJob_Names()
437                 {
438                         $query          = "SELECT Name FROM Job GROUP BY Name";
439                         $backupjobs = array();
440                         
441                         $result = $this->db_link->query( $query );
442                         
443                         if (PEAR::isError( $result ) ) {
444                                 die("Unable to get BackupJobs list from catalog" );
445                         }else{
446                                 while( $backupjob = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {
447                                         array_push( $backupjobs, $backupjob["Name"] );
448                                 }
449                                 return $backupjobs;
450                         }
451                 }
452                 
453                 public function Get_ElapsedTime_Job( $delay = LAST_DAY )
454                 {
455                         $query                  = "";
456                         $total_elapsed  = 0;
457                         
458                         // Interval calculation
459                         $end_date   = mktime();
460                         $start_date = $end_date - $delay;
461                         
462                         $start_date = date( "Y-m-d H:m:s", $start_date );
463                         $end_date   = date( "Y-m-d H:m:s", $end_date );
464                         
465                         switch( $this->driver )
466                         {
467                                 case 'mysql':
468                                         $query  = "SELECT UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime) AS elapsed from Job ";
469                                         $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
470                                 break;
471                         }
472                         $result = $this->db_link->query( $query );
473                         
474                         if( PEAR::isError($result) ){
475                                 die( "Unable to get elapsed time for jobs from catalog<br />query = $query <br />" . $result->getMessage() );
476                         }else {
477                                 while( $time = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {
478                                         //echo 'elapsed = ' . $time['elapsed'] . '<br />';
479                                         $total_elapsed += $time['elapsed'];
480                                 }
481                                 // Verify if elapsed time is more than 1 day
482                                 if ( $total_elapsed > 86400 ) {
483                                         return gmstrftime("%d days %H:%M:%S", $total_elapsed );
484                                 }else {
485                                         return gmstrftime("%H:%M:%S", $total_elapsed );
486                                 }
487                         }
488                 }
489                 
490                 // Return Jobs statistics for a specific interval such as
491                 // - Completed jobs number
492                 // - Failed jobs number
493                 // - Waiting jobs number
494                 // The returned values will be used by a Bgraph classe
495                 public function GetJobsStatistics( $type = 'completed', $delay = LAST_DAY )
496                 {
497                         $query  = "";
498                         $where  = "";
499                         $jobs   = "";
500                         $label  = "";
501                         $res    = "";
502                         
503                         // Interval calculation
504                         $end_date   = mktime();
505                         $start_date = $end_date - $delay;
506                         
507                         $start_date = date( "Y-m-d H:m:s", $start_date );
508                         $end_date   = date( "Y-m-d H:m:s", $end_date );
509                         
510                         // Job status
511                         switch( $type )
512                         {
513                                 case 'completed':
514                                         $where = "AND JobStatus = 'T' ";
515                                         $label = "Completed";
516                                 break;
517                                 case 'completed_errors':
518                                         $where = "AND JobStatus = 'E' ";
519                                         $label = "Completed with errors";
520                                 break;
521                                 case 'failed':
522                                         $where = "AND JobStatus = 'f' ";
523                                         $label = "Failed";
524                                 break;
525                                 case 'waiting':
526                                         $where = "AND JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
527                                         $label = "Waiting";
528                                 break;
529                                 case 'created':
530                                         $where = "AND JobStatus = 'C' ";
531                                         $label = "Created but not running";
532                                 break;
533                                 case 'running':
534                                         $where = "AND JobStatus = 'R' ";
535                                         $label = "Running";
536                                 break;
537                                 case 'error':
538                                         $where = "AND JobStatus IN ('e','f') ";
539                                         $label = "Errors";
540                                 break;
541                         }
542                         
543                         $query  = 'SELECT COUNT(JobId) AS ' . $type . ' ';
544                         $query .= 'FROM Job ';
545                         $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
546                         $query .= $where;
547                 
548                         $jobs = $this->db_link->query( $query );
549                 
550                         if (PEAR::isError( $jobs ) ) {
551                                 die( "Unable to get last $type jobs status from catalog<br />" . $status->getMessage() );
552                         }else {
553                                 $res = $jobs->fetchRow();
554                                 return array( $label , current($res) );
555                         }
556                 } // end function GetJobsStatistics()
557                 
558                 public function GetPoolsStatistics( $pools )
559                 {
560                         foreach( $pools as $pool_name => $pool ) {
561                                 //var_dump( $pool );
562                                 $query = "SELECT COUNT(*) AS nb_vol FROM Media WHERE PoolId = '$pool'";
563                                 //echo $query . '<br />';
564                                 //echo 'Pool name ' . $pool_name . '<br />';
565                                 $result = $this->db_link->query( $query );
566                                 
567                                 if( PEAR::isError( $result ) ) {
568                                         die("Unable to get volume number from catalog");
569                                 }else{
570                                         $nb_vol = $result->fetchRow(DB_FETCHMODE_ASSOC);
571                                         return array( $pool_name, $nb_vol['nb_vol'] );
572                                 }
573                         }
574                 }
575                 
576                 public function GetStoredFiles()
577                 {
578                         $nbfiles = 0;
579                         $query = "SELECT COUNT(FilenameId) AS nbfiles FROM Filename";
580                         $result = $this->db_link->query( $query );
581                         
582                         if( !PEAR::isError($result) ) {
583                                 $nbfiles = $result->fetchRow(DB_FETCHMODE_ASSOC);
584                                 $nbfiles = $nbfiles['nbfiles'];
585                         }else{
586                                 die("Unable to get protected files from catalog");
587                         }
588                         return $nbfiles;
589                 }
590                 
591                 public function GetStoredBytes( $delay = LAST_DAY )
592                 {
593                         $query = "SELECT SUM(JobBytes) as stored_bytes FROM Job ";
594                         
595                         // Interval calculation
596                         $end_date   = mktime();
597                         $start_date = $end_date - $delay;
598                         
599                         $start_date = date( "Y-m-d H:m:s", $start_date );
600                         $end_date   = date( "Y-m-d H:m:s", $end_date );
601                         
602                         if( $delay != ALL ) {
603                                 $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
604                         }
605                         
606                         $result = $this->db_link->query( $query );
607                         
608                         if( PEAR::isError( $result ) ) {
609                                 die( "Unable to get Job Bytes from catalog" );
610                         }else{
611                                 return $result->fetchRow( DB_FETCHMODE_ASSOC );
612                         }
613                 }
614                 
615                 public function GetStoredBytesByInterval( $start_date, $end_date )
616                 {
617                         $query = "SELECT SUM(JobBytes) as stored_bytes, EndTime FROM Job WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
618                         
619                         $result = $this->db_link->query( $query );
620                         
621                         if( PEAR::isError( $result ) ) {
622                                 die( "Unable to get Job Bytes from catalog" );
623                         }else{
624                                 $stored_bytes = 0;
625                                 $tmp = $result->fetchRow( DB_FETCHMODE_ASSOC );
626                                 
627                                 $day = date( "d/m", strtotime($end_date) );
628                                 
629                                 if( isset( $tmp['stored_bytes'] ) ) {
630                                         $hbytes = $this->human_file_size( $tmp['stored_bytes'], 3, 'GB');
631                                         $hbytes = explode( " ", $hbytes );
632                                         $stored_bytes = $hbytes[0];
633                                 }
634                                 
635                                 return array( $day, $stored_bytes );
636                         }
637                 }
638 } // end class Bweb
639 ?>