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

	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	$aa="";
	if( isset($_SESSION['countrymid']))
	{
		if($_SESSION['countrymid']=="All")
		{
		$aa="";
		}
		else
		{
			$aa=" and res_college_master.countrymid=".$_SESSION['countrymid'];
		}
	}
	
	$bb="";
	if( isset($_SESSION['coursemid']))
	{
		if($_SESSION['coursemid']=="all")
		{
		
		}
		else
		{
				$cname21=$_SESSION['coursemid'];
			$bb=" and res_course_master.cmdesc='$cname21'";
		}
	}
	
	
	 $eve = "select * from res_course_master,res_college_master  where res_course_master.collegemid = res_college_master.collegemid and res_course_master.collegemid = res_college_master.collegemid $aa $bb";
	$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))
		 {
			 	
				//$countryname=$rt['countryname'];
				
				$coursemid=$rt['coursemid'];
				
				
				$collegemid=$rt['collegemid'];
				$losmid=$rt['levelofstudy'];
				$countrymid=$rt['countrymid'];
				$cnmid=$rt['cnmid'];
				
				$cmpbroucher=$rt['cmpbroucher'];
				$cmcoursebroucher=$rt['cmcoursebroucher'];
				
				$pidedit="<a href='courseedit.php?id=".$rt['coursemid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
				
				$cmpbroucher1="<a target='_blank' href='./docs/$cmpbroucher'>download</a>";
				
				$cobroucher="<a target='_blank' href='./docs/$cmcoursebroucher'>download</a>";
				
				
				$piddelete="<a href='coursedelete.php?id=".$rt['coursemid']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>";				
					$op=$pidedit."&nbsp;&nbsp;&nbsp; ".$piddelete;			
				$cmdesc=str_replace ("'","'",$rt['cmdesc']);
				$cmdesc=str_replace ('"','\"',$cmdesc);
				
				$cmduration=str_replace ("'","\'",$rt['cmduration']);
				$cmduration=str_replace ('"','\"',$cmduration);
				
				$cmfees=str_replace ("'","\'",$rt['cmfees']);
				$cmfees=str_replace ('"','\"',$cmfees);
				
				$cmdocument=str_replace ("'","\'",$rt['cmdocument']);
				$cmdocument=str_replace ('"','\"',$cmdocument);
				
				$cmeligibility=str_replace ("'","\'",$rt['cmeligibility']);
				$cmeligibility=str_replace ('"','\"',$cmeligibility);
				
				$cmfacility=str_replace ("'","\'",$rt['cmfacility']);
				$cmfacility=str_replace ('"','\"',$cmfacility);
				
				$cmremarks=str_replace ("'","\'",$rt['cmremarks']);
				$cmremarks=str_replace ('"','\"',$cmremarks);
				
				$cmother=str_replace ("'","\'",$rt['cmother']);
				$cmother=str_replace ('"','\"',$cmother);
				
				
					
						$cmname=$rt['cmname'];
						$cmpbroucher=$rt['cmpbroucher'];
						if($cmpbroucher==""){
							$cmpbroucher1="";
							}
						else{
						$cmpbroucher1="<a target='_blank' href='./docs/$cmpbroucher'>download</a>";
						}
						$cmcoursebroucher=$rt['cmcoursebroucher'];
						if($cmcoursebroucher==""){
							$cmcoursebroucher1="";
							}
						else{
						$cmcoursebroucher1="<a target='_blank' href='./docs/$cmcoursebroucher'>download</a>";
						}
						
						
					
					
					$countryname="";
					$eve5= "select * from   res_country_master where countrymid=$countrymid";
					$re5 = mysqli_query($conn, $eve5);
					 while($rt5 = mysqli_fetch_assoc($re5))
					{
			
						//$losmid=$rt4['losmid'];
						$countryname=$rt5['countryname'];
						
					}
					$coursename="";
					$eve55= "select * from   res_coursename_master where cnmid=$cnmid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$coursename=$rt55['coursename'];
						
					}
					$levelofstudy="";
					$eve55= "select * from   res_levelofstudy_master where losmid=$losmid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						$losmid=$rt55['losmid'];
						$levelofstudy=$rt55['levelofstudy'];
						
					}
					
					
				$cemail="<a target='_blank' href='sendcoursedetail.php?id=$coursemid'>Send</a>";
								
				$posts[] = array('srno'=> $i++,'cmdesc'=> $cmdesc, 'cmname'=> $cmname,'levelofstudy'=>$levelofstudy,'countrymid'=>$countrymid,'cmduration'=> $cmduration, 'cmfees'=> $cmfees, 'cmeligibility'=> $cmeligibility, 'cmfacility'=> $cmfacility, 'cmdocument'=> $cmdocument, 'cmremarks'=> $cmremarks, 'cmother'=> $cmother, 'cmpbroucher'=> $cmpbroucher, 'cmcoursebroucher1'=> $cmcoursebroucher1,'countryname'=>$countryname,'cmpbroucher1'=>$cmpbroucher1,'cemail'=>$cemail,'coursename'=>$coursename,'op'=>$op);
		 }
		 
		$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);
	
	
?>