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

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

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

    $query                         = "SELECT suggestion_id, type, title, content, comment, status, status, created_at, updated_at FROM suggestion
                                      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['content']            = dataFilter( $row['content'] ) ;
        $row['comment']            = dataFilter( $row['comment'] ) ;

        // get all media
        $select_media              = $mysqli->query( "SELECT media_id, file, filetype FROM suggestion_media
                                                      WHERE deleted_at IS NULL AND suggestion_id = '".$array['suggestion_id']."'" ) ;
        $photos                    = [] ;
        if ( $select_media->num_rows > 0 ){
            while ( $row_media     = $select_media->fetch_assoc() ){
                
                switch ( $row_media['filetype'] ){
                    case 'jpg'  :
                    case 'jpeg' :
                    case 'png'  :  
                        $photos[]          = [
                            'media_id'     => $row_media['media_id'],
                            'type'         => 'online',
                            'filetype'     => $row_media['filetype'],
                            'file'         => ( $row_media['file'] != '' ? PATH.'uploads/Suggestion/b/'.$row_media['file'] : '' )
                        ] ;
                    break ;
                    default     :
                        $photos[]          = [
                            'media_id'     => $row_media['media_id'],
                            'type'         => 'online',
                            'filetype'     => $row_media['filetype'],
                            'file'         => ( $row_media['file'] != '' ? PATH.'uploads/Suggestion/'.$row_media['file'] : '' )
                        ] ;
                }



            }
        }

        $row['photos']             = $photos ;

        $data                      = $row ;

    }
}

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