<?php
 	session_start(); 

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

	include("connect.php");
date_default_timezone_set("Asia/Kolkata");
$mdate1= date('Y-m-d H:i:s');
$mdate= date('d-m-Y');
	$usermid = $_SESSION['umid'];
	
	//$cmname=$_POST['cmname'];
	if(isset($_POST['imid1']))
	{
	$imid1=$_POST['imid1'];
	}
	
	$stiqmid=$_POST['stiqmid'];
	$eve2 = "select imid from res_studentinquiry_detail where stiqmid=$stiqmid";
	$re2 = mysqli_query($conn, $eve2);
	while($rt2 = mysqli_fetch_assoc($re2))

	{
		$imid1 = $rt2['imid'];
	}
	$coursemid=$_POST['coursemid'];
	$eve2 = "select collegemid,countrymid,campusmid,feesin from res_course_master where coursemid=$coursemid";
	$re2 = mysqli_query($conn, $eve2);
	while($rt2 = mysqli_fetch_assoc($re2))

	{
		$collegemid = $rt2['collegemid'];
		$countrymid = $rt2['countrymid'];
		$campusmid = $rt2['campusmid'];
		$feesin = $rt2['feesin'];
	}
	
	$coremarks=$_POST['ccoremarks'];
	$coursefees=$_POST['ccoursefees'];
	$adoapplication=date("Y-m-d", strtotime($_POST['adoapplication']));
	$aprogramstartdate=date("Y-m-d", strtotime($_POST['aprogramstartdate']));
	$aprogramenddate=date("Y-m-d", strtotime($_POST['aprogramenddate']));
	$statusmid=$_POST['statusmid'];
	$asemester=$_POST['asemester'];
	$intekyear='';
	$intekmonth='';
	
			
			$studentid = '';
			$eve2 = "select cstudentid from res_collegeapp_master where coursemid=$coursemid";
	$re2 = mysqli_query($conn, $eve2);
	while($rt2 = mysqli_fetch_assoc($re2))

	{
		$studentid = $rt2['cstudentid'];
		
	}
		
		
	
	
		$eve1 = "INSERT INTO res_admission_master (imid,stiqmid, coursemid,collegemid,countrymid,ccoremarks,ccoursefees,statusmid,adoapplication,amaddedon,amaddedby,amupdatedon,amupdatedby,astudentid,intekyear,intekmonth,campusmid,aprogramstartdate,aprogramenddate,asemester) VALUES('$imid1','$stiqmid','$coursemid','$collegemid','$countrymid','$coremarks','$coursefees','$statusmid','$adoapplication','$mdate1','$usermid','$mdate1','$usermid','$studentid','$intekyear','$intekmonth','$campusmid','$aprogramstartdate','$aprogramenddate','$asemester')";
		
			
		if ($conn->query($eve1) === TRUE)
			{
				$ptype = 'College Admission';
						$admid = $conn->insert_id;
						
						  $delete_checkbox_array1 = $_POST['asemstartmonth'];
						 
						
		$m=0;
			foreach ($delete_checkbox_array1 as $one_by_one_sid) 
			{
				$asemstartmonth=$one_by_one_sid;
						$asemstartmonth = date('m',strtotime($asemstartmonth));
				$asemstartyear=$_POST['asemstartyear'][$m];
				$asemfees=$_POST['asemfees'][$m];
				
				$m = $m + 1;
			
				
				
					  $eve2="insert into res_admissioncoursesem_detail (admid,asemstartmonth,asemstartyear,asemfees,asemfeesin,acdaddedon,acdaddedby,asem) values($admid,'$asemstartmonth','$asemstartyear','$asemfees','$feesin','$mdate1','$usermid',$m)";
					$re2 = mysqli_query($conn, $eve2);
					
				
			}
		
		
		
		/* 
		$paycurrency=$_POST['paycurrency'];
	$paycurrencyvalue=$_POST['paycurrencyvalue'];
						
						  $eve2 = "insert into res_inquiryservice_detail (imid,isaddedby,isaddedon,isupdatedby,isupdatedon,stiqmid,ispendingamount,packagefees,servicefinalrate,spaymenttype,servicepayamount,linkmid,ptype) values ($imid1,$usermid,'$mdate1',$usermid,'$mdate1','$stiqmid','$paycurrencyvalue','$paycurrencyvalue','$paycurrencyvalue','Full Payment','$paycurrencyvalue','$admid','$ptype')";
						

	if ($conn->query($eve2) === TRUE)
	{
		$isdid = $conn->insert_id;
		 $eve3 = "INSERT INTO res_payments_detail (imid,isdid, paidamount,pdaddedon,pdaddedby,pdupdatedon,pdupdatedby,paycurrency,paycurrencyvalue) VALUES('$imid1','$isdid','$paycurrencyvalue','$mdate1','$usermid','$mdate1','$usermid','$paycurrency','$paycurrencyvalue')";
		
		$re3 = mysqli_query($conn, $eve3);
	} */
			}
			else
			{
				$_SESSION['msg1'] = "Error";
			}
			
			if($_SESSION['frompage']=='aplicationInquirydetailpage')
			{
				header("Location: applicationinquirydetail.php?id=$stiqmid");
			}else{
	header("Location: inquirydetail.php?id=$imid1&tab=student_application");
			}
			
	
?>