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

if ( $boolean_login ){
    $status            = '201' ;
    $list              = [] ;

    $query             = '' ;
    $mysqli_item       = $mysqli->query( "SELECT a.item_id, a.file, b.title FROM rms_prepaid_item a
                                          LEFT JOIN rms_prepaid_item_translation b ON ( a.item_id = b.item_id )
                                          WHERE a.deleted_at IS NULL AND a.status = 'active' AND b.lang = '".$array['lang']."' ORDER BY a.sortable ASC" ) ;

    if ( $mysqli_item->num_rows > 0 ){

        $status        = '200' ;

        $denos         = [] ;
        $mysqli_deno   = $mysqli->query( "SELECT a.deno_id, a.item_id, b.title FROM rms_prepaid_deno a
                                          LEFT JOIN rms_prepaid_deno_translation b ON ( a.deno_id = b.deno_id )
                                          WHERE a.deleted_at IS NULL AND a.status = 'active' AND b.lang = '".$array['lang']."' ORDER BY a.sortable ASC" ) ;
        if ( $mysqli_deno->num_rows > 0 ){
            while ( $row_deno        = $mysqli_deno->fetch_assoc() ){
                $row_deno['title']   = dataFilter( $row_deno['title'] ) ;
                $denos[$row_deno['item_id']][] = $row_deno ;
            }
        }

        while ( $row_item = $mysqli_item->fetch_assoc() ){
            $row_item['id']          = dataFilter( $row_item['item_id'] ) ;
            $row_item['title']       = dataFilter( $row_item['title'] ) ;
            $row_item['file']        = ( $row_item['file'] != '' ? PATH.'uploads/RmsPrepaidItem/b/'.$row_item['file'] : '' ) ;
            $row_item['denos']       = ( $denos[$row_item['item_id']] != null ? $denos[$row_item['item_id']] : [] ) ;
            $list[]                  = $row_item ;
        }

    }

    $data['list']       = $list ;
}

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