Complete port of Moodle 1.8 formslib.php back into 1.7 to aid development of any modules that may use formslib in 1.7
MDL-9159
This commit is contained in:
+103
-159
@@ -1,177 +1,122 @@
|
||||
<?php // $Id$
|
||||
// Edit course settings
|
||||
|
||||
require_once("../config.php");
|
||||
require_once("lib.php");
|
||||
require_once("$CFG->libdir/blocklib.php");
|
||||
require_once("$CFG->dirroot/enrol/enrol.class.php");
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot.'/enrol/enrol.class.php');
|
||||
require_once($CFG->libdir.'/blocklib.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
|
||||
|
||||
require_login();
|
||||
|
||||
$mform =& new moodleform('edit_course', 'post', 'edit2.php');
|
||||
|
||||
$mform->acceptGet('id', 'category');
|
||||
|
||||
$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");
|
||||
/// basic access control checks
|
||||
if ($id) { // editing course
|
||||
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);
|
||||
|
||||
if (!has_capability('moodle/course:update', $context)) {
|
||||
error("You do not currently have editing privileges!");
|
||||
} else if ($categoryid) { // creating new course in this category
|
||||
$course = null;
|
||||
if (!$category = get_record('course_categories', 'id', $categoryid)) {
|
||||
error('Category ID was incorrect');
|
||||
}
|
||||
|
||||
if (course_in_meta($course)) {
|
||||
$disable_meta = get_string('metaalreadyinmeta');
|
||||
} else if ($course->metacourse) {
|
||||
if (count_records("course_meta","parent_course",$course->id) > 0) {
|
||||
$disable_meta = get_string('metaalreadyhascourses');
|
||||
}
|
||||
} else {
|
||||
$managers = count(get_users_by_capability($context, 'moodle/course:managemetacourse'));
|
||||
$participants = count(get_users_by_capability($context, 'moodle/course:view'));
|
||||
if ($participants > $managers) {
|
||||
$disable_meta = get_string('metaalreadyhasenrolments');
|
||||
}
|
||||
}
|
||||
} else { // Admin is creating a new course
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
if (!has_capability('moodle/course:create',$context)) {
|
||||
error("You do not currently have course creation privileges!");
|
||||
}
|
||||
|
||||
$course = NULL;
|
||||
require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id));
|
||||
} else {
|
||||
error('Either course id or category must be specified');
|
||||
}
|
||||
|
||||
if (! $site = get_site()) {
|
||||
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
||||
}
|
||||
|
||||
|
||||
|
||||
include("edit_form.php");
|
||||
|
||||
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
// data_submitted tries to validate form data and returns false if
|
||||
// the user inputted data is invalid and the form should be redisplayed with
|
||||
// feedback.
|
||||
|
||||
if ($fromform=$mform->data_submitted()) {
|
||||
|
||||
|
||||
if (!empty($fromform->enrolstartdisabled)){
|
||||
$fromform->enrolstartdate = 0;
|
||||
}
|
||||
|
||||
if (!empty($fromform->enrolenddisabled)) {
|
||||
$fromform->enrolenddate = 0;
|
||||
}
|
||||
/// prepare course
|
||||
if (!empty($course)) {
|
||||
$allowedmods = array();
|
||||
if (!empty($fromform->allowedmods)) {
|
||||
$allowedmods = $fromform->allowedmods;
|
||||
unset($fromform->allowedmods);
|
||||
}
|
||||
|
||||
$fromform->timemodified = time();
|
||||
|
||||
if ($fromform->defaultrole == -1) { // Just leave it however it is
|
||||
unset($fromform->defaultrole);
|
||||
}
|
||||
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);
|
||||
if ($am = get_records('course_allowed_modules','course',$course->id)) {
|
||||
foreach ($am as $m) {
|
||||
$allowedmods[] = $m->module;
|
||||
}
|
||||
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)");
|
||||
if (empty($course->restrictmodules)) {
|
||||
$allowedmods = explode(',',$CFG->defaultallowedmodules);
|
||||
} // it'll be greyed out but we want these by default anyway.
|
||||
}
|
||||
} else {
|
||||
$fromform->timecreated = time();
|
||||
|
||||
// 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;
|
||||
$course->allowedmods = $allowedmods;
|
||||
|
||||
if ($course->enrolstartdate){
|
||||
$course->enrolstartdisabled = 0;
|
||||
}
|
||||
// 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!");
|
||||
|
||||
if ($course->enrolenddate) {
|
||||
$course->enrolenddisabled = 0;
|
||||
}
|
||||
}
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
//print the form
|
||||
/// first create the form
|
||||
$editform = new course_edit_form('edit.php', compact('course', 'category'));
|
||||
// now override defaults if course already exists
|
||||
if (!empty($course)) {
|
||||
$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()) {
|
||||
|
||||
/// process data if submitted
|
||||
|
||||
//preprocess data
|
||||
if ($data->enrolstartdisabled){
|
||||
$data->enrolstartdate = 0;
|
||||
}
|
||||
|
||||
if ($data->enrolenddisabled) {
|
||||
$data->enrolenddate = 0;
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -179,20 +124,19 @@
|
||||
$strcategories = get_string("categories");
|
||||
|
||||
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>
|
||||
-> $streditcoursesettings", $focus);
|
||||
-> $streditcoursesettings", $editform->focus());
|
||||
} else {
|
||||
print_header("$site->shortname: $straddnewcourse", "$site->fullname",
|
||||
"<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"index.php\">$strcategories</a> -> $straddnewcourse", $focus);
|
||||
print_header("$site->shortname: $straddnewcourse", $site->fullname,
|
||||
"<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"index.php\">$strcategories</a> -> $straddnewcourse", $editform->focus());
|
||||
}
|
||||
|
||||
|
||||
print_heading($streditcoursesettings);
|
||||
|
||||
$mform->display();
|
||||
|
||||
$editform->display();
|
||||
|
||||
print_footer($course);
|
||||
|
||||
?>
|
||||
|
||||
+341
-351
@@ -1,392 +1,382 @@
|
||||
<?php
|
||||
/// 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.
|
||||
<?php //$Id$
|
||||
|
||||
// $toform will be used for the default value of a field if no data has been submitted.
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
if (!empty($course)) {
|
||||
//this is what we do if we are editing a record from the db
|
||||
$toform = $course;
|
||||
$toform->allowedmods = array();
|
||||
if ($am = get_records("course_allowed_modules","course",$course->id)) {
|
||||
foreach ($am as $m) {
|
||||
$toform->allowedmods[] = $m->module;
|
||||
class course_edit_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
global $USER, $CFG;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
$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', $course->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 {
|
||||
if (empty($course->restrictmodules)) {
|
||||
$toform->allowedmods = explode(',',$CFG->defaultallowedmodules);
|
||||
} // it'll be greyed out but we want these by default anyway.
|
||||
}
|
||||
} else {
|
||||
//this is a brand new course!
|
||||
$toform->startdate = time() + 3600 * 24;
|
||||
$toform->fullname = get_string("defaultcoursefullname");
|
||||
$toform->shortname = get_string("defaultcourseshortname");
|
||||
$toform->summary = get_string("defaultcoursesummary");
|
||||
$toform->format = "weeks";
|
||||
$toform->password = "";
|
||||
$toform->guest = 0;
|
||||
$toform->numsections = 10;
|
||||
$toform->idnumber = '';
|
||||
$toform->cost = '';
|
||||
$toform->currency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
|
||||
$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;
|
||||
}
|
||||
$coursecontext = null;
|
||||
$context = $categorycontext;
|
||||
}
|
||||
|
||||
/// form definition with new course defaults
|
||||
//--------------------------------------------------------------------------------
|
||||
$mform->addElement('header','general', get_string('general', 'form'));
|
||||
|
||||
}
|
||||
//must have create course capability in both categories in order to move course
|
||||
if (has_capability('moodle/course:create', $categorycontext)) {
|
||||
$displaylist = array();
|
||||
$parentlist = array();
|
||||
make_categories_list($displaylist, $parentlist);
|
||||
foreach ($displaylist as $key=>$val) {
|
||||
if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $key))) {
|
||||
unset($displaylist[$key]);
|
||||
}
|
||||
}
|
||||
$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('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->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->setDefault('format', $toform->format);
|
||||
$courseformats = get_list_of_plugins("course/format");
|
||||
$formcourseformats = array();
|
||||
$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);
|
||||
|
||||
foreach ($courseformats as $courseformat) {
|
||||
$formcourseformats["$courseformat"] = get_string("format$courseformat");
|
||||
}
|
||||
$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('select', 'format', get_string("format"), $formcourseformats );
|
||||
$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);
|
||||
|
||||
$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'));
|
||||
$courseformats = get_list_of_plugins('course/format');
|
||||
$formcourseformats = array();
|
||||
foreach ($courseformats as $courseformat) {
|
||||
$formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
|
||||
if($formcourseformats["$courseformat"]=="[[format$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');
|
||||
|
||||
$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);
|
||||
for ($i=1; $i<=52; $i++) {
|
||||
$sectionmenu[$i] = "$i";
|
||||
}
|
||||
$mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
|
||||
$mform->setDefault('numsections', 10);
|
||||
|
||||
$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->addElement('date_selector', 'startdate', get_string('startdate'));
|
||||
$mform->setHelpButton('startdate', array('coursestartdate', get_string('startdate')), true);
|
||||
$mform->setDefault('startdate', time() + 3600 * 24);
|
||||
|
||||
$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);
|
||||
$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);
|
||||
|
||||
$options = range(0, 10);
|
||||
$mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
|
||||
$mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true);
|
||||
$mform->setDefault('newsitems', 5);
|
||||
|
||||
$mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
|
||||
$mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true);
|
||||
$mform->setDefault('showgrades', 1);
|
||||
|
||||
$mform->addElement('selectyesno', 'showreports', get_string('showreports'));
|
||||
$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);
|
||||
}
|
||||
|
||||
if (empty($disable_meta)) {
|
||||
$meta=array();
|
||||
$meta[0] = get_string('no');
|
||||
$meta[1] = get_string('yes');
|
||||
$mform->addElement('select', 'metacourse', get_string("managemeta"), $meta);
|
||||
}else{
|
||||
$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);
|
||||
if ($disable_meta === false) {
|
||||
$mform->addElement('select', 'metacourse', get_string('managemeta'), $meta);
|
||||
$mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true);
|
||||
$mform->setDefault('metacourse', 0);
|
||||
} else {
|
||||
$defaultroleelement->addOption(get_string('currentrole', 'role'),-1);
|
||||
// no metacourse element - we do not want to change it anyway!
|
||||
$mform->addElement('static', 'nometacourse', get_string('managemeta'),
|
||||
((empty($course->metacourse)) ? $meta[0] : $meta[1]) . " - $disable_meta ");
|
||||
$mform->setHelpButton('nometacourse', array('metacourse', get_string('metacourse')), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$mform->addElement('header','enrolhdr', get_string("enrolment"));
|
||||
$mform->setDefault('enrol',(isset($toform->enrol))?$toform->enrol:'');
|
||||
|
||||
$modules = explode(',', $CFG->enrol_plugins_enabled);
|
||||
foreach ($modules as $module) {
|
||||
$name = get_string("enrolname", "enrol_$module");
|
||||
$plugin = enrolment_factory::factory($module);
|
||||
if (method_exists($plugin, 'print_entry')) {
|
||||
$choices[$name] = $module;
|
||||
$roles = get_assignable_roles($context);
|
||||
if (!empty($course)) {
|
||||
// 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)) {
|
||||
$roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
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->setDefault('enrollable',(isset($toform->enrollable))?$toform->enrollable:1);
|
||||
$radio = array();
|
||||
$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);
|
||||
$mform->setDefault('enrolstartdisabled',
|
||||
(!isset($toform->enrolstartdate)||
|
||||
(isset($toform->enrolstartdate)&&!$toform->enrolstartdate)
|
||||
?1:0));
|
||||
$enroldatestartgrp = array();
|
||||
$enroldatestartgrp[] = &moodleform::createElement('date_selector', 'enrolstartdate');
|
||||
$enroldatestartgrp[] = &moodleform::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
|
||||
$mform->addGroup($enroldatestartgrp, '', get_string('enrolstartdate'), ' ', false);
|
||||
|
||||
$mform->setDefault('enrolenddate',(isset($toform->enrolenddate))?$toform->enrolenddate:0);
|
||||
$mform->setDefault('enrolenddisabled',
|
||||
(!isset($toform->enrolenddate)||
|
||||
(isset($toform->enrolenddate)&&!$toform->enrolenddate)
|
||||
?1:0));
|
||||
$enroldateendgrp = array();
|
||||
$enroldateendgrp[] = &moodleform::createElement('date_selector', 'enrolenddate');
|
||||
$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);
|
||||
$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->addElement('header','expirynotifyhdr', get_string("expirynotify"));
|
||||
|
||||
$mform->setDefault('expirynotify',(isset($toform->expirynotify))?$toform->expirynotify:0);
|
||||
unset($choices);
|
||||
$choices["0"] = get_string("no");
|
||||
$choices["1"] = get_string("yes");
|
||||
$mform->addElement('select', 'expirynotify', get_string("expirynotify"), $choices);
|
||||
$mform->setDefault('notifystudents',(isset($toform->notifystudents))?$toform->notifystudents:0);
|
||||
$mform->addElement('select', 'notifystudents', get_string("expirynotifystudents"), $choices);
|
||||
$mform->setDefault('expirythreshold',(isset($toform->expirythreshold))?$toform->expirythreshold:10 * 86400);
|
||||
$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->addElement('header','', get_string("groupmode"));
|
||||
$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;
|
||||
$mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices);
|
||||
$mform->setDefault('defaultrole', 0);
|
||||
|
||||
$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','enrolhdr', get_string('enrolments'));
|
||||
|
||||
$mform->addElement('header','', get_string("availability"));
|
||||
$choices = array();
|
||||
$modules = explode(',', $CFG->enrol_plugins_enabled);
|
||||
foreach ($modules as $module) {
|
||||
$name = get_string('enrolname', "enrol_$module");
|
||||
$plugin = enrolment_factory::factory($module);
|
||||
if (method_exists($plugin, 'print_entry')) {
|
||||
$choices[$name] = $module;
|
||||
}
|
||||
}
|
||||
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('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);
|
||||
$radio = array();
|
||||
$radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('no'), 0);
|
||||
$radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('yes'), 1);
|
||||
$radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('enroldate'), 2);
|
||||
$mform->addGroup($radio, 'enrollable', get_string('enrollable'), ' ', false);
|
||||
$mform->setHelpButton('enrollable', array('courseenrollable', get_string('enrollable')), true);
|
||||
$mform->setDefault('enrollable', 1);
|
||||
|
||||
$enroldatestartgrp = array();
|
||||
$enroldatestartgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolstartdate');
|
||||
$enroldatestartgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
|
||||
$mform->addGroup($enroldatestartgrp, 'enrolstartdategrp', get_string('enrolstartdate'), ' ', false);
|
||||
$mform->setDefault('enrolstartdate', 0);
|
||||
$mform->setDefault('enrolstartdisabled', 1);
|
||||
$mform->disabledIf('enrolstartdategrp', 'enrolstartdisabled', 'checked');
|
||||
|
||||
$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);
|
||||
$mform->disabledIf('enroldateendgrp', 'enrolenddisabled', 'checked');
|
||||
|
||||
$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('notify'), $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('groups', 'group'));
|
||||
|
||||
$choices = array();
|
||||
$choices[NOGROUPS] = get_string('no');
|
||||
$choices[SEPARATEGROUPS] = get_string('separate');
|
||||
$choices[VISIBLEGROUPS] = get_string('visible');
|
||||
$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);
|
||||
//defining a rule for a form element within a group :
|
||||
$costgrprules=array();
|
||||
//set the message to null to tell Moodle to use a default message
|
||||
//available for most rules, fetched from language pack (err_{rulename}).
|
||||
$costgrprules['cost'][]=array(null, 'numeric', null, 'client');
|
||||
$mform->addGroupRule('costgrp',$costgrprules);
|
||||
$mform->setHelpButton('costgrp', array('cost', get_string('cost')), true);
|
||||
$mform->setDefault('cost', '');
|
||||
$mform->setDefault('currency', empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
$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);
|
||||
$mods = array(0=>get_string('allownone'));
|
||||
$mods += get_records_menu('modules', '','','','id, name');
|
||||
|
||||
|
||||
$mform->addElement('select', 'allowedmods', get_string('to'), $mods,
|
||||
array('multiple'=>'multiple', 'size'=>'10'));
|
||||
$mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0);
|
||||
} 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);
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
$this->add_action_buttons();
|
||||
//--------------------------------------------------------------------------------
|
||||
$mform->addElement('hidden', 'id', null);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
// fill in default teacher and student names to keep backwards compatibility for a while
|
||||
$mform->addElement('hidden', 'teacher', get_string('defaultcourseteacher'));
|
||||
$mform->addElement('hidden', 'teachers', get_string('defaultcourseteachers'));
|
||||
$mform->addElement('hidden', 'student', get_string('defaultcoursestudent'));
|
||||
$mform->addElement('hidden', 'students', get_string('defaultcoursestudents'));
|
||||
}
|
||||
|
||||
$mform->addElement('header','', get_string("language"));
|
||||
$mform->setDefault('lang',(isset($toform->lang))?$toform->lang:'');
|
||||
$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;
|
||||
/// perform some extra moodle validation
|
||||
function validation($data){
|
||||
$errors= array();
|
||||
if ($foundcourses = get_records("course", "shortname", addslashes($fields['shortname']))) {
|
||||
if (!empty($course->id)) {
|
||||
unset($foundcourses[$course->id]);
|
||||
if ($foundcourses = get_records('course', 'shortname', $data['shortname'])) {
|
||||
if (!empty($data['id'])) {
|
||||
unset($foundcourses[$data['id']]);
|
||||
}
|
||||
if (!empty($foundcourses)) {
|
||||
foreach ($foundcourses as $foundcourse) {
|
||||
$foundcoursenames[] = $foundcourse->fullname;
|
||||
}
|
||||
$foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
|
||||
|
||||
$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");
|
||||
$foundcoursenamestring = implode(',', $foundcoursenames);
|
||||
$errors['shortname']= get_string('shortnametaken', '', $foundcoursenamestring);
|
||||
}
|
||||
}
|
||||
if (0==count($errors)){
|
||||
|
||||
if (empty($data['enrolenddisabled'])){
|
||||
if ($data['enrolenddate'] <= $data['enrolstartdate']){
|
||||
$errors['enroldateendgrp'] = get_string('enrolenddaterror');
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == count($errors)){
|
||||
return true;
|
||||
}else {
|
||||
} else {
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
$mform->addFormRule('form_check');
|
||||
|
||||
$renderer =& $mform->defaultRenderer();
|
||||
$renderer->addStopFieldsetElements('submit');
|
||||
?>
|
||||
}
|
||||
?>
|
||||
+31
-5
@@ -1,10 +1,36 @@
|
||||
<?PHP // $Id$
|
||||
// form.php - created with Moodle 1.7 beta + (2006101003)
|
||||
<?PHP // $Id$
|
||||
|
||||
|
||||
$string['denotesreq'] = '$a denotes required field.';
|
||||
$string['somefieldsrequired'] = 'There are required fields in this form';
|
||||
$string['requiredfield'] = 'This is a required field';
|
||||
$string['err_alphanumeric']='You must enter only letters or numbers here.';
|
||||
$string['err_email']='You must enter a valid email address here.';
|
||||
$string['err_lettersonly']='You must enter only letters here.';
|
||||
$string['err_maxlength']='You must enter not more than $a->format characters here.';
|
||||
$string['err_minlength']='You must enter at least $a->format characters here.';
|
||||
$string['err_nopunctuation']='You must enter no punctuation characters here.';
|
||||
$string['err_nonzero']='You must enter a number not starting with a 0 here.';
|
||||
$string['err_numeric']='You must enter a number here.';
|
||||
$string['err_rangelength']='You must enter between {$a->format[0]} and {$a->format[1]} characters here.';
|
||||
$string['err_required']='You must supply a value here.';
|
||||
$string['nomethodforaddinghelpbutton'] = 'There is no method for adding a help button to form element $a->name (class $a->classname)';
|
||||
$string['nonexistentformelements'] = 'Trying to add help buttons to nonexistent form elements : $a';
|
||||
$string['requiredelement'] = 'Required field.';
|
||||
$string['requiredelement'] = 'Required field';
|
||||
$string['general'] = 'General';
|
||||
$string['optional'] = 'Optional';
|
||||
$string['modstandardels']='Common Module Settings';
|
||||
$string['miscellaneoussettings']='Miscellaneous Settings';
|
||||
$string['addfields']='Add $a fields to form';
|
||||
$string['day']='Day';
|
||||
$string['month']='Month';
|
||||
$string['year']='Year';
|
||||
$string['hour']='Hour';
|
||||
$string['minute']='Minute';
|
||||
|
||||
$string['advancedelement']='Advanced Element';
|
||||
$string['hideadvanced']='Hide Advanced';
|
||||
$string['showadvanced']='Show Advanced';
|
||||
|
||||
$string['timing'] = 'Timing';
|
||||
$string['security'] = 'Security';
|
||||
$string['display'] = 'Display';
|
||||
?>
|
||||
|
||||
+50
-10
@@ -3,11 +3,11 @@ require_once('HTML/QuickForm/checkbox.php');
|
||||
|
||||
/**
|
||||
* HTML class for a checkbox type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_checkbox extends HTML_QuickForm_checkbox{
|
||||
class MoodleQuickForm_checkbox extends HTML_QuickForm_checkbox{
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
@@ -19,18 +19,21 @@ class moodleform_checkbox extends HTML_QuickForm_checkbox{
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
@@ -43,21 +46,58 @@ class moodleform_checkbox extends HTML_QuickForm_checkbox{
|
||||
}
|
||||
/**
|
||||
* Automatically generates and assigns an 'id' attribute for the element.
|
||||
*
|
||||
*
|
||||
* Currently used to ensure that labels work on radio buttons and
|
||||
* checkboxes. Per idea of Alexander Radivanovich.
|
||||
* Overriden in moodleforms to remove qf_ prefix.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
function _generateId()
|
||||
{
|
||||
static $idx = 1;
|
||||
|
||||
if (!$this->getAttribute('id')) {
|
||||
$this->updateAttributes(array('id' => substr(md5(microtime() . $idx++), 0, 6)));
|
||||
$this->updateAttributes(array('id' => 'id_'.substr(md5(microtime() . $idx++), 0, 6)));
|
||||
}
|
||||
} // end func _generateId
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
//fixes bug in quickforms which lets previous set value override submitted value if checkbox is not checked
|
||||
// and no value is submitted
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
// if no boxes were checked, then there is no value in the array
|
||||
// yet we don't want to display default value in this case
|
||||
if ($caller->isSubmitted()) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
} else {
|
||||
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
//fix here. setChecked should not be conditional
|
||||
$this->setChecked($value);
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
}
|
||||
?>
|
||||
+105
-47
@@ -5,25 +5,25 @@ require_once "$CFG->libdir/formslib.php";
|
||||
|
||||
/**
|
||||
* Class for a group of elements used to input a date.
|
||||
*
|
||||
* Emulates moodle print_date_selector function
|
||||
*
|
||||
*
|
||||
* Emulates moodle print_date_selector function
|
||||
*
|
||||
* @author Jamie Pratt <[email protected]>
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_date_selector extends moodleform_group
|
||||
class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
||||
{
|
||||
/**
|
||||
* Control the fieldnames for form elements
|
||||
*
|
||||
* day => string day fieldname
|
||||
* month => string month fieldname
|
||||
* year => string year fieldname
|
||||
* startyear => integer start of range of years that can be selected
|
||||
* stopyear => integer last year that can be selected
|
||||
* timezone => float/string timezone
|
||||
* applydst => apply users daylight savings adjustment?
|
||||
* optional => if true, show a checkbox beside the date to turn it on (or off)
|
||||
*/
|
||||
var $_options = array('startyear'=>1970, 'stopyear'=>2020,
|
||||
'timezone'=>99, 'applydst'=>true);
|
||||
'timezone'=>99, 'applydst'=>true, 'optional'=>false);
|
||||
|
||||
/**
|
||||
* These complement separators, they are appended to the resultant HTML
|
||||
@@ -34,14 +34,14 @@ class moodleform_date_selector extends moodleform_group
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param string Element's name
|
||||
* @param mixed Label(s) for an element
|
||||
* @param array Options to control the element's display
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
*/
|
||||
function moodleform_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
|
||||
function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
|
||||
{
|
||||
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
@@ -76,32 +76,82 @@ class moodleform_date_selector extends moodleform_group
|
||||
for ($i=$this->_options['startyear']; $i<=$this->_options['stopyear']; $i++) {
|
||||
$years[$i] = $i;
|
||||
}
|
||||
$this->_elements[] =& moodleform::createElement('select', 'day', null, $days, $this->getAttributes(), true);
|
||||
$this->_elements[] =& moodleform::createElement('select','month', null, $months, $this->getAttributes(), true);
|
||||
$this->_elements[] =& moodleform::createElement('select','year', null, $years, $this->getAttributes(), true);
|
||||
$this->_elements[] =& MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true);
|
||||
$this->_elements[] =& MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true);
|
||||
$this->_elements[] =& MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $this->getAttributes(), true);
|
||||
// If optional we add a checkbox which the user can use to turn if on
|
||||
if($this->_options['optional']) {
|
||||
$this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'off', null, get_string('disable'), $this->getAttributes(), true);
|
||||
}
|
||||
foreach ($this->_elements as $element){
|
||||
if (method_exists($element, 'setHiddenLabel')){
|
||||
$element->setHiddenLabel(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
function setValue($value)
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if (!($value)) {
|
||||
$value = time();
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
// if no boxes were checked, then there is no value in the array
|
||||
// yet we don't want to display default value in this case
|
||||
if ($caller->isSubmitted()) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
$requestvalue=$value;
|
||||
if ($value == 0) {
|
||||
$value = time();
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
$currentdate = usergetdate($value);
|
||||
$value = array(
|
||||
'day' => $currentdate['mday'],
|
||||
'month' => $currentdate['mon'],
|
||||
'year' => $currentdate['year']);
|
||||
// If optional, default to off, unless a date was provided
|
||||
if($this->_options['optional']) {
|
||||
$value['off'] = ($requestvalue == 0) ? true : false;
|
||||
}
|
||||
} else {
|
||||
$value['off'] = (isset($value['off'])) ? true : false;
|
||||
}
|
||||
if (null !== $value){
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
case 'createElement':
|
||||
if($arg[2]['optional']) {
|
||||
$caller->disabledIf($arg[0], $arg[0].'[off]', 'checked');
|
||||
}
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
break;
|
||||
default:
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
$currentdate = usergetdate($value);
|
||||
$value = array(
|
||||
'day' => $currentdate['mday'],
|
||||
'month' => $currentdate['mon'],
|
||||
'year' => $currentdate['year']);
|
||||
|
||||
}
|
||||
parent::setValue($value);
|
||||
}
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
function toHtml()
|
||||
@@ -122,16 +172,7 @@ class moodleform_date_selector extends moodleform_group
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' == $event) {
|
||||
return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Output a timestamp. Give it the name of the group.
|
||||
*
|
||||
@@ -142,16 +183,33 @@ class moodleform_date_selector extends moodleform_group
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = null;
|
||||
$valuearray = $this->_elements[0]->exportValue($submitValues[$this->getName()], true);
|
||||
$valuearray +=$this->_elements[1]->exportValue($submitValues[$this->getName()], true);
|
||||
$valuearray +=$this->_elements[2]->exportValue($submitValues[$this->getName()], true);
|
||||
$value[$this->getName()]=make_timestamp($valuearray['year'],
|
||||
$valuearray['month'],
|
||||
$valuearray['day'],
|
||||
0,0,0,
|
||||
$this->_options['timezone'],
|
||||
$this->_options['applydst']);
|
||||
return $value;
|
||||
$valuearray = array();
|
||||
foreach ($this->_elements as $element){
|
||||
$thisexport = $element->exportValue($submitValues[$this->getName()], true);
|
||||
if ($thisexport!=null){
|
||||
$valuearray += $thisexport;
|
||||
}
|
||||
}
|
||||
if (count($valuearray)){
|
||||
if($this->_options['optional']) {
|
||||
// If checkbox is on, the value is zero, so go no further
|
||||
if(!empty($valuearray['off'])) {
|
||||
$value[$this->getName()]=0;
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
$value[$this->getName()]=make_timestamp($valuearray['year'],
|
||||
$valuearray['month'],
|
||||
$valuearray['day'],
|
||||
0,0,0,
|
||||
$this->_options['timezone'],
|
||||
$this->_options['applydst']);
|
||||
|
||||
return $value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
+27
-9
@@ -3,11 +3,11 @@ require_once('HTML/QuickForm/file.php');
|
||||
|
||||
/**
|
||||
* HTML class for a form element to upload a file
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_file extends HTML_QuickForm_file{
|
||||
class MoodleQuickForm_file extends HTML_QuickForm_file{
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
@@ -19,27 +19,45 @@ class moodleform_file extends HTML_QuickForm_file{
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
* set html for help button
|
||||
*
|
||||
* @access public
|
||||
* @return string html for help button
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function getHelpButton(){
|
||||
return $this->_helpbutton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override createElement event to add max files
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ($event == 'createElement') {
|
||||
$className = get_class($this);
|
||||
$this->$className($arg[0], $arg[1].' ('.get_string('maxsize', '', display_size($caller->getMaxFileSize())).')', $arg[2]);
|
||||
return true;
|
||||
}
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
}
|
||||
?>
|
||||
+23
-10
@@ -3,14 +3,14 @@ require_once("HTML/QuickForm/group.php");
|
||||
|
||||
/**
|
||||
* HTML class for a form element group
|
||||
*
|
||||
*
|
||||
* @author Adam Daniel <[email protected]>
|
||||
* @author Bertrand Mansion <[email protected]>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_group extends HTML_QuickForm_group{
|
||||
class MoodleQuickForm_group extends HTML_QuickForm_group{
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
@@ -25,24 +25,28 @@ class moodleform_group extends HTML_QuickForm_group{
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
* set html for help button
|
||||
*
|
||||
* @access public
|
||||
* @return string html for help button
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function getHelpButton(){
|
||||
return $this->_helpbutton;
|
||||
@@ -50,4 +54,13 @@ class moodleform_group extends HTML_QuickForm_group{
|
||||
function getElementTemplateType(){
|
||||
return $this->_elementTemplateType;
|
||||
}
|
||||
}
|
||||
function setElements($elements){
|
||||
parent::setElements($elements);
|
||||
foreach ($this->_elements as $element){
|
||||
if (method_exists($element, 'setHiddenLabel')){
|
||||
$element->setHiddenLabel(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
+5
-4
@@ -3,11 +3,11 @@ require_once('HTML/QuickForm/hidden.php');
|
||||
|
||||
/**
|
||||
* HTML class for a hidden type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_hidden extends HTML_QuickForm_hidden{
|
||||
class MoodleQuickForm_hidden extends HTML_QuickForm_hidden{
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
@@ -19,9 +19,10 @@ class moodleform_hidden extends HTML_QuickForm_hidden{
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
|
||||
+32
-9
@@ -4,17 +4,17 @@ require_once("$CFG->libdir/form/textarea.php");
|
||||
|
||||
/**
|
||||
* HTML class for htmleditor type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_htmleditor extends moodleform_textarea{
|
||||
class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
|
||||
var $_type;
|
||||
var $_elementTemplateType='default';
|
||||
var $_canUseHtmlEditor;
|
||||
var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>65, 'width'=>0,'height'=>0, 'course'=>0);
|
||||
function moodleform_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
|
||||
parent::moodleform_textarea($elementName, $elementLabel, $attributes);
|
||||
var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0, 'course'=>0);
|
||||
function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
|
||||
parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
|
||||
// set the options, do not bother setting bogus ones
|
||||
if (is_array($options)) {
|
||||
foreach ($options as $name => $value) {
|
||||
@@ -36,14 +36,36 @@ class moodleform_htmleditor extends moodleform_textarea{
|
||||
}else{
|
||||
$this->_type='textarea';
|
||||
}
|
||||
$this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
|
||||
}
|
||||
/**
|
||||
* set html for help button
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!$this->_canUseHtmlEditor){
|
||||
if ('editorhelpbutton' == $function){
|
||||
$key = array_search('richtext', $helpbuttonargs);
|
||||
if ($key !== FALSE){
|
||||
array_splice($helpbuttonargs, $key, 1, array('text', 'emoticons'));
|
||||
}
|
||||
} elseif ('helpbutton' == $function && $helpbuttonargs[0] == 'richtext' && ((!isset($helpbuttonargs[2])) || $helpbuttonargs[2] == 'moodle')){
|
||||
//replace single 'richtext' help button with text and emoticon button when htmleditor off.
|
||||
return $this->setHelpButton(array('text', 'emoticons'), 'editorhelpbutton');
|
||||
}
|
||||
}
|
||||
return parent::setHelpButton($helpbuttonargs, $function);
|
||||
}
|
||||
function getElementTemplateType(){
|
||||
return $this->_elementTemplateType;
|
||||
}
|
||||
function toHtml(){
|
||||
if ($this->_options['canUseHtmlEditor'] && !$this->_flagFrozen){
|
||||
if ($this->_canUseHtmlEditor && !$this->_flagFrozen){
|
||||
ob_start();
|
||||
use_html_editor($this->getName());
|
||||
use_html_editor($this->getName(), '', $this->getAttribute('id'));
|
||||
$script=ob_get_clean();
|
||||
} else {
|
||||
$script='';
|
||||
@@ -52,7 +74,7 @@ class moodleform_htmleditor extends moodleform_textarea{
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() .
|
||||
print_textarea($this->_options['canUseHtmlEditor'],
|
||||
print_textarea($this->_canUseHtmlEditor,
|
||||
$this->_options['rows'],
|
||||
$this->_options['cols'],
|
||||
$this->_options['width'],
|
||||
@@ -60,7 +82,8 @@ class moodleform_htmleditor extends moodleform_textarea{
|
||||
$this->getName(),
|
||||
preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()),
|
||||
$this->_options['course'],
|
||||
true).$script;
|
||||
true,
|
||||
$this->getAttribute('id')).$script;
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
|
||||
+10
-7
@@ -3,11 +3,11 @@ require_once('HTML/QuickForm/password.php');
|
||||
|
||||
/**
|
||||
* HTML class for a password type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_password extends HTML_QuickForm_password{
|
||||
class MoodleQuickForm_password extends HTML_QuickForm_password{
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
@@ -19,18 +19,21 @@ class moodleform_password extends HTML_QuickForm_password{
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
|
||||
+13
-10
@@ -3,11 +3,11 @@ require_once('HTML/QuickForm/radio.php');
|
||||
|
||||
/**
|
||||
* HTML class for a radio type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_radio extends HTML_QuickForm_radio{
|
||||
class MoodleQuickForm_radio extends HTML_QuickForm_radio{
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
@@ -19,18 +19,21 @@ class moodleform_radio extends HTML_QuickForm_radio{
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
@@ -43,20 +46,20 @@ class moodleform_radio extends HTML_QuickForm_radio{
|
||||
}
|
||||
/**
|
||||
* Automatically generates and assigns an 'id' attribute for the element.
|
||||
*
|
||||
*
|
||||
* Currently used to ensure that labels work on radio buttons and
|
||||
* checkboxes. Per idea of Alexander Radivanovich.
|
||||
* Overriden in moodleforms to remove qf_ prefix.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
function _generateId()
|
||||
{
|
||||
static $idx = 1;
|
||||
|
||||
if (!$this->getAttribute('id')) {
|
||||
$this->updateAttributes(array('id' => substr(md5(microtime() . $idx++), 0, 6)));
|
||||
$this->updateAttributes(array('id' => 'id_'.substr(md5(microtime() . $idx++), 0, 6)));
|
||||
}
|
||||
} // end func _generateId
|
||||
}
|
||||
|
||||
+88
-7
@@ -3,34 +3,68 @@ require_once('HTML/QuickForm/select.php');
|
||||
|
||||
/**
|
||||
* HTML class for a select type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_select extends HTML_QuickForm_select{
|
||||
class MoodleQuickForm_select extends HTML_QuickForm_select{
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_helpbutton='';
|
||||
var $_hiddenLabel=false;
|
||||
function setHiddenLabel($hiddenLabel){
|
||||
$this->_hiddenLabel = $hiddenLabel;
|
||||
}
|
||||
function toHtml(){
|
||||
if ($this->_hiddenLabel){
|
||||
$this->_generateId();
|
||||
return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
|
||||
$this->getLabel().'</label>'.parent::toHtml();
|
||||
} else {
|
||||
return parent::toHtml();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Automatically generates and assigns an 'id' attribute for the element.
|
||||
*
|
||||
* Currently used to ensure that labels work on radio buttons and
|
||||
* checkboxes. Per idea of Alexander Radivanovich.
|
||||
* Overriden in moodleforms to remove qf_ prefix.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _generateId()
|
||||
{
|
||||
static $idx = 1;
|
||||
|
||||
if (!$this->getAttribute('id')) {
|
||||
$this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
|
||||
}
|
||||
} // end func _generateId
|
||||
/**
|
||||
* set html for help button
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
@@ -41,5 +75,52 @@ class moodleform_select extends HTML_QuickForm_select{
|
||||
function getHelpButton(){
|
||||
return $this->_helpbutton;
|
||||
}
|
||||
/**
|
||||
* Removes an OPTION from the SELECT
|
||||
*
|
||||
* @param string $value Value for the OPTION to remove
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function removeOption($value)
|
||||
{
|
||||
$key=array_search($value, $this->_values);
|
||||
if ($key!==FALSE || $key!==null) {
|
||||
unset($this->_values[$key]);
|
||||
}
|
||||
foreach ($this->_options as $key=>$option){
|
||||
if ($option['attr']['value']==$value){
|
||||
unset($this->_options[$key]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // end func removeOption
|
||||
/**
|
||||
* Removes all OPTIONs from the SELECT
|
||||
*
|
||||
* @param string $value Value for the OPTION to remove
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function removeOptions()
|
||||
{
|
||||
$this->_options = array();
|
||||
} // end func removeOption
|
||||
/**
|
||||
* Slightly different container template when frozen. Don't want to use a label tag
|
||||
* with a for attribute in that case for the element label but instead use a div.
|
||||
* Templates are defined in renderer constructor.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getElementTemplateType(){
|
||||
if ($this->_flagFrozen){
|
||||
return 'static';
|
||||
} else {
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
+15
-7
@@ -3,11 +3,12 @@ require_once("HTML/QuickForm/static.php");
|
||||
|
||||
/**
|
||||
* HTML class for a text type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_static extends HTML_QuickForm_static{
|
||||
class MoodleQuickForm_static extends HTML_QuickForm_static{
|
||||
var $_elementTemplateType='static';
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
@@ -19,18 +20,21 @@ class moodleform_static extends HTML_QuickForm_static{
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
@@ -41,5 +45,9 @@ class moodleform_static extends HTML_QuickForm_static{
|
||||
function getHelpButton(){
|
||||
return $this->_helpbutton;
|
||||
}
|
||||
|
||||
function getElementTemplateType(){
|
||||
return $this->_elementTemplateType;
|
||||
}
|
||||
}
|
||||
?>
|
||||
+55
-7
@@ -3,34 +3,68 @@ require_once("HTML/QuickForm/text.php");
|
||||
|
||||
/**
|
||||
* HTML class for a text type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_text extends HTML_QuickForm_text{
|
||||
class MoodleQuickForm_text extends HTML_QuickForm_text{
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_helpbutton='';
|
||||
var $_hiddenLabel=false;
|
||||
function setHiddenLabel($hiddenLabel){
|
||||
$this->_hiddenLabel = $hiddenLabel;
|
||||
}
|
||||
function toHtml(){
|
||||
if ($this->_hiddenLabel){
|
||||
$this->_generateId();
|
||||
return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
|
||||
$this->getLabel().'</label>'.parent::toHtml();
|
||||
} else {
|
||||
return parent::toHtml();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Automatically generates and assigns an 'id' attribute for the element.
|
||||
*
|
||||
* Currently used to ensure that labels work on radio buttons and
|
||||
* checkboxes. Per idea of Alexander Radivanovich.
|
||||
* Overriden in moodleforms to remove qf_ prefix.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _generateId()
|
||||
{
|
||||
static $idx = 1;
|
||||
|
||||
if (!$this->getAttribute('id')) {
|
||||
$this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
|
||||
}
|
||||
} // end func _generateId
|
||||
/**
|
||||
* set html for help button
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
@@ -41,4 +75,18 @@ class moodleform_text extends HTML_QuickForm_text{
|
||||
function getHelpButton(){
|
||||
return $this->_helpbutton;
|
||||
}
|
||||
/**
|
||||
* Slightly different container template when frozen. Don't want to use a label tag
|
||||
* with a for attribute in that case for the element label but instead use a div.
|
||||
* Templates are defined in renderer constructor.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getElementTemplateType(){
|
||||
if ($this->_flagFrozen){
|
||||
return 'static';
|
||||
} else {
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
-7
@@ -3,11 +3,17 @@ require_once('HTML/QuickForm/textarea.php');
|
||||
|
||||
/**
|
||||
* HTML class for a textarea type element
|
||||
*
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class moodleform_textarea extends HTML_QuickForm_textarea{
|
||||
class MoodleQuickForm_textarea extends HTML_QuickForm_textarea{
|
||||
/**
|
||||
* Need to store id of form as we may need it for helpbutton
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_formid = '';
|
||||
/**
|
||||
* html for help button, if empty then no help
|
||||
*
|
||||
@@ -19,18 +25,27 @@ class moodleform_textarea extends HTML_QuickForm_textarea{
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs){
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
global $SESSION;
|
||||
if (!is_array($helpbuttonargs)){
|
||||
$helpbuttonargs=array($helpbuttonargs);
|
||||
}else{
|
||||
$helpbuttonargs=$helpbuttonargs;
|
||||
}
|
||||
//we do this to to return html instead of printing it
|
||||
//we do this to to return html instead of printing it
|
||||
//without having to specify it in every call to make a button.
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
$this->_helpbutton=call_user_func_array('helpbutton', $helpbuttonargs);
|
||||
if ('helpbutton' == $function){
|
||||
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
||||
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
||||
} elseif ('editorhelpbutton' == $function){
|
||||
if (in_array('emoticons', $helpbuttonargs)){
|
||||
$SESSION->inserttextform = $this->_formid;
|
||||
$SESSION->inserttextfield = $this->getAttribute('name');
|
||||
}
|
||||
}
|
||||
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
||||
}
|
||||
/**
|
||||
* get html for help button
|
||||
@@ -41,5 +56,24 @@ class moodleform_textarea extends HTML_QuickForm_textarea{
|
||||
function getHelpButton(){
|
||||
return $this->_helpbutton;
|
||||
}
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'createElement':
|
||||
$this->_formid = $caller->getAttribute('id');
|
||||
break;
|
||||
}
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
} // end func onQuickFormEvent
|
||||
}
|
||||
?>
|
||||
+1476
-263
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user