]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bacula-web/classes.inc
bacula-web: Removed title variable from config file
[bacula/bacula] / gui / bacula-web / classes.inc
index 14a0b2104f521038d752872eed0a0ffefec90c30..ec57f26f7192cbff7e444dd2099f892bbcddd64a 100644 (file)
@@ -34,21 +34,46 @@ class Bweb extends DB {
         var $StartDate;
         var $EndDate;
         var $driver;
+       var $dbs;
+       var $dbs_name;
 
 
 
         function Bweb() {
                 
                 $conf = new Config_File (CONFIG_DIR);
-                
-                
-                $this->dsn[hostspec] = $conf->get(CONFIG_FILE,"DATABASE","host");
-                $this->dsn[username] = $conf->get(CONFIG_FILE,"DATABASE","login");
-                $this->dsn[password] = $conf->get(CONFIG_FILE,"DATABASE","pass");
-                $this->dsn[database] = $conf->get(CONFIG_FILE,"DATABASE","db_name");
-                $this->dsn[phptype] = $conf->get(CONFIG_FILE,"DATABASE","db_type");   // mysql, (sqlite, pgsql) -->> Yet not checked
-                if (  $conf->get(CONFIG_FILE,"DATABASE","db_port") )
-                        $this->dsn[port] = $conf->get(CONFIG_FILE,"DATABASE","db_port");
+               $this->dbs = array();
+               $i = 2;
+               $sections = $conf->get(CONFIG_FILE,"DATABASE","host");
+               array_push($this->dbs, "DATABASE");
+               while ( !empty($sections) ) {                
+                       $sections = $conf->get(CONFIG_FILE,"DATABASE".$i,"host");
+                       if ( !empty($sections) )
+                               array_push($this->dbs,"DATABASE".$i);
+                       $i++;
+               }
+
+               if ( $i < 4)
+                       $sec = "DATABASE";
+               else {
+                       if ( !empty($_POST['sel_database']) ) {
+                               $_SESSION['DATABASE'] = $_POST['sel_database'];
+                               $sec = $_POST['sel_database'];
+                       } else {
+                               if (isset($_SESSION['DATABASE']) )
+                                       $sec = $_SESSION['DATABASE'];
+                               else
+                                       $sec = "DATABASE";
+                       }
+               }
+
+                $this->dsn['hostspec'] = $conf->get(CONFIG_FILE,$sec,"host");
+                $this->dsn['username'] = $conf->get(CONFIG_FILE,$sec,"login");
+                $this->dsn['password'] = $conf->get(CONFIG_FILE,$sec,"pass");
+                $this->dsn['database'] = $conf->get(CONFIG_FILE,$sec,"db_name");
+                $this->dsn['phptype'] = $conf->get(CONFIG_FILE,$sec,"db_type");   // mysql, pgsql
+                if (  $conf->get(CONFIG_FILE,$sec,"db_port") )
+                        $this->dsn[port] = $conf->get(CONFIG_FILE,$sec,"db_port");
                         
                 $this->link =& $this->connect($this->dsn);
                 
@@ -56,14 +81,13 @@ class Bweb extends DB {
                     die($this->link->getMessage());
                 $this->driver = $this->dsn[phptype];                            
                 register_shutdown_function(array(&$this,'close'));
-         }
-
-
+               $this->dbs_name = $this->dsn['database'];
+       }
                 
         function close() {
 
                 $this->link->disconnect();
-         }      
+        }      
 
         
          
@@ -73,7 +97,7 @@ class Bweb extends DB {
                         or die("classes.inc: Error query: 1");
                 $return =& $result->fetchRow(); 
                 return $return[0];
-         }//end function
+        }//end function
 
         
          
@@ -83,7 +107,7 @@ class Bweb extends DB {
                         or die("classes.inc: Error query: 2");
                 $return =& $result->fetchRow();
                 return $return[0];
-         }//end function 
+        }//end function 
 
                  
 
@@ -104,7 +128,7 @@ class Bweb extends DB {
                         if ($this->driver == "mysql" )
                                 $result = $this->link->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 Name='$tmp[0]' order by Media.VolumeName");
                         else if ($this->driver == "pgsql")
-                                $result = $this->link->query("select Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten,FROM_UNIXTIME(Media.LastWritten::Timestamp without time zone + Media.VolRetention) as expire from Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId where Name='$tmp[0]' order by Media.VolumeName");                                                          
+                               $result = $this->link->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 Name='$tmp[0]' order by Media.VolumeName");
                         while ( $tmp1 = $result->fetchRow() ) {
                                 $pos = array_key_exists($tmp[0],$volume);
                                 if ($pos != FALSE)
@@ -124,15 +148,17 @@ class Bweb extends DB {
                         $dbsize = $this->link->query("show table status")
                                 or die ("classes.inc: Error query: 3");
                         if ( $dbsize->numRows() ) {
-                                while ( $res = $dbsize->fetchRow() )
-                                        $database_size += $res[5];
+                                while ( $res = $dbsize->fetchRow(DB_FETCHMODE_ASSOC) )
+                                        $database_size += $res["Data_length"];
                         }
                         else
                                 return 0;
                 }
                 else if ( $this->driver == "pgsql") {
-                        $dbsize = $this->link->query("select database_size('bacula')")
+                        $dbsize = $this->link->query("select pg_database_size('$this->dbs_name')")
                                 or die ("classes.inc: Error query: 4");
+                       if (PEAR::isError($dbsize))
+                           die($dbsize->getMessage());
                         if ( $dbsize->numRows() ) {
                                 while ( $res = $dbsize->fetchRow() )
                                         $database_size += $res[0];
@@ -199,7 +225,7 @@ class BGraph {
                         $graph->SetXDataLabelAngle(90);
                 else
                         $graph->SetXDataLabelAngle(0);
-//              $graph->SetNumXTicks(10);
+               $graph->SetNumXTicks(1);
 //              $graph->SetXDataLabelPos('none');
 //              $graph->SetXTickLabelPos('plotdown');
                 
@@ -351,18 +377,24 @@ class BCreateGraph extends BGraph {
                                         $result->free();
                                         break;
                                 case BACULA_TYPE_BYTES_ENDTIME_ALLJOBS:  // Special: Generic graph from all clientes.
-                                        $i = -1;                         // Counter of number of jobs of one cliente. SP: Contador del nmero de jobs totales de un cliente.
+                                        $i = -1;                         // Counter of number of jobs of one client. SP: Contador del nmero de jobs totales de un cliente.
                                         $i2 = 0;                         // Counter of number of keys of array. SP: Contador del nmero de valores del array.
                                         
+                                        if ($DB_bacula->driver == "mysql") {
                                         $res = $DB_bacula->link->query("select Name from Job where UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-$this->elapsed  group by Name order by Name desc")
                                                 or die ("classes.inc: Error at query: 7");
-                                        if ($DB_bacula->driver == "mysql")
                                                 $resdata = $DB_bacula->link->query("select date_format(EndTime,\"%Y-%m-%d\") from Job where UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-$this->elapsed  group by date_format(EndTime, \"%Y-%m-%d\") order by EndTime")
                                                         or die ("classes.inc: Error at query: 8");
-                                        else if ($DB_bacula->driver == "pgsql")
-                                                $resdata = $DB_bacula->link->query("select date_format(EndTime,'%Y-%m-%d') from Job where UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-$this->elapsed  group by EndTime order by EndTime")                                                   
+                                       }
+                                        else if ($DB_bacula->driver == "pgsql") {
+                                               $res = $DB_bacula->link->query("select Name from Job where EndTime > now() - 1*interval'$this->elapsed s'  group by Name order by Name desc")
+                                                       or die ("classes.inc: Error at query: 8");
+                                                $resdata = $DB_bacula->link->query("select to_char(EndTime,'YY-MM-DD') from Job where EndTime > NOW() - 1*interval'$this->elapsed s'  group by EndTime order by EndTime")
                                                         or die ("classes.inc: Error at query: 9");
+                                       }
                                         
+                                       if (PEAR::isError($resdata))
+                                               die("classes.inc: Error at query: 9.1<br>".$resdata->getMessage());
                                         while ( $tmpdata = $res->fetchRow() )
                                                 array_push($this->clientes,$tmpdata[0]);
                                                 
@@ -379,13 +411,15 @@ class BCreateGraph extends BGraph {
                                                 $count++;
                                                 array_push($spr,$tmpdata[0]);
                                                 if ($DB_bacula->driver == "mysql")
-                                                        $result = $DB_bacula->link->query("select date_format(EndTime,\"%Y-%m-%d\"),SUM(JobBytes),Name,count(Name) as Nname from Job WHERE EndTime like '$tmpdata[0]%' group by Name order by Name desc")
+                                                        $result = $DB_bacula->link->query("select date_format(EndTime,\"%Y-%m-%d\"),SUM(JobBytes) as sum,Name as name,count(Name) as Nname from Job WHERE EndTime like '$tmpdata[0]%' group by Name order by Name desc")
                                                                 or die ("classes.inc: Error at query: 10");
-                                                else if ($DB_bacula->driver == "pgsql")
-                                                        $result = $DB_bacula->link->query("select date_format(EndTime,'%Y-%m-%d'),SUM(JobBytes),Name,count(Name) as Nname from Job WHERE EndTime like '$tmpdata[0]%' group by EndTime,Name order by Name desc")
+                                                else if ($DB_bacula->driver == "pgsql") {
+                                                       $query = "select to_char(EndTime,'YY-MM-DD'),SUM(JobBytes) as sum,Name,count(Name) as Nname from Job WHERE EndTime like '%$tmpdata[0]%' group by EndTime,Name order by Name desc";
+                                                        $result = $DB_bacula->link->query($query)
                                                                 or die ("classes.inc: Error at query: 11");
+                                               }
                                                 while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) ) {
-                                                        $spr2 = array_merge($spr2,array($row["Name"]=>$row["SUM(JobBytes)"]));
+                                                        $spr2 = array_merge($spr2,array($row["name"]=>$row["sum"]));
                                                         $i = $result->numRows();
                                                 }
 
@@ -395,7 +429,7 @@ class BCreateGraph extends BGraph {
 //                                              echo "</pre>";
                                                 
                                                 reset ($this->clientes);        
-                                                                                               do { 
+                                               do {
                                                         if ( $spr2[current($this->clientes)] != NULL)
                                                                 array_push($spr,$spr2[current($this->clientes)]);
                                                         else
@@ -411,7 +445,7 @@ class BCreateGraph extends BGraph {
                                                 $spr = array();
                                                 $spr2 = array();
                                         }
-                                
+
                                         for ( $i = 0; $i < count($whole_result); $i++ ) {  // To equal the arrays so that the graph is not unsquared. SP:Igualamos las matrices para que la gr�ica no se descuadre
                                                 $tmp = count($whole_result[$i]);
                                                 if ( $i2 < $tmp )                // Estupidez?. Check this code later...
@@ -437,7 +471,7 @@ class BCreateGraph extends BGraph {
 
 
 
-        //Conversi� de la fecha a Mysql-format para Smarty.           THE SAME FUNCTION AT 2 CLASSES. THIS WAY IS BUGGY. TO SOLVE LATER.
+        //Convert date from mysql to smarty.           THE SAME FUNCTION AT 2 CLASSES. THIS WAY IS BUGGY. TO SOLVE LATER.
         function PrepareDate($StartDateMonth,$StartDateDay,$StartDateYear,$EndDateMonth,$EndDateDay,$EndDateYear){
         
                 $this->StartDate = $StartDateYear."-".$StartDateMonth."-".$StartDateDay." 00:00:00";