-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the settings page and some of the app settings to it
- Loading branch information
1 parent
e794ab2
commit f7b374d
Showing
7 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
---------------------------------- | ||
------ Created: 110924 ------ | ||
------ Austin Best ------ | ||
---------------------------------- | ||
*/ | ||
|
||
if (!$_SESSION) { | ||
session_start(); | ||
} | ||
|
||
if (!$_SESSION['IN_UI']) { | ||
exit('Invalid session, refresh the page'); | ||
} | ||
|
||
require '../loader.php'; | ||
|
||
if ($_POST['m'] == 'saveSettings') { | ||
$newSettings = []; | ||
foreach ($_POST as $key => $val) { | ||
if (str_equals_any($key, ['m', 'apikey'])) { | ||
continue; | ||
} | ||
|
||
$newSettings[$key] = $val; | ||
} | ||
|
||
$proxyDb->setSettings($newSettings, $settingsTable); | ||
|
||
if ($_POST['apikey'] && $_POST['apikey'] != APP_APIKEY) { | ||
file_put_contents(APP_APIKEY_FILE, $_POST['apikey']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function saveSettings() | ||
{ | ||
let params = []; | ||
|
||
$.each($('[id^=setting-]'), function() { | ||
let val = ''; | ||
if ($(this).is(':checkbox') || $(this).is(':radio')) { | ||
val = $(this).prop('checked') ? 1 : 0; | ||
} else { | ||
val = $(this).val(); | ||
} | ||
|
||
params += '&' + $(this).attr('id').replace('setting-', '') + '=' + val; | ||
}); | ||
|
||
$.ajax({ | ||
type: 'POST', | ||
url: 'ajax/settings.php', | ||
data: '&m=saveSettings' + params, | ||
success: function (resultData) { | ||
toast('Settings', 'The settings have been updated', 'success'); | ||
} | ||
}); | ||
} | ||
// ------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
---------------------------------- | ||
------ Created: 110924 ------ | ||
------ Austin Best ------ | ||
---------------------------------- | ||
*/ | ||
|
||
//-- RESET THE LIST | ||
$q = []; | ||
|
||
//-- ALWAYS NEED TO BUMP THE MIGRATION ID | ||
$q[] = "UPDATE " . SETTINGS_TABLE . " | ||
SET value = '002' | ||
WHERE name = 'migration'"; | ||
|
||
$settings = [ | ||
'backupRetentionLength' => $BACKUP_AGE, | ||
'logRotationSize' => $LOG_ROTATE_SIZE, | ||
'logRetentionLength' => $LOG_AGE, | ||
]; | ||
|
||
$settingRows = []; | ||
foreach ($settings as $key => $val) { | ||
$settingRows[] = "('" . $key . "', '" . $val . "')"; | ||
} | ||
|
||
$q[] = "INSERT INTO " . SETTINGS_TABLE . " | ||
(`name`, `value`) | ||
VALUES " . implode(', ', $settingRows); | ||
|
||
foreach ($q as $query) { | ||
logger(MIGRATION_LOG, '<span class="text-success">[Q]</span> ' . preg_replace('!\s+!', ' ', $query)); | ||
|
||
$proxyDb->query($query); | ||
|
||
if ($proxyDb->error() != 'not an error') { | ||
logger(MIGRATION_LOG, '<span class="text-info">[R]</span> ' . $proxyDb->error(), 'error'); | ||
} else { | ||
logger(MIGRATION_LOG, '<span class="text-info">[R]</span> query applied!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters