<?php echo !empty($msg)?format_notice($this, $msg): ""; $this->session = \Config\Services::session();?> 
<table border="0" cellspacing="0" cellpadding="0" class="listtable">
<?php
if (!empty($list)) {
    $rowsPerPage = !empty($pagecount)? $pagecount: NUM_OF_ROWS_PER_PAGE;
    $listCount = count($list);
    $page = !empty($page)? $page: 1;
    $stop = ($rowsPerPage >= $listCount && !empty($listid))? "<input name='paginationdiv__".$listid."_stop' id='paginationdiv__".$listid."_stop' type='hidden' value='".$page."' />": "";
    
    if ($action == 'payrollreport') {
        echo "<tr class='header'><td>&nbsp;</td><td>Registration Number</td><td>Name</td><td>Title</td><td>Salary Scale</td><td>Birth Date</td><td>Status</td><td>Proposed Retirement</td></tr>";
    } elseif ($action == 'cimreport') {
        echo "<tr class='header'><td>&nbsp;</td><td>Registration Number</td><td>Name</td><td>Title</td><td>Responsibility</td><td>Birth Date</td><td>Location</td><td>School</td><td>School Type</td></tr>";
    } elseif ($action == 'rejectreport') {
        echo "<tr class='header'><td>&nbsp;</td><td>Item</td><td>Applicant</td><td>Step</td><td>Approver</td><td>Reason</td><td>Date</td><td>Applicant's Email</td><td>Approver's Email</td></tr>";
    }elseif ($action == 'mandatoryretirement') {
        echo "<tr class='header'><td>&nbsp;</td><td>Name</td><td>Age</td><td>UTS</td><td>IPPS</td><td>NIN</td><td>School</td></tr>";
    } elseif ($action == 'positionreport') {
        echo "<tr class='header'><td>&nbsp;</td><td>Name</td><td>Age</td><td>Title</td><td>IPPS</td><td>NIN</td><td>School</td><td>Last Updated</td></tr>";
    }elseif ($action == 'gradereport') {
        echo "<tr class='header'><td>&nbsp;</td><td>Name</td><td>Age</td><td>Grade</td><td>NIN</td><td>School</td><td>Last Updated</td></tr>";
    }elseif ($action == 'subjectreport') {
        echo "<tr class='header'><td>&nbsp;</td><td>Name</td><td>Age</td><td>NIN</td><td>Subjects Taught</td><td>School</td><td>Last Updated</td></tr>";
    }elseif ($action == 'approvedreport') {
        echo "<tr class='header'><td>&nbsp;</td><td>Item</td><td>Applicant</td><td>Step</td><td>Approver</td><td>Reason</td><td>Date</td><td>Applicant's Email</td><td>Approver's Email</td></tr>";
    } else {
        echo "<tr class='header'><td>&nbsp;</td><td>Name</td><td>Age</td><td>NIN</td><td>Certificate Number</td><td>Grade</td><td>Telephone</td><td>Email</td><td>Teacher Status</td><td>Last Updated</td></tr>";
    }
    
    # Pick the lesser of the two - since if there is a next page, the list count will come with an extra row
    $maxRows = $listCount < $rowsPerPage? $listCount: $rowsPerPage;
    $listType = " data-type='teacher' ";
    
    for ($i=0; $i<$maxRows; $i++) {
        $row = $list[$i];
        echo "<tr class='listrow' ".($i%2 == 1? "style='background-color:#F0F0F0;'": "").">
    <td width='1%' style='padding:0px; padding-top:5px; vertical-align:top;'>";
    
    
        if ((!empty($action) && $action == 'verify') || (!empty($action) && $action == 'verify_pre_primary')) {
            if ($row['teacher_status'] == 'completed') {
                echo "<div data-val='approve_toapproved__".$row['id']."' ".$listType." class='approverow' title='Click to approve'></div>
			<div data-val='reject_fromcompleted__".$row['id']."' ".$listType." class='rejectrow' title='Click to reject'></div>";
            } elseif ($row['teacher_status'] == 'active') {
                echo "<div data-val='archive__".$row['id']."' ".$listType." class='archiverow confirm' title='Click to archive'></div>";
            } elseif ($row['teacher_status'] == 'archived') {
                echo "<div data-val='restore__".$row['id']."' ".$listType." class='restorerow confirm' title='Click to restore'></div>";
            }
        } elseif ((!empty($action) && $action == 'approve') || (!empty($action) && $action == 'approve_pre_primary')) {
            if ($row['teacher_status'] == 'approved' && !$this->session->get('__nosignature')) {
                echo "<div data-val='approve_toconfirmed__".$row['id']."' ".$listType." class='approverow' title='Click to approve'></div>
			<div data-val='reject_fromapproved__".$row['id']."' ".$listType." class='rejectrow' title='Click to reject'></div>";
            }
        } elseif ((!empty($action) && $action == 'certify') || (!empty($action) && $action == 'certify_pre_primary')) {
            // print_r($row['teacher_status']);
            if ($row['teacher_status'] == 'confirmed' && !$this->session->get('__nosignature')) {
                echo "<div data-val='certify_certificate__".$row['id']."' ".$listType." class='approverow' title='Click to approve'></div>
			<div data-val='reject_fromcertified__".$row['id']."' ".$listType." class='rejectrow' title='Click to reject'></div>
            <div data-val='reject_incorrectgrade__".$row['id']."' ".$listType." class='restorerow' title='Incorrect grade awarded; click to reject.'></div>";
            } 
        }
    
        # confirm_documents
        elseif (!empty($action) && $action == 'confirm') {
            echo "<div data-val='confirm_document__".$row['id']."' ".$listType." class='approverow' title='Click to approve'></div>
			<div data-val='reject_fromapproved__".$row['id']."' ".$listType." class='rejectrow' title='Click to reject'></div>";
        }
    
        echo "</td>";
    
    
        if ($action == 'payrollreport') {
            echo "<td>".$row['file_number']."</td>
			<td>".$row['name']."</td>
			<td>".$row['title']."</td>
			<td>".$row['salary_scale']."</td>
			<td>".format_date($row['date_of_birth'], 'd-M-Y')."</td>
			<td>".$row['teacher_status']."</td>
			<td>".format_date($row['proposed_retirement'], 'd-M-Y').$stop."</td>
			</tr>";
        } elseif ($action == 'cimreport') {
            echo "<td>".$row['file_number']."</td>
			<td>".$row['name']."</td>
			<td>".$row['title']."</td>
			<td>".$row['responsibility']."</td>
			<td>".format_date($row['date_of_birth'], 'd-M-Y')."</td>
			<td>".$row['location']."</td>
			<td>".$row['school']."</td>
			<td>".$row['school_type'].$stop."</td>
			</tr>";
        } elseif ($action == 'rejectreport') {
            echo "<td>".ucfirst($row['Item'])."</td>
			<td>".$row['Applicant']."</td>
			<td>".$row['Step']."</td>
			<td>".$row['Approver']."</td>
			<td>".$row['Reason']."</td>
			<td>".format_date($row['Date'], 'd-M-Y')."</td>			
			<td>".$row['ApplicantEmail']."</td>
			<td>".$row['ApproverEmail']."<br>
            <div class='rightnote'><a href='javascript:void(0);' data-href='".base_url()."/Teacher/add/id/".$row['id']."/action/view' class='openPopup'>details</a>
            </div><div class='modal fade' id='myModal' role='dialog'>
            <div class='modal-dialog'>
                <div class='modal-content'><div class='modal-body'></div>
                    <div class='modal-footer'>
                        <button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
                    </div>
                </div>      
            </div>
        </div></td></tr>";
        } elseif ($action == 'approvedreport') {
            echo    "<td>".ucfirst($row['Item'])."</td>
                    <td>".$row['Applicant']."</td>
                    <td>".$row['Step']."</td>
                    <td>".$row['Approver']."</td>
                    <td>".$row['Reason']."</td>
                    <td>".format_date($row['Date'], 'd-M-Y')."</td>      
                    <td>".$row['ApplicantEmail']."</td>
                    <td>".$row['ApproverEmail'].$stop."</td>
                    </tr>";
        } elseif ($action == 'mandatoryretirement') {
            echo    "<td>".ucfirst($row['teacher_name'])."</td>
                    <td style='".format_age($row['age'])."'>".(($row['age'] == 'Unknown')?$row['age']:$row['age']." yrs".format_age($row['age'], 'timeleft'))."</td>
                    <td>".$row['file_number']."</td>
                    <td>".$row['nin']."</td>
                    <td>".$row['ipps']."</td>      
                    <td>".$row['emp_school']."</td>
                    </tr>";
        }
        elseif ($action == 'subjectreport') {
            echo    "<td>".ucfirst($row['teacher_name'])."</td>
                    <td style='".format_age($row['age'])."'>".(($row['age'] == 'Unknown')?$row['age']:$row['age']." yrs".format_age($row['age'], 'timeleft'))."</td>
                    <td>".$row['nin']."</td>      
                    <td>".$row['subject']."</td>
                    <td>".$row['emp_school']."</td>
                    <td>".format_date($row['last_updated'], 'd-M-Y h:ia T').$stop."</td>
                    </tr>";
        }elseif ($action == 'positionreport') {
            echo    "<td>".ucfirst($row['teacher_name'])."</td>
                    <td style='".format_age($row['age'])."'>".(($row['age'] == 'Unknown')?$row['age']:$row['age']." yrs".format_age($row['age'], 'timeleft'))."</td>
                    <td>".$row['title']."</td>
                    <td>".$row['ipps']."</td>
                    <td>".$row['nin']."</td>      
                    <td>".$row['emp_school']."</td>
                    <td>".format_date($row['last_updated'], 'd-M-Y h:ia T').$stop."</td>
                    </tr>";
        }elseif ($action == 'gradereport') {
            echo    "<td>".ucfirst($row['teacher_name'])."</td>
                    <td style='".format_age($row['age'])."'>".(($row['age'] == 'Unknown')?$row['age']:$row['age']." yrs".format_age($row['age'], 'timeleft'))."</td>
                    <td>".$row['grade']."</td>
                    <td>".$row['nin']."</td>      
                    <td>".(!empty($row['emp_school'])?$row['emp_school']:'&nbsp;')."</td>
                    <td>".format_date($row['last_updated'], 'd-M-Y h:ia T').$stop."</td>
                    </tr>";
        }
        else {
            echo "<td>".$row['name']."</td> 
			<td style='".format_age($row['age'])."'>".(($row['age'] == 'Unknown')?$row['age']:$row['age']." yrs".format_age($row['age'], 'timeleft'))."</td>
			<td>".(!empty($row['nin'])? $row['nin']: '&nbsp;')."</td>
			<td>".(!empty($row['tracking_number'])? str_replace(',', ', ', $row['tracking_number']): '&nbsp;')."</td>
            <td>".(!empty($row['grade'])? ucwords(strtolower($row['grade'])): '&nbsp;')."</td>
			<td>".$row['telephone']."</td>
			<td>".$row['email_address']."</td>
			<td>".strtoupper($row['teacher_status'])."</td>
			<td>".format_date($row['last_updated'], 'd-M-Y h:ia T').
    
            "<br>
            <div class='rightnote'><a href='javascript:void(0);' data-href='".base_url()."/Teacher/add/id/".$row['id']."/action/view' class='openPopup'>details</a>
            </div><div class='modal fade' id='myModal' role='dialog'>
            <div class='modal-dialog'>
                <div class='modal-content'><div class='modal-body'></div>
                    <div class='modal-footer'>
                        <button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
                    </div>
                </div>      
            </div>
        </div>".
    
            ((check_access($this, 'add_new_teacher', 'boolean') && !empty($action) && $action == 'view')? "<div class='rightnote'><a  href='javascript:void(0);' data-href='".base_url()."/Teacher/add/id/".$row['id']."/action/verify' class='editPopup'>edit</a></div> </div><div class='modal fade' id='editModal' role='dialog'>
            <div class='modal-dialog'>
                <div class='modal-content'><div class='modal-body'></div>
                </div>      
            </div>
        </div>": "")
    
            ."</td></tr>
	<tr><td style='padding:0px;'></td><td colspan='7' style='padding:0px;'><div id='action__".$row['id']."' class='actionrowdiv' style='display:none;'></div>".$stop."</td></tr>";
        }
    }
} else {
    $stop = "<input name='paginationdiv__".$listid."_stop' id='paginationdiv__".$listid."_stop' type='hidden' value='1' />";
    echo "<tr><td>".format_notice($this, 'WARNING: There are no items in this list.').$stop."</td></tr>";
}
?>

  
</table>
