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