<div class="content-wrapper" style="min-height: 946px;">
    <section class="content-header">
        <h1>
            <i class="fa fa-map-o"></i> <?php echo $this->lang->line('examinations'); ?> <small><?php echo $this->lang->line('student_fee1'); ?></small> </h1>
			<?php 
			echo "<pre>"; 
		//	print_r($gradeList);
			echo "<hr />";
		//	print_r($className);
			echo "<h1>Class: $class_name | Section: $section_name</h1>";
		//	print_r($examSchedule);
		//	print_r($all_exams_get); 		
		//	print_r($annual_result); 		
			print_r($setting); 		
			echo "</pre>"; 
			
			$_GLOBAL['annual_result'] = $annual_result;
			?>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><i class="fa fa-search"></i> <?php echo $this->lang->line('select_criteria'); ?></h3>
                        <div class="box-tools pull-right">
                            <a href="<?php echo base_url(); ?>admin/mark/create" class="btn btn-primary btn-sm"  data-toggle="tooltip" title="<?php echo $this->lang->line('add'); ?>" >
                                <i class="fa fa-plus"></i> <?php echo $this->lang->line('add'); ?>
                            </a>
                        </div>
                    </div>
                    <form action="<?php echo site_url('admin/mark') ?>"  method="post" accept-charset="utf-8" id="schedule-form">
                        <div class="box-body">
                            <div class="row">
                                <input type="hidden" name="save_exam" value="search" >                               
                                <?php echo $this->customlib->getCSRF(); ?>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="exampleInputEmail1"><?php echo $this->lang->line('exam_name'); ?></label>

                                        <select autofocus="" id="exam_id" name="exam_id" class="form-control" >
                                            <option value=""><?php echo $this->lang->line('select'); ?></option>
                                            <?php
                                            foreach ($examlist as $exam) {
                                                ?>
                                                <option value="<?php echo $exam['id'] ?>" <?php
                                                if ($exam_id == $exam['id']) {
                                                    echo "selected =selected";
													$current_term = $exam['name'];
                                                }
                                                ?>><?php echo $exam['name'] ?></option>
                                                        <?php
                                                        $count++;
                                                    }
                                                    ?>
                                        </select>
                                        <span class="text-danger"><?php echo form_error('exam_id'); ?></span>
                                    </div>
                                </div><!-- /.col -->
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="exampleInputEmail1"><?php echo $this->lang->line('class'); ?></label>
                                        <select  id="class_id" name="class_id" class="form-control" >
                                            <option value=""><?php echo $this->lang->line('select'); ?></option>
                                            <?php
                                            foreach ($classlist as $class) {
                                                ?>
                                                <option value="<?php echo $class['id'] ?>" <?php
                                                if ($class_id == $class['id']) {
                                                    echo "selected =selected";
													$current_class = $class['class'];
                                                }
                                                ?>><?php echo $class['class'] ?></option>

                                                <?php
                                                $count++;
                                            }
                                            ?>
                                        </select>
                                        <span class="text-danger"><?php echo form_error('class_id'); ?></span>
                                    </div>
                                </div><!-- /.col -->
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="exampleInputEmail1"><?php echo $this->lang->line('section'); ?></label>
                                        <select  id="section_id" name="section_id" class="form-control" >
                                            <option value=""><?php echo $this->lang->line('select'); ?></option>
                                        </select>
                                        <span class="text-danger"><?php echo form_error('section_id'); ?></span>
                                    </div>
                                </div><!-- /.col -->
                            </div><!-- /.row -->
                        </div><!-- /.box-body -->
                    </form>
                </div>
                <?php
                if (isset($examSchedule['status'])) {
                    ?>

                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title">
                                <i class="fa fa-list"></i> <?php echo $this->lang->line('marks_register'); ?></h3>
                        </div>
                        <div class="box-body">
                            <?php
                            if ($examSchedule['status'] == "yes") {
			
                                ?>

                                <form role="form" id="" class="" method="post" action="<?php echo site_url('admin/mark/create') ?>">
                                    <?php echo $this->customlib->getCSRF(); ?>
                                    <input type="hidden" name="class_id" value="<?php echo $class_id; ?>">
                                    <input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
                                    <input type="hidden" name="exam_id" value="<?php echo $exam_id; ?>">
                                    <div class="table-responsive">
									<div class="download_label"><?php echo $this->lang->line('marks_register'); ?></div>
                                        <table class="table table-striped table-bordered table-hover example">
                                            <thead>
                                                <tr>
                                                    <th>
                                                        <?php echo $this->lang->line('admission_no'); ?>
                                                    </th>
                                                    <th>
                                                        <?php echo $this->lang->line('roll_no'); ?>
                                                    </th>
                                                    <th>
                                                        <?php echo $this->lang->line('student'); ?>
                                                    </th>
                                                    <th>
                                                        <?php echo $this->lang->line('gender'); ?>
                                                    </th>


                                                    <?php
                                                    $s = 0;
                                                    if ($examSchedule['status'] == "yes") {
                                                        foreach ($examSchedule['result'] as $key => $st) {
                                                            if ($s == 0) {
                                                                foreach ($st['exam_array'] as $key => $exam_schedule) {
                                                                    ?>
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "C. A 1";
                                                                        ?>
                                                                    </th>
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "C. A 2";
                                                                        ?>
                                                                    </th>																	
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "C. A 3";
                                                                        ?>
                                                                    </th>
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "EXAM";
                                                                        ?>
                                                                    </th>
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name'] . "<br /> TOTAL";
                                                                        ?>
                                                                    </th>	
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "HIGHEST";
                                                                        ?>
                                                                    </th>	
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "LOWEST";
                                                                        ?>
                                                                    </th>
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "AVERAGE";
                                                                        ?>
                                                                    </th>	
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "POSITION";
                                                                        ?>
                                                                    </th>
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "GRADE";
                                                                        ?>
                                                                    </th>																	
																	
                                                                    <?php
                                                                }
                                                            }
                                                            $s++;
                                                        }
                                                    } else {
                                                        ?>

                                                        <?php
                                                    }
                                                    ?>
                                                    <th><?php echo $this->lang->line('grand_total'); ?></th>
                                                    <th>Grand Obtainable</th>
                                                    <th><?php echo $this->lang->line('percent') . ' (%)'; ?></th>
                                                    <th>CLASS AVERAGE</th>
                                                    <th>POSITION</th>
                                                    <th>EDIT</th>
                                                    <th>PRINT</th>
                                                 <!--   <th><?php echo $this->lang->line('result'); ?></th> -->
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $s = 0;
                                                foreach ($examSchedule['result'] as $key => $student) {
                                                    ?>
                                                <input type="hidden" name="student[]" value="<?php echo $student['student_id'] ?>">

                                                <?php
                                                if (!empty($student['exam_array'])) {
                                                    if ($s == 0) {
                                                        foreach ($student['exam_array'] as $key => $exam_schedule) {
                                                            ?>
                                                            <input type="hidden" name="exam_schedule[]" value="<?php echo $exam_schedule['exam_schedule_id'] ?>">
                                                            <?php
                                                        }
                                                    }
                                                } else {
                                                    ?>

                                                    <?php
                                                }
                                                $s++;
                                            }
                                            ?>
                                            <?php
                                            foreach ($examSchedule['result'] as $key => $student) {
												$dossier = "<div style='margin:40px;'><table border='1' style='width:100%;'>";
												
												$dossier .= "
												<tr style='font-weight:bold;'>
												<td>SUBJECTS</td>
												<td>CA 1</td>
												<td>CA 2</td>
												<td>CA 3</td>
												<td>EXAM</td>
												<td>TOTAL</td>
												<td>HIGHEST</td>
												<td>LOWEST</td>
												<td>AVERAGE</td>
												<td>POSITION</td>
												<td>GRADE</td>
												<td>REMARK</td>
												</tr>
												";
												
												
                                                $total_marks = 0;
                                                $obtain_marks = "0";
                                                $result = "Pass";
                                                ?>
                                                <tr>
                                                    <td>
                                                        <?php echo $student['admission_no'] ?>
                                                    </td>
                                                    <td>
                                                        <?php echo $student['roll_no'] ?>
                                                    </td>
                                                    <td>
                                                        <?php echo $student['firstname'] . " " . $student['lastname']; ?>
                                                    </td>
                                                    <td>
                                                        <?php echo $student['gender'] ?>
													<?php
													///OTHER STUDENT DETAILS
												//	echo "<pre>";
												//	echo $student['gender'];
												//	print_r($student['current_details']);
												//	echo $student['current_details']['class'] . $student['current_details']['section'];
												//	echo "</pre>";
													///END OTHER STUDENT DETAILS	
				//echo "<img src='" . base_url() . "/" . $student['current_details']['image'] ."' width='100px'>";
													?>									
                                                    </td>
                                                    <?php
                                                    if (!empty($student['exam_array'])) {
														$grand_total_mark = 0; 
                                                        count($student['exam_array']);
                                                        $s = 0;
                                                        foreach ($student['exam_array'] as $key => $exam_schedule) {
															
															$dossier .= "<tr>";
															$dossier .= "<td>". $exam_schedule['exam_name'] . "</td>";
                                                            $total_marks = (int)$total_marks + (int)$exam_schedule['full_marks'];
                                                            ?>
															<td>
															<?php echo $exam_schedule['ca1']; ?>
															<?php $dossier .= "<td>". $exam_schedule['ca1'] . "</td>"; ?>
															</td>
															<td>
															<?php echo $exam_schedule['ca2']; ?>
															<?php $dossier .= "<td>". $exam_schedule['ca2'] . "</td>"; ?>
															</td>
															<td>
															<?php echo $exam_schedule['ca3']; ?>
															<?php $dossier .= "<td>". $exam_schedule['ca3'] . "</td>"; ?>
															</td>
															<td>
															<?php echo $exam_schedule['get_marks']; ?>
															<?php $dossier .= "<td>". $exam_schedule['get_marks'] . "</td>"; ?>
															</td>															
                                                            <td>
                                                                <?php
																
                                                                if (!isset($exam_schedule['attendence'])) {
                                                                    echo "N/A";
                                                                    $result = "N/A";
                                                                } else {
                                                                    if ($exam_schedule['attendence'] == "pre") {
                                                                    //    echo $get_marks_student = $exam_schedule['get_marks'];
                                                                        echo $get_marks_student = $exam_schedule['ca1'] +  $exam_schedule['ca2'] +  $exam_schedule['ca3'] +  $exam_schedule['get_marks'];
																		///SET MARK GRADE
																		$grade_name = "";
																		$grade_desc = "";
																		foreach($gradeList as $grade => $grade_details){
																			if(($get_marks_student >= $grade_details['mark_from']) && ($get_marks_student <= $grade_details['mark_upto'])){
																			//	echo $grade_details['name'];
																				$grade_name = $grade_details['name'];
																				$grade_desc = $grade_details['description'];
																			}
																			
																			if(($get_marks_student > 100) || ($get_marks_student < 0)){
																			//	echo $grade_details['name'];
																				$grade_name = "<label class='label label-danger'>Out of range</label>";
																				$grade_desc = "<label class='label label-danger'>Out of range</label>";
																			}
																			
																			
																		}
																		
																		///END SET MARK GRADE
																		
																		$grand_total_mark += $get_marks_student;
                                                                        $passing_marks_student = $exam_schedule['passing_marks'];
                                                                        if ($result == "Pass") {
                                                                            if ($get_marks_student < $passing_marks_student) {
                                                                                $result = "Fail";
                                                                            }
                                                                        }
                                                                        $obtain_marks = $obtain_marks + $exam_schedule['get_marks'];
                                                                    } else {
                                                                        $result = "Fail";
                                                                        $s++;
                                                                        echo ($exam_schedule['attendence']);
                                                                    }
                                                                }
                                                                ?>
                                                            </td>
															<?php $dossier .= "<td>". $get_marks_student . "</td>"; ?>
															<td>
															<?php 
															$highest = highest($exam_schedule['exam_schedule_id'], $examSchedule);
															echo $highest;
															?>
															<?php $dossier .= "<td>". $highest . "</td>"; ?>
															</td>	
															<td>
															<?php 
															$lowest = lowest($exam_schedule['exam_schedule_id'], $examSchedule);
															echo $lowest;
															?>
															<?php $dossier .= "<td>". $lowest . "</td>"; ?>															
															</td>	
															<td>
															<?php 															
															$average = average($exam_schedule['exam_schedule_id'], $examSchedule); 
															echo $average;
															?>
															<?php $dossier .= "<td>". $average . "</td>"; ?>	
															</td>	
															<td>
															<?php 
															$position = position($exam_schedule['exam_schedule_id'], $examSchedule, $student['student_id']);
															echo $position;
															?>
															<?php $dossier .= "<td>". $position . "</td>"; ?>
															</td>
															<td>
															<?php echo $grade_name; ?>
															</td>
															<?php $dossier .= "<td>". $grade_name . "</td>"; ?>
															<?php $dossier .= "<td>". $grade_desc . "</td>"; ?>
                                                            <?php
															
														$dossier .= "</tr>";	
                                                        }
                                                        if ($s == count($student['exam_array'])) {
                                                            $obtain_marks = 0;
                                                        }
                                                        ?>
														
													<?php

													$dossier .= "</table></div>";	
													
													?>
														
                                                     <!--   <td> <?php echo $obtain_marks . " /" . $total_marks; ?> </td> -->													 
                                                        <td> <?php echo $grand_total_mark; ?> </td>													
                                                        <td> <?php echo $total_marks; ?> </td>																									
                                                        <td> 
														<?php
                                                            $per = $grand_total_mark * 100 / $total_marks;
                                                            $average = number_format($per, 2, '.', '');
                                                            echo $average;
                                                         ?>
														</td>
														<td>														
														<?php 
														$class_average = class_average($examSchedule);
														echo $class_average;
														?>
														</td>														
														</td>
														<td>
														<?php 
														$class_position = class_position($examSchedule, $student['student_id']); 
														echo $class_position;
														?>														
														</td>
														<td><button class='btn btn-primary btn-sm'>EDIT</button></td>
														<?php 
														$student_count = count($examSchedule['result']);
														$subject_count = count($examSchedule['result'][0]['exam_array']);
														$student_admission_no = $student['admission_no'];
														$student_firstname = $student['firstname'];
														$student_lastname = $student['lastname'];
														$x_student_id = $student['student_id'];
														$student_class = $class_name;
														$student_section = $section_name;
														$student_session = $student['session_name'];
													//	$student_sex = $examSchedule['result'][$x_student_id]['current_details']['gender'];
														$student_sex = $student['gender'];
														$student_image = $student['current_details']['image'];
														$setting_name = $setting['name'];
														$setting_email = $setting['email'];
														$setting_phone = $setting['phone'];
														$setting_address = $setting['address'];
														$setting_image = $setting['image'];
														$student_c1 = $student['character']['c1'];
														$student_c2 = $student['character']['c2'];
														$student_c3 = $student['character']['c3'];
														$student_c4 = $student['character']['c4'];
														$student_c5 = $student['character']['c5'];
														$student_c6 = $student['character']['c6'];
														$student_c7 = $student['character']['c7'];
														$student_c8 = $student['character']['c8'];
														$student_c9 = $student['character']['c9'];
														$student_c10 = $student['character']['c10'];
														$student_c11 = $student['character']['c11'];
														$student_c12 = $student['character']['c12'];
														$student_c13 = $student['character']['c13'];
														$student_c14 = $student['character']['c14'];
														$student_c15 = $student['character']['c15'];
														$student_c16 = $student['character']['c16'];
														$student_c17 = $student['character']['c17'];
														$student_c18 = $student['character']['c18'];
														$student_c19 = $student['character']['c19'];
														$student_c20 = $student['character']['c20'];
														$student_c21 = $student['character']['c21'];
														$student_c22 = $student['character']['c22'];
														$student_c23 = $student['character']['c23'];
														$student_c24 = $student['character']['c24'];
													//	$student_image = "<img src='" . base_url() . "/" . $student['current_details']['image'] ."' width='100px'>";													
														?>
														<?php
														$dossier_header = "
														<div style='margin:30px; padding:10px; border:1px black solid;'>
														<table style='width:100%;text-align:center;'>
														<tr>
														<td width='15%'>
														<img src='" . base_url() . "/uploads/school_content/logo/" . $setting_image ."' width='100px' border='1' />
														</td>
														<td width='70%'>
														<h1 style='margin:0px;padding:0px;'>$setting_name</h1>
														<h3 style='margin:0px;padding:0px;'>$setting_address</h3>
														<h4 style='margin:0px;padding:0px;'>$setting_phone</h4>
														<h4 style='margin:0px;padding:0px;'>$setting_email</h4>
														
														</td>
														<td width='15%'>
														<img src='" . base_url() . "/" . $student_image ."' width='100px' border='1' />
														</td>
														</tr>														
														</table>
														</div>
														<center><h2 style='margin:0px;padding:0px;'>Termly Continuous Assessment Report</h2></center>
														";
														
														
														$dossier_top = "
														<div style='margin:30px; padding:10px; border:1px black solid;'>
														<strong>Admission No:</strong> $student_admission_no &nbsp;&nbsp;&nbsp;
														<strong>Student's Name:</strong> $student_lastname $student_firstname &nbsp;&nbsp;&nbsp;
														<br />
														<br />
														<strong>Term:</strong> $current_term &nbsp;&nbsp;&nbsp;
														<strong>Class:</strong> $student_class$student_section&nbsp;&nbsp;&nbsp;
														<strong>Session:</strong> $student_session&nbsp;&nbsp;&nbsp;
														<strong>Sex:</strong> $student_sex&nbsp;&nbsp;&nbsp;
														
														</div>
														";
														
														
														$dossier .= "
														<div style='margin:30px'>
														<strong>Obtainable:</strong> $total_marks &nbsp;&nbsp;&nbsp; 
														<strong>Score obtained:</strong> $grand_total_mark &nbsp;&nbsp;&nbsp; 
														<strong>Average:</strong> $average &nbsp;&nbsp;&nbsp; 
														<strong>Class Average:</strong> $class_average &nbsp;&nbsp;&nbsp; 
														<strong>Position:</strong> $class_position Out of $student_count &nbsp;&nbsp;&nbsp; 
														<br />
														<strong>Subjects:</strong> $subject_count &nbsp;&nbsp;&nbsp;
														</div>														
														
														";	
														
														$dossier .= "
														<div style='margin:30px'>
														<div style='margin:30px;border:1px solid black;text-align:center;'>
														<strong>
														General character traits - Keys: 5 - Excellent, 4 - Very good, 3 - Good, 2 - Fair, 1 - poor
														</strong>
														</div>
<table border='1px' style='width:100%;'>	
<tr><td>Punctuality</td><td>$student_c1</td><td>Sense of Responsibility</td><td>$student_c2</td><td>Organizational Ability</td><td>$student_c3</td><td>Communiaction Skill</td><td>$student_c4</td><td>Sports</td><td>$student_c5</td></tr>													
<tr><td>Neatness</td><td>$student_c6</td><td>Initiative</td><td>$student_c7</td><td>Spirit of Co-operation</td><td>$student_c8</td><td>Musical Skill</td><td>$student_c9</td><td>Craft</td><td>$student_c10</td></tr>													
<tr><td>Politeness</td><td>$student_c11</td><td>Relationship with Teacher</td><td>$student_c12</td><td>Tolerance</td><td>$student_c13</td><td>Hand Writing</td><td>$student_c14</td><td>Fluency</td><td>$student_c15</td></tr>													
<tr><td>Attentiveness</td><td>$student_c16</td><td>Respect for others</td><td>$student_c17</td><td>Self Control</td><td>$student_c18</td><td>Courage</td><td>$student_c19</td><td>Humility</td><td>$student_c20</td></tr>													
</table>														
														</div>														
														
														";	
														?>
														
														
														<?php
														
													
														
														
														$display_id = $student['student_id']. "_term";
														
														echo "
														<td>
														<div style='display:none;' id='$display_id'>
														$dossier_header
														$dossier_top
														$dossier
														</div>
														<input type='button' class='btn btn-primary btn-sm' value='VIEW' onclick=\"dialog('',document.getElementById('$display_id').innerHTML);\"></td>
														";									
														?>
														
														<!--
                                                        <th><?php
                                                            if ($result == "Pass") {

                                                                echo "<label class='label label-success'>";
                                                            } else {

                                                                echo "<label class='label label-danger'>";
                                                            }
                                                            echo $result;
                                                            echo "<label/>";
                                                            ?></th>
														-->	
                                                        <?php
                                                    } else {
                                                        ?>

                                                        <?php
                                                    }
                                                    ?>

                                                </tr>
                                                <?php
                                            }
                                            ?>

                                            </tbody>
                                        </table>
                                    </div>
<!--- Annual -->  <!--- Annual --> <!--- Annual --> <!--- Annual --> <!--- Annual -->
                        <div class="box-header with-border">
                            <h3 class="box-title">
                                <i class="fa fa-list"></i> ANNUAL REPORT</h3>
                        </div>
							<div class="table-responsive">
									<div class="download_label">Annual Report</div>
                                        <table class="table table-striped table-bordered table-hover example">
                                            <thead>
                                                <tr>
                                                    <th>
                                                        <?php echo $this->lang->line('admission_no'); ?>
                                                    </th>
                                                    <th>
                                                        <?php echo $this->lang->line('roll_no'); ?>
                                                    </th>
                                                    <th>
                                                        <?php echo $this->lang->line('student'); ?>
                                                    </th>
                                                    <th>
                                                        <?php echo $this->lang->line('gender'); ?>
                                                    </th>


                                                    <?php
                                                    $s = 0;
                                                    if ($examSchedule['status'] == "yes") {
                                                        foreach ($examSchedule['result'] as $key => $st) {
                                                            if ($s == 0) {
                                                                foreach ($st['exam_array'] as $key => $exam_schedule) {
                                                                    ?>
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "1ST TERM";
                                                                        ?>
                                                                    </th>
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "2ND TERM";
                                                                        ?>
                                                                    </th>																	
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "3RD TERM";
                                                                        ?>
                                                                    </th>
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name'] . "<br /> ANNUAL TOTAL";
                                                                        ?>
                                                                    </th>	
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . " ANNUAL HIGHEST";
                                                                        ?>
                                                                    </th>	
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . "ANNUAL LOWEST";
                                                                        ?>
                                                                    </th>
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . " ANNUAL AVERAGE";
                                                                        ?>
                                                                    </th>	
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . " ANNUAL POSITION";
                                                                        ?>
                                                                    </th>
																	<th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name']. "<br/>" . " ANNUAL GRADE";
                                                                        ?>
                                                                    </th>																	
																	
                                                                    <?php
                                                                }
                                                            }
                                                            $s++;
                                                        }
                                                    } else {
                                                        ?>

                                                        <?php
                                                    }
                                                    ?>
                                                    <th>ANNUAL GRAND TOTAL</th>
                                                    <th>ANNUAL Grand Obtainable</th>
                                                    <th><?php echo $this->lang->line('percent') . ' (%)'; ?></th>
                                                    <th>CLASS AVERAGE</th>
                                                    <th>POSITION</th>
                                                    <th>EDIT</th>
                                                    <th>DOSSSIER</th>
                                                 <!--   <th><?php echo $this->lang->line('result'); ?></th> -->
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $s = 0;
                                                foreach ($examSchedule['result'] as $key => $student) {
                                                    ?>
                                                <input type="hidden" name="student[]" value="<?php echo $student['student_id'] ?>">

                                                <?php
                                                if (!empty($student['exam_array'])) {
                                                    if ($s == 0) {
                                                        foreach ($student['exam_array'] as $key => $exam_schedule) {
                                                            ?>
                                                            <input type="hidden" name="exam_schedule[]" value="<?php echo $exam_schedule['exam_schedule_id'] ?>">
                                                            <?php
                                                        }
                                                    }
                                                } else {
                                                    ?>

                                                    <?php
                                                }
                                                $s++;
                                            }
                                            ?>
                                            <?php
                                            foreach ($examSchedule['result'] as $key => $student) {
												
												$dossier = "<div style='margin:40px;'><table border='1' style='width:100%;'>";
												
												$dossier .= "
												<tr style='font-weight:bold;'>
												<td>SUBJECTS</td>
												<td>Term 1</td>
												<td>Term 2</td>
												<td>Term 3</td>
												<td>Annual Total</td>
												<td>Highest in Class</td>
												<td>Lowest in Class</td>
												<td>Average</td>
												<td>Position</td>
												<td>Grade</td>
												<td>Remark</td>
												</tr>
												";
												
                                                $total_marks = 0;
                                                $obtain_marks = "0";
                                                $result = "Pass";
                                                ?>
                                                <tr>
                                                    <td>
                                                        <?php echo $student['admission_no'] ?>
                                                    </td>
                                                    <td>
                                                        <?php echo $student['roll_no'] ?>
                                                    </td>
                                                    <td>
                                                        <?php echo $student['firstname'] . " " . $student['lastname']; ?>
                                                    </td>
                                                    <td>
                                                        <?php echo $student['gender'] ?>
													<?php
													///OTHER STUDENT DETAILS
												//	echo "<pre>";
												//	echo $student['gender'];
												//	print_r($student['current_details']);
												//	echo $student['current_details']['class'] . $student['current_details']['section'];
												//	echo "</pre>";
													///END OTHER STUDENT DETAILS	
					//	echo "<img src='" . base_url() . "/" . $student['current_details']['image'] ."' width='100px'>";
													?>									
                                                    </td>
                                                    <?php
													
													$each_student_id = $student['student_id'];
                                                    if (!empty($student['exam_array'])) {
														$grand_total_mark = 0; 
                                                        count($student['exam_array']);
                                                        $s = 0;
                                                        foreach ($student['exam_array'] as $key => $exam_schedule) {
															
															$dossier .= "<tr>";
															$dossier .= "<td>". $exam_schedule['exam_name'] . "</td>";
															
                                                            $total_marks = (int)$total_marks + (int)$exam_schedule['full_marks'];
                                                            ?>
															<td>															
															<?php 																														
																$sub_term_total1 = subject_term_total($annual_result, 0, $each_student_id, $key); 															
																echo $sub_term_total1; 
																$dossier .= "<td>". $sub_term_total1 . "</td>";
															?>
															<?php  ?>	
															</td>
															<td>
															<?php 																														
																$sub_term_total2 = subject_term_total($annual_result, 1, $each_student_id, $key); 															
																echo $sub_term_total2; 
																$dossier .= "<td>". $sub_term_total2 . "</td>";
															?>
															<?php  ?>	
															
															</td>
															<td>
															<?php 																														
																$sub_term_total3 = subject_term_total($annual_result, 2, $each_student_id, $key); 															
																echo $sub_term_total3; 
																$dossier .= "<td>". $sub_term_total3 . "</td>";
															?>
															</td>
                                                            <td>
															<?php
															$sub_annual_total = subject_annual_total($annual_result, $each_student_id, $key); 															
															echo $sub_annual_total;
															$dossier .= "<td>". $sub_annual_total . "</td>";
															?>
															<?php  ?>			
                                                            </td>															
															<td>
															<?php																
															$subject_range = subject_highest($annual_result, $key, "max"); 															
															echo $subject_range;
															$dossier .= "<td>". $subject_range . "</td>";
															?>
															<?php  ?>																
															</td>	
															<td>
															<?php																
															$subject_range = subject_highest($annual_result, $key, "min"); 															
															echo $subject_range;
															$dossier .= "<td>". $subject_range . "</td>";
															?>
															<?php  ?>									
															</td>	
															<td>
															<?php

															$sub_avg = subject_average($annual_result, $key);															
															$sub_avg = number_format($sub_avg, 2, '.', '');
															echo $sub_avg;
															$dossier .= "<td>". $sub_avg . "</td>";
															?>
															</td>	
															<td>
															<?php 
															//subject_position
															//
															$sub_postion = subject_position($annual_result, $each_student_id, $key);			
															echo $sub_postion;
															$dossier .= "<td>". $sub_postion . "</td>";													
															?>
															</td>
															<td>
															<?php 
																///SET MARK GRADE
																$e_annual = $sub_annual_total/3;
																		$grade_name = "";
																		$grade_desc = "";
																		foreach($gradeList as $grade => $grade_details){
																			if(($e_annual >= $grade_details['mark_from']) && ($e_annual <= $grade_details['mark_upto'])){
																			//	echo $grade_details['name'];
																				$grade_name = $grade_details['name'];
																				$grade_desc = $grade_details['description'];
																			}
																			
																			if(($e_annual > 100) || ($e_annual < 0)){
																			//	echo $grade_details['name'];
																				$grade_name = "<label class='label label-danger'>Out of range</label>";
																				$grade_desc = "<label class='label label-danger'>Out of range</label>";
																			}
																			
																			
																		}
																echo 	$grade_name;
																$dossier .= "<td>". $grade_name . "</td>";																											
																		///END SET MARK GRADE

															?>
															</td>
															
															<?php										
															$dossier .= "<td>". $grade_desc . "</td>";
															?>
														
															
                                                            <?php
															
														$dossier .= "</tr>";	
                                                        }
                                                        if ($s == count($student['exam_array'])) {
                                                            $obtain_marks = 0;
                                                        }
                                                        ?>
														
													<?php
														$dossier .= "</table></div>";
													?>
														
                                                     <!--   <td> <?php echo $obtain_marks . " /" . $total_marks; ?> </td> -->
													 
                                                        <td>
														<?php 
														//annual_total
														$annual_total = annual_total($annual_result, $each_student_id);			
														echo $annual_total;														

														?> 
														
														</td>
														
                                                        <td> 														
														<?php 
														$annual_obtainable = count($annual_result[0][0]['exam_array']) * 100 * 3;
														echo $annual_obtainable;
														
														?> 
														
														</td>
														
                                                        <td> 
														<?php
                                                            $annual_per = $annual_total * 100 / $annual_obtainable;
                                                            $annual_per = number_format($annual_per, 2, '.', '');
                                                            echo $annual_per;
                                                            ?>

														<td>														
														<?php 
														
														//annual_class_average														
														$annual_class_average = annual_class_average($annual_result);
														$annual_class_average_percent = $annual_class_average/$annual_obtainable * 100;
														$annual_class_average_percent = number_format($annual_class_average_percent, 2, '.', '');															
														echo $annual_class_average_percent;															
														?>
														</td>
														
														</td>
														<td>
														<?php 
															$annual_position = annual_position($annual_result, $each_student_id);
															echo $annual_position;
														?>
														</td>
														
														<td><button class='btn btn-primary btn-sm'>EDIT</button></td>
																												<?php 
														$student_count = count($examSchedule['result']);
														$subject_count = count($examSchedule['result'][0]['exam_array']);
														$student_admission_no = $student['admission_no'];
														$student_firstname = $student['firstname'];
														$student_lastname = $student['lastname'];
														$x_student_id = $student['student_id'];
														$student_class = $class_name;
														$student_section = $section_name;
														$student_session = $student['session_name'];
													//	$student_sex = $examSchedule['result'][$x_student_id]['current_details']['gender'];
														$student_sex = $student['gender'];
														$student_image = $student['current_details']['image'];
														$setting_name = $setting['name'];
														$setting_email = $setting['email'];
														$setting_phone = $setting['phone'];
														$setting_address = $setting['address'];
														$setting_image = $setting['image'];
													//	$student_image = "<img src='" . base_url() . "/" . $student['current_details']['image'] ."' width='100px'>";													
														?>
														<?php
														$dossier_header = "
														<div style='margin:30px; padding:10px; border:1px black solid;'>
														<table style='width:100%;text-align:center;'>
														<tr>
														<td width='15%'>
														<img src='" . base_url() . "/uploads/school_content/logo/" . $setting_image ."' width='100px' border='1' />
														</td>
														<td width='70%'>
														<h1 style='margin:0px;padding:0px;'>$setting_name</h1>
														<h3 style='margin:0px;padding:0px;'>$setting_address</h3>
														<h4 style='margin:0px;padding:0px;'>$setting_phone</h4>
														<h4 style='margin:0px;padding:0px;'>$setting_email</h4>
														
														</td>
														<td width='15%'>
														<img src='" . base_url() . "/" . $student_image ."' width='100px' border='1' />
														</td>
														</tr>														
														</table>
														</div>
														<center><h2 style='margin:0px;padding:0px;'> STUDENT ANNUAL REPORT </h2></center>
														";
														
														
														$dossier_top = "
														<div style='margin:30px; padding:10px; border:1px black solid;'>
														<strong>Admission No:</strong> $student_admission_no &nbsp;&nbsp;&nbsp;
														<strong>Student's Name:</strong> $student_lastname $student_firstname &nbsp;&nbsp;&nbsp;
														<br />
														<br />
														<strong>Term:</strong> Annual &nbsp;&nbsp;&nbsp;
														<strong>Class:</strong> $student_class$student_section&nbsp;&nbsp;&nbsp;
														<strong>Session:</strong> $student_session&nbsp;&nbsp;&nbsp;
														<strong>Sex:</strong> $student_sex&nbsp;&nbsp;&nbsp;
														
														</div>
														";														

														$dossier .= "
														<div style='margin:30px'>
														<strong>Obtainable:</strong> $annual_obtainable &nbsp;&nbsp;&nbsp; 
														<strong>Score obtained:</strong> $annual_total &nbsp;&nbsp;&nbsp; 
														<strong>Average:</strong> $annual_per &nbsp;&nbsp;&nbsp; 
														<strong>Class Average:</strong> $annual_class_average_percent &nbsp;&nbsp;&nbsp; 
														<strong>Position:</strong> $annual_position Out of $student_count &nbsp;&nbsp;&nbsp; 
														<br />
														<strong>Subjects:</strong> $subject_count &nbsp;&nbsp;&nbsp;
														</div>														
														
														";															
														?>

														
														<?
														$display_id = $student['student_id']. "_annual";
														echo "
														<td>
														<div style='display:none;' id='$display_id'>
														$dossier_header
														$dossier_top
														$dossier
														</div>
														<input type='button' value='VIEW' onclick=\"dialog('',document.getElementById('$display_id').innerHTML);\"></td>
														";
														?>

														<!--
                                                        <th><?php
                                                            if ($result == "Pass") {

                                                                echo "<label class='label label-success'>";
                                                            } else {

                                                                echo "<label class='label label-danger'>";
                                                            }
                                                            echo $result;
                                                            echo "<label/>";
                                                            ?></th>
														-->	
                                                        <?php
                                                    } else {
                                                        ?>

                                                        <?php
                                                    }
                                                    ?>

                                                </tr>
                                                <?php
                                            }
                                            ?>

                                            </tbody>
                                        </table>
                                    </div>
<!--- End Annual -->
                                </form>
                                <?php
                            } else {
                                ?>
                                <div class="alert alert-info"><?php echo $this->lang->line('no_record_found'); ?></div>
                                <?php
                            }
                            ?>

                        </div><!---./end box-body--->
                    </div>
                </div>
                <!-- right column -->
            </div>   <!-- /.row -->
            <?php
        } else {
            
        }
        ?>
    </section><!-- /.content -->
</div>
<?php
function highest($e_id, $exam){ 
$subject_total_array = array();
	for ($i=0;$i<count($exam['result']);$i++){
			for ($j=0;$j<count($exam['result'][$i]['exam_array']);$j++){
				
				$each_student = $exam['result'][$i]['exam_array'][$j];
				if($e_id == $each_student['exam_schedule_id']){
				$each_student_total = $each_student['ca1'] + $each_student['ca2'] + $each_student['ca3'] + $each_student['get_marks'];	
				$subject_total_array[$i] = $each_student_total;	
				}					
		}
	
	}
	return max($subject_total_array);
}


function lowest($e_id, $exam){ 
$subject_total_array = array();
	for ($i=0;$i<count($exam['result']);$i++){
			for ($j=0;$j<count($exam['result'][$i]['exam_array']);$j++){
				
				$each_student = $exam['result'][$i]['exam_array'][$j];
				if($e_id == $each_student['exam_schedule_id']){
				$each_student_total = $each_student['ca1'] + $each_student['ca2'] + $each_student['ca3'] + $each_student['get_marks'];	
				$subject_total_array[$i] = $each_student_total;	
				}					
		}
	
	}
	return min($subject_total_array);
}


function average($e_id, $exam){
	$subject_total_array = array();
	for ($i=0;$i<count($exam['result']);$i++){
			for ($j=0;$j<count($exam['result'][$i]['exam_array']);$j++){
				
				$each_student = $exam['result'][$i]['exam_array'][$j];
				if($e_id == $each_student['exam_schedule_id']){
				$each_student_total = $each_student['ca1'] + $each_student['ca2'] + $each_student['ca3'] + $each_student['get_marks'];	
				$subject_total_array[$i] = $each_student_total;	
				}					
		}
	
	}
	$average = array_sum($subject_total_array)/count($subject_total_array);
	return number_format($average, 2, '.', '');
	
	}
	
	
function position($e_id, $exam, $s_id){
	$subject_total_array = array();
	for ($i=0;$i<count($exam['result']);$i++){
			for ($j=0;$j<count($exam['result'][$i]['exam_array']);$j++){
				
				$each_student = $exam['result'][$i]['exam_array'][$j];
				if($e_id == $each_student['exam_schedule_id']){
				$each_student_total = $each_student['ca1'] + $each_student['ca2'] + $each_student['ca3'] + $each_student['get_marks'];	
				$subject_total_array[$i] = $each_student_total;	
				$stu_id = (string) $exam['result'][$i]['student_id'];	
				$stu_total = (string) $each_student_total;	
				$student_total[$stu_id] = $stu_total;	
				}					
		}
	
	}
/*		
		echo "$s_id -- <br />";
		echo "<pre>";
		print_r($student_total);
		natsort($student_total);
		print_r($student_total);
		
*/	
	
	$student_total_reset_key = array_values($student_total);
	
	rsort($student_total_reset_key);
	
//	print_r($student_total_reset_key);	

	foreach($student_total as $sid => $stotal){
		$check_position = array_search($stotal, $student_total_reset_key);
		if(($stotal == $student_total_reset_key[$check_position]) && ($sid == $s_id)){
			$position = $check_position + 1;			
			return $position;	
		}
	}
	
}




function class_average($exam){
	$subject_total_array = array();
	$each_student_total = 0;
	$exam_count = count($exam['result'][0]['exam_array']);
	
	for ($i=0;$i<count($exam['result']);$i++){
		
			for ($j=0;$j<count($exam['result'][$i]['exam_array']);$j++){
				
				$each_student = $exam['result'][$i]['exam_array'][$j];

				$each_student_total += $each_student['ca1'] + $each_student['ca2'] + $each_student['ca3'] + $each_student['get_marks'];	
				$subject_total_array[$i] = $each_student_total;	
					
		}
	
	}

	$average = $each_student_total/(100*$exam_count*count($exam['result'])) * 100;

	return number_format($average, 2, '.', '');

	
}

//class_position
	
function class_position($exam, $s_id){
	$subject_total_array = array();
	for ($i=0;$i<count($exam['result']);$i++){
		$each_student_total = 0;
			for ($j=0;$j<count($exam['result'][$i]['exam_array']);$j++){
				
				$each_student = $exam['result'][$i]['exam_array'][$j];
			//	if($e_id == $each_student['exam_schedule_id']){
				$each_student_total += $each_student['ca1'] + $each_student['ca2'] + $each_student['ca3'] + $each_student['get_marks'];	
				$subject_total_array[$i] = $each_student_total;	
				$stu_id = (string) $exam['result'][$i]['student_id'];	
				$stu_total = (string) $each_student_total;	
				$student_total[$stu_id] = $stu_total;	
			//	}					
		}
	
	}
/*		
		echo "$s_id -- <br />";
		echo "<pre>";
		print_r($student_total);
		natsort($student_total);
		print_r($student_total);
		
*/	
	
	$student_total_reset_key = array_values($student_total);
	
	rsort($student_total_reset_key);
	
//	print_r($student_total_reset_key);	

	foreach($student_total as $sid => $stotal){
		$check_position = array_search($stotal, $student_total_reset_key);
		if(($stotal == $student_total_reset_key[$check_position]) && ($sid == $s_id)){
			$position = $check_position + 1;			
			return $position;	
		}
	}
	
}



//////ANNUAL_CALCULATIONS

function subject_term_total($annual_result, $term_key, $this_student_id, $subject_key){
	foreach($annual_result[$term_key] as $student_key => $student_details){
		if($student_details['student_id'] == $this_student_id){
			foreach($student_details['exam_array'] as $sub_key => $sub_details){
				if($sub_key == $subject_key){
					$total_subject_score = $sub_details['ca1'] + $sub_details['ca2'] + $sub_details['ca3'] + $sub_details['get_marks'];
					return $total_subject_score;
				}
				
			}	
			break;
		}
		
	}
	
}




function subject_annual_total($annual_result, $this_student_id, $subject_key){
	$total_subject_score = 0;
	foreach($annual_result as $term_key => $term_details){
		foreach($annual_result[$term_key] as $student_key => $student_details){
			if($student_details['student_id'] == $this_student_id){			
				foreach($student_details['exam_array'] as $sub_key => $sub_details){
					if($sub_key == $subject_key){
						$total_subject_score += $sub_details['ca1'] + $sub_details['ca2'] + $sub_details['ca3'] + $sub_details['get_marks'];						
					}					
				}	
				break;
			}
		}	
	}


return $total_subject_score;
	
}


function subject_highest($annual_result, $subject_key, $min_max){
	
	$scores_array = array();
	
	
	foreach($annual_result as $term_key => $term_details){
		
		foreach($annual_result[$term_key] as $student_key => $student_details){
			//if($student_details['student_id'] == $this_student_id){	
				$total_subject_score = 0;
				foreach($student_details['exam_array'] as $sub_key => $sub_details){
					if($sub_key == $subject_key){
						$total_subject_score += $sub_details['ca1'] + $sub_details['ca2'] + $sub_details['ca3'] + $sub_details['get_marks'];
						$scores_array[$student_details['student_id']] += $total_subject_score;						
					}					
				}	
			//	break;
			//}
		}	
		
	
	}


if($min_max == "max")
{return max($scores_array);}
if($min_max == "min")
{return min($scores_array);}
	
}


function subject_average($annual_result, $subject_key){
	$scores_array = array();	
	foreach($annual_result as $term_key => $term_details){
		
		foreach($annual_result[$term_key] as $student_key => $student_details){
			//if($student_details['student_id'] == $this_student_id){	
				$total_subject_score = 0;
				foreach($student_details['exam_array'] as $sub_key => $sub_details){
					if($sub_key == $subject_key){
						$total_subject_score += $sub_details['ca1'] + $sub_details['ca2'] + $sub_details['ca3'] + $sub_details['get_marks'];
						$scores_array[$student_details['student_id']] += $total_subject_score;						
					}					
				}	
			//	break;
			//}
		}	
		
	
	}
//////DIVIDE BY UPLOADED SUBJECTS
	//$average = array_sum($scores_array)/count($scores_array)/count($annual_result);
	$average = array_sum($scores_array)/count($scores_array)/3;
	return $average;

	
}

function subject_position($annual_result, $this_student_id, $subject_key){
	
	$scores_array = array();
	
	
	foreach($annual_result as $term_key => $term_details){
		
		foreach($annual_result[$term_key] as $student_key => $student_details){
			//if($student_details['student_id'] == $this_student_id){	
				$total_subject_score = 0;
				foreach($student_details['exam_array'] as $sub_key => $sub_details){
					if($sub_key == $subject_key){
						$total_subject_score += $sub_details['ca1'] + $sub_details['ca2'] + $sub_details['ca3'] + $sub_details['get_marks'];
						$scores_array[$student_details['student_id']] += $total_subject_score;						
					}					
				}	
			//	break;
			//}
		}	
		
	
	}
	
	$student_total = $scores_array;
	
	
	$student_total_reset_key = array_values($student_total);
	
	rsort($student_total_reset_key);
	
//	print_r($student_total_reset_key);	

	foreach($student_total as $sid => $stotal){
		$check_position = array_search($stotal, $student_total_reset_key);
		if(($stotal == $student_total_reset_key[$check_position]) && ($sid == $this_student_id)){
			$position = $check_position + 1;			
			return $position;
			break;
		}
	}	



	
}




function annual_total($annual_result, $this_student_id){
	$total_subject_score = 0;
	foreach($annual_result as $term_key => $term_details){
		foreach($annual_result[$term_key] as $student_key => $student_details){
			if($student_details['student_id'] == $this_student_id){			
				foreach($student_details['exam_array'] as $sub_key => $sub_details){
				//	if($sub_key == $subject_key){
						$total_subject_score += $sub_details['ca1'] + $sub_details['ca2'] + $sub_details['ca3'] + $sub_details['get_marks'];						
				//	}					
				}	
				break;
			}
		}	
	}


return $total_subject_score;
	
}

function annual_class_average($annual_result){
	$total_subject_score = 0;
	foreach($annual_result as $term_key => $term_details){
		foreach($annual_result[$term_key] as $student_key => $student_details){
				foreach($student_details['exam_array'] as $sub_key => $sub_details){
						$total_subject_score += $sub_details['ca1'] + $sub_details['ca2'] + $sub_details['ca3'] + $sub_details['get_marks'];										
				}	
		}	
	}


return ($total_subject_score/count($annual_result[0]));
}



function annual_position($annual_result, $this_student_id){
	$scores_array = array();
	foreach($annual_result as $term_key => $term_details){
		
		foreach($annual_result[$term_key] as $student_key => $student_details){
				$total_subject_score = 0;
				foreach($student_details['exam_array'] as $sub_key => $sub_details){
						$total_subject_score += $sub_details['ca1'] + $sub_details['ca2'] + $sub_details['ca3'] + $sub_details['get_marks'];
															
				}
			$scores_array[$student_details['student_id']] += $total_subject_score;	
		}	
		
	
	}
	
	$student_total = $scores_array;	
	
	$student_total_reset_key = array_values($student_total);
	
	rsort($student_total_reset_key);
	
//	print_r($student_total_reset_key);	

	foreach($student_total as $sid => $stotal){
		$check_position = array_search($stotal, $student_total_reset_key);
		if(($stotal == $student_total_reset_key[$check_position]) && ($sid == $this_student_id)){
			$position = $check_position + 1;			
			return $position;
			break;
		}
	}		
}

echo "
<script>alert('";
var_dump($className);
echo "
');</script>
";



?>

<style>
#dialog {
position:fixed;
top:0px;
left:0px;
width:100%;
height:100%;
background: url('<?php echo base_url()?>/backend/images/fading.png');
display:none;
z-index:100000;
}

#dialog_box {
width:50%;
height:50%;
background:white;
overflow: auto;
position:absolute;
border-radius:10px 10px;
border:4px green dotted;
z-index:100002;
}

#dialog_head{
opacity:1;
}
</style>

<div id="dialog">

<div id="dialog_box">
<h1 style="margin:0px;text-align:center;" id="dialog_head"></h1>
<div id="dialog_body">

</div>
<center><button class='btn btn-primary btn-sm' onclick="close_dialog()">CLOSE</button></center>
</div>

</div>


<script>
function dialog(head,body){
//$("#dialog").slideDown();
$("#dialog").fadeIn();
$("#dialog_head").html(head);
$("#dialog_body").html(body);
//$("#dialog_box").css("width", "200px");
//alert(document.body.getBoundingClientRect().width);
window_width = document.body.getBoundingClientRect().width;
box_width = Math.round(7/10 * window_width);
box_position_x = Math.round(window_width-box_width)/2;


window_height = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;

//window_height = document.body.getBoundingClientRect().height;
box_height = Math.round(9/10 * window_height);
box_position_y = Math.round(window_height-box_height)/2;


if(window_width < 400){box_width = window_width; box_position_x = 0;}
if(window_height < 300){box_height = window_height; box_position_y = 0;}

//$("#dialog").css("display", "");
$("#dialog_box").css("position", "fixed");

$("#dialog_box").css("width", box_width + "px");
$("#dialog_box").css("left", box_position_x + "px");

$("#dialog_box").css("height", box_height + "px");
$("#dialog_box").css("top", box_position_y + "px");


}

function close_dialog(){
$("#dialog").fadeOut();
}
</script>
<script type="text/javascript">
    function getSectionByClass(class_id, section_id) {
        if (class_id != "" && section_id != "") {
            $('#section_id').html("");
            var base_url = '<?php echo base_url() ?>';
            var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
            $.ajax({
                type: "GET",
                url: base_url + "sections/getByClass",
                data: {'class_id': class_id},
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, obj)
                    {
                        var sel = "";
                        if (section_id == obj.section_id) {
                            sel = "selected";
                        }
                        div_data += "<option value=" + obj.section_id + " " + sel + ">" + obj.section + "</option>";
                    });
                    $('#section_id').append(div_data);
                }
            });
        }
    }

    $(document).ready(function () {
        $(document).on('change', '#class_id', function (e) {
            $('#section_id').html("");
            var class_id = $(this).val();
            var base_url = '<?php echo base_url() ?>';
            var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
            $.ajax({
                type: "GET",
                url: base_url + "sections/getByClass",
                data: {'class_id': class_id},
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, obj)
                    {
                        div_data += "<option value=" + obj.section_id + ">" + obj.section + "</option>";
                    });
                    $('#section_id').append(div_data);
                }
            });
        });
        var class_id = $('#class_id').val();
        var section_id = '<?php echo set_value('section_id') ?>';
        getSectionByClass(class_id, section_id);
        $(document).on('change', '#feecategory_id', function (e) {
            $('#feetype_id').html("");
            var feecategory_id = $(this).val();
            var base_url = '<?php echo base_url() ?>';
            var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
            $.ajax({
                type: "GET",
                url: base_url + "feemaster/getByFeecategory",
                data: {'feecategory_id': feecategory_id},
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, obj)
                    {
                        div_data += "<option value=" + obj.id + ">" + obj.type + "</option>";
                    });
                    $('#feetype_id').append(div_data);
                }
            });
        });
    });
    $(document).on('change', '#section_id', function (e) {
        $("form#schedule-form").submit();
    });
</script>
