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

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

    $search_query      = " AND a.main_id = '".$array['main_id']."'" ;
    if ( $array['search'] != '' ){
        $search_query .= " AND b.title LIKE '%".$array['search']."%'" ;
    }

    $query             = "SELECT a.sub_id, a.main_id, a.type, a.file, a.created_at, b.title, b.description FROM setting_request_sub a
                          LEFT JOIN setting_request_sub_translation b ON ( a.sub_id = b.sub_id )
                          WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."' AND a.branch LIKE '%/".$array['branch_id']."/%' " . $search_query ;
    $mysqli_query      = $mysqli->query( $query . " ORDER BY a.sortable ASC, a.created_at ASC LIMIT " . getLimit( $current ) ) ;

    if ( $mysqli_query->num_rows > 0 ){

        $status        = '200' ;

        $list          = [] ;
        while ( $row   = $mysqli_query->fetch_assoc() ){
            $row['main_id']     = dataFilter( $row['main_id'] ) ;
            $row['sub_id']      = dataFilter( $row['sub_id'] ) ;
            $row['title']       = dataFilter( $row['title'] ) ;
            $row['description'] = dataFilter( $row['description'] ) ;
            $row['file']        = ( $row['file'] != '' ? PATH.'uploads/Request/b/'.$row['file'] : '' ) ;
            $list[]             = $row ;
        }

        $data['list']  = $list ;

    }
}

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