new class based syntax for handling api requests in php
This commit is contained in:
		@@ -1,29 +1,25 @@
 | 
			
		||||
<?php
 | 
			
		||||
require 'Database.php';
 | 
			
		||||
require 'SSettings.php';
 | 
			
		||||
require 'RequestBase.php';
 | 
			
		||||
 | 
			
		||||
$conn = Database::getInstance()->getConnection();
 | 
			
		||||
$settings = new SSettings();
 | 
			
		||||
 | 
			
		||||
if (isset($_POST['action'])) {
 | 
			
		||||
    $action = $_POST['action'];
 | 
			
		||||
    switch ($action) {
 | 
			
		||||
        case "loadGeneralSettings":
 | 
			
		||||
class Settings extends RequestBase {
 | 
			
		||||
    function initIdentifiers() {
 | 
			
		||||
        $this->addIdentifier("loadGeneralSettings", function () {
 | 
			
		||||
            $query = "SELECT * from settings";
 | 
			
		||||
 | 
			
		||||
            $result = $conn->query($query);
 | 
			
		||||
            $result = $this->conn->query($query);
 | 
			
		||||
            if ($result->num_rows > 1) {
 | 
			
		||||
                // todo throw error
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $r = mysqli_fetch_assoc($result);
 | 
			
		||||
            // booleans need to be set manually
 | 
			
		||||
            $r['passwordEnabled']  = $r['password'] != "-1";
 | 
			
		||||
            $r['passwordEnabled'] = $r['password'] != "-1";
 | 
			
		||||
            $r['TMDB_grabbing'] = ($r['TMDB_grabbing'] != '0');
 | 
			
		||||
 | 
			
		||||
            echo json_encode($r);
 | 
			
		||||
            break;
 | 
			
		||||
        case "saveGeneralSettings":
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->addIdentifier("saveGeneralSettings", function () {
 | 
			
		||||
            $mediacentername = $_POST['mediacentername'];
 | 
			
		||||
            $password = $_POST['password'];
 | 
			
		||||
            $videopath = $_POST['videopath'];
 | 
			
		||||
@@ -38,16 +34,17 @@ if (isset($_POST['action'])) {
 | 
			
		||||
                        TMDB_grabbing=$tmdbsupport
 | 
			
		||||
                    WHERE 1";
 | 
			
		||||
 | 
			
		||||
            if ($conn->query($query) === true) {
 | 
			
		||||
            if ($this->conn->query($query) === true) {
 | 
			
		||||
                echo '{"success": true}';
 | 
			
		||||
            } else {
 | 
			
		||||
                echo '{"success": true}';
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case "loadInitialData":
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->addIdentifier("loadInitialData", function () {
 | 
			
		||||
            $query = "SELECT * from settings";
 | 
			
		||||
 | 
			
		||||
            $result = $conn->query($query);
 | 
			
		||||
            $result = $this->conn->query($query);
 | 
			
		||||
            if ($result->num_rows > 1) {
 | 
			
		||||
                // todo throw error
 | 
			
		||||
            }
 | 
			
		||||
@@ -60,6 +57,9 @@ if (isset($_POST['action'])) {
 | 
			
		||||
            }
 | 
			
		||||
            unset($r['password']);
 | 
			
		||||
            echo json_encode($r);
 | 
			
		||||
            break;
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$sett = new Settings();
 | 
			
		||||
$sett->handleAction();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user