. /** * @package core * @subpackage grading * @copyright 2011 David Mudrak * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); require_once($CFG->dirroot.'/grade/grading/lib.php'); // identify gradable area by its id $areaid = optional_param('areaid', null, PARAM_INT); // alternatively the context, component and areaname must be provided $contextid = optional_param('contextid', null, PARAM_INT); $component = optional_param('component', null, PARAM_COMPONENT); $area = optional_param('area', null, PARAM_AREA); // keep the caller's URL so that we know where to send the user finally $returnurl = optional_param('returnurl', null, PARAM_LOCALURL); // active method selector $setmethod = optional_param('setmethod', null, PARAM_PLUGIN); // publish the given form definition as a new template in the forms bank $shareform = optional_param('shareform', null, PARAM_INT); // consider the required action as confirmed $confirmed = optional_param('confirmed', false, PARAM_BOOL); // a message to display, typically a previous action's result $message = optional_param('message', null, PARAM_NOTAGS); if (!is_null($areaid)) { // get manager by id $manager = get_grading_manager($areaid); } else { // get manager by context and component if (is_null($contextid) or is_null($component) or is_null($area)) { throw new coding_exception('The caller script must identify the gradable area.'); } $context = get_context_instance_by_id($contextid, MUST_EXIST); $manager = get_grading_manager($context, $component, $area); } // currently active method $method = $manager->get_active_method(); if ($manager->get_context()->contextlevel == CONTEXT_SYSTEM) { // this is a shared area in the forms bank, redirect the user $params = array('areaid' =>$areaid); if (!is_null($returnurl)) { $params['returnurl'] = $returnurl; } redirect(new moodle_url('/grade/grading/bank.php', $params)); } else if ($manager->get_context()->contextlevel >= CONTEXT_COURSE) { list($context, $course, $cm) = get_context_info_array($manager->get_context()->id); if (is_null($returnurl)) { $returnurl = new moodle_url('/course/view.php', array('id' => $course->id)); } else { $returnurl = new moodle_url($returnurl); } require_login($course, true, $cm); require_capability('moodle/grade:managegradingforms', $context); } else { throw new coding_exception('Unsupported gradable area context level'); } $PAGE->set_url($manager->get_management_url($returnurl)); navigation_node::override_active_url($manager->get_management_url()); $PAGE->set_title(get_string('gradingmanagement', 'core_grading')); $PAGE->set_heading(get_string('gradingmanagement', 'core_grading')); $output = $PAGE->get_renderer('core_grading'); // process the eventual change of the active grading method if (!empty($setmethod)) { require_sesskey(); if ($setmethod == 'none') { // here we expect that noone would actually want to call their plugin as 'none' $setmethod = null; } $manager->set_active_method($setmethod); redirect($PAGE->url); } // publish the form as a template if (!empty($shareform)) { require_capability('moodle/grade:sharegradingforms', get_system_context()); $controller = $manager->get_controller($method); $definition = $controller->get_definition(); if (!$confirmed) { // let the user confirm they understand what they are doing (haha ;-) echo $output->header(); echo $output->confirm(get_string('manageactionshareconfirm', 'core_grading', s($definition->name)), new moodle_url($PAGE->url, array('shareform' => $shareform, 'confirmed' => 1)), $PAGE->url); echo $output->footer(); die(); } else { require_sesskey(); $newareaid = $manager->create_shared_area($method); $targetarea = get_grading_manager($newareaid); $targetcontroller = $targetarea->get_controller($method); $targetcontroller->update_definition($controller->get_definition_copy($targetcontroller)); redirect(new moodle_url($PAGE->url, array('message' => get_string('manageactionsharedone', 'core_grading')))); } } echo $output->header(); if (!empty($message)) { echo $output->management_message($message); } echo $output->heading(get_string('gradingmanagementtitle', 'core_grading', array( 'component' => $manager->get_component_title(), 'area' => $manager->get_area_title()))); // display the active grading method information and selector echo $output->management_method_selector($manager, $PAGE->url); // get the currently active method's controller if (!empty($method)) { $controller = $manager->get_controller($method); // display relevant actions echo $output->container_start('actions'); if ($controller->is_form_defined()) { $definition = $controller->get_definition(); echo $output->management_action_icon($controller->get_editor_url($returnurl), get_string('manageactionedit', 'core_grading'), 'b/document-edit'); echo $output->management_action_icon($PAGE->url, get_string('manageactiondelete', 'core_grading'), 'b/edit-delete'); if (has_capability('moodle/grade:sharegradingforms', get_system_context())) { echo $output->management_action_icon(new moodle_url($PAGE->url, array('shareform' => $definition->id)), get_string('manageactionshare', 'core_grading'), 'b/bookmark-new'); } } else { echo $output->management_action_icon($controller->get_editor_url($returnurl), get_string('manageactionnew', 'core_grading'), 'b/document-new'); echo $output->management_action_icon($PAGE->url, get_string('manageactionclone', 'core_grading'), 'b/edit-copy'); } echo $output->container_end(); // display the grading form preview if ($controller->is_form_defined()) { echo $output->box($controller->render_preview($PAGE), 'preview'); } } echo $output->footer();