MDL-15262 Added 3 new capabilities without changing defaults, as suggested by Matt...
[moodle.git] / course / edit_form.php
CommitLineData
a81bf9c3 1<?php //$Id$
2
39625498 3require_once($CFG->libdir.'/formslib.php');
4
a81bf9c3 5class course_edit_form extends moodleform {
6
7 function definition() {
f33e1ed4 8 global $USER, $CFG, $DB;
a81bf9c3 9
cfec0454 10 $courseconfig = get_config('moodlecourse');
a81bf9c3 11 $mform =& $this->_form;
a81bf9c3 12
13 $course = $this->_customdata['course'];
14 $category = $this->_customdata['category'];
15
16 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
17 $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
18
19 $disable_meta = false; // basic meta course state protection; server-side security checks not needed
20
21 if (!empty($course)) {
22 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
23 $context = $coursecontext;
24
25 if (course_in_meta($course)) {
26 $disable_meta = get_string('metaalreadyinmeta');
27
28 } else if ($course->metacourse) {
c3df0901 29 if ($DB->count_records('course_meta', array('parent_course'=>$course->id)) > 0) {
a81bf9c3 30 $disable_meta = get_string('metaalreadyhascourses');
31 }
32
33 } else {
6682b29c 34 // if users already enrolled directly into coures, do not allow switching to meta,
35 // users with metacourse manage permission are exception
36 // please note that we do not need exact results - anything unexpected here prevents metacourse
37 $managers = get_users_by_capability($coursecontext, 'moodle/course:managemetacourse', 'u.id');
38 $enrolroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $coursecontext);
39 if ($users = get_role_users(array_keys($enrolroles), $coursecontext, false, 'u.id', 'u.id ASC')) {
40 foreach($users as $user) {
41 if (!isset($managers[$user->id])) {
42 $disable_meta = get_string('metaalreadyhasenrolments');
43 break;
44 }
45 }
a81bf9c3 46 }
6682b29c 47 unset($managers);
48 unset($users);
49 unset($enrolroles);
461f5127 50 }
51 } else {
a81bf9c3 52 $coursecontext = null;
53 $context = $categorycontext;
54 }
55
56/// form definition with new course defaults
57//--------------------------------------------------------------------------------
2b63df96 58 $mform->addElement('header','general', get_string('general', 'form'));
a81bf9c3 59
60 //must have create course capability in both categories in order to move course
61 if (has_capability('moodle/course:create', $categorycontext)) {
62 $displaylist = array();
63 $parentlist = array();
64 make_categories_list($displaylist, $parentlist);
65 foreach ($displaylist as $key=>$val) {
66 if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $key))) {
67 unset($displaylist[$key]);
68 }
461f5127 69 }
a81bf9c3 70 $mform->addElement('select', 'category', get_string('category'), $displaylist);
71 } else {
72 $mform->addElement('hidden', 'category', null);
461f5127 73 }
a81bf9c3 74 $mform->setHelpButton('category', array('coursecategory', get_string('category')));
cfec0454 75 $mform->setDefault('category', $courseconfig->category);
a81bf9c3 76 $mform->setType('category', PARAM_INT);
461f5127 77
c3df0901 78 $fullname = get_string('defaultcoursefullname');
79 $shortname = get_string('defaultcourseshortname');
80 while ($DB->record_exists('course', array('fullname'=>$fullname))
81 or $DB->record_exists('course', array('fullname'=>$fullname))) {
82 $fullname++;
83 $shortname++;
84 }
c3df0901 85
f7c0d84b 86 if (has_capability('moodle/course:changefullname', $coursecontext)) {
87 $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"');
88 $mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
89 $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
90 $mform->setType('fullname', PARAM_MULTILANG);
91 $mform->setDefault('fullname', $fullname);
92 }
c3df0901 93
f7c0d84b 94 if (has_capability('moodle/course:changeshortname', $coursecontext)) {
95 $mform->addElement('text','shortname', get_string('shortnamecourse'),'maxlength="100" size="20"');
96 $mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
97 $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
98 $mform->setType('shortname', PARAM_MULTILANG);
99 $mform->setDefault('shortname', $shortname);
100 }
101
102 if (has_capability('moodle/course:changeidnumber', $coursecontext)) {
103 $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"');
104 $mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
105 $mform->setType('idnumber', PARAM_RAW);
106 }
01963b95 107
a81bf9c3 108 $mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));
80f69dc0 109 $mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
a81bf9c3 110 $mform->setType('summary', PARAM_RAW);
111
112 $courseformats = get_list_of_plugins('course/format');
113 $formcourseformats = array();
114 foreach ($courseformats as $courseformat) {
ae628043 115 $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
116 if($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
117 $formcourseformats["$courseformat"] = get_string("format$courseformat");
a23f0aaf 118 }
a81bf9c3 119 }
120 $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
121 $mform->setHelpButton('format', array('courseformats', get_string('courseformats')), true);
cfec0454 122 $mform->setDefault('format', $courseconfig->format);
a81bf9c3 123
124 for ($i=1; $i<=52; $i++) {
125 $sectionmenu[$i] = "$i";
126 }
127 $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
cfec0454 128 $mform->setDefault('numsections', $courseconfig->numsections);
a81bf9c3 129
130 $mform->addElement('date_selector', 'startdate', get_string('startdate'));
131 $mform->setHelpButton('startdate', array('coursestartdate', get_string('startdate')), true);
132 $mform->setDefault('startdate', time() + 3600 * 24);
133
134 $choices = array();
135 $choices['0'] = get_string('hiddensectionscollapsed');
136 $choices['1'] = get_string('hiddensectionsinvisible');
137 $mform->addElement('select', 'hiddensections', get_string('hiddensections'), $choices);
138 $mform->setHelpButton('hiddensections', array('coursehiddensections', get_string('hiddensections')), true);
cfec0454 139 $mform->setDefault('hiddensections', $courseconfig->hiddensections);
a81bf9c3 140
65877218 141 $options = range(0, 10);
a81bf9c3 142 $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
143 $mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true);
cfec0454 144 $mform->setDefault('newsitems', $courseconfig->newsitems);
a81bf9c3 145
65877218 146 $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
a81bf9c3 147 $mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true);
cfec0454 148 $mform->setDefault('showgrades', $courseconfig->showgrades);
a81bf9c3 149
65877218 150 $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
a81bf9c3 151 $mform->setHelpButton('showreports', array('coursereports', get_string('activityreport')), true);
cfec0454 152 $mform->setDefault('showreports', $courseconfig->showreports);
a81bf9c3 153
154 $choices = get_max_upload_sizes($CFG->maxbytes);
155 $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
156 $mform->setHelpButton('maxbytes', array('courseuploadsize', get_string('maximumupload')), true);
cfec0454 157 $mform->setDefault('maxbytes', $courseconfig->maxbytes);
a81bf9c3 158
159 if (!empty($CFG->allowcoursethemes)) {
160 $themes=array();
161 $themes[''] = get_string('forceno');
162 $themes += get_list_of_themes();
163 $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
164 }
461f5127 165
01963b95 166 $meta=array();
167 $meta[0] = get_string('no');
168 $meta[1] = get_string('yes');
a81bf9c3 169 if ($disable_meta === false) {
170 $mform->addElement('select', 'metacourse', get_string('managemeta'), $meta);
3d397ee0 171 $mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true);
cfec0454 172 $mform->setDefault('metacourse', $courseconfig->metacourse);
a81bf9c3 173 } else {
3d397ee0 174 // no metacourse element - we do not want to change it anyway!
175 $mform->addElement('static', 'nometacourse', get_string('managemeta'),
a81bf9c3 176 ((empty($course->metacourse)) ? $meta[0] : $meta[1]) . " - $disable_meta ");
3d397ee0 177 $mform->setHelpButton('nometacourse', array('metacourse', get_string('metacourse')), true);
a81bf9c3 178 }
01963b95 179
e15d4dd0 180//--------------------------------------------------------------------------------
181 $mform->addElement('header','enrolhdr', get_string('enrolments'));
182
183 $choices = array();
184 $modules = explode(',', $CFG->enrol_plugins_enabled);
185 foreach ($modules as $module) {
186 $name = get_string('enrolname', "enrol_$module");
187 $plugin = enrolment_factory::factory($module);
188 if (method_exists($plugin, 'print_entry')) {
189 $choices[$name] = $module;
190 }
191 }
192 asort($choices);
193 $choices = array_flip($choices);
194 $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices);
195 $mform->addElement('select', 'enrol', get_string('enrolmentplugins'), $choices);
196 $mform->setHelpButton('enrol', array('courseenrolmentplugins', get_string('enrolmentplugins')), true);
cfec0454 197 $mform->setDefault('enrol', $courseconfig->enrol);
e15d4dd0 198
199
a81bf9c3 200 $roles = get_assignable_roles($context);
201 if (!empty($course)) {
202 // add current default role, so that it is selectable even when user can not assign it
c3df0901 203 if ($current_role = $DB->get_record('role', array('id'=>$course->defaultrole))) {
a81bf9c3 204 $roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
205 }
206 }
207 $choices = array();
c3df0901 208 if ($sitedefaultrole = $DB->get_record('role', array('id'=>$CFG->defaultcourseroleid))) {
a81bf9c3 209 $choices[0] = get_string('sitedefault').' ('.$sitedefaultrole->name.')';
01963b95 210 } else {
a81bf9c3 211 $choices[0] = get_string('sitedefault');
01963b95 212 }
a81bf9c3 213 $choices = $choices + $roles;
f20d7c41 214
215 // fix for MDL-9197
216 foreach ($choices as $choiceid => $choice) {
217 $choices[$choiceid] = format_string($choice);
218 }
219
a81bf9c3 220 $mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices);
221 $mform->setDefault('defaultrole', 0);
222
01963b95 223
a81bf9c3 224 $radio = array();
225 $radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('no'), 0);
226 $radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('yes'), 1);
227 $radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('enroldate'), 2);
228 $mform->addGroup($radio, 'enrollable', get_string('enrollable'), ' ', false);
6be58b1c 229 $mform->setHelpButton('enrollable', array('courseenrollable2', get_string('enrollable')), true);
cfec0454 230 $mform->setDefault('enrollable', $courseconfig->enrollable);
a81bf9c3 231
232 $enroldatestartgrp = array();
233 $enroldatestartgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolstartdate');
234 $enroldatestartgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
2dbd6409 235 $mform->addGroup($enroldatestartgrp, 'enrolstartdategrp', get_string('enrolstartdate'), ' ', false);
a81bf9c3 236 $mform->setDefault('enrolstartdate', 0);
237 $mform->setDefault('enrolstartdisabled', 1);
2dbd6409 238 $mform->disabledIf('enrolstartdategrp', 'enrolstartdisabled', 'checked');
a81bf9c3 239
240 $enroldateendgrp = array();
241 $enroldateendgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolenddate');
242 $enroldateendgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolenddisabled', null, get_string('disable'));
243 $mform->addGroup($enroldateendgrp, 'enroldateendgrp', get_string('enrolenddate'), ' ', false);
244 $mform->setDefault('enrolenddate', 0);
245 $mform->setDefault('enrolenddisabled', 1);
2dbd6409 246 $mform->disabledIf('enroldateendgrp', 'enrolenddisabled', 'checked');
a81bf9c3 247
248 $periodmenu=array();
249 $periodmenu[0] = get_string('unlimited');
250 for ($i=1; $i<=365; $i++) {
251 $seconds = $i * 86400;
252 $periodmenu[$seconds] = get_string('numdays', '', $i);
253 }
254 $mform->addElement('select', 'enrolperiod', get_string('enrolperiod'), $periodmenu);
cfec0454 255 $mform->setDefault('enrolperiod', $courseconfig->enrolperiod);
a81bf9c3 256
e15d4dd0 257
a81bf9c3 258//--------------------------------------------------------------------------------
259 $mform->addElement('header','expirynotifyhdr', get_string('expirynotify'));
260
261 $choices = array();
262 $choices['0'] = get_string('no');
263 $choices['1'] = get_string('yes');
ec3dac98 264 $mform->addElement('select', 'expirynotify', get_string('notify'), $choices);
a81bf9c3 265 $mform->setHelpButton('expirynotify', array('expirynotify', get_string('expirynotify')), true);
cfec0454 266 $mform->setDefault('expirynotify', $courseconfig->expirynotify);
a81bf9c3 267
268 $mform->addElement('select', 'notifystudents', get_string('expirynotifystudents'), $choices);
269 $mform->setHelpButton('notifystudents', array('expirynotifystudents', get_string('expirynotifystudents')), true);
cfec0454 270 $mform->setDefault('notifystudents', $courseconfig->notifystudents);
a81bf9c3 271
272 $thresholdmenu=array();
273 for ($i=1; $i<=30; $i++) {
274 $seconds = $i * 86400;
275 $thresholdmenu[$seconds] = get_string('numdays', '', $i);
276 }
277 $mform->addElement('select', 'expirythreshold', get_string('expirythreshold'), $thresholdmenu);
278 $mform->setHelpButton('expirythreshold', array('expirythreshold', get_string('expirythreshold')), true);
cfec0454 279 $mform->setDefault('expirythreshold', $courseconfig->expirythreshold);
a81bf9c3 280
281//--------------------------------------------------------------------------------
ec3dac98 282 $mform->addElement('header','', get_string('groups', 'group'));
a81bf9c3 283
284 $choices = array();
467cebb0 285 $choices[NOGROUPS] = get_string('groupsnone', 'group');
286 $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
287 $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
a81bf9c3 288 $mform->addElement('select', 'groupmode', get_string('groupmode'), $choices);
289 $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')), true);
cfec0454 290 $mform->setDefault('groupmode', $courseconfig->groupmode);
a81bf9c3 291
292 $choices = array();
293 $choices['0'] = get_string('no');
294 $choices['1'] = get_string('yes');
295 $mform->addElement('select', 'groupmodeforce', get_string('force'), $choices);
296 $mform->setHelpButton('groupmodeforce', array('groupmodeforce', get_string('groupmodeforce')), true);
cfec0454 297 $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);
a81bf9c3 298
24f41672 299 if (!empty($CFG->enablegroupings)) {
300 //default groupings selector
301 $options = array();
302 $options[0] = get_string('none');
303 $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
304 }
305
a81bf9c3 306//--------------------------------------------------------------------------------
307 $mform->addElement('header','', get_string('availability'));
308
309 $choices = array();
310 $choices['0'] = get_string('courseavailablenot');
311 $choices['1'] = get_string('courseavailable');
312 $mform->addElement('select', 'visible', get_string('availability'), $choices);
313 $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
cfec0454 314 $mform->setDefault('visible', $courseconfig->visible);
a81bf9c3 315
1898ccac 316 $mform->addElement('passwordunmask', 'enrolpassword', get_string('enrolmentkey'), 'size="25"');
317 $mform->setHelpButton('enrolpassword', array('enrolmentkey', get_string('enrolmentkey')), true);
318 $mform->setDefault('enrolpassword', '');
cfec0454 319 $mform->setDefault('enrolpassword', $courseconfig->enrolpassword);
1898ccac 320 $mform->setType('enrolpassword', PARAM_RAW);
a81bf9c3 321
322 $choices = array();
323 $choices['0'] = get_string('guestsno');
324 $choices['1'] = get_string('guestsyes');
325 $choices['2'] = get_string('guestskey');
326 $mform->addElement('select', 'guest', get_string('opentoguests'), $choices);
327 $mform->setHelpButton('guest', array('guestaccess', get_string('opentoguests')), true);
cfec0454 328 $mform->setDefault('guest', $courseconfig->guest);
f7c0d84b 329
a937b164 330 // 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
331 $enrol_object = $CFG;
332 if (!empty($course)) {
82d3334a 333 $enrol_object = $course;
a937b164 334 }
c5340330 335 // If the print_entry method exists and the course enrol method isn't manual (both set or inherited from site), show cost
336 if (method_exists(enrolment_factory::factory($enrol_object->enrol), 'print_entry') && !($enrol_object->enrol == 'manual' || (empty($enrol_object->enrol) && $CFG->enrol == 'manual'))) {
a81bf9c3 337 $costgroup=array();
338 $currencies = get_list_of_currencies();
339 $costgroup[]= &MoodleQuickForm::createElement('text','cost', '', 'maxlength="6" size="6"');
340 $costgroup[]= &MoodleQuickForm::createElement('select', 'currency', '', $currencies);
341 $mform->addGroup($costgroup, 'costgrp', get_string('cost'), '&nbsp;', false);
5bc97c98 342 //defining a rule for a form element within a group :
343 $costgrprules=array();
344 //set the message to null to tell Moodle to use a default message
345 //available for most rules, fetched from language pack (err_{rulename}).
346 $costgrprules['cost'][]=array(null, 'numeric', null, 'client');
347 $mform->addGroupRule('costgrp',$costgrprules);
a81bf9c3 348 $mform->setHelpButton('costgrp', array('cost', get_string('cost')), true);
349 $mform->setDefault('cost', '');
350 $mform->setDefault('currency', empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
e995c46e 351
a81bf9c3 352 }
353
354//--------------------------------------------------------------------------------
355 $mform->addElement('header','', get_string('language'));
356
357 $languages=array();
358 $languages[''] = get_string('forceno');
359 $languages += get_list_of_languages();
360 $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
cfec0454 361 $mform->setDefault('lang', $courseconfig->lang);
a81bf9c3 362
4e781c7b 363//--------------------------------------------------------------------------------
364 require_once($CFG->libdir.'/completionlib.php');
365 if(completion_info::is_enabled_for_site()) {
366 $mform->addElement('header','', get_string('progress','completion'));
f7c0d84b 367 $mform->addElement('select', 'enablecompletion', get_string('completion','completion'),
4e781c7b 368 array(0=>get_string('completiondisabled','completion'), 1=>get_string('completionenabled','completion')));
cfec0454 369 $mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
4e781c7b 370 } else {
371 $mform->addElement('hidden', 'enablecompletion');
372 $mform->setDefault('enablecompletion',0);
373 }
374
a81bf9c3 375//--------------------------------------------------------------------------------
376 if (has_capability('moodle/site:config', $systemcontext) && ((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) {
377 $mform->addElement('header', '', get_string('restrictmodules'));
378
379 $options = array();
380 $options['0'] = get_string('no');
381 $options['1'] = get_string('yes');
2dbd6409 382 $mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options);
a81bf9c3 383 $mods = array(0=>get_string('allownone'));
3b112723 384 $mods += $DB->get_records_menu('modules', array(), 'name', 'id, name');
a81bf9c3 385
386
2dbd6409 387 $mform->addElement('select', 'allowedmods', get_string('to'), $mods,
388 array('multiple'=>'multiple', 'size'=>'10'));
389 $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0);
390 } else {
a81bf9c3 391 $mform->addElement('hidden', 'restrictmodules', null);
392 }
393 if ($CFG->restrictmodulesfor == 'all') {
394 $mform->setDefault('allowedmods', explode(',',$CFG->defaultallowedmodules));
395 if (!empty($CFG->restrictbydefault)) {
396 $mform->setDefault('restrictmodules', 1);
397 }
398 }
399 $mform->setType('restrictmodules', PARAM_INT);
400
0150c561 401/// customizable role names in this course
402//--------------------------------------------------------------------------------
7d2e9a52 403 $mform->addElement('header','rolerenaming', get_string('rolerenaming'));
404 $mform->setHelpButton('rolerenaming', array('rolerenaming', get_string('rolerenaming')), true);
0150c561 405
c3df0901 406 if ($roles = $DB->get_records('role')) {
0150c561 407 foreach ($roles as $role) {
408 $mform->addElement('text', 'role_'.$role->id, $role->name);
409 if ($coursecontext) {
c3df0901 410 if ($rolename = $DB->get_record('role_names', array('roleid'=>$role->id, 'contextid'=>$coursecontext->id))) {
f7c0d84b 411 $mform->setDefault('role_'.$role->id, $rolename->name);
412 }
0150c561 413 }
414 }
415 }
416
a81bf9c3 417//--------------------------------------------------------------------------------
a23f0aaf 418 $this->add_action_buttons();
a81bf9c3 419//--------------------------------------------------------------------------------
420 $mform->addElement('hidden', 'id', null);
421 $mform->setType('id', PARAM_INT);
422
423 // fill in default teacher and student names to keep backwards compatibility for a while
424 $mform->addElement('hidden', 'teacher', get_string('defaultcourseteacher'));
425 $mform->addElement('hidden', 'teachers', get_string('defaultcourseteachers'));
426 $mform->addElement('hidden', 'student', get_string('defaultcoursestudent'));
427 $mform->addElement('hidden', 'students', get_string('defaultcoursestudents'));
c08ac016 428 }
2dbd6409 429
24f41672 430 function definition_after_data() {
c3df0901 431 global $DB;
24f41672 432
433 $mform =& $this->_form;
434
435 // add availabe groupings
436 if ($courseid = $mform->getElementValue('id') and $mform->elementExists('defaultgroupingid')) {
437 $options = array();
c3df0901 438 if ($groupings = $DB->get_records('groupings', array('courseid'=>$courseid))) {
24f41672 439 foreach ($groupings as $grouping) {
440 $options[$grouping->id] = format_string($grouping->name);
441 }
442 }
443 $gr_el =& $mform->getElement('defaultgroupingid');
444 $gr_el->load($options);
445 }
446 }
f7c0d84b 447
a81bf9c3 448
449/// perform some extra moodle validation
a78890d5 450 function validation($data, $files) {
c3df0901 451 global $DB;
452
a78890d5 453 $errors = parent::validation($data, $files);
c3df0901 454 if ($foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname']))) {
a81bf9c3 455 if (!empty($data['id'])) {
456 unset($foundcourses[$data['id']]);
01963b95 457 }
458 if (!empty($foundcourses)) {
459 foreach ($foundcourses as $foundcourse) {
460 $foundcoursenames[] = $foundcourse->fullname;
461 }
a81bf9c3 462 $foundcoursenamestring = implode(',', $foundcoursenames);
463 $errors['shortname']= get_string('shortnametaken', '', $foundcoursenamestring);
01963b95 464 }
01963b95 465 }
a81bf9c3 466
467 if (empty($data['enrolenddisabled'])){
468 if ($data['enrolenddate'] <= $data['enrolstartdate']){
469 $errors['enroldateendgrp'] = get_string('enrolenddaterror');
01963b95 470 }
471 }
a81bf9c3 472
a78890d5 473 return $errors;
01963b95 474 }
a81bf9c3 475}
a937b164 476?>