Skip to content

Commit

Permalink
Removed indexed array option for get_domain_default_props() function …
Browse files Browse the repository at this point in the history
…to avoid usage of list()
  • Loading branch information
nuxwin committed Oct 11, 2012
1 parent 2e66423 commit d6c62a7
Show file tree
Hide file tree
Showing 31 changed files with 106 additions and 247 deletions.
38 changes: 5 additions & 33 deletions gui/library/client-functions.php
Expand Up @@ -37,46 +37,18 @@
* Note: For performance reasons, the data are retrieved once per request.
*
* @param int $domainAdminId User unique identifier
* @param bool $returnWKeys Tells whether or not return value should be a
* associative array
* @return array If $returnWkeys is TRUE, returns an associative array
* where each key is a domain propertie name. Otherwise
* returns an indexed array where each value correspond
* to a propertie value, following the columns order in
* database table.
* @todo Remove indexed array option to avoid using PHP list() function
* @return array Returns an associative array where each key is a domain propertie name.
*/
function get_domain_default_props($domainAdminId, $returnWKeys = false)
function get_domain_default_props($domainAdminId)
{
static $domainProperties = null;

if (null === $domainProperties) {
$query = "
SELECT
`domain_id`, `domain_name`, `domain_gid`, `domain_uid`,
`domain_created_id`, `domain_created`, `domain_expires`,
`domain_last_modified`, `domain_mailacc_limit`, `domain_ftpacc_limit`,
`domain_traffic_limit`, `domain_sqld_limit`, `domain_sqlu_limit`,
`domain_status`, `domain_alias_limit`, `domain_subd_limit`,
`domain_ip_id`, `domain_disk_limit`, `domain_disk_usage`,
`domain_php`, `domain_cgi`, `allowbackup`, `domain_dns`,
`domain_software_allowed`, `phpini_perm_system`,
`phpini_perm_allow_url_fopen`, `phpini_perm_display_errors`,
`phpini_perm_disable_functions`, `domain_external_mail`
FROM
`domain`
WHERE
`domain_admin_id` = ?
";
$stmt = exec_query($query, $domainAdminId);
$stmt = exec_query("SELECT * FROM `domain` WHERE `domain_admin_id` = ?", $domainAdminId);
$domainProperties = $stmt->fields;
}

if ($returnWKeys) {
return $domainProperties;
} else {
return array_values($domainProperties);
}
return $domainProperties;
}

/**
Expand Down Expand Up @@ -749,7 +721,7 @@ function customerHasFeature($featureNames, $forceReload = false)
/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');
$debug = (bool) $cfg->DEBUG;
$dmnProps = get_domain_default_props((int)$_SESSION['user_id'], true);
$dmnProps = get_domain_default_props((int)$_SESSION['user_id']);

$availableFeatures = array(
'domain' => ($dmnProps['domain_alias_limit'] != '-1'
Expand Down
2 changes: 1 addition & 1 deletion gui/library/iMSCP/View/Helpers/Functions/Common.php
Expand Up @@ -297,7 +297,7 @@ function generateNavigation($tpl)
// Dynamic links (only at customer level)
if (isset($_SESSION['user_type']) && $_SESSION['user_type'] == 'user') {

$domainProperties = get_domain_default_props($_SESSION['user_id'], true);
$domainProperties = get_domain_default_props($_SESSION['user_id']);

$tpl->assign(array(
'FILEMANAGER_PATH' => $cfg->FILEMANAGER_PATH,
Expand Down
2 changes: 1 addition & 1 deletion gui/library/iMSCP/View/Helpers/Functions/User.php
Expand Up @@ -233,7 +233,7 @@ function gen_client_menu($tpl, $menuTemplateFile)
}

// Getting domain properties
$domainProperties = get_domain_default_props($_SESSION['user_id'], true);
$domainProperties = get_domain_default_props($_SESSION['user_id']);

if (customerHasFeature('awstats')) {
$tpl->assign(array(
Expand Down
2 changes: 1 addition & 1 deletion gui/public/admin/domain_details.php
Expand Up @@ -58,7 +58,7 @@ function admin_generatePage($tpl, $domainId)
redirectTo('manage_users.php');
}

$domainProperties = get_domain_default_props($stmt->fields['domain_admin_id'], true);
$domainProperties = get_domain_default_props($stmt->fields['domain_admin_id']);

/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');
Expand Down
8 changes: 3 additions & 5 deletions gui/public/client/alias_add.php
Expand Up @@ -46,12 +46,10 @@
*/
function check_client_domainalias_counts($user_id)
{
$domainProperties = get_domain_default_props($user_id, true);
$domainProperties = get_domain_default_props($user_id);
$domainAliasesUsage = get_domain_running_als_cnt($domainProperties['domain_id']);

if ($domainProperties['domain_alias_limit'] != 0 &&
$domainAliasesUsage >= $domainProperties['domain_alias_limit']
) {
if ($domainProperties['domain_alias_limit'] != 0 && $domainAliasesUsage >= $domainProperties['domain_alias_limit']) {
set_page_message(tr('You reached your domain aliases limit.'), 'error');
redirectTo('domains_manage.php');
}
Expand Down Expand Up @@ -402,7 +400,7 @@ function add_domain_alias()
generateNavigation($tpl);
}

$domainProperties = get_domain_default_props($_SESSION['user_id'], true);
$domainProperties = get_domain_default_props($_SESSION['user_id']);
$currentNumberDomainAliases = get_domain_running_als_cnt($domainProperties['domain_id']);

/**
Expand Down
4 changes: 3 additions & 1 deletion gui/public/client/alias_edit.php
Expand Up @@ -132,7 +132,9 @@ function gen_editalias_page(&$tpl, $edit_id) {
$cfg = iMSCP_Registry::get('config');

// Get data from sql
list($domain_id) = get_domain_default_props($_SESSION['user_id']);
$domainProps = get_domain_default_props($_SESSION['user_id']);
$domain_id = $domainProps['domain_id'];

$res = exec_query("SELECT * FROM `domain_aliasses` WHERE `alias_id` = ? AND `domain_id` = ?", array($edit_id, $domain_id));

if ($res->recordCount() <= 0) {
Expand Down
10 changes: 6 additions & 4 deletions gui/public/client/dns_edit.php
Expand Up @@ -260,9 +260,10 @@ function gen_editdns_page($tpl, $edit_id) {
/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');

list(
$dmn_id, $dmn_name,,,,,,,,,,,,,,,,,,,,,$dmn_dns
) = get_domain_default_props($_SESSION['user_id']);
$domainProps = get_domain_default_props($_SESSION['user_id']);
$dmn_id = $domainProps['domain_id'];
$dmn_name = $domainProps['domain_name'];
$dmn_dns = $domainProps['domain_dns'];

if ($dmn_dns != 'yes') {
not_allowed();
Expand Down Expand Up @@ -577,7 +578,8 @@ function check_fwd_data($tpl, $edit_id) {
$_class = $_POST['class'];
$_type = $_POST['type'];

list($dmn_id) = get_domain_default_props($_SESSION['user_id']);
$domainProps = get_domain_default_props($_SESSION['user_id']);
$dmn_id = $domainProps['domain_id'];
if ($add_mode) {
$query = "
SELECT
Expand Down
3 changes: 2 additions & 1 deletion gui/public/client/ftp_accounts.php
Expand Up @@ -47,7 +47,8 @@
*/
function gen_page_ftp_list($tpl)
{
list(,$dmn_name) = get_domain_default_props($_SESSION['user_id']);
$domainProps = get_domain_default_props($_SESSION['user_id']);
$dmn_name = $domainProps['domain_name'];

$query = "
SELECT
Expand Down
84 changes: 11 additions & 73 deletions gui/public/client/ftp_add.php
Expand Up @@ -257,30 +257,10 @@ function get_ftp_user_gid($dmn_name, $ftp_user) {
$rs = exec_query($query, $dmn_name);

if ($rs->recordCount() == 0) { // there is no such group. we'll need a new one.
list($temp_dmn_id,
$temp_dmn_name,
$temp_dmn_gid,
$temp_dmn_uid,
$temp_dmn_created_id,
$temp_dmn_created,
$temp_dmn_expires,
$temp_dmn_last_modified,
$temp_dmn_mailacc_limit,
$temp_dmn_ftpacc_limit,
$temp_dmn_traff_limit,
$temp_dmn_sqld_limit,
$temp_dmn_sqlu_limit,
$temp_dmn_status,
$temp_dmn_als_limit,
$temp_dmn_subd_limit,
$temp_dmn_ip_id,
$temp_dmn_disk_limit,
$temp_dmn_disk_usage,
$temp_dmn_php,
$temp_dmn_cgi,
$allowbackup,
$dmn_dns
) = get_domain_default_props($_SESSION['user_id']);
$domainProps = get_domain_default_props($_SESSION['user_id']);
$temp_dmn_name = $domainProps['domain_name'];
$temp_dmn_gid = $domainProps['domain_gid'];
$temp_dmn_disk_limit = $domainProps['domain_disk_limit'];

$query = "
INSERT INTO ftp_group
Expand Down Expand Up @@ -366,30 +346,8 @@ function get_ftp_user_uid($dmn_name, $ftp_user, $ftp_user_gid) {
return -1;
}

list($temp_dmn_id,
$temp_dmn_name,
$temp_dmn_gid,
$temp_dmn_uid,
$temp_dmn_created_id,
$temp_dmn_created,
$temp_dmn_expires,
$temp_dmn_last_modified,
$temp_dmn_mailacc_limit,
$temp_dmn_ftpacc_limit,
$temp_dmn_traff_limit,
$temp_dmn_sqld_limit,
$temp_dmn_sqlu_limit,
$temp_dmn_status,
$temp_dmn_als_limit,
$temp_dmn_subd_limit,
$temp_dmn_ip_id,
$temp_dmn_disk_limit,
$temp_dmn_disk_usage,
$temp_dmn_php,
$temp_dmn_cgi,
$allowbackup,
$dmn_dns
) = get_domain_default_props($_SESSION['user_id']);
$domainProps = get_domain_default_props($_SESSION['user_id']);
$temp_dmn_uid = $domainProps['domain_uid'];

return $temp_dmn_uid;
}
Expand Down Expand Up @@ -481,7 +439,7 @@ function add_ftp_user($dmn_name)
exec_query($query, array($ftp_user, $ftp_passwd, $ftp_rawpasswd, $ftp_uid, $ftp_gid, $ftp_shell, $ftp_home));

$domain_props = get_domain_default_props($_SESSION['user_id']);
update_reseller_c_props($domain_props[4]);
update_reseller_c_props($domain_props['domain_created_id']);

iMSCP_Events_Manager::getInstance()->dispatch(iMSCP_Events::onAfterAddFtp);

Expand Down Expand Up @@ -551,30 +509,10 @@ function check_ftp_acc_data($tpl, $dmn_id, $dmn_name) {
* @return void
*/
function gen_page_ftp_acc_props($tpl, $user_id) {
list($dmn_id,
$dmn_name,
$dmn_gid,
$dmn_uid,
$dmn_created_id,
$dmn_created,
$dmn_expires,
$dmn_last_modified,
$dmn_mailacc_limit,
$dmn_ftpacc_limit,
$dmn_traff_limit,
$dmn_sqld_limit,
$dmn_sqlu_limit,
$dmn_status,
$dmn_als_limit,
$dmn_subd_limit,
$dmn_ip_id,
$dmn_disk_limit,
$dmn_disk_usage,
$dmn_php,
$dmn_cgi,
$allowbackup,
$dmn_dns
) = get_domain_default_props($user_id);
$domainProps = get_domain_default_props($user_id);
$dmn_id = $domainProps['domain_id'];
$dmn_name = $domainProps['domain_name'];
$dmn_ftpacc_limit = $domainProps['domain_ftpacc_limit'];

list($ftp_acc_cnt, $dmn_ftp_acc_cnt, $sub_ftp_acc_cnt, $als_ftp_acc_cnt) = get_domain_running_ftp_acc_cnt($dmn_id);

Expand Down
2 changes: 1 addition & 1 deletion gui/public/client/ftp_delete.php
Expand Up @@ -133,7 +133,7 @@
$rs = exec_query($query, $ftp_id);

$domain_props = get_domain_default_props($_SESSION['user_id']);
update_reseller_c_props($domain_props[4]);
update_reseller_c_props($domain_props['domain_created_id']);

iMSCP_Events_Manager::getInstance()->dispatch(iMSCP_Events::onAfterDeleteFtp, array('ftpid' => $ftp_id));

Expand Down
4 changes: 2 additions & 2 deletions gui/public/client/hosting_plan_update.php
Expand Up @@ -73,7 +73,7 @@ function client_generateHostingPlanEntries($tpl, $customerId)
/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');

$domainProperties = get_domain_default_props($_SESSION['user_id'], true);
$domainProperties = get_domain_default_props($_SESSION['user_id']);

//$availabe_order = 0;
$hpTitle = tr('Hosting plans available for update');
Expand Down Expand Up @@ -383,7 +383,7 @@ function client_addNewOrder($orderId, $customerId)
/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');

$domainProperties = get_domain_default_props($customerId, true);
$domainProperties = get_domain_default_props($customerId);

$query = "SELECT * FROM `hosting_plans` WHERE `id` = ?";
$stmt = exec_query($query, $orderId);
Expand Down
8 changes: 4 additions & 4 deletions gui/public/client/index.php
Expand Up @@ -179,7 +179,7 @@ function client_generateFeatureStatus($tpl)
);

if (customerHasFeature('backup')) {
$domainProperties = get_domain_default_props($_SESSION['user_id'], true);
$domainProperties = get_domain_default_props($_SESSION['user_id']);

// Backup feature for customer can also be disabled by reseller via GUI
switch ($domainProperties['allowbackup']) {
Expand Down Expand Up @@ -211,7 +211,7 @@ function client_generateFeatureStatus($tpl)
*/
function client_makeTrafficUsage($domainId)
{
$domainProperties = get_domain_default_props($_SESSION['user_id'], true);
$domainProperties = get_domain_default_props($_SESSION['user_id']);
$fdofmnth = mktime(0, 0, 0, date('m'), 1, date('Y'));
$ldofmnth = mktime(1, 0, 0, date('m') + 1, 0, date('Y'));

Expand Down Expand Up @@ -279,7 +279,7 @@ function client_generateDomainExpiresInformation($tpl)
{
/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');
$domainProperties = get_domain_default_props($_SESSION['user_id'], true);
$domainProperties = get_domain_default_props($_SESSION['user_id']);

if ($domainProperties['domain_expires'] != 0) {
$domainRemainingTime = '';
Expand Down Expand Up @@ -348,7 +348,7 @@ function client_generateDomainExpiresInformation($tpl)
client_generateDomainExpiresInformation($tpl);
client_generateFeatureStatus($tpl);

$domainProperties = get_domain_default_props($_SESSION['user_id'], true);
$domainProperties = get_domain_default_props($_SESSION['user_id']);

list(
$domainTrafficPercent, $domainTrafficUsage
Expand Down
6 changes: 4 additions & 2 deletions gui/public/client/mail_accounts.php
Expand Up @@ -819,8 +819,10 @@ function gen_page_lists($tpl, $user_id) {
/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');

list($domainId,$dmn_name,,,,,,,$dmn_mailacc_limit
) = get_domain_default_props($user_id);
$domainProps = get_domain_default_props($user_id);
$domainId = $domainProps['domain_id'];
$dmn_name = $domainProps['domain_name'];
$dmn_mailacc_limit = $domainProps['domain_mailacc_limit'];

$dmn_mails = gen_page_dmn_mail_list($tpl, $domainId, $dmn_name);
$sub_mails = gen_page_sub_mail_list($tpl, $domainId, $dmn_name);
Expand Down
29 changes: 5 additions & 24 deletions gui/public/client/mail_add.php
Expand Up @@ -615,30 +615,11 @@ function check_mail_acc_data($dmn_id, $dmn_name) {
* @return void
*/
function gen_page_mail_acc_props($tpl, $user_id) {
list($dmn_id,
$dmn_name,
$dmn_gid,
$dmn_uid,
$dmn_created_id,
$dmn_created,
$dmn_expires,
$dmn_last_modified,
$dmn_mailacc_limit,
$dmn_ftpacc_limit,
$dmn_traff_limit,
$dmn_sqld_limit,
$dmn_sqlu_limit,
$dmn_status,
$dmn_als_limit,
$dmn_subd_limit,
$dmn_ip_id,
$dmn_disk_limit,
$dmn_disk_usage,
$dmn_php,
$dmn_cgi,
$allowbackup,
$dmn_dns
) = get_domain_default_props($user_id);

$domainProps = get_domain_default_props($user_id);
$dmn_id = $domainProps['domain_id'];
$dmn_name = $domainProps['domain_name'];
$dmn_mailacc_limit = $domainProps['domain_mailacc_limit'];

list($mail_acc_cnt,
$dmn_mail_acc_cnt,
Expand Down

0 comments on commit d6c62a7

Please sign in to comment.