<?php
include('../../../function/__data_app_db.php');
$__data_action = 'false';
 $_name_in_jsnj  = $__go_to = $inq_id=$job_id=$job_card_no=$errData = $item_list_name=$item_list = $vehicles_details='';
$item_qty='0';
if(isset($_POST["tkn"]) && $_POST["tkn"] == $_SESSION['signup_token']){

    $doc_no = validate_jsnj_data($_POST["doc_no"]);
    $company_name = validate_jsnj_data($_POST["company_name"]);
    $book_date = jsnj_date_ymd($_POST["book_date"]);
    $ship_from_name = validate_jsnj_data($_POST["ship_from_name"]);
    $ship_from_phone = validate_jsnj_data($_POST["ship_from_phone"]);
    $ship_from_email = validate_jsnj_data($_POST["ship_from_email"]);
    $ship_from_country = validate_jsnj_data($_POST["ship_from_country"]);
    $ship_from_state = validate_jsnj_data($_POST["ship_from_state"]);
    $ship_from_city = validate_jsnj_data($_POST["ship_from_city"]);
    $ship_from_pincode = validate_jsnj_data($_POST["ship_from_pincode"]);
    $ship_from_address = validate_jsnj_data($_POST["ship_from_address"]);
    $ship_to_name = validate_jsnj_data($_POST["ship_to_name"]);
    $ship_to_phone = validate_jsnj_data($_POST["ship_to_phone"]);
    $ship_to_email = validate_jsnj_data($_POST["ship_to_email"]);
    $ship_to_country = validate_jsnj_data($_POST["ship_to_country"]);
    $ship_to_state = validate_jsnj_data($_POST["ship_to_state"]);
    $ship_to_city = validate_jsnj_data($_POST["ship_to_city"]);
    $ship_to_pincode = validate_jsnj_data($_POST["ship_to_pincode"]);
    $ship_to_address = validate_jsnj_data($_POST["ship_to_address"]);
    $ship_to_address = validate_jsnj_data($_POST["ship_to_address"]);
    $type = validate_jsnj_data($_POST["type"]);
    $weight = validate_jsnj_data($_POST["weight"]);
    $invoice_number = validate_jsnj_data($_POST["invoice_number"]);
    $quantity = validate_jsnj_data($_POST["quantity"]);
    $freight = validate_jsnj_data($_POST["freight"]);
    $pick_date = jsnj_date_ymd($_POST["pick_date"]);
    $pick_time = validate_jsnj_data($_POST["pick_time"]);
    $db_query = "INSERT INTO `tbl_courier`(`doc_no`, `company_name`, `ship_name`, `phone`, `s_add`, `s_country`, `s_state`, `s_city`, `s_pincode`, `rev_name`, `r_phone`, `r_add`, `r_country`, `r_state`, `r_city`, `r_pincode`, `type`, `weight`, `invice_no`, `qty`, `freight`,  `pick_date`, `pick_time`,`book_date`, `ip`) VALUES ('$doc_no','$company_name','$ship_from_name','$ship_from_phone','$ship_from_address','$ship_from_country','$ship_from_state','$ship_from_city','$ship_from_pincode','$ship_to_name','$ship_to_phone','$ship_to_address','$ship_to_country','$ship_to_state','$ship_to_city','$ship_to_pincode','$type','$weight','$invoice_number','$quantity','$freight','$pick_date','$pick_time','$book_date','$ip')";
    if($errData=='') {
        $res = mysqli_query($_conn_db, $db_query);
        $cid=  mysqli_insert_id($_conn_db);;
        $res = mysqli_query($_conn_db, "INSERT INTO `tbl_courier_track`(`doc_no`,`c_id`, `t_from`, `t_type`, `t_date_time`, `status`, `ip`) VALUES ('$doc_no','$cid','$ship_from_address','Pending','$pick_date','1','$ip')");
        if($res){
            $errData='';
        } else {
            $errData='| Something want wrong. Try again! |';
        }
    };

 if($errData=='') {
  if($res){
    $__notif_title = 'Tracking Details Updated';
	$__notif_disc = 'Successfully';
	$__notif_type = 'success';
	$__go_to = "track-order?inq=$doc_no";
	$__data_action = 'true';
  }
  else{
	$__notif_title = 'Oops!';
	$__notif_disc = 'Something want wrong please reload this page';
	$__notif_type = 'danger';
  }
 }else{
   $__notif_title = 'Oops!';
   $__notif_disc = $errData;
   $__notif_type = 'warning';
 }
$dataResult = array('page' => 'track-order', 'res' => $__data_action, 'notif_title' => $__notif_title, 'notif_desc' => $__notif_disc,  'notif_type' => $__notif_type, 'goTo' => $__go_to);
echo json_encode($dataResult);
} else {
    echo 'lol';
};
?>