<?php 
// version 1.0
require_once(dirname(__FILE__)."/functions.php");
require_once(dirname(__FILE__)."/actions.php");
require_once(dirname(__FILE__)."/do-action.php");
require_once(dirname(__FILE__)."/query-functions.php");
require_once(dirname(__FILE__)."/table-functions.php");

class external_examination {

	public static $plugin_name = "external_examination";
	public static $plugin_ref = "External Examination";

	public function __construct () {
		
	}

	public static function install() {
		if(VERSION === "delux") {
			unregister_admin_page([
				"compiled-mock-results",
				"q-ext-exam",
				"upload-mock-exam",
				"mock-results"
			]);

			unregister_admin_submenu([
				"upload_mock_exam",
				"compiled_mock_results",
				"mock_results"
			]);
		}
		$super_admin = ['external_examination', 'upload_external_exam', 'q_ext_exam', 'mock_exam_gradebook', 'mock_exam_broadsheet', 'compiled_mock_results', 'mock_result_sheet', 'mock_for_mastersheet', 'print_mock_broadsheet'];
		$admin = ['external_examination', 'upload_external_exam', 'q_ext_exam', 'mock_exam_gradebook', 'mock_exam_broadsheet', 'compiled_mock_results', 'mock_result_sheet', 'mock_for_mastersheet', 'print_mock_broadsheet'];
		$teacher = ['external_examination', 'q_ext_exam', 'mock_exam_gradebook', 'mock_exam_broadsheet', 'compiled_mock_results', 'mock_result_sheet', 'print_mock_broadsheet'];
		$student = ['external_examination', 'q_ext_exam', 'download_external_exam', 'mock_result_sheet', 'mock_results'];
		$se = [];
		update_role('software_engineer', array_unique(array_merge($super_admin, $admin, $teacher, $student, $se)));
		update_role('super_admin', $super_admin);
		update_role('admin', $admin);
		update_role('teacher', $teacher);
		update_role('student', $student);

		$post = new post;
		register_admin_page(array(
			'title' => 'Upload External Exam',
			'callback' => 'upload_external_exam_cb',
			'access' => 'upload_external_exam',
			'permalink' => 'upload-external-exam'
		));

		register_admin_page(array(
			'title' => 'Download Result',
			'callback' => 'download_external_exam_cb',
			'access' => 'download_external_exam',
			'permalink' => 'download-external-exam'
		));

		register_admin_page(array(
			'title' => 'Mock Exam Broadsheet',
			'callback' => 'mock_exam_broadsheet_cb',
			'access' => 'mock_exam_broadsheet',
			'permalink' => 'mock-exam-broadsheet'
		));

		register_admin_page(array(
			'title' => 'Gradebook (Mock Exams)',
			'callback' => 'mock_exam_gradebook_cb',
			'access' => 'mock_exam_gradebook',
			'permalink' => 'mock-exam-gradebook'
		));

		register_admin_page(array(
			'title' => 'Mock Result Sheet',
			'callback' => 'mock_result_sheet_cb',
			'access' => 'mock_result_sheet',
			'permalink' => 'mock-result-sheet'
		));

		register_admin_page(array(
			'title' => 'Mock For Mastersheet',
			'callback' => 'mock_for_mastersheet_cb',
			'access' => 'mock_for_mastersheet',
			'permalink' => 'mock-for-mastersheet'
		));

		register_admin_page(array(
			'title' => 'Print Broadsheet',
			'callback' => 'print_mock_broadsheet_cb',
			'access' => 'print_mock_broadsheet',
			'permalink' => 'print-mock-broadsheet'
		));

		register_admin_menu(array(
			'id' => 'external_examination',
			'title' => 'External Examination',
			'icon' => 'fas fa-external-link-alt',
			'page' => '',
			'access' => 'external_examination',
			'order' => 3
		));

		register_admin_submenu(array(
			'mm_id' => 'external_examination',
			'id' => 'mock_exam_gradebook',
			'title' => 'Mock Exam Gradebook',
			'icon' => '',
			'page' => 'mock-exam-gradebook',
			'access' => 'mock_exam_gradebook'
		));

		register_admin_submenu(array(
			'mm_id' => 'external_examination',
			'id' => 'upload_external_exam',
			'title' => 'Upload External Exam',
			'icon' => '',
			'page' => 'upload-external-exam',
			'access' => 'upload_external_exam'
		));

		register_admin_submenu(array(
			'mm_id' => 'external_examination',
			'id' => 'mock_exam_broadsheet',
			'title' => 'Mock Broadsheet',
			'icon' => '',
			'page' => 'mock-exam-broadsheet',
			'access' => 'mock_exam_broadsheet'
		));

		register_admin_submenu(array(
			'mm_id' => 'external_examination',
			'id' => 'download_external_exam',
			'title' => 'Download Result',
			'icon' => '',
			'page' => 'download-external-exam',
			'access' => 'download_external_exam'
		));

		register_admin_submenu(array(
			'mm_id' => 'external_examination',
			'id' => 'mock_for_mastersheet',
			'title' => 'Mock For Mastersheet',
			'icon' => '',
			'page' => 'mock-for-mastersheet',
			'access' => 'mock_for_mastersheet'
		));

		add_action('more_school_settings_field', 'ext_exam_settings_field');
		add_action('save_more_school_settings_field', 'ext_exam_save_settings_field');
		remove_action('more_settings_field', 'ext_exam_settings_field');
		remove_action('save_more_settings_field', 'ext_exam_save_settings_field');
		add_action('display_ext_result_filter', 'display_ext_result_filter');
		add_action('display_mock_result_filter', 'display_mock_result_filter');
		add_action('display_mock_result_filter2', 'display_mock_result_filter2');
		add_action('display_mock_exam_broadsheet', 'display_mock_exam_broadsheet');
		add_action('mock_result_card', 'mock_result_card');
		add_action("more_teacher_set_button", "ext_exam_more_teacher_set_button");
		add_action("compile_mock_result_button", "compile_mock_result_button");

		add_action("search_query_filter_mock_exam_broadsheet", "eedu_portal_class_filter", 1);
		add_action("search_query_filter_mock_exam_broadsheet", "eedu_portal_term_filter", 2);
		add_action("search_query_filter_mock_exam_broadsheet", "extexam_mock_exam_broadsheet_filter", 3);
		add_action("search_query_filter_mock_exam_gradebook", "eedu_portal_class_course_filter", 1);
		add_action("search_query_filter_mock_exam_gradebook", "eedu_portal_term_filter", 2);
		add_action("search_query_filter_mock_exam_gradebook", "extexam_mock_exam_broadsheet_filter", 3);
		add_action("mock_exam_filter", "extexam_mock_exam_broadsheet_filter");
		add_action("extexam_mock_exam_broadsheet_filter", "extexam_mock_exam_broadsheet_filter");
	}

	public static function uninstall() {
		unregister_admin_page([
			'upload-external-exam', 'q-ext-exam', 'download-external-exam', 'upload-mock-exam', 'mock-exam-broadsheet'
		]);

		unregister_admin_menu([
			'external_examination'
		]);

		remove_action('more_settings_field', 'ext_exam_settings_field');
		remove_action('save_more_settings_field', 'ext_exam_save_settings_field');
		remove_action('display_ext_result_filter', 'display_ext_result_filter');
		remove_action('display_mock_result_filter', 'display_mock_result_filter');
		remove_action('display_mock_result_filter2', 'display_mock_result_filter2');
		remove_action('display_mock_exam_broadsheet', 'display_mock_exam_broadsheet');
		remove_action('mock_result_card', 'mock_result_card');
		remove_action("more_teacher_set_button", "ext_exam_more_teacher_set_button");
	}
}