<?php
session_start();
include('connect.php');
error_reporting(0);

date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d H:i:s');
	
	$idate=date('Y-m-d');

if(isset($_POST["stiqmid"]) && !empty($_POST["stiqmid"])){
   
	
	$stiqmid=$_POST['stiqmid'];
	//$stiqmid=12;
	
	
	$eve1 = "select res_studentinquiry_detail.siprefferedcountry,res_studentinquiry_detail.siprefferedsubservice,res_studentinquiry_detail.offermid,res_inquiry_master.inqbranch from res_inquiry_master,res_studentinquiry_detail where res_studentinquiry_detail.imid = res_inquiry_master.imid and res_studentinquiry_detail.stiqmid = $stiqmid";
	$re1 = mysqli_query($conn, $eve1);
	  if(mysqli_num_rows($re1) > 0)
	{
		
        while($rt1 = mysqli_fetch_assoc($re1))
		{
			$siprefferedcountry = $rt1['siprefferedcountry'];
			$inqbranch = $rt1['inqbranch'];
			$siprefferedsubservice = $rt1['siprefferedsubservice'];
			$offermid1 = $rt1['offermid'];
		}
	}
	
	
	if($siprefferedcountry == 0)
	{
		$eve = "select * from res_offer_master where offermid in (select offermid from res_offerbranch_detail where branchmid=$inqbranch ) and  offermid in (select offermid from res_offersubservice_detail where subservicemid=$siprefferedsubservice )   and offervalidtill > '$idate' and offerstartdate <= '$idate'";
		
	}else{
	
		 $eve = "select * from res_offer_master where offermid in (select offermid from res_offerbranch_detail where branchmid=$inqbranch ) and offermid in (select offermid from res_offercountry_detail where countrymid=$siprefferedcountry ) and offermid in (select offermid from res_offersubservice_detail where subservicemid=$siprefferedsubservice ) and offervalidtill > '$idate' and offerstartdate <= '$idate'";
	}
		
	
	$re = mysqli_query($conn, $eve);
	
	// echo '<option value="'.$eve.'">'.$eve.'</option>';
    //Count total number of rows
    if(mysqli_num_rows($re) > 0)
	{
		echo '<option value="0">Select</option>';
        while($rt = mysqli_fetch_assoc($re))
		{
			/* $coursemid=$rt['coursemid'];
			$_SESSION['selectedcourse']=$coursemid; */
			$offermid=$rt['offermid'];
			
			$offername=$rt['offername'];
			if($offermid1 == $offermid)
			{
			
            echo '<option value="'.$offermid.'" selected>'.$offername.'</option>';
			}else{
				 echo '<option value="'.$offermid.'" >'.$offername.'</option>';
			}
        }
    }else{
        echo '<option value="0">Select </option>';
    }
}
?>
