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