<?php
define('system',1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
$rawData = file_get_contents("php://input");

$data = json_decode($rawData);


if($data){
    $summary = '';
    foreach ($data->summary as $item){
        $summary .= '<br/>'.$item;
    }

    require_once('_config/config.php');

    $db=mysqli_connect($cfg['mysql']['host'], $cfg['mysql']['user'], $cfg['mysql']['password']);
    mysqli_select_db($db,$cfg['mysql']['base']);
    mysqli_query($db, "SET CHARSET 'utf8'");
   
    $mystring = $data->test6;
    $findme   = 'undefined';
    $pos = strpos($mystring, $findme);

    if ($pos !== false) {
        $data->test6 = '';
    }

    $query = "INSERT INTO table_historia SET `his#uzytkownik`='{$data->user}',
                           `his#test1`='{$data->test1}',
                           `his#test2`='{$data->test2}',
                           `his#test3`='{$data->test3}',
                           `his#test4`='{$data->test4}',
                           `his#test5`='{$data->test5}',
                           `his#test6`='{$data->test6}',
                           `his#test7`='{$data->test7}',
                           `his#podsumowanie`='{$summary}',
                           `his#data`=NOW()
                           ";
    mysqli_query($db, $query);

    echo '{"status": "OK"}';
}

?>