<?php 

function extexam_mock_exam_broadsheet($args) {
	$class = eedu_portal_get_class_selection($args['class_category']);
	$html = "";
	$html .= eedu_portal_default_paperhead();
    $html .= extexam_make_broadsheet($class['class'], $class['category'], $args['term'], $args['ext_exam']);
    $html .= "<div>";
	$html .= "<a href=\"print-mock-broadsheet?class=".$class['class']."&category=".$class['category']."&term=".$args['term']."&ext_exam=".$args['ext_exam']."&media=print\" class=\"btn btn-default popmeup\" data-width=1270 data-height=800>Print</a>";
	$html .= "<a href=\"javaScript:void(0);\" class=\"btn btn-default ajax-action\" data-action-callback=\"eedu_portal_refresh_mock_broadsheet\" data-class=".$class['class']." data-category=\"".$class['category']."\" data-term=".$args['term']." data-ext_exam=".$args['ext_exam']." data-callback=\"click\" data-callbackid=\"#search-query-btn\">Refresh Changes</a>";
    $html .= "<a href=\"javaScript:void(0);\" data-action-callback=\"extexam_compile_mock_results\" data-class=\"".$class['class']."\" data-category=\"".$class['category']."\" data-term=\"".$args['term']."\" data-content=\"Are you sure you want to go ahead and compile this result?\" data-ext_exam=\"".$args['ext_exam']."\" class=\"btn btn-primary ajax-action\">Compile Result</a>";
    $html .= "</div>";
    return $html;
}

function extexam_mock_exam_gradebook($args) {
	if($args['course'] == "") {
		return "You have not selected any subject";
	}
	if($args['ext_exam'] == "") {
		return "Please specify the mock examination";
	}
	$class = eedu_portal_get_class_selection($args['class_category']);
	$students = eedu_portal_get_class_students($class['class'], $class['category'], $args['term']);
	$html = "";
	$table = new table("gradebook", $students);
	$table->grading = new grading;
	$table->grading->root_mode_of_scoring();
	$table->grades = $table->grading->get_grades();
	$table->existing = db_post_unique(['type' => 'mock_exam_gradebook', 'class' => $class['class'], 'category' => $class['category'], 'course' => $args['course'], 'term' => $args['term'], 'exam' => $args['ext_exam']]);
	if($table->existing) {
		$table->results = _unserialize($table->existing['scores']);
	}
	$table->table_id = "table";
	$columns = [
		"sn" => "SN",
		"fullname" => "Full Name"
	];
	$dynamic_columns = [
		'grade' => "_tf_mock_exam_gradebook_grade",
		'score' => "_tf_mock_exam_gradebook_score"
	];
	$columns['score'] = "<div class=\"text-center\"><small>Score</small><br />100%</div>";
	$columns['grade'] = "<div class=\"text-center\">Grade</div>";
	$table->set_display_columns($columns);
	$table->set_dynamic_columns($dynamic_columns);
	$html .= "<form method=\"post\" action=\"contents/plugins/external_examination/ajax.php\" id=\"result_sheet_form\">";
	$html .= "<button class=\"btn btn-primary submit pull-right\" id=\"submit-btn1\">Save Entries</button>";
	$html .= eedu_portal_default_paperhead();
	$html .= "<div class=\"text-center\"><strong>".strtoupper(get_class_name($class['class'], $class['category'])." ".get_course_name($args['course'])." ".get_full_term_name($args['term']))."</strong><br /><p class=\"text-muted\"><small>".$args["ext_exam"]." MOCK EXAMINATION</small></p></div><hr />";
	$html .= $table->table_html();
	$html .= "<div>";
	$html .= "<input type=\"hidden\" name=\"action\" value=\"save_gradebook\">";
	$html .= "<input type=\"hidden\" name=\"class\" value=\"".$class['class']."\">";
	$html .= "<input type=\"hidden\" name=\"category\" value=\"".$class['category']."\">";
	$html .= "<input type=\"hidden\" name=\"course\" value=\"".$args['course']."\">";
	$html .= "<input type=\"hidden\" name=\"term\" value=\"".$args['term']."\">";
	$html .= "<input type=\"hidden\" name=\"exam\" value=\"".$args['ext_exam']."\">";
	$html .= "<input type=\"hidden\" name=\"session\" value=\"".get_term_session($args['term'])."\">";
	$html .= "<button class=\"btn btn-primary submit pull-right\" id=\"submit-btn\">Save Entries</button>";
	$html .= "</div>";
	$html .= "</form>";
	return $html;
}