From 7954af888da59ace422c7b2056437224e36a5374 Mon Sep 17 00:00:00 2001 From: Lukas Heiligenbrunner Date: Fri, 10 Jul 2020 19:13:40 +0200 Subject: [PATCH] save settings correctly to db and parse response from insertion --- api/Settings.php | 19 +++++++++++++++++++ src/pages/SettingsPage/GeneralSettings.js | 13 +++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/api/Settings.php b/api/Settings.php index 4afb181..059a23d 100644 --- a/api/Settings.php +++ b/api/Settings.php @@ -22,5 +22,24 @@ if (isset($_POST['action'])) { } echo json_encode($r); break; + case "saveGeneralSettings": + $mediacentername = $_POST['mediacentername']; + $password = $_POST['password']; + $videopath = $_POST['videopath']; + $tvshowpath = $_POST['tvshowpath']; + + $query = "UPDATE settings SET + video_path='$videopath', + episode_path='$tvshowpath', + password='$password', + mediacenter_name='$mediacentername' + WHERE 1"; + + if ($conn->query($query) === true) { + echo '{"success": true}'; + } else { + echo '{"success": true}'; + } + break; } } diff --git a/src/pages/SettingsPage/GeneralSettings.js b/src/pages/SettingsPage/GeneralSettings.js index 6ec0a98..fa4996d 100644 --- a/src/pages/SettingsPage/GeneralSettings.js +++ b/src/pages/SettingsPage/GeneralSettings.js @@ -93,10 +93,19 @@ class GeneralSettings extends React.Component { const updateRequest = new FormData(); updateRequest.append('action', 'saveGeneralSettings'); - fetch('/api/settings.php', {method: 'POST', body: updateRequest}) + updateRequest.append('password', this.state.passwordsupport ? this.state.password : "-1"); + updateRequest.append('videopath', this.state.videopath); + updateRequest.append('tvshowpath', this.state.tvshowpath); + updateRequest.append('mediacentername', this.state.mediacentername); + + fetch('/api/Settings.php', {method: 'POST', body: updateRequest}) .then((response) => response.json() .then((result) => { - // todo 2020-07-4: settings result here + if (result.success) { + // todo 2020-07-10: popup success + } else { + // todo 2020-07-10: popup error + } })); } }