$urlparams = array();
$blockpage->setup($urlparams);
$companyid = iomad::get_my_companyid($context);
$mform = new course_department_title_form(null, $companyid);
$courseform = new show_courses_selector_form(null, $companyid, 0, 0);
$blockpage->display_header();
$mform->set_data(array('department' => $department, 'title' => $title));
$mform->display();
if ($data = $mform->get_data()) {
    $courseform = new show_courses_selector_form(null, $companyid, $data->department, $data->title);
    $courseform->display();
}
if ($data = $courseform->get_data()) {
    switch (strtolower($data->action)) {
        case 'add':
            // Add courses for department & title
            assign_courses_to_department_title($companyid, $companycourses, $department, $title);
            $courseform = new show_courses_selector_form(null, $companyid, $department, $title);
            $courseform->display();
            break;
        case 'remove':
            // Remove courses for department & title
            remove_courses_from_department_title($companyid, $selectedcourses, $department, $title);
            $courseform = new show_courses_selector_form(null, $companyid, $department, $title);
            $courseform->display();
            break;
        default:
            break;
    }
}
echo $OUTPUT->footer();
}
/*GWL : Add condition to provide access for Site admin*/
$PAGE->set_url(new moodle_url('/local/manage_company_dept_title/addcoursetodepttitle.php'));
$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->navbar->add(get_string('assigncourse', 'local_manage_company_dept_title'));
require_login();
//$PAGE->set_pagetype('my-index');
echo $OUTPUT->header();
$courseid = required_param('course', PARAM_INT);
require_capability('local/manage_company_dept_title:manage_courses', $context);
if (has_capability('block/iomad_company_admin:manageallcompanycourses', $context) && $company) {
    $companyid = $company;
} else {
    $companyid = iomad::get_my_companyid($context);
}
$mform = new add_course_to_department_title_form(null, $companyid, $courseid);
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/blocks/iomad_company_admin/companycourses.php'));
    echo $OUTPUT->box_start('generalbox', 'notice');
    echo html_writer::tag('p', get_string('purgecachesconfirm', 'admin'));
    echo $OUTPUT->single_button($actionurl, get_string('purgecaches', 'admin'), 'post');
    echo $OUTPUT->box_end();
} else {
    if ($data = $mform->get_data()) {
        assign_courses_to_department_title($companyid, array($courseid), $data->department, $data->title);
        redirect(new moodle_url('/blocks/iomad_company_admin/companycourses.php'), get_string('assigncoursesuccessfully', 'local_manage_company_dept_title'), 2);
    }
}
$mform->display();
echo $OUTPUT->footer();