<?php
/*$out = array();
$db    = new PDO('mysql:host=sql101.mipropia.com;dbname=mipc_21018021_ga2018;charset=utf8', 'mipc_21018021', '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';
date_default_timezone_set('America/Bogota');
$today = date('Y-m-d');
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 evento where  fecha_evento>='2018-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).'',
        'url' => '',
        'class'=> 'event-warning',
        'start' => strtotime($rs[2]) . '000',
        'end' => strtotime($rs[2]) .'000'
    );




}


/*foreach($arreglo as $row) {

    $out[] = array(
        'id' => $row->id,
        'title' => $row->mensaje,
        'url' => 'http://www.example.com/',
        'start' => strtotime($row->fecha_evento) . '000',
        'end' => strtotime($row->fecha_evento) .'000'
    );
}*/


}


/*
 for($i=1; $i<=15; $i++){   //from day 01 to day 15
    $data = date('Y-m-d', strtotime("+".$i." days"));
    $out[] = array(
        'id' => $i,
        'title' => 'Event name '.$i,
        'url' => 'http://www.example.com/',
        'class' => 'event-important',
        'start' => strtotime($data).'000'
    );
}*/

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