<?php
include "../database.php";
session_start();

$stamp_type  = $_POST["stamp_type"];
$stamp_note  = addslashes($_POST["stamp_note"]);
$stamp_date  = date("Y-m-d", strtotime($_POST["stamp_date"]));
$stamp_time  = date("H:i", strtotime($_POST["stamp_time"]));
$datetime    = date("Y-m-d H:i:s");
$user_id     = $_SESSION['id'];
$in_transfer = $_POST["in_transfer"];
$transfer_location = $_POST["transfer_location"];
$secure               = rand(100000, 1000000);

$stamp_datetime = $stamp_date." ".$stamp_time;

$sql_insert = "INSERT INTO stamps VALUES (NULL,$user_id,'$stamp_type','$stamp_date','$stamp_time','$stamp_note','$datetime', $in_transfer, 0, '$transfer_location', 0,0, $secure)";
if ($con->query($sql_insert) === true) {
    $id = $con->insert_id;

    $sql_insert = "INSERT INTO tbl_events VALUES (NULL,'$stamp_type', '$stamp_datetime', '$stamp_datetime', $user_id, 0, '#2196f3', 'Timbratura', $id)";
    if ($con->query($sql_insert) === true) {
        echo "ok";
    } else {
        echo "error";
    }
} else {
    echo "error";
}

$con->close();
