<?php

//------------------------------------------------------------------------------/
// DISPLAY EVENTS FROM THE DATABASE IN JSON FORMAT
//------------------------------------------------------------------------------/
use QuickPdo\QuickPdo;
require_once __DIR__ . "/../../init.php";
require_once __DIR__ . "/../../functions/db.php";
if (isset($_GET['start']) && isset($_GET['end'])) {
    $stmt = 'select * from the_events where start_date >= :start and end_date <= :end';
    $_events = QuickPdo::fetchAll($stmt, ['start' => $_GET['start'], 'end' => $_GET['end']]);
    $events = [];
    foreach ($_events as $e) {
        $events[] = ['id' => $e['id'], 'title' => $e['title'], 'start' => dateMysqlTime2Iso8601($e['start_date']), 'end' => dateMysqlTime2Iso8601($e['end_date'])];
    }
    echo json_encode($events);
}
/**
 * I try to put any db interaction in this file,
 * so that you have only one file to update to adapt the database to your needs.
 */
function fetchAllEventsByDateRange($start, $end)
{
    $stmt = 'select * from the_events where start_date >= :start and end_date <= :end';
    return QuickPdo::fetchAll($stmt, ['start' => $start, 'end' => $end]);
}
                 }
             }
         }
         //------------------------------------------------------------------------------/
         // REQUEST COMPUTING
         //------------------------------------------------------------------------------/
         $fromClause = $lh->getFrom($mc);
         if (false !== ($info = QuickPdo::fetch("select count(*) as count from {$fromClause}"))) {
             $ret['recordsTotal'] = (int) $info['count'];
             $ret['recordsFiltered'] = $ret['recordsTotal'];
             $requestFields = $lh->getRequestFields();
             $stmt .= "select " . implode(', ', $requestFields) . " from {$fromClause}";
             $stmt .= $sWhere;
             $stmt .= $sOrder;
             $stmt .= " limit {$start}, {$length}";
             if (false !== ($res = QuickPdo::fetchAll($stmt, $markers))) {
                 $ret['data'] = [];
                 foreach ($res as $k => $row) {
                     $row = ['DT_RowId' => $row['id']] + $row;
                     $ret['data'][$k] = $row;
                 }
             }
             // recordFiltered
             $stmtCountFiltered = "select count(*) as count from {$fromClause}";
             $stmtCountFiltered .= $sWhere;
             if (false !== ($info = QuickPdo::fetch($stmtCountFiltered, $markers))) {
                 $ret['recordsFiltered'] = (int) $info['count'];
             }
         }
     }
 } catch (\Exception $e) {