<?php
include('../config/setup.php');

if($_SERVER['REQUEST_METHOD'] == 'POST'){
    
    $action = $_POST['action'];
    
    // sub_cate edit query
    
    if($action == 'sub_cate_edit'){
        $Sub_Category_id = $_POST['Sub_Category_id'];
        $Sub_Category_Desc = $_POST['Sub_Category_Desc'];
        $duration = $_POST['duration']; 
        $mobile = $_POST['mobile']; 
        $sql = "UPDATE sub_category SET Sub_Category_Desc = '$Sub_Category_Desc' , duration = '$duration' , mobile = '$mobile' WHERE Sub_Category_id = '$Sub_Category_id' " ;
        if($config->query($sql) === TRUE){
           echo '<script>window.location.href="add_course_img.php?msg=success&sid='.$Sub_Category_id.'&'.$mobile.'"</script>';
        }else {
           echo '<script>window.location.href="add_course_img.php?msg=error&sid='.$Sub_Category_id.'"</script>';
        }
    }
    
    // sub_cate img edit query 
    
    if($action == 'sub_cate_img_edit'){
        $Sub_Category_id = $_POST['Sub_Category_id'];
        // sub_cate image
        $images = $_FILES['course_image']['name'];
        $old_filename = $_POST['old_image'];
        $update_filename = "";
        if($images != NULL){
            $image_extension = pathinfo($images,PATHINFO_EXTENSION);
            $filename = time().'.'.$image_extension;
            $update_filename = $filename;
        }else{
            $update_filename = $old_filename;
        }
        
        $sql = "UPDATE sub_category SET Sub_Category_image = '$update_filename' WHERE Sub_Category_id = '$Sub_Category_id' " ;
        if($config->query($sql) === TRUE){
            // check sub_cate img 
            if($images != NULL){
                if(file_exists('../../img/course/'.$old_filename)){
                    unlink('../../img/course/'.$old_filename);
                }
                move_uploaded_file($_FILES['course_image']['tmp_name'],'../../img/course/'.$update_filename);
            }
            echo '<script>window.location.href="add_course_img.php?msg=success&sid='.$Sub_Category_id.'"</script>';
        }else {
           echo '<script>window.location.href="add_course_img.php?msg=error&sid='.$Sub_Category_id.'"</script>';
        }
    }

    // course content add
    
    if($action == 'cc_add'){
        $Sub_Category_id = $_POST['Sub_Category_id'];
        $Main_Category_sub = $_POST['Main_Category_sub'];
        $cc_title = $_POST['cc_title'];
        $cc_desc = $_POST['cc_desc'];

        $sql = "INSERT INTO course_content(cc_cate_id , cc_sub_cate_id , cc_title, cc_desc , cc_status) VALUES('$Main_Category_sub', '$Sub_Category_id', '$cc_title', '$cc_desc' , 1) " ;
        if($config->query($sql) === TRUE){
           echo '<script>window.location.href="add_course_details.php?msg=success&sid='.$Sub_Category_id.'"</script>';
        }else {
           echo '<script>window.location.href="add_course_details.php?msg=error&sid='.$Sub_Category_id.'"</script>';
        }
    }
    // course content edit
    
    if($action == 'cc_edit'){
        $Sub_Category_id = $_POST['Sub_Category_id'];
        $cc_edit_id = $_POST['cc_edit_id'];
        $cc_title = $_POST['cc_title'];
        $cc_desc = $_POST['cc_desc'];

        $sql = "UPDATE course_content SET cc_title = '$cc_title', cc_desc = '$cc_desc' WHERE cc_id = '$cc_edit_id' " ;
        if($config->query($sql) === TRUE){
           echo '<script>window.location.href="add_course_details.php?msg=success&sid='.$Sub_Category_id.'"</script>';
        }else {
           echo '<script>window.location.href="add_course_details.php?msg=error&sid='.$Sub_Category_id.'"</script>';
        }
    }
    
    // course content delete
    
    if($action == 'cc_del'){
        $cc_del_id = $_POST['cc_del_id'];
        $Sub_Category_id = $_POST['Sub_Category_id'];

        $sql = "DELETE FROM course_content WHERE cc_id = '$cc_del_id' " ;
        if($config->query($sql) === TRUE){
           echo '<script>window.location.href="add_course_details.php?msg=success&sid='.$Sub_Category_id.'"</script>';
        }else {
           echo '<script>window.location.href="add_course_details.php?msg=error&sid='.$Sub_Category_id.'"</script>';
        }
    }
    
    // course duration add
    
    if($action == 'cd_add'){
        $Sub_Category_id = $_POST['Sub_Category_id'];
        $Main_Category_sub = $_POST['Main_Category_sub'];
        $cd_title = $_POST['cd_title'];
        $cd_desc = $_POST['cd_desc'];

        $sql = "INSERT INTO course_duration(cd_cate_id , cd_sub_cate_id , cd_title, cd_desc , cd_status) VALUES('$Main_Category_sub', '$Sub_Category_id', '$cd_title', '$cd_desc' , 1) " ;
        if($config->query($sql) === TRUE){
           echo '<script>window.location.href="add_course_duration.php?msg=success&sid='.$Sub_Category_id.'"</script>';
        }else {
           echo '<script>window.location.href="add_course_duration.php?msg=error&sid='.$Sub_Category_id.'"</script>';
        }
    }
    
    // course duration edit
    
    if($action == 'cd_edit'){
        $Sub_Category_id = $_POST['Sub_Category_id'];
        $cd_edit_id = $_POST['cd_edit_id'];
        $cd_title = $_POST['cd_title'];
        $cd_desc = $_POST['cd_desc'];

        $sql = "UPDATE course_duration SET cd_title = '$cd_title', cd_desc = '$cd_desc' WHERE cd_id = '$cd_edit_id' " ;
        if($config->query($sql) === TRUE){
           echo '<script>window.location.href="add_course_duration.php?msg=success&sid='.$Sub_Category_id.'"</script>';
        }else {
           echo '<script>window.location.href="add_course_duration.php?msg=error&sid='.$Sub_Category_id.'"</script>';
        }
    }
    
    // course duration delete
    
    if($action == 'cd_del'){
        $cd_del_id = $_POST['cd_del_id'];
        $Sub_Category_id = $_POST['Sub_Category_id'];

        $sql = "DELETE FROM course_duration WHERE cd_id = '$cd_del_id' " ;
        if($config->query($sql) === TRUE){
           echo '<script>window.location.href="add_course_duration.php?msg=success&sid='.$Sub_Category_id.'"</script>';
        }else {
           echo '<script>window.location.href="add_course_duration.php?msg=error&sid='.$Sub_Category_id.'"</script>';
        }
    }
    


}


?> 



































