Skip to content

Commit

Permalink
check for existing fields when setting/updating tablelisting-columns
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
  • Loading branch information
d00p committed Feb 14, 2023
1 parent 89843d6 commit 4003a8d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/Froxlor/Ajax/Ajax.php
Expand Up @@ -237,19 +237,19 @@ private function searchGlobal()
private function updateTablelisting()
{
$columns = [];
foreach ((Request::any('columns') ?? []) as $value) {
foreach ((Request::post('columns') ?? []) as $value) {
$columns[] = $value;
}
if (!empty($columns)) {
Listing::storeColumnListingForUser([Request::any('listing') => $columns]);
$columns = Listing::storeColumnListingForUser([Request::post('listing') => $columns]);
return $this->jsonResponse($columns);
}
return $this->errorResponse('At least one column must be selected', 406);
}

private function resetTablelisting()
{
Listing::deleteColumnListingForUser([Request::any('listing') => []]);
Listing::deleteColumnListingForUser([Request::post('listing') => []]);
return $this->jsonResponse([]);
}

Expand Down
23 changes: 20 additions & 3 deletions lib/Froxlor/UI/Listing.php
Expand Up @@ -27,6 +27,7 @@

use Froxlor\CurrentUser;
use Froxlor\Database\Database;
use Froxlor\Froxlor;
use Froxlor\UI\Panel\UI;
use InvalidArgumentException;

Expand Down Expand Up @@ -247,9 +248,9 @@ private static function getAvailableColumnsForListing(array $tabellisting): arra
* ]
*
* @param array $tabellisting
* @return bool
* @return array
*/
public static function storeColumnListingForUser(array $tabellisting): bool
public static function storeColumnListingForUser(array $tabellisting): array
{
$section = array_key_first($tabellisting);
if (empty($section) || !is_array($tabellisting[$section]) || empty($tabellisting[$section])) {
Expand All @@ -259,6 +260,22 @@ public static function storeColumnListingForUser(array $tabellisting): bool
if (CurrentUser::isAdmin()) {
$userid = 'adminid';
}
// include all possible tablelisting-definitions to check for the right section
foreach(glob(Froxlor::getInstallDir().'lib/tablelisting/{,*/}*.php', GLOB_BRACE) as $tbl_file) {
$table_listings = include $tbl_file;
if (!isset($table_listings[$section])) {
continue;
} else {
break;
}
}
$columns_available = array_keys($table_listings[$section]['columns']);
// filter out unknown columns
foreach ($tabellisting[$section] as $index => $column_changed) {
if (!in_array($column_changed, $columns_available)) {
unset($tabellisting[$section][$index]);
}
}
// delete possible existing entry
self::deleteColumnListingForUser($tabellisting);
// add new entry
Expand All @@ -273,7 +290,7 @@ public static function storeColumnListingForUser(array $tabellisting): bool
'section' => $section,
'cols' => json_encode($tabellisting[$section])
]);
return true;
return $tabellisting[$section];
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/tablelisting/admin/tablelisting.domains.php
Expand Up @@ -29,11 +29,14 @@
use Froxlor\UI\Callbacks\Text;
use Froxlor\UI\Listing;

// used outside scope variables
$customerCollectionCount = !is_null($customerCollection ?? null) ? $customerCollection->count() : 0;

return [
'domain_list' => [
'title' => lng('admin.domains'),
'icon' => 'fa-solid fa-globe',
'empty_msg' => $customerCollection->count() == 0 ? lng('admin.domain_nocustomeraddingavailable') : '',
'empty_msg' => $customerCollectionCount == 0 ? lng('admin.domain_nocustomeraddingavailable') : '',
'self_overview' => ['section' => 'domains', 'page' => 'domains'],
'default_sorting' => ['d.domain_ace' => 'asc'],
'columns' => [
Expand Down
3 changes: 3 additions & 0 deletions lib/tablelisting/customer/tablelisting.htaccess.php
Expand Up @@ -27,6 +27,9 @@
use Froxlor\UI\Callbacks\Text;
use Froxlor\UI\Listing;

// used outside scope variables
$cperlenabled = $cperlenabled ?? false;

return [
'htaccess_list' => [
'title' => lng('menue.extras.pathoptions'),
Expand Down
3 changes: 3 additions & 0 deletions lib/tablelisting/customer/tablelisting.mysqls.php
Expand Up @@ -27,6 +27,9 @@
use Froxlor\UI\Callbacks\Text;
use Froxlor\UI\Listing;

// used outside scope variables
$multiple_mysqlservers = $multiple_mysqlservers ?? false;

return [
'mysql_list' => [
'title' => lng('menue.mysql.databases'),
Expand Down
4 changes: 4 additions & 0 deletions lib/tablelisting/tablelisting.dns.php
Expand Up @@ -27,6 +27,10 @@
use Froxlor\UI\Callbacks\Text;
use Froxlor\UI\Listing;

// used outside scope variables
$domain = $domain ?? '';
$domain_id = $domain_id ?? '';

return [
'dns_list' => [
'title' => 'DNS Entries',
Expand Down

0 comments on commit 4003a8d

Please sign in to comment.