<?php 
header("Content-Language: es-co");
header('Content-Encoding: UTF-8');
header("Content-Description: File Transfer");
header('Content-Type: text/csv; charset=utf-8' );
session_start();
require('../45789417/ref4780.php');
if (!isset($_SESSION['userid'])) {
  echo "<script language='Javascript'> location.href='../login.php';</script>";
    exit();
  };
		    /* citas x dia */
		    $date1 = $_GET['date1'];
		    if($date1 != ''){
		    	header('Content-Disposition: attachment; filename=Citas_dia_'.$date1.'.csv');
		   		$result = mysqli_query($con,"SELECT * FROM se_evenement WHERE start like '$date1%' ORDER BY name");
		    	$shtml=  $shtml."Fecha cita;Nombre;Tipo de doc;Cedula;Telefono;Descripcion;Tipo de cita;Estado;Pago;Continuo;Como se entero;Atendido por";
		    	$shtml= $shtml."\r\n";
				while ($reg = mysqli_fetch_array($result)){
					$shtml=	$shtml."".$reg['start'].";"
							.$reg['name'].";"
							.$reg['tipo_cc'].";"
							.$reg['title'].";"
							.$reg['cell'].";"
							.preg_replace('/\r\n|\n\r|\n|\r|;/',' -  ',strtoupper($reg['description'])).";"
							.$reg['t_servicio'].";"
							.$reg['status'].";"
							.$reg['pay'].";"
							.$reg['continua'].";"
							.$reg['como_entero'].";"
							.$reg['atendido'];
					$shtml= $shtml."\r\n";
					}
				echo $shtml; 						
			};
		    /* citas x mes */
		    $date2 = $_GET['date2'];
		    if($date2 != ''){
		    header('Content-Disposition: attachment; filename=Citas_mes_'.$date2.'.csv');
		    $result = mysqli_query($con,"SELECT * FROM se_evenement WHERE start like '%$date2%' ORDER BY name");
		    	$shtml=  $shtml."Fecha cita;Nombre;Tipo de doc;Cedula;Telefono;Descripcion;Tipo de cita;Estado;Pago;Continuo;Como se entero;Atendido por";
		    	$shtml= $shtml."\r\n";
				while ($reg = mysqli_fetch_array($result)){
					$shtml=	$shtml."".$reg['start'].";"
							.$reg['name'].";"
							.$reg['tipo_cc'].";"
							.$reg['title'].";"
							.$reg['cell'].";"
							.preg_replace('/\r\n|\n\r|\n|\r|;/',' -  ',strtoupper($reg['description'])).";"
							.$reg['t_servicio'].";"
							.$reg['status'].";"
							.$reg['pay'].";"
							.$reg['continua'].";"
							.$reg['como_entero'].";"
							.$reg['atendido'];
					$shtml= $shtml."\r\n";
					}
				echo $shtml; 						
			};
?>
