From 620a22bf3ec8240b578e9d0366847aec5d372428 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 20 Nov 2019 09:33:28 +0100 Subject: [PATCH] fix listing of subdomains for customers, fixes #759 Signed-off-by: Michael Kaufmann --- customer_domains.php | 44 +++++++++---------------- lib/Froxlor/Api/ApiCommand.php | 10 ++++-- lib/Froxlor/Api/Commands/SubDomains.php | 5 +-- lib/Froxlor/UI/Pagination.php | 13 ++++++-- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/customer_domains.php b/customer_domains.php index 43e0a819..ad531c1f 100644 --- a/customer_domains.php +++ b/customer_domains.php @@ -71,19 +71,24 @@ if ($page == 'overview') { if ($row['parentdomainid'] == '0' && $row['caneditdomain'] == '1') { $parentdomains_count ++; } - $domain_array[$row['parentdomainid']][] = $row; + $domain_array[$row['parentdomainname']][] = $row; } - if (isset($domain_array[0])) { - foreach ($domain_array[0] as $pdomain) { - // PARENTDOMAIN - $row = \Froxlor\PhpHelper::htmlentitiesArray($pdomain); - if (Settings::Get('system.awstats_enabled') == '1') { - $statsapp = 'awstats'; - } else { - $statsapp = 'webalizer'; - } - eval("\$domains.=\"" . \Froxlor\UI\Template::getTemplate("domains/domains_delimiter") . "\";"); + foreach ($domain_array as $parentdomain => $sdomains) { + // PARENTDOMAIN + if (Settings::Get('system.awstats_enabled') == '1') { + $statsapp = 'awstats'; + } else { + $statsapp = 'webalizer'; + } + $row = [ + 'domain' => $idna_convert->decode($parentdomain) + ]; + eval("\$domains.=\"" . \Froxlor\UI\Template::getTemplate("domains/domains_delimiter") . "\";"); + + foreach ($sdomains as $domain) { + $row = \Froxlor\PhpHelper::htmlentitiesArray($domain); + // show docroot nicely if (strpos($row['documentroot'], $userinfo['documentroot']) === 0) { $row['documentroot'] = \Froxlor\FileDir::makeCorrectDir(str_replace($userinfo['documentroot'], "/", $row['documentroot'])); @@ -94,23 +99,6 @@ if ($page == 'overview') { $show_ssledit = true; } eval("\$domains.=\"" . \Froxlor\UI\Template::getTemplate("domains/domains_domain") . "\";"); - - // every domain below the parentdomain - if (isset($domain_array[$pdomain['id']])) { - $mydomains = $domain_array[$pdomain['id']]; - foreach ($mydomains as $row) { - // show docroot nicely - if (strpos($row['documentroot'], $userinfo['documentroot']) === 0) { - $row['documentroot'] = \Froxlor\FileDir::makeCorrectDir(str_replace($userinfo['documentroot'], "/", $row['documentroot'])); - } - // get ssl-ips if activated - $show_ssledit = false; - if (Settings::Get('system.use_ssl') == '1' && \Froxlor\Domain\Domain::domainHasSslIpPort($row['id']) && $row['caneditdomain'] == '1' && $row['letsencrypt'] == 0) { - $show_ssledit = true; - } - eval("\$domains.=\"" . \Froxlor\UI\Template::getTemplate("domains/domains_domain") . "\";"); - } - } } } diff --git a/lib/Froxlor/Api/ApiCommand.php b/lib/Froxlor/Api/ApiCommand.php index b0d6a0be..1f67a7a4 100644 --- a/lib/Froxlor/Api/ApiCommand.php +++ b/lib/Froxlor/Api/ApiCommand.php @@ -331,15 +331,21 @@ abstract class ApiCommand extends ApiParameter * * @param array $sql_orderby * optional array with index = fieldname and value = ASC|DESC + * @param boolean $append + * optional append to ORDER BY clause rather then create new one, default false [internal] * * @return string */ - protected function getOrderBy() + protected function getOrderBy($append = false) { $orderby = $this->getParam('sql_orderby', true, array()); $order = ""; if (! empty($orderby)) { - $order .= " ORDER BY "; + if ($append) { + $order .= ", "; + } else { + $order .= " ORDER BY "; + } foreach ($orderby as $field => $by) { $sortfield = explode('.', $field); foreach ($sortfield as $id => $sfield) { diff --git a/lib/Froxlor/Api/Commands/SubDomains.php b/lib/Froxlor/Api/Commands/SubDomains.php index d773e992..9a2a954a 100644 --- a/lib/Froxlor/Api/Commands/SubDomains.php +++ b/lib/Froxlor/Api/Commands/SubDomains.php @@ -767,13 +767,14 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc // prepare select statement $domains_stmt = Database::prepare(" - SELECT " . implode(",", $select_fields) . ", `ad`.`id` AS `aliasdomainid`, `ad`.`domain` AS `aliasdomain`, `da`.`id` AS `domainaliasid`, `da`.`domain` AS `domainalias` + SELECT " . implode(",", $select_fields) . ", IF(`d`.`parentdomainid` > 0, `pd`.`domain`, `d`.`domain`) AS `parentdomainname`, `ad`.`id` AS `aliasdomainid`, `ad`.`domain` AS `aliasdomain`, `da`.`id` AS `domainaliasid`, `da`.`domain` AS `domainalias` FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `ad` ON `d`.`aliasdomain`=`ad`.`id` LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `da` ON `da`.`aliasdomain`=`d`.`id` + LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `pd` ON `pd`.`id`=`d`.`parentdomainid` WHERE `d`.`customerid` IN (" . implode(', ', $customer_ids) . ") AND `d`.`email_only` = '0' - AND `d`.`id` NOT IN (" . implode(', ', $customer_stdsubs) . ")" . $this->getSearchWhere($query_fields, true) . $this->getOrderBy() . $this->getLimit()); + AND `d`.`id` NOT IN (" . implode(', ', $customer_stdsubs) . ")" . $this->getSearchWhere($query_fields, true) . " ORDER BY `parentdomainname` " . $this->getOrderBy(true) . $this->getLimit()); $result = array(); Database::pexecute($domains_stmt, $query_fields, true, true); diff --git a/lib/Froxlor/UI/Pagination.php b/lib/Froxlor/UI/Pagination.php index 9632c12b..eb5a3717 100644 --- a/lib/Froxlor/UI/Pagination.php +++ b/lib/Froxlor/UI/Pagination.php @@ -285,15 +285,22 @@ class Pagination $stop = $pages; } - $pagingcode = '« < '; + // check for possible sorting values and keep it + $orderstr = ''; + foreach ($this->fields as $fieldname => $fieldcaption) { + $fieldname = htmlspecialchars($fieldname); + $orderstr .= '&sortfield=' . $fieldname . '&sortorder=' . $this->sortorder; + } + + $pagingcode = '« < '; for ($i = $start; $i <= $stop; $i ++) { if ($i != $this->pageno) { - $pagingcode .= ' ' . $i . ' '; + $pagingcode .= ' ' . $i . ' '; } else { $pagingcode .= ' ' . $i . ' '; } } - $pagingcode .= ' > »'; + $pagingcode .= ' > »'; } else { $pagingcode = ''; }