<?php
    ini_set( 'display_errors', 'On' ); 
    error_reporting( E_ALL );
    if(isset($_GET['key'])&&$_GET['key']=="brt6k11t"){
        require_once('../connect.php');
    
        $conn = new mysqli($host, $user, $pass, $database);
        
        $sql = "SELECT * FROM `settings` WHERE 1";
        $query = mysqli_query($conn, $sql);
        if(mysqli_num_rows($query)>0){
            $allSettings = mysqli_fetch_all($query, MYSQLI_ASSOC);
            $formattedSettings = array();
            $counter = 1;
            
            foreach($allSettings as $row) {
                foreach($row as $key => $value) {
                    $formattedSettings[$counter] = array(
                        'name' => $key,
                        'value' => $value
                    );
                    $counter++;
                }
            }
            
            $response = array(
                'success' => 'yes',
                'settings' => $formattedSettings
            );
        }else{
            $response = array(
                'success' => 'no',
                'message' => 'Błąd pobierania ustawień'
            );
        }
        $conn->close();

        header('Content-Type: application/json');
        echo json_encode($response);
    }
?>