<?php

$inputRules = [
    "title"      => ["required" => true, "validate" => ["filter" => FILTER_SANITIZE_FULL_SPECIAL_CHARS]],
    "priority"   => ["required" => true, "validate" => ["filter" => FILTER_SANITIZE_FULL_SPECIAL_CHARS]],
    'datepicker' => ["required" => true, "validate" => ["filter" => FILTER_SANITIZE_FULL_SPECIAL_CHARS]]
];

$failed = false;

if (__RB_validateInput($inputRules, 'insert_meeting')) {
    $failed = false;
    $oldPost = $_POST;
    $objCreate = [];

    foreach ($inputRules as $key => $val) {
        if ($key == 'datepicker') {
            $date = (explode(" - ", $_POST[$key]));
            $objCreate['start'] = $date[0];
            $objCreate['end'] = $date[1];
        } else {
            $objCreate[$key] = $_POST[$key];
        }
    }

    if (!$failed) {

        $json = "";
        $data = [
            'id' => $_POST['id'],
            'id_customer' => $_SESSION['id'],
            'data'        => $objCreate
        ];

        __RB_api_cloud('addMeeting', $data, $json);

        $__RB_success['meeting_upload'] = true;

        $_POST = [];
    }
}
