object_configuration_form_template.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Choice 1.0 configuration form.
  4. *
  5. * This is a fragment of HTML which gives the form elements for configuration of a choice object, v1.0.
  6. * ONLY the basic form elements should be included.
  7. * The "form" tags and submit button are already specified outside.
  8. * The $auth_obj and $sloodleauthid variables will identify the object being configured.
  9. *
  10. * @package sloodlechoice
  11. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  12. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  13. *
  14. * @contributor Peter R. Bloomfield
  15. * @contributor Edmund Edgar
  16. *
  17. */
  18. // IMPORTANT: make sure this is called from within a Sloodle script
  19. if (!defined('SLOODLE_VERSION')) {
  20. error('Not called from within a Sloodle script.');
  21. exit();
  22. }
  23. // Execute everything within a function to ensure we don't mess up the data in the other file
  24. sloodle_display_config_form($sloodleauthid, $auth_obj);
  25. function sloodle_display_config_form($sloodleauthid, $auth_obj)
  26. {
  27. //--------------------------------------------------------
  28. // SETUP
  29. $def = $auth_obj->objectDefinition();
  30. $fieldsets = $def->field_sets;
  31. $settings = $auth_obj->config_name_value_hash();
  32. if ($auth_obj->id > 0) {
  33. $def->populateDefaults( $settings );
  34. }
  35. $courseid = $auth_obj->course->get_course_id();
  36. if ( $module_choice = $def->module_choice($courseid) ) {
  37. // Historically, these forms have put the module choice under "General Configuration"
  38. // This seems wrong, but for now we'll levae it as it is.
  39. if (!isset($fieldsets['generalconfiguration'])) {
  40. $fieldsets = array_merge(array('generalconfiguration'=>array()), $fieldsets);
  41. }
  42. array_unshift($fieldsets['generalconfiguration'], $module_choice);
  43. }
  44. foreach($fieldsets as $fieldsetname => $fieldset) {
  45. sloodle_print_box_start('generalbox boxaligncenter');
  46. echo '<h3>'.get_string($fieldsetname,'sloodle').'</h3>';
  47. foreach($fieldset as $field) {
  48. echo get_string($field->title,'sloodle').': ';
  49. if ($field->type == 'yesno' ) {
  50. choose_from_menu_yesno($field->fieldname, $field->default);
  51. } else if ( ($options = $field->translatedOptions()) && is_array($options) ) {
  52. choose_from_menu($options, $field->fieldname, $field->default, '');
  53. } else {
  54. echo '<input type="text" name="'.$field->fieldname.'" value="'.htmlspecialchars( $field->default, ENT_QUOTES) .'" size="8" maxlength="8" />';
  55. }
  56. echo "<br><br>\n";
  57. }
  58. sloodle_print_box_end();
  59. }
  60. }
  61. ?>