<?php
session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	date_default_timezone_set("Asia/Kolkata");
$mdate1= date('Y-m-d H:i:s');
$mdate= date('d-m-Y');
	$usermid = $_SESSION['umid'];

	$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	include("connect.php");
include("mylibrary.php"); 

	$siprefferservice=checkvalidstring ($_POST['siprefferservice']);
	
	
		$siprefferedsubservice=checkvalidstring ($_POST['siprefferedsubservice']);
	
	
	
	if($siprefferservice == 'Student Visa')
	{
	$siintakemonth=checkvalidstring ($_POST['siintakemonth']);
	
	
	
	$siintakeyear=checkvalidstring ($_POST['siintakeyear']);
	
	
	$siprfferedcollege=checkvalidstring ($_POST['siprfferedcollege']);
	
	
	$sipreffercourse=checkvalidstring ($_POST['sipreffercourse']);
	
	}else{
		$siintakemonth="";
		$siintakeyear="";
		$siprfferedcollege="";
		$sipreffercourse="";
	}
	
	
	
	//$imstatus="Followup";
	
	$imid=$_POST['imid'];
	$offermid=$_POST['ipoffer'];
	
	$siprefferedcountry=checkvalidstring ($_POST['siprefferedcountry']);
	
	
	$siremarks=checkvalidstring ($_POST['siremarks']);
	
	
	
	
	
	
	
	
	
	
	
	$status=checkvalidstring ($_POST['status']);
	
	$siprfferedcollege='';
	
	$sistatus = 'Inquiry Added';
	$inquirydate = date("Y-m-d",strtotime($_POST['inquirydate']));
	
	
	
	
	
	date_default_timezone_set("Asia/Kolkata");
	$mdate= date('Y-m-d H:i:s');
	
	
	
	  $eve1 = "INSERT INTO res_studentinquiry_detail (siintakemonth,  siprfferedcollege, sipreffercourse ,siprefferservice,siintakeyear,siprefferedcountry,status,inquirydate,siremarks,imid,siaddedon,siaddedby,siupdatedon,siupdatedby,siprefferedsubservice,sistatus,offermid) VALUES('$siintakemonth','$siprfferedcollege','$sipreffercourse' ,'$siprefferservice','$siintakeyear','$siprefferedcountry','$status','$inquirydate','$siremarks','$imid','$mdate1','$usermid','$mdate1','$usermid','$siprefferedsubservice','$sistatus','$offermid')";
	
	
	if ($conn->query($eve1) === TRUE)
	{
		
			
		
			$counsellorid=$_SESSION['umid'];
			$eve2 = "update res_inquiry_master set  idate='$inquirydate',iprefferedcountry='$siprefferedcountry' ,ipreefferedservice='$siprefferservice',ipstatus='$status',ipupdatedon='$mdate',ipupdatedby='$usermid' where imid=$imid";
			$re2 = mysqli_query($conn, $eve2);
			
			$date1 = date("Y-m-d",strtotime("+2 days"));
			$date2 = date("Y-m-d",strtotime("+4 days"));
			$date3 = date("Y-m-d",strtotime("+7 days"));
			
			$eve4 = "insert into res_upcomingfollowup_master (imid, ufdate, ufremark,ufaddedby,ufaddedon,stiqmid) values ($imid,'$date1','Call',$usermid,'$mdate','$stiqmid')";
			$re4 = mysqli_query($conn, $eve4);
			$eve5 = "insert into res_upcomingfollowup_master (imid, ufdate, ufremark,ufaddedby,ufaddedon,stiqmid) values ($imid,'$date2','Call',$usermid,'$mdate','$stiqmid')";
			$re5 = mysqli_query($conn, $eve5);
			$eve6 = "insert into res_upcomingfollowup_master (imid, ufdate, ufremark,ufaddedby,ufaddedon,stiqmid) values ($imid,'$date2','Call',$usermid,'$mdate','$stiqmid')";
			$re6 = mysqli_query($conn, $eve6);
		
	
		$_SESSION['msg'] = "Record saved successfully";
	}
	else
	{
		$_SESSION['msg1'] = "Error";
	}
	header('Location: inquirydetail.php?id='.$imid.'#student_inquires');
?>