<?php 
    $min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;
    $running_year = $this->crud->getInfo('running_year');
    $student_info = $this->db->get_where('student' , array('student_id' => $student_id))->result_array(); 
    foreach($student_info as $row):
    $class_id = $this->db->get_where('enroll', array('student_id' => $row['student_id'], 'year' => $running_year))->row()->class_id;
    $section_id = $this->db->get_where('enroll', array('student_id' => $row['student_id'], 'year' => $running_year))->row()->section_id;
?>
    <div class="content-w"> 
        <?php include 'fancy.php';?>
        <div class="header-spacer"></div>
        <div class="content-i">
            <div class="content-box">
                <div class="conty">
                    <div class="back backbutton">		
    	                <a title="<?php echo getEduAppGTLang('return');?>" href="<?php echo base_url();?>admin/students/"><i class="picons-thin-icon-thin-0131_arrow_back_undo"></i></a>	
	                </div>
                    <div class="row">
                        <main class="col col-xl-9 order-xl-2 col-lg-12 order-lg-1 col-md-12 col-sm-12 col-12">                
                            <div id="newsfeed-items-grid">
                                <div class="ui-block paddingtel">
                                    <div class="user-profile">
                                        <div class="up-head-w" style="background-image:url(<?php echo base_url();?>public/uploads/<?php echo $this->crud->getInfo('bglogin');?>)">
                                            <div class="up-main-info">
                                                <div class="user-avatar-w">
                                                    <div class="user-avatar">
                                                        <img alt="" src="<?php echo $this->crud->get_image_url('student', $row['student_id']);?>" class="bg-white">
                                                    </div>
                                                </div>
                                                <h3 class="text-white"><?php echo $row['first_name'];?> <?php echo $row['last_name'];?></h3>
                                                <h5 class="up-sub-header">@<?php echo $row['username'];?></h5>
                                            </div>
                                            <svg class="decor" width="842px" height="219px" viewBox="0 0 842 219" preserveAspectRatio="xMaxYMax meet" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g transform="translate(-381.000000, -362.000000)" fill="#FFFFFF"><path class="decor-path" d="M1223,362 L1223,581 L381,581 C868.912802,575.666667 1149.57947,502.666667 1223,362 Z"></path></g></svg>
                                        </div>
                                        <div class="up-controls">
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="value-pair">
                                                        <div><?php echo getEduAppGTLang('account_type');?>:</div>
                                                        <div class="value badge badge-pill badge-primary"><?php echo getEduAppGTLang('student');?></div>
                                                    </div>
                                                    <div class="value-pair">
                                                        <div><?php echo getEduAppGTLang('member_since');?>:</div>
                                                        <div class="value"><?php echo $row['since'];?>.</div>
                                                    </div>
                                                    <div class="value-pair">
                                                        <div><?php echo getEduAppGTLang('roll');?>:</div>
                                                        <div class="value"><?php echo $this->db->get_where('enroll', array('student_id' => $row['student_id']))->row()->roll;?>.</div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                <?php 
                                    $student_info = $this->crud->get_student_info($student_id);
                                    $exams         = $this->crud->get_exams();
                                    foreach ($student_info as $row1):
                                    foreach ($exams as $row2):
                                ?>
                                    <div class="col-sm-12">
                                        <div class="element-box lined-primary">
                                            <h5 class="form-header"><?php echo getEduAppGTLang('marks');?><br> <small><?php echo $row2['name'];?></small></h5>
                                            <div class="table-responsive">
                                                <table class="table table-lightborder">
                                                    <thead>
                                                        <tr>
                                                            <th><?php echo getEduAppGTLang('subject');?></th>
                                                            <th><?php echo getEduAppGTLang('teacher');?></th>
                                                            <th><?php echo getEduAppGTLang('mark');?></th>
                                                            <th><?php echo getEduAppGTLang('average');?></th>
                                                            <th><?php echo getEduAppGTLang('grade');?></th>
                                                            <th><?php echo getEduAppGTLang('comment');?></th>
                                                            <th><?php echo getEduAppGTLang('view_all');?></th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    <?php 
                                                        $subjects = $this->db->get_where('subject' , array('class_id' => $class_id, 'section_id' => $section_id))->result_array();
                                                        foreach ($subjects as $row3): 
                                                        $obtained_mark_query = $this->db->get_where('mark' , array('subject_id' => $row3['subject_id'], 'exam_id' => $row2['exam_id'],'class_id' => $class_id, 'student_id' => $student_id, 'year' => $running_year));
                                                        if($obtained_mark_query->num_rows() > 0) 
                                                        {
                                                            $marks = $obtained_mark_query->result_array();
                                                            foreach ($marks as $row4):
                                                        
                                                    ?>
                                                        <tr>
                                                            <td><?php echo $row3['name'];?></td>
                                                            <td><img alt="" src="<?php echo $this->crud->get_image_url('teacher', $row3['teacher_id']); ?>" width="25px" class="tbl-user"> <?php echo $this->crud->get_name('teacher', $row3['teacher_id']); ?></td>
                                                            <td>
                                                                <?php echo $this->db->get_where('mark' , array('subject_id' => $row3['subject_id'], 'exam_id' => $row2['exam_id'], 'student_id' => $student_id, 'year' => $running_year))->row()->mark_obtained;?>
                                                            </td>
                                                            <td>
                                                            <?php 
                                                                $avg = $this->db->get_where('mark' , array('subject_id' => $row3['subject_id'], 'exam_id' => $row2['exam_id'], 'student_id' => $student_id, 'year' => $running_year))->row()->final;
                                                                if($avg < $min || $avg == 0):
                                                            ?>
                                                                <span class="badge badge-danger text-white"><?php echo $avg;?></span>
                                                            <?php endif;?>
                                                            <?php if($avg >= $min):?>
                                                                <span class="badge badge-success text-white"><?php echo $avg;?></span>
                                                            <?php endif;?>
                                                            </td>
                                                            <td><?php echo $grade = $this->crud->get_grade($avg);?></td>
                                                            <td><?php echo $this->db->get_where('mark' , array('subject_id' => $row3['subject_id'], 'exam_id' => $row2['exam_id'], 'student_id' => $student_id, 'year' => $running_year))->row()->comment; ?></td>
                                                                <?php $data = base64_encode($row2['exam_id']."-".$student_id."-".$row3['subject_id']); ?>
                                                            <td><a class="btn btn-rounded btn-sm btn-primary text-white" href="<?php echo base_url();?>admin/subject_marks/<?php echo $data;?>"><?php echo getEduAppGTLang('view_all');?></a></td>
                                                        </tr>
                                                    <?php endforeach;} endforeach;?>
                                                    </tbody>
                                                </table>
                                                <div class="form-buttons-w text-right">
                                                    <a target="_blank" href="<?php echo base_url();?>admin/marks_print_view/<?php echo $student_id;?>/<?php echo $row2['exam_id'];?>"><button class="btn btn-rounded btn-success" type="submit"><i class="picons-thin-icon-thin-0333_printer"></i>  <?php echo getEduAppGTLang('print');?></button></a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <?php endforeach; endforeach; ?>
                                </div>
                            </div>
                        </main>
                        <?php include 'student_left.php';?>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php endforeach;?>