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

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

$data  = $header;
//-$sql = "SELECT * FROM notes $where ORDER BY note_date DESC";
$sql = "SELECT id,admin_id,job_id,note_text,note_date,reminder_time FROM notes $where ORDER BY note_date 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);
	$note_date = ($row['note_date'] != "0000-00-00 00:00:00") ? date("d-m-Y",strtotime($row['note_date'])) : "";
	
	$data .= '"'.$row['job_id'].'"'.",".'"'.$row['note_text'].'"'.",".'"'.$consultant_string.'"'.",".'"'.$note_date.'"'.",".'"'.$row['reminder_time'].'"'."\n";
}

$file_name = "reminder_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;
?>