<?php 
    $running_year = $this->crud->getInfo('running_year');
    $subjectData = $this->db->get_where('activity' , array('activity_id' => $param2, 'year' => $running_year))->result_array(); 
?>    
    <?php 
        foreach($subjectData as $row): 
        $addMinutes = 0;
        if($row['showResults'] == 3){
            $addMinutes = 15;   
        }elseif($row['showResults'] == 4){
            $addMinutes = 30;
        }
        $current_time          = time();
        $exam_start_time       = strtotime($row['delivery_date'].' '.$row['start_time']);
        $exam_end_time         = strtotime($row['delivery_date'].' '.$row['end_time']);
        
        $startResult           = strtotime($row['end_time']);
        $endResult             = $addMinutes*60;
        $newResult             = date("H:i",$startResult+$endResult).':00';
        $exam_end_time_results = strtotime($row['delivery_date'].' '.$newResult);
    ?>
    <div class="modal-body">
        <div class="modal-header mdl-header">
            <h6 class="title text-white"><?php echo getEduAppGTLang('online_exam_details');?></h6>
        </div>
        <div class="ui-block-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="mb-4">
                        <label class="rmmb"><b><?php echo getEduAppGTLang('title');?></b></label><br>
                        <span><?php echo $row['title'];?></span>
                    </div>
                    <div class="mb-4">
                        <label class="rmmb"><b><?php echo getEduAppGTLang('description');?></b></label><br>
                        <span><?php echo $row['description'];?></span>
                    </div>
                    <div class="mb-4">
                        <label class="rmmb"><b><?php echo getEduAppGTLang('date');?></b></label><br>
                        <span><?php echo date('M d, Y', strtotime($row['delivery_date']));?></span>
                    </div>
                    <div class="mb-4">
                        <label class="rmmb"><b><?php echo getEduAppGTLang('hour');?></b></label><br>
                        <span><?php echo date('h:i A',strtotime($row['start_time'])).' - '.date('h:i A',strtotime($row['end_time']));?></span>
                    </div>
                    <?php if ($this->crud->check_availability_for_student($row['activity_id'],$this->session->userdata('login_user_id')) != "submitted"): ?>
                        <?php if ($current_time >= $exam_start_time && $current_time <= $exam_end_time): ?>
                            <a href="<?php echo base_url();?>student/examroom/<?php echo $row['activity_id'];?>/" class="btn btn-success btn-rounded"><?php echo getEduAppGTLang('take_exam');?></a>
                        <?php else: ?>
                            <div class="alert alert-info">
                                <?php echo getEduAppGTLang('take_exam_message');?>.
                            </div>
                        <?php endif; ?>
                    <?php endif; ?>
                    <?php if($row['showResults'] == 2):?>
                    <div class="mb-4">
                        <label class="rmmb"><b><?php echo getEduAppGTLang('your_results');?></b></label><br>
                        <?php
                            $query = $this->db->get_where('online_exam_result', array('online_exam_id' => $param2, 'student_id' => $this->session->userdata('login_user_id')));
                            if ($query->num_rows() > 0)
                            {
                                $query_result = $query->row_array();
                                echo '<span class="badge badge-success">'.getEduAppGTLang($query_result['result']).'</span>';
                            }
                            else {
                                echo "<span class='badge badge-warning'>". getEduAppGTLang('not_started_yet')."</span>";
                            }
                        ?>
                    </div>
                    <div class="mb-4">
                        <label class="rmmb"><b><?php echo getEduAppGTLang('mark');?></b></label><br>
                        <span class="badge badge-info">
                        <?php $query = $this->db->get_where('online_exam_result', array('online_exam_id' => $param2, 'student_id' => $this->session->userdata('login_user_id')));
                            if ($query->num_rows() > 0){
                            $query_result = $query->row_array();
                            echo $query_result['obtained_mark'];
                        }
                        else {
                            echo 0;
                        }?>
                        </span>
                    </div>
                    <?php endif;?>
                </div>
            </div>
        </div>
    </div>
    <?php endforeach;?>