<?php
include('../include/auth.php');
include('../include/lskfjwfe.php');
header('Content-Type: application/json');

$partner_id = (int)$_POST['partner_id'];
$start = mysqli_real_escape_string($db2, $_POST['start']);
$end = mysqli_real_escape_string($db2, $_POST['end']);
$charge = (float)$_POST['charge'];

$query = $db2->query("
  INSERT INTO api_outofhours (api_outofhours_start, api_outofhours_end, api_outofhours_charge, api_outofhours_partner_id)
  VALUES ('$start', '$end', $charge, $partner_id)
");

if ($query) {
  $details = mysqli_real_escape_string($db2, json_encode($_POST));
  $db2->query("INSERT INTO action_logs (action, details, user) VALUES ('add_api_outofhours', '$details', '$user')");
  echo json_encode(['success' => true]);
} else {
  echo json_encode(['success' => false, 'error' => mysqli_error($db2)]);
}
