<?php
use \Psr\Http\Message\ResponseInterface as Response;
use \Psr\Http\Message\ServerRequestInterface as Request;

$app->post('/getstudentattendancereportsstudent', function (Request $request, Response $response, $args) {

    require __DIR__ . '/../../bootstrap.php';
    $body = $request->getParsedBody();

    require_once __DIR__ . '/../utility.php';
    $fn = new Session();
    $current_session = $fn->getCurrentSession();

    // check the time
    $post4pm = false;
    if (date('H') >= 17 && date('H') <= 23) {
        $post4pm = true;
    }

    if (date('H') >= 1 && date('H') <= 7) {
        $post4pm = true;
    }

    $post4pm = true; // delete this line and school hour window will be deleted

    if($post4pm == true){
        $data['status'] = true;
        $data['status_text'] = $entityManager->getRepository('Student')->getStudentAttendaceReportsStudent($body, $current_session);
        
    }else{
        $data['status'] = false;
        $data['status_text'] = 'Please try in between 5PM to 8AM';
    }

    

    return $response->withJson($data, 200);
});


$app->post('/getstudentattendancereportsstudentbydate', function (Request $request, Response $response, $args) {

    require __DIR__ . '/../../bootstrap.php';
    $body = $request->getParsedBody();

    require_once __DIR__ . '/../utility.php';
    $fn = new Session();
    $current_session = $fn->getCurrentSession();

    // check the time
    $post4pm = false;
    if (date('H') >= 17 && date('H') <= 23) {
        $post4pm = true;
    }

    if (date('H') >= 1 && date('H') <= 7) {
        $post4pm = true;
    }


    $post4pm = true; // delete this line and school hour window will be deleted

    if($post4pm == true){
        $data['status'] = true;
        $data['status_text'] = $entityManager->getRepository('Student')->getStudentAttendaceReportsStudentByDate($body, $current_session);
        
    }else{
        $data['status'] = false;
        $data['status_text'] = 'Please try in between 5PM to 8AM';
    }

    

    return $response->withJson($data, 200);
});