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

class excel_result_compilation {

	public static $plugin_ref = "Excel Result Compilation";
	public static $plugin_name = "excel_result_compilation";
	public static $plugin_root = 'contents\plugins\excel_result_compilation';

	public function __construct () {
		
	}

	public static function install() {
		if(VERSION === "delux") {
			unregister_admin_page([
				"ft-comment-offline",
				"upload-result-sheet"
			]);

			unregister_admin_submenu([
				"ft_comment_offline"
			]);
		}
		$super_admin = ['upload_result_sheet', 'bulk_user_upload', 'ft_comment_offline', 'manage_gradebook_with_excel', 'manage_mock_gradebook_with_excel'];
		$admin = ['upload_result_sheet', 'ft_comment_offline', 'manage_gradebook_with_excel', 'manage_mock_gradebook_with_excel'];
		$teacher = ['upload_result_sheet', 'ft_comment_offline', 'manage_gradebook_with_excel', 'manage_mock_gradebook_with_excel'];
		$student = [];
		$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;
		// if(!$post->search_post_by_permalink('upload-result-sheet')) :
		// 	register_admin_page(array(
		// 			'title' => 'Upload Result Sheet',
		// 			'callback' => 'upload_result_sheet_cb',
		// 			'access' => 'upload_result_sheet',
		// 			'permalink' => 'upload-result-sheet'
		// 		));
		// endif;

		if(!$post->search_post_by_permalink('bulk-user-upload')) :
			register_admin_page(array(
					'title' => 'Bulk User Upload',
					'callback' => 'bulk_user_upload_cb',
					'access' => 'bulk_user_upload',
					'permalink' => 'bulk-user-upload'
				));
		endif;

		// if(!$post->search_post_by_permalink('ft-comment-offline')) :
		// 	register_admin_page(array(
		// 			'title' => 'Form Teacher Comment Offline',
		// 			'callback' => 'ft_comment_offline_cb',
		// 			'access' => 'ft_comment_offline',
		// 			'permalink' => 'ft-comment-offline'
		// 		));
		// endif;

		register_admin_page(array(
			'title' => 'Manage Gradebook With Excel',
			'callback' => 'manage_gradebook_with_excel_cb',
			'access' => 'manage_gradebook_with_excel',
			'permalink' => 'manage-gradebook-with-excel'
		));

		register_admin_page(array(
			'title' => 'Manage Mock Gradebook With Excel',
			'callback' => 'manage_mock_gradebook_with_excel_cb',
			'access' => 'manage_mock_gradebook_with_excel',
			'permalink' => 'manage-mock-gradebook-with-excel'
		));

		register_admin_submenu(array(
			'mm_id' => 'users',
			'id' => 'bulk_user_upload',
			'title' => 'Bulk User Upload',
			'icon' => '',
			'page' => 'bulk-user-upload',
			'access' => 'bulk_user_upload'
		));

		// register_admin_submenu(array(
		// 	'mm_id' => 'performance',
		// 	'id' => 'ft_comment_offline',
		// 	'title' => 'FT Comment Offline',
		// 	'icon' => '',
		// 	'page' => 'ft-comment-offline',
		// 	'access' => 'ft_comment_offline'
		// ));

		add_action('bulk_user_upload_form_students', 'download_bulk_student_template_button', 2);
		add_action('bulk_user_upload_form_staff', 'download_bulk_staff_template_button', 2);
		remove_action('_after_compute_result', 'download_template_button', 2);
		remove_action('_after_upload_result_button', 'download_template_button', 2);
		add_action('upload_mock_exam_after', 'download_mock_template_button', 2);
		add_action('upload_mock_exam_after', 'upload_mock_template_button', 1);
		add_action('_after_compute_result', 'upload_template_button', 1);
		add_action('bulk_user_upload_form_students', 'upload_bulk_student_template_button', 1);
		add_action('bulk_user_upload_form_staff', 'upload_bulk_staff_template_button', 1);
		add_action('ft_comment_offline_form', 'ft_comment_offline_template_button', 1);
		add_action('ft_comment_offline_form', 'ft_comment_offline_download_button', 2);
		add_action('search_by_form_teachers', 'search_by_form_teachers');
		add_action('_before_compute_result', '_upload_result_link');

		add_action("after_dz_upload_eedu_upload_gradebook", "eedu_upload_gradebook_after");
		add_action("after_dz_upload_eedu_upload_mock_gradebook", "eedu_upload_mock_gradebook_after");
		add_action("after_dz_upload_eedu_upload_students", "eedu_upload_students_after");
	}

	public static function uninstall() {
		unregister_admin_page([
			'upload-result-sheet',
			'bulk-user-upload',
			'ft-comment-offline'
		]);

		unregister_admin_submenu([
			'bulk_user_upload',
			'ft_comment_offline'
		]);
		remove_action('bulk_user_upload_form_students', 'download_bulk_student_template_button');
		remove_action('bulk_user_upload_form_staff', 'download_bulk_staff_template_button');
		remove_action('_after_compute_result', 'download_template_button');
		remove_action('_after_upload_result_button', 'download_template_button');
		remove_action('_after_compute_result', 'upload_template_button');
		remove_action('bulk_user_upload_form_students', 'upload_bulk_student_template_button');
		remove_action('bulk_user_upload_form_staff', 'upload_bulk_staff_template_button');
		remove_action('ft_comment_offline_form', 'ft_comment_offline_template_button');
		remove_action('ft_comment_offline_form', 'ft_comment_offline_download_button');
		remove_action('search_by_form_teachers', 'search_by_form_teachers');
		remove_action('upload_mock_exam_after', 'download_mock_template_button');
		remove_action('upload_mock_exam_after', 'upload_mock_template_button');
		remove_action('_before_compute_result', '_upload_result_link');
	}
}