<?
ob_clean();
include("../../startup.php"); 
###########################################  	END  FILTER CONITIONS 	#####################################

$header = "id,description,consultant,date,time\n";

$data  = $header;
$sql = "SELECT * FROM appointment $where ORDER BY id DESC";

$rs = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($rs)){
	
	$admin_id = explode(",",$row['admin_id']);
	$consultant_string = "";
	foreach($admin_id as $a_id){
		$consultant_string .= ucfirst(utility::getTableFieldById("admin","name","id",$a_id))."#";
	}
	$consultant_string = substr($consultant_string,0,-1);
	$appointment_date = ($row['appointment_date'] != "0000-00-00 00:00:00") ? date("d-m-Y",strtotime($row['appointment_date'])) : "";
	
	$data .= '"'.$row['job_id'].'"'.",".'"'.$row['appointment_text'].'"'.",".'"'.$consultant_string.'"'.",".'"'.$appointment_date.'"'.",".'"'.$row['appointment_time'].'"'."\n";
}

$file_name = "appointment_details_export.csv";
ob_clean();
echo $data;
header("Content-type: application/csv"); 
header("Content-Disposition: attachment; filename=$file_name");
header("Pragma: no-cache");
header("Expires: 0");
die;
?>