* User: Stefan
 * Date: 29.7.2015
 * Time: 0:14
 */
require_once 'core/init.php';
if (!isset($_SESSION["id_korisnika"])) {
    header("Location:index.php");
    die;
} else {
    $id_korisnika = $_SESSION["id_korisnika"];
}
if (isset($_GET['q'])) {
    $id = sanitize($_GET['q']);
    $v = new Vest($id);
    $lat = $v->lat();
    $lng = $v->lng();
    $naziv = $v->grad();
} else {
    die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>CMS</title>
<?php 
require "includes/header.php";
?>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCqECZ8wTuVbGEVFw1o3TlwL4qhvMwYsn0"></script>
    <script type="text/javascript" src="includes/init.js"></script>
</head>
 * Date: 12.6.2015
 * Time: 13:20
 */
$vreme = '1';
$kat = '0';
if (isset($_POST["filter"]) && $_POST["filter"] != "") {
    $filter = json_decode($_POST["filter"], true);
    $vreme = $filter['vreme'];
    $kat = $filter['kategorije'];
}
if ($kat == '0') {
    $katsql = "";
} else {
    $katsql = "AND kategorija='{$kat}'";
}
$db = new DB();
$sql = "SELECT id_vesti FROM vesti WHERE obrisano=0 AND datum_publikovanja IS NOT NULL AND DATE(`vreme`) >= DATE(NOW() - INTERVAL '{$vreme}' DAY)" . $katsql;
$db->get($sql);
$data = array();
$i = 0;
$rez = $db->res;
foreach ($rez as $r) {
    $vest = new Vest($r['id_vesti']);
    $data[$i]['tittle'] = $vest->naslov();
    $data[$i]['link'] = $vest->link();
    $data[$i]['lat'] = $vest->lat();
    $data[$i]['lng'] = $vest->lng();
    $data[$i]['time'] = $vest->vreme();
    $i++;
}
echo json_encode($data, JSON_PRETTY_PRINT);