/** * Form definition. */ public function definition() { global $PAGE; $mform = $this->_form; $roles = get_roles_for_contextlevels(CONTEXT_USER); if (empty($roles)) { $output = $PAGE->get_renderer('tool_cohortroles'); $warning = $output->notify_problem(get_string('noassignableroles', 'tool_cohortroles')); $mform->addElement('html', $warning); return; } $options = array('ajax' => 'tool_lp/form-user-selector', 'multiple' => true); $mform->addElement('autocomplete', 'userids', get_string('selectusers', 'tool_cohortroles'), array(), $options); $mform->addRule('userids', null, 'required'); $names = role_get_names(); $options = array(); foreach ($roles as $idx => $roleid) { $options[$roleid] = $names[$roleid]->localname; } $mform->addElement('select', 'roleid', get_string('selectrole', 'tool_cohortroles'), $options); $mform->addRule('roleid', null, 'required'); $context = context_system::instance(); $options = array('ajax' => 'tool_lp/form-cohort-selector', 'multiple' => true, 'data-contextid' => $context->id, 'data-includes' => 'all'); $mform->addElement('autocomplete', 'cohortids', get_string('selectcohorts', 'tool_cohortroles'), array(), $options); $mform->addRule('cohortids', null, 'required'); $mform->addElement('submit', 'submit', get_string('assign', 'tool_cohortroles')); }
/** * Tests constructing and using condition. */ public function test_usage() { global $CFG, $USER, $DB; $this->resetAfterTest(); $CFG->enableavailability = true; // Make a test course and user. $generator = $this->getDataGenerator(); $course = $generator->create_course(); $teacher = $generator->create_user(); $student = $generator->create_user(); $roleswithnames = array(); $contextroleids = get_roles_for_contextlevels(CONTEXT_COURSE); $roles = $DB->get_records_list('role', 'id', $contextroleids, '', 'shortname, id'); $generator->enrol_user($student->id, $course->id, $roles['student']->id); $generator->enrol_user($teacher->id, $course->id, $roles['editingteacher']->id); $studentinfo = new \core_availability\mock_info($course, $student->id); $teacherinfo = new \core_availability\mock_info($course, $teacher->id); // Do test (not in grouping). $structure = (object) array('type' => 'role', 'id' => (int) $roles['editingteacher']->id); $cond = new condition($structure); // Check if available (when not available). $this->assertFalse($cond->is_available(false, $studentinfo, true, $student->id)); $this->assertTrue($cond->is_available(false, $teacherinfo, true, $teacher->id)); $information = $cond->get_description(false, false, $studentinfo); }
protected function get_course_roles($context) { global $DB; $roleswithnames = array(); $contextroleids = get_roles_for_contextlevels(CONTEXT_COURSE); $contextroles = $DB->get_records_list('role', 'id', $contextroleids); foreach ($contextroles as $id => $role) { $roleswithnames[$id] = role_get_name($role, $context); } return $roleswithnames; }
public function definition() { $mform =& $this->_form; $category = $this->_customdata['category']; $mform->addElement('header', 'rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); if ($roles = get_all_roles()) { $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL); $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSECAT); foreach ($roles as $role) { $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->localname)); $mform->setType('role_' . $role->id, PARAM_TEXT); if (!in_array($role->id, $assignableroles)) { $mform->setAdvanced('role_' . $role->id); } } } $mform->addElement('hidden', 'id', $category->id); $mform->setType('id', PARAM_INT); $mform->addElement('html', get_string('roleedit_notice', 'local_contextadmin')); $this->add_action_buttons(true, get_string('savechanges')); }
function definition() { global $USER, $CFG, $DB; $courseconfig = get_config('moodlecourse'); $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 ($DB->count_records('course_meta', array('parent_course' => $course->id)) > 0) { $disable_meta = get_string('metaalreadyhascourses'); } } else { // if users already enrolled directly into coures, do not allow switching to meta, // users with metacourse manage permission are exception // please note that we do not need exact results - anything unexpected here prevents metacourse $managers = get_users_by_capability($coursecontext, 'moodle/course:managemetacourse', 'u.id'); $enrolroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $coursecontext); if ($users = get_role_users(array_keys($enrolroles), $coursecontext, false, 'u.id', 'u.id ASC')) { foreach ($users as $user) { if (!isset($managers[$user->id])) { $disable_meta = get_string('metaalreadyhasenrolments'); break; } } } unset($managers); unset($users); unset($enrolroles); } } } else { $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, 'moodle/course:create'); $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); $fullname = get_string('defaultcoursefullname'); $shortname = get_string('defaultcourseshortname'); while ($DB->record_exists('course', array('fullname' => $fullname)) or $DB->record_exists('course', array('fullname' => $fullname))) { $fullname++; $shortname++; } $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"'); $mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_MULTILANG); if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); $mform->setConstant('fullname', $course->fullname); } $mform->setDefault('fullname', $fullname); $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); $mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_MULTILANG); if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); $mform->setConstant('shortname', $course->shortname); } $mform->setDefault('shortname', $shortname); $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); if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); $mform->setConstants('idnumber', $course->idnumber); } $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows' => '10', 'cols' => '65')); $mform->setHelpButton('summary', array('text2', get_string('helptext')), true); $mform->setType('summary', PARAM_RAW); $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', $courseconfig->format); for ($i = 1; $i <= 52; $i++) { $sectionmenu[$i] = "{$i}"; } $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu); $mform->setDefault('numsections', $courseconfig->numsections); $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', $courseconfig->hiddensections); $options = range(0, 10); $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); $mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true); $mform->setDefault('newsitems', $courseconfig->newsitems); $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); $mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true); $mform->setDefault('showgrades', $courseconfig->showgrades); $mform->addElement('selectyesno', 'showreports', get_string('showreports')); $mform->setHelpButton('showreports', array('coursereports', get_string('activityreport')), true); $mform->setDefault('showreports', $courseconfig->showreports); $choices = get_max_upload_sizes($CFG->maxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->setHelpButton('maxbytes', array('courseuploadsize', get_string('maximumupload')), true); $mform->setDefault('maxbytes', $courseconfig->maxbytes); if (!empty($CFG->allowcoursethemes)) { $themes = array(); $themes[''] = get_string('forceno'); $themes += get_list_of_themes(); $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); } $meta = array(); $meta[0] = get_string('no'); $meta[1] = get_string('yes'); if ($disable_meta === false) { $mform->addElement('select', 'metacourse', get_string('managemeta'), $meta); $mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true); $mform->setDefault('metacourse', $courseconfig->metacourse); } else { // 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('enrolments')); $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('enrol', $courseconfig->enrol); $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 = $DB->get_record('role', array('id' => $course->defaultrole))) { $roles[$current_role->id] = strip_tags(format_string($current_role->name, true)); } } $choices = array(); if ($sitedefaultrole = $DB->get_record('role', array('id' => $CFG->defaultcourseroleid))) { $choices[0] = get_string('sitedefault') . ' (' . $sitedefaultrole->name . ')'; } else { $choices[0] = get_string('sitedefault'); } $choices = $choices + $roles; // fix for MDL-9197 foreach ($choices as $choiceid => $choice) { $choices[$choiceid] = format_string($choice); } $mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices); $mform->setDefault('defaultrole', 0); $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('courseenrollable2', get_string('enrollable')), true); $mform->setDefault('enrollable', $courseconfig->enrollable); $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate'), array('optional' => true)); $mform->setDefault('enrolstartdate', 0); $mform->disabledIf('enrolstartdate', 'enrollable', 'neq', 2); $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate'), array('optional' => true)); $mform->setDefault('enrolenddate', 0); $mform->disabledIf('enrolenddate', 'enrollable', 'neq', 2); $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod'), array('optional' => true, 'defaultunit' => 86400)); $mform->setDefault('enrolperiod', $courseconfig->enrolperiod); //-------------------------------------------------------------------------------- $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', $courseconfig->expirynotify); $mform->addElement('select', 'notifystudents', get_string('expirynotifystudents'), $choices); $mform->setHelpButton('notifystudents', array('expirynotifystudents', get_string('expirynotifystudents')), true); $mform->setDefault('notifystudents', $courseconfig->notifystudents); $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', $courseconfig->expirythreshold); //-------------------------------------------------------------------------------- $mform->addElement('header', '', get_string('groups', 'group')); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'groupmode', get_string('groupmode'), $choices); $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')), true); $mform->setDefault('groupmode', $courseconfig->groupmode); $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', $courseconfig->groupmodeforce); if (!empty($CFG->enablegroupings)) { //default groupings selector $options = array(); $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); } //-------------------------------------------------------------------------------- $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', $courseconfig->visible); if ($course and !has_capability('moodle/course:visibility', $coursecontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $course->visible); } $mform->addElement('passwordunmask', 'enrolpassword', get_string('enrolmentkey'), 'size="25"'); $mform->setHelpButton('enrolpassword', array('enrolmentkey', get_string('enrolmentkey')), true); $mform->setDefault('enrolpassword', ''); $mform->setDefault('enrolpassword', $courseconfig->enrolpassword); $mform->setType('enrolpassword', PARAM_RAW); if (empty($course) or $course->password !== '' and $course->id != SITEID) { // do not require password in existing courses that do not have password yet - backwards compatibility ;-) if (!empty($CFG->enrol_manual_requirekey)) { $mform->addRule('enrolpassword', get_string('required'), 'required', null, 'client'); } } $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', $courseconfig->guest); // If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here $enrol_object = $CFG; if (!empty($course)) { $enrol_object = $course; } // If the print_entry method exists and the course enrol method isn't manual (both set or inherited from site), show cost if (method_exists(enrolment_factory::factory($enrol_object->enrol), 'print_entry') && !($enrol_object->enrol == 'manual' || empty($enrol_object->enrol) && $CFG->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); $mform->setDefault('lang', $courseconfig->lang); //-------------------------------------------------------------------------------- require_once $CFG->libdir . '/completionlib.php'; if (completion_info::is_enabled_for_site()) { $mform->addElement('header', '', get_string('progress', 'completion')); $mform->addElement('select', 'enablecompletion', get_string('completion', 'completion'), array(0 => get_string('completiondisabled', 'completion'), 1 => get_string('completionenabled', 'completion'))); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setDefault('enablecompletion', 0); } //-------------------------------------------------------------------------------- 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 += $DB->get_records_menu('modules', array(), 'name', '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); /// customizable role names in this course //-------------------------------------------------------------------------------- $mform->addElement('header', 'rolerenaming', get_string('rolerenaming')); $mform->setHelpButton('rolerenaming', array('rolerenaming', get_string('rolerenaming')), true); if ($roles = get_all_roles()) { if ($coursecontext) { $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS_RAW); } $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE); foreach ($roles as $role) { $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->name)); if (isset($role->localname)) { $mform->setDefault('role_' . $role->id, $role->localname); } $mform->setType('role_' . $role->id, PARAM_TEXT); if (!in_array($role->id, $assignableroles)) { $mform->setAdvanced('role_' . $role->id); } } } //-------------------------------------------------------------------------------- $this->add_action_buttons(); //-------------------------------------------------------------------------------- $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); }
function definition() { global $USER, $CFG, $DB, $PAGE; $mform = $this->_form; $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id')))); $course = $this->_customdata['course']; // this contains the data of this form $category = $this->_customdata['category']; $editoroptions = $this->_customdata['editoroptions']; $returnto = $this->_customdata['returnto']; $systemcontext = context_system::instance(); $categorycontext = context_coursecat::instance($category->id); if (!empty($course->id)) { $coursecontext = context_course::instance($course->id); $context = $coursecontext; } else { $coursecontext = null; $context = $categorycontext; } $courseconfig = get_config('moodlecourse'); $this->course = $course; $this->context = $context; /// form definition with new course defaults //-------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('hidden', 'returnto', null); $mform->setType('returnto', PARAM_ALPHANUM); $mform->setConstant('returnto', $returnto); $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); $mform->setConstant('fullname', $course->fullname); } $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); $mform->addHelpButton('shortname', 'shortnamecourse'); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); $mform->setConstant('shortname', $course->shortname); } // Verify permissions to change course category or keep current. if (empty($course->id)) { if (has_capability('moodle/course:create', $categorycontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist); $mform->addHelpButton('category', 'coursecategory'); $mform->setDefault('category', $category->id); } else { $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $category->id); } } else { if (has_capability('moodle/course:changecategory', $coursecontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); if (!isset($displaylist[$course->category])) { //always keep current $displaylist[$course->category] = coursecat::get($course->category)->get_formatted_name(); } $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist); $mform->addHelpButton('category', 'coursecategory'); } else { //keep current $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $course->category); } } $choices = array(); $choices['0'] = get_string('hide'); $choices['1'] = get_string('show'); $mform->addElement('select', 'visible', get_string('visible'), $choices); $mform->addHelpButton('visible', 'visible'); $mform->setDefault('visible', $courseconfig->visible); if (!has_capability('moodle/course:visibility', $context)) { $mform->hardFreeze('visible'); if (!empty($course->id)) { $mform->setConstant('visible', $course->visible); } else { $mform->setConstant('visible', $courseconfig->visible); } } $mform->addElement('date_selector', 'startdate', get_string('startdate')); $mform->addHelpButton('startdate', 'startdate'); $mform->setDefault('startdate', time() + 3600 * 24); $mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbercourse'); $mform->setType('idnumber', PARAM_RAW); if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); $mform->setConstants('idnumber', $course->idnumber); } // Description. $mform->addElement('header', 'descriptionhdr', get_string('description')); $mform->setExpanded('descriptionhdr'); $mform->addElement('editor', 'summary_editor', get_string('coursesummary'), null, $editoroptions); $mform->addHelpButton('summary_editor', 'coursesummary'); $mform->setType('summary_editor', PARAM_RAW); $summaryfields = 'summary_editor'; if ($overviewfilesoptions = course_overviewfiles_options($course)) { $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions); $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles'); $summaryfields .= ',overviewfiles_filemanager'; } if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) { // Remove the description header it does not contain anything any more. $mform->removeElement('descriptionhdr'); $mform->hardFreeze($summaryfields); } // Course format. $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin')); $courseformats = get_sorted_course_formats(true); $formcourseformats = array(); foreach ($courseformats as $courseformat) { $formcourseformats[$courseformat] = get_string('pluginname', "format_{$courseformat}"); } if (isset($course->format)) { $course->format = course_get_format($course)->get_format(); // replace with default if not found if (!in_array($course->format, $courseformats)) { // this format is disabled. Still display it in the dropdown $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_' . $course->format)); } } $mform->addElement('select', 'format', get_string('format'), $formcourseformats); $mform->addHelpButton('format', 'format'); $mform->setDefault('format', $courseconfig->format); // Button to update format-specific options on format change (will be hidden by JavaScript). $mform->registerNoSubmitButton('updatecourseformat'); $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate')); // Just a placeholder for the course format options. $mform->addElement('hidden', 'addcourseformatoptionshere'); $mform->setType('addcourseformatoptionshere', PARAM_BOOL); // Appearance. $mform->addElement('header', 'appearancehdr', get_string('appearance')); if (!empty($CFG->allowcoursethemes)) { $themeobjects = get_list_of_themes(); $themes = array(); $themes[''] = get_string('forceno'); foreach ($themeobjects as $key => $theme) { if (empty($theme->hidefromselector)) { $themes[$key] = get_string('pluginname', 'theme_' . $theme->name); } } $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); } $languages = array(); $languages[''] = get_string('forceno'); $languages += get_string_manager()->get_list_of_translations(); $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages); $mform->setDefault('lang', $courseconfig->lang); $options = range(0, 10); $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); $mform->addHelpButton('newsitems', 'newsitemsnumber'); $mform->setDefault('newsitems', $courseconfig->newsitems); $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); $mform->addHelpButton('showgrades', 'showgrades'); $mform->setDefault('showgrades', $courseconfig->showgrades); $mform->addElement('selectyesno', 'showreports', get_string('showreports')); $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); // Files and uploads. $mform->addElement('header', 'filehdr', get_string('filesanduploads')); if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) { if (empty($course->legacyfiles)) { //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet $choices = array('0' => get_string('no'), '2' => get_string('yes')); } else { $choices = array('1' => get_string('no'), '2' => get_string('yes')); } $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices); $mform->addHelpButton('legacyfiles', 'courselegacyfiles'); if (!isset($courseconfig->legacyfiles)) { // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses $courseconfig->legacyfiles = 0; } $mform->setDefault('legacyfiles', $courseconfig->legacyfiles); } // Handle non-existing $course->maxbytes on course creation. $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes; // Let's prepare the maxbytes popup. $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); // Completion tracking. if (completion_info::is_enabled_for_site()) { $mform->addElement('header', 'completionhdr', get_string('completion', 'completion')); $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion')); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion'); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setType('enablecompletion', PARAM_INT); $mform->setDefault('enablecompletion', 0); } //-------------------------------------------------------------------------------- enrol_course_edit_form($mform, $course, $context); //-------------------------------------------------------------------------------- $mform->addElement('header', 'groups', get_string('groups', 'group')); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices); $mform->addHelpButton('groupmode', 'groupmode', 'group'); $mform->setDefault('groupmode', $courseconfig->groupmode); $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group')); $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group'); $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce); //default groupings selector $options = array(); $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); //-------------------------------------------------------------------------------- /// customizable role names in this course //-------------------------------------------------------------------------------- $mform->addElement('header', 'rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); if ($roles = get_all_roles()) { $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL); $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE); foreach ($roles as $role) { $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->localname)); $mform->setType('role_' . $role->id, PARAM_TEXT); } } //-------------------------------------------------------------------------------- $this->add_action_buttons(); //-------------------------------------------------------------------------------- $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); /// finally set the current form data //-------------------------------------------------------------------------------- $this->set_data($course); }
/** * Test getting of role context levels */ public function test_get_roles_for_contextlevels() { global $DB; $allroles = get_all_roles(); foreach (context_helper::get_all_levels() as $level => $unused) { $roles = get_roles_for_contextlevels($level); foreach ($allroles as $roleid => $unused) { $exists = $DB->record_exists('role_context_levels', array('contextlevel' => $level, 'roleid' => $roleid)); if (in_array($roleid, $roles)) { $this->assertTrue($exists); } else { $this->assertFalse($exists); } } } }
function definition() { global $USER, $CFG, $DB; $mform = $this->_form; $course = $this->_customdata['course']; // this contains the data of this form $category = $this->_customdata['category']; $editoroptions = $this->_customdata['editoroptions']; $returnto = $this->_customdata['returnto']; $systemcontext = get_context_instance(CONTEXT_SYSTEM); $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id); if (!empty($course->id)) { $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $context = $coursecontext; } else { $coursecontext = null; $context = $categorycontext; } $courseconfig = get_config('moodlecourse'); $this->course = $course; $this->context = $context; /// form definition with new course defaults //-------------------------------------------------------------------------------- $mform->addElement('header','general', get_string('general', 'form')); $mform->addElement('hidden', 'returnto', null); $mform->setType('returnto', PARAM_ALPHANUM); $mform->setConstant('returnto', $returnto); // verify permissions to change course category or keep current if (empty($course->id)) { if (has_capability('moodle/course:create', $categorycontext)) { $displaylist = array(); $parentlist = array(); make_categories_list($displaylist, $parentlist, 'moodle/course:create'); $mform->addElement('select', 'category', get_string('category'), $displaylist); $mform->addHelpButton('category', 'category'); $mform->setDefault('category', $category->id); } else { $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $category->id); } } else { if (has_capability('moodle/course:changecategory', $coursecontext)) { $displaylist = array(); $parentlist = array(); make_categories_list($displaylist, $parentlist, 'moodle/course:create'); if (!isset($displaylist[$course->category])) { //always keep current $displaylist[$course->category] = format_string($DB->get_field('course_categories', 'name', array('id'=>$course->category))); } $mform->addElement('select', 'category', get_string('category'), $displaylist); $mform->addHelpButton('category', 'category'); } else { //keep current $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $course->category); } } $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_MULTILANG); if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); $mform->setConstant('fullname', $course->fullname); } $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); $mform->addHelpButton('shortname', 'shortnamecourse'); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_MULTILANG); if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); $mform->setConstant('shortname', $course->shortname); } $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbercourse'); $mform->setType('idnumber', PARAM_RAW); if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); $mform->setConstants('idnumber', $course->idnumber); } $mform->addElement('editor','summary_editor', get_string('coursesummary'), null, $editoroptions); $mform->addHelpButton('summary_editor', 'coursesummary'); $mform->setType('summary_editor', PARAM_RAW); if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) { $mform->hardFreeze('summary_editor'); } $courseformats = get_plugin_list('format'); $formcourseformats = array(); foreach ($courseformats as $courseformat => $formatdir) { $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat"); } $mform->addElement('select', 'format', get_string('format'), $formcourseformats); $mform->addHelpButton('format', 'format'); $mform->setDefault('format', $courseconfig->format); for ($i=1; $i<=52; $i++) { $sectionmenu[$i] = "$i"; } $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu); $mform->setDefault('numsections', $courseconfig->numsections); $mform->addElement('date_selector', 'startdate', get_string('startdate')); $mform->addHelpButton('startdate', 'startdate'); $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->addHelpButton('hiddensections', 'hiddensections'); $mform->setDefault('hiddensections', $courseconfig->hiddensections); $options = range(0, 10); $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); $mform->addHelpButton('newsitems', 'newsitemsnumber'); $mform->setDefault('newsitems', $courseconfig->newsitems); $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); $mform->addHelpButton('showgrades', 'showgrades'); $mform->setDefault('showgrades', $courseconfig->showgrades); $mform->addElement('selectyesno', 'showreports', get_string('showreports')); $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); $choices = get_max_upload_sizes($CFG->maxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) { if (empty($course->legacyfiles)) { //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet $choices = array('0'=>get_string('no'), '2'=>get_string('yes')); } else { $choices = array('1'=>get_string('no'), '2'=>get_string('yes')); } $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices); $mform->addHelpButton('legacyfiles', 'courselegacyfiles'); if (!isset($courseconfig->legacyfiles)) { // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses $courseconfig->legacyfiles = 0; } $mform->setDefault('legacyfiles', $courseconfig->legacyfiles); } if (!empty($CFG->allowcoursethemes)) { $themeobjects = get_list_of_themes(); $themes=array(); $themes[''] = get_string('forceno'); foreach ($themeobjects as $key=>$theme) { $themes[$key] = $theme->name; } $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); } //-------------------------------------------------------------------------------- enrol_course_edit_form($mform, $course, $context); //-------------------------------------------------------------------------------- $mform->addElement('header','', get_string('groups', 'group')); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices); $mform->addHelpButton('groupmode', 'groupmode', 'group'); $mform->setDefault('groupmode', $courseconfig->groupmode); $choices = array(); $choices['0'] = get_string('no'); $choices['1'] = get_string('yes'); $mform->addElement('select', 'groupmodeforce', get_string('groupmodeforce', 'group'), $choices); $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group'); $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce); //default groupings selector $options = array(); $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); //-------------------------------------------------------------------------------- $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->addHelpButton('visible', 'availability'); $mform->setDefault('visible', $courseconfig->visible); if (!has_capability('moodle/course:visibility', $context)) { $mform->hardFreeze('visible'); if (!empty($course->id)) { $mform->setConstant('visible', $course->visible); } else { $mform->setConstant('visible', $category->visible); } } //-------------------------------------------------------------------------------- $mform->addElement('header','', get_string('language')); $languages=array(); $languages[''] = get_string('forceno'); $languages += get_string_manager()->get_list_of_translations(); $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages); $mform->setDefault('lang', $courseconfig->lang); //-------------------------------------------------------------------------------- if (completion_info::is_enabled_for_site()) { $mform->addElement('header','', get_string('progress','completion')); $mform->addElement('select', 'enablecompletion', get_string('completion','completion'), array(0=>get_string('completiondisabled','completion'), 1=>get_string('completionenabled','completion'))); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); $mform->addElement('checkbox', 'completionstartonenrol', get_string('completionstartonenrol', 'completion')); $mform->setDefault('completionstartonenrol', $courseconfig->completionstartonenrol); $mform->disabledIf('completionstartonenrol', 'enablecompletion', 'eq', 0); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setType('enablecompletion', PARAM_INT); $mform->setDefault('enablecompletion',0); $mform->addElement('hidden', 'completionstartonenrol'); $mform->setType('completionstartonenrol', PARAM_INT); $mform->setDefault('completionstartonenrol',0); } //-------------------------------------------------------------------------------- if (has_capability('moodle/site:config', $systemcontext)) { if (((!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); if (!empty($CFG->restrictbydefault)) { $mform->setDefault('restrictmodules', 1); } $mods = array(0=>get_string('allownone')); $mods += $DB->get_records_menu('modules', array('visible'=>1), 'name', 'id, name'); $mform->addElement('select', 'allowedmods', get_string('to'), $mods, array('multiple'=>'multiple', 'size'=>'10')); $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0); // defaults are already in $course } else { // remove any mod restriction $mform->addElement('hidden', 'restrictmodules', 0); $mform->setType('restrictmodules', PARAM_INT); } } else { $mform->addElement('hidden', 'restrictmodules'); $mform->setType('restrictmodules', PARAM_INT); if (empty($course->id)) { $mform->setConstant('restrictmodules', (int)($CFG->restrictmodulesfor == 'all')); } else { // keep previous $mform->setConstant('restrictmodules', $course->restrictmodules); } } /// customizable role names in this course //-------------------------------------------------------------------------------- $mform->addElement('header','rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); if ($roles = get_all_roles()) { if ($coursecontext) { $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS_RAW); } $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE); foreach ($roles as $role) { $mform->addElement('text', 'role_'.$role->id, get_string('yourwordforx', '', $role->name)); if (isset($role->localname)) { $mform->setDefault('role_'.$role->id, $role->localname); } $mform->setType('role_'.$role->id, PARAM_TEXT); if (!in_array($role->id, $assignableroles)) { $mform->setAdvanced('role_'.$role->id); } } } //-------------------------------------------------------------------------------- $this->add_action_buttons(); //-------------------------------------------------------------------------------- $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); /// finally set the current form data //-------------------------------------------------------------------------------- $this->set_data($course); }
/** * Form definition. */ function definition() { global $CFG, $PAGE,$USER,$DB; $mform = $this->_form; $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id')))); $course = $this->_customdata['course']; // this contains the data of this form //print_object($course); $category = $this->_customdata['category']; $editoroptions = $this->_customdata['editoroptions']; $returnto = $this->_customdata['returnto']; $systemcontext = context_system::instance(); $categorycontext = context_coursecat::instance($category->id); if (!empty($course->id)) { $coursecontext = context_course::instance($course->id); $context = $coursecontext; } else { $coursecontext = null; $context = $categorycontext; } $courseconfig = get_config('moodlecourse'); $this->course = $course; $this->context = $context; // Form definition with new course defaults. $mform->addElement('header','general', get_string('general', 'form')); $mform->addElement('hidden', 'returnto', null); $mform->setType('returnto', PARAM_ALPHANUM); $mform->setConstant('returnto', $returnto); /* * EA_NK23-02-2015 * Added cost center field */ $is_manager = $DB->record_exists_sql("SELECT ra.userid FROM {role_assignments} as ra JOIN {role} as r ON ra.roleid=r.id WHERE r.archetype='manager' AND ra.userid={$USER->id}"); if(is_siteadmin()) { /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ $admincostcenters=user_wise_department(); //print_object($admincostcenters); $mform->addElement('select', 'costcenter', get_string('pluginname', 'local_costcenter'), $admincostcenters); /*==================Ended by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ }elseif(!is_siteadmin()){ $admincostcenters=user_wise_department(); $mform->addElement('select', 'costcenter', get_string('pluginname', 'local_costcenter'), $admincostcenters); } //$costcenter = $DB->get_records_sql_menu("SELECT cc.id,cc.fullname FROM mdl_local_userdata ud JOIN mdl_local_costcenter cc ON ud.costcenterid=cc.id WHERE ud.userid={$USER->id}"); //$mform->addElement('hidden','costcenter'); //$mform->setDefault('costcenter',$costcenter->id); //$mform->addElement('static', 'costcenterid', get_string('pluginname', 'local_costcenter'), $costcenter->fullname); $mform->setType('costcenter', PARAM_RAW); /* EA_NK23-02-2015 Customization ends here */ $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); $mform->setConstant('fullname', $course->fullname); } $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); $mform->addHelpButton('shortname', 'shortnamecourse'); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); $mform->setConstant('shortname', $course->shortname); } // Verify permissions to change course category or keep current. if (empty($course->id)) { if (has_capability('moodle/course:create', $categorycontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); /*======================Started By Raju.T for Disaply Course Categories based on training manager deparment on 9-11-2015============*/ if(is_siteadmin()){ $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); /*==================Ended by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ }else{ /*======================Ended By Raju.T for Disaply Course Categories based on training manager deparment on 9-11-2015============*/ $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); $userdepartment_exist=$DB->record_exists('local_userdata',array('userid'=>$USER->id)); if($userdepartment_exist==1){ $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id)); if($userdepartment->lms_category=="AST" || $userdepartment->lms_category=="AST-EXT"){ $trainer_type_options=array(null=>'----Select to----',T=>'Trainer',SM=>'Sales Manager'); $mform->addElement('select', 'assignedto', get_string('assigne_to'), $trainer_type_options); //$mform->setConstant('category', $category->id); //$mform->setDefault('assignedto', $course->assignedto); } } /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ } $mform->addHelpButton('category', 'coursecategory'); $mform->setDefault('category', $category->id); $mform->addElement('text','duration',get_string('course_duration'),'maxlength="100" size="10"'); if(!empty($course->assignedto)){ $mform->setDefault('duration', $course->duration); }else{ $mform->setDefault('duration','0'); } $mform->setType('duration', PARAM_RAW); $mform->addRule('duration', get_string('possitiveonly'), 'regex', '#^(0|[1-9][0-9]*)$#'); } else { $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $category->id); } } else { if (has_capability('moodle/course:changecategory', $coursecontext)) { $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); } else { //keep current $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $course->category); } $userdepartment_exist=$DB->record_exists('local_userdata',array('userid'=>$USER->id)); if($userdepartment_exist==1){ $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id)); if($userdepartment->lms_category=="AST" || $userdepartment->lms_category=="AST-EXT"){ $trainer_type_options=array(null=>'----Select to----',T=>'Trainer',SM=>'Sales Manager'); $mform->addElement('select', 'assignedto', get_string('assigne_to'), $trainer_type_options); //$mform->setConstant('category', $category->id); //$mform->setDefault('assignedto', $course->assignedto); } } /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ $mform->addElement('text','duration',get_string('course_duration'),'maxlength="100" size="10"'); if(!empty($course->assignedto)){ $mform->setDefault('duration', $course->duration); }else{ $mform->setDefault('duration','0'); } $mform->setType('duration', PARAM_RAW); $mform->addRule('duration', get_string('possitiveonly'), 'regex', '#^(0|[1-9][0-9]*)$#'); } $choices = array(); $choices['0'] = get_string('hide'); $choices['1'] = get_string('show'); $mform->addElement('select', 'visible', get_string('visible'), $choices); $mform->addHelpButton('visible', 'visible'); $mform->setDefault('visible', $courseconfig->visible); if (!empty($course->id)) { if (!has_capability('moodle/course:visibility', $coursecontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $course->visible); } } else { if (!guess_if_creator_will_have_course_capability('moodle/course:visibility', $categorycontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $courseconfig->visible); } } $mform->addElement('date_selector', 'startdate', get_string('startdate')); $mform->addHelpButton('startdate', 'startdate'); $mform->setDefault('startdate', time() + 3600 * 24); $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbercourse'); $mform->setType('idnumber', PARAM_RAW); if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); $mform->setConstants('idnumber', $course->idnumber); } // Description. $mform->addElement('header', 'descriptionhdr', get_string('description')); $mform->setExpanded('descriptionhdr'); $mform->addElement('editor','summary_editor', get_string('coursesummary'), null, $editoroptions); $mform->addHelpButton('summary_editor', 'coursesummary'); $mform->setType('summary_editor', PARAM_RAW); $summaryfields = 'summary_editor'; if ($overviewfilesoptions = course_overviewfiles_options($course)) { $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions); $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles'); $summaryfields .= ',overviewfiles_filemanager'; } if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) { // Remove the description header it does not contain anything any more. $mform->removeElement('descriptionhdr'); $mform->hardFreeze($summaryfields); } // Course format. $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin')); $courseformats = get_sorted_course_formats(true); $formcourseformats = array(); foreach ($courseformats as $courseformat) { $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat"); } if (isset($course->format)) { $course->format = course_get_format($course)->get_format(); // replace with default if not found if (!in_array($course->format, $courseformats)) { // this format is disabled. Still display it in the dropdown $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_'.$course->format)); } } $mform->addElement('select', 'format', get_string('format'), $formcourseformats); $mform->addHelpButton('format', 'format'); $mform->setDefault('format', $courseconfig->format); // Button to update format-specific options on format change (will be hidden by JavaScript). $mform->registerNoSubmitButton('updatecourseformat'); $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate')); // Just a placeholder for the course format options. $mform->addElement('hidden', 'addcourseformatoptionshere'); $mform->setType('addcourseformatoptionshere', PARAM_BOOL); // Appearance. $mform->addElement('header', 'appearancehdr', get_string('appearance')); if (!empty($CFG->allowcoursethemes)) { $themeobjects = get_list_of_themes(); $themes=array(); $themes[''] = get_string('forceno'); foreach ($themeobjects as $key=>$theme) { if (empty($theme->hidefromselector)) { $themes[$key] = get_string('pluginname', 'theme_'.$theme->name); } } $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); } $languages=array(); $languages[''] = get_string('forceno'); $languages += get_string_manager()->get_list_of_translations(); $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages); $mform->setDefault('lang', $courseconfig->lang); // Multi-Calendar Support - see MDL-18375. $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); // We do not want to show this option unless there is more than one calendar type to display. if (count($calendartypes) > 1) { $calendars = array(); $calendars[''] = get_string('forceno'); $calendars += $calendartypes; $mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars); } $options = range(0, 10); $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); $mform->addHelpButton('newsitems', 'newsitemsnumber'); $mform->setDefault('newsitems', $courseconfig->newsitems); $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); $mform->addHelpButton('showgrades', 'showgrades'); $mform->setDefault('showgrades', $courseconfig->showgrades); $mform->addElement('selectyesno', 'showreports', get_string('showreports')); $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); // Files and uploads. $mform->addElement('header', 'filehdr', get_string('filesanduploads')); if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) { if (empty($course->legacyfiles)) { //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet $choices = array('0'=>get_string('no'), '2'=>get_string('yes')); } else { $choices = array('1'=>get_string('no'), '2'=>get_string('yes')); } $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices); $mform->addHelpButton('legacyfiles', 'courselegacyfiles'); if (!isset($courseconfig->legacyfiles)) { // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses $courseconfig->legacyfiles = 0; } $mform->setDefault('legacyfiles', $courseconfig->legacyfiles); } // Handle non-existing $course->maxbytes on course creation. $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes; // Let's prepare the maxbytes popup. $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); // Completion tracking. if (completion_info::is_enabled_for_site()) { $mform->addElement('header', 'completionhdr', get_string('completion', 'completion')); $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion')); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion'); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setType('enablecompletion', PARAM_INT); $mform->setDefault('enablecompletion', 0); } enrol_course_edit_form($mform, $course, $context); $mform->addElement('header','groups', get_string('groupsettingsheader', 'group')); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices); $mform->addHelpButton('groupmode', 'groupmode', 'group'); $mform->setDefault('groupmode', $courseconfig->groupmode); $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group')); $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group'); $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce); //default groupings selector $options = array(); $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); // Customizable role names in this course. $mform->addElement('header','rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); if ($roles = get_all_roles()) { $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL); $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE); foreach ($roles as $role) { $mform->addElement('text', 'role_'.$role->id, get_string('yourwordforx', '', $role->localname)); $mform->setType('role_'.$role->id, PARAM_TEXT); } } $this->add_action_buttons(); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); // Finally set the current form data $this->set_data($course); }