<?php
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
ob_start();
session_start();
if((($_SERVER['SERVER_ADDR']==$_SESSION['demo_server_ip']) && ((!empty($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0] : $_SERVER['REMOTE_ADDR']))!=$_SESSION['demo_developer_ip']) && ($_SESSION['id_user']==$_SESSION['demo_user_id'])) || ($_SESSION['svt_si']!=session_id())) {
    die();
}
require_once("../../db/connection.php");
require_once("../functions.php");
$id_user = $_SESSION['id_user'];
$id_virtualtour = $_SESSION['id_virtualtour_sel'];
$id_marker = (int)$_POST['id'];
if(!check_elem_ownership($id_user,$id_virtualtour,'marker',$id_marker)) {
    ob_end_clean();
    echo json_encode(array("status"=>"error"));
    die();
}
session_write_close();
$id_room_target = (int)$_POST['id_room_target'];
$yaw = $_POST['yaw'];
$pitch = $_POST['pitch'];
if($yaw=='') $yaw = NULL; else $yaw = (float)$yaw;
if($pitch=='') $pitch = NULL; else $pitch = (float)$pitch;
$lookat = (int)$_POST['lookat'];
$yaw_look_m = $_POST['yaw_look_m'];
$pitch_look_m = $_POST['pitch_look_m'];
if($yaw_look_m=='') $yaw_look_m = NULL; else $yaw_look_m = (float)$yaw_look_m;
if($pitch_look_m=='') $pitch_look_m = NULL; else $pitch_look_m = (float)$pitch_look_m;
if($yaw==$yaw_look_m && $pitch==$pitch_look_m) {
    $yaw_look_m = NULL;
    $pitch_look_m = NULL;
}
$duration_look_m = (int)$_POST['duration_look_m'];
$query = "UPDATE svt_markers SET id_room_target=?,yaw_room_target=?,pitch_room_target=?,lookat=?,yaw_look_room_target=?,pitch_look_room_target=?,duration_look_room_target=? WHERE id=?;";
if($smt = $mysqli->prepare($query)) {
    $smt->bind_param('iddiddii', $id_room_target,$yaw,$pitch,$lookat,$yaw_look_m,$pitch_look_m,$duration_look_m,$id_marker);
    $result = $smt->execute();
    if($result) {
        ob_end_clean();
        echo json_encode(array("status"=>"ok"));
    } else {
        ob_end_clean();
        echo json_encode(array("status"=>"error"));
    }
} else {
    ob_end_clean();
    echo json_encode(array("status"=>"error"));
}