X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=gui%2Fbacula-web%2Fbweb.inc.php;h=d57090bedbe6fea1c0f5e2461c143127b4c2bb47;hb=42dd3beecf66880bb879affbcefe369ba108b89c;hp=3d756a246fdc475af7d3d9e4a2a037591a9cb507;hpb=f0824473ef103dc2dfd623d0c8a2877598cd92b8;p=bacula%2Fbacula
diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php
index 3d756a246f..d57090bedb 100644
--- a/gui/bacula-web/bweb.inc.php
+++ b/gui/bacula-web/bweb.inc.php
@@ -14,15 +14,7 @@
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
*/
-require_once "paths.php";
-require_once "DB.php"; // Pear DB
require_once "config.inc.php";
-require_once "bgraph.inc.php";
-require_once($smarty_path."Config_File.class.php");
-
-if (!function_exists('array_fill')) { // For PHP < 4.2.0 users
- require_once('array_fill.func.php');
-}
class Bweb extends DB {
@@ -32,6 +24,7 @@ class Bweb extends DB {
var $dbs;
var $dbs_name;
+ public $tpl;
public $db_link; // Database link
private $db_dsn; // Data Source Name
@@ -45,50 +38,10 @@ class Bweb extends DB {
// Loading configuration
$this->config_file = getcwd() . '/configs/bacula.conf';
+
if( !$this->load_config() )
die( "Unable to load configuration");
- //echo "Number of catalog defined " . count($this->catalogs) . "
";
-
- /*
- $conf = new Config_File (CONFIG_DIR);
- $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");
- */
-
// Construct a valid dsn
$this->db_dsn['hostspec'] = $this->catalogs[0]["host"];
$this->db_dsn['username'] = $this->catalogs[0]["login"];
@@ -106,9 +59,51 @@ class Bweb extends DB {
register_shutdown_function(array(&$this,'close'));
$this->dbs_name = $this->db_dsn['database'];
}
+
+ // Initialize smarty template classe
+ $this->init_tpl();
+ // Initialize smarty gettext function
+ $this->init_gettext();
}
- function load_config()
+ // Initialize Smarty template classe
+ function init_tpl()
+ {
+ $this->tpl = new Smarty();
+
+ $this->tpl->compile_check = true;
+ $this->tpl->debugging = false;
+ $this->tpl->force_compile = true;
+
+ $this->tpl->template_dir = "./templates";
+ $this->tpl->compile_dir = "./templates_c";
+ $this->tpl->config_dir = "./configs";
+ }
+
+ function init_gettext()
+ {
+ global $smarty_gettext_path;
+
+ if ( function_exists("gettext") ) {
+ require_once( BW_SMARTY_GETTEXT . "smarty_gettext.php" );
+ $this->tpl->register_block('t','smarty_translate');
+
+ $language = $this->get_config_param("lang");
+ $domain = "messages";
+ putenv("LANG=$language");
+ setlocale(LC_ALL, $language);
+ bindtextdomain($domain,"./locale");
+ textdomain($domain);
+ }
+ else {
+ function smarty_translate($params, $text, &$smarty) {
+ return $text;
+ }
+ $smarty->register_block('t','smarty_translate');
+ }
+ }
+
+ function load_config()
{
$this->config = parse_ini_file( $this->config_file, true );
@@ -241,34 +236,6 @@ class Bweb extends DB {
die( "Unable to get database size
" . $jobs->getMessage() );
return $this->human_file_size( $database_size );
-
- /*
- if ( $this->driver == "mysql") {
- $dbsize = $this->db_link->query("show table status") or die ("classes.inc: Error query: 3");
-
- if ( $dbsize->numRows() ) {
- while ( $res = $dbsize->fetchRow(DB_FETCHMODE_ASSOC) )
- $database_size += $res["Data_length"];
- } else {
- return 0;
- } // end if else
- } // end if
- else if ( $this->driver == "pgsql") {
- $dbsize = $this->db_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];
- } else {
- return 0;
- }
- } // end if
-
- $dbsize->free();
- */
} // end function GetDbSize()
public function Get_Nb_Clients()
@@ -300,11 +267,6 @@ class Bweb extends DB {
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";
@@ -313,11 +275,6 @@ class Bweb extends DB {
$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
@@ -326,7 +283,6 @@ class Bweb extends DB {
break;
} // end switch
- //$this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
$medias = $this->db_link->query( $query );
if( PEAR::isError( $medias ) ) {
@@ -376,6 +332,29 @@ class Bweb extends DB {
return $volumes;
} // end function GetVolumeList()
+ public function CountJobsbyLevel( $delay = LAST_DAY, $level = 'F' )
+ {
+ $end_date = mktime();
+ $start_date = $end_date - $delay;
+
+ $start_date = date( "Y-m-d H:i:s", $start_date );
+ $end_date = date( "Y-m-d H:i:s", $end_date );
+
+ $query = "SELECT COUNT(JobId) as jobs FROM Job ";
+ $query .= "WHERE (EndTime BETWEEN '$start_date' AND '$end_date') AND ";
+ $query .= "Level = '$level' ";
+
+ $result = $this->db_link->query( $query );
+
+ if (PEAR::isError( $result ) ) {
+ die( "Unable to get number of jobs with $level status from catalog
" . $result->getMessage() );
+ }else {
+ $jobs = $result->fetchRow( DB_FETCHMODE_ASSOC );
+ return $jobs['jobs'];
+ }
+
+ }
+
public function CountJobs( $delay = LAST_DAY, $status = 'any' )
{
$query = "SELECT COUNT(JobId) AS job_nb FROM Job ";
@@ -612,19 +591,32 @@ class Bweb extends DB {
}
}
- public function GetStoredFiles()
+ public function GetStoredFiles( $delay = LAST_DAY )
{
- $nbfiles = 0;
- $query = "SELECT COUNT(FilenameId) AS nbfiles FROM Filename";
+ $totalfiles = 0;
+
+ $query = "SELECT SUM(JobFiles) AS stored_files FROM Job ";
+
+ // Interval calculation
+ $end_date = mktime();
+ $start_date = $end_date - $delay;
+
+ $start_date = date( "Y-m-d H:i:s", $start_date );
+ $end_date = date( "Y-m-d H:i:s", $end_date );
+
+ if( $delay != ALL )
+ $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
+
$result = $this->db_link->query( $query );
if( !PEAR::isError($result) ) {
- $nbfiles = $result->fetchRow(DB_FETCHMODE_ASSOC);
- $nbfiles = $nbfiles['nbfiles'];
+ $nbfiles = $result->fetchRow(DB_FETCHMODE_ASSOC);
+ $totalfiles = $totalfiles + $nbfiles['stored_files'];
}else{
- die("Unable to get protected files from catalog");
+ die("Unable to get protected files from catalog
" . $result->getMessage() );
}
- return $nbfiles;
+
+ return $totalfiles;
}
public function GetStoredBytes( $delay = LAST_DAY )
@@ -638,9 +630,8 @@ class Bweb extends DB {
$start_date = date( "Y-m-d H:i:s", $start_date );
$end_date = date( "Y-m-d H:i:s", $end_date );
- if( $delay != ALL ) {
+ if( $delay != ALL )
$query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
- }
$result = $this->db_link->query( $query );
@@ -721,6 +712,5 @@ class Bweb extends DB {
return array( $day, $stored_files );
}
}
-
} // end class Bweb
?>