<?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__)."/filters.php");
require_once(dirname(__FILE__)."/query-functions.php");
require_once(dirname(__FILE__)."/table-functions.php");

class classroom_plus {

	public static $plugin_name = "classroom_plus";
	public static $plugin_root = 'contents\plugins\classroom_plus';
	public static $plugin_ref = "Classroom Plus";

	public function __construct () {
		
	}

	public static function install() {
		$super_admin = ['cp_view_lesson', 'cp_add_lesson', 'cp_edit_lesson', 'cp_attach_lesson_material', 'cp_attach_lesson_material_link', "cp_delete_lesson", 'cp_create_link', 'cp_create_assignment', 'cp_edit_material', 'cp_view_material', 'cp_select_topic', 'cp_classwork_stream', 'cp_add_quiz', 'cp_manage_quiz', 'cp_edit_quiz', 'cp_delete_quiz', 'cp_manage_quiz', 'cp_edit_quiz', 'cp_delete_quiz', 'cp_add_objective_question', 'cp_add_theory_question', "cp_add_question", "cp_edit_question", "cp_delete_question", "cp_delete_answer", "lesson_notes"];
		$admin = ['cp_view_lesson', 'cp_add_lesson', 'cp_edit_lesson', 'cp_attach_lesson_material', 'cp_attach_lesson_material_link', "cp_delete_lesson", 'cp_create_link', 'cp_create_assignment', 'cp_edit_material', 'cp_view_material', 'cp_select_topic', 'cp_classwork_stream', 'cp_add_quiz', 'cp_manage_quiz', 'cp_edit_quiz', 'cp_delete_quiz', 'cp_add_objective_question', 'cp_add_theory_question', "cp_add_question", "cp_edit_question", "cp_delete_question", "cp_delete_answer", "lesson_notes"];
		$bursar = ['cp_view_lesson', 'cp_view_material', 'cp_select_topic', 'cp_classwork_stream'];
		$teacher = ['cp_view_lesson', 'cp_add_lesson', 'cp_edit_lesson', 'cp_attach_lesson_material', 'cp_attach_lesson_material_link', "cp_delete_lesson", 'cp_create_link', 'cp_create_assignment', 'cp_edit_material', 'cp_view_material', 'cp_select_topic', 'cp_classwork_stream', 'cp_add_quiz', 'cp_manage_quiz', 'cp_edit_quiz', 'cp_delete_quiz', 'cp_add_objective_question', 'cp_add_theory_question', "cp_add_question", "cp_edit_question", "cp_delete_question", "lesson_notes"];
		$student = ['cp_view_lesson', 'cp_view_material', 'cp_select_topic', 'cp_classwork_stream', "cp_write_quiz", "cp_all_available_quiz", "lesson_notes"];
		$debtor = [];
		$se = [];
		
		update_role('software_engineer', array_unique(array_merge($super_admin, $admin, $teacher, $student, $bursar, $debtor, $se)));
		update_role('super_admin', $super_admin);
		update_role('admin', $admin);
		update_role('teacher', $teacher);
		update_role('student', $student);
		update_role('bursar', $bursar);
		update_role('debtor', $debtor);

		$menu = new menu;
		$menu->update_admin_menu_item('academic-operations', ['title' => 'Classroom Plus']);

		register_admin_page(array(
			'title' => 'Lessons Notes',
			'callback' => 'cp_lesson_notes_cb',
			'access' => 'lesson_notes',
			'permalink' => 'lesson-notes',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Lesson',
			'callback' => 'cp_view_lesson_cb',
			'access' => 'cp_view_lesson',
			'permalink' => 'cp-view-lesson',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Add Lesson',
			'callback' => 'cp_add_lesson_cb',
			'access' => 'cp_add_lesson',
			'permalink' => 'cp-add-lesson',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Add Quiz',
			'callback' => 'cp_add_quiz_cb',
			'access' => 'cp_add_quiz',
			'permalink' => 'cp-add-quiz',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Manage Quiz',
			'callback' => 'cp_manage_quiz_cb',
			'access' => 'cp_manage_quiz',
			'permalink' => 'cp-manage-quiz',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Add Objective Question',
			'callback' => 'cp_add_objective_question_cb',
			'access' => 'cp_add_objective_question',
			'permalink' => 'cp-add-objective-question',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Add Theory Question',
			'callback' => 'cp_add_theory_question_cb',
			'access' => 'cp_add_theory_question',
			'permalink' => 'cp-add-theory-question',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Edit Quiz',
			'callback' => 'cp_edit_quiz_cb',
			'access' => 'cp_edit_quiz',
			'permalink' => 'cp-edit-quiz',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Edit Lesson',
			'callback' => 'cp_edit_lesson_cb',
			'access' => 'cp_edit_lesson',
			'permalink' => 'cp-edit-lesson',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Attach Lesson Material',
			'callback' => 'cp_attach_lesson_material_cb',
			'access' => 'cp_attach_lesson_material',
			'permalink' => 'attach-lesson-material',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Attach Lesson Material Link',
			'callback' => 'cp_attach_lesson_material_link_cb',
			'access' => 'cp_attach_lesson_material_link',
			'permalink' => 'attach-lesson-material-link',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Create Link',
			'callback' => 'cp_create_link_cb',
			'access' => 'cp_create_link',
			'permalink' => 'cp-create-link',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Create Assignment',
			'callback' => 'cp_create_assignment_cb',
			'access' => 'cp_create_assignment',
			'permalink' => 'cp-create-assignment',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Attach Lesson Material',
			'callback' => 'cp_attach_lesson_material_cb',
			'access' => 'cp_attach_lesson_material',
			'permalink' => 'attach-lesson-material',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Edit Material',
			'callback' => 'cp_edit_material_cb',
			'access' => 'cp_edit_material',
			'permalink' => 'cp-edit-material',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'View Material',
			'callback' => 'cp_view_material_cb',
			'access' => 'cp_view_material',
			'permalink' => 'cp-view-material',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Select Topic',
			'callback' => 'cp_select_topic_cb',
			'access' => 'cp_select_topic',
			'permalink' => 'cp-select-topic',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Classwork Stream',
			'callback' => 'cp_classwork_stream_cb',
			'access' => 'cp_classwork_stream',
			'permalink' => 'cp-classwork-stream',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Write Quiz',
			'callback' => 'cp_write_quiz_cb',
			'access' => 'cp_write_quiz',
			'permalink' => 'cp-write-quiz',
			'template' => 'classroom plus'
		));

		register_admin_page(array(
			'title' => 'Online Quiz/Test',
			'callback' => 'cp_all_available_quiz_cb',
			'access' => 'cp_all_available_quiz',
			'permalink' => 'cp-all-available-quiz',
			'template' => 'classroom plus'
		));

		add_filter("more_templates", "classroom_plus_template");
		add_filter("template_classroom plus", "classroom_plus_template_link");
		add_action("cp_course_outline_filter", "cp_course_outline_filter");
		add_action("cp-view-lesson_header", "cp_view_lesson_header");
		add_action("attach-lesson-material_header", "attach_lesson_material_header");
		add_action("cp_get_lessons", "cp_get_lessons");
		add_action("cp_get_available_quiz", "cp_get_available_quiz");
		add_action('dashboard_additional_top_panels', "cp_dashboard_additional_top_panels");
		add_action("cp_play_quiz", "cp_play_quiz");

		add_filter("cp-view-material_header", "cp_view_material_header");
		add_filter("cp-view-lesson_header", "cp_lesson_header");
		add_filter("cp-select-topic_header", "cp_select_topic_header");
		add_action('load_other_dependencies', 'cp_load_dependencies');
		add_action("after_comment_cp_view_material", "cp_after_contribution_notice");
		add_action("after_comment_cp_view_lesson", "cp_after_lesson_contribution_notice");

		if(class_exists("cp_streams")) {
			$streams = new cp_streams();
			$streams->init();
		}

		// register_admin_menu(array(
		// 	'id' => 'store_config',
		// 	'title' => 'Store Config',
		// 	'icon' => 'fas fa-cog',
		// 	'page' => '',
		// 	'access' => 'store_config',
		// 	'order' => 2
		// ));
		register_admin_submenu(array(
			'mm_id' => 'academic-operations',
			'id' => 'cp_lesson_notes',
			'title' => 'Lesson Notes',
			'icon' => '',
			'page' => 'lesson-notes',
			'access' => 'lesson_notes'
		));

		register_admin_submenu(array(
			'mm_id' => 'academic-operations',
			'id' => 'cp_classwork_stream',
			'title' => 'Stream',
			'icon' => '',
			'page' => 'cp-classwork-stream',
			'access' => 'cp_classwork_stream'
		));

		register_admin_submenu(array(
			'mm_id' => 'academic-operations',
			'id' => 'cp_all_available_quiz',
			'title' => 'Online Quiz/Test',
			'icon' => '',
			'page' => 'cp-all-available-quiz',
			'access' => 'cp_all_available_quiz'
		));

	}

	public static function uninstall() {
		// unregister_admin_page([
			
		// ]);

		// unregister_admin_menu([
			
		// ]);
	}

}