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