示例#1
0
    error("Site isn't defined!");
}
if ($categoryadd) {
    // Show Add category form: if $id is given, it is used as the parent category
    $strtitle = get_string("addnewcategory");
    $context = get_context_instance(CONTEXT_SYSTEM);
    $category = null;
} elseif (!is_null($id) && !$categoryadd) {
    // Show Edit category form: $id is given as the identifier of the category being edited
    $strtitle = get_string("editcategorysettings");
    $context = get_context_instance(CONTEXT_COURSECAT, $id);
    if (!($category = get_record("course_categories", "id", $id))) {
        error("Category not known!");
    }
}
$mform = new editcategory_form('editcategory.php', compact(array('category', 'id')));
if (!empty($category)) {
    $mform->set_data($category);
} elseif (!is_null($id)) {
    $data = new stdClass();
    $data->parent = $id;
    $data->categoryadd = 1;
    $mform->set_data($data);
}
if ($mform->is_cancelled()) {
    if (empty($category)) {
        redirect($CFG->wwwroot . '/course/index.php?categoryedit=on');
    } else {
        redirect($CFG->wwwroot . '/course/category.php?categoryedit=on&id=' . $category->id);
    }
} else {
        $context = get_system_context();
    }
    $PAGE->set_context($context);
    $category = new stdClass();
    $category->id = 0;
    $category->parent = $parent;
    require_capability('moodle/category:manage', $context);
    $strtitle = 'Agregar nueva materia';
    $editorcontext = null;
    $title = "{$SITE->shortname}: " . 'Agregar nueva materia';
    $fullname = $SITE->fullname;
}
$PAGE->set_pagelayout('admin');
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => true);
$category = file_prepare_standard_editor($category, 'description', $editoroptions, $editorcontext, 'coursecat', 'description', 0);
$mform = new editcategory_form('editcategory.php', compact('category', 'editoroptions'));
$mform->set_data($category);
if ($mform->is_cancelled()) {
    if ($id) {
        redirect($CFG->wwwroot . '/course/category.php?id=' . $id . '&categoryedit=on');
    } else {
        if ($parent) {
            redirect($CFG->wwwroot . '/course/category.php?id=' . $parent . '&categoryedit=on');
        } else {
            redirect($CFG->wwwroot . '/course/index.php?categoryedit=on');
        }
    }
} else {
    if ($data = $mform->get_data()) {
        $newcategory = new stdClass();
        $newcategory->name = $data->name;