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

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

    $search_query      = '' ;
    $search_query     .= " AND a.training_id = '".$array['id']."'" ;

    $join_filter       = "" ;
    $join_query        = "" ;
    if ( $array['mode'] == 'view' ){
        $join_filter  .= ", c.training_so, c.status as training_status, c.remark as training_remark, c.rated as training_rated, c.comment as training_comment" ;
        $join_query   .= " LEFT JOIN staff_training c ON ( a.training_id = c.training_id )" ;
        $search_query .= " AND c.view_id = '".$array['view_id']."' AND c.staff_id = '".$staff_info['staff_id']."'" ;
    }

    $query             = "SELECT a.training_id, a.training_type, a.date_start, a.date_end, a.file, a.status, a.created_at, b.title, b.content ".$join_filter." FROM training a
                          LEFT JOIN training_translation b ON ( a.training_id = b.training_id )
                          ".$join_query."
                          WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."' " . $search_query ;
    $mysqli_query      = $mysqli->query( $query ) ;

    if ( $mysqli_query->num_rows > 0 ){
        $status                  = '200' ;

        $generatecode            = generateQrcode( '', $row['training_so'], $row['training_so'] ) ;

        $row                     = $mysqli_query->fetch_assoc() ; 
        $row['id']               = dataFilter( $row['training_id'] ) ;
        $row['sonumber']         = dataFilter( $row['training_so'] ) ;
        $row['qrcode']           = $generatecode['url'] ;
        $row['title']            = dataFilter( $row['title'] ) ;
        $row['content']          = dataFilter( $row['content'] ) ;
        $row['file']             = ( $row['file'] != '' ? PATH.'uploads/Training/b/'.$row['file'] : '' ) ;

        $is_training             = 'no' ;
        if ( $row['status']     == 'active' ){
            if ( $row['training_type'] == 'all' || ( $row['training_type'] == 'date' && $row['date_start'] <= TODAYDAY && $row['date_end'] >= TODAYDAY ) ){
                $is_training     = 'yes' ;
            }
        }
        $row['is_training']      = $is_training ;
        $row['date_start']       = resetDateFormat( $row['date_start'] ) ;
        $row['date_end']         = resetDateFormat( $row['date_end'] ) ;
        $row['created_at']       = resetDateFormat( $row['created_at'] ) ;
        $row['training_status']  = ( checkExists( $row['training_status'] ) != '' ? $row['training_status'] : '') ;
        $row['training_remark']  = dataFilter( checkExists( $row['training_remark'] ) != '' ? $row['training_remark'] : '') ;
        $row['training_rated']   = dataFilter( checkExists( $row['training_rated'] ) != '' ? $row['training_rated'] : 0) ;
        $row['training_comment'] = dataFilter( checkExists( $row['training_comment'] ) != '' ? $row['training_comment'] : '') ;

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

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