<?php
include('../../function/__data_app_db.php');
$__data_action = 'false';
$_name_in_jsnj  = $__go_to = $errData =  $__notif_title=$__notif_disc=$__notif_type=$__go_to='';
if(isset($_POST["deleteData"])) {
    if(isset($_POST["for"]) && $_POST["for"] == 'track-order') {
        for ($count = 0; $count < count($_POST["deleteData"]); $count++) {
            $deletData = validate_jsnj_data($_POST['deleteData'][$count]);
            $query = "DELETE FROM tbl_courier WHERE cid = '" . $deletData . "'";
            $statement = $_app_conn_db->prepare($query);
            $result = $statement->execute();
            if($result){
                $query = "DELETE FROM tbl_courier_track WHERE c_id = '" . $deletData . "'";
                $statement = $_app_conn_db->prepare($query);
                $result = $statement->execute();

                $__notif_title = 'Congratulations!';
                $__notif_disc = 'Data delete successfully.';
                $__notif_type = 'success';
                $__data_action = 'true';
            } else {
                $__notif_title = 'Oops!';
                $__notif_disc = 'Something want wrong.';
                $__notif_type = 'warning';
            }
        }
    }
    if(isset($_POST["for"]) && $_POST["for"] == 'review') {
        for ($count = 0; $count < count($_POST["deleteData"]); $count++) {
            $deletData = validate_jsnj_data($_POST['deleteData'][$count]);
            $query = "DELETE FROM review WHERE review_id = '" . $deletData . "'";
            $statement = $_app_conn_db->prepare($query);
            $result = $statement->execute();
            if($result){
                $__notif_title = 'Congratulations!';
                $__notif_disc = 'Data delete successfully.';
                $__notif_type = 'success';
                $__data_action = 'true';
            } else {
                $__notif_title = 'Oops!';
                $__notif_disc = 'Something want wrong.';
                $__notif_type = 'warning';
            }
        }
    }
    if(isset($_POST["for"]) && $_POST["for"] == 'track_details') {
        $deletData = validate_jsnj_data($_POST['deleteData']);
        $query = "DELETE FROM tbl_courier_track WHERE tracking_id = '" . $deletData . "'";
        $statement = $_app_conn_db->prepare($query);
        $result = $statement->execute();
            if ($result) {
                $__notif_title = 'Congratulations!';
                $__notif_disc = 'Data delete successfully.';
                $__notif_type = 'success';
                $__data_action = 'true';
            } else {
                $__notif_title = 'Oops!';
                $__notif_disc = 'Something want wrong.';
                $__notif_type = 'warning';
            }
        }

}

$dataResult = array('page' => 'deleteData', 'res' => $__data_action, 'notif_title' => $__notif_title, 'notif_disc' => $__notif_disc,  'notif_type' => $__notif_type, 'go_to' => $__go_to);
echo json_encode($dataResult);