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

class admission {

	public static $plugin_name = "admission";
	public static $plugin_ref = "Admission Module";

	public function __construct () {
		
	}

	public static function install() {
		$common_access = ['check_entrance_result'];
		add_common_access($common_access);
		$super_admin = ['register_new_candidate', 'admission', 'candidate_list', 'entrance_exam_subjects', 'upload_entrance_result', 'candidate_profile', 'offer_admission', 'check_entrance_result'];
		$admin = ['register_new_candidate', 'admission', 'candidate_list', 'upload_entrance_result', 'candidate_profile', 'offer_admission', 'check_entrance_result'];
		$bursar = ['register_new_candidate', 'admission', 'candidate_list', 'check_entrance_result'];
		$teacher = ['check_entrance_result'];
		$student = ['check_entrance_result'];
		$se = ['check_entrance_result'];
		$candidate = ['check_entrance_result'];
		$fresher = ['check_entrance_result'];
		update_role('software_engineer', array_unique(array_merge($super_admin, $admin, $teacher, $student, $se, $bursar, $candidate, $fresher)));
		update_role('super_admin', $super_admin);
		update_role('admin', $admin);
		update_role('teacher', $teacher);
		update_role('student', $student);
		update_role('bursar', $bursar);
		update_role('candidate', $candidate);
		update_role('fresher', $fresher);

		$post = new post;
		if(!$post->search_post_by_permalink('register-new-candidate')) :
			register_admin_page(array(
					'title' => 'Register New Candidate',
					'callback' => 'register_new_candidate_cb',
					'access' => 'register_new_candidate',
					'permalink' => 'register-new-candidate'
				));
		endif;

		if(!$post->search_post_by_permalink('candidate-list')) :
			register_admin_page(array(
					'title' => 'Candidate List',
					'callback' => 'candidate_list_cb',
					'access' => 'candidate_list',
					'permalink' => 'candidate-list'
				));
		endif;

		if(!$post->search_post_by_permalink('entrance-exam-subjects')) :
			register_admin_page(array(
					'title' => 'Entrance Exam Subjects',
					'callback' => 'entrance_exam_subjects_cb',
					'access' => 'entrance_exam_subjects',
					'permalink' => 'entrance-exam-subjects'
				));
		endif;

		if(!$post->search_post_by_permalink('upload-entrance-result')) :
			register_admin_page(array(
					'title' => 'Upload Entrance Result',
					'callback' => 'upload_entrance_result_cb',
					'access' => 'upload_entrance_result',
					'permalink' => 'upload-entrance-result'
				));
		endif;

		if(!$post->search_post_by_permalink('candidate-profile')) :
			register_admin_page(array(
					'title' => 'Candidate Profile',
					'callback' => 'candidate_profile_cb',
					'access' => 'candidate_profile',
					'permalink' => 'candidate-profile'
				));
		endif;

		if(!$post->search_post_by_permalink('check-entrance-result')) :
			register_admin_page(array(
					'title' => 'Check Result',
					'callback' => 'check_entrance_result_cb',
					'access' => 'check_entrance_result',
					'permalink' => 'check-entrance-result',
					'availability' => 'public'
				));
		endif;

		register_admin_menu(array(
			'id' => 'admission',
			'title' => 'Admission Module',
			'icon' => 'fab fa-adn',
			'page' => '',
			'access' => 'admission',
			'order' => 9
		));

		register_admin_submenu(array(
			'mm_id' => 'admission',
			'id' => 'register_new_candidate',
			'title' => 'New Candidate',
			'icon' => '',
			'page' => 'register-new-candidate',
			'access' => 'register_new_candidate'
		));

		register_admin_submenu(array(
			'mm_id' => 'admission',
			'id' => 'candidate_list',
			'title' => 'Candidate List',
			'icon' => '',
			'page' => 'candidate-list',
			'access' => 'candidate_list'
		));

		register_admin_submenu(array(
			'mm_id' => 'admission',
			'id' => 'entrance_exam_subjects',
			'title' => 'Entrance Subjects',
			'icon' => '',
			'page' => 'entrance-exam-subjects',
			'access' => 'entrance_exam_subjects'
		));

		register_admin_submenu(array(
			'mm_id' => 'admission',
			'id' => 'upload_entrance_result',
			'title' => 'Upload Result',
			'icon' => '',
			'page' => 'upload-entrance-result',
			'access' => 'upload_entrance_result'
		));

		add_action('more_school_settings_field', 'admission_settings');
		add_action('save_more_school_settings_field', 'save_admission_settings');
		add_action('ent_exam_filter', 'ent_exam_filter');
		add_action('candidate_filter', 'candidate_filter');
		add_action('after_apply_fees_form', 'set_registration_fee');
		add_action('display_offer_admission_form', 'display_offer_admission_form');
		remove_action('more_settings_field', 'admission_settings');
		remove_action('save_more_settings_field', 'save_admission_settings');
		add_filter("filter_fee", "adm_filter_fee");

	}

	public static function uninstall() {
		unregister_admin_page([
				'register-new-candidate', 'candidate-list', 'entrance-exam-subjects', 'upload-entrance-result', 'publish-entrance-exam-result'
			]);

		unregister_admin_menu([
			'admission'
		]);

		// unregister_admin_submenu([
			
		// ]);

		remove_action('more_school_settings_field', 'admission_settings');
		remove_action('save_more_school_settings_field', 'save_admission_settings');
		remove_action('ent_exam_filter', 'ent_exam_filter');
		remove_action('candidate_filter', 'candidate_filter');
		remove_action('after_apply_fees_form', 'set_registration_fee');
		remove_action('display_offer_admission_form', 'display_offer_admission_form');
	}

}