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