<?php
/*$out = array();
$db    = new PDO('mysql:host=localhost;dbname=u148573338_ga2024;charset=utf8', 'u148573338_adminga24', 'S1lvestre');
$start = $_REQUEST['from'] / 1000;
$end   = $_REQUEST['to'] / 1000;
$sql   = sprintf("SELECT * FROM evento WHERE `datetime` BETWEEN '01-01-2016' and '31-12-2016' ",
    $db->quote(date('Y-m-d', '2016-01-01')), $db->quote(date('Y-m-d', '2016-12-31')));
*/
include '../conector.php';
session_start();
date_default_timezone_set('America/Bogota');
$today = date('Y-m-d');

if(isset($_SESSION["user"]) && ($_SESSION["tipo"]=='E'||$_SESSION["tipo"]=='P')){
if($_SESSION["tipo"]=='E'){$cuenta="select estudiante.estudiante_id,estudiante.curso_id,estudiante.vernotas from estudiante where usuario='".$_SESSION["user"]."'	and estudiante.estado_est='A'";}
if($_SESSION["tipo"]=='P'){$cuenta="select estudiante.estudiante_id,estudiante.curso_id,estudiante.vernotas from estudiante where estudiante.estudiante_id=".$_SESSION["estudiante"]." ";}
$res_cuenta=mysql_query($cuenta);
$rs_cta=mysql_fetch_array($res_cuenta);


function fixBadUnicodeForJson($str) {
    $str = preg_replace("/\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})/e", 'chr(hexdec("$1")).chr(hexdec("$2")).chr(hexdec("$3")).chr(hexdec("$4")).chr(hexdec("$5"))', $str);
    $str = preg_replace("/\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})/e", 'chr(hexdec("$1")).chr(hexdec("$2")).chr(hexdec("$3")).chr(hexdec("$4"))', $str);
    $str = preg_replace("/\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})/e", 'chr(hexdec("$1")).chr(hexdec("$2")).chr(hexdec("$3"))', $str);
    $str = preg_replace("/\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})/e", 'chr(hexdec("$1")).chr(hexdec("$2"))', $str);
    $str = preg_replace("/\\\\u00([0-9a-f]{2})/e", 'chr(hexdec("$1"))', $str);
    return $str;
}

$sel_anuncio="
select * from ((select ID,mensaje,fecha_evento,docente,curso,user,fecha_pub, 
(select nombre from docente where teacher_id=evento.docente ) as nom
from evento where evento.curso='".$rs_cta[1]."' and fecha_evento>='2016-01-01'
and user=0
) 
union	
(select ID,mensaje,fecha_evento,docente,curso,user,fecha_pub, 
(select name from usuarios where usuarios.id=evento.docente ) as nom
from evento where evento.curso='".$rs_cta[1]."' and fecha_evento>='2016-01-01'
and user=1
) ) a order by a.fecha_evento DESC

			";

//$sel_anuncio="select * from evento where  fecha_evento>='2016-01-01' ";



if($res_sel_anuncio=mysql_query($sel_anuncio)){
//echo $sel_anuncio."---<br>";

$out = array();

while($rs=mysql_fetch_array($res_sel_anuncio)){
$cadena=substr($rs[1],0,1500);

//$cadena=mb_convert_encoding();
//$cadena=fixBadUnicodeForJson($cadena);

//$cadena=str_replace($cadena,'\u00c3\u00b1', '&ntilde;');
$cadena=utf8_encode(htmlentities($cadena));
//htmlentities($cadena);


$out[] = array(
        'id' => $rs[0],
        'title' => utf8_decode($cadena).'<br><font size=2 > '.$rs[7]."</font>",
        'url' => '',
        'class'=> 'event-success',
        'start' => strtotime($rs[2]) . '000',
        'end' => strtotime($rs[2]) .'000'
    );




}



}


echo json_encode(array('success' => 1, 'result' => $out));
exit;
}
?>