From: Davide Franco Date: Thu, 28 Oct 2010 20:48:43 +0000 (+0200) Subject: bacula-web: Improved volumes list X-Git-Tag: Release-5.2.1~986 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4ac7e021808e335aa9a517d98a8d4fc8fd2125a9;p=bacula%2Fbacula bacula-web: Improved volumes list - New GetVolumeList function in classes.inc - Improved smarty code in volumes.tpl, more lisible now - Removed useless php code in index.php --- diff --git a/gui/bacula-web/classes.inc b/gui/bacula-web/classes.inc index df5adb8020..1f40b393d9 100644 --- a/gui/bacula-web/classes.inc +++ b/gui/bacula-web/classes.inc @@ -118,8 +118,6 @@ class Bweb extends DB { }//end function - - function GetDataVolumes() { $volume = array(); @@ -196,6 +194,94 @@ class Bweb extends DB { return $this->human_file_size( $database_size ); } // end function GetDbSize() + + // Return an array of volumes ordered by poolid and volume name + function GetVolumeList() { + + $volumes = array(); + $query = ""; + $debug = false; + + // Get the list of pools id + $query = "SELECT Pool.poolid, Pool.name FROM Pool ORDER BY Pool.poolid"; + + $this->link->setFetchMode(DB_FETCHMODE_ASSOC); + $pools = $this->link->query( $query ); + + if( PEAR::isError( $pools ) ) + die("Error: Failed to get pool list
SQL Query: $query
" . $pools->getMessage() ); + + while( $pool = $pools->fetchRow() ) { + switch( $this->driver ) + { + case 'mysql': +/* + $query = "SELECT Media.VolumeName, Media.VolBytes, Media.VolStatus, Pool.Name, Media.MediaType,Media.LastWritten, FROM_UNIXTIME(UNIX_TIMESTAMP(Media.LastWritten)+Media.VolRetention ) AS expire + FROM Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId WHERE poolid='$pool[0]' + ORDER BY Media.VolumeName"; +*/ + $query = "SELECT Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention + FROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid + WHERE Media.poolid = '". $pool['poolid'] . "' ORDER BY Media.volumename"; + break; + case 'pgsql': + $query = "SELECT media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention + FROM media LEFT JOIN pool ON media.poolid = pool.poolid + WHERE media.poolid = '". $pool['poolid'] . "' ORDER BY media.volumename"; + /* + $query = "SELECT Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten, Media.LastWritten + Media.VolRetention * interval '1 second' AS expire + FROM Pool LEFT JOIN Media ON media.poolid=pool.poolid WHERE poolid='$pool[0]' + ORDER BY Media.VolumeName"; + */ + break; + case 'sqlite': + $query = ""; // not yet implemented + break; + default: + break; + } // end switch + + $this->link->setFetchMode(DB_FETCHMODE_ASSOC); + $medias = $this->link->query( $query ); + + if( PEAR::isError( $medias ) ) { + die( "Failed to get media list for pool $volume[0]
" . $medias->getMessage() ); + }else { + if( $debug ) echo "Found " . $medias->numRows() . " medias for pool " . $pool['name'] . "
"; + + // Create array key for each pool + if( !array_key_exists( $pool['name'], $volumes) ) + { + $volumes[ $pool['name'] ] = array(); + } + while( $media = $medias->fetchRow() ) { + if( $debug ) { + var_dump( $media ); + } + + if( $medias->numRows() == 0 ) { + if( $debug ) echo "No media in pool " . $pool['name'] . "
"; + } else { + if( $media['lastwritten'] != "0000-00-00 00:00:00" ) { + // Calculate expiration date + $expire_date = strtotime($media['lastwritten']) + $media['volretention']; + $media['expire'] = strftime("%Y-%M-%D", $expire_date); + + // Media used size in a more readable format + $media['volbytes'] = $this->human_file_size( $media['volbytes'] ); + } else { + $media['lastwritten'] = "N/A"; + $media['expire'] = "N/A"; + $media['volbytes'] = "0 KB"; + } + // Add the media in pool array + array_push( $volumes[ $pool['name']], $media); + } + } // end while + } // end if else + } // end while + return $volumes; + } // end function GetVolumeList() } // end class Bweb diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index 80a506603e..789675db32 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -88,8 +88,6 @@ $client->free(); $totalfiles->free(); $last24bytes->free(); - - // report_select.tpl & last_run_report.tpl $res = $dbSql->link->query("select Name from Job group by Name"); $a_jobs = array(); @@ -99,11 +97,8 @@ $smarty->assign('total_name_jobs',$a_jobs); $smarty->assign('time2',( (time())-2678400) ); // Current time - 1 month.