<?php









//user_action.php









include('db_con.php');




if (isset($_SESSION['user_id'])) {




    $user_type = $_SESSION['user_type'];




    $user_id = $_SESSION['user_id'];




    $user_name = $_SESSION['user_name'];




    $branch_id = $_SESSION['branch_id'];




    $branch_name = $_SESSION['branch_name'];




    $store_id = $_SESSION['store_id'];




    $store_name = $_SESSION['store_name'];




}else{




  header('Location: login');




  die();




}




$dated = date('Y-m-d');









if(isset($_POST['btn_action']))









{









	if($_POST['btn_action'] == 'Add')




	{




		




		




		$query = "




		INSERT INTO titles (heading1,heading2,heading3)




        VALUES (:heading1, :heading2, :heading3)




    ";	




		$statement = $connect->prepare($query);




		$statement->execute(




			array(




          




         




           ':heading1'          =>  trim($_POST["heading1"]),




          ':heading2'          =>  trim($_POST["heading2"]),       




          ':heading3'          =>  trim($_POST["heading3"]),




          




          )




		);









		




		//$result = $statement->fetchAll();




		if(isset($result))




		{




			echo 'New Title Added';




		}




	}




	if($_POST['btn_action'] == 'fetch_single')




	{




		$query = "




		SELECT * from titles where id = :id";




		




		$statement = $connect->prepare($query);




		$statement->execute(




			array(




				':id'	=>	$_POST["id"]




			)




		);




		$result = $statement->fetchAll();




		foreach($result as $row)




		{




			




			




			




          $output['heading1']          =  $row['heading1'];




          $output['heading2']          =  $row['heading2'];          




          $output['heading3']          =  $row['heading3'];




          




		}




		echo json_encode($output);




	}




	if($_POST['btn_action'] == 'Edit')




	{




		




		




			$query = "




			UPDATE titles SET




				




				heading1 = '".$_POST["heading1"]."',




				heading2 = '".$_POST["heading2"]."',												




				heading3 = '".$_POST["heading3"]."'




				WHERE id = '".$_POST["id"]."'




			";




		




		$statement = $connect->prepare($query);




		$statement->execute();




		//$result = $statement->fetchAll();




		if(isset($result))




		{




			echo 'Title Details Edited';




		}




	}




	if($_POST['btn_action'] == 'delete')




	{




		




		$query = "




		delete from titles where id = :id




		";




		$statement = $connect->prepare($query);




		$statement->execute(




			array(




				':id'	=>	$_POST["id"]




			)




		);




			




		//$result = $statement->fetchAll();	




		if(isset($result))




		{




			echo 'DELETED ';




		}




	}




}









?>