function definition() { $mform =& $this->_form; $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('hidden', 'id', $this->_customdata['id']); $mform->setType('id', PARAM_INT); $mform->addElement('text', 'name', get_string('name'), 'maxlength="255" size="50"'); $mform->addRule('name', null, 'required', null, 'client'); $mform->setType('name', PARAM_MULTILANG); $mform->addElement('editor', 'text', get_string('noticetext', 'facetoface'), array('rows' => 10, 'cols' => 64)); $mform->setType('text', PARAM_RAW); $mform->addRule('text', null, 'required', null, 'client'); $mform->addElement('header', 'conditions', get_string('conditions', 'facetoface')); $mform->addElement('html', get_string('conditionsexplanation', 'facetoface')); // Show all custom fields $customfields = $this->_customdata['customfields']; facetoface_add_customfields_to_form($mform, $customfields, true); $this->add_action_buttons(); }
function definition() { global $CFG, $DB; $mform =& $this->_form; $mform->addElement('hidden', 'id', $this->_customdata['id']); $mform->addElement('hidden', 'f', $this->_customdata['f']); $mform->addElement('hidden', 's', $this->_customdata['s']); $mform->addElement('hidden', 'c', $this->_customdata['c']); $mform->setType('id', PARAM_INT); $mform->setType('f', PARAM_INT); $mform->setType('s', PARAM_INT); $mform->setType('c', PARAM_INT); $mform->addElement('header', 'general', get_string('general', 'form')); $editoroptions = $this->_customdata['editoroptions']; // Show all custom fields $customfields = $this->_customdata['customfields']; facetoface_add_customfields_to_form($mform, $customfields); $formarray = array(); $formarray[] = $mform->createElement('selectyesno', 'datetimeknown', get_string('sessiondatetimeknown', 'facetoface')); $formarray[] = $mform->createElement('static', 'datetimeknownhint', '', html_writer::tag('span', get_string('datetimeknownhinttext','facetoface'), array('class' => 'hint-text'))); $mform->addGroup($formarray,'datetimeknown_group', get_string('sessiondatetimeknown','facetoface'), array(' '),false); $mform->addGroupRule('datetimeknown_group', null, 'required', null, 'client'); $mform->setDefault('datetimeknown', false); $mform->addHelpButton('datetimeknown_group', 'sessiondatetimeknown', 'facetoface'); $repeatarray = array(); $timezones = get_clean_timezone_list(true); $timezones[get_string('sessiontimezoneunknown', 'facetoface')] = get_string('sessiontimezoneunknown', 'facetoface'); $repeatarray[] = &$mform->createElement('hidden', 'sessiondateid', 0); $repeatarray[] = $mform->createElement('select', 'sessiontimezone', get_string('sessiontimezone', 'facetoface'), $timezones); $repeatarray[] = &$mform->createElement('date_time_selector', 'timestart', get_string('timestart', 'facetoface')); $repeatarray[] = &$mform->createElement('date_time_selector', 'timefinish', get_string('timefinish', 'facetoface')); $checkboxelement = &$mform->createElement('checkbox', 'datedelete', '', get_string('dateremove', 'facetoface')); unset($checkboxelement->_attributes['id']); // necessary until MDL-20441 is fixed $repeatarray[] = $checkboxelement; $repeatarray[] = &$mform->createElement('html', html_writer::empty_tag('br')); // spacer $repeatcount = $this->_customdata['nbdays']; $repeatoptions = array(); $repeatoptions['timestart']['disabledif'] = array('datetimeknown', 'eq', 0); $repeatoptions['timefinish']['disabledif'] = array('datetimeknown', 'eq', 0); $repeatoptions['sessiontimezone']['disabledif'] = array('datetimeknown', 'eq', 0); $repeatoptions['sessiontimezone']['default'] = $this->_customdata['defaulttimezone']; $mform->setType('timestart', PARAM_INT); $mform->setType('timefinish', PARAM_INT); $mform->setType('sessiontimezone', PARAM_TEXT); $mform->setType('sessiondateid', PARAM_INT); $this->repeat_elements($repeatarray, $repeatcount, $repeatoptions, 'date_repeats', 'date_add_fields', 1, get_string('dateadd', 'facetoface'), true); // Rooms form $pdroom = ''; $roomnote = ''; if (!empty($this->_customdata['s'])) { $sql = "SELECT r.* FROM {facetoface_sessions} s INNER JOIN {facetoface_room} r ON s.roomid = r.id WHERE s.id = ? AND r.custom = 0"; $params = array($this->_customdata['s']); if ($room = $DB->get_record_sql($sql, $params)) { $pdroom = $room->name.', '.$room->building.', '.$room->address.', '.$room->description." (".get_string('capacity', 'facetoface').": ".$room->capacity.")"; $pdroom = format_string($pdroom); if ($room->type == 'external') { $roomnote = '<br><em>'.get_string('roommustbebookedtoexternalcalendar', 'facetoface').'</em>'; } } } $mform->addElement('static', 'predefinedroom', get_string('room', 'facetoface'), '<span id="pdroom">'.$pdroom.'</span><span id="roomnote">'.$roomnote.'</span>'); $mform->addElement('static', 'addpdroom', '', '<input type="button" value="'.get_string('choosepredefinedroom', 'facetoface').'" name="show-addpdroom-dialog" id="show-addpdroom-dialog" />'); $mform->addElement('hidden', 'pdroomid', 0); $mform->setType('pdroomid', PARAM_INT); $mform->addElement('hidden', 'pdroomcapacity', 0); $mform->setType('pdroomcapacity', PARAM_INT); $mform->addElement('checkbox', 'customroom', '', get_string('otherroom', 'facetoface')); $mform->setType('customroom', PARAM_INT); $mform->disabledIf('customroom', 'datetimeknown', 'eq', 0); $mform->addElement('html', '<div class="fitem"><div class="fitemtitle"></div><table><tr><td>'); $mform->addElement('static', '', '', get_string('roomname', 'facetoface')); $mform->addElement('html', '</td><td>'); $mform->addElement('static', '', '', get_string('building', 'facetoface')); $mform->addElement('html', '</td><td>'); $mform->addElement('static', '', '', get_string('address', 'facetoface')); $mform->addElement('html', '</td><td>'); $mform->addElement('static', '', '', get_string('capacity', 'facetoface')); $mform->addElement('html', '</td></tr><td>'); $mform->addElement('text', 'croomname', array(), array('class' => 'cellwidth', 'maxlength' => '90')); $mform->setType('croomname', PARAM_TEXT); $mform->disabledIf('croomname', 'customroom', 'notchecked'); $mform->addElement('html', '</td><td>'); $mform->addElement('text', 'croombuilding', array(), array('class' => 'cellwidth', 'maxlength' => '90')); $mform->setType('croombuilding', PARAM_TEXT); $mform->disabledIf('croombuilding', 'customroom', 'notchecked'); $mform->addElement('html', '</td><td>'); $mform->addElement('text', 'croomaddress', array(), array('class' => 'cellwidth', 'maxlength' => '230')); $mform->setType('croomaddress', PARAM_TEXT); $mform->disabledIf('croomaddress', 'customroom', 'notchecked'); $mform->addElement('html', '</td><td>'); $mform->addElement('text', 'croomcapacity', array(), array('class' => 'cellwidth', 'maxlength' => '10')); $mform->disabledIf('croomcapacity', 'customroom', 'notchecked'); $mform->setType('croomcapacity', PARAM_INT); $mform->addElement('html', '</td><tr></table></div>'); $mform->addElement('text', 'capacity', get_string('capacity', 'facetoface'), 'size="5"'); $mform->addRule('capacity', null, 'required', null, 'client'); $mform->setType('capacity', PARAM_INT); $mform->setDefault('capacity', 10); $mform->addRule('capacity', null, 'numeric', null, 'client'); $mform->addHelpButton('capacity', 'capacity', 'facetoface'); $mform->addElement('checkbox', 'allowoverbook', get_string('allowoverbook', 'facetoface')); $mform->addHelpButton('allowoverbook', 'allowoverbook', 'facetoface'); $mform->addElement('text', 'duration', get_string('duration', 'facetoface'), 'size="5"'); $mform->setType('duration', PARAM_TEXT); $mform->addHelpButton('duration', 'duration', 'facetoface'); if (!get_config(NULL, 'facetoface_hidecost')) { $formarray = array(); $formarray[] = $mform->createElement('text', 'normalcost', get_string('normalcost', 'facetoface'), 'size="5"'); $formarray[] = $mform->createElement('static', 'normalcosthint', '', html_writer::tag('span', get_string('normalcosthinttext','facetoface'), array('class' => 'hint-text'))); $mform->addGroup($formarray,'normalcost_group', get_string('normalcost','facetoface'), array(' '),false); $mform->setType('normalcost', PARAM_TEXT); $mform->addHelpButton('normalcost_group', 'normalcost', 'facetoface'); if (!get_config(NULL, 'facetoface_hidediscount')) { $formarray = array(); $formarray[] = $mform->createElement('text', 'discountcost', get_string('discountcost', 'facetoface'), 'size="5"'); $formarray[] = $mform->createElement('static', 'discountcosthint', '', html_writer::tag('span', get_string('discountcosthinttext','facetoface'), array('class' => 'hint-text'))); $mform->addGroup($formarray,'discountcost_group', get_string('discountcost','facetoface'), array(' '),false); $mform->setType('discountcost', PARAM_TEXT); $mform->addHelpButton('discountcost_group', 'discountcost', 'facetoface'); } } $mform->addElement('editor', 'details_editor', get_string('details', 'facetoface'), null, $editoroptions); $mform->setType('details_editor', PARAM_RAW); $mform->addHelpButton('details_editor', 'details', 'facetoface'); // Choose users for trainer roles $context = context_course::instance($this->_customdata['course']->id); $roles = facetoface_get_trainer_roles($context); if ($roles) { // Get current trainers $current_trainers = facetoface_get_trainers($this->_customdata['s']); // Get course context and roles $rolenames = role_get_names($context); // Loop through all selected roles $header_shown = false; foreach ($roles as $role) { $rolename = format_string($rolenames[$role->id]->localname); // Attempt to load users with this role in this context. $rs = get_role_users($role->id, $context, true, 'u.id, u.firstname, u.lastname', 'u.id ASC'); if (!$rs) { continue; } $choices = array(); foreach ($rs as $roleuser) { $choices[$roleuser->id] = fullname($roleuser); } // Show header (if haven't already) if ($choices && !$header_shown) { $mform->addElement('header', 'trainerroles', get_string('sessionroles', 'facetoface')); $header_shown = true; } // If only a few, use checkboxes if (count($choices) < 4) { $role_shown = false; foreach ($choices as $cid => $choice) { // Only display the role title for the first checkbox for each role if (!$role_shown) { $roledisplay = $rolename; $role_shown = true; } else { $roledisplay = ''; } $mform->addElement('advcheckbox', 'trainerrole['.$role->id.']['.$cid.']', $roledisplay, $choice, null, array('', $cid)); $mform->setType('trainerrole['.$role->id.']['.$cid.']', PARAM_INT); } } else { $mform->addElement('select', 'trainerrole['.$role->id.']', $rolename, $choices, array('multiple' => 'multiple')); $mform->setType('trainerrole['.$role->id.']', PARAM_SEQUENCE); } // Select current trainers if ($current_trainers) { foreach ($current_trainers as $roleid => $trainers) { $t = array(); foreach ($trainers as $trainer) { $t[] = $trainer->id; $mform->setDefault('trainerrole['.$roleid.']['.$trainer->id.']', $trainer->id); } $mform->setDefault('trainerrole['.$roleid.']', implode(',', $t)); } } } } // If conflicts are disabled if (!empty($CFG->facetoface_allowschedulingconflicts)) { $mform->addElement('selectyesno', 'allowconflicts', get_string('allowschedulingconflicts', 'facetoface')); $mform->setDefault('allowconflicts', 0); // defaults to 'no' $mform->addHelpButton('allowconflicts', 'allowschedulingconflicts', 'facetoface'); $mform->setType('allowconflicts', PARAM_BOOL); } $this->add_action_buttons(); }
public function definition() { global $CFG, $DB; $mform =& $this->_form; // Course Module ID. $mform->addElement('hidden', 'id', $this->_customdata['id']); $mform->setType('id', PARAM_INT); // Facetoface Instance ID. $mform->addElement('hidden', 'f', $this->_customdata['f']); $mform->setType('f', PARAM_INT); // Facetoface Session ID. $mform->addElement('hidden', 's', $this->_customdata['s']); $mform->setType('s', PARAM_INT); // Copy Session Flag. $mform->addElement('hidden', 'c', $this->_customdata['c']); $mform->setType('c', PARAM_INT); $mform->addElement('header', 'general', get_string('general', 'form')); $editoroptions = $this->_customdata['editoroptions']; // Show all custom fields. $customfields = $this->_customdata['customfields']; facetoface_add_customfields_to_form($mform, $customfields); // Hack to put help files on these custom fields. // TODO: add to the admin page a feature to put help text on custom fields. if ($mform->elementExists('custom_location')) { $mform->addHelpButton('custom_location', 'location', 'facetoface'); } if ($mform->elementExists('custom_venue')) { $mform->addHelpButton('custom_venue', 'venue', 'facetoface'); } if ($mform->elementExists('custom_room')) { $mform->addHelpButton('custom_room', 'room', 'facetoface'); } $formarray = array(); $formarray[] = $mform->createElement('selectyesno', 'datetimeknown', get_string('sessiondatetimeknown', 'facetoface')); $formarray[] = $mform->createElement('static', 'datetimeknownhint', '', html_writer::tag('span', get_string('datetimeknownhinttext', 'facetoface'), array('class' => 'hint-text'))); $mform->addGroup($formarray, 'datetimeknown_group', get_string('sessiondatetimeknown', 'facetoface'), array(' '), false); $mform->addGroupRule('datetimeknown_group', null, 'required', null, 'client'); $mform->setDefault('datetimeknown', false); $mform->addHelpButton('datetimeknown_group', 'sessiondatetimeknown', 'facetoface'); $repeatarray = array(); $repeatarray[] =& $mform->createElement('hidden', 'sessiondateid', 0); $mform->setType('sessiondateid', PARAM_INT); $repeatarray[] =& $mform->createElement('date_time_selector', 'timestart', get_string('timestart', 'facetoface')); $repeatarray[] =& $mform->createElement('date_time_selector', 'timefinish', get_string('timefinish', 'facetoface')); $checkboxelement =& $mform->createElement('checkbox', 'datedelete', '', get_string('dateremove', 'facetoface')); unset($checkboxelement->_attributes['id']); // Necessary until MDL-20441 is fixed. $repeatarray[] = $checkboxelement; $repeatarray[] =& $mform->createElement('html', html_writer::empty_tag('br')); // Spacer. $repeatcount = $this->_customdata['nbdays']; $repeatoptions = array(); $repeatoptions['timestart']['disabledif'] = array('datetimeknown', 'eq', 0); $repeatoptions['timefinish']['disabledif'] = array('datetimeknown', 'eq', 0); $mform->setType('timestart', PARAM_INT); $mform->setType('timefinish', PARAM_INT); $this->repeat_elements($repeatarray, $repeatcount, $repeatoptions, 'date_repeats', 'date_add_fields', 1, get_string('dateadd', 'facetoface'), true); $mform->addElement('text', 'capacity', get_string('capacity', 'facetoface'), 'size="5"'); $mform->addRule('capacity', null, 'required', null, 'client'); $mform->setType('capacity', PARAM_INT); $mform->setDefault('capacity', 10); $mform->addHelpButton('capacity', 'capacity', 'facetoface'); $mform->addElement('checkbox', 'allowoverbook', get_string('allowoverbook', 'facetoface')); $mform->addHelpButton('allowoverbook', 'allowoverbook', 'facetoface'); $mform->addElement('text', 'duration', get_string('duration', 'facetoface'), 'size="5"'); $mform->setType('duration', PARAM_TEXT); $mform->addHelpButton('duration', 'duration', 'facetoface'); if (!get_config(null, 'facetoface_hidecost')) { $formarray = array(); $formarray[] = $mform->createElement('text', 'normalcost', get_string('normalcost', 'facetoface'), 'size="5"'); $formarray[] = $mform->createElement('static', 'normalcosthint', '', html_writer::tag('span', get_string('normalcosthinttext', 'facetoface'), array('class' => 'hint-text'))); $mform->addGroup($formarray, 'normalcost_group', get_string('normalcost', 'facetoface'), array(' '), false); $mform->setType('normalcost', PARAM_TEXT); $mform->addHelpButton('normalcost_group', 'normalcost', 'facetoface'); if (!get_config(null, 'facetoface_hidediscount')) { $formarray = array(); $formarray[] = $mform->createElement('text', 'discountcost', get_string('discountcost', 'facetoface'), 'size="5"'); $formarray[] = $mform->createElement('static', 'discountcosthint', '', html_writer::tag('span', get_string('discountcosthinttext', 'facetoface'), array('class' => 'hint-text'))); $mform->addGroup($formarray, 'discountcost_group', get_string('discountcost', 'facetoface'), array(' '), false); $mform->setType('discountcost', PARAM_TEXT); $mform->addHelpButton('discountcost_group', 'discountcost', 'facetoface'); } } $mform->addElement('editor', 'details_editor', get_string('details', 'facetoface'), null, $editoroptions); $mform->setType('details_editor', PARAM_RAW); $mform->addHelpButton('details_editor', 'details', 'facetoface'); // Choose users for trainer roles. $rolenames = facetoface_get_trainer_roles(); if ($rolenames) { // Get current trainers. $currenttrainers = facetoface_get_trainers($this->_customdata['s']); // Loop through all selected roles. $headershown = false; foreach ($rolenames as $role => $rolename) { $rolename = $rolename->name; // Get course context. $context = context_course::instance($this->_customdata['course']->id); // Attempt to load users with this role in this course. $usernamefields = get_all_user_name_fields(true); $rs = $DB->get_recordset_sql("\n SELECT\n u.id,\n {$usernamefields}\n FROM\n {role_assignments} ra\n LEFT JOIN\n {user} u\n ON ra.userid = u.id\n WHERE\n contextid = {$context->id}\n AND roleid = {$role}\n "); if (!$rs) { continue; } $choices = array(); foreach ($rs as $roleuser) { $choices[$roleuser->id] = fullname($roleuser); } $rs->close(); // Show header (if haven't already). if ($choices && !$headershown) { $mform->addElement('header', 'trainerroles', get_string('sessionroles', 'facetoface')); $headershown = true; } // If only a few, use checkboxes. if (count($choices) < 4) { $roleshown = false; foreach ($choices as $cid => $choice) { // Only display the role title for the first checkbox for each role. if (!$roleshown) { $roledisplay = $rolename; $roleshown = true; } else { $roledisplay = ''; } $mform->addElement('advcheckbox', 'trainerrole[' . $role . '][' . $cid . ']', $roledisplay, $choice, null, array('', $cid)); $mform->setType('trainerrole[' . $role . '][' . $cid . ']', PARAM_INT); } } else { $mform->addElement('select', 'trainerrole[' . $role . ']', $rolename, $choices, array('multiple' => 'multiple')); $mform->setType('trainerrole[' . $role . ']', PARAM_SEQUENCE); } // Select current trainers. if ($currenttrainers) { foreach ($currenttrainers as $role => $trainers) { $t = array(); foreach ($trainers as $trainer) { $t[] = $trainer->id; $mform->setDefault('trainerrole[' . $role . '][' . $trainer->id . ']', $trainer->id); } $mform->setDefault('trainerrole[' . $role . ']', implode(',', $t)); } } } } $this->add_action_buttons(); }