<?php


 error_reporting(0);

include("../include/config.php"); 


##########################################################################################

//For Insert Data
if(array_key_exists("add_new_testimonials",$_REQUEST)){
    
//    echo "add_new_testimonials"; die;
    $name = $_POST['name'];
    $comment = mysqli_real_escape_string($conn,$_POST['comment']);

   
    
            //Preview_file
$fileName1 = time().$_FILES["Preview_photo"]["name"]; 
$fileTmpLoc1 = $_FILES["Preview_photo"]["tmp_name"]; 
$fileType1 = $_FILES["Preview_photo"]["type"];
$fileSize1 = $_FILES["Preview_photo"]["size"];
$fileErrorMsg1 = $_FILES["Preview_photo"]["error"];
$kaboom1 = explode(".", $fileName1); 
$fileExt1 = end($kaboom1);
    
  
$moveResult1 = move_uploaded_file($fileTmpLoc1, "upload-files/$fileName1"); 
    
if($moveResult1!= true) 
{ 
echo "ERROR: File not uploaded1. Try again.";   
unlink($fileTmpLoc1); 
    
exit(); 
} 
    
    
    $query="INSERT INTO `testimonials`(`name`, `photo`, `feedback`, `status`) VALUES ('$name', '$fileName1', '$comment', 'active')";
			echo $query;
            
            
			if (mysqli_query($conn, $query)) {
				header("location:view-testimonials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
}

##################################################################################################

//For Update Data
if(array_key_exists("update_testimonials",$_REQUEST)){


//	echo "updat update_testimonials"; die;
    $testi_id = $_POST['testi_id'];
    $name = $_POST['name'];
    $comment = mysqli_real_escape_string($conn,$_POST['comment']);

    $Preview_photo = $_POST['testi_photo']; 
    
            //Preview_file
$fileName1 = time().$_FILES["Preview_photo"]["name"]; 
$fileTmpLoc1 = $_FILES["Preview_photo"]["tmp_name"]; 
$fileType1 = $_FILES["Preview_photo"]["type"];
$fileSize1 = $_FILES["Preview_photo"]["size"];
$fileErrorMsg1 = $_FILES["Preview_photo"]["error"];
$kaboom1 = explode(".", $fileName1); 
$fileExt1 = end($kaboom1);
    
  
$moveResult1 = move_uploaded_file($fileTmpLoc1, "upload-files/$fileName1"); 
    

    if(empty($_FILES['Preview_photo']['name']))
    { 
        $fileName1 = $Preview_photo;
    }
    
            
    $query="UPDATE `testimonials` SET `name` = '$name' , `photo` = '$fileName1', `feedback` = '$comment' WHERE `testimonials`.`id`='$testi_id';";
			echo $query;
            
            
			if (mysqli_query($conn, $query)) {
				header("location:view-testimonials.php");
            }
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
}

##################################################################################################

//For detete Delete_ebook data
if(array_key_exists("Delete_testimonial",$_REQUEST)){
    
    $t_id = $_GET['id'];
    
//  echo $t_id; die;
    
        
    $query="DELETE FROM `testimonials` WHERE `testimonials`.`id` = '$t_id'";
	        
			if (mysqli_query($conn, $query)) {
				header("location:view-testimonials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
}

##########################################################################################

// status active status_active_ebook  data
if(array_key_exists("status_active_testimoniale",$_REQUEST)){
   
        $net_id = $_GET['id'];
        
        	 $query="UPDATE `testimonials` SET `status` = 'active' WHERE `testimonials`.`id` = '$net_id'";

			if (mysqli_query($conn, $query)) {
				header("location:view-testimonials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
    
}

##########################################################################################
// status deactive status_deactive_ebook data
if(array_key_exists("status_deactive_testimonial",$_REQUEST)){
    
  $net_id = $_GET['id'];
        
        	 $query="UPDATE `testimonials` SET `status` = 'deactive' WHERE `testimonials`.`id` = '$net_id'";
		
            
			if (mysqli_query($conn, $query)) {
				header("location:view-testimonials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
    
}


##################################################################################################
//Other Material
##########################################################################################

//For Insert Data of Other Material
if(array_key_exists("add_other_materials",$_REQUEST)){
    
//    echo "add_other_materials"; die;
    $topic_Name = $_POST['topic_Name'];
    $url = create_slug($topic_Name);
//    $image_a = $_POST['image_a'];
     $uploaded_date = date("d-m-Y");
            
$fileName = time().$_FILES["image"]["name"]; 
$fileTmpLoc = $_FILES["image"]["tmp_name"]; 
$fileType = $_FILES["image"]["type"];
$fileSize = $_FILES["image"]["size"];
$fileErrorMsg = $_FILES["image"]["error"];
$kaboom = explode(".", $fileName); 
$fileExt = end($kaboom);
    
  
$moveResult = move_uploaded_file($fileTmpLoc, "other-material-files/$fileName"); 
    
if($moveResult!= true) 
{ 
echo "ERROR: File not uploaded. Try again.";   
unlink($fileTmpLoc); 
    
exit(); 
} 
        
    $query="INSERT INTO `other_materials`(`topic_name`, `url`, `upload_file`, `uploaded_date`, `status`) VALUES ('$topic_Name', '$url', '$fileName', '$uploaded_date', 'active')";
			
            
            
			if (mysqli_query($conn, $query)) {
				header("location:add-other-materials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
}


##################################################################################################

//For Update Data
if(array_key_exists("update_other_materials",$_REQUEST)){
    
    $sub_id = $_POST['uploaded_id'];
    $topic_Name = $_POST['topic_Name'];
    $url = create_slug($topic_Name);
   $uploaded_file = $_POST['uploaded_file'];
    
            
$fileName = time().$_FILES["image"]["name"]; 
$fileTmpLoc = $_FILES["image"]["tmp_name"]; 
$fileType = $_FILES["image"]["type"];
$fileSize = $_FILES["image"]["size"];
$fileErrorMsg = $_FILES["image"]["error"];
$kaboom = explode(".", $fileName); 
$fileExt = end($kaboom);
    
  
$moveResult = move_uploaded_file($fileTmpLoc, "other-material-files/$fileName"); 
    

   
    if(empty($_FILES['image']['name']))
    { 
        $fileName = $uploaded_file;
    }
    
     $query = "UPDATE `other_materials` SET `topic_name` = '$topic_Name', `url` = '$url', `upload_file` = '$fileName' WHERE `other_materials`.`id` = '$sub_id'";
    
    echo $query;
			
            
            
			if (mysqli_query($conn, $query)) {
				header("location:add-other-materials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
}

##################################################################################################

//For detete data
if(array_key_exists("Delete_other_material_Topic",$_REQUEST)){
    
    $t_id = $_GET['id'];
    
//  echo Delete_other_material_Topic; die;
    
        
    $query="DELETE FROM `other_materials` WHERE `other_materials`.`id` = '$t_id'";
			
            
            
			if (mysqli_query($conn, $query)) {
				header("location:add-other-materials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
}

##########################################################################################

// status active other  other material_topic  data
if(array_key_exists("status_active_other_material",$_REQUEST)){
   
        $net_id = $_GET['id'];
        
        	 $query="UPDATE `other_materials` SET `status` = 'active' WHERE `other_materials`.`id` = '$net_id'";

			if (mysqli_query($conn, $query)) {
				header("location:add-other-materials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
    
}

##########################################################################################
// status deactive other material_topic data
if(array_key_exists("status_deactive_other_material",$_REQUEST)){
    
  $net_id = $_GET['id'];
        
        	 $query="UPDATE `other_materials` SET `status` = 'deactive' WHERE `other_materials`.`id` = '$net_id'";
		
            
			if (mysqli_query($conn, $query)) {
				header("location:add-other-materials.php");
			} 
            
			else {
				include('include/error-modal.php');
			}
			mysqli_close($conn);
    
}


##################################################################################################
?>
