<?php 

function manage_my_classes_cb() {
	global $post_meta;
	$sorting = new sorting;
	$session = Session::getInstance();
	$token = new_token();
	$form_teacher_classes = get_form_teacher_classes($session->id);
	$course_mapping = get_option('course_mapping');
	$prefect_mapping = get_option('prefect_mapping');
	foreach ($form_teacher_classes as $class): 

		$students = get_class_students(['class_id' =>$class['class_id'], 'category_id' =>$class['category_id']]);
		$students = $output = $sorting->sort_by_meta_value($students, 'surname', 'asc');
		$option = [];
		if(_count($students) > 0) {
			foreach ($students as $student_id => $student_meta) {
				$option[$student_meta['surname'].' '.$student_meta['other_names']] = $student_meta['id'];
			}
		}
	?>
	<form method="post" action="contents/plugins/eedu_portal/ajax.php" id="<?php echo $class['class_id'].'-cat'.$class['category_id'] ?>">
	<div class="panel panel-custom bg-white">
	    <div class="panel-heading">
	        <h1><?php echo get_class_name($class['class_id'], $class['category_id']); ?></h1>
	    </div>
            <div class="panel-body instruction">
            <div class="row">
	            <div class="col-md-6">
	                <div class="row">
	                	<div class="col-md-12">
	                		<div class="square-border">
	                			<?php select(['label' => 'Nominate '.get_option('pref_name_for_class_prefect'), 'id' => 'prefect', 'name' => 'prefect['.$class['class_id'].']['.$class['category_id'].']', 'class' => 'selectstud form-control', 'data-form' => $class['class_id'].'-cat'.$class['category_id']], $option, $prefect_mapping[$class['class_id']][$class['category_id']]) ?>
	                			<input type="hidden" name="action" value="nominate_class_prefect">
	                		</div>
	                	</div>
	                	<div class="col-md-6">
	                		<div class="padding-top">
	                			<a href="mark-attendance" class="btn btn-outline-info btn-block"><i class="fas fa-pencil"></i>&nbsp;Mark Attendance</a>
	                			<a href="attendance-report" class="btn btn-outline-info btn-block"><i class="fas fa-bar-chart-o"></i>&nbsp; Attendance Report</a>
	                		</div>
	                	</div>
	                	<div class="col-md-6">
	                		<div class="padding-top">
	                			<a href="edit-timetable?class=<?php echo base64_encode($class['class_id']) ?>&category=<?php echo base64_encode($class['category_id']) ?>" class="btn btn-outline-info btn-block"><i class="fas fa-pencil"></i>&nbsp;Edit Timetable</a>
	                		</div>
	                	</div>
	                </div>
	            </div>
	            
	            <div class="col-md-6">
	                <div class="row">
	                	<div class="col-md-12">
	                		<div class="col-md-6">
								<div class="koweb-card card card-blue text-center helper_step2">
									<div class="card-block">
										<h4 class="card-title">
											<i class="fas fa-clock-o text-white" aria-hidden="true"></i>
										</h4>
										<p class="text-white">Timetable</p>
									</div>
									<a class="card-footer text-white" href="class-timetable?class=<?php echo base64_encode($class['class_id']); ?>&category=<?php echo base64_encode($class['category_id']) ?>">
										Open
									</a>
								</div>
							</div>
							<div class="col-md-6">
								<div class="koweb-card card card-red text-center helper_step2">
									<div class="card-block">
										<h4 class="card-title">
											<i class="fas fa-book text-white" aria-hidden="true"></i>
										</h4>
										<p class="text-white">Broadsheet</p>
									</div>
									<a class="card-footer text-white" href="broadsheet">
										Open
									</a>
								</div>
							</div>
							<div class="col-md-6">
								<div class="card">
				                    <div class="card-body">
				                        <div class="stat-widget-one">
				                            <div class="stat-icon dib"><i class="ti-user text-success border-success"></i></div>
				                            <div class="stat-content dib">
				                                <div class="stat-text">Students</div>
				                                <div class="stat-digit"><?php echo _count($students); ?></div>
				                            </div>
				                        </div>
				                    </div>
				                </div>
							</div>
							<div class="col-md-6">
								<div class="card">
				                    <div class="card-body">
				                        <div class="stat-widget-one">
				                            <div class="stat-icon dib"><i class="ti-layers text-primary border-primary"></i></div>
				                            <div class="stat-content dib">
				                                <div class="stat-text">Courses</div>
				                                <div class="stat-digit"><?php echo _count($course_mapping[$class['class_id']][$class['category_id']]); ?></div>
				                            </div>
				                        </div>
				                    </div>
				                </div>
							</div>
	                	</div>
	                </div>
	            </div>
            </div>
        <hr>
 
   <br>

	<div class="table-responsive vertical-scroll">
	  <table id="xbootstrap-data-table-export" class="table table-striped table-bordered">
            <thead>
              <tr>
                <th>Roll No</th>
				<th>Name</th>
				<th>Student ID</th>
				<th>Image</th>
				<th>Gender</th>
				<th>Class</th>
              </tr>
            </thead>
            <tbody>
<?php
$i = 1;
if(_count($output) > 0) : 
	foreach ($output as $key => $value) {
	 ?>
	 			<tr>
	 				<td><?=$i ?></td>
	 				<td><?=$value['surname'].' '.$value['other_names']; 
	 					action(['profile' => '?id='.$value['id'], 'attendance report' => 'attendance-report?class='.base64_encode($class['class_id']).'&category='.base64_encode($class['category_id']).'&student_id='.base64_encode($value['id'])], ['view_student'], ['edit_student', false]);
	 					?>
	 				</td>
	 				<td><i class="fas fa-user"></i>&nbsp;<?=strtoupper($value['username']);?></td>
	 				<td><img class="img img-72" src="<?php echo get_user_image($value['id']); ?>"></td>
	 				<td><?=$value['gender'];?></td>
	 				<td><?=get_class_name($class['class_id']) ?></td>
	 			</tr>

	<?php $i++; } 
endif;
			?>
            </tbody>
          </table>
	</div>
	</div>
	</div>
	</form>
	<?php endforeach ?>
	<?php
	add_page_javascript('contents/plugins/eedu_portal/js/manage-my-classes.js');
}