<?php 

function attendance_report_cb() {
	global $app;
	$user_meta = $app->user_meta;
	global $post_meta;
	$post = new post;
	$token = new_token();
	
	
	if($user_meta['role'] == 'student') {
		$term = get_option("current_academic_term");
		$term_meta = $post->get_post_meta($term);
		$session_name = get_session_name($term_meta['acsession']);
		$class = $user_meta['class'];
		$category = $user_meta['category'];
		$class_name = get_class_name($class, $category);
		$caption = $user_meta['surname']." ".$user_meta['other_names']." attendance report for ".$class_name." ".$term_meta['term_name']." ".$session_name;
		$individual_analysis = analyse_individual_attendance($class, $category, $term);
	} else {
		do_action("performance_filter");
		if(!isset($_POST['term']))
			return;
		$term = $_POST['term'];
		$term_meta = $post->get_post_meta($term);
		$session_name = get_session_name($term_meta['acsession']);
		$class = $_POST['class'];
		$category = $_POST['category'];
		$class_name = get_class_name($class, $category);
		$caption = $class_name." attendance report for ".$term_meta['term_name']." ".$session_name;
		if(isset($_GET['student_id'])) {
			$student_id = base64_decode($_GET['student_id']);
			$caption = get_fullname($student_id)." attendance report for ".$class_name." ".$term_meta['term_name']." ".$session_name;
			$individual_analysis = analyse_individual_attendance($class, $category, $term, $student_id);
		} else {
			$individual_analysis = false;
		}
	}
	
	$report_analysis = analyse_class_attendance($class, $category, $term);
	?>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-custom bg-white">
			    <div class="panel-heading">
			        <h1><?php echo $caption; ?></h1>
			    </div>
		            <div class="panel-body instruction">
		            	<?php 
		            	if($individual_analysis) {
		            		do_action('get_class_attendance_summary', ['class' => $class, 'category' => $category, 'term' => $term, 'report_analysis' => $report_analysis, 'token' => $token, 'individual_analysis' => $individual_analysis, 'give_details' => true]);
		            	} else {
		            		do_action('get_class_attendance_summary', ['class' => $class, 'category' => $category, 'term' => $term, 'report_analysis' => $report_analysis, 'token' => $token, 'give_details' => false]);
		            	}
		            	?>
		            	
		            </div>
		    </div>
		</div>
	</div>
	<?php
}