. /** * Cohort related management functions, this file needs to be included manually. * * @package core_cohort * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require('../config.php'); require($CFG->dirroot.'/course/lib.php'); require($CFG->dirroot.'/cohort/lib.php'); require($CFG->dirroot.'/cohort/edit_form.php'); $id = optional_param('id', 0, PARAM_INT); $contextid = optional_param('contextid', 0, PARAM_INT); $delete = optional_param('delete', 0, PARAM_BOOL); $show = optional_param('show', 0, PARAM_BOOL); $hide = optional_param('hide', 0, PARAM_BOOL); $confirm = optional_param('confirm', 0, PARAM_BOOL); $returnurl = optional_param('returnurl', '', PARAM_LOCALURL); require_login(); $category = null; if ($id) { $cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST); $context = context::instance_by_id($cohort->contextid, MUST_EXIST); } else { $context = context::instance_by_id($contextid, MUST_EXIST); if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) { print_error('invalidcontext'); } $cohort = new stdClass(); $cohort->id = 0; $cohort->contextid = $context->id; $cohort->name = ''; $cohort->description = ''; } require_capability('moodle/cohort:manage', $context); if ($returnurl) { $returnurl = new moodle_url($returnurl); } else { $returnurl = new moodle_url('/cohort/index.php', array('contextid'=>$context->id)); } if (!empty($cohort->component)) { // We can not manually edit cohorts that were created by external systems, sorry. redirect($returnurl); } $PAGE->set_context($context); $baseurl = new moodle_url('/cohort/edit.php', array('contextid' => $context->id, 'id' => $cohort->id)); $PAGE->set_url($baseurl); $PAGE->set_context($context); $PAGE->set_pagelayout('admin'); if ($context->contextlevel == CONTEXT_COURSECAT) { $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST); navigation_node::override_active_url(new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid))); } else { navigation_node::override_active_url(new moodle_url('/cohort/index.php', array())); } if ($delete and $cohort->id) { $PAGE->url->param('delete', 1); if ($confirm and confirm_sesskey()) { cohort_delete_cohort($cohort); redirect($returnurl); } $strheading = get_string('delcohort', 'cohort'); $PAGE->navbar->add($strheading); $PAGE->set_title($strheading); $PAGE->set_heading($COURSE->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading($strheading); $yesurl = new moodle_url('/cohort/edit.php', array('id' => $cohort->id, 'delete' => 1, 'confirm' => 1, 'sesskey' => sesskey(), 'returnurl' => $returnurl->out_as_local_url())); $message = get_string('delconfirm', 'cohort', format_string($cohort->name)); echo $OUTPUT->confirm($message, $yesurl, $returnurl); echo $OUTPUT->footer(); die; } if ($show && $cohort->id && confirm_sesskey()) { if (!$cohort->visible) { $record = (object)array('id' => $cohort->id, 'visible' => 1, 'contextid' => $cohort->contextid); cohort_update_cohort($record); } redirect($returnurl); } if ($hide && $cohort->id && confirm_sesskey()) { if ($cohort->visible) { $record = (object)array('id' => $cohort->id, 'visible' => 0, 'contextid' => $cohort->contextid); cohort_update_cohort($record); } redirect($returnurl); } $editoroptions = array('maxfiles'=>0, 'context'=>$context); if ($cohort->id) { // Edit existing. $cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context); $strheading = get_string('editcohort', 'cohort'); } else { // Add new. $cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context); $strheading = get_string('addcohort', 'cohort'); } $PAGE->set_title($strheading); $PAGE->set_heading($COURSE->fullname); $PAGE->navbar->add($strheading); $editform = new cohort_edit_form(null, array('editoroptions'=>$editoroptions, 'data'=>$cohort, 'returnurl'=>$returnurl)); if ($editform->is_cancelled()) { redirect($returnurl); } else if ($data = $editform->get_data()) { $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $context); if ($data->id) { cohort_update_cohort($data); } else { cohort_add_cohort($data); } if ($returnurl->get_param('showall') || $returnurl->get_param('contextid') == $data->contextid) { // Redirect to where we were before. redirect($returnurl); } else { // Use new context id, it has been changed. redirect(new moodle_url('/cohort/index.php', array('contextid' => $data->contextid))); } } echo $OUTPUT->header(); echo $OUTPUT->heading($strheading); if (!$id && ($editcontrols = cohort_edit_controls($context, $baseurl))) { echo $OUTPUT->render($editcontrols); } echo $editform->display(); echo $OUTPUT->footer();