<?php    
    if(isset($_POST['deleteTimeTable'])){
        
        $del_id=$_POST['deleteTimeTable'];

        $sq = "SELECT document FROM exam_time_table WHERE time_table_id='$del_id'";
        $que = mysql_query($sq);
        
        while($document = mysql_fetch_assoc($que)){
            $doc = $document['document'];
        }
        
        
        //delete photo in folder
        if(!unlink("../../uploads/time_table/exam/$doc")){
            echo'<div class="alert alert-warning absolue center text-center" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <span class="text-warning">Error occured while trying to delete Time Table document</span>
                </div>';
        }else{
            if(!$uppdate=mysql_query("update exam SET deleted_by='$stafNo' WHERE time_table_id='$del_id'"))
            {
                echo'<div class="alert alert-danger absolue center text-center" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        <span class="text-danger"><b>Failed to delete:</b> Error occured while trying to read staff info on delete: <br>'.mysql_error().'</span>
                    </div>';
            }else
            { 
                //delete row(s) of record(s)
                $sql = "DELETE FROM exam_time_table WHERE time_table_id='$del_id'";
                $deleted = mysql_query($sql);
                //get no. of rows deleted
                $records=  mysql_affected_rows();

                // if successful redirect to refresh page
                if($records>0){      
                    $_SESSION["del"]='True';
                    header('Location:exam-time-table.php');
                    echo "<script type='text/javascript'> document.location = 'exam-time-table.php'; </script>";
                    exit();
                }else{
                    echo'<div class="alert alert-warning absolue center text-center" role="alert">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                            <span class="text-warning">No Time Table(s) deleted!</span>
                        </div>';
                }
            }
        }
    }
?>                                                             