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