| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php //$Id: edit_form.php,v 1.37.2.11 2008/10/13 19:38:49 skodak Exp $ 2 3 require_once($CFG->libdir.'/formslib.php'); 4 5 class course_edit_form extends moodleform { 6 7 function definition() { 8 global $USER, $CFG; 9 10 $mform =& $this->_form; 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) { 28 if (count_records('course_meta', 'parent_course', $course->id) > 0) { 29 $disable_meta = get_string('metaalreadyhascourses'); 30 } 31 32 } else { 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 } 45 } 46 unset($managers); 47 unset($users); 48 unset($enrolroles); 49 } 50 } else { 51 $coursecontext = null; 52 $context = $categorycontext; 53 } 54 55 /// form definition with new course defaults 56 //-------------------------------------------------------------------------------- 57 $mform->addElement('header','general', get_string('general', 'form')); 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 } 68 } 69 $mform->addElement('select', 'category', get_string('category'), $displaylist); 70 } else { 71 $mform->addElement('hidden', 'category', null); 72 } 73 $mform->setHelpButton('category', array('coursecategory', get_string('category'))); 74 $mform->setDefault('category', $category->id); 75 $mform->setType('category', PARAM_INT); 76 77 $mform->addElement('text','fullname', get_string('fullname'),'maxlength="254" size="50"'); 78 $mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true); 79 $mform->setDefault('fullname', get_string('defaultcoursefullname')); 80 $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); 81 $mform->setType('fullname', PARAM_MULTILANG); 82 if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) { 83 $mform->hardFreeze('fullname'); 84 $mform->setConstant('fullname', $course->fullname); 85 } 86 87 $mform->addElement('text','shortname', get_string('shortname'),'maxlength="100" size="20"'); 88 $mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), true); 89 $mform->setDefault('shortname', get_string('defaultcourseshortname')); 90 $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); 91 $mform->setType('shortname', PARAM_MULTILANG); 92 if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) { 93 $mform->hardFreeze('shortname'); 94 $mform->setConstant('shortname', $course->shortname); 95 } 96 97 $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"'); 98 $mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true); 99 $mform->setType('idnumber', PARAM_RAW); 100 if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) { 101 $mform->hardFreeze('idnumber'); 102 $mform->setConstants('idnumber', $course->idnumber); 103 } 104 105 $mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65')); 106 $mform->setHelpButton('summary', array('text', get_string('helptext')), true); 107 $mform->setType('summary', PARAM_RAW); 108 109 $courseformats = get_list_of_plugins('course/format'); 110 $formcourseformats = array(); 111 foreach ($courseformats as $courseformat) { 112 $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat"); 113 if($formcourseformats["$courseformat"]=="[[format$courseformat]]") { 114 $formcourseformats["$courseformat"] = get_string("format$courseformat"); 115 } 116 } 117 $mform->addElement('select', 'format', get_string('format'), $formcourseformats); 118 $mform->setHelpButton('format', array('courseformats', get_string('courseformats')), true); 119 $mform->setDefault('format', 'weeks'); 120 121 for ($i=1; $i<=52; $i++) { 122 $sectionmenu[$i] = "$i"; 123 } 124 $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu); 125 $mform->setDefault('numsections', 10); 126 127 $mform->addElement('date_selector', 'startdate', get_string('startdate')); 128 $mform->setHelpButton('startdate', array('coursestartdate', get_string('startdate')), true); 129 $mform->setDefault('startdate', time() + 3600 * 24); 130 131 $choices = array(); 132 $choices['0'] = get_string('hiddensectionscollapsed'); 133 $choices['1'] = get_string('hiddensectionsinvisible'); 134 $mform->addElement('select', 'hiddensections', get_string('hiddensections'), $choices); 135 $mform->setHelpButton('hiddensections', array('coursehiddensections', get_string('hiddensections')), true); 136 $mform->setDefault('hiddensections', 0); 137 138 $options = range(0, 10); 139 $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); 140 $mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true); 141 $mform->setDefault('newsitems', 5); 142 143 $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); 144 $mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true); 145 $mform->setDefault('showgrades', 1); 146 147 $mform->addElement('selectyesno', 'showreports', get_string('showreports')); 148 $mform->setHelpButton('showreports', array('coursereports', get_string('activityreport')), true); 149 $mform->setDefault('showreports', 0); 150 151 $choices = get_max_upload_sizes($CFG->maxbytes); 152 $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); 153 $mform->setHelpButton('maxbytes', array('courseuploadsize', get_string('maximumupload')), true); 154 155 if (!empty($CFG->allowcoursethemes)) { 156 $themes=array(); 157 $themes[''] = get_string('forceno'); 158 $themes += get_list_of_themes(); 159 $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); 160 } 161 162 $meta=array(); 163 $meta[0] = get_string('no'); 164 $meta[1] = get_string('yes'); 165 if ($disable_meta === false) { 166 $mform->addElement('select', 'metacourse', get_string('managemeta'), $meta); 167 $mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true); 168 $mform->setDefault('metacourse', 0); 169 } else { 170 // no metacourse element - we do not want to change it anyway! 171 $mform->addElement('static', 'nometacourse', get_string('managemeta'), 172 ((empty($course->metacourse)) ? $meta[0] : $meta[1]) . " - $disable_meta "); 173 $mform->setHelpButton('nometacourse', array('metacourse', get_string('metacourse')), true); 174 } 175 176 //-------------------------------------------------------------------------------- 177 $mform->addElement('header','enrolhdr', get_string('enrolments')); 178 179 $choices = array(); 180 $modules = explode(',', $CFG->enrol_plugins_enabled); 181 foreach ($modules as $module) { 182 $name = get_string('enrolname', "enrol_$module"); 183 $plugin = enrolment_factory::factory($module); 184 if (method_exists($plugin, 'print_entry')) { 185 $choices[$name] = $module; 186 } 187 } 188 asort($choices); 189 $choices = array_flip($choices); 190 $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices); 191 $mform->addElement('select', 'enrol', get_string('enrolmentplugins'), $choices); 192 $mform->setHelpButton('enrol', array('courseenrolmentplugins', get_string('enrolmentplugins')), true); 193 194 195 $roles = get_assignable_roles($context); 196 if (!empty($course)) { 197 // add current default role, so that it is selectable even when user can not assign it 198 if ($current_role = get_record('role', 'id', $course->defaultrole)) { 199 $roles[$current_role->id] = strip_tags(format_string($current_role->name, true)); 200 } 201 } 202 $choices = array(); 203 if ($sitedefaultrole = get_record('role', 'id', $CFG->defaultcourseroleid)) { 204 $choices[0] = get_string('sitedefault').' ('.$sitedefaultrole->name.')'; 205 } else { 206 $choices[0] = get_string('sitedefault'); 207 } 208 $choices = $choices + $roles; 209 210 // fix for MDL-9197 211 foreach ($choices as $choiceid => $choice) { 212 $choices[$choiceid] = format_string($choice); 213 } 214 215 $mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices); 216 $mform->setDefault('defaultrole', 0); 217 218 219 $radio = array(); 220 $radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('no'), 0); 221 $radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('yes'), 1); 222 $radio[] = &MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('enroldate'), 2); 223 $mform->addGroup($radio, 'enrollable', get_string('enrollable'), ' ', false); 224 $mform->setHelpButton('enrollable', array('courseenrollable2', get_string('enrollable')), true); 225 $mform->setDefault('enrollable', 1); 226 227 $enroldatestartgrp = array(); 228 $enroldatestartgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolstartdate'); 229 $enroldatestartgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable')); 230 $mform->addGroup($enroldatestartgrp, 'enrolstartdategrp', get_string('enrolstartdate'), ' ', false); 231 $mform->setDefault('enrolstartdate', 0); 232 $mform->setDefault('enrolstartdisabled', 1); 233 $mform->disabledIf('enrolstartdategrp', 'enrolstartdisabled', 'checked'); 234 235 $enroldateendgrp = array(); 236 $enroldateendgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolenddate'); 237 $enroldateendgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolenddisabled', null, get_string('disable')); 238 $mform->addGroup($enroldateendgrp, 'enroldateendgrp', get_string('enrolenddate'), ' ', false); 239 $mform->setDefault('enrolenddate', 0); 240 $mform->setDefault('enrolenddisabled', 1); 241 $mform->disabledIf('enroldateendgrp', 'enrolenddisabled', 'checked'); 242 243 $periodmenu=array(); 244 $periodmenu[0] = get_string('unlimited'); 245 for ($i=1; $i<=365; $i++) { 246 $seconds = $i * 86400; 247 $periodmenu[$seconds] = get_string('numdays', '', $i); 248 } 249 $mform->addElement('select', 'enrolperiod', get_string('enrolperiod'), $periodmenu); 250 $mform->setDefault('enrolperiod', 0); 251 252 253 //-------------------------------------------------------------------------------- 254 $mform->addElement('header','expirynotifyhdr', get_string('expirynotify')); 255 256 $choices = array(); 257 $choices['0'] = get_string('no'); 258 $choices['1'] = get_string('yes'); 259 $mform->addElement('select', 'expirynotify', get_string('notify'), $choices); 260 $mform->setHelpButton('expirynotify', array('expirynotify', get_string('expirynotify')), true); 261 $mform->setDefault('expirynotify', 0); 262 263 $mform->addElement('select', 'notifystudents', get_string('expirynotifystudents'), $choices); 264 $mform->setHelpButton('notifystudents', array('expirynotifystudents', get_string('expirynotifystudents')), true); 265 $mform->setDefault('notifystudents', 0); 266 267 $thresholdmenu=array(); 268 for ($i=1; $i<=30; $i++) { 269 $seconds = $i * 86400; 270 $thresholdmenu[$seconds] = get_string('numdays', '', $i); 271 } 272 $mform->addElement('select', 'expirythreshold', get_string('expirythreshold'), $thresholdmenu); 273 $mform->setHelpButton('expirythreshold', array('expirythreshold', get_string('expirythreshold')), true); 274 $mform->setDefault('expirythreshold', 10 * 86400); 275 276 //-------------------------------------------------------------------------------- 277 $mform->addElement('header','', get_string('groups', 'group')); 278 279 $choices = array(); 280 $choices[NOGROUPS] = get_string('groupsnone', 'group'); 281 $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); 282 $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); 283 $mform->addElement('select', 'groupmode', get_string('groupmode'), $choices); 284 $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')), true); 285 $mform->setDefault('groupmode', 0); 286 287 $choices = array(); 288 $choices['0'] = get_string('no'); 289 $choices['1'] = get_string('yes'); 290 $mform->addElement('select', 'groupmodeforce', get_string('force'), $choices); 291 $mform->setHelpButton('groupmodeforce', array('groupmodeforce', get_string('groupmodeforce')), true); 292 $mform->setDefault('groupmodeforce', 0); 293 294 if (!empty($CFG->enablegroupings)) { 295 //default groupings selector 296 $options = array(); 297 $options[0] = get_string('none'); 298 $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); 299 } 300 301 //-------------------------------------------------------------------------------- 302 $mform->addElement('header','', get_string('availability')); 303 304 $choices = array(); 305 $choices['0'] = get_string('courseavailablenot'); 306 $choices['1'] = get_string('courseavailable'); 307 $mform->addElement('select', 'visible', get_string('availability'), $choices); 308 $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true); 309 $mform->setDefault('visible', 1); 310 311 $mform->addElement('passwordunmask', 'enrolpassword', get_string('enrolmentkey'), 'size="25"'); 312 $mform->setHelpButton('enrolpassword', array('enrolmentkey', get_string('enrolmentkey')), true); 313 $mform->setDefault('enrolpassword', ''); 314 $mform->setType('enrolpassword', PARAM_RAW); 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); 322 $mform->setDefault('guest', 0); 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)) { 327 $enrol_object = $course; 328 } 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'))) { 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'), ' ', false); 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); 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); 345 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); 355 356 //-------------------------------------------------------------------------------- 357 if (has_capability('moodle/site:config', $systemcontext) && ((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) { 358 $mform->addElement('header', '', get_string('restrictmodules')); 359 360 $options = array(); 361 $options['0'] = get_string('no'); 362 $options['1'] = get_string('yes'); 363 $mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options); 364 $mods = array(0=>get_string('allownone')); 365 $mods += get_records_menu('modules', '','','','id, name'); 366 367 368 $mform->addElement('select', 'allowedmods', get_string('to'), $mods, 369 array('multiple'=>'multiple', 'size'=>'10')); 370 $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0); 371 } else { 372 $mform->addElement('hidden', 'restrictmodules', null); 373 } 374 if ($CFG->restrictmodulesfor == 'all') { 375 $mform->setDefault('allowedmods', explode(',',$CFG->defaultallowedmodules)); 376 if (!empty($CFG->restrictbydefault)) { 377 $mform->setDefault('restrictmodules', 1); 378 } 379 } 380 $mform->setType('restrictmodules', PARAM_INT); 381 382 /// customizable role names in this course 383 //-------------------------------------------------------------------------------- 384 $mform->addElement('header','rolerenaming', get_string('rolerenaming')); 385 $mform->setHelpButton('rolerenaming', array('rolerenaming', get_string('rolerenaming')), true); 386 387 if ($roles = get_records('role')) { 388 foreach ($roles as $role) { 389 $mform->addElement('text', 'role_'.$role->id, $role->name); 390 if ($coursecontext) { 391 if ($rolename = get_record('role_names', 'roleid', $role->id, 'contextid', $coursecontext->id)) { 392 $mform->setDefault('role_'.$role->id, $rolename->name); 393 } 394 } 395 } 396 } 397 398 //-------------------------------------------------------------------------------- 399 $this->add_action_buttons(); 400 //-------------------------------------------------------------------------------- 401 $mform->addElement('hidden', 'id', null); 402 $mform->setType('id', PARAM_INT); 403 404 // fill in default teacher and student names to keep backwards compatibility for a while 405 $mform->addElement('hidden', 'teacher', get_string('defaultcourseteacher')); 406 $mform->addElement('hidden', 'teachers', get_string('defaultcourseteachers')); 407 $mform->addElement('hidden', 'student', get_string('defaultcoursestudent')); 408 $mform->addElement('hidden', 'students', get_string('defaultcoursestudents')); 409 } 410 411 function definition_after_data() { 412 global $CFG; 413 414 $mform =& $this->_form; 415 416 // add availabe groupings 417 if ($courseid = $mform->getElementValue('id') and $mform->elementExists('defaultgroupingid')) { 418 $options = array(); 419 if ($groupings = get_records('groupings', 'courseid', $courseid)) { 420 foreach ($groupings as $grouping) { 421 $options[$grouping->id] = format_string($grouping->name); 422 } 423 } 424 $gr_el =& $mform->getElement('defaultgroupingid'); 425 $gr_el->load($options); 426 } 427 } 428 429 430 /// perform some extra moodle validation 431 function validation($data, $files) { 432 $errors = parent::validation($data, $files); 433 if ($foundcourses = get_records('course', 'shortname', $data['shortname'])) { 434 if (!empty($data['id'])) { 435 unset($foundcourses[$data['id']]); 436 } 437 if (!empty($foundcourses)) { 438 foreach ($foundcourses as $foundcourse) { 439 $foundcoursenames[] = $foundcourse->fullname; 440 } 441 $foundcoursenamestring = implode(',', $foundcoursenames); 442 $errors['shortname']= get_string('shortnametaken', '', $foundcoursenamestring); 443 } 444 } 445 446 if (empty($data['enrolenddisabled'])){ 447 if ($data['enrolenddate'] <= $data['enrolstartdate']){ 448 $errors['enroldateendgrp'] = get_string('enrolenddaterror'); 449 } 450 } 451 452 return $errors; 453 } 454 } 455 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |