<?php  
session_start(); 
if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
	include("connect.php");	header("Access-Control-Allow-Origin: *");
	$umid=$_SESSION['umid'];
	
										$campusmid1=$_SESSION['campusmid1'];
										
										$ctidid = $_SESSION['ctidid'];
		  $eve1="SELECT * FROM res_commissiontermintake_detail  where ctidid = $ctidid  ";
	$re1 = mysqli_query($conn, $eve1);

    if(mysqli_num_rows($re1) > 0)
	{
	  while($rt1 = mysqli_fetch_assoc($re1))
		{
			/* $coursemid=$rt['coursemid'];
			$_SESSION['selectedcourse']=$coursemid; */
			$ctistartmonth=$rt1['ctistartmonth'];
			
			$ctistartyear=$rt1['ctistartyear'];
			$ctiendmonth=$rt1['ctiendmonth'];
			$ctieendyear=$rt1['ctieendyear'];
			
		}
	}
	
	$startmonth = date('m',strtotime($ctistartmonth));
	$startyear = date('Y',strtotime($ctistartyear));
	$endmonth = date('m',strtotime($ctiendmonth));
	$endyear = date('Y',strtotime($ctieendyear));
	
	$startintake  = date('Y-m-d',strtotime('01-'.$startmonth.'-'.$startyear));
	$endintake  = date('Y-m-t',strtotime('01-'.$endmonth.'-'.$endyear));
	
	

		$aa = "and Concat((res_admissioncoursesem_detail.asemstartyear ) ,'-' , LPAD(res_admissioncoursesem_detail.asemstartmonth, 2, '0'),'-01') >='$startintake' and Concat((res_admissioncoursesem_detail.asemstartyear  ) ,'-' , LPAD(res_admissioncoursesem_detail.asemstartmonth, 2, '0'),'-01')  <= '$endintake' ";
	/* 	$aa = "and date(CONCAT(res_admission_master.intekyear,'-',res_admission_master.intekmonth,'-01') >='$startintake' and date(CONCAT(res_admission_master.intekyear,'-',res_admission_master.intekmonth,'-01') <= '$endintake' ";
		$aa = "and DATEFROMPARTS(res_admission_master.intekyear,res_admission_master.intekmonth,01) >='$startintake' and DATEFROMPARTS(res_admission_master.intekyear,res_admission_master.intekmonth,01) <= '$endintake' "; */
	
	 
	/*  echo $eve = "select * from res_inquiry_master,res_admission_master,res_course_master where res_admission_master.imid = res_inquiry_master.imid and  res_admission_master.admid in (select linkmid from res_inquiryservice_detail where ispendingamount < 1 and ptype='College Admission') and res_course_master.coursemid = res_admission_master.coursemid and res_course_master.campusmid = res_admission_master.campusmid and res_admission_master.campusmid in (select ccampusmid from res_commissioncampus_detail where campusmid=$campusmid1 and commissionmid in (select commissionmid from res_commission_master where termsclaimable >= res_admission_master.intaketerm ) )  and res_course_master.campusmid = $campusmid1 $aa"; */
	 
	   $eve = " SELECT * FROM res_inquiry_master, res_admission_master,res_admissioncoursesem_detail, res_course_master WHERE res_admission_master.imid = res_inquiry_master.imid  
  AND res_course_master.coursemid = res_admission_master.coursemid AND res_admissioncoursesem_detail.admid = res_admission_master.admid
  AND res_course_master.campusmid = res_admission_master.campusmid and   res_admissioncoursesem_detail.acsdid not in (select acsdid from res_invoice_detail) and res_course_master.campusmid in (select ccampusmid from res_commissioncampus_detail where  commissionmid in (select commissionmid from res_commission_master where termsclaimable >= res_admissioncoursesem_detail.asem ) ) AND   res_course_master.campusmid = $campusmid1 $aa";
	$re = mysqli_query($conn,$eve);
	$response = array();
	$posts = array();
	
	$result="0";
	
	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		 while($rt = mysqli_fetch_assoc($re))
		 {
			 	$ipname=$rt['ipname'];
			 	$imid=$rt['imid'];
			 	$admid=$rt['admid'];
			 	$acsdid=$rt['acsdid'];
			 	$asem=$rt['asem'];
				$ipmiddlename=$rt['ipmiddlename'];
				$ipsurname=$rt['ipsurname'];
				$capplicationfee=$rt['capplicationfee'];
				$studentid=$rt['astudentid'];
				$intekyear=$rt['asemstartyear'];
				
				$adintakemonth = sprintf("%02s", $rt['asemstartmonth']);

$adintakemonth = date('F',strtotime("01-".$adintakemonth."-".date("Y")));
				$intake = $adintakemonth.','.$intekyear;
				$ipname=$ipname." ".$ipmiddlename." ".$ipsurname;
						$adoapplication=date("d-m-Y",strtotime($rt['adoapplication']));
						$coursemid=$rt['coursemid'];
											 $eve22 = "select coursename from res_course_master,res_coursename_master where res_course_master.coursemid=$coursemid and     res_coursename_master.cnmid = res_course_master.cnmid";
											$re22 = mysqli_query($conn, $eve22);
											while($rt22 = mysqli_fetch_assoc($re22))
										{
											$coursename = $rt22['coursename'];
										}	

								
				
								
				$posts[] = array('srno'=> $i++,'ipname'=> $ipname, 'adoapplication'=> $adoapplication, 'coursename'=> $coursename, 'intake'=> $intake, 'term'=> $asem, 'studentid'=> $studentid, 'acsdid'=> $acsdid);
		 }
		 
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		mysqli_close($conn);
		return;
	}
	
   else
   {
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
   }   
	mysqli_close($conn);	
	
?>