summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2018-07-04 12:35:56 +0200
committerSimon Rettberg2018-07-04 12:35:56 +0200
commitff57c086a3b868cc73f159fa29891d26a5a3e02b (patch)
treefac6f4ed2af7f2a864e2f234938c09a1639fd7a8 /modules-available/serversetup-bwlp/page.inc.php
parent[serversetup-bwlp] Slightly nicer colors; html cleanup (diff)
downloadslx-admin-ff57c086a3b868cc73f159fa29891d26a5a3e02b.tar.gz
slx-admin-ff57c086a3b868cc73f159fa29891d26a5a3e02b.tar.xz
slx-admin-ff57c086a3b868cc73f159fa29891d26a5a3e02b.zip
[serversetup-bwlp] Fix hotkey saving, adding new entries
Diffstat (limited to 'modules-available/serversetup-bwlp/page.inc.php')
-rw-r--r--modules-available/serversetup-bwlp/page.inc.php53
1 files changed, 31 insertions, 22 deletions
diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php
index 061abfd5..00b658c4 100644
--- a/modules-available/serversetup-bwlp/page.inc.php
+++ b/modules-available/serversetup-bwlp/page.inc.php
@@ -187,25 +187,11 @@ class Page_ServerSetup extends Page
$menu['timeout'] = round($menu['timeoutms'] / 1000);
$menu['entries'] = Database::queryAll("SELECT menuentryid, entryid, hotkey, title, hidden, sortval, plainpass FROM
serversetup_menuentry WHERE menuid = :id ORDER BY sortval ASC", compact('id'));
- $keyList = array_map(function ($item) { return ['key' => $item]; }, MenuEntry::getKeyList());
- $entryList = Database::queryAll("SELECT entryid, title, hotkey FROM serversetup_bootentry ORDER BY title ASC");
+ $menu['keys'] = array_map(function ($item) { return ['key' => $item]; }, MenuEntry::getKeyList());
+ $menu['entrylist'] = Database::queryAll("SELECT entryid, title, hotkey FROM serversetup_bootentry ORDER BY title ASC");
foreach ($menu['entries'] as &$entry) {
$entry['isdefault'] = ($entry['menuentryid'] == $menu['defaultentryid']);
- $entry['keys'] = $keyList;
- foreach ($entry['keys'] as &$key) {
- if ($key['key'] === $entry['hotkey']) {
- $key['selected'] = 'selected'; // TODO: plainpass only when permissions
- }
- }
- $entry['entrylist'] = $entryList;
- foreach ($entry['entrylist'] as &$item) {
- if ($item['entryid'] == $entry['entryid']) {
- $item['selected'] = 'selected';
- }
- if (empty($item['title'])) {
- $item['title'] = $item['entryid'];
- }
- }
+ // TODO: plainpass only when permissions
}
// TODO: Make assigned locations editable
Permission::addGlobalTags($menu['perms'], 0, ['ipxe.menu.edit']);
@@ -303,7 +289,7 @@ class Page_ServerSetup extends Page
'menuid' => $id,
'title' => IPxe::sanitizeIpxeString(Request::post('title', '', 'string')),
'timeoutms' => abs(Request::post('timeoutms', 0, 'int') * 1000),
- 'defaultentryid' => Request::post('defaultentry', false, 'int'),
+ 'defaultentryid' => Request::post('defaultentry', null, 'int'),
]);
if (User::hasPermission('ipxe.menu.edit', 0)) {
Database::exec('UPDATE serversetup_menu SET isdefault = (menuid = :menuid)', ['menuid' => $id]);
@@ -313,15 +299,38 @@ class Page_ServerSetup extends Page
$entries = Request::post('entry', false, 'array');
foreach ($entries as $key => $entry) {
+ if (!isset($entry['sortval'])) {
+ error_log(print_r($entry, true));
+ continue;
+ }
+ // Fallback defaults
+ $entry += [
+ 'entryid' => null,
+ 'title' => '',
+ 'hidden' => 0,
+ 'plainpass' => '',
+ ];
$params = [
- 'entryid' => $entry['entryid'], // TODO validate
- 'hotkey' => MenuEntry::filterKeyName($entry['hotkey']),
'title' => IPxe::sanitizeIpxeString($entry['title']),
- 'hidden' => (int)$entry['hidden'],
'sortval' => (int)$entry['sortval'],
- 'plainpass' => $entry['plainpass'],
'menuid' => $menu['menuid'],
];
+ if (empty($entry['entryid'])) {
+ // Spacer
+ $params += [
+ 'entryid' => null,
+ 'hotkey' => '',
+ 'hidden' => 0, // Doesn't make any sense
+ 'plainpass' => '', // Doesn't make any sense
+ ];
+ } else {
+ $params += [
+ 'entryid' => $entry['entryid'], // TODO validate?
+ 'hotkey' => MenuEntry::filterKeyName($entry['hotkey']),
+ 'hidden' => (int)$entry['hidden'], // TODO (needs hotkey to make sense)
+ 'plainpass' => $entry['plainpass'],
+ ];
+ }
if (is_numeric($key)) {
$keepIds[] = $key;
$params['menuentryid'] = $key;