diff --git a/api/Settings.php b/api/Settings.php new file mode 100644 index 0000000..4afb181 --- /dev/null +++ b/api/Settings.php @@ -0,0 +1,26 @@ +getConnection(); + +if (isset($_POST['action'])) { + $action = $_POST['action']; + switch ($action) { + case "loadGeneralSettings": + $query = "SELECT * from settings"; + + $result = $conn->query($query); + if ($result->num_rows > 1) { + // todo throw error + } + + $r = mysqli_fetch_assoc($result); + if ($r['password'] != "-1") { + $r['passwordEnabled'] = true; + } else { + $r['passwordEnabled'] = true; + } + echo json_encode($r); + break; + } +} diff --git a/src/pages/SettingsPage/GeneralSettings.js b/src/pages/SettingsPage/GeneralSettings.js index 7e1d914..6ec0a98 100644 --- a/src/pages/SettingsPage/GeneralSettings.js +++ b/src/pages/SettingsPage/GeneralSettings.js @@ -7,9 +7,12 @@ class GeneralSettings extends React.Component { super(props); this.state = { - tvshowsupport: false, + passwordsupport: false, + videopath: "", - tvshowpath: "" + tvshowpath: "", + mediacentername: "", + password: "" }; } @@ -17,11 +20,16 @@ class GeneralSettings extends React.Component { const updateRequest = new FormData(); updateRequest.append('action', 'loadGeneralSettings'); - fetch('/api/settings.php', {method: 'POST', body: updateRequest}) + fetch('/api/Settings.php', {method: 'POST', body: updateRequest}) .then((response) => response.json() .then((result) => { - // todo 2020-07-3: set state here - // todo 2020-07-4: php and test code + this.setState({ + videopath: result.video_path, + tvshowpath: result.episode_path, + mediacentername: result.mediacenter_name, + password: result.password, + passwordsupport: result.passwordEnabled + }); })); } @@ -36,12 +44,15 @@ class GeneralSettings extends React.Component {