mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
refactored course/edit2.php and edit_form MDL-6914 ; set $CFG->use_new_forms=1; in config.php if you want to test it ;-)
This commit is contained in:
parent
e561e6fe6c
commit
a81bf9c3ce
3 changed files with 538 additions and 504 deletions
|
@ -9,6 +9,11 @@
|
||||||
$id = optional_param('id', 0, PARAM_INT); // course id
|
$id = optional_param('id', 0, PARAM_INT); // course id
|
||||||
$category = optional_param('category', 0, PARAM_INT); // possible default category
|
$category = optional_param('category', 0, PARAM_INT); // possible default category
|
||||||
|
|
||||||
|
// redirect to new form if testing as developer
|
||||||
|
if (!empty($CFG->use_new_forms)) {
|
||||||
|
redirect('edit2.php?id='.$id.'&category='.$category);
|
||||||
|
}
|
||||||
|
|
||||||
require_login();
|
require_login();
|
||||||
|
|
||||||
$disable_meta = false;
|
$disable_meta = false;
|
||||||
|
|
321
course/edit2.php
321
course/edit2.php
|
@ -1,181 +1,93 @@
|
||||||
<?php // $Id$
|
<?php // $Id$
|
||||||
// Edit course settings
|
// Edit course settings
|
||||||
|
|
||||||
require_once("../config.php");
|
require_once('../config.php');
|
||||||
require_once("lib.php");
|
require_once($CFG->dirroot.'/enrol/enrol.class.php');
|
||||||
require_once("$CFG->libdir/blocklib.php");
|
require_once($CFG->libdir.'/blocklib.php');
|
||||||
require_once("$CFG->dirroot/enrol/enrol.class.php");
|
require_once($CFG->libdir.'/formslib.php');
|
||||||
|
require_once('lib.php');
|
||||||
|
require_once('edit_form.php');
|
||||||
|
|
||||||
include_once $CFG->libdir.'/formslib.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
|
||||||
print_header();
|
|
||||||
notice('This file is disabled due to recent changes in formslib.php, edit3.php will be here soon ;-).');
|
|
||||||
die;
|
|
||||||
|
|
||||||
require_login();
|
require_login();
|
||||||
|
|
||||||
$mform =& new moodleform('edit_course', 'post', 'edit2.php');
|
/// basic access control checks
|
||||||
|
if ($id) { // editing course
|
||||||
$mform->acceptGet('id', 'category');
|
if (!$course = get_record('course', 'id', $id)) {
|
||||||
|
error('Course ID was incorrect');
|
||||||
$id = $mform->optional_param('id', 0, PARAM_INT); // course id
|
|
||||||
$category = $mform->optional_param('category', 0, PARAM_INT); // possible default category
|
|
||||||
|
|
||||||
|
|
||||||
$disable_meta = false;
|
|
||||||
$focus = "";
|
|
||||||
|
|
||||||
if ($id) {
|
|
||||||
if (! $course = get_record("course", "id", $id)) {
|
|
||||||
error("Course ID was incorrect");
|
|
||||||
}
|
}
|
||||||
|
$category = get_record('course_categories', 'id', $course->category);
|
||||||
|
require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
|
||||||
|
|
||||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
} else if ($categoryid) { // creating new course in this category
|
||||||
|
$course = null;
|
||||||
if (!has_capability('moodle/course:update', $context)) {
|
if (!$category = get_record('course_categories', 'id', $categoryid)) {
|
||||||
error("You do not currently have editing privileges!");
|
error('Category ID was incorrect');
|
||||||
}
|
}
|
||||||
|
require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id));
|
||||||
|
|
||||||
if (course_in_meta($course)) {
|
} else {
|
||||||
$disable_meta = get_string('metaalreadyinmeta');
|
error('Either course id or category must be specified');
|
||||||
} else if ($course->metacourse) {
|
}
|
||||||
if (count_records("course_meta","parent_course",$course->id) > 0) {
|
|
||||||
$disable_meta = get_string('metaalreadyhascourses');
|
/// prepare course
|
||||||
|
if (!empty($course)) {
|
||||||
|
$allowedmods = array();
|
||||||
|
if (!empty($course)) {
|
||||||
|
if ($am = get_records('course_allowed_modules','course',$course->id)) {
|
||||||
|
foreach ($am as $m) {
|
||||||
|
$allowedmods[] = $m->module;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$managers = count(get_users_by_capability($context, 'moodle/course:managemetacourse'));
|
if (empty($course->restrictmodules)) {
|
||||||
$participants = count(get_users_by_capability($context, 'moodle/course:view'));
|
$allowedmods = explode(',',$CFG->defaultallowedmodules);
|
||||||
if ($participants > $managers) {
|
} // it'll be greyed out but we want these by default anyway.
|
||||||
$disable_meta = get_string('metaalreadyhasenrolments');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else { // Admin is creating a new course
|
$course->allowedmods = $allowedmods;
|
||||||
|
|
||||||
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
if ($course->enrolstartdate){
|
||||||
if (!has_capability('moodle/course:create',$context)) {
|
$course->enrolstartdisabled = 0;
|
||||||
error("You do not currently have course creation privileges!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$course = NULL;
|
if ($course->enrolenddate) {
|
||||||
|
$course->enrolenddisabled = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $site = get_site()) {
|
}
|
||||||
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
/// first create the form
|
||||||
include("edit_form.php");
|
$editform = new course_edit_form('edit2.php', compact('course', 'category'));
|
||||||
|
|
||||||
|
|
||||||
|
/// process data if submitted
|
||||||
|
if ($data = $editform->data_submitted()) {
|
||||||
|
|
||||||
/// If data submitted, then process and store.
|
//preprocess data
|
||||||
// data_submitted tries to validate form data and returns false if
|
if ($data->enrolstartdisabled){
|
||||||
// the user inputted data is invalid and the form should be redisplayed with
|
$data->enrolstartdate = 0;
|
||||||
// feedback.
|
|
||||||
|
|
||||||
if ($fromform=$mform->data_submitted()) {
|
|
||||||
|
|
||||||
|
|
||||||
if (!empty($fromform->enrolstartdisabled)){
|
|
||||||
$fromform->enrolstartdate = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($fromform->enrolenddisabled)) {
|
if ($data->enrolenddisabled) {
|
||||||
$fromform->enrolenddate = 0;
|
$data->enrolenddate = 0;
|
||||||
}
|
|
||||||
$allowedmods = array();
|
|
||||||
if (!empty($fromform->allowedmods)) {
|
|
||||||
$allowedmods = $fromform->allowedmods;
|
|
||||||
unset($fromform->allowedmods);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$fromform->timemodified = time();
|
$data->timemodified = time();
|
||||||
|
|
||||||
if ($fromform->defaultrole == -1) { // Just leave it however it is
|
if (empty($course)) {
|
||||||
unset($fromform->defaultrole);
|
create_course($data);
|
||||||
}
|
|
||||||
if (!empty($course)) {
|
|
||||||
// Test for and remove blocks which aren't appropriate anymore
|
|
||||||
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
|
|
||||||
blocks_remove_inappropriate($page);
|
|
||||||
|
|
||||||
// Update with the new data
|
|
||||||
if (update_record('course', $fromform)) {
|
|
||||||
add_to_log($course->id, "course", "update", "edit.php?id=$id", "");
|
|
||||||
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
|
||||||
$course->restrictmodules = $fromform->restrictmodules;
|
|
||||||
update_restricted_mods($course,$allowedmods);
|
|
||||||
}
|
|
||||||
fix_course_sortorder();
|
|
||||||
// everything ok, no need to display any message in redirect
|
|
||||||
redirect("view.php?id=$course->id");
|
|
||||||
} else {
|
|
||||||
error("Serious Error! Could not update the course record! (id = $fromform->id)");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$fromform->timecreated = time();
|
update_course($data);
|
||||||
|
|
||||||
// place at beginning of category
|
|
||||||
fix_course_sortorder();
|
|
||||||
$fromform->sortorder = get_field_sql("SELECT min(sortorder)-1 FROM {$CFG->prefix}course WHERE category=$fromform->category");
|
|
||||||
if (empty($fromform->sortorder)) {
|
|
||||||
$fromform->sortorder = 100;
|
|
||||||
}
|
|
||||||
// fill in default teacher and student names to keep backwards compatibility
|
|
||||||
$fromform->teacher = addslashes(get_string('defaultcourseteacher'));
|
|
||||||
$fromform->teachers = addslashes(get_string('defaultcourseteachers'));
|
|
||||||
$fromform->student = addslashes(get_string('defaultcoursestudent'));
|
|
||||||
$fromform->students = addslashes(get_string('defaultcoursestudents'));
|
|
||||||
|
|
||||||
if ($newcourseid = insert_record('course', $fromform)) { // Set up new course
|
|
||||||
|
|
||||||
// Setup the blocks
|
|
||||||
$page = page_create_object(PAGE_COURSE_VIEW, $newcourseid);
|
|
||||||
blocks_repopulate_page($page); // Return value not checked because you can always edit later
|
|
||||||
|
|
||||||
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
|
||||||
$course = get_record("course","id",$newcourseid);
|
|
||||||
update_restricted_mods($course,$allowedmods);
|
|
||||||
}
|
|
||||||
|
|
||||||
$section = NULL;
|
|
||||||
$section->course = $newcourseid; // Create a default section.
|
|
||||||
$section->section = 0;
|
|
||||||
$section->id = insert_record("course_sections", $section);
|
|
||||||
|
|
||||||
fix_course_sortorder();
|
|
||||||
add_to_log(SITEID, "course", "new", "view.php?id=$newcourseid", "$fromform->fullname (ID $newcourseid)") ;
|
|
||||||
$context = get_context_instance(CONTEXT_COURSE, $newcourseid);
|
|
||||||
|
|
||||||
if ($fromform->metacourse and has_capability('moodle/course:managemetacourse', $context)) { // Redirect users with metacourse capability to student import
|
|
||||||
redirect($CFG->wwwroot."/course/importstudents.php?id=$newcourseid");
|
|
||||||
|
|
||||||
} else if (has_capability('moodle/role:assign', $context)) { // Redirect users with assign capability to assign users to different roles
|
|
||||||
redirect($CFG->wwwroot."/$CFG->admin/roles/assign.php?contextid=$context->id");
|
|
||||||
|
|
||||||
} else { // Add current teacher and send to course
|
|
||||||
|
|
||||||
// find a role with legacy:edittingteacher
|
|
||||||
if ($teacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, $context)) {
|
|
||||||
// assign the role to this user
|
|
||||||
$teachereditrole = array_shift($teacherroles);
|
|
||||||
role_assign($teachereditrole->id, $USER->id, 0, $context->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect("view.php?id=$newcourseid");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
error("Serious Error! Could not create the new course!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
die;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//print the form
|
///print the form
|
||||||
|
|
||||||
|
$site = get_site();
|
||||||
|
|
||||||
$streditcoursesettings = get_string("editcoursesettings");
|
$streditcoursesettings = get_string("editcoursesettings");
|
||||||
$straddnewcourse = get_string("addnewcourse");
|
$straddnewcourse = get_string("addnewcourse");
|
||||||
|
@ -185,18 +97,127 @@
|
||||||
if (!empty($course)) {
|
if (!empty($course)) {
|
||||||
print_header($streditcoursesettings, "$course->fullname",
|
print_header($streditcoursesettings, "$course->fullname",
|
||||||
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
|
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
|
||||||
-> $streditcoursesettings", $focus);
|
-> $streditcoursesettings");
|
||||||
} else {
|
} else {
|
||||||
print_header("$site->shortname: $straddnewcourse", "$site->fullname",
|
print_header("$site->shortname: $straddnewcourse", "$site->fullname",
|
||||||
"<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
|
"<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
|
||||||
"<a href=\"index.php\">$strcategories</a> -> $straddnewcourse", $focus);
|
"<a href=\"index.php\">$strcategories</a> -> $straddnewcourse");
|
||||||
|
}
|
||||||
|
|
||||||
|
print_heading($streditcoursesettings);
|
||||||
|
$editform->display();
|
||||||
|
print_footer($course);
|
||||||
|
|
||||||
|
die;
|
||||||
|
|
||||||
|
|
||||||
|
/// internal functions
|
||||||
|
|
||||||
|
function create_course($data) {
|
||||||
|
global $CFG, $USER;
|
||||||
|
|
||||||
|
// preprocess allowed mods
|
||||||
|
$allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
|
||||||
|
unset($data->allowedmods);
|
||||||
|
if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
|
if ($CFG->restrictmodulesfor == 'all') {
|
||||||
|
$data->restrictmodules = 1;
|
||||||
|
} else {
|
||||||
|
$data->restrictmodules = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
print_heading($streditcoursesettings);
|
$data->timecreated = time();
|
||||||
|
|
||||||
$mform->display();
|
// place at beginning of category
|
||||||
|
fix_course_sortorder();
|
||||||
|
$data->sortorder = get_field_sql("SELECT min(sortorder)-1 FROM {$CFG->prefix}course WHERE category=$data->category");
|
||||||
|
if (empty($data->sortorder)) {
|
||||||
|
$data->sortorder = 100;
|
||||||
|
}
|
||||||
|
|
||||||
print_footer($course);
|
if ($newcourseid = insert_record('course', $data)) { // Set up new course
|
||||||
|
|
||||||
|
$course = get_record('course', 'id', $newcourseid);
|
||||||
|
|
||||||
|
// Setup the blocks
|
||||||
|
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
|
||||||
|
blocks_repopulate_page($page); // Return value not checked because you can always edit later
|
||||||
|
|
||||||
|
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
|
update_restricted_mods($course, $allowedmods);
|
||||||
|
}
|
||||||
|
|
||||||
|
$section = new object();
|
||||||
|
$section->course = $course->id; // Create a default section.
|
||||||
|
$section->section = 0;
|
||||||
|
$section->id = insert_record('course_sections', $section);
|
||||||
|
|
||||||
|
fix_course_sortorder();
|
||||||
|
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$data->fullname (ID $course->id)") ;
|
||||||
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||||
|
|
||||||
|
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 if (has_capability('moodle/role:assign', $context)) { // Redirect users with assign capability to assign users to different roles
|
||||||
|
redirect($CFG->wwwroot."/$CFG->admin/roles/assign.php?contextid=$context->id");
|
||||||
|
|
||||||
|
} else { // Add current teacher and send to course
|
||||||
|
// find a role with legacy:edittingteacher
|
||||||
|
if ($teacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, $context)) {
|
||||||
|
// assign the role to this user
|
||||||
|
$teachereditrole = array_shift($teacherroles);
|
||||||
|
role_assign($teachereditrole->id, $USER->id, 0, $context->id);
|
||||||
|
}
|
||||||
|
redirect($CFG->wwwroot."/course/view.php?id=$course->id");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
error("Serious Error! Could not create the new course!");
|
||||||
|
}
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_course($data) {
|
||||||
|
global $USER, $CFG;
|
||||||
|
|
||||||
|
// preprocess allowed mods
|
||||||
|
$allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
|
||||||
|
unset($data->allowedmods);
|
||||||
|
if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
|
unset($data->restrictmodules);
|
||||||
|
}
|
||||||
|
|
||||||
|
$oldcourse = get_record('course', 'id', $data->id); // should not fail, already tested above
|
||||||
|
if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category))
|
||||||
|
or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
|
||||||
|
// can not move to new category, keep the old one
|
||||||
|
unset($data->category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update with the new data
|
||||||
|
if (update_record('course', $data)) {
|
||||||
|
|
||||||
|
$course = get_record('course', 'id', $data->id);
|
||||||
|
|
||||||
|
add_to_log($course->id, "course", "update", "edit.php?id=$course->id", "");
|
||||||
|
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
||||||
|
update_restricted_mods($course, $allowedmods);
|
||||||
|
}
|
||||||
|
fix_course_sortorder();
|
||||||
|
|
||||||
|
// Test for and remove blocks which aren't appropriate anymore
|
||||||
|
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
|
||||||
|
blocks_remove_inappropriate($page);
|
||||||
|
|
||||||
|
redirect($CFG->wwwroot."/course/view.php?id=$course->id");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
error("Serious Error! Could not update the course record! (id = $form->id)");
|
||||||
|
}
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,392 +1,400 @@
|
||||||
<?php
|
<?php //$Id$
|
||||||
/// For moodleform we reconstruct all the data about the form after submission before we
|
|
||||||
/// extract data submitted. So we can then tell for select, checkbox and radio fields what
|
|
||||||
/// options could have been submitted by the form eg submitted value for a single selection
|
|
||||||
/// select field must be one of the options of the select field.
|
|
||||||
|
|
||||||
// $toform will be used for the default value of a field if no data has been submitted.
|
class course_edit_form extends moodleform {
|
||||||
|
|
||||||
if (!empty($course)) {
|
function definition() {
|
||||||
//this is what we do if we are editing a record from the db
|
global $USER, $CFG;
|
||||||
$toform = $course;
|
|
||||||
$toform->allowedmods = array();
|
$mform =& $this->_form;
|
||||||
if ($am = get_records("course_allowed_modules","course",$course->id)) {
|
$renderer =& $mform->defaultRenderer();
|
||||||
foreach ($am as $m) {
|
|
||||||
$toform->allowedmods[] = $m->module;
|
$course = $this->_customdata['course'];
|
||||||
|
$category = $this->_customdata['category'];
|
||||||
|
|
||||||
|
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||||
|
$categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
|
||||||
|
|
||||||
|
$disable_meta = false; // basic meta course state protection; server-side security checks not needed
|
||||||
|
|
||||||
|
if (!empty($course)) {
|
||||||
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||||
|
$context = $coursecontext;
|
||||||
|
|
||||||
|
if (course_in_meta($course)) {
|
||||||
|
$disable_meta = get_string('metaalreadyinmeta');
|
||||||
|
|
||||||
|
} else if ($course->metacourse) {
|
||||||
|
if (count_records('course_meta', 'parent_course', $coursecourse->id) > 0) {
|
||||||
|
$disable_meta = get_string('metaalreadyhascourses');
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$managers = count(get_users_by_capability($coursecontext, 'moodle/course:managemetacourse'));
|
||||||
|
$participants = count(get_users_by_capability($coursecontext, 'moodle/course:view'));
|
||||||
|
if ($participants > $managers) {
|
||||||
|
$disable_meta = get_string('metaalreadyhasenrolments');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (empty($course->restrictmodules)) {
|
$coursecontext = null;
|
||||||
$toform->allowedmods = explode(',',$CFG->defaultallowedmodules);
|
$context = $categorycontext;
|
||||||
} // it'll be greyed out but we want these by default anyway.
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//this is a brand new course!
|
/// form definition with new course defaults
|
||||||
$toform->startdate = time() + 3600 * 24;
|
//--------------------------------------------------------------------------------
|
||||||
$toform->fullname = get_string("defaultcoursefullname");
|
$mform->addElement('header','general', get_string('general'));
|
||||||
$toform->shortname = get_string("defaultcourseshortname");
|
|
||||||
$toform->summary = get_string("defaultcoursesummary");
|
//must have create course capability in both categories in order to move course
|
||||||
$toform->format = "weeks";
|
if (has_capability('moodle/course:create', $categorycontext)) {
|
||||||
$toform->password = "";
|
$displaylist = array();
|
||||||
$toform->guest = 0;
|
$parentlist = array();
|
||||||
$toform->numsections = 10;
|
make_categories_list($displaylist, $parentlist);
|
||||||
$toform->idnumber = '';
|
foreach ($displaylist as $key=>$val) {
|
||||||
$toform->cost = '';
|
if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $key))) {
|
||||||
$toform->currency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
|
unset($displaylist[$key]);
|
||||||
$toform->newsitems = 5;
|
}
|
||||||
$toform->showgrades = 1;
|
|
||||||
$toform->groupmode = 0;
|
|
||||||
$toform->groupmodeforce = 0;
|
|
||||||
$toform->category = $category;
|
|
||||||
$toform->id = "";
|
|
||||||
$toform->visible = 1;
|
|
||||||
$toform->allowedmods = array();
|
|
||||||
if ($CFG->restrictmodulesfor == 'all') {
|
|
||||||
$toform->allowedmods = explode(',',$CFG->defaultallowedmodules);
|
|
||||||
if (!empty($CFG->restrictbydefault)) {
|
|
||||||
$toform->restrictmodules = 1;
|
|
||||||
}
|
}
|
||||||
|
$mform->addElement('select', 'category', get_string('category'), $displaylist);
|
||||||
|
} else {
|
||||||
|
$mform->addElement('hidden', 'category', null);
|
||||||
|
}
|
||||||
|
$mform->setHelpButton('category', array('coursecategory', get_string('category')));
|
||||||
|
$mform->setDefault('category', $category->id);
|
||||||
|
$mform->setType('category', PARAM_INT);
|
||||||
|
|
||||||
|
$mform->addElement('text','fullname', get_string('fullname'),'maxlength="254" size="50"');
|
||||||
|
$mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true);
|
||||||
|
$mform->setDefault('fullname', get_string('defaultcoursefullname'));
|
||||||
|
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
|
||||||
|
$mform->setType('fullname', PARAM_MULTILANG);
|
||||||
|
|
||||||
|
$mform->addElement('text','shortname', get_string('shortname'),'maxlength="15" size="10"');
|
||||||
|
$mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), true);
|
||||||
|
$mform->setDefault('shortname', get_string('defaultcourseshortname'));
|
||||||
|
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
|
||||||
|
$mform->setType('shortname', PARAM_MULTILANG);
|
||||||
|
|
||||||
|
$mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"');
|
||||||
|
$mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
|
||||||
|
$mform->setType('idnumber', PARAM_RAW);
|
||||||
|
|
||||||
|
$mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));
|
||||||
|
$mform->setHelpButton('summary', array('text', get_string('helptext')), true);
|
||||||
|
$mform->setDefault('summary', get_string('defaultcoursesummary'));
|
||||||
|
$mform->addRule('summary', get_string('missingsummary'), 'required', null, 'client');
|
||||||
|
$mform->setType('summary', PARAM_RAW);
|
||||||
|
|
||||||
|
$courseformats = get_list_of_plugins('course/format');
|
||||||
|
$formcourseformats = array();
|
||||||
|
foreach ($courseformats as $courseformat) {
|
||||||
|
$formcourseformats["$courseformat"] = get_string("format$courseformat");
|
||||||
|
}
|
||||||
|
$mform->addElement('select', 'format', get_string('format'), $formcourseformats);
|
||||||
|
$mform->setHelpButton('format', array('courseformats', get_string('courseformats')), true);
|
||||||
|
$mform->setDefault('format', 'weeks');
|
||||||
|
|
||||||
|
for ($i=1; $i<=52; $i++) {
|
||||||
|
$sectionmenu[$i] = "$i";
|
||||||
|
}
|
||||||
|
$mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
|
||||||
|
$mform->setDefault('numsections', 10);
|
||||||
|
|
||||||
|
$mform->addElement('date_selector', 'startdate', get_string('startdate'));
|
||||||
|
$mform->setHelpButton('startdate', array('coursestartdate', get_string('startdate')), true);
|
||||||
|
$mform->setDefault('startdate', time() + 3600 * 24);
|
||||||
|
|
||||||
|
$choices = array();
|
||||||
|
$choices['0'] = get_string('hiddensectionscollapsed');
|
||||||
|
$choices['1'] = get_string('hiddensectionsinvisible');
|
||||||
|
$mform->addElement('select', 'hiddensections', get_string('hiddensections'), $choices);
|
||||||
|
$mform->setHelpButton('hiddensections', array('coursehiddensections', get_string('hiddensections')), true);
|
||||||
|
$mform->setDefault('hiddensections', 0);
|
||||||
|
|
||||||
|
$newsitem = get_string('newsitem');
|
||||||
|
$newsitems = get_string('newsitems');
|
||||||
|
$options = array('0' => "0 $newsitems",
|
||||||
|
'1' => "1 $newsitem",
|
||||||
|
'2' => "2 $newsitems",
|
||||||
|
'3' => "3 $newsitems",
|
||||||
|
'4' => "4 $newsitems",
|
||||||
|
'5' => "5 $newsitems",
|
||||||
|
'6' => "6 $newsitems",
|
||||||
|
'7' => "7 $newsitems",
|
||||||
|
'8' => "8 $newsitems",
|
||||||
|
'9' => "9 $newsitems",
|
||||||
|
'10' => "10 $newsitems");
|
||||||
|
$mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
|
||||||
|
$mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true);
|
||||||
|
$mform->setDefault('newsitems', 5);
|
||||||
|
|
||||||
|
$choices = array();
|
||||||
|
$choices['0'] = get_string('no');
|
||||||
|
$choices['1'] = get_string('yes');
|
||||||
|
$mform->addElement('select', 'showgrades', get_string('showgrades'), $choices);
|
||||||
|
$mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true);
|
||||||
|
$mform->setDefault('showgrades', 1);
|
||||||
|
|
||||||
|
$choices = array();
|
||||||
|
$choices['0'] = get_string('no');
|
||||||
|
$choices['1'] = get_string('yes');
|
||||||
|
$mform->addElement('select', 'showreports', get_string('showreports'), $choices);
|
||||||
|
$mform->setHelpButton('showreports', array('coursereports', get_string('activityreport')), true);
|
||||||
|
$mform->setDefault('showreports', 0);
|
||||||
|
|
||||||
|
$choices = get_max_upload_sizes($CFG->maxbytes);
|
||||||
|
$mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
|
||||||
|
$mform->setHelpButton('maxbytes', array('courseuploadsize', get_string('maximumupload')), true);
|
||||||
|
|
||||||
|
if (!empty($CFG->allowcoursethemes)) {
|
||||||
|
$themes=array();
|
||||||
|
$themes[''] = get_string('forceno');
|
||||||
|
$themes += get_list_of_themes();
|
||||||
|
$mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$mform->addElement('header','general', get_string("general"));
|
|
||||||
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $toform->category))) {
|
|
||||||
$displaylist = array();
|
|
||||||
$parentlist = array();
|
|
||||||
make_categories_list($displaylist, $parentlist);
|
|
||||||
$mform->addElement('select', "category", get_string("category"), $displaylist );
|
|
||||||
}
|
|
||||||
$mform->setDefault('fullname', $toform->fullname);
|
|
||||||
$mform->addElement('text','fullname', get_string("fullname"),'maxlength="254" size="50"');
|
|
||||||
$mform->setDefault('shortname', $toform->shortname);
|
|
||||||
$mform->addElement('text','shortname', get_string("shortname"),'maxlength="15" size="10"');
|
|
||||||
$mform->setDefault('idnumber', $toform->idnumber);
|
|
||||||
$mform->addElement('text','idnumber', get_string("idnumbercourse"),'maxlength="100" size="10"');
|
|
||||||
$mform->setDefault('summary', $toform->summary);
|
|
||||||
$mform->addElement('htmleditor','summary', get_string("summary"), array('rows'=>'10', 'cols'=>'65'));
|
|
||||||
|
|
||||||
$mform->setDefault('format', $toform->format);
|
|
||||||
$courseformats = get_list_of_plugins("course/format");
|
|
||||||
$formcourseformats = array();
|
|
||||||
|
|
||||||
foreach ($courseformats as $courseformat) {
|
|
||||||
$formcourseformats["$courseformat"] = get_string("format$courseformat");
|
|
||||||
}
|
|
||||||
|
|
||||||
$mform->addElement('select', 'format', get_string("format"), $formcourseformats );
|
|
||||||
|
|
||||||
$mform->setDefault('numsections', $toform->numsections);
|
|
||||||
for ($i=1; $i<=52; $i++) {
|
|
||||||
$sectionmenu[$i] = "$i";
|
|
||||||
}
|
|
||||||
$mform->addElement('select', 'numsections', get_string("numberweeks"), $sectionmenu);
|
|
||||||
$mform->setDefault('startdate', $toform->startdate);
|
|
||||||
$mform->addElement('date_selector', 'startdate', get_string('startdate'));
|
|
||||||
|
|
||||||
$mform->setDefault('hiddensections',(isset($toform->hiddensections))?$toform->hiddensections:0);
|
|
||||||
unset($choices);
|
|
||||||
$choices["0"] = get_string("hiddensectionscollapsed");
|
|
||||||
$choices["1"] = get_string("hiddensectionsinvisible");
|
|
||||||
$mform->addElement('select', 'hiddensections', get_string("hiddensections"), $choices);
|
|
||||||
|
|
||||||
$mform->setDefault('newsitems', $toform->newsitems);
|
|
||||||
$newsitem = get_string("newsitem");
|
|
||||||
$newsitems = get_string("newsitems");
|
|
||||||
$options = array("0" => "0 $newsitems",
|
|
||||||
"1" => "1 $newsitem",
|
|
||||||
"2" => "2 $newsitems",
|
|
||||||
"3" => "3 $newsitems",
|
|
||||||
"4" => "4 $newsitems",
|
|
||||||
"5" => "5 $newsitems",
|
|
||||||
"6" => "6 $newsitems",
|
|
||||||
"7" => "7 $newsitems",
|
|
||||||
"8" => "8 $newsitems",
|
|
||||||
"9" => "9 $newsitems",
|
|
||||||
"10" => "10 $newsitems");
|
|
||||||
$mform->addElement('select', 'newsitems', get_string("newsitemsnumber"), $options);
|
|
||||||
|
|
||||||
$mform->setDefault('showgrades', $toform->showgrades);
|
|
||||||
unset($choices);
|
|
||||||
$choices["0"] = get_string("no");
|
|
||||||
$choices["1"] = get_string("yes");
|
|
||||||
$mform->addElement('select', 'showgrades', get_string("showgrades"), $choices);
|
|
||||||
unset($choices);
|
|
||||||
$mform->setDefault('showreports',(isset($toform->showreports))?$toform->showreports:0);
|
|
||||||
$choices["0"] = get_string("no");
|
|
||||||
$choices["1"] = get_string("yes");
|
|
||||||
$mform->addElement('select', 'showreports', get_string("showreports"), $choices);
|
|
||||||
$mform->setDefault('maxbytes',(isset($toform->maxbytes))?$toform->maxbytes:0);
|
|
||||||
$choices = get_max_upload_sizes($CFG->maxbytes);
|
|
||||||
$mform->addElement('select', 'maxbytes', get_string("maximumupload"), $choices);
|
|
||||||
if (!empty($CFG->allowcoursethemes)) {
|
|
||||||
$mform->setDefault('theme',(isset($toform->theme))?$toform->theme:'');
|
|
||||||
|
|
||||||
$themes=array();
|
|
||||||
$themes[''] = get_string("forceno");
|
|
||||||
$themes += get_list_of_themes();
|
|
||||||
$mform->addElement('select', 'theme', get_string("forcetheme"), $themes);
|
|
||||||
}
|
|
||||||
unset($choices);
|
|
||||||
$mform->setDefault('metacourse',(isset($toform->metacourse))?$toform->metacourse:0);
|
|
||||||
|
|
||||||
if (empty($disable_meta)) {
|
|
||||||
$meta=array();
|
$meta=array();
|
||||||
$meta[0] = get_string('no');
|
$meta[0] = get_string('no');
|
||||||
$meta[1] = get_string('yes');
|
$meta[1] = get_string('yes');
|
||||||
$mform->addElement('select', 'metacourse', get_string("managemeta"), $meta);
|
if ($disable_meta === false) {
|
||||||
}else{
|
$mform->addElement('select', 'metacourse', get_string('managemeta'), $meta);
|
||||||
$mform->addElement('static', 'metacourse', get_string("managemeta"),
|
|
||||||
((empty($toform->metacourse)) ? get_string("no") : get_string("yes"))
|
|
||||||
. " - $disable_meta ");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$mform->setDefault('defaultrole',(isset($toform->defaultrole))?$toform->defaultrole:0);
|
|
||||||
$roles = get_assignable_roles($context);
|
|
||||||
asort($roles);
|
|
||||||
$choices = array();
|
|
||||||
|
|
||||||
if ($sitedefaultrole = get_record('role', 'id', $CFG->defaultcourseroleid)) {
|
|
||||||
$choices[0] = get_string('sitedefault').' ('.$sitedefaultrole->name.')';
|
|
||||||
} else {
|
|
||||||
$choices[0] = get_string('sitedefault');
|
|
||||||
}
|
|
||||||
|
|
||||||
$choices = $choices + $roles;
|
|
||||||
$defaultroleelement=$mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices );
|
|
||||||
if ($mform->exportValue('defaultrole') && !isset($roles[$mform->exportValue('defaultrole')])) { // Existing setting is one we can't choose
|
|
||||||
if ($coursedefaultrole = get_record('role', 'id', $mform->exportValue('defaultrole'))) {
|
|
||||||
|
|
||||||
$defaultroleelement->addOption(get_string('currentrole', 'role').' ('.$coursedefaultrole->name.')',-1);
|
|
||||||
} else {
|
} else {
|
||||||
$defaultroleelement->addOption(get_string('currentrole', 'role'),-1);
|
$mform->addElement('static', 'metacourse', get_string('managemeta'),
|
||||||
|
((empty($course->metacourse)) ? $meta[0] : $meta[1]) . " - $disable_meta ");
|
||||||
}
|
}
|
||||||
}
|
$mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true);
|
||||||
|
$mform->setDefault('metacourse', 0);
|
||||||
|
|
||||||
|
$roles = get_assignable_roles($context);
|
||||||
$mform->addElement('header','enrolhdr', get_string("enrolment"));
|
if (!empty($course)) {
|
||||||
$mform->setDefault('enrol',(isset($toform->enrol))?$toform->enrol:'');
|
// add current default role, so that it is selectable even when user can not assign it
|
||||||
|
if ($current_role = get_record('role', 'id', $course->defaultrole)) {
|
||||||
$modules = explode(',', $CFG->enrol_plugins_enabled);
|
$roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
|
||||||
foreach ($modules as $module) {
|
}
|
||||||
$name = get_string("enrolname", "enrol_$module");
|
|
||||||
$plugin = enrolment_factory::factory($module);
|
|
||||||
if (method_exists($plugin, 'print_entry')) {
|
|
||||||
$choices[$name] = $module;
|
|
||||||
}
|
}
|
||||||
}
|
$choices = array();
|
||||||
asort($choices);
|
if ($sitedefaultrole = get_record('role', 'id', $CFG->defaultcourseroleid)) {
|
||||||
$choices = array_flip($choices);
|
$choices[0] = get_string('sitedefault').' ('.$sitedefaultrole->name.')';
|
||||||
$choices = array_merge(array('' => get_string('sitedefault').' ('.get_string("enrolname", "enrol_$CFG->enrol").')'), $choices);
|
} else {
|
||||||
$mform->addElement('select', 'enrol', get_string("enrolmentplugins"), $choices );
|
$choices[0] = get_string('sitedefault');
|
||||||
|
}
|
||||||
|
$choices = $choices + $roles;
|
||||||
|
$mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices);
|
||||||
|
$mform->setDefault('defaultrole', 0);
|
||||||
|
|
||||||
$mform->setDefault('enrollable',(isset($toform->enrollable))?$toform->enrollable:1);
|
//--------------------------------------------------------------------------------
|
||||||
$radio = array();
|
$mform->addElement('header','enrolhdr', get_string('enrolments'));
|
||||||
$radio[] = &moodleform::createElement('radio', 'enrollable', null, get_string("no"), 0);
|
|
||||||
$radio[] = &moodleform::createElement('radio', 'enrollable', null, get_string("yes"), 1);
|
|
||||||
$radio[] = &moodleform::createElement('radio', 'enrollable', null, get_string("enroldate"), 2);
|
|
||||||
$mform->addGroup($radio, 'enrollable', get_string("enrollable"), ' ', false);
|
|
||||||
|
|
||||||
$mform->setDefault('enrolstartdate',(isset($toform->enrolstartdate))?$toform->enrolstartdate:0);
|
$modules = explode(',', $CFG->enrol_plugins_enabled);
|
||||||
$mform->setDefault('enrolstartdisabled',
|
foreach ($modules as $module) {
|
||||||
(!isset($toform->enrolstartdate)||
|
$name = get_string('enrolname', "enrol_$module");
|
||||||
(isset($toform->enrolstartdate)&&!$toform->enrolstartdate)
|
$plugin = enrolment_factory::factory($module);
|
||||||
?1:0));
|
if (method_exists($plugin, 'print_entry')) {
|
||||||
$enroldatestartgrp = array();
|
$choices[$name] = $module;
|
||||||
$enroldatestartgrp[] = &moodleform::createElement('date_selector', 'enrolstartdate');
|
}
|
||||||
$enroldatestartgrp[] = &moodleform::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
|
}
|
||||||
$mform->addGroup($enroldatestartgrp, '', get_string('enrolstartdate'), ' ', false);
|
asort($choices);
|
||||||
|
$choices = array_flip($choices);
|
||||||
|
$choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices);
|
||||||
|
$mform->addElement('select', 'enrol', get_string('enrolmentplugins'), $choices);
|
||||||
|
$mform->setHelpButton('enrol', array('courseenrolmentplugins', get_string('enrolmentplugins')), true);
|
||||||
|
|
||||||
$mform->setDefault('enrolenddate',(isset($toform->enrolenddate))?$toform->enrolenddate:0);
|
$radio = array();
|
||||||
$mform->setDefault('enrolenddisabled',
|
$radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('no'), 0);
|
||||||
(!isset($toform->enrolenddate)||
|
$radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('yes'), 1);
|
||||||
(isset($toform->enrolenddate)&&!$toform->enrolenddate)
|
$radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('enroldate'), 2);
|
||||||
?1:0));
|
$mform->addGroup($radio, 'enrollable', get_string('enrollable'), ' ', false);
|
||||||
$enroldateendgrp = array();
|
$mform->setHelpButton('enrollable', array('courseenrollable', get_string('enrollable')), true);
|
||||||
$enroldateendgrp[] = &moodleform::createElement('date_selector', 'enrolenddate');
|
$mform->setDefault('enrollable', 1);
|
||||||
$enroldateendgrp[] = &moodleform::createElement('checkbox', 'enrolenddisabled', null, get_string('disable'));
|
|
||||||
$mform->addGroup($enroldateendgrp, 'enroldateendgrp', get_string('enrolenddate'), ' ', false);
|
|
||||||
|
|
||||||
$mform->setDefault('enrolperiod',(isset($toform->enrolperiod))?$toform->enrolperiod:0);
|
$enroldatestartgrp = array();
|
||||||
$periodmenu=array();
|
$enroldatestartgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolstartdate');
|
||||||
$periodmenu[0] = get_string('unlimited');
|
$enroldatestartgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
|
||||||
for ($i=1; $i<=365; $i++) {
|
$mform->addGroup($enroldatestartgrp, '', get_string('enrolstartdate'), ' ', false);
|
||||||
$seconds = $i * 86400;
|
$mform->setDefault('enrolstartdate', 0);
|
||||||
$periodmenu[$seconds] = get_string('numdays', '', $i);
|
$mform->setDefault('enrolstartdisabled', 1);
|
||||||
}
|
|
||||||
$mform->addElement('select', 'enrolperiod', get_string("enrolperiod"), $periodmenu);
|
$enroldateendgrp = array();
|
||||||
|
$enroldateendgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolenddate');
|
||||||
|
$enroldateendgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolenddisabled', null, get_string('disable'));
|
||||||
|
$mform->addGroup($enroldateendgrp, 'enroldateendgrp', get_string('enrolenddate'), ' ', false);
|
||||||
|
$mform->setDefault('enrolenddate', 0);
|
||||||
|
$mform->setDefault('enrolenddisabled', 1);
|
||||||
|
|
||||||
|
$periodmenu=array();
|
||||||
|
$periodmenu[0] = get_string('unlimited');
|
||||||
|
for ($i=1; $i<=365; $i++) {
|
||||||
|
$seconds = $i * 86400;
|
||||||
|
$periodmenu[$seconds] = get_string('numdays', '', $i);
|
||||||
|
}
|
||||||
|
$mform->addElement('select', 'enrolperiod', get_string('enrolperiod'), $periodmenu);
|
||||||
|
$mform->setDefault('enrolperiod', 0);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
$mform->addElement('header','expirynotifyhdr', get_string('expirynotify'));
|
||||||
|
|
||||||
|
$choices = array();
|
||||||
|
$choices['0'] = get_string('no');
|
||||||
|
$choices['1'] = get_string('yes');
|
||||||
|
$mform->addElement('select', 'expirynotify', get_string('expirynotify'), $choices);
|
||||||
|
$mform->setHelpButton('expirynotify', array('expirynotify', get_string('expirynotify')), true);
|
||||||
|
$mform->setDefault('expirynotify', 0);
|
||||||
|
|
||||||
|
$mform->addElement('select', 'notifystudents', get_string('expirynotifystudents'), $choices);
|
||||||
|
$mform->setHelpButton('notifystudents', array('expirynotifystudents', get_string('expirynotifystudents')), true);
|
||||||
|
$mform->setDefault('notifystudents', 0);
|
||||||
|
|
||||||
|
$thresholdmenu=array();
|
||||||
|
for ($i=1; $i<=30; $i++) {
|
||||||
|
$seconds = $i * 86400;
|
||||||
|
$thresholdmenu[$seconds] = get_string('numdays', '', $i);
|
||||||
|
}
|
||||||
|
$mform->addElement('select', 'expirythreshold', get_string('expirythreshold'), $thresholdmenu);
|
||||||
|
$mform->setHelpButton('expirythreshold', array('expirythreshold', get_string('expirythreshold')), true);
|
||||||
|
$mform->setDefault('expirythreshold', 10 * 86400);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
$mform->addElement('header','', get_string('groupmode'));
|
||||||
|
|
||||||
|
$choices = array();
|
||||||
|
$choices[NOGROUPS] = get_string('groupsnone');
|
||||||
|
$choices[SEPARATEGROUPS] = get_string('groupsseparate');
|
||||||
|
$choices[VISIBLEGROUPS] = get_string('groupsvisible');
|
||||||
|
$mform->addElement('select', 'groupmode', get_string('groupmode'), $choices);
|
||||||
|
$mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')), true);
|
||||||
|
$mform->setDefault('groupmode', 0);
|
||||||
|
|
||||||
|
$choices = array();
|
||||||
|
$choices['0'] = get_string('no');
|
||||||
|
$choices['1'] = get_string('yes');
|
||||||
|
$mform->addElement('select', 'groupmodeforce', get_string('force'), $choices);
|
||||||
|
$mform->setHelpButton('groupmodeforce', array('groupmodeforce', get_string('groupmodeforce')), true);
|
||||||
|
$mform->setDefault('groupmodeforce', 0);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
$mform->addElement('header','', get_string('availability'));
|
||||||
|
|
||||||
|
$choices = array();
|
||||||
|
$choices['0'] = get_string('courseavailablenot');
|
||||||
|
$choices['1'] = get_string('courseavailable');
|
||||||
|
$mform->addElement('select', 'visible', get_string('availability'), $choices);
|
||||||
|
$mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
|
||||||
|
$mform->setDefault('visible', 1);
|
||||||
|
|
||||||
|
$mform->addElement('text', 'password', get_string('enrolmentkey'), 'size="25"');
|
||||||
|
$mform->setHelpButton('password', array('enrolmentkey', get_string('enrolmentkey')), true);
|
||||||
|
$mform->setDefault('password', '');
|
||||||
|
$mform->setType('password', PARAM_RAW);
|
||||||
|
|
||||||
|
$choices = array();
|
||||||
|
$choices['0'] = get_string('guestsno');
|
||||||
|
$choices['1'] = get_string('guestsyes');
|
||||||
|
$choices['2'] = get_string('guestskey');
|
||||||
|
$mform->addElement('select', 'guest', get_string('opentoguests'), $choices);
|
||||||
|
$mform->setHelpButton('guest', array('guestaccess', get_string('opentoguests')), true);
|
||||||
|
$mform->setDefault('guest', 0);
|
||||||
|
|
||||||
|
if (!empty($course) && method_exists(enrolment_factory::factory($course->enrol), 'print_entry') && $course->enrol != 'manual') {
|
||||||
|
$costgroup=array();
|
||||||
|
$currencies = get_list_of_currencies();
|
||||||
|
$costgroup[]= &MoodleQuickForm::createElement('text','cost', '', 'maxlength="6" size="6"');
|
||||||
|
$costgroup[]= &MoodleQuickForm::createElement('select', 'currency', '', $currencies);
|
||||||
|
$mform->addGroup($costgroup, 'costgrp', get_string('cost'), ' ', false);
|
||||||
|
$mform->setHelpButton('costgrp', array('cost', get_string('cost')), true);
|
||||||
|
$mform->setDefault('cost', '');
|
||||||
|
$mform->setDefault('currency', empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
|
||||||
|
// TODO: fix rule usage and add proper error message
|
||||||
|
//$mform->addRule('cost', get_string('error'), 'numeric', null, 'client');
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
$mform->addElement('header','', get_string('language'));
|
||||||
|
|
||||||
|
$languages=array();
|
||||||
|
$languages[''] = get_string('forceno');
|
||||||
|
$languages += get_list_of_languages();
|
||||||
|
$mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
if (has_capability('moodle/site:config', $systemcontext) && ((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) {
|
||||||
|
$mform->addElement('header', '', get_string('restrictmodules'));
|
||||||
|
|
||||||
|
$options = array();
|
||||||
|
$options['0'] = get_string('no');
|
||||||
|
$options['1'] = get_string('yes');
|
||||||
|
$mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options,
|
||||||
|
array('onChange'=>"document.getElementById('id_allowedmods').disabled=".
|
||||||
|
"((this.selectedIndex==0)?true:false);"));
|
||||||
|
$mods = array(0=>get_string('allownone'));
|
||||||
|
$mods += get_records_menu('modules', '','','','id, name');
|
||||||
|
$disabled=($mform->exportValue('restrictmodules')==1) ? array() :array('disabled' => 'disabled') ;
|
||||||
|
|
||||||
|
|
||||||
$mform->addElement('header','expirynotifyhdr', get_string("expirynotify"));
|
$mform->addElement('select', 'allowedmods', get_string('to'),$mods,
|
||||||
|
array('multiple'=>'multiple', 'size'=>'10', 'id'=>'allowedmods')
|
||||||
|
+$disabled);
|
||||||
|
}else {
|
||||||
|
$mform->addElement('hidden', 'restrictmodules', null);
|
||||||
|
}
|
||||||
|
if ($CFG->restrictmodulesfor == 'all') {
|
||||||
|
$mform->setDefault('allowedmods', explode(',',$CFG->defaultallowedmodules));
|
||||||
|
if (!empty($CFG->restrictbydefault)) {
|
||||||
|
$mform->setDefault('restrictmodules', 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$mform->setType('restrictmodules', PARAM_INT);
|
||||||
|
|
||||||
$mform->setDefault('expirynotify',(isset($toform->expirynotify))?$toform->expirynotify:0);
|
//--------------------------------------------------------------------------------
|
||||||
unset($choices);
|
$mform->addElement('submit', 'submit', get_string('savechanges'));
|
||||||
$choices["0"] = get_string("no");
|
|
||||||
$choices["1"] = get_string("yes");
|
//--------------------------------------------------------------------------------
|
||||||
$mform->addElement('select', 'expirynotify', get_string("expirynotify"), $choices);
|
$mform->addElement('hidden', 'id', null);
|
||||||
$mform->setDefault('notifystudents',(isset($toform->notifystudents))?$toform->notifystudents:0);
|
$mform->setType('id', PARAM_INT);
|
||||||
$mform->addElement('select', 'notifystudents', get_string("expirynotifystudents"), $choices);
|
|
||||||
$mform->setDefault('expirythreshold',(isset($toform->expirythreshold))?$toform->expirythreshold:10 * 86400);
|
// fill in default teacher and student names to keep backwards compatibility for a while
|
||||||
$thresholdmenu=array();
|
$mform->addElement('hidden', 'teacher', get_string('defaultcourseteacher'));
|
||||||
for ($i=1; $i<=30; $i++) {
|
$mform->addElement('hidden', 'teachers', get_string('defaultcourseteachers'));
|
||||||
$seconds = $i * 86400;
|
$mform->addElement('hidden', 'student', get_string('defaultcoursestudent'));
|
||||||
$thresholdmenu[$seconds] = get_string('numdays', '', $i);
|
$mform->addElement('hidden', 'students', get_string('defaultcoursestudents'));
|
||||||
}
|
|
||||||
$mform->addElement('select', 'expirythreshold', get_string("expirythreshold"), $thresholdmenu);
|
|
||||||
|
|
||||||
|
|
||||||
$mform->addElement('header','', get_string("groupmode"));
|
//--------------------------------------------------------------------------------
|
||||||
|
$renderer->addStopFieldsetElements('submit');
|
||||||
|
|
||||||
$mform->setDefault('groupmode', $toform->groupmode);
|
|
||||||
unset($choices);
|
|
||||||
$choices[NOGROUPS] = get_string("groupsnone");
|
|
||||||
$choices[SEPARATEGROUPS] = get_string("groupsseparate");
|
|
||||||
$choices[VISIBLEGROUPS] = get_string("groupsvisible");
|
|
||||||
$mform->addElement('select', 'groupmode', get_string("groupmode"), $choices);
|
|
||||||
$mform->setDefault('groupmodeforce', $toform->groupmodeforce);
|
|
||||||
unset($choices);
|
|
||||||
$choices["0"] = get_string("no");
|
|
||||||
$choices["1"] = get_string("yes");
|
|
||||||
$mform->addElement('select', 'groupmodeforce', get_string("force"), $choices);
|
|
||||||
|
|
||||||
$mform->addElement('header','', get_string("availability"));
|
// now override defaults if course already exists
|
||||||
|
if (!empty($course)) {
|
||||||
|
$this->set_defaults($course);
|
||||||
|
}
|
||||||
|
|
||||||
$mform->setDefault('visible', $toform->visible);
|
|
||||||
unset($choices);
|
|
||||||
$choices["0"] = get_string("courseavailablenot");
|
|
||||||
$choices["1"] = get_string("courseavailable");
|
|
||||||
$mform->addElement('select', 'visible', get_string("availability"), $choices);
|
|
||||||
$mform->setDefault('password', $toform->password);
|
|
||||||
$mform->addElement('text', 'password', get_string("enrolmentkey"), 'size="25"');
|
|
||||||
$mform->setDefault('guest', $toform->guest);
|
|
||||||
unset($choices);
|
|
||||||
$choices["0"] = get_string("guestsno");
|
|
||||||
$choices["1"] = get_string("guestsyes");
|
|
||||||
$choices["2"] = get_string("guestskey");
|
|
||||||
$mform->addElement('select', 'guest', get_string("opentoguests"), $choices);
|
|
||||||
if (isset($course) && method_exists(enrolment_factory::factory($course->enrol), 'print_entry') && $course->enrol != 'manual') {
|
|
||||||
$mform->setDefault('cost', $toform->cost);
|
|
||||||
$mform->setDefault('currency', $toform->currency);
|
|
||||||
$costgroup=array();
|
|
||||||
$currencies = get_list_of_currencies();
|
|
||||||
$costgroup[]= &moodleform::createElement('text','cost', '', 'maxlength="6" size="6"');
|
|
||||||
$costgroup[]= &moodleform::createElement('select', 'currency', '', $currencies);
|
|
||||||
$mform->addGroup($costgroup, 'costgrp', get_string("cost"), ' ', false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$mform->addElement('header','', get_string("language"));
|
/// perform some extra moodle validation
|
||||||
$mform->setDefault('lang',(isset($toform->lang))?$toform->lang:'');
|
function validation($data){
|
||||||
$languages=array();
|
|
||||||
$languages[''] = get_string("forceno");
|
|
||||||
$languages += get_list_of_languages();
|
|
||||||
$mform->addElement('select', 'lang', get_string("forcelanguage"), $languages);
|
|
||||||
|
|
||||||
if(!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $toform->category))) {
|
|
||||||
$mform->addElement('hidden', 'category', null);
|
|
||||||
}
|
|
||||||
$mform->addElement('hidden', 'id', null);
|
|
||||||
|
|
||||||
$mform->setDefault('restrictmodules',(isset($toform->restrictmodules))?$toform->restrictmodules:0);
|
|
||||||
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) && ((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) {
|
|
||||||
unset($options);
|
|
||||||
$options[0] = get_string("no");
|
|
||||||
$options[1] = get_string("yes");
|
|
||||||
$mform->addElement('header', '', get_string("restrictmodules"));
|
|
||||||
$mform->addElement('select', 'restrictmodules', get_string("restrictmodules"), $options,
|
|
||||||
array('onChange'=>"document.getElementById('id_allowedmods').disabled=".
|
|
||||||
"((this.selectedIndex==0)?true:false);"));
|
|
||||||
$mods = array(0=>get_string('allownone'));
|
|
||||||
$mods += get_records_menu("modules", '','','','id, name');
|
|
||||||
$disabled=($mform->exportValue('restrictmodules')==1) ? array() :array('disabled' => 'disabled') ;
|
|
||||||
|
|
||||||
|
|
||||||
$mform->setDefault('allowedmods', $toform->allowedmods);
|
|
||||||
$mform->addElement('select', 'allowedmods', get_string("to"),$mods,
|
|
||||||
array('multiple'=>"multiple", 'size'=>"10", 'id'=>"allowedmods")
|
|
||||||
+$disabled);
|
|
||||||
}else {
|
|
||||||
$mform->addElement('hidden', 'restrictmodules', $toform->restrictmodules);
|
|
||||||
}
|
|
||||||
$mform->setHelpButtons(array('category'=>array("coursecategory", get_string("category")),
|
|
||||||
'fullname'=>array("coursefullname", get_string("fullname")),
|
|
||||||
'shortname'=>array("courseshortname", get_string("shortname")),
|
|
||||||
'idnumber'=>array("courseidnumber", get_string("idnumbercourse")),
|
|
||||||
'summary'=>array("text", get_string("helptext")),
|
|
||||||
'format'=>array("courseformats", get_string("courseformats")),
|
|
||||||
'summary'=>array("coursestartdate", get_string("startdate")),
|
|
||||||
'enrol'=>array("courseenrolmentplugins", get_string("enrolmentplugins")),
|
|
||||||
'enrollable'=>array("courseenrollable", get_string("enrollable")),
|
|
||||||
'expirynotify'=>array("expirynotify", get_string("expirynotify")),
|
|
||||||
'notifystudents'=>array("expirynotifystudents", get_string("expirynotifystudents")),
|
|
||||||
'expirythreshold'=>array("expirythreshold", get_string("expirythreshold")),
|
|
||||||
'groupmode'=>array("groupmode", get_string("groupmode")),
|
|
||||||
'groupmodeforce'=>array("groupmodeforce", get_string("groupmodeforce")),
|
|
||||||
'visible'=>array("courseavailability", get_string("availability")),
|
|
||||||
'password'=>array("enrolmentkey", get_string("enrolmentkey")),
|
|
||||||
'guest'=>array("guestaccess", get_string("opentoguests")),
|
|
||||||
'costgrp'=>array("cost", get_string("cost")),
|
|
||||||
'hiddensections'=>array("coursehiddensections", get_string("hiddensections")),
|
|
||||||
'newsitems'=>array("coursenewsitems", get_string("newsitemsnumber")),
|
|
||||||
'showgrades'=>array("coursegrades", get_string("grades")),
|
|
||||||
'showreports'=>array("coursereports", get_string("activityreport")),
|
|
||||||
'maxbytes'=>array("courseuploadsize", get_string("maximumupload")),
|
|
||||||
'metacourse'=>array("metacourse", get_string("metacourse")),
|
|
||||||
'defaultrole'=>array("coursedefaultrole", get_string("defaultrole", 'role'))),
|
|
||||||
true);
|
|
||||||
$mform->addElement('submit', 'submit', get_string("savechanges"));
|
|
||||||
|
|
||||||
$mform->addRule('fullname', get_string("missingfullname"), 'required', null, 'client');
|
|
||||||
$mform->addRule('shortname', get_string("missingshortname"), 'required', null, 'client');
|
|
||||||
$mform->addRule('summary', get_string("missingsummary"), 'required', null, 'client');
|
|
||||||
$mform->addRule('category', get_string("missingcategory"), 'required', null, 'client');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* a Form rule check - if we need to create rules which involve the contents of more than one
|
|
||||||
* field this is the way to do it. We can do it all at once in one function or create several
|
|
||||||
* form rules.
|
|
||||||
*
|
|
||||||
* @param array $fields values from form without slashes
|
|
||||||
* @return mixed array of errors or true if passed check
|
|
||||||
*/
|
|
||||||
function form_check($fields){
|
|
||||||
global $course;
|
|
||||||
$errors= array();
|
$errors= array();
|
||||||
if ($foundcourses = get_records("course", "shortname", addslashes($fields['shortname']))) {
|
if ($foundcourses = get_records('course', 'shortname', $data['shortname'])) {
|
||||||
if (!empty($course->id)) {
|
if (!empty($data['id'])) {
|
||||||
unset($foundcourses[$course->id]);
|
unset($foundcourses[$data['id']]);
|
||||||
}
|
}
|
||||||
if (!empty($foundcourses)) {
|
if (!empty($foundcourses)) {
|
||||||
foreach ($foundcourses as $foundcourse) {
|
foreach ($foundcourses as $foundcourse) {
|
||||||
$foundcoursenames[] = $foundcourse->fullname;
|
$foundcoursenames[] = $foundcourse->fullname;
|
||||||
}
|
}
|
||||||
$foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
|
$foundcoursenamestring = implode(',', $foundcoursenames);
|
||||||
|
$errors['shortname']= get_string('shortnametaken', '', $foundcoursenamestring);
|
||||||
$errors['shortname']= get_string("shortnametaken", "", $foundcoursenamestring);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
if (empty($fields['enrolenddisabled'])){
|
|
||||||
$enrolenddate=make_timestamp($fields['enrolenddate']['year'],
|
|
||||||
$fields['enrolenddate']['month'],
|
|
||||||
$fields['enrolenddate']['day']);
|
|
||||||
$enrolstartdate=make_timestamp($fields['enrolstartdate']['year'],
|
|
||||||
$fields['enrolstartdate']['month'],
|
|
||||||
$fields['enrolstartdate']['day']);
|
|
||||||
if ($enrolenddate <= $enrolstartdate){
|
|
||||||
$errors['enroldateendgrp']=get_string("enrolenddaterror");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0==count($errors)){
|
|
||||||
|
if (empty($data['enrolenddisabled'])){
|
||||||
|
if ($data['enrolenddate'] <= $data['enrolstartdate']){
|
||||||
|
$errors['enroldateendgrp'] = get_string('enrolenddaterror');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == count($errors)){
|
||||||
return true;
|
return true;
|
||||||
}else {
|
} else {
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$mform->addFormRule('form_check');
|
}
|
||||||
|
|
||||||
$renderer =& $mform->defaultRenderer();
|
|
||||||
$renderer->addStopFieldsetElements('submit');
|
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue