<?php

    require_once "config/connection.php";
    
    $arr = array();

    foreach ($_POST["chk_case_id"] as $idx => $case_id)
    {
        $sql = "DELETE FROM `case` WHERE `case_id` = ".$case_id;

        if(!mysql_query($sql))
        {
            $arr["status"] = 0;
            $arr["message"] = mysql_error();
            die(json_encode($arr));    
        }
        
        
        $sql = "select * from `case_file`
            where `case_id` = ".$case_id;
        
        $tmprs = mysql_query($sql);
        while($tmprow = mysql_fetch_array($tmprs))
        {
            unlink(CASE_FILES_UPLOAD_DIR . "/" . $tmprow["case_file_path"]);
        }
        
        $sql = "DELETE FROM `case_file` WHERE `case_id` = ".$case_id;

        if(!mysql_query($sql))
        {
            $arr["status"] = 0;
            $arr["message"] = mysql_error();
            die(json_encode($arr));    
        }
    }
    
    $arr["status"] = 1;
    $arr["message"] = "Case(s) supprimée(s) avec succès.";
    echo json_encode($arr);     
