<?php
 	session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}



$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	
	include("connect.php");
include("mylibrary.php");
	$csubject='';
	//$traningsubservicename=$_POST['traningsubservicename'];
	$cdepartment=checkvalidstring ($_POST['cdepartment']);
	$cmessage=checkvalidstring ($_POST['cmessage']);
	$cemailsubject=checkvalidstring ($_POST['cemailsubject']);
	if($cdepartment == 'Accounts')
	{
	 $csubject=checkvalidstring ($_POST['csubjectaccount']);
	}else if($cdepartment == 'Application')
	{
	 $csubject=checkvalidstring ($_POST['csubjectapplication']);
	}else if($cdepartment == 'Counselor')
	{
	 $csubject=checkvalidstring ($_POST['csubjectcounselor']);
	}else if($cdepartment == 'Visa Manager')
	{
	 $csubject=checkvalidstring ($_POST['csubjectvisamanager']);
	}else if($cdepartment == 'Reception')
	{
	 $csubject=checkvalidstring ($_POST['csubjectreception']);
	}else if($cdepartment == 'Agent Network')
	{
	 $csubject=checkvalidstring ($_POST['csubjectagentnetwork']);
	}else if($cdepartment == 'HR')
	{
	 $csubject=checkvalidstring ($_POST['csubjecthr']);
	}
	
		 $csubject;
		
	$eve = "select * from res_communication_master where csubject='$csubject' and cdepartment='$cdepartment' and ctemplatetype='Email'  ";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg1'] = " Already Inserted.";
		header('Location: emailtemplate.php');
	}
	else
	{	
		  $eve1 = "INSERT INTO res_communication_master (csubject, cdepartment,cmessage,cemailsubject,cstatus,ctemplatetype) VALUES('$csubject','$cdepartment','$cmessage','$cemailsubject','Active','Email')";
		 
		
		$re1 = mysqli_query($conn, $eve1);
			
	$_SESSION['msg'] = "Record saved successfully";
	header('Location: emailtemplate.php');
			
	}
?>