<?php 
    $running_year = $this->crud->getInfo('running_year');
    $info = base64_decode($data);
    $ex = explode('-', $info);
    $sub = $this->db->get_where('subject', array('subject_id' => $ex[2]))->result_array();
    foreach($sub as $row):
    $students   =   $this->db->get_where('enroll' , array('class_id' => $ex[0], 'section_id' => $ex[1] , 'year' => $running_year))->result_array();
?>
    <div class="content-w">
        <div class="conty">
        <?php $info = base64_decode($data);?>
        <?php $ids = explode("-",$info);?>
        <?php include 'fancy.php';?>
        <div class="header-spacer"></div>
            <?php include 'subject_header.php';?>
            <div class="content-i">
                <div class="content-box">
                    <div class="back mb-3">
                        <a class="fs-16" href="<?php echo base_url();?>student/subject_dashboard/<?php echo $data;?>/"><i class="picons-thin-icon-thin-0131_arrow_back_undo"></i> <span><?php echo getEduAppGTLang('return_to_dashboard');?></span></a>
                    </div>
                    <div class="row">
                        <main class="col col-xl-12 order-xl-2 col-lg-12 order-lg-1 col-md-12 col-sm-12 col-12">
                            <div class="element-wrapper">         
			                    <?php echo form_open(base_url() . 'student/attendance_report_selector/', array('class' => 'form m-b')); ?>   
					                <div class="row">                
    							        <input type="hidden" name="data" value="<?php echo $data; ?>">
    						            <input type="hidden" name="operation" value="selection">
						                <div class="col-sm-4">    
						                    <div class="form-group is-select">
                                                <label class="control-label"><?php echo getEduAppGTLang('month');?></label>
                                                <div class="select">
                                                    <select name="month" required="" onchange="show_year()">
                                                        <option value=""><?php echo getEduAppGTLang('select');?></option>
                                                        <?php
            						                        for ($i = 1; $i <= 12; $i++):
                                                            if ($i == 1) $m = getEduAppGTLang('january');
                                                            else if ($i == 2) $m = getEduAppGTLang('february');
                                                            else if ($i == 3) $m = getEduAppGTLang('march');
                                                            else if ($i == 4) $m = getEduAppGTLang('april');
                                                            else if ($i == 5) $m = getEduAppGTLang('may');
                                                            else if ($i == 6) $m = getEduAppGTLang('june');
                                                            else if ($i == 7) $m = getEduAppGTLang('july');
                                                            else if ($i == 8) $m = getEduAppGTLang('august');
                                                            else if ($i == 9) $m = getEduAppGTLang('september');
                                                            else if ($i == 10) $m = getEduAppGTLang('october');
                                                            else if ($i == 11) $m = getEduAppGTLang('november');
                                                            else if ($i == 12) $m = getEduAppGTLang('december');
                				                        ?>
                					                    <option value="<?php echo $i; ?>"<?php if($month == $i) echo 'selected'; ?>  ><?php echo $m; ?></option>
                				                        <?php endfor;?>
                                                    </select>
                                                </div>
                                            </div>
						                </div>       
						                <input type="hidden" name="year" value="<?php echo $running_year;?>">
						                <div class="col-sm-2">                 
							                <div class="form-group"> 
								                <button class="btn btn-rounded btn-success btn-upper top-20"><span><?php echo getEduAppGTLang('generate');?></span></button>
							                </div>                
						                </div>             
					                </div>            
				                <?php echo form_close();?>       
		                    </div> 
		                    <?php if($month != ''):?>
                            <div id="newsfeed-items-grid">      
                                <div class="element-box lined-primary shadow">              
                                    <div class="element-wrapper">
                                        <div class="element-box-tp">
                                            <h6 class="element-header"><?php echo getEduAppGTLang('attendance_report');?> <?php echo getEduAppGTLang('of');?> [<?php echo $this->db->get_where('subject', array('subject_id' => $ex[2]))->row()->name;?>]</h6>
                                            <div class="table-responsive">
                                                <table class="table table-sm table-lightborder">
                                                    <thead>                    
                                                        <tr class="text-center" height="50px">
                                                            <th class="text-left"> <?php echo getEduAppGTLang('student');?></th>  
                                                            <?php
                                                                $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
                                                                for ($i = 1; $i <= $days; $i++) {
                                                            ?>                    
                                                            <th class="text-center"> <?php echo $i; ?> </th>                    
                                                            <?php } ?>
                                                        </tr> 
                                                    </thead>                  
                                                    <tbody>                    
                                                        <tr>                      
                                                            <td><img alt="" src="<?php echo $this->crud->get_image_url($this->session->userdata('login_type'), $this->session->userdata('login_user_id'));?>" width="20px" class="tbl-st"> <?php echo $this->crud->get_name('student', $this->session->userdata('login_user_id')); ?> </td>    
                                                        <?php
                                                            $status = 0;
                                                            for ($i = 1; $i <= $days; $i++) {
                                                            $timestamp = strtotime($i . '-' . $month . '-' . $year);
                                                            $this->db->group_by('timestamp');
                                                            $attendance = $this->db->get_where('attendance', array('section_id' => $ex[1], 'class_id' => $ex[0], 'subject_id' => $ex[2], 'year' => $year, 'timestamp' => $timestamp, 'student_id' => $this->session->userdata('login_user_id')))->result_array();
                                                            foreach ($attendance as $row1): $month_dummy = date('d', $row1['timestamp']);
                                                            if ($i == $month_dummy) $status = $row1['status'];
                                                            endforeach; ?>
                                                            <td class="text-center">
                                                            <?php if ($status == 1) { ?>
                                                                <div class="status-pilli green" data-title="<?php echo getEduAppGTLang('present');?>" data-toggle="tooltip"></div>
                                                            <?php  } if($status == 2)  { ?>
                                                                <div class="status-pilli red" data-title="<?php echo getEduAppGTLang('absent');?>" data-toggle="tooltip"></div>
                                                            <?php  } if($status == 3)  { ?>
                                                                <div class="status-pilli yellow" data-title="<?php echo getEduAppGTLang('late');?>" data-toggle="tooltip"></div>
                                                            <?php  } $status =0;?>
                                                            </td>                      
                                                            <?php } ?>
                                                        </tr>                                      
                                                    </tbody>                
                                                </table>    
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <?php endif;?>
                        </main>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php endforeach;?>