<?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');
$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	$umid = $_SESSION['umid'];
	include("connect.php");

	
	//$cmname=$_POST['cmname'];
	
	 $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'];
	}
	
	$batchmid=$_POST['batchmid'];
	
	
	
	
		 $eve1 = "INSERT INTO res_batchallocation_detail (imid,stiqmid,batchmid,baaddedon,baaddedby,baupdatedon,baupdatedby) VALUES('$imid1','$stiqmid','$batchmid','$mdate1','$umid','$mdate1','$umid')";
		
		if ($conn->query($eve1) === TRUE)
		{
			$last_id = $conn->insert_id;
				 $eve11 = "select * from res_batch_master where batchmid=$batchmid";
				$re11 = mysqli_query($conn,$eve11);
				while($rt11 = mysqli_fetch_assoc($re11))
				{
					$batchstartdate=date("Y-m-d",strtotime($rt11['batchstartdate']));
					$batchenddate=date("Y-m-d",strtotime($rt11['batchenddate']));
				}
				
				
				$batchstartdate1=date("Y-m-d",strtotime($batchstartdate.'-1 day'));
				$batchstardate10= date('l',strtotime($batchstartdate.'-1 day'));
				
				$diff = abs(strtotime($batchenddate) - strtotime($batchstartdate));

			 $days = floor($diff / (60*60*24));

				
			  
				for($j=0;$j<=$days;$j++)
											{
									 
									 $batchstartdate1= date('Y-m-d',strtotime($batchstartdate1.'+1 day'));
									  
									  $batchstardate10= date('l',strtotime($batchstardate10.'+1 day'));
									
						if($batchstardate10 != 'Sunday')
						{							
				
			$eve12 = "INSERT INTO res_attendence_detail (imid,attendence,batchmid,attendancedate,badid) VALUES('$imid1',0,'$batchmid','$batchstartdate1','$last_id')";
			$re12 = mysqli_query($conn,$eve12);
						}
											}
											
											 
			
		}
		else
		{
			$_SESSION['msg1'] = "Error";
		}
	
	header("Location: coachinginquirydetail.php?id=$stiqmid");
			
	
?>