From 276d6b30d1743c0b6cd742e2048d0db4627b2d82 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Sun, 15 Dec 2013 11:47:23 +0100 Subject: [PATCH] first few implementations of new Setting-class, refs #1325 Signed-off-by: Michael Kaufmann (d00p) --- admin_admins.php | 31 +-- admin_configfiles.php | 26 +-- admin_cronjobs.php | 2 +- admin_customers.php | 109 +++++----- admin_domains.php | 64 +++--- admin_index.php | 22 +- admin_ipsandports.php | 14 +- admin_logger.php | 4 +- admin_phpsettings.php | 10 +- admin_settings.php | 6 +- admin_templates.php | 8 +- admin_tickets.php | 36 ++- admin_traffic.php | 4 +- admin_updates.php | 23 +- lib/classes/database/class.DbManager.php | 18 +- .../database/manager/class.DbManagerMySQL.php | 10 +- lib/classes/output/class.paging.php | 59 ++--- lib/classes/settings/class.Settings.php | 205 ++++++++++++++++++ .../database/function.correctMysqlUsers.php | 4 +- .../froxlor/function.updateFunctions.php | 40 ++-- 20 files changed, 448 insertions(+), 247 deletions(-) create mode 100644 lib/classes/settings/class.Settings.php diff --git a/admin_admins.php b/admin_admins.php index 88dd799b..92c6b6b4 100644 --- a/admin_admins.php +++ b/admin_admins.php @@ -42,7 +42,7 @@ if ($page == 'admins' 'traffic_used' => $lng['customer']['traffic'] . ' (' . $lng['panel']['used'] . ')', 'deactivated' => $lng['admin']['deactivated'] ); - $paging = new paging($userinfo, TABLE_PANEL_ADMINS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); + $paging = new paging($userinfo, TABLE_PANEL_ADMINS, $fields); $admins = ''; $result_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_ADMINS . "` " . $paging->getSqlWhere(false) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit()); $numrows_admins = Database::num_rows(); @@ -54,14 +54,16 @@ if ($page == 'admins' $i = 0; $count = 0; + $dec_places = Settings::Get('panel.decimal_places'); + while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { if ($paging->checkDisplay($i)) { - $row['traffic_used'] = round($row['traffic_used'] / (1024 * 1024), $settings['panel']['decimal_places']); - $row['traffic'] = round($row['traffic'] / (1024 * 1024), $settings['panel']['decimal_places']); - $row['diskspace_used'] = round($row['diskspace_used'] / 1024, $settings['panel']['decimal_places']); - $row['diskspace'] = round($row['diskspace'] / 1024, $settings['panel']['decimal_places']); + $row['traffic_used'] = round($row['traffic_used'] / (1024 * 1024), $dec_places); + $row['traffic'] = round($row['traffic'] / (1024 * 1024), $dec_places); + $row['diskspace_used'] = round($row['diskspace_used'] / 1024, $dec_places); + $row['diskspace'] = round($row['diskspace'] / 1024, $dec_places); // percent-values for progressbar // For Disk usage @@ -223,7 +225,7 @@ if ($page == 'admins' $email_forwarders = - 1; } - if ($settings['system']['mail_quota_enabled'] == '1') { + if (Settings::Get('system.mail_quota_enabled') == '1') { $email_quota = validate($_POST['email_quota'], 'email_quota', '/^\d+$/', 'vmailquotawrong', array('0', '')); if (isset($_POST['email_quota_ul'])) { @@ -238,7 +240,7 @@ if ($page == 'admins' $ftps = - 1; } - if ($settings['ticket']['enabled'] == 1) { + if (Settings::Get('ticket.enabled') == 1) { $tickets = intval_ressource($_POST['tickets']); if (isset($_POST['tickets_ul'])) { @@ -312,8 +314,8 @@ if ($page == 'admins' standard_error('loginnameexists', $loginname); } // Accounts which match systemaccounts are not allowed, filtering them - elseif (preg_match('/^' . preg_quote($settings['customer']['accountprefix'], '/') . '([0-9]+)/', $loginname)) { - standard_error('loginnameissystemaccount', $settings['customer']['accountprefix']); + elseif (preg_match('/^' . preg_quote(Settings::Get('customer.accountprefix'), '/') . '([0-9]+)/', $loginname)) { + standard_error('loginnameissystemaccount', Settings::Get('customer.accountprefix')); } elseif (!validateUsername($loginname)) { standard_error('loginnameiswrong', $loginname); @@ -352,7 +354,7 @@ if ($page == 'admins' $tickets_see_all = '0'; } - $_theme = $settings['panel']['default_theme']; + $_theme = Settings::Get('panel.default_theme'); $ins_data = array( 'loginname' => $loginname, @@ -537,7 +539,7 @@ if ($page == 'admins' $email_forwarders = -1; } - if ($settings['system']['mail_quota_enabled'] == '1') { + if (Settings('system.mail_quota_enabled') == '1') { $email_quota = validate($_POST['email_quota'], 'email_quota', '/^\d+$/', 'vmailquotawrong', array('0', '')); if (isset($_POST['email_quota_ul'])) { $email_quota = -1; @@ -551,7 +553,7 @@ if ($page == 'admins' $ftps = -1; } - if ($settings['ticket']['enabled'] == 1) { + if (Settings::Get('ticket.enabled') == 1) { $tickets = intval_ressource($_POST['tickets']); if (isset($_POST['tickets_ul'])) { $tickets = -1; @@ -749,8 +751,9 @@ if ($page == 'admins' } else { - $result['traffic'] = round($result['traffic'] / (1024 * 1024), $settings['panel']['decimal_places']); - $result['diskspace'] = round($result['diskspace'] / 1024, $settings['panel']['decimal_places']); + $dec_places = Settings::Get('panel.decimal_places'); + $result['traffic'] = round($result['traffic'] / (1024 * 1024), $dec_places); + $result['diskspace'] = round($result['diskspace'] / 1024, $dec_places); $result['email'] = $idna_convert->decode($result['email']); $customers_ul = makecheckbox('customers_ul', $lng['customer']['unlimited'], '-1', false, $result['customers'], true, true); diff --git a/admin_configfiles.php b/admin_configfiles.php index 48bb87f1..63a64073 100644 --- a/admin_configfiles.php +++ b/admin_configfiles.php @@ -85,19 +85,19 @@ if($userinfo['change_serversettings'] == '1') '' => 'MYSQL_PASSWORD', '' => $sql['db'], '' => $sql['host'], - '' => $settings['system']['hostname'], - '' => $settings['system']['ipaddress'], - '' => $settings['system']['nameservers'], - '' => $settings['system']['vmail_homedir'], - '' => $settings['system']['vmail_uid'], - '' => $settings['system']['vmail_gid'], - '' => ($settings['system']['use_ssl'] == '1') ? 'imaps pop3s' : '', - '' => ($settings['system']['mod_fcgid_tmpdir'] != '') ? makeCorrectDir($settings['system']['mod_fcgid_tmpdir']) : '/tmp/', - '' => makeCorrectDir(dirname(__FILE__)), - '' => makeCorrectDir($settings['system']['bindconf_directory']), - '' => $settings['system']['apachereload_command'], - '' => makeCorrectDir($settings['system']['logfiles_directory']), - '' => makeCorrectDir($settings['phpfpm']['fastcgi_ipcdir']) + '' => Settings::Get('system.hostname'), + '' => Settings::Get('system.ipaddress'), + '' => Settings::Get('system.nameservers'), + '' => Settings::Get('system.vmail_homedir'), + '' => Settings::Get('system.vmail_uid'), + '' => Settings::Get('system.vmail_gid'), + '' => (Settings::Get('system.use_ssl') == '1') ? 'imaps pop3s' : '', + '' => (Settings::Get('system.mod_fcgid_tmpdir') != '') ? makeCorrectDir(Settings::Get('system.mod_fcgid_tmpdir')) : '/tmp/', + '' => makeCorrectDir(FROXLOR_INSTALL_DIR), + '' => makeCorrectDir(Settings::Get('system.bindconf_directory')), + '' => Settings::Get('system.apachereload_command'), + '' => makeCorrectDir(Settings::Get('system.logfiles_directory')), + '' => makeCorrectDir(Settings::Get('phpfpm.fastcgi_ipcdir')) ); $files = ''; $configpage = ''; diff --git a/admin_cronjobs.php b/admin_cronjobs.php index 4ccf0d78..f2b5823d 100644 --- a/admin_cronjobs.php +++ b/admin_cronjobs.php @@ -33,7 +33,7 @@ if ($page == 'cronjobs' || $page == 'overview') { 'c.interval' => $lng['cron']['interval'], 'c.isactive' => $lng['cron']['isactive'] ); - $paging = new paging($userinfo, TABLE_PANEL_CRONRUNS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); + $paging = new paging($userinfo, TABLE_PANEL_CRONRUNS, $fields); /* * @TODO Fix sorting diff --git a/admin_customers.php b/admin_customers.php index 9cd0f5eb..90f4fb42 100644 --- a/admin_customers.php +++ b/admin_customers.php @@ -47,7 +47,7 @@ if ($page == 'customers' 'c.traffic_used' => $lng['customer']['traffic'] . ' (' . $lng['panel']['used'] . ')' ); - $paging = new paging($userinfo, TABLE_PANEL_CUSTOMERS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); + $paging = new paging($userinfo, TABLE_PANEL_CUSTOMERS, $fields); $customers = ''; $result_stmt = Database::prepare(" SELECT `c`.*, `a`.`loginname` AS `adminname` @@ -56,7 +56,7 @@ if ($page == 'customers' ($userinfo['customers_see_all'] ? '' : " `c`.`adminid` = :adminid AND ") . " `c`.`adminid` = `a`.`adminid` " . $paging->getSqlWhere(true) . " " . - $paging->getSqlOrderBy($settings['panel']['natsorting']) . " " . + $paging->getSqlOrderBy() . " " . $paging->getSqlLimit() ); Database::pexecute($result_stmt, array('adminid' => $userinfo['adminid'])); @@ -83,10 +83,11 @@ if ($page == 'customers' Database::pexecute($domains_stmt, array('cid' => $row['customerid'], 'stdd' => $row['standardsubdomain'])); $domains = $domains_stmt->fetch(PDO::FETCH_ASSOC); $row['domains'] = intval($domains['domains']); - $row['traffic_used'] = round($row['traffic_used'] / (1024 * 1024), $settings['panel']['decimal_places']); - $row['traffic'] = round($row['traffic'] / (1024 * 1024), $settings['panel']['decimal_places']); - $row['diskspace_used'] = round($row['diskspace_used'] / 1024, $settings['panel']['decimal_places']); - $row['diskspace'] = round($row['diskspace'] / 1024, $settings['panel']['decimal_places']); + $dec_places = Settings::Get('panel.decimal_places'); + $row['traffic_used'] = round($row['traffic_used'] / (1024 * 1024), $dec_places); + $row['traffic'] = round($row['traffic'] / (1024 * 1024), $dec_places); + $row['diskspace_used'] = round($row['diskspace_used'] / 1024, $dec_places); + $row['diskspace'] = round($row['diskspace'] / 1024, $dec_places); $last_login = ((int)$row['lastlogin_succ'] == 0) ? $lng['panel']['neverloggedin'] : date('d.m.Y', $row['lastlogin_succ']); /** @@ -110,8 +111,8 @@ if ($page == 'customers' } $islocked = 0; - if ($row['loginfail_count'] >= $settings['login']['maxloginattempts'] - && $row['lastlogin_fail'] > (time() - $settings['login']['deactivatetime']) + if ($row['loginfail_count'] >= Settings::Get('login.maxloginattempts') + && $row['lastlogin_fail'] > (time() - Settings::Get('login.deactivatetime')) ) { $islocked = 1; } @@ -243,7 +244,7 @@ if ($page == 'customers' Database::needRoot(true); $last_dbserver = 0; - $dbm = new DbManager($settings, $log); + $dbm = new DbManager($log); while ($row_database = $databases_stmt->fetch(PDO::FETCH_ASSOC)) { @@ -359,6 +360,7 @@ if ($page == 'customers' if ($tickets !== false && isset($tickets[0])) { foreach ($tickets as $ticket) { $now = time(); + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$ticket); $mainticket->Set('lastchange', $now, true, true); $mainticket->Set('lastreplier', '1', true, true); @@ -426,7 +428,7 @@ if ($page == 'customers' $email_forwarders = - 1; } - if ($settings['system']['mail_quota_enabled'] == '1') { + if (Settings::Get('system.mail_quota_enabled') == '1') { $email_quota = validate($_POST['email_quota'], 'email_quota', '/^\d+$/', 'vmailquotawrong', array('0', '')); if (isset($_POST['email_quota_ul'])) { $email_quota = - 1; @@ -453,9 +455,9 @@ if ($page == 'customers' $ftps = - 1; } - $tickets = ($settings['ticket']['enabled'] == 1 ? intval_ressource($_POST['tickets']) : 0); + $tickets = (Settings::Get('ticket.enabled') == 1 ? intval_ressource($_POST['tickets']) : 0); if (isset($_POST['tickets_ul']) - && $settings['ticket']['enabled'] == '1' + && Settings::Get('ticket.enabled') == '1' ) { $tickets = - 1; } @@ -510,7 +512,7 @@ if ($page == 'customers' || ((($userinfo['emails_used'] + $emails) > $userinfo['emails']) && $userinfo['emails'] != '-1') || ((($userinfo['email_accounts_used'] + $email_accounts) > $userinfo['email_accounts']) && $userinfo['email_accounts'] != '-1') || ((($userinfo['email_forwarders_used'] + $email_forwarders) > $userinfo['email_forwarders']) && $userinfo['email_forwarders'] != '-1') - || ((($userinfo['email_quota_used'] + $email_quota) > $userinfo['email_quota']) && $userinfo['email_quota'] != '-1' && $settings['system']['mail_quota_enabled'] == '1') + || ((($userinfo['email_quota_used'] + $email_quota) > $userinfo['email_quota']) && $userinfo['email_quota'] != '-1' && Settings::Get('system.mail_quota_enabled') == '1') || ((($userinfo['ftps_used'] + $ftps) > $userinfo['ftps']) && $userinfo['ftps'] != '-1') || ((($userinfo['tickets_used'] + $tickets) > $userinfo['tickets']) && $userinfo['tickets'] != '-1') || ((($userinfo['subdomains_used'] + $subdomains) > $userinfo['subdomains']) && $userinfo['subdomains'] != '-1') @@ -519,7 +521,7 @@ if ($page == 'customers' || ($emails == '-1' && $userinfo['emails'] != '-1') || ($email_accounts == '-1' && $userinfo['email_accounts'] != '-1') || ($email_forwarders == '-1' && $userinfo['email_forwarders'] != '-1') - || ($email_quota == '-1' && $userinfo['email_quota'] != '-1' && $settings['system']['mail_quota_enabled'] == '1') + || ($email_quota == '-1' && $userinfo['email_quota'] != '-1' && Settings::Get('system.mail_quota_enabled') == '1') || ($ftps == '-1' && $userinfo['ftps'] != '-1') || ($tickets == '-1' && $userinfo['tickets'] != '-1') || ($subdomains == '-1' && $userinfo['subdomains'] != '-1') @@ -546,12 +548,12 @@ if ($page == 'customers' if (isset($_POST['new_loginname']) && $_POST['new_loginname'] != '' ) { - $accountnumber = intval($settings['system']['lastaccountnumber']); + $accountnumber = intval(Settings::Get('system.lastaccountnumber')); $loginname = validate($_POST['new_loginname'], 'loginname', '/^[a-z][a-z0-9\-_]+$/i'); // Accounts which match systemaccounts are not allowed, filtering them - if (preg_match('/^' . preg_quote($settings['customer']['accountprefix'], '/') . '([0-9]+)/', $loginname)) { - standard_error('loginnameissystemaccount', $settings['customer']['accountprefix']); + if (preg_match('/^' . preg_quote(Settings::Get('customer.accountprefix'), '/') . '([0-9]+)/', $loginname)) { + standard_error('loginnameissystemaccount', Settings::Get('customer.accountprefix')); } // Additional filtering for Bug #962 @@ -559,12 +561,12 @@ if ($page == 'customers' && !in_array("posix_getpwnam", explode(",", ini_get('disable_functions'))) && posix_getpwnam($loginname) ) { - standard_error('loginnameissystemaccount', $settings['customer']['accountprefix']); + standard_error('loginnameissystemaccount', Settings::Get('customer.accountprefix')); } } else { - $accountnumber = intval($settings['system']['lastaccountnumber']) + 1; - $loginname = $settings['customer']['accountprefix'] . $accountnumber; + $accountnumber = intval(Settings::Get('system.lastaccountnumber')) + 1; + $loginname = Settings::Get('customer.accountprefix') . $accountnumber; } // Check if the account already exists @@ -583,16 +585,16 @@ if ($page == 'customers' ) { standard_error('loginnameexists', $loginname); - } elseif (!validateUsername($loginname, $settings['panel']['unix_names'], 14 - strlen($settings['customer']['mysqlprefix']))) { - if (strlen($loginname) > 14 - strlen($settings['customer']['mysqlprefix'])) { - standard_error('loginnameiswrong2', 14 - strlen($settings['customer']['mysqlprefix'])); + } elseif (!validateUsername($loginname, Settings::Get('panel.unix_names'), 14 - strlen(Settings::Get('customer.mysqlprefix')))) { + if (strlen($loginname) > 14 - strlen(Settings::Get('customer.mysqlprefix'))) { + standard_error('loginnameiswrong2', 14 - strlen(Settings::Get('customer.mysqlprefix'))); } else { standard_error('loginnameiswrong', $loginname); } } - $guid = intval($settings['system']['lastguid']) + 1; - $documentroot = makeCorrectDir($settings['system']['documentroot_prefix'] . '/' . $loginname); + $guid = intval(Settings::Get('system.lastguid')) + 1; + $documentroot = makeCorrectDir(Settings::Get('system.documentroot_prefix') . '/' . $loginname); if (file_exists($documentroot)) { standard_error('documentrootexists', $documentroot); @@ -614,7 +616,7 @@ if ($page == 'customers' $password = substr(md5(uniqid(microtime(), 1)), 12, 6); } - $_theme = $settings['panel']['default_theme']; + $_theme = Settings::Get('panel.default_theme'); $ins_data = array( 'adminid' => $userinfo['adminid'], @@ -722,7 +724,7 @@ if ($page == 'customers' } if ($tickets != '-1' - && $settings['ticket']['enabled'] == 1 + && Settings::Get('ticket.enabled') == 1 ) { $admin_update_query.= ", `tickets_used` = `tickets_used` + 0" . (int)$tickets; } @@ -741,7 +743,7 @@ if ($page == 'customers' ); Database::pexecute($upd_stmt, array('guid' => $guid)); - if ($accountnumber != intval($settings['system']['lastaccountnumber'])) { + if ($accountnumber != intval(Settings::Get('system.lastaccountnumber'))) { $upd_stmt = Database::prepare(" UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = :accno @@ -777,7 +779,7 @@ if ($page == 'customers' 'passwd' => $htpasswdPassword ); - if ($settings['system']['awstats_enabled'] == '1') { + if (Settings::Get('system.awstats_enabled') == '1') { $ins_data['path'] = makeCorrectDir($documentroot . '/awstats/'); $log->logAction(ADM_ACTION, LOG_NOTICE, "automatically added awstats htpasswd for user '" . $loginname . "'"); } else { @@ -809,7 +811,7 @@ if ($page == 'customers' 'customerid' => $customerid, 'groupname' => $loginname, 'guid' => $guid, - 'members' => $loginname.','.$settings['system']['httpuser'] + 'members' => $loginname.','.Settings::Get('system.httpuser') ); Database::pexecute($ins_stmt, $ins_data); // FTP-Quotatallies @@ -824,12 +826,12 @@ if ($page == 'customers' if ($createstdsubdomain == '1') { - if (isset($settings['system']['stdsubdomain']) - && $settings['system']['stdsubdomain'] != '' + if (Settings::Get('system.stdsubdomain') !== null + && Settings::Get('system.stdsubdomain') != '' ) { - $_stdsubdomain = $loginname . '.' . $settings['system']['stdsubdomain']; + $_stdsubdomain = $loginname . '.' . Settings::Get('system.stdsubdomain'); } else { - $_stdsubdomain = $loginname . '.' . $settings['system']['hostname']; + $_stdsubdomain = $loginname . '.' . Settings::Get('system.hostname'); } $ins_data = array( @@ -861,7 +863,7 @@ if ($page == 'customers' $ins_stmt = Database::prepare(" INSERT INTO `".TABLE_DOMAINTOIP."` SET `id_domain` = :domainid, `id_ipandports` = :ipid" ); - Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipid' => $settings['system']['defaultip'])); + Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipid' => Settings::Get('system.defaultip'))); $upd_stmt = Database::prepare(" UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `standardsubdomain` = :domainid WHERE `customerid` = :customerid" @@ -873,8 +875,8 @@ if ($page == 'customers' if ($sendpassword == '1') { - $srv_hostname = $settings['system']['hostname']; - if ($settings['system']['froxlordirectlyviahostname'] == '0') { + $srv_hostname = Settings::Get('system.hostname'); + if (Settings::Get('system.froxlordirectlyviahostname') == '0') { $srv_hostname .= '/froxlor'; } @@ -882,7 +884,7 @@ if ($page == 'customers' SELECT ip, port FROM `".TABLE_PANEL_IPSANDPORTS."` WHERE `id` = :defaultip "); - $srv_ip = Database::pexecute_first($srv_ip_stmt, array('defaultip' => $settings['system']['defaultip'])); + $srv_ip = Database::pexecute_first($srv_ip_stmt, array('defaultip' => Settings::Get('system.defaultip'))); $replace_arr = array( 'FIRSTNAME' => $firstname, @@ -942,7 +944,7 @@ if ($page == 'customers' $language_options = ''; while (list($language_file, $language_name) = each($languages)) { - $language_options.= makeoption($language_name, $language_file, $settings['panel']['standardlanguage'], true); + $language_options.= makeoption($language_name, $language_file, Settings::Get('panel.standardlanguage'), true); } $diskspace_ul = makecheckbox('diskspace_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); @@ -1034,7 +1036,7 @@ if ($page == 'customers' $email_forwarders = - 1; } - if ($settings['system']['mail_quota_enabled'] == '1') { + if (Settings::Get('system.mail_quota_enabled') == '1') { $email_quota = validate($_POST['email_quota'], 'email_quota', '/^\d+$/', 'vmailquotawrong', array('0', '')); if (isset($_POST['email_quota_ul'])) { $email_quota = - 1; @@ -1061,9 +1063,9 @@ if ($page == 'customers' $ftps = - 1; } - $tickets = ($settings['ticket']['enabled'] == 1 ? intval_ressource($_POST['tickets']) : 0); + $tickets = (Settings::Get('ticket.enabled') == 1 ? intval_ressource($_POST['tickets']) : 0); if (isset($_POST['tickets_ul']) - && $settings['ticket']['enabled'] == '1' + && Settings::Get('ticket.enabled') == '1' ) { $tickets = - 1; } @@ -1109,7 +1111,7 @@ if ($page == 'customers' || ((($userinfo['emails_used'] + $emails - $result['emails']) > $userinfo['emails']) && $userinfo['emails'] != '-1') || ((($userinfo['email_accounts_used'] + $email_accounts - $result['email_accounts']) > $userinfo['email_accounts']) && $userinfo['email_accounts'] != '-1') || ((($userinfo['email_forwarders_used'] + $email_forwarders - $result['email_forwarders']) > $userinfo['email_forwarders']) && $userinfo['email_forwarders'] != '-1') - || ((($userinfo['email_quota_used'] + $email_quota - $result['email_quota']) > $userinfo['email_quota']) && $userinfo['email_quota'] != '-1' && $settings['system']['mail_quota_enabled'] == '1') + || ((($userinfo['email_quota_used'] + $email_quota - $result['email_quota']) > $userinfo['email_quota']) && $userinfo['email_quota'] != '-1' && Settings::Get('system.mail_quota_enabled') == '1') || ((($userinfo['ftps_used'] + $ftps - $result['ftps']) > $userinfo['ftps']) && $userinfo['ftps'] != '-1') || ((($userinfo['tickets_used'] + $tickets - $result['tickets']) > $userinfo['tickets']) && $userinfo['tickets'] != '-1') || ((($userinfo['subdomains_used'] + $subdomains - $result['subdomains']) > $userinfo['subdomains']) && $userinfo['subdomains'] != '-1') @@ -1118,7 +1120,7 @@ if ($page == 'customers' || ($emails == '-1' && $userinfo['emails'] != '-1') || ($email_accounts == '-1' && $userinfo['email_accounts'] != '-1') || ($email_forwarders == '-1' && $userinfo['email_forwarders'] != '-1') - || ($email_quota == '-1' && $userinfo['email_quota'] != '-1' && $settings['system']['mail_quota_enabled'] == '1') + || ($email_quota == '-1' && $userinfo['email_quota'] != '-1' && Settings::Get('system.mail_quota_enabled') == '1') || ($ftps == '-1' && $userinfo['ftps'] != '-1') || ($tickets == '-1' && $userinfo['tickets'] != '-1') || ($subdomains == '-1' && $userinfo['subdomains'] != '-1') @@ -1157,12 +1159,12 @@ if ($page == 'customers' && $result['standardsubdomain'] == '0' ) { - if (isset($settings['system']['stdsubdomain']) - && $settings['system']['stdsubdomain'] != '' + if (Settings::Get('system.stdsubdomain') !== null + && Settings::Get('system.stdsubdomain') != '' ) { - $_stdsubdomain = $result['loginname'] . '.' . $settings['system']['stdsubdomain']; + $_stdsubdomain = $result['loginname'] . '.' . Settings::Get('system.stdsubdomain'); } else { - $_stdsubdomain = $result['loginname'] . '.' . $settings['system']['hostname']; + $_stdsubdomain = $result['loginname'] . '.' . Settings::Get('system.hostname'); } $ins_data = array( @@ -1194,7 +1196,7 @@ if ($page == 'customers' $ins_stmt = Database::prepare(" INSERT INTO `".TABLE_DOMAINTOIP."` SET `id_domain` = :domainid, `id_ipandports` = :ipid" ); - Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipid' => $settings['system']['defaultip'])); + Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipid' => Settings::Get('system.defaultip'))); $upd_stmt = Database::prepare(" UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `standardsubdomain` = :domainid WHERE `customerid` = :customerid" @@ -1265,7 +1267,7 @@ if ($page == 'customers' Database::needRoot(true); $last_dbserver = 0; - $dbm = new DbManager($settings, $log); + $dbm = new DbManager($log); // For each of them while ($row_database = $databases_stmt->fetch(PDO::FETCH_ASSOC)) { @@ -1276,7 +1278,7 @@ if ($page == 'customers' $last_dbserver = $row_database['dbserver']; } - foreach (array_unique(explode(',', $settings['system']['mysql_access_host'])) as $mysql_access_host) { + foreach (array_unique(explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) { $mysql_access_host = trim($mysql_access_host); // Prevent access, if deactivated @@ -1497,8 +1499,9 @@ if ($page == 'customers' $language_options.= makeoption($language_name, $language_file, $result['def_language'], true); } - $result['traffic'] = round($result['traffic'] / (1024 * 1024), $settings['panel']['decimal_places']); - $result['diskspace'] = round($result['diskspace'] / 1024, $settings['panel']['decimal_places']); + $dec_places = Settings::Get('panel.decimal_places'); + $result['traffic'] = round($result['traffic'] / (1024 * 1024), $dec_places); + $result['diskspace'] = round($result['diskspace'] / 1024, $dec_places); $result['email'] = $idna_convert->decode($result['email']); $diskspace_ul = makecheckbox('diskspace_ul', $lng['customer']['unlimited'], '-1', false, $result['diskspace'], true, true); diff --git a/admin_domains.php b/admin_domains.php index 8f31a7cf..a7a92fdf 100644 --- a/admin_domains.php +++ b/admin_domains.php @@ -51,7 +51,7 @@ if ($page == 'domains' 'c.loginname' => $lng['login']['username'], 'd.aliasdomain' => $lng['domains']['aliasdomain'] ); - $paging = new paging($userinfo, TABLE_PANEL_DOMAINS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); + $paging = new paging($userinfo, TABLE_PANEL_DOMAINS, $fields); $domains = ''; $result_stmt = Database::prepare(" SELECT `d`.*, `c`.`loginname`, `c`.`name`, `c`.`firstname`, `c`.`company`, `c`.`standardsubdomain`, `ad`.`id` AS `aliasdomainid`, `ad`.`domain` AS `aliasdomain` @@ -283,7 +283,7 @@ if ($page == 'domains' && $_POST['send'] == 'send' ) { - if ($_POST['domain'] == $settings['system']['hostname']) { + if ($_POST['domain'] == Settings::Get('system.hostname')) { standard_error('admin_domain_emailsystemhostname'); exit; } @@ -361,7 +361,7 @@ if ($page == 'domains' $isbinddomain = '0'; $zonefile = ''; - if ($settings['system']['bind_enable'] == '1') { + if (Settings::Get('system.bind_enable') == '1') { if (isset($_POST['isbinddomain'])) { $isbinddomain = intval($_POST['isbinddomain']); } @@ -391,14 +391,14 @@ if ($page == 'domains' } } elseif (isset($_POST['documentroot']) && ($_POST['documentroot'] == '') - && ($settings['system']['documentroot_use_default_value'] == 1) + && (Settings::Get('system.documentroot_use_default_value') == 1) ) { $documentroot = makeCorrectDir($customer['documentroot'] . '/' . $domain); } } else { $isbinddomain = '0'; - if ($settings['system']['bind_enable'] == '1') { + if (Settings::Get('system.bind_enable') == '1') { $isbinddomain = '1'; } $caneditdomain = '1'; @@ -413,8 +413,8 @@ if ($page == 'domains' $openbasedir = isset($_POST['openbasedir']) ? intval($_POST['openbasedir']) : 0; - if ((int)$settings['system']['mod_fcgid'] == 1 - || (int)$settings['phpfpm']['enabled'] == 1 + if ((int)Settings::Get('system.mod_fcgid') == 1 + || (int)Settings::Get('phpfpm.enabled') == 1 ) { $phpsettingid = (int)$_POST['phpsettingid']; $phpsettingid_check_stmt = Database::prepare(" @@ -430,7 +430,7 @@ if ($page == 'domains' standard_error('phpsettingidwrong'); } - if ((int)$settings['system']['mod_fcgid'] == 1) { + if ((int)Settings::Get('system.mod_fcgid') == 1) { $mod_fcgid_starter = validate($_POST['mod_fcgid_starter'], 'mod_fcgid_starter', '/^[0-9]*$/', '', array('-1', '')); $mod_fcgid_maxrequests = validate($_POST['mod_fcgid_maxrequests'], 'mod_fcgid_maxrequests', '/^[0-9]*$/', '', array('-1', '')); } else { @@ -440,10 +440,10 @@ if ($page == 'domains' } else { - if ((int)$settings['phpfpm']['enabled'] == 1) { - $phpsettingid = $settings['phpfpm']['defaultini']; + if ((int)Settings::Get('phpfpm.enabled') == 1) { + $phpsettingid = Settings::Get('phpfpm.defaultini'); } else { - $phpsettingid = $settings['system']['mod_fcgid_defaultini']; + $phpsettingid = Settings::Get('system.mod_fcgid_defaultini'); } $mod_fcgid_starter = '-1'; $mod_fcgid_maxrequests = '-1'; @@ -452,10 +452,10 @@ if ($page == 'domains' } else { $openbasedir = '1'; - if ((int)$settings['phpfpm']['enabled'] == 1) { - $phpsettingid = $settings['phpfpm']['defaultini']; + if ((int)Settings::Get('phpfpm.enabled') == 1) { + $phpsettingid = Settings::Get('phpfpm.defaultini'); } else { - $phpsettingid = $settings['system']['mod_fcgid_defaultini']; + $phpsettingid = Settings::Get('system.mod_fcgid_defaultini'); } $mod_fcgid_starter = '-1'; $mod_fcgid_maxrequests = '-1'; @@ -501,7 +501,7 @@ if ($page == 'domains' } } - if ($settings['system']['use_ssl'] == "1" + if (Settings::Get('system.use_ssl') == "1" && isset($_POST['ssl_ipandport']) ) { $ssl_redirect = 0; @@ -646,7 +646,7 @@ if ($page == 'domains' standard_error(array('stringisempty', 'mydomain')); } // Check whether domain validation is enabled and if, validate the domain - elseif ($settings['system']['validate_domain'] && !validateDomain($domain)) { + elseif (Settings::Get('system.validate_domain') && !validateDomain($domain)) { standard_error(array('stringiswrong', 'mydomain')); } elseif($documentroot == '') { standard_error(array('stringisempty', 'mydocumentroot')); @@ -935,10 +935,10 @@ if ($page == 'domains' $configs = Database::query("SELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "`"); while ($row = $configs->fetch(PDO::FETCH_ASSOC)) { - if ((int)$settings['phpfpm']['enabled'] == 1) { - $phpconfigs.= makeoption($row['description'], $row['id'], $settings['phpfpm']['defaultini'], true, true); + if ((int)Settings::Get('phpfpm.enabled') == 1) { + $phpconfigs.= makeoption($row['description'], $row['id'], Settings::Get('phpfpm.defaultini'), true, true); } else { - $phpconfigs.= makeoption($row['description'], $row['id'], $settings['system']['mod_fcgid_defaultini'], true, true); + $phpconfigs.= makeoption($row['description'], $row['id'], Settings::Get('system.mod_fcgid_defaultini'), true, true); } } @@ -1046,7 +1046,7 @@ if ($page == 'domains' if ($customerid > 0 && $customerid != $result['customerid'] - && $settings['panel']['allow_domain_change_customer'] == '1' + && Settings::Get('panel.allow_domain_change_customer') == '1' ) { $customer_stmt = Database::prepare(" @@ -1094,7 +1094,7 @@ if ($page == 'domains' if ($adminid > 0 && $adminid != $result['adminid'] - && $settings['panel']['allow_domain_change_admin'] == '1' + && Settings::Get('panel.allow_domain_change_admin') == '1' ) { $admin_stmt = Database::prepare(" @@ -1150,7 +1150,7 @@ if ($page == 'domains' if ($userinfo['change_serversettings'] == '1') { $isbinddomain = $result['isbinddomain']; $zonefile = $result['zonefile']; - if ($settings['system']['bind_enable'] == '1') { + if (Settings::Get('system.bind_enable') == '1') { if (isset($_POST['isbinddomain'])) { $isbinddomain = (int)$_POST['isbinddomain']; } else { @@ -1159,7 +1159,7 @@ if ($page == 'domains' $zonefile = validate($_POST['zonefile'], 'zonefile'); } - if ($settings['dkim']['use_dkim'] == '1') { + if (Settings::Get('dkim.use_dkim') == '1') { $dkim = isset($_POST['dkim']) ? 1 : 0; } else { $dkim = $result['dkim']; @@ -1171,7 +1171,7 @@ if ($page == 'domains' if ($documentroot == '') { // If path is empty and 'Use domain name as default value for DocumentRoot path' is enabled in settings, // set default path to subdomain or domain name - if ($settings['system']['documentroot_use_default_value'] == 1) { + if (Settings::Get('system.documentroot_use_default_value') == 1) { $documentroot = makeCorrectDir($customer['documentroot'] . '/' . $result['domain']); } else { $documentroot = $customer['documentroot']; @@ -1200,8 +1200,8 @@ if ($page == 'domains' $openbasedir = isset($_POST['openbasedir']) ? intval($_POST['openbasedir']) : 0; - if ((int)$settings['system']['mod_fcgid'] == 1 - || (int)$settings['phpfpm']['enabled'] == 1 + if ((int)Settings::Get('system.mod_fcgid') == 1 + || (int)Settings::Get('phpfpm.enabled') == 1 ) { $phpsettingid = (int)$_POST['phpsettingid']; $phpsettingid_check_stmt = Database::prepare(" @@ -1216,7 +1216,7 @@ if ($page == 'domains' standard_error('phpsettingidwrong'); } - if ((int)$settings['system']['mod_fcgid'] == 1) { + if ((int)Settings::Get('system.mod_fcgid') == 1) { $mod_fcgid_starter = validate($_POST['mod_fcgid_starter'], 'mod_fcgid_starter', '/^[0-9]*$/', '', array('-1', '')); $mod_fcgid_maxrequests = validate($_POST['mod_fcgid_maxrequests'], 'mod_fcgid_maxrequests', '/^[0-9]*$/', '', array('-1', '')); } else { @@ -1261,7 +1261,7 @@ if ($page == 'domains' } } - if ($settings['system']['use_ssl'] == '1' + if (Settings::Get('system.use_ssl') == '1' && isset($_POST['ssl_ipandport']) ) { $ssl = 1; // if ssl is set and != 0, it can only be 1 @@ -1490,7 +1490,7 @@ if ($page == 'domains' } if ($customerid != $result['customerid'] - && $settings['panel']['allow_domain_change_customer'] == '1' + && Settings::Get('panel.allow_domain_change_customer') == '1' ) { $upd_data = array('customerid' => $customerid, 'domainid' => $result['id']); $upd_stmt = Database::prepare(" @@ -1526,7 +1526,7 @@ if ($page == 'domains' } if ($adminid != $result['adminid'] - && $settings['panel']['allow_domain_change_admin'] == '1' + && Settings::Get('panel.allow_domain_change_admin') == '1' ) { $upd_stmt = Database::prepare(" UPDATE `" . TABLE_PANEL_ADMINS . "` SET `domains_used` = `domains_used` + 1 WHERE `adminid` = :adminid @@ -1688,7 +1688,7 @@ if ($page == 'domains' } else { - if ($settings['panel']['allow_domain_change_customer'] == '1') { + if (Settings::Get('panel.allow_domain_change_customer') == '1') { $customers = ''; $result_customers_stmt = Database::prepare(" SELECT `customerid`, `loginname`, `name`, `firstname`, `company` FROM `" . TABLE_PANEL_CUSTOMERS . "` @@ -1725,7 +1725,7 @@ if ($page == 'domains' } if ($userinfo['customers_see_all'] == '1') { - if ($settings['panel']['allow_domain_change_admin'] == '1') { + if (Settings::Get('panel.allow_domain_change_admin') == '1') { $admins = ''; $result_admins_stmt = Database::prepare(" diff --git a/admin_index.php b/admin_index.php index 51795a58..8be08418 100644 --- a/admin_index.php +++ b/admin_index.php @@ -26,7 +26,7 @@ if ($action == 'logout') { $params = array('adminid' => (int)$userinfo['adminid']); - if ($settings['session']['allow_multiple_login'] == '1') { + if (Settings::Get('session.allow_multiple_login') == '1') { $stmt = Database::prepare("DELETE FROM `" . TABLE_PANEL_SESSIONS . "` WHERE `userid` = :adminid AND `adminsession` = '1' @@ -67,8 +67,9 @@ if ($page == 'overview') { FROM `" . TABLE_PANEL_CUSTOMERS . "`" . ($userinfo['customers_see_all'] ? '' : " WHERE `adminid` = :adminid ")); $overview = Database::pexecute_first($overview_stmt, array('adminid' => $userinfo['adminid'])); - $overview['traffic_used'] = round($overview['traffic_used'] / (1024 * 1024), $settings['panel']['decimal_places']); - $overview['diskspace_used'] = round($overview['diskspace_used'] / 1024, $settings['panel']['decimal_places']); + $dec_places = Settings::Get('panel.decimal_places'); + $overview['traffic_used'] = round($overview['traffic_used'] / (1024 * 1024), $dec_places); + $overview['diskspace_used'] = round($overview['diskspace_used'] / 1024, $dec_places); $number_domains_stmt = Database::prepare(" SELECT COUNT(*) AS `number_domains` FROM `" . TABLE_PANEL_DOMAINS . "` @@ -132,10 +133,11 @@ if ($page == 'overview') { $isnewerversion = 0; } - $userinfo['diskspace'] = round($userinfo['diskspace'] / 1024, $settings['panel']['decimal_places']); - $userinfo['diskspace_used'] = round($userinfo['diskspace_used'] / 1024, $settings['panel']['decimal_places']); - $userinfo['traffic'] = round($userinfo['traffic'] / (1024 * 1024), $settings['panel']['decimal_places']); - $userinfo['traffic_used'] = round($userinfo['traffic_used'] / (1024 * 1024), $settings['panel']['decimal_places']); + $dec_places = Settings::Get('panel.decimal_places'); + $userinfo['diskspace'] = round($userinfo['diskspace'] / 1024, $dec_places); + $userinfo['diskspace_used'] = round($userinfo['diskspace_used'] / 1024, $dec_places); + $userinfo['traffic'] = round($userinfo['traffic'] / (1024 * 1024), $dec_places); + $userinfo['traffic_used'] = round($userinfo['traffic_used'] / (1024 * 1024), $dec_places); $userinfo = str_replace_array('-1', $lng['customer']['unlimited'], $userinfo, 'customers domains diskspace traffic mysqls emails email_accounts email_forwarders email_quota ftps tickets subdomains'); $cron_last_runs = getCronjobsLastRun(); @@ -266,7 +268,7 @@ if ($page == 'overview') { $language_options = ''; - $default_lang = $settings['panel']['standardlanguage']; + $default_lang = Settings::Get('panel.standardlanguage'); if ($userinfo['def_language'] != '') { $default_lang = $userinfo['def_language']; } @@ -312,7 +314,7 @@ if ($page == 'overview') { $theme_options = ''; - $default_theme = $settings['panel']['default_theme']; + $default_theme = Settings::Get('panel.default_theme'); if ($userinfo['theme'] != '') { $default_theme = $userinfo['theme']; } @@ -326,7 +328,7 @@ if ($page == 'overview') { } } elseif ($page == 'send_error_report' - && $settings['system']['allow_error_report_admin'] == '1' + && Settings::Get('system.allow_error_report_admin') == '1' ) { // only show this if we really have an exception to report diff --git a/admin_ipsandports.php b/admin_ipsandports.php index 5d00b69b..4465bfb0 100644 --- a/admin_ipsandports.php +++ b/admin_ipsandports.php @@ -37,7 +37,7 @@ if ($page == 'ipsandports' 'ip' => $lng['admin']['ipsandports']['ip'], 'port' => $lng['admin']['ipsandports']['port'] ); - $paging = new paging($userinfo, TABLE_PANEL_IPSANDPORTS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); + $paging = new paging($userinfo, TABLE_PANEL_IPSANDPORTS, $fields); $ipsandports = ''; $result_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` " . $paging->getSqlWhere(false) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit()); Database::pexecute($result_stmt); @@ -79,7 +79,7 @@ if ($page == 'ipsandports' $result_checkdomain = Database::pexecute_first($result_checkdomain_stmt, array('id' => $id)); if ($result_checkdomain['id'] == '') { - if ($result['id'] != $settings['system']['defaultip']) { + if ($result['id'] != Settings::Get('system.defaultip')) { $result_sameipotherport_stmt = Database::prepare(" SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "` @@ -87,8 +87,8 @@ if ($page == 'ipsandports' ); $result_sameipotherport = Database::pexecute_first($result_sameipotherport_stmt, array('id' => $id, 'ip' => $result['ip'])); - if (($result['ip'] != $settings['system']['ipaddress']) - || ($result['ip'] == $settings['system']['ipaddress'] + if (($result['ip'] != Settings::Get('system.ipaddress')) + || ($result['ip'] == Settings::Get('system.ipaddress') && $result_sameipotherport['id'] != '') ) { $result_stmt = Database::prepare(" @@ -152,7 +152,7 @@ if ($page == 'ipsandports' $default_vhostconf_domain = validate(str_replace("\r\n", "\n", $_POST['default_vhostconf_domain']), 'default_vhostconf_domain', '/^[^\0]*$/'); $docroot = validate($_POST['docroot'], 'docroot'); - if ((int)$settings['system']['use_ssl'] == 1) { + if ((int)Settings::Get('system.use_ssl') == 1) { $ssl = isset($_POST['ssl']) ? intval($_POST['ssl']) : 0; $ssl_cert_file = validate($_POST['ssl_cert_file'], 'ssl_cert_file'); $ssl_key_file = validate($_POST['ssl_key_file'], 'ssl_key_file'); @@ -304,7 +304,7 @@ if ($page == 'ipsandports' ); $result_sameipotherport = Database::pexecute_first($result_sameipotherport_stmt, array('ip' => $ip, 'id' => $id)); - if ((int)$settings['system']['use_ssl'] == 1 + if ((int)Settings::Get('system.use_ssl') == 1 && isset($_POST['ssl']) && $_POST['ssl'] != 0 ) { @@ -364,7 +364,7 @@ if ($page == 'ipsandports' } if ($result['ip'] != $ip - && $result['ip'] == $settings['system']['ipaddress'] + && $result['ip'] == Settings::Get('system.ipaddress') && $result_sameipotherport['id'] == '' ) { standard_error('cantchangesystemip'); diff --git a/admin_logger.php b/admin_logger.php index 5387abc8..aec3e4c0 100644 --- a/admin_logger.php +++ b/admin_logger.php @@ -30,9 +30,7 @@ if ($page == 'log' 'user' => $lng['logger']['user'], 'text' => $lng['logger']['action'] ); - $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); - $paging->sortfield = 'date'; - $paging->sortorder = 'desc'; + $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc'); $result_stmt = Database::query(' SELECT * FROM `' . TABLE_PANEL_LOG . '` ' . $paging->getSqlWhere(false) . ' ' . $paging->getSqlOrderBy() . ' ' . $paging->getSqlLimit() ); diff --git a/admin_phpsettings.php b/admin_phpsettings.php index 32b3a10f..c741ce54 100644 --- a/admin_phpsettings.php +++ b/admin_phpsettings.php @@ -48,7 +48,7 @@ if ($page == 'overview') { $query_params['adminid'] = $userinfo['adminid']; } - if ((int)$settings['panel']['phpconfigs_hidestdsubdomain'] == 1) { + if ((int)Settings::Get('panel.phpconfigs_hidestdsubdomain') == 1) { $ssdids_res = Database::query(" SELECT DISTINCT `standardsubdomain` FROM `".TABLE_PANEL_CUSTOMERS."` WHERE `standardsubdomain` > 0 ORDER BY `standardsubdomain` ASC;" @@ -91,7 +91,7 @@ if ($page == 'overview') { $description = validate($_POST['description'], 'description'); $phpsettings = validate(str_replace("\r\n", "\n", $_POST['phpsettings']), 'phpsettings', '/^[^\0]*$/'); - if ($settings['system']['mod_fcgid'] == 1) { + if (Settings::Get('system.mod_fcgid') == 1) { $binary = makeCorrectFile(validate($_POST['binary'], 'binary')); $file_extensions = validate($_POST['file_extensions'], 'file_extensions', '/^[a-zA-Z0-9\s]*$/'); $mod_fcgid_starter = validate($_POST['mod_fcgid_starter'], 'mod_fcgid_starter', '/^[0-9]*$/', '', array('-1', '')); @@ -101,7 +101,7 @@ if ($page == 'overview') { $fpm_reqtermtimeout = 0; $fpm_reqslowtimeout = 0; } - elseif ($settings['phpfpm']['enabled'] == 1) { + elseif (Settings::Get('phpfpm.enabled') == 1) { $fpm_enableslowlog = isset($_POST['phpfpm_enable_slowlog']) ? (int)$_POST['phpfpm_enable_slowlog'] : 0; $fpm_reqtermtimeout = validate($_POST['phpfpm_reqtermtimeout'], 'phpfpm_reqtermtimeout', '/^([0-9]+)(|s|m|h|d)$/'); $fpm_reqslowtimeout = validate($_POST['phpfpm_reqslowtimeout'], 'phpfpm_reqslowtimeout', '/^([0-9]+)(|s|m|h|d)$/'); @@ -225,7 +225,7 @@ if ($page == 'overview') { $description = validate($_POST['description'], 'description'); $phpsettings = validate(str_replace("\r\n", "\n", $_POST['phpsettings']), 'phpsettings', '/^[^\0]*$/'); - if ($settings['system']['mod_fcgid'] == 1) { + if (Settings::Get('system.mod_fcgid') == 1) { $binary = makeCorrectFile(validate($_POST['binary'], 'binary')); $file_extensions = validate($_POST['file_extensions'], 'file_extensions', '/^[a-zA-Z0-9\s]*$/'); $mod_fcgid_starter = validate($_POST['mod_fcgid_starter'], 'mod_fcgid_starter', '/^[0-9]*$/', '', array('-1', '')); @@ -235,7 +235,7 @@ if ($page == 'overview') { $fpm_reqtermtimeout = 0; $fpm_reqslowtimeout = 0; } - elseif ($settings['phpfpm']['enabled'] == 1) { + elseif (Settings::Get('phpfpm.enabled') == 1) { $fpm_enableslowlog = isset($_POST['phpfpm_enable_slowlog']) ? (int)$_POST['phpfpm_enable_slowlog'] : 0; $fpm_reqtermtimeout = validate($_POST['phpfpm_reqtermtimeout'], 'phpfpm_reqtermtimeout', '/^([0-9]+)(|s|m|h|d)$/'); $fpm_reqslowtimeout = validate($_POST['phpfpm_reqslowtimeout'], 'phpfpm_reqslowtimeout', '/^([0-9]+)(|s|m|h|d)$/'); diff --git a/admin_settings.php b/admin_settings.php index 8935789f..c71a1f89 100644 --- a/admin_settings.php +++ b/admin_settings.php @@ -245,7 +245,7 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') { "); while ($array = $result_stmt->fetch(PDO::FETCH_ASSOC)) { - $difference = $settings['system']['mail_quota'] - $array['quota']; + $difference = Settings::Get('system.mail_quota') - $array['quota']; Database::pexecute($upd_stmt, array('diff' => $difference, 'customerid' => $customerid)); } } @@ -254,11 +254,11 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') { $upd_stmt = Database::prepare(" UPDATE `" . TABLE_MAIL_USERS . "` SET `quota` = :quota "); - Database::pexecute($upd_stmt, array('quota' => $settings['system']['mail_quota'])); + Database::pexecute($upd_stmt, array('quota' => Settings::Get('system.mail_quota'))); // Update the Customer, if the used quota is bigger than the allowed quota Database::query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `email_quota` = `email_quota_used` WHERE `email_quota` < `email_quota_used`"); - $log->logAction(ADM_ACTION, LOG_WARNING, 'enforcing mailquota to all customers: ' . $settings['system']['mail_quota'] . ' MB'); + $log->logAction(ADM_ACTION, LOG_WARNING, 'enforcing mailquota to all customers: ' . Settings::Get('system.mail_quota') . ' MB'); redirectTo('admin_settings.php', array('s' => $s)); } else { diff --git a/admin_templates.php b/admin_templates.php index 1ce0f26c..e8e4e318 100644 --- a/admin_templates.php +++ b/admin_templates.php @@ -45,14 +45,14 @@ $available_templates = array( ); // only show templates of features that are enabled #1191 -if ((int)$settings['system']['report_enable'] == 1) { +if ((int)Settings::Get('system.report_enable') == 1) { array_push($available_templates, 'trafficmaxpercent', 'diskmaxpercent' ); } -if ((int)$settings['ticket']['enabled'] == 1) { +if ((int)Settings::Get('ticket.enabled') == 1) { array_push($available_templates, 'new_ticket_by_customer', 'new_ticket_for_customer', @@ -70,7 +70,7 @@ if ($action == '') { //email templates $log->logAction(ADM_ACTION, LOG_NOTICE, "viewed admin_templates"); - if ($settings['panel']['sendalternativemail'] == 1) { + if (Settings::Get('panel.sendalternativemail') == 1) { $available_templates[] = 'pop_success_alternative'; } @@ -206,7 +206,7 @@ if ($action == '') { } elseif($action == 'add') { - if ($settings['panel']['sendalternativemail'] == 1) { + if (Settings::Get('panel.sendalternativemail') == 1) { $available_templates[] = 'pop_success_alternative'; } diff --git a/admin_tickets.php b/admin_tickets.php index f38311cc..3dda9c88 100644 --- a/admin_tickets.php +++ b/admin_tickets.php @@ -67,7 +67,7 @@ if ($page == 'tickets' 'subject' => $lng['ticket']['subject'], 'lastreplier' => $lng['ticket']['lastreplier'] ); - $paging = new paging($userinfo, TABLE_PANEL_TICKETS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); + $paging = new paging($userinfo, TABLE_PANEL_TICKETS, $fields, null, null, 1, 'desc'); $result_stmt = Database::prepare(" SELECT `main`.`id`, `main`.`customerid`, ( SELECT COUNT(`sub`.`id`) @@ -179,6 +179,7 @@ if ($page == 'tickets' if (isset($_POST['send']) && $_POST['send'] == 'send' ) { + // FIXME ticket -> settings $newticket = ticket::getInstanceOf($userinfo, $settings, -1); $newticket->Set('subject', validate($_POST['subject'], 'subject'), true, false); $newticket->Set('priority', validate($_POST['priority'], 'priority'), true, false); @@ -246,9 +247,10 @@ if ($page == 'tickets' $customers.= makeoption(getCorrectFullUserDetails($row_customer) . ' (' . $row_customer['loginname'] . ')', $row_customer['customerid']); } - $priorities = makeoption($lng['ticket']['high'], '1', $settings['ticket']['default_priority']); - $priorities.= makeoption($lng['ticket']['normal'], '2', $settings['ticket']['default_priority']); - $priorities.= makeoption($lng['ticket']['low'], '3', $settings['ticket']['default_priority']); + $def_prio = Settings::Get('ticket.default_priority'); + $priorities = makeoption($lng['ticket']['high'], '1', $def_prio); + $priorities.= makeoption($lng['ticket']['normal'], '2', $def_prio); + $priorities.= makeoption($lng['ticket']['low'], '3', $def_prio); $ticket_new_data = include_once dirname(__FILE__).'/lib/formfields/admin/tickets/formfield.ticket_new.php'; $ticket_new_form = htmlform::genHTMLForm($ticket_new_data); @@ -269,7 +271,7 @@ if ($page == 'tickets' if (isset($_POST['send']) && $_POST['send'] == 'send' ) { - + // FIXME ticket -> settings $replyticket = ticket::getInstanceOf($userinfo, $settings, -1); $replyticket->Set('subject', validate($_POST['subject'], 'subject'), true, false); $replyticket->Set('priority', validate($_POST['priority'], 'priority'), true, false); @@ -279,6 +281,7 @@ if ($page == 'tickets' standard_error(array('stringisempty', 'mymessage')); } else { $now = time(); + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); $replyticket->Set('customer', $mainticket->Get('customer'), true, true); $replyticket->Set('lastchange', $now, true, true); @@ -305,6 +308,7 @@ if ($page == 'tickets' } else { $ticket_replies = ''; + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); $dt = date("d.m.Y H:i\h", $mainticket->Get('dt')); $status = ticket::getStatusText($lng, $mainticket->Get('status')); @@ -348,7 +352,7 @@ if ($page == 'tickets' $numrows_andere = Database::num_rows(); while ($row2 = $andere_stmt->fetch(PDO::FETCH_ASSOC)) { - + // FIXME ticket -> settings $subticket = ticket::getInstanceOf($userinfo, $settings, (int)$row2['id']); $lastchange = date("d.m.Y H:i\h", $subticket->Get('lastchange')); @@ -396,6 +400,7 @@ if ($page == 'tickets' && $_POST['send'] == 'send' ) { $now = time(); + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); $mainticket->Set('lastchange', $now, true, true); $mainticket->Set('lastreplier', '1', true, true); @@ -404,6 +409,7 @@ if ($page == 'tickets' $log->logAction(ADM_ACTION, LOG_NOTICE, "closed ticket '" . $mainticket->Get('subject') . "'"); redirectTo($filename, array('page' => $page, 's' => $s)); } else { + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); ask_yesno('ticket_reallyclose', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject')); } @@ -412,6 +418,7 @@ if ($page == 'tickets' && $id != 0 ) { $now = time(); + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); $mainticket->Set('lastchange', $now, true, true); $mainticket->Set('lastreplier', '1', true, true); @@ -427,6 +434,7 @@ if ($page == 'tickets' && $_POST['send'] == 'send' ) { $now = time(); + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); $mainticket->Set('lastchange', $now, true, true); $mainticket->Set('lastreplier', '1', true, true); @@ -436,6 +444,7 @@ if ($page == 'tickets' $log->logAction(ADM_ACTION, LOG_NOTICE, "archived ticket '" . $mainticket->Get('subject') . "'"); redirectTo($filename, array('page' => $page, 's' => $s)); } else { + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); ask_yesno('ticket_reallyarchive', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject')); } @@ -446,11 +455,13 @@ if ($page == 'tickets' if (isset($_POST['send']) && $_POST['send'] == 'send' ) { + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); $log->logAction(ADM_ACTION, LOG_INFO, "deleted ticket '" . $mainticket->Get('subject') . "'"); $mainticket->Delete(); redirectTo($filename, array('page' => $page, 's' => $s)); } else { + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); ask_yesno('ticket_reallydelete', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject')); } @@ -471,7 +482,7 @@ if ($page == 'tickets' if ($userinfo['tickets_see_all'] != '1') { $where = " `main`.`adminid` = :adminid"; } - $paging = new paging($userinfo, TABLE_PANEL_TICKET_CATS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); + $paging = new paging($userinfo, TABLE_PANEL_TICKET_CATS, $fields); $result_stmt = Database::prepare(" SELECT `main`.`id`, `main`.`name`, `main`.`logicalorder`, ( SELECT COUNT(`sub`.`id`) FROM `" . TABLE_PANEL_TICKETS . "` `sub` @@ -636,12 +647,10 @@ if ($page == 'tickets' $fields = array( 'lastchange' => $lng['ticket']['lastchange'], - 'ticket_answers' => $lng['ticket']['ticket_answers'], 'subject' => $lng['ticket']['subject'], - 'lastreplier' => $lng['ticket']['lastreplier'], - 'priority' => $lng['ticket']['priority'] + 'lastreplier' => $lng['ticket']['lastreplier'] ); - $paging = new paging($userinfo, TABLE_PANEL_TICKETS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']); + $paging = new paging($userinfo, TABLE_PANEL_TICKETS, $fields); $result_stmt = Database::prepare($query . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit()); Database::pexecute($result_stmt, $archive_params); $sortcode = $paging->getHtmlSortCode($lng); @@ -795,6 +804,7 @@ if ($page == 'tickets' ) { $log->logAction(ADM_ACTION, LOG_NOTICE, "viewed archived-ticket #" . $id); $ticket_replies = ''; + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); $lastchange = date("d.m.Y H:i\h", $mainticket->Get('lastchange')); $dt = date("d.m.Y H:i\h", $mainticket->Get('dt')); @@ -845,7 +855,7 @@ if ($page == 'tickets' $numrows_andere = Database::num_rows(); while ($row2 = $andere_stmt->fetch(PDO::FETCH_ASSOC)) { - + // FIXME ticket -> settings $subticket = ticket::getInstanceOf($userinfo, $settings, (int)$row2['id']); $lastchange = date("d.m.Y H:i\h", $subticket->Get('lastchange')); @@ -897,11 +907,13 @@ if ($page == 'tickets' if (isset($_POST['send']) && $_POST['send'] == 'send' ) { + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); $log->logAction(ADM_ACTION, LOG_INFO, "deleted archived ticket '" . $mainticket->Get('subject') . "'"); $mainticket->Delete(); redirectTo($filename, array('page' => $page, 's' => $s)); } else { + // FIXME ticket -> settings $mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id); ask_yesno('ticket_reallydelete', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject')); } diff --git a/admin_traffic.php b/admin_traffic.php index d6f6f7b8..7c7b974e 100644 --- a/admin_traffic.php +++ b/admin_traffic.php @@ -122,7 +122,7 @@ if ($page == 'overview' || $page == 'customers') { Database::pexecute($traffic_list_stmt, array('year' => (date("Y")-$years), 'id' => $customer_name['customerid'])); while ($traffic_month = $traffic_list_stmt->fetch(PDO::FETCH_ASSOC)) { - $virtual_host[$months[(int)$traffic_month['month']]] = size_readable($traffic_month['traffic'], 'GiB', 'bi', '%01.'.(int)$settings['panel']['decimal_places'].'f %s'); + $virtual_host[$months[(int)$traffic_month['month']]] = size_readable($traffic_month['traffic'], 'GiB', 'bi', '%01.'.(int)Settings::Get('panel.decimal_places').'f %s'); $totals[$months[(int)$traffic_month['month']]] += $traffic_month['traffic']; } eval("\$domain_list .= sprintf(\"%s\", \"" . getTemplate("traffic/index_table_row") . "\");"); @@ -132,7 +132,7 @@ if ($page == 'overview' || $page == 'customers') { 'name' => $lng['traffic']['months']['total'], ); foreach ($totals as $month => $bytes) { - $virtual_host[$month] = ($bytes == 0 ? '-' : size_readable($bytes, 'GiB', 'bi', '%01.'.(int)$settings['panel']['decimal_places'].'f %s')); + $virtual_host[$month] = ($bytes == 0 ? '-' : size_readable($bytes, 'GiB', 'bi', '%01.'.(int)Settings::Get('panel.decimal_places').'f %s')); } $customerview = 0; eval("\$total_list = sprintf(\"%s\", \"" . getTemplate("traffic/index_table_row") . "\");"); diff --git a/admin_updates.php b/admin_updates.php index 153cfe0b..02a44f16 100644 --- a/admin_updates.php +++ b/admin_updates.php @@ -27,20 +27,13 @@ if ($page == 'overview') { * so we have to set them both to run a correct upgrade */ if (!isFroxlor()) { - if (!isset($settings['panel']['version']) - || $settings['panel']['version'] == '' + if (Settings::Get('panel.version') == null + || Settings::Get('panel.version') == '' ) { - $settings['panel']['version'] = '1.4.2.1'; - $stmt = Database::prepare(" - INSERT INTO `" . TABLE_PANEL_SETTINGS . "` SET - `settinggroup` = 'panel', - `varname` = 'version', - `value` = :version" - ); - Database::pexecute($stmt, array('version' => $settings['panel']['version'])); + Settings::Set('panel.version', '1.4.2.1'); } - if (!isset($settings['system']['dbversion']) - || $settings['system']['dbversion'] == '' + if (Settings::Get('system.dbversion') == null + || Settings::Get('system.dbversion') == '' ) { /** * for syscp-stable (1.4.2.1) this value has to be 0 @@ -54,9 +47,9 @@ if ($page == 'overview') { $result = $result_stmt->fetch(PDO::FETCH_ASSOC); if (isset($result['value'])) { - $settings['system']['dbversion'] = (int)$result['value']; + Settings::Set('system.dbversion', (int)$result['value'], false); } else { - $settings['system']['dbversion'] = 0; + Settings::Set('system.dbversion', 0, false); } } } @@ -91,7 +84,7 @@ if ($page == 'overview') { } if (!$successful_update) { - $current_version = $settings['panel']['version']; + $current_version = Settings::Get('panel.version'); $new_version = $version; $ui_text = $lng['update']['update_information']['part_a']; diff --git a/lib/classes/database/class.DbManager.php b/lib/classes/database/class.DbManager.php index e0d7a700..23a9e5ad 100644 --- a/lib/classes/database/class.DbManager.php +++ b/lib/classes/database/class.DbManager.php @@ -32,12 +32,6 @@ */ class DbManager { - /** - * Settings array - * @var array - */ - private $_settings = null; - /** * FroxlorLogger object * @var object @@ -53,11 +47,9 @@ class DbManager { /** * main constructor * - * @param array $settings * @param FroxlorLogger $log */ - public function __construct($settings, &$log = null) { - $this->_settings = $settings; + public function __construct(&$log = null) { $this->_log = $log; $this->_setManager(); } @@ -79,7 +71,7 @@ class DbManager { Database::needRoot(true); // check whether we shall create a random username - if (strtoupper($this->_settings['customer']['mysqlprefix']) == 'RANDOM') { + if (strtoupper(Settings::Get('customer.mysqlprefix')) == 'RANDOM') { // get all usernames from db-manager $allsqlusers = $this->getManager()->getAllSqlUsers(); // generate random username @@ -89,7 +81,7 @@ class DbManager { $username = $loginname . '-' . substr(md5(uniqid(microtime(), 1)), 20, 3); } } else { - $username = $loginname . $this->_settings['customer']['mysqlprefix'] . (intval($last_accnumber) + 1); + $username = $loginname . Settings::Get('customer.mysqlprefix') . (intval($last_accnumber) + 1); } // now create the database itself @@ -97,7 +89,7 @@ class DbManager { $this->_log->logAction(USR_ACTION, LOG_INFO, "created database '" . $username . "'"); // and give permission to the user on every access-host we have - foreach (array_map('trim', explode(',', $this->_settings['system']['mysql_access_host'])) as $mysql_access_host) { + foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) { $this->getManager()->grantPrivilegesTo($username, $password, $mysql_access_host); $this->_log->logAction(USR_ACTION, LOG_NOTICE, "grant all privileges for '" . $username . "'@'" . $mysql_access_host . "'"); } @@ -125,6 +117,6 @@ class DbManager { */ private function _setManager() { // TODO read different dbms from settings later - $this->_manager = new DbManagerMySQL($this->_settings, $this->_log); + $this->_manager = new DbManagerMySQL($this->_log); } } \ No newline at end of file diff --git a/lib/classes/database/manager/class.DbManagerMySQL.php b/lib/classes/database/manager/class.DbManagerMySQL.php index ddf2cb5c..805e4f50 100644 --- a/lib/classes/database/manager/class.DbManagerMySQL.php +++ b/lib/classes/database/manager/class.DbManagerMySQL.php @@ -32,12 +32,6 @@ */ class DbManagerMySQL { - /** - * Settings array - * @var array - */ - private $_settings = null; - /** * FroxlorLogger object * @var object @@ -47,11 +41,9 @@ class DbManagerMySQL { /** * main constructor * - * @param array $settings * @param FroxlorLogger $log */ - public function __construct($settings, &$log = null) { - $this->_settings = $settings; + public function __construct(&$log = null) { $this->_log = $log; } diff --git a/lib/classes/output/class.paging.php b/lib/classes/output/class.paging.php index 48c193e9..54fb352f 100644 --- a/lib/classes/output/class.paging.php +++ b/lib/classes/output/class.paging.php @@ -27,67 +27,67 @@ class paging { * Userinfo * @var array */ - var $userinfo = array(); + private $userinfo = array(); /** * MySQL-Table * @var string */ - var $table = ''; + private $table = ''; /** * Fields with description which should be selectable * @var array */ - var $fields = array(); + private $fields = array(); /** * Entries per page * @var int */ - var $entriesperpage = 0; + private $entriesperpage = 0; /** * Number of entries of table * @var int */ - var $entries = 0; + private $entries = 0; /** * Sortorder, asc or desc * @var string */ - var $sortorder = 'asc'; + public $sortorder = 'asc'; /** * Sortfield * @var string */ - var $sortfield = ''; + public $sortfield = ''; /** * Searchfield * @var string */ - var $searchfield = ''; + private $searchfield = ''; /** * Searchtext * @var string */ - var $searchtext = ''; + private $searchtext = ''; /** * Pagenumber * @var int */ - var $pageno = 0; + private $pageno = 0; /** * Switch natsorting on/off * @var bool */ - var $natSorting = false; + private $natSorting = false; /** * Class constructor. Loads settings from request or from userdata and saves them to session. @@ -95,10 +95,19 @@ class paging { * @param array userinfo * @param string Name of Table * @param array Fields, in format array( 'fieldname_in_mysql' => 'field_caption' ) - * @param int entries per page - * @param bool Switch natsorting on/off (global, affects all calls of sort) + * @param int *deprecated* entries per page + * @param bool *deprecated* Switch natsorting on/off (global, affects all calls of sort) + * @param int $default_field default sorting-field-index + * @param string $default_order default sorting order 'asc' or 'desc' + * */ - function paging($userinfo, $table, $fields, $entriesperpage, $natSorting = false) { + public function __construct($userinfo, $table, $fields, $entriesperpage = 0, $natSorting = false, $default_field = 0, $default_order = 'asc') { + + // entries per page and natsorting-flag are not + // passed as parameter anymore, because these are + // from the settings anyway + $entriesperpage = Settings::Get('panel.paging'); + $natSorting = Settings::Get('panel.natsorting'); $this->userinfo = $userinfo; @@ -129,7 +138,7 @@ class paging { $this->sortorder = strtolower($this->userinfo['lastpaging']['sortorder']); } else { - $this->sortorder = 'asc'; + $this->sortorder = $default_order; } } @@ -147,7 +156,7 @@ class paging { $this->sortfield = $this->userinfo['lastpaging']['sortfield']; } else { $fieldnames = array_keys($fields); - $this->sortfield = $fieldnames[0]; + $this->sortfield = $fieldnames[$default_field]; } } @@ -228,7 +237,7 @@ class paging { * * @param int entries */ - function setEntries($entries) { + public function setEntries($entries) { $this->entries = $entries; @@ -245,7 +254,7 @@ class paging { * @param int number of row * @return bool to display or not to display, that's the question */ - function checkDisplay($count) { + public function checkDisplay($count) { $begin = (intval($this->pageno) - 1) * intval($this->entriesperpage); $end = (intval($this->pageno) * intval($this->entriesperpage)); return (($count >= $begin && $count < $end) || $this->entriesperpage == 0); @@ -257,7 +266,7 @@ class paging { * @param bool should returned condition code start with WHERE (false) or AND (true)? * @return string the condition code */ - function getSqlWhere($append = false) { + public function getSqlWhere($append = false) { if ($this->searchtext != '') { if ($append == true) { $condition = ' AND '; @@ -326,7 +335,7 @@ class paging { * @param bool Switch natsorting on/off (local, affects just this call) * @return string the "order by"-code */ - function getSqlOrderBy($natSorting = null) { + public function getSqlOrderBy($natSorting = null) { $sortfield = explode('.', $this->sortfield); foreach ($sortfield as $id => $field) { @@ -366,7 +375,7 @@ class paging { * * @return string always empty */ - function getSqlLimit() { + public function getSqlLimit() { /** * currently not in use */ @@ -379,7 +388,7 @@ class paging { * @param array Language array * @return string the html sortcode */ - function getHtmlSortCode($lng, $break = false) { + public function getHtmlSortCode($lng, $break = false) { $sortcode = ''; $fieldoptions = ''; @@ -405,7 +414,7 @@ class paging { * @param string If set, only this field will be returned * @return mixed An array or a string (if field is set) of html code of arrows */ - function getHtmlArrowCode($baseurl, $field = '') { + public function getHtmlArrowCode($baseurl, $field = '') { global $theme; @@ -433,7 +442,7 @@ class paging { * @param array Language array * @return string the html searchcode */ - function getHtmlSearchCode($lng) { + public function getHtmlSearchCode($lng) { $searchcode = ''; $fieldoptions = ''; @@ -451,7 +460,7 @@ class paging { * @param string URL to use as base for links * @return string the html pagingcode */ - function getHtmlPagingCode($baseurl) { + public function getHtmlPagingCode($baseurl) { if ($this->entriesperpage == 0) { return ''; } else { diff --git a/lib/classes/settings/class.Settings.php b/lib/classes/settings/class.Settings.php new file mode 100644 index 00000000..1d421506 --- /dev/null +++ b/lib/classes/settings/class.Settings.php @@ -0,0 +1,205 @@ + + * @author Froxlor team (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Classes + * + * @since 0.9.31 + * + */ + +/** + * Class Settings + * + * Interaction with settings from the db + * + * @copyright (c) the authors + * @author Michael Kaufmann + * @author Froxlor team (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Classes + */ +class Settings { + + /** + * current settings object + * + * @var object + */ + private static $_obj = null; + + /** + * settings data + * + * @var array + */ + private static $_data = null; + + /** + * changed and unsaved settings data + * + * @var array + */ + private static $_updatedata = null; + + /** + * prepared statement for updating the + * settings table + * + * @var PDOStatement + */ + private static $_updstmt = null; + + /** + * private constructor, reads in all settings + */ + private function __construct() { + $this->_readSettings(); + self::$_updatedata = array(); + // prepare statement + self::$_updstmt = Database::prepare(" + UPDATE `".TABLE_PANEL_SETTINGS."` SET `value` = :value + WHERE `settinggroup` = :group AND `varname` = :varname + "); + } + + /** + * Read in all settings from the database + * and set the internal $_data array + */ + private function _readSettings() { + $settings_data = loadConfigArrayDir('actions/admin/settings/'); + self::$_data = loadSettings($settings_data); + } + + /** + * update a value in the database + * + * @param string $group + * @param string $varname + * @param string $value + */ + private function _storeSetting($group = null, $varname = null, $value = null) { + $upd_data = array( + 'group' => $group, + 'varname' => $varname, + 'value' => $value + ); + Database::pexecute(self::$_updstmt, $upd_data); + } + + /** + * return a setting-value by its group and varname + * + * @param string $setting a group and a varname separated by a dot (group.varname) + * + * @return mixed + */ + public function pGet($setting = null) { + $sstr = explode(".", $setting); + // no separator - do'h + if (!isset($sstr[1])) { + return null; + } + $result = null; + if (isset(self::$_data[$sstr[0]][$sstr[1]])) { + $result = self::$_data[$sstr[0]][$sstr[1]]; + } + return $result; + } + + /** + * update a setting / set a new value + * + * @param string $setting a group and a varname separated by a dot (group.varname) + * @param string $value + * @param boolean $instant_save + */ + public function pSet($setting = null, $value = null, $instant_save = true) { + // check whether the setting exists + if (Settings::Get($setting) !== null) { + // set new value in array + $sstr = explode(".", $setting); + self::$_data[$sstr[0]][$sstr[1]] = $value; + // should we store to db instantly? + if ($instant_save) { + $this->_storeSetting($sstr[0], $sstr[1], $value); + } else { + if (!is_array(self::$_data[$sstr[0]])) { + self::$_data[$sstr[0]] = array(); + } + self::$_data[$sstr[0]][$sstr[1]] = $value; + } + } + } + + /** + * Store all un-saved changes to the database and + * re-read in all settings + */ + public function pFlush() { + if (is_array(self::$_updatedata) && count(self::$_updatedata) > 0) { + // save all un-saved changes to the settings + foreach ($self::$_updatedata as $group => $vargroup) { + foreach ($vargroup as $varname => $value) { + $this->_storeSetting($group, $varname, $value); + } + } + // now empty the array + self::$_updatedata = array(); + // re-read in all settings + $this->_readSettings(); + } + } + + /** + * forget all un-saved changes to settings + */ + public function pStash() { + // empty update array + self::$_updatedata = array(); + } + + /** + * create new object and return instance + * + * @return object + */ + private static function getInstance() { + // do we got an object already? + if (self::$_obj == null) { + self::$_obj = new self(); + } + // return it + return self::$_obj; + } + + /** + * let's us interact with the settings-Object by using static + * call like "Settings::function()" + * + * @param string $name + * @param mixed $args + * + * @return mixed + */ + public static function __callStatic($name, $args) { + // as our functions are not static and therefore cannot + // be called statically, we prefix a 'p' to all of + // our public functions so we can use Settings::functionname() + // which looks cooler and is easier to use + $callback = array(self::getInstance(), "p".$name); + $result = call_user_func_array($callback, $args); + return $result; + } +} diff --git a/lib/functions/database/function.correctMysqlUsers.php b/lib/functions/database/function.correctMysqlUsers.php index a3a2ce83..7db4212e 100644 --- a/lib/functions/database/function.correctMysqlUsers.php +++ b/lib/functions/database/function.correctMysqlUsers.php @@ -19,7 +19,7 @@ function correctMysqlUsers($mysql_access_host_array) { - global $settings, $log; + global $log; // get sql-root access data Database::needRoot(true); @@ -36,7 +36,7 @@ function correctMysqlUsers($mysql_access_host_array) { Database::needSqlData(); $sql_root = Database::getSqlData(); - $dbm = new DbManager($settings, $log); + $dbm = new DbManager($log); $users = $dbm->getManager()->getAllSqlUsers(false); $databases = array( diff --git a/lib/functions/froxlor/function.updateFunctions.php b/lib/functions/froxlor/function.updateFunctions.php index 2ef1d9e4..138567d3 100644 --- a/lib/functions/froxlor/function.updateFunctions.php +++ b/lib/functions/froxlor/function.updateFunctions.php @@ -21,21 +21,19 @@ * updates the panel.version field * to the given value (no checks here!) * - * @param string new-version + * @param string $new_version new-version * - * @return bool true on success, else false + * @return bool true on success, else false */ function updateToVersion($new_version = null) { - global $settings; - if ($new_version !== null && $new_version != '') { $upd_stmt = Database::prepare(" UPDATE `".TABLE_PANEL_SETTINGS."` SET `value` = :newversion WHERE `settinggroup` = 'panel' AND `varname` = 'version'" ); Database::pexecute($upd_stmt, array('newversion' => $new_version)); - $settings['panel']['version'] = $new_version; + Settings::Set('panel.version', $new_version); return true; } return false; @@ -46,13 +44,12 @@ function updateToVersion($new_version = null) { * * checks if the panel is froxlor * - * @return bool true if panel is froxlor, else false + * @return bool true if panel is froxlor, else false */ function isFroxlor() { - global $settings; - if (isset($settings['panel']['frontend']) - && $settings['panel']['frontend'] == 'froxlor' + if (Settings::Get('panel.frontend') !== null + && Settings::Get('panel.frontend') == 'froxlor' ) { return true; } @@ -65,16 +62,14 @@ function isFroxlor() { * checks if a given version is the * current one (and panel is froxlor) * - * @param string version to check + * @param string $to_check version to check * - * @return bool true if version to check matches, else false + * @return bool true if version to check matches, else false */ function isFroxlorVersion($to_check = null) { - global $settings; - - if ($settings['panel']['frontend'] == 'froxlor' - && $settings['panel']['version'] == $to_check + if (Settings::Get('panel.frontend') == 'froxlor' + && Settings::Get('panel.version') == $to_check ) { return true; } @@ -82,21 +77,18 @@ function isFroxlorVersion($to_check = null) { } /** - * Function isFroxlorVersion + * Function hasUpdates * - * checks if a given version is the - * current one (and panel is froxlor) + * checks if a given version is not equal the current one * - * @param string version to check + * @param string $to_check version to check * - * @return bool true if version to check matches, else false + * @return bool true if version to check does not match, else false */ function hasUpdates($to_check = null) { - global $settings; - - if (!isset($settings['panel']['version']) - || $settings['panel']['version'] != $to_check + if (Settings::Get('panel.version') == null + || Settings::Get('panel.version') != $to_check ) { return true; }