public static function connect($dsn, $user = null, $password = null, $options = array()) { try { if (is_null(self::$connection)) { self::$connection = new PDO($dsn, $user, $password); } } catch (PDOException $e) { CErrorHandler::displayError($e); } return self::$connection; }
$job['compression'] = 'N/A'; } // Job speed $start = $job['starttime']; $end = $job['endtime']; $seconds = DateTimeUtil::get_ElaspedSeconds($end, $start); if ($seconds !== false && $seconds > 0) { $speed = $job['jobbytes'] / $seconds; $job['speed'] = CUtils::Get_Human_Size($speed, 2) . '/s'; } else { $job['speed'] = 'N/A'; } // Job bytes more easy to read $job['jobbytes'] = CUtils::Get_Human_Size($job['jobbytes']); $job['jobfiles'] = CUtils::format_Number($job['jobfiles']); $jobs[] = $job; } // end while } catch (Exception $e) { CErrorHandler::displayError($e); } $view->assign('jobs', $jobs); $view->assign('backupjob_name', $backupjob_name); $view->assign('backupjob_period', $backupjob_period); $view->assign('backupjob_bytes', $backupjob_bytes); $view->assign('backupjob_files', $backupjob_files); // Set page name $current_page = 'Backup job report'; $view->assign('page_name', $current_page); // Process and display the template $view->display('backupjob-report.tpl');
public function __construct(&$view) { // Loading configuration file parameters try { if (!FileConfig::open(CONFIG_FILE)) { throw new Exception("The configuration file is missing"); } else { $this->catalog_nb = FileConfig::count_Catalogs(); } } catch (Exception $e) { CErrorHandler::displayError($e); } // Template engine initalization $this->view = $view; // Checking template cache permissions if (!is_writable(VIEW_CACHE_DIR)) { throw new Exception("The template cache folder <b>" . VIEW_CACHE_DIR . "</b> must be writable by Apache user"); } // Initialize smarty gettext function $language = FileConfig::get_Value('language'); if (!$language) { throw new Exception("Language translation problem"); } $this->translate = new CTranslation($language); $this->translate->set_Language($this->view); // Get catalog_id from http $_GET request if (!is_null(CHttpRequest::get_Value('catalog_id'))) { if (FileConfig::catalogExist(CHttpRequest::get_Value('catalog_id'))) { $this->catalog_current_id = CHttpRequest::get_Value('catalog_id'); $_SESSION['catalog_id'] = $this->catalog_current_id; } else { $_SESSION['catalog_id'] = 0; $this->catalog_current_id = 0; throw new Exception('The catalog_id value provided does not correspond to a valid catalog, please verify the config.php file'); } } else { if (isset($_SESSION['catalog_id'])) { // Stick with previously selected catalog_id $this->catalog_current_id = $_SESSION['catalog_id']; } } // Define catalog id and catalog label $this->view->assign('catalog_current_id', $this->catalog_current_id); $this->view->assign('catalog_label', FileConfig::get_Value('label', $this->catalog_current_id)); // Getting database connection paremeter from configuration file $dsn = FileConfig::get_DataSourceName($this->catalog_current_id); $driver = FileConfig::get_Value('db_type', $this->catalog_current_id); $user = ''; $pwd = ''; if ($driver != 'sqlite') { $user = FileConfig::get_Value('login', $this->catalog_current_id); $pwd = FileConfig::get_Value('password', $this->catalog_current_id); } switch ($driver) { case 'mysql': case 'pgsql': $this->db_link = CDB::connect($dsn, $user, $pwd); break; case 'sqlite': $this->db_link = CDB::connect($dsn); break; } // Getting driver name from PDO connection $this->db_driver = CDB::getDriverName(); // Set PDO connection options $this->db_link->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $this->db_link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->db_link->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('CDBResult', array($this))); // MySQL connection specific parameter if ($driver == 'mysql') { $this->db_link->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); } // Bacula catalog selection if ($this->catalog_nb > 1) { // Catalogs list $this->view->assign('catalogs', FileConfig::get_Catalogs()); // Catalogs count $this->view->assign('catalog_nb', $this->catalog_nb); } }