Skip to content

Commit 4003a8d

Browse files
committed
check for existing fields when setting/updating tablelisting-columns
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
1 parent 89843d6 commit 4003a8d

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

Diff for: lib/Froxlor/Ajax/Ajax.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,19 @@ private function searchGlobal()
237237
private function updateTablelisting()
238238
{
239239
$columns = [];
240-
foreach ((Request::any('columns') ?? []) as $value) {
240+
foreach ((Request::post('columns') ?? []) as $value) {
241241
$columns[] = $value;
242242
}
243243
if (!empty($columns)) {
244-
Listing::storeColumnListingForUser([Request::any('listing') => $columns]);
244+
$columns = Listing::storeColumnListingForUser([Request::post('listing') => $columns]);
245245
return $this->jsonResponse($columns);
246246
}
247247
return $this->errorResponse('At least one column must be selected', 406);
248248
}
249249

250250
private function resetTablelisting()
251251
{
252-
Listing::deleteColumnListingForUser([Request::any('listing') => []]);
252+
Listing::deleteColumnListingForUser([Request::post('listing') => []]);
253253
return $this->jsonResponse([]);
254254
}
255255

Diff for: lib/Froxlor/UI/Listing.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
use Froxlor\CurrentUser;
2929
use Froxlor\Database\Database;
30+
use Froxlor\Froxlor;
3031
use Froxlor\UI\Panel\UI;
3132
use InvalidArgumentException;
3233

@@ -247,9 +248,9 @@ private static function getAvailableColumnsForListing(array $tabellisting): arra
247248
* ]
248249
*
249250
* @param array $tabellisting
250-
* @return bool
251+
* @return array
251252
*/
252-
public static function storeColumnListingForUser(array $tabellisting): bool
253+
public static function storeColumnListingForUser(array $tabellisting): array
253254
{
254255
$section = array_key_first($tabellisting);
255256
if (empty($section) || !is_array($tabellisting[$section]) || empty($tabellisting[$section])) {
@@ -259,6 +260,22 @@ public static function storeColumnListingForUser(array $tabellisting): bool
259260
if (CurrentUser::isAdmin()) {
260261
$userid = 'adminid';
261262
}
263+
// include all possible tablelisting-definitions to check for the right section
264+
foreach(glob(Froxlor::getInstallDir().'lib/tablelisting/{,*/}*.php', GLOB_BRACE) as $tbl_file) {
265+
$table_listings = include $tbl_file;
266+
if (!isset($table_listings[$section])) {
267+
continue;
268+
} else {
269+
break;
270+
}
271+
}
272+
$columns_available = array_keys($table_listings[$section]['columns']);
273+
// filter out unknown columns
274+
foreach ($tabellisting[$section] as $index => $column_changed) {
275+
if (!in_array($column_changed, $columns_available)) {
276+
unset($tabellisting[$section][$index]);
277+
}
278+
}
262279
// delete possible existing entry
263280
self::deleteColumnListingForUser($tabellisting);
264281
// add new entry
@@ -273,7 +290,7 @@ public static function storeColumnListingForUser(array $tabellisting): bool
273290
'section' => $section,
274291
'cols' => json_encode($tabellisting[$section])
275292
]);
276-
return true;
293+
return $tabellisting[$section];
277294
}
278295

279296
/**

Diff for: lib/tablelisting/admin/tablelisting.domains.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@
2929
use Froxlor\UI\Callbacks\Text;
3030
use Froxlor\UI\Listing;
3131

32+
// used outside scope variables
33+
$customerCollectionCount = !is_null($customerCollection ?? null) ? $customerCollection->count() : 0;
34+
3235
return [
3336
'domain_list' => [
3437
'title' => lng('admin.domains'),
3538
'icon' => 'fa-solid fa-globe',
36-
'empty_msg' => $customerCollection->count() == 0 ? lng('admin.domain_nocustomeraddingavailable') : '',
39+
'empty_msg' => $customerCollectionCount == 0 ? lng('admin.domain_nocustomeraddingavailable') : '',
3740
'self_overview' => ['section' => 'domains', 'page' => 'domains'],
3841
'default_sorting' => ['d.domain_ace' => 'asc'],
3942
'columns' => [

Diff for: lib/tablelisting/customer/tablelisting.htaccess.php

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
use Froxlor\UI\Callbacks\Text;
2828
use Froxlor\UI\Listing;
2929

30+
// used outside scope variables
31+
$cperlenabled = $cperlenabled ?? false;
32+
3033
return [
3134
'htaccess_list' => [
3235
'title' => lng('menue.extras.pathoptions'),

Diff for: lib/tablelisting/customer/tablelisting.mysqls.php

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
use Froxlor\UI\Callbacks\Text;
2828
use Froxlor\UI\Listing;
2929

30+
// used outside scope variables
31+
$multiple_mysqlservers = $multiple_mysqlservers ?? false;
32+
3033
return [
3134
'mysql_list' => [
3235
'title' => lng('menue.mysql.databases'),

Diff for: lib/tablelisting/tablelisting.dns.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
use Froxlor\UI\Callbacks\Text;
2828
use Froxlor\UI\Listing;
2929

30+
// used outside scope variables
31+
$domain = $domain ?? '';
32+
$domain_id = $domain_id ?? '';
33+
3034
return [
3135
'dns_list' => [
3236
'title' => 'DNS Entries',

0 commit comments

Comments
 (0)