]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/bweb.inc.php
bacula-web: Removed paths.php from git
[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 require_once "config.inc.php";
18
19 class Bweb extends DB {
20
21     var $StartDate;
22     var $EndDate;
23     var $driver;
24         var $dbs;
25         var $dbs_name;
26         
27         public $tpl;
28         public $db_link;                                                // Database link
29         private $db_dsn;                                                // Data Source Name
30         
31         private $config_file;                                   // Config filename
32         private $config;                                                // Loaded config from bacula.conf
33         private $catalogs = array();                    // Catalog array
34
35     function __construct()
36         {             
37                 $this->catalogs = array();
38                 
39                 // Loading configuration
40                 $this->config_file = getcwd() . '/configs/bacula.conf';
41                 
42                 if( !$this->load_config() )
43                         die( "Unable to load configuration");
44                         
45                 // Construct a valid dsn
46         $this->db_dsn['hostspec'] = $this->catalogs[0]["host"];
47         $this->db_dsn['username'] = $this->catalogs[0]["login"];
48                 $this->db_dsn['password'] = $this->catalogs[0]["pass"];
49                 $this->db_dsn['database'] = $this->catalogs[0]["db_name"];
50                 $this->db_dsn['phptype']  = $this->catalogs[0]["db_type"];
51                 
52                                         
53         $this->db_link = $this->connect($this->db_dsn);
54         
55                 if (DB::isError($this->db_link)) {
56                         die($this->db_link->getMessage());
57                 }else {
58                         $this->driver = $this->db_dsn['phptype'];                            
59             register_shutdown_function(array(&$this,'close'));
60                         $this->dbs_name = $this->db_dsn['database'];
61                 }
62                 
63                 // Initialize smarty template classe
64                 $this->init_tpl();
65                 // Initialize smarty gettext function
66                 $this->init_gettext();
67         }
68                 
69     // Initialize Smarty template classe
70         function init_tpl()
71         {
72                 $this->tpl = new Smarty();
73                 
74                 $this->tpl->compile_check       = true;
75                 $this->tpl->debugging           = false;
76                 $this->tpl->force_compile       = true;
77
78                 $this->tpl->template_dir        = "./templates";
79                 $this->tpl->compile_dir         = "./templates_c";
80                 $this->tpl->config_dir          = "./configs";
81         }
82         
83         function init_gettext()
84         {
85                 global $smarty_gettext_path;
86                 
87                 if ( function_exists("gettext") ) {
88                         require_once( $smarty_gettext_path."smarty_gettext.php" );     
89                         $this->tpl->register_block('t','smarty_translate');
90         
91                         $language = $this->get_config_param("lang");
92                         $domain = "messages";   
93                         putenv("LANG=$language"); 
94                         setlocale(LC_ALL, $language);
95                         bindtextdomain($domain,"./locale");
96                         textdomain($domain);
97                 }
98                 else {
99                         function smarty_translate($params, $text, &$smarty) {
100                 return $text;
101                         }
102                         $smarty->register_block('t','smarty_translate');
103                 }
104         }
105         
106         function load_config()
107         {
108                 $this->config = parse_ini_file( $this->config_file, true );
109                 
110                 if( !$this->config == false ) {
111                         // Loading database connection information
112                         foreach( $this->config as $parameter => $value )
113                         {
114                                 //echo "Param $parameter = $value <br />";
115                                 if( is_array($value) ){         // Parsing database section
116                                         array_push( $this->catalogs, $value );
117                                 }
118                         }
119                         return true;
120                 }else
121                         return false;
122         }
123         
124         public function get_config_param( $param )
125         {
126                 if( isset( $this->config[$param] ) )
127                         return $this->config[$param];
128                 else
129                         return false;
130         }
131         
132         public function Get_Nb_Catalogs() 
133         {
134                 return count( $this->catalogs );
135         }
136         
137         
138         function close() 
139         {
140                 $this->db_link->disconnect();
141     }      
142
143         
144          
145         function CalculateBytesPeriod($server,$StartDate,$EndPeriod) {   // Bytes transferred in a period.
146
147                 $result =& $this->db_link->query("select SUM(JobBytes) from Job WHERE EndTime < '$EndPeriod' and EndTime > '$StartDate' and Name='$server'")
148                         or die("classes.inc: Error query: 1");
149                 $return =& $result->fetchRow(); 
150                 return $return[0];
151         }//end function
152
153         
154          
155         function CalculateFilesPeriod($server,$StartDate,$EndPeriod) {    // Number of files transferred in a period.
156
157                 $result =& $this->db_link->query("select SUM(JobFiles) from Job WHERE EndTime < '$EndPeriod' and EndTime > '$StartDate' and Name='$server'")
158                         or die("classes.inc: Error query: 2");
159                 $return =& $result->fetchRow();
160                 return $return[0];
161         }//end function 
162
163                  
164
165         function PrepareDate($StartDateMonth,$StartDateDay,$StartDateYear,$EndDateMonth,$EndDateDay,$EndDateYear) {  // Convert date for Smarty. Check if only works with Mysql.
166         
167                 $this->StartDate=$StartDateYear."-".$StartDateMonth."-".$StartDateDay." 00:00:00";
168                 $this->EndDate=$EndDateYear."-".$EndDateMonth."-".$EndDateDay." 23:59:59";  // last day full
169                 
170         }//end function
171                 
172                 // Return humanized size with default unit of GB
173                 // if auto provide for unit argument, automaticaly decide which unit
174                 function human_file_size( $size, $decimal = 2, $unit = 'auto' )
175                 {
176                         $unit_id = 0;
177                         $lisible = false;
178                         $units = array('B','KB','MB','GB','TB');
179                         $hsize = $size;
180
181                         switch( $unit )
182                         {
183                                 case 'auto';
184                                         while( !$lisible ) {
185                                                 if ( $hsize >= 1024 ) {
186                                                         $hsize    = $hsize / 1024;
187                                                         $unit_id += 1;
188                                                 }        
189                                                 else {
190                                                         $lisible = true;
191                                                 } 
192                                         }
193                                 break;
194                                 
195                                 default:
196                                         $p = array_search( $unit, $units);
197                                         $hsize = $hsize / pow(1024,$p);
198                                 break;
199                         } // end switch
200                         
201                         $hsize = sprintf("%." . $decimal . "f", $hsize);
202                         $hsize = $hsize . ' ' . $units[$unit_id];
203                         return $hsize;
204                 } // end function
205
206                 
207                 function GetDbSize() 
208                 {
209                         $database_size  = 0;
210                         $query                  = "";
211                         
212                         switch( $this->driver )
213                         {
214                                 case 'mysql':
215                                         $query  = "SELECT table_schema AS 'database', sum( data_length + index_length) AS 'dbsize' ";
216                                         $query .= "FROM information_schema.TABLES ";
217                                         $query .= "WHERE table_schema = 'bacula' ";
218                                         $query .= "GROUP BY table_schema";
219                                 break;
220                                 case 'pgsql':
221                                         $query  = "SELECT pg_database_size('bacula') AS dbsize";
222                                 break;
223                                 case 'sqlite':
224                                         // Not yet implemented
225                                         return "0 MB";
226                                 break;
227                         }
228                         
229                         $result = $this->db_link->query( $query );
230                         
231                         if(! PEAR::isError( $result ) )
232                         {
233                                 $db = $result->fetchRow( DB_FETCHMODE_ASSOC );
234                                 $database_size =+ $db['dbsize'];
235                         }else
236                                 die( "Unable to get database size<br />" . $jobs->getMessage() );
237                         
238                         return $this->human_file_size( $database_size );  
239         } // end function GetDbSize()
240                 
241                 public function Get_Nb_Clients()
242                 {
243                         $clients = $this->db_link->query("SELECT COUNT(*) AS nb_client FROM Client");
244                         if( PEAR::isError($clients) )
245                                 die( "Unable to get client number" );
246                         else
247                                 return $clients->fetchRow( DB_FETCHMODE_ASSOC );
248                 }
249
250                 // Return an array of volumes ordered by poolid and volume name
251                 function GetVolumeList() {
252
253                 $volumes   = array();
254                 $query     = "";
255                                 $debug     = false;
256                                 
257                                 // Get the list of pools id
258                                 $query = "SELECT Pool.poolid, Pool.name FROM Pool ORDER BY Pool.poolid";
259                                 
260                                 //$this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
261                                 $pools = $this->db_link->query( $query );
262                                 
263                                 if( PEAR::isError( $pools ) )
264                                         die("Error: Failed to get pool list <br />SQL Query: $query<br />" . $pools->getMessage() );
265                                 
266                                 while( $pool = $pools->fetchRow( DB_FETCHMODE_ASSOC ) ) {
267                                         switch( $this->driver )
268                                         {
269                                                 case 'mysql':
270                                                         $query  = "SELECT Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention
271                                                                            FROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid
272                                                                        WHERE Media.poolid = '". $pool['poolid'] . "' ORDER BY Media.volumename";
273                                                 break;
274                                                 case 'pgsql':
275                                                         $query  = "SELECT media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention
276                                                                            FROM media LEFT JOIN pool ON media.poolid = pool.poolid
277                                                                        WHERE media.poolid = '". $pool['poolid'] . "' ORDER BY media.volumename";
278                                                 break;
279                                                 case 'sqlite':
280                                                         $query  = "";           // not yet implemented
281                                                 break;
282                                                 default:
283                                                 break;
284                                         } // end switch
285                                         
286                                         $medias = $this->db_link->query( $query );
287
288                                         if( PEAR::isError( $medias ) ) {
289                                                 die( "Failed to get media list for pool $volume[0] <br /> " . $medias->getMessage() );
290                                         }else {
291                                                 if( $debug ) echo "Found " . $medias->numRows() . " medias for pool " . $pool['name'] . " <br />";
292                                         
293                                                 // Create array key for each pool
294                                                 if( !array_key_exists( $pool['name'], $volumes) )
295                                                 {
296                                                         $volumes[ $pool['name'] ] = array();
297                                                 }
298                                                 while( $media = $medias->fetchRow( DB_FETCHMODE_ASSOC ) ) {
299                                                         if( $debug ) {
300                                                                 var_dump( $media );
301                                                         }
302                                                         // If the pool is empty (no volumes in this pool)
303                                                         if( $medias->numRows() == 0 ) {
304                                                                 if( $debug ) echo "No media in pool " . $pool['name'] . "<br />";
305                                                         } else {
306                                                                         if( $media['lastwritten'] != "0000-00-00 00:00:00" ) {
307                                                                                 // Calculate expiration date if the volume is Full
308                                                                                 if( $media['volstatus'] == 'Full' ) {
309                                                                                         $expire_date     = strtotime($media['lastwritten']) + $media['volretention'];
310                                                                                         $media['expire'] = strftime("%Y-%m-%d", $expire_date);
311                                                                                 }else {
312                                                                                         $media['expire'] = 'N/A';
313                                                                                 }
314                                                                                 // Media used bytes in a human format
315                                                                                 $media['volbytes'] = $this->human_file_size( $media['volbytes'] );
316                                                                         } else {
317                                                                                 $media['lastwritten'] = "N/A";
318                                                                                 $media['expire']      = "N/A";
319                                                                                 $media['volbytes']        = "0 KB";
320                                                                         }                                                               
321                                                                 
322                                                                 // Odd or even row
323                                                                 if( count(  $volumes[ $pool['name'] ] ) % 2)
324                                                                         $media['class'] = 'odd';
325
326                                                                 // Add the media in pool array
327                                                                 array_push( $volumes[ $pool['name']], $media);
328                                                         }
329                                                 } // end while
330                                         } // end if else
331                                 } // end while
332                                 return $volumes;
333         } // end function GetVolumeList()
334                 
335                 public function CountJobsbyLevel( $delay = LAST_DAY, $level = 'F' )
336                 {
337                         $end_date    = mktime();
338                         $start_date  = $end_date - $delay;
339                         
340                         $start_date  = date( "Y-m-d H:i:s", $start_date );
341                         $end_date    = date( "Y-m-d H:i:s", $end_date );
342                         
343                         $query   = "SELECT COUNT(JobId) as jobs FROM Job ";
344                         $query  .= "WHERE (EndTime BETWEEN '$start_date' AND '$end_date') AND ";
345                         $query  .= "Level = '$level' ";
346                         
347                         $result  = $this->db_link->query( $query );
348                         
349                         if (PEAR::isError( $result ) ) {
350                                 die( "Unable to get number of jobs with $level status from catalog <br />" . $result->getMessage() );
351                         }else {
352                                 $jobs = $result->fetchRow( DB_FETCHMODE_ASSOC ); 
353                                 return $jobs['jobs'];
354                         }
355                         
356                 }
357                 
358                 public function CountJobs( $delay = LAST_DAY, $status = 'any' )
359                 {
360                         $query                  = "SELECT COUNT(JobId) AS job_nb FROM Job ";
361                         $where_delay    = "";
362                         $where_status   = "";
363                         
364                         // Interval condition for SQL query
365                         if( $delay != ALL ) {
366                                 $end_date    = mktime();
367                                 $start_date  = $end_date - $delay;
368                         
369                                 $start_date  = date( "Y-m-d H:i:s", $start_date );
370                                 $end_date    = date( "Y-m-d H:i:s", $end_date );
371                         
372                                 $where_delay = "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
373                         }
374                         
375                         if( $status != 'any' ) {
376                                 switch( $status )
377                                 {
378                                         case 'completed':
379                                                 $where_status = "JobStatus = 'T' ";
380                                         break;
381                                         case 'failed':
382                                                 $where_status = "JobStatus IN ('f','E') ";
383                                         break;
384                                         case 'canceled':
385                                                 $where_status = "JobStatus = 'A' ";
386                                         break;
387                                         case 'waiting':
388                                                 $where_status = "JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
389                                         break;
390                                 } // end switch
391                         }
392                         
393                         if( !empty($where_delay) )
394                                 $query = $query . $where_delay . 'AND ' . $where_status;
395                         else {
396                                 if( !empty($where_status) )
397                                         $query = $query . 'WHERE ' . $where_status;
398                         }
399                                 
400                         $jobs = $this->db_link->query( $query );
401                 
402                         if (PEAR::isError( $jobs ) ) {
403                                 die( "Unable to get last $status jobs number from catalog <br />" . $jobs->getMessage() );
404                         }else {
405                                 $jobs = $jobs->fetchRow( DB_FETCHMODE_ASSOC ); 
406                                 return $jobs['job_nb'];
407                         }
408                 }
409                 
410                 // Return the list of Pools in a array
411                 public function Get_Pools_List()
412                 {
413                         $pool_list = array();
414                         $result    = "";
415                         
416                         $query = "SELECT Name, PoolId FROM Pool";
417                         
418                         $result = $this->db_link->query ( $query );
419         
420                         if( PEAR::isError( $result ) ) {
421                                 die( "Unable to get the pool list from catalog" );                              
422                         }else {
423                                 while( $pool = $result->fetchRow(DB_FETCHMODE_ASSOC) ) {
424                                         array_push( $pool_list, array( $pool['Name'] => $pool['PoolId'] ) );
425                                 }
426                                 return $pool_list;
427                         }
428                 }
429                 
430                 public function Get_BackupJob_Names()
431                 {
432                         $query          = "SELECT Name FROM Job GROUP BY Name";
433                         $backupjobs = array();
434                         
435                         $result = $this->db_link->query( $query );
436                         
437                         if (PEAR::isError( $result ) ) {
438                                 die("Unable to get BackupJobs list from catalog" );
439                         }else{
440                                 while( $backupjob = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {
441                                         array_push( $backupjobs, $backupjob["Name"] );
442                                 }
443                                 return $backupjobs;
444                         }
445                 }
446                 
447                 // Return elasped time string for a job
448                 function Get_ElapsedTime( $start_time, $end_time ) 
449                 { 
450                         $diff = $end_time - $start_time;
451                         
452                         $daysDiff = sprintf("%02d", floor($diff/60/60/24) );
453                         $diff -= $daysDiff*60*60*24;
454                         
455                         $hrsDiff = sprintf("%02d", floor($diff/60/60) );
456                         $diff -= $hrsDiff*60*60;
457                         
458                         $minsDiff = sprintf("%02d", floor($diff/60) );
459                         $diff -= $minsDiff*60;
460                         $secsDiff = sprintf("%02d", $diff );
461                         
462                         if( $daysDiff > 0 )
463                                 return $daysDiff . 'day(s) ' . $hrsDiff.':' . $minsDiff . ':' . $secsDiff;
464                         else
465                                 return $hrsDiff . ':' . $minsDiff . ':' . $secsDiff;
466                 }
467                 
468                 public function Get_ElapsedTime_Job( $delay = LAST_DAY )
469                 {
470                         $query                  = "";
471                         $total_elapsed  = 0;
472                         
473                         // Interval calculation
474                         $end_date   = mktime();
475                         $start_date = $end_date - $delay;
476                         
477                         $start_date = date( "Y-m-d H:i:s", $start_date );
478                         $end_date   = date( "Y-m-d H:i:s", $end_date );
479                         
480                         switch( $this->driver )
481                         {
482                                 case 'mysql':
483                                         $query  = "SELECT UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime) AS elapsed from Job ";
484                                         $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
485                                 break;
486                         }
487                         $result = $this->db_link->query( $query );
488                         
489                         if( PEAR::isError($result) ){
490                                 die( "Unable to get elapsed time for jobs from catalog<br />query = $query <br />" . $result->getMessage() );
491                         }else {
492                                 while( $time = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {
493                                         //echo 'elapsed = ' . $time['elapsed'] . '<br />';
494                                         $total_elapsed += $time['elapsed'];
495                                 }
496                                 // Verify if elapsed time is more than 1 day
497                                 if ( $total_elapsed > LAST_DAY ) {
498                                         return date("%d days H:i:s", $total_elapsed );
499                                 }else {
500                                         return date("H:i:s", $total_elapsed );
501                                 }
502                         }
503                 }
504                 
505                 // Return Jobs statistics for a specific interval such as
506                 // - Completed jobs number
507                 // - Failed jobs number
508                 // - Waiting jobs number
509                 // The returned values will be used by a Bgraph classe
510                 public function GetJobsStatistics( $type = 'completed', $delay = LAST_DAY )
511                 {
512                         $query  = "";
513                         $where  = "";
514                         $jobs   = "";
515                         $label  = "";
516                         $res    = "";
517                         
518                         // Interval calculation
519                         $end_date   = mktime();
520                         $start_date = $end_date - $delay;
521                         
522                         $start_date = date( "Y-m-d H:i:s", $start_date );
523                         $end_date   = date( "Y-m-d H:i:s", $end_date );
524                         
525                         $interval_where = "(EndTime BETWEEN '$start_date' AND '$end_date') AND ";
526                         
527                         // Job status
528                         switch( $type )
529                         {
530                                 case 'completed':
531                                         $where = $interval_where . "JobStatus = 'T' ";
532                                         $label = "Completed";
533                                 break;
534                                 case 'terminated_errors':
535                                         $where = $interval_where . "JobStatus = 'E' ";
536                                         $label = "Terminated with errors";
537                                 break;
538                                 case 'failed':
539                                         $where = $interval_where . "JobStatus = 'f' ";
540                                         $label = "Failed";
541                                 break;
542                                 case 'waiting':
543                                         $where = "JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
544                                         $label = "Waiting";
545                                 break;
546                                 case 'created':
547                                         $where = "JobStatus = 'C' ";
548                                         $label = "Created but not running";
549                                 break;
550                                 case 'running':
551                                         $where = "JobStatus = 'R' ";
552                                         $label = "Running";
553                                 break;
554                                 case 'error':
555                                         $where = $interval_where . "JobStatus IN ('e','f') ";
556                                         $label = "Errors";
557                                 break;
558                         }
559                         
560                         $query  = 'SELECT COUNT(JobId) AS ' . $type . ' ';
561                         $query .= 'FROM Job ';
562                         $query .= "WHERE $where ";
563                 
564                         //echo 'query = ' . $query . '<br />';
565                         
566                         $jobs = $this->db_link->query( $query );
567                 
568                         if (PEAR::isError( $jobs ) ) {
569                                 die( "Unable to get last $type jobs status from catalog<br />" . $status->getMessage() );
570                         }else {
571                                 $res = $jobs->fetchRow();
572                                 return array( $label , current($res) );
573                         }
574                 } // end function GetJobsStatistics()
575                 
576                 public function GetPoolsStatistics( $pools )
577                 {
578                         foreach( $pools as $pool_name => $pool ) {
579                                 //var_dump( $pool );
580                                 $query = "SELECT COUNT(*) AS nb_vol FROM Media WHERE PoolId = '$pool'";
581                                 //echo $query . '<br />';
582                                 //echo 'Pool name ' . $pool_name . '<br />';
583                                 $result = $this->db_link->query( $query );
584                                 
585                                 if( PEAR::isError( $result ) ) {
586                                         die("Unable to get volume number from catalog");
587                                 }else{
588                                         $nb_vol = $result->fetchRow(DB_FETCHMODE_ASSOC);
589                                         return array( $pool_name, $nb_vol['nb_vol'] );
590                                 }
591                         }
592                 }
593                 
594                 public function GetStoredFiles( $delay = LAST_DAY )
595                 {
596                         $totalfiles = 0;
597
598                         $query = "SELECT SUM(JobFiles) AS stored_files FROM Job ";
599                         
600                         // Interval calculation
601                         $end_date   = mktime();
602                         $start_date = $end_date - $delay;
603                         
604                         $start_date = date( "Y-m-d H:i:s", $start_date );
605                         $end_date   = date( "Y-m-d H:i:s", $end_date );                 
606
607                         if( $delay != ALL )
608                                 $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
609                                 
610                         $result = $this->db_link->query( $query );
611                         
612                         if( !PEAR::isError($result) ) {
613                                 $nbfiles        = $result->fetchRow(DB_FETCHMODE_ASSOC);
614                                 $totalfiles = $totalfiles + $nbfiles['stored_files'];
615                         }else{
616                                 die("Unable to get protected files from catalog <br />" . $result->getMessage() );
617                         }
618                         
619                         return $totalfiles;
620                 }
621                 
622                 public function GetStoredBytes( $delay = LAST_DAY )
623                 {
624                         $query = "SELECT SUM(JobBytes) as stored_bytes FROM Job ";
625                         
626                         // Interval calculation
627                         $end_date   = mktime();
628                         $start_date = $end_date - $delay;
629                         
630                         $start_date = date( "Y-m-d H:i:s", $start_date );
631                         $end_date   = date( "Y-m-d H:i:s", $end_date );
632                         
633                         if( $delay != ALL )
634                                 $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
635                         
636                         $result = $this->db_link->query( $query );
637                         
638                         if( PEAR::isError( $result ) ) {
639                                 die( "Unable to get Job Bytes from catalog" );
640                         }else{
641                                 return $result->fetchRow( DB_FETCHMODE_ASSOC );
642                         }
643                 }
644                 
645                 public function GetStoredBytesByInterval( $start_date, $end_date )
646                 {
647                         $query = "SELECT SUM(JobBytes) as stored_bytes, EndTime FROM Job WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
648                         
649                         $result = $this->db_link->query( $query );
650                         
651                         if( PEAR::isError( $result ) ) {
652                                 die( "Unable to get Job Bytes from catalog" );
653                         }else{
654                                 $stored_bytes = 0;
655                                 $tmp = $result->fetchRow( DB_FETCHMODE_ASSOC );
656                                 
657                                 $day = date( "D d", strtotime($end_date) );
658                                 
659                                 if( isset( $tmp['stored_bytes'] ) ) {
660                                         $hbytes = $this->human_file_size( $tmp['stored_bytes'], 3, 'GB');
661                                         $hbytes = explode( " ", $hbytes );
662                                         $stored_bytes = $hbytes[0];
663                                 }
664                                 
665                                 return array( $day, $stored_bytes );
666                         }
667                 }
668                 
669                 public function GetStoredBytesByJob( $jobname, $start_date, $end_date )
670                 {
671                         $query  = "SELECT SUM(JobBytes) as stored_bytes, EndTime FROM Job ";
672                         $query .= "WHERE ( EndTime BETWEEN '$start_date' AND '$end_date' ) AND ";
673                         $query .= "Name = '$jobname'";
674                         
675                         $result = $this->db_link->query( $query );
676                         
677                         if( PEAR::isError( $result ) ) {
678                                 die( "Unable to get Job Bytes from catalog" );
679                         }else{
680                                 $stored_bytes = 0;
681                                 $tmp = $result->fetchRow( DB_FETCHMODE_ASSOC );
682                                 
683                                 $day = date( "D d", strtotime($end_date) );
684                                 
685                                 if( isset( $tmp['stored_bytes'] ) ) {
686                                         $hbytes = $this->human_file_size( $tmp['stored_bytes'], 3, 'GB');
687                                         $hbytes = explode( " ", $hbytes );
688                                         $stored_bytes = $hbytes[0];
689                                 }
690                                 
691                                 return array( $day, $stored_bytes );
692                         }                       
693                 }
694                 
695                 public function GetStoredFilesByJob( $jobname, $start_date, $end_date )
696                 {
697                         $query  = "SELECT SUM(JobFiles) as stored_files, EndTime FROM Job ";
698                         $query .= "WHERE ( EndTime BETWEEN '$start_date' AND '$end_date' ) AND ";
699                         $query .= "Name = '$jobname'";
700                         
701                         $result = $this->db_link->query( $query );
702                         
703                         if( PEAR::isError( $result ) ) {
704                                 die( "Unable to get Job Files from catalog" );
705                         }else{
706                                 $stored_bytes = 0;
707                                 $tmp = $result->fetchRow( DB_FETCHMODE_ASSOC );
708                                 
709                                 $day                    = date( "D d", strtotime($end_date) );
710                                 $stored_files   = $tmp['stored_files'];
711                                 
712                                 return array( $day, $stored_files );
713                         }                       
714                 }
715 } // end class Bweb
716 ?>