<?php
$must_login                        = true ;
$require_path                      = '../../../' ;
$require_sub                       = '../../' ;
require( $require_sub.'header.php' ) ;

if ( $boolean_login ){
	$status   		               = '201' ;

	$search_query                  = '' ;
    $search_query                 .= " AND request_id = '".$array['request_id']."'" ;

    $query                         = "SELECT request_id, is_main, type, title, description, quantity, size, date_from, date_to, reason, content, comment, status, status, created_at, updated_at FROM request
                                      WHERE deleted_at IS NULL " . $search_query ;
    $mysqli_query                  = $mysqli->query( $query . " LIMIT 1" ) ;

    if ( $mysqli_query->num_rows > 0 ){

        $status                    = '200' ;

        $list                      = [] ;
        $row                       = $mysqli_query->fetch_assoc() ;
        $row['title']              = dataFilter( $row['title'] ) ;
        $row['description']        = dataFilter( $row['description'] ) ;
        $row['date_from']          = dataFilter( $row['date_from'] ) ;
        $row['date_to']            = dataFilter( $row['date_to'] ) ;
        $row['time_from']          = date( 'H:ia', strtotime( $row['date_from'] ) ) ;
        $row['time_to']            = date( 'H:ia', strtotime( $row['date_to'] ) ) ;
        $row['reason']             = dataFilter( $row['reason'] ) ;
        $row['content']            = dataFilter( $row['content'] ) ;
        $row['comment']            = dataFilter( $row['comment'] ) ;

        // get all media
        $select_media              = $mysqli->query( "SELECT media_id, file FROM request_media
                                                      WHERE deleted_at IS NULL AND request_id = '".$array['request_id']."'" ) ;
        $photos                    = [] ;
        if ( $select_media->num_rows > 0 ){
            while ( $row_media     = $select_media->fetch_assoc() ){
                $photos[]          = [
                    'media_id'     => $row_media['media_id'],
                    'type'         => 'online',
                    'file'         => ( $row_media['file'] != '' ? PATH.'uploads/Request/b/'.$row_media['file'] : '' )
                ] ;
            }
        }

        $row['photos']             = $photos ;

        $data                      = $row ;

    }
}

require( $require_sub.'footer.php' ) ;
?>