<?php
// error_reporting(E_ALL);
// ini_set('display_errors', 1);
    if (isset($_GET['key'])) {
        if (($_GET['key'] === 'brt6k11t')&&$_POST['action']=="get") {
            require('../connect.php');
            require('../times.php');

            $conn = new mysqli($host, $user, $pass, $database);

            $sql = "SELECT * FROM `last_data`";

            $result = mysqli_query($conn, $sql);

            if (mysqli_num_rows($result) > 0) {
                $row = mysqli_fetch_assoc($result);

                if (($current_datetime >= $start_time && $current_datetime <= $end_time)&&(file_get_contents("../allowWork.txt")=="yes")) {
                    if($row['r201']=='3'||$row['r201']=='2'){
                        if(($row['r216']<'-50')) {
                            $response = "less";
                        }elseif(($row['r219']>'3000')&&($row['r216']>'-10')){
                            $response = "more";
                        }elseif((($row['r217']  <'-150'))||(($row['r232'] <'-100')&&($row['r229'] < 40))){
                            $response = "stop";
                        }else{
                            $response = "ok";
                        }
                    }else{
                        $response = "stop";
                    }
                }else{
                    $response = "stop";
                }
            }else{
                $response = "Błąd serwera";
            }

            $conn->close();

            // header('Content-Type: application/json');
            echo $response;
        }
    }else{
        echo "Błąd weryfikacji";
    }
?>