mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
d4a03c00ea
The code to print blocks in now in theme layout.php files. (Or in moodle_core_renderer::handle_legacy_theme) Code for printing blocks everywhere else has been stripped out. (Total diffstat 1225 insertions, 2019 deletions) The way the HTML for a block instance is generated has been cleaned up a lot. Now, the block_instance generates a block_contents object which gives a structured representation of the block, and then $OUTPUT->block builds all the HTML from that. How theme config.php files specify the layout template and block regions by page general type has been changed to be even more flexible. Further refinement for how the theme and block code gets initialised. Ability for scrits to add 'pretend blocks' to the page. That is, things that look like blocks, but are not normal block_instances. (Like the add a new block UI.) Things that are still broken: * some pages in lesson, quiz and resource. I'm working on it. * lots of developer debug notices pointing out things that need to be updated.
152 lines
5.5 KiB
PHP
152 lines
5.5 KiB
PHP
<?php // $Id$
|
|
// Edit course settings
|
|
|
|
require_once('../config.php');
|
|
require_once($CFG->dirroot.'/enrol/enrol.class.php');
|
|
require_once('lib.php');
|
|
require_once('edit_form.php');
|
|
|
|
$id = optional_param('id', 0, PARAM_INT); // course id
|
|
$categoryid = optional_param('category', 0, PARAM_INT); // course category - can be changed in edit form
|
|
|
|
$PAGE->set_generaltype('form');
|
|
|
|
/// basic access control checks
|
|
if ($id) { // editing course
|
|
|
|
if($id == SITEID){
|
|
// don't allow editing of 'site course' using this from
|
|
print_error('cannoteditsiteform');
|
|
}
|
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
|
print_error('invalidcourseid');
|
|
}
|
|
require_login($course->id);
|
|
$category = $DB->get_record('course_categories', array('id'=>$course->category));
|
|
require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
|
|
|
|
} else if ($categoryid) { // creating new course in this category
|
|
$course = null;
|
|
require_login();
|
|
if (!$category = $DB->get_record('course_categories', array('id'=>$categoryid))) {
|
|
print_error('unknowcategory');
|
|
}
|
|
require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id));
|
|
} else {
|
|
require_login();
|
|
print_error('needcoursecategroyid');
|
|
}
|
|
|
|
/// prepare course
|
|
if (!empty($course)) {
|
|
$allowedmods = array();
|
|
if (!empty($course)) {
|
|
if ($am = $DB->get_records('course_allowed_modules', array('course'=>$course->id))) {
|
|
foreach ($am as $m) {
|
|
$allowedmods[] = $m->module;
|
|
}
|
|
} else {
|
|
if (empty($course->restrictmodules)) {
|
|
$allowedmods = explode(',',$CFG->defaultallowedmodules);
|
|
} // it'll be greyed out but we want these by default anyway.
|
|
}
|
|
$course->allowedmods = $allowedmods;
|
|
}
|
|
}
|
|
|
|
/// first create the form
|
|
$editform = new course_edit_form('edit.php', compact('course', 'category'));
|
|
// now override defaults if course already exists
|
|
if (!empty($course)) {
|
|
$course->enrolpassword = $course->password; // we need some other name for password field MDL-9929
|
|
$editform->set_data($course);
|
|
}
|
|
if ($editform->is_cancelled()){
|
|
if (empty($course)) {
|
|
redirect($CFG->wwwroot);
|
|
} else {
|
|
redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
|
|
}
|
|
|
|
} else if ($data = $editform->get_data()) {
|
|
|
|
$data->password = $data->enrolpassword; // we need some other name for password field MDL-9929
|
|
/// process data if submitted
|
|
|
|
//preprocess data
|
|
$data->timemodified = time();
|
|
|
|
if (empty($course)) {
|
|
if (!$course = create_course($data)) {
|
|
print_error('coursenotcreated');
|
|
}
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
// assign default role to creator if not already having permission to manage course assignments
|
|
if (!has_capability('moodle/course:view', $context) or !has_capability('moodle/role:assign', $context)) {
|
|
role_assign($CFG->creatornewroleid, $USER->id, 0, $context->id);
|
|
}
|
|
|
|
// ensure we can use the course right after creating it
|
|
// this means trigger a reload of accessinfo...
|
|
mark_context_dirty($context->path);
|
|
|
|
if ($data->metacourse and has_capability('moodle/course:managemetacourse', $context)) {
|
|
// Redirect users with metacourse capability to student import
|
|
redirect($CFG->wwwroot."/course/importstudents.php?id=$course->id");
|
|
} else {
|
|
// Redirect to roles assignment
|
|
redirect($CFG->wwwroot."/$CFG->admin/roles/assign.php?contextid=$context->id");
|
|
}
|
|
|
|
} else {
|
|
if (!update_course($data)) {
|
|
print_error('coursenotupdated');
|
|
}
|
|
redirect($CFG->wwwroot."/course/view.php?id=$course->id");
|
|
}
|
|
}
|
|
|
|
|
|
/// Print the form
|
|
|
|
$site = get_site();
|
|
|
|
$streditcoursesettings = get_string("editcoursesettings");
|
|
$straddnewcourse = get_string("addnewcourse");
|
|
$stradministration = get_string("administration");
|
|
$strcategories = get_string("categories");
|
|
$navlinks = array();
|
|
|
|
if (!empty($course)) {
|
|
$navlinks[] = array('name' => $streditcoursesettings,
|
|
'link' => null,
|
|
'type' => 'misc');
|
|
$title = $streditcoursesettings;
|
|
$fullname = $course->fullname;
|
|
} else {
|
|
$navlinks[] = array('name' => $stradministration,
|
|
'link' => "$CFG->wwwroot/$CFG->admin/index.php",
|
|
'type' => 'misc');
|
|
$navlinks[] = array('name' => $strcategories,
|
|
'link' => 'index.php',
|
|
'type' => 'misc');
|
|
$navlinks[] = array('name' => $straddnewcourse,
|
|
'link' => null,
|
|
'type' => 'misc');
|
|
$title = "$site->shortname: $straddnewcourse";
|
|
$fullname = $site->fullname;
|
|
}
|
|
|
|
$navigation = build_navigation($navlinks);
|
|
print_header($title, $fullname, $navigation, $editform->focus());
|
|
print_heading($streditcoursesettings);
|
|
|
|
$editform->display();
|
|
|
|
print_footer($course);
|
|
|
|
?>
|