]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved volumes list
authorDavide Franco <bacula-dev@dflc.ch>
Thu, 28 Oct 2010 20:48:43 +0000 (22:48 +0200)
committerEric Bollengier <eric@eb.homelinux.org>
Tue, 2 Nov 2010 07:20:32 +0000 (08:20 +0100)
  - New GetVolumeList function in classes.inc
  - Improved smarty code in volumes.tpl, more lisible now
  - Removed useless php code in index.php

gui/bacula-web/classes.inc
gui/bacula-web/index.php
gui/bacula-web/templates/volumes.tpl

index df5adb8020f184c7bf94986bfc6f49a8c64002cf..1f40b393d932ebcc480bb1ce6c2686abd39e6374 100644 (file)
@@ -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 <br />SQL Query: $query<br />" . $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] <br /> " . $medias->getMessage() );
+                                       }else {
+                                               if( $debug ) echo "Found " . $medias->numRows() . " medias for pool " . $pool['name'] . " <br />";
+                                       
+                                               // 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'] . "<br />";
+                                                       } 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
 
index 80a506603e16b6442c33d9ec9597716acbe38d02..789675db32f2c199329ae8cf4db7d9a8b2adbca9 100644 (file)
@@ -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. <select> date
 $res->free();
 
-// volumes.tpl
-$volumes = $dbSql->GetDataVolumes();                                                                                    // Obtain array with info
-$pools = array_keys($volumes);                                                                                                  // Extract Pools
-$smarty->assign('pools',$pools);        
-$smarty->assign('volumes',$volumes);
+// Get volumes list (volumes.tpl)
+$smarty->assign('pools',$dbSql->GetVolumeList() );
 
 // last_run_report.tpl
 if ($mode == "Lite" && $_GET['Full_popup'] != "yes") {
index 7bbc12adf1259dba41a47a7153820f6ee78b8a63..5779845c40b77e1825b33c7983de9cc89aeb3209 100644 (file)
@@ -9,68 +9,37 @@
         <td class=tbl_header2 background="images/end4.png"><img src="images/empty.png"></td>
 </tr>
 -->
-<table>
-       {foreach from=$pools item=current}
+<table border=0 width=100% class=code cellspacing=0 cellpadding=0>
+       {foreach from=$pools item=pool key=pool_name}
+       <tr>
+               <th colspan="6" style="font-size: 10pt; text-align: center; background-color: #E0C8E5; color: black; padding: 3px;">
+                       {$pool_name}
+               </th>
+       </tr>
+       <tr style="text-align: center;">
+               <td style="background-image: url(images/bg5.png);" class=tbl_pool_inter_1>Name</td>
+               <td style="background-image: url(images/bg5.png);" class=tbl_pool_inter_1>{t}Bytes{/t}</td>
+               <td style="background-image: url(images/bg5.png);" class=tbl_pool_inter_1>{t}Media Type{/t}</td>
+               <td style="background-image: url(images/bg5.png);" class=tbl_pool_inter_1>{t}Expire{/t}</td>
+               <td style="background-image: url(images/bg5.png);" class=tbl_pool_inter_1>{t}Last written{/t}</td>
+               <td style="background-image: url(images/bg5.png);" class=tbl_pool_inter_1>{t}Status{/t}</td>
+       </tr>
+       {foreach from=$pool item=volume}
+               <tr style="text-align: center;">
+                       <td style="text-align: left;">{$volume.volumename}</td>
+                       <td>{$volume.volbytes}</td>
+                       <td>{$volume.mediatype}</td>
+                       <td>{$volume.expire}</td>
+                       <td>{$volume.lastwritten}</td>
+                       <td>{$volume.volstatus}</td>
+               {foreachelse}
                <tr>
-                       <td colspan=6>&nbsp;</td></tr>
-        <tr>
-                       <td colspan="6" class="pool_name">
-                {$current}
-            </td>
-        </tr>
-        {foreach from=$volumes item=current2}
-                {assign var=key value=$current2}
-                {foreach from=$key item=current3 name=loop}
-                {if $current3.3 == $current && $current3.0 != ""}
-                        {if $smarty.foreach.loop.first == TRUE}
-                                <tr>
-                                        <td class="tbl_vol_header">Volume Name</td>
-                                        <td class="tbl_vol_header">Volume Bytes</td>
-                                        <td class="tbl_vol_header">Media Type</td>
-                                        <td class="tbl_vol_header">Expire on</td>
-                                        <td class="tbl_vol_header">Last Written</td>                                      
-                                        <td class="tbl_vol_header">Volume Status</td>
-                                </tr>
-                        {/if}
-                                <tr align=center bgcolor={cycle values="#D9E3FC,#CBE7F5"}>
-                                        <td>{$current3.0}</td>
-                                        <td>{$current3.1}</td>
-                                        <td>{$current3.4}</td>
-                                        <td {popup text='$current3.6}>
-                                                                                       {if $current3.6|date_format:"%Y" <= "1979"}
-                                                                                         --
-                                                                                       {else}
-                                                                                         {$current3.6|date_format:"%Y/%m/%d"}
-                                                                                       {/if}
-                                                                               </td>
-                                        <td {popup text='$current3.5}>
-                                                                                       {if $current3.5 == "0000-00-00 00:00:00"}
-                                                                                         --
-                                                                                       {else}
-                                                                                         {$current3.5|date_format:"%Y/%m/%d"}
-                                                                                       {/if}
-                                                                               </td>
-                                        <td>
-                                                <font color=
-                                                {if $current3.2 == "Error"}
-                                                        red>
-                                                {elseif $current3.2 == "Purged"}
-                                                        blue>
-                                                {elseif $current3.2 == "Append"}
-                                                        green>
-                                                {elseif $current3.2 == "Recycle"}
-                                                        orange>
-                                                {else}
-                                                        "">
-                                                {/if}
-                                                {$current3.2}
-                                                </font>
-                                        </td>
-                                </tr>
-                        {/if}
-                {/foreach}
-        {/foreach}
-{/foreach}
+                       <td colspan="6" style="text-align: center; font-weight: bold; font-size: 8pt; padding: 1em;">
+                               No volume in this pool
+                       </td>
+               {/foreach}
+               </tr>
+       {/foreach}
 </table>
 
 </div> <!-- end div box -->