From 98544236bf0ebd46e367012922febf49feeb77de Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Thu, 17 Mar 2011 19:08:35 +0100 Subject: [PATCH] bacula-web: Several improvments with php code - Integrated php gettext init in bweb classe - Removed useless declaration in index.php - Smarty classe declaration now in bweb classe - Adapted php code in index.php for new smarty classe instance name --- gui/bacula-web/bweb.inc.php | 47 ++++++++++++++++++++++++- gui/bacula-web/index.php | 70 ++++++++++++------------------------- 2 files changed, 69 insertions(+), 48 deletions(-) diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php index 12590ca67f..bd7a04e3a0 100644 --- a/gui/bacula-web/bweb.inc.php +++ b/gui/bacula-web/bweb.inc.php @@ -15,6 +15,8 @@ +-------------------------------------------------------------------------+ */ require_once "paths.php"; +require_once($smarty_path."Smarty.class.php"); + require_once "DB.php"; // Pear DB require_once "config.inc.php"; require_once "bgraph.inc.php"; @@ -27,6 +29,7 @@ class Bweb extends DB { var $dbs; var $dbs_name; + public $tpl; public $db_link; // Database link private $db_dsn; // Data Source Name @@ -61,9 +64,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( $smarty_gettext_path."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 ); diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index 39543614fe..57f26244ee 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -15,50 +15,26 @@ +-------------------------------------------------------------------------+ */ session_start(); -require ("paths.php"); -require($smarty_path."Smarty.class.php"); -include "bweb.inc.php"; +require_once('paths.php'); +include_once( 'bweb.inc.php' ); -$smarty = new Smarty(); $dbSql = new Bweb(); -require("lang.php"); +//require("lang.php"); $mode = ""; -$smarty->compile_check = true; -$smarty->debugging = false; -$smarty->force_compile = true; - -$smarty->template_dir = "./templates"; -$smarty->compile_dir = "./templates_c"; -$smarty->config_dir = "./configs"; - /* -$smarty->config_load("bacula.conf"); // Load config file -$mode = $smarty->get_config_vars("mode"); -*/ // Lite o Extend? - // Getting mode from config file $mode = $dbSql->get_config_param("mode"); if( $mode == false ) $mode = "Lite"; $smarty->assign( "mode", $mode ); - -/* -// Determine which template to show -$indexreport = $dbSql->get_config_param( "IndexReport" ); - -if( $indexreport == 0 ) { - $smarty->assign( "last_report", "last_run_report.tpl" ); -}else { - $smarty->assign( "last_report", "report_select.tpl" ); -} */ // Assign to template catalogs number -$smarty->assign( "dbs", $dbSql->Get_Nb_Catalogs() ); +$dbSql->tpl->assign( "dbs", $dbSql->Get_Nb_Catalogs() ); //Assign dbs /* @@ -70,50 +46,50 @@ if ( count($dbSql->dbs) >1 ) { // Stored files number $totalfiles = $dbSql->GetStoredFiles( ALL ); -$smarty->assign('stored_files',$totalfiles); +$dbSql->tpl->assign('stored_files',$totalfiles); // Database size -$smarty->assign('database_size', $dbSql->GetDbSize()); +$dbSql->tpl->assign('database_size', $dbSql->GetDbSize()); // Overall stored bytes $result = $dbSql->GetStoredBytes( ALL ); -$smarty->assign('stored_bytes', $dbSql->human_file_size($result['stored_bytes']) ); +$dbSql->tpl->assign('stored_bytes', $dbSql->human_file_size($result['stored_bytes']) ); // Total stored bytes since last 24 hours $result = $dbSql->GetStoredBytes( LAST_DAY ); -$smarty->assign('bytes_last', $dbSql->human_file_size($result['stored_bytes']) ); +$dbSql->tpl->assign('bytes_last', $dbSql->human_file_size($result['stored_bytes']) ); // Total stored files since last 24 hours $files_last = $dbSql->GetStoredFiles( LAST_DAY ); -$smarty->assign('files_last', $files_last ); +$dbSql->tpl->assign('files_last', $files_last ); // Number of clients $nb_clients = $dbSql->Get_Nb_Clients(); -$smarty->assign('clientes_totales',$nb_clients["nb_client"] ); +$dbSql->tpl->assign('clientes_totales',$nb_clients["nb_client"] ); // Backup Job list for report.tpl and last_run_report.tpl -$smarty->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() ); +$dbSql->tpl->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() ); // Get volumes list (volumes.tpl) -$smarty->assign('pools', $dbSql->GetVolumeList() ); +$dbSql->tpl->assign('pools', $dbSql->GetVolumeList() ); // Last 24 hours completed jobs number -$smarty->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) ); +$dbSql->tpl->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) ); // Last 24 hours failed jobs number -$smarty->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) ); +$dbSql->tpl->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) ); // Last 24 hours waiting jobs number -$smarty->assign( 'waiting_jobs', $dbSql->CountJobs( LAST_DAY, 'waiting' ) ); +$dbSql->tpl->assign( 'waiting_jobs', $dbSql->CountJobs( LAST_DAY, 'waiting' ) ); // Last 24 hours elapsed time (last_run_report.tpl) //$smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() ); // Last 24 hours Job Levels -$smarty->assign( 'incr_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'I') ); -$smarty->assign( 'diff_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'D') ); -$smarty->assign( 'full_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'F') ); +$dbSql->tpl->assign( 'incr_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'I') ); +$dbSql->tpl->assign( 'diff_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'D') ); +$dbSql->tpl->assign( 'full_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'F') ); // Last 24 hours Job status graph $data = array(); @@ -128,7 +104,7 @@ $graph->SetData( $data, 'pie', 'text-data-single' ); $graph->SetGraphSize( 400, 230 ); $graph->Render(); -$smarty->assign('graph_jobs', $graph->Get_Image_file() ); +$dbSql->tpl->assign('graph_jobs', $graph->Get_Image_file() ); unset($graph); // Pool and volumes graph @@ -145,7 +121,7 @@ $graph->SetData( $data, 'pie', 'text-data-single' ); $graph->SetGraphSize( 400, 230 ); $graph->Render(); -$smarty->assign('graph_pools', $graph->Get_Image_file() ); +$dbSql->tpl->assign('graph_pools', $graph->Get_Image_file() ); // Last 7 days stored Bytes graph $data = array(); @@ -168,7 +144,7 @@ $graph->SetData( $days_stored_bytes, 'bars', 'text-data' ); $graph->SetGraphSize( 400, 230 ); $graph->Render(); -$smarty->assign('graph_stored_bytes', $graph->Get_Image_file() ); +$dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() ); // Last 15 used volumes $vol_list = array(); @@ -187,12 +163,12 @@ else { while ( $vol = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) array_push( $vol_list, $vol ); } -$smarty->assign( 'volume_list', $vol_list ); +$dbSql->tpl->assign( 'volume_list', $vol_list ); //if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes") // $smarty->display('full_popup.tpl'); //else // Render template -$smarty->display('index.tpl'); +$dbSql->tpl->display('index.tpl'); ?> -- 2.39.5