<?php  
session_start(); 

if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	 $eve = "select * from res_college_master,res_contact_master where res_contact_master.clinkid = res_college_master.collegemid and res_contact_master.clinktype = 'College'";
	$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))
		 {
			 	$attechment=$rt['cmattechment'];
				
				if ($attechment != ""){
				
				   $attechment="<a target='_blank' href='./docs/$attechment'>download</a>";
				}
				else		
				{
					$attechment="";
				}
				$collegemid=$rt['collegemid'];
				
				$countrymid=$rt['ccountry'];
				
				$pidedit="<a href='collegeedit.php?id=".$rt['collegemid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
				
				
				$piddelete="<a href='collegedelete.php?id=".$rt['collegemid']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='fa fa-trash-o fa-lg'> </a>";		
$op=$pidedit."&nbsp;&nbsp;&nbsp; ".$piddelete;
								
								
				$cmname=str_replace ("'","'",$rt['cmname']);
				$cmname=str_replace ('"','\"',$cmname);
				
				$cmaddress1=str_replace ("'","'",$rt['caddress1']);
				$cmaddress1=str_replace ('"','\"',$cmaddress1);
				
				$cmaddress2=str_replace ("'","'",$rt['caddress2']);
				$cmaddress2=str_replace ('"','\"',$cmaddress2);
				
				$cmaddress = $cmaddress1." ".$cmaddress2;
				
				$cmiddlename=str_replace ("'","'",$rt['cmiddlename']);
				$cmiddlename=str_replace ('"','\"',$cmiddlename);
				
				$contactname=str_replace ("'","'",$rt['contactname']);
				$contactname=str_replace ('"','\"',$contactname);
				$csurname=str_replace ("'","'",$rt['csurname']);
				$csurname=str_replace ('"','\"',$csurname);
				
				$cmcontactperson = $contactname." ".$cmiddlename." ".$csurname;
				
				
				$cmphone=str_replace ("'","'",$rt['contactnumber']);
				$cmphone=str_replace ('"','\"',$cmphone);
				
				$cmemail=str_replace ("'","'",$rt['contactemail']);
				$cmemail=str_replace ('"','\"',$cmemail);
				
				$eve2= "select countryname from res_country_master where countrymid=$countrymid";
					$re2 = mysqli_query($conn, $eve2);
					 while($rt2 = mysqli_fetch_assoc($re2))
					{
						$countryname=$rt2['countryname'];
					}
				
				
								
				$posts[] = array('srno'=> $i++,'op'=> $op, 'cmname'=> $cmname, 'cmaddress'=> $cmaddress, 'cmcontactperson'=> $cmcontactperson, 'cmphone'=> $cmphone, 'cmemail'=> $cmemail, 'countryname'=> $countryname);
		 }
		 
		$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);
	
	
?>