notecard_configuration_form.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org)
  3. /**
  4. * This page lets an educator/admin create a configuration notecard.
  5. * It will be accessed by a link from a Controller page, and will
  6. * display a form based on scripts in the Sloodle "mod" folder.
  7. *
  8. * @package sloodle
  9. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  10. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11. *
  12. * @contributor Peter R. Bloomfield
  13. *
  14. */
  15. /** Sloodle/Moodle configuration script. */
  16. require_once('../init.php');
  17. /** Sloodle core library functionality */
  18. require_once(SLOODLE_DIRROOT.'/lib.php');
  19. /** Sloodle API. */
  20. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  21. require_once(SLOODLE_LIBROOT.'/active_object.php');
  22. require_once(SLOODLE_LIBROOT.'/object_configs.php');
  23. // Fetch our required parameters
  24. $sloodlecontrollerid = required_param('sloodlecontrollerid', PARAM_INT);
  25. $sloodleobjtype = required_param('sloodleobjtype', PARAM_TEXT);
  26. // Fetch string table text
  27. $strsloodle = get_string('modulename', 'sloodle');
  28. $strsloodles = get_string('modulenameplural', 'sloodle');
  29. $pagename = get_string('objectconfig:header', 'sloodle');
  30. $strsavechanges = get_string('savechanges');
  31. $stryes = get_string('yes');
  32. $strno = get_string('no');
  33. // Attempt to fetch the course module instance
  34. if (! $cm = get_coursemodule_from_id('sloodle', $sloodlecontrollerid)) {
  35. error("Failed to load course module");
  36. }
  37. // Get the course data
  38. if (! $course = sloodle_get_record("course", "id", $cm->course)) {
  39. error("Course is misconfigured");
  40. }
  41. // Get the Sloodle instance
  42. if (! $sloodle = sloodle_get_record('sloodle', 'id', $cm->instance)) {
  43. error('Failed to find Sloodle module instance.');
  44. }
  45. // Get the Sloodle course data
  46. $sloodle_course = new SloodleCourse();
  47. if (!$sloodle_course->load($course)) error(get_string('failedcourseload','sloodle'));
  48. if (!$sloodle_course->controller->load($sloodlecontrollerid)) error('Failed to load Sloodle Controller.');
  49. // Ensure that the user is logged-in for this course
  50. require_course_login($course, true, $cm);
  51. // Is the user allowed to edit the module?
  52. $module_context = get_context_instance(CONTEXT_MODULE, $cm->id);
  53. $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
  54. require_capability('moodle/course:manageactivities', $module_context);
  55. // Display the page header
  56. //$navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id=$course->id\">$strsloodles</a> ->";
  57. $navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?id=$sloodlecontrollerid\">".format_string($sloodle->name)."</a> ->";
  58. sloodle_print_header_simple($pagename, "&nbsp;", "$navigation ". $pagename, "", "", true, '', navmenu($course, $cm));
  59. // We can display the Sloodle module info... log the view
  60. add_to_log($course->id, 'sloodle', 'view sloodle config', "classroom/notecard_configuration.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype", $sloodleobjtype, $cm->id);
  61. // Make sure the object type is recognised
  62. $objectpath = SLOODLE_DIRROOT."/mod/$sloodleobjtype";
  63. if (!file_exists($objectpath)) error("ERROR: object \"$sloodleobjtype\" is not installed.");
  64. // Determine if we have a custom configuration page
  65. // Split up the object identifier into name and version number, then get the translated name
  66. list($objectname, $objectversion) = SloodleObjectConfig::ParseModIdentifier($sloodleobjtype);
  67. $strobjectname = get_string("object:$objectname", 'sloodle');
  68. //---------------------------------------------------------------------------------
  69. // Display intro information
  70. sloodle_print_box_start('generalbox boxwidthwide boxaligncenter');
  71. echo '<div style="text-align:center;">';
  72. echo "<h1>$pagename</h1>";
  73. echo "<h2>$strobjectname $objectversion</h2>";
  74. // Display our configuration form
  75. echo '<form action="'.SLOODLE_WWWROOT.'/classroom/notecard_configuration_view.php" method="POST">';
  76. echo '<input type="hidden" name="formsubmitted" value="true">';
  77. // We need to create some dummy data for the form
  78. // (basically pretend we have an authorised object, and hope nobody tries to use the missing data anywhere!)
  79. // (not the best idea, I know, but the notecard stuff was added late... :-\)
  80. $sloodleauthid = 0;
  81. $auth_obj = new SloodleActiveObject();
  82. $auth_obj->course = $sloodle_course;
  83. $auth_obj->type = $sloodleobjtype;
  84. $hascustomconfig = $auth_obj->has_custom_config();
  85. // Are there any custom configuration options?
  86. if ($hascustomconfig) {
  87. // TODO: Do I really need all this?
  88. $dummysession = new SloodleSession(false);
  89. $dummysession->user->load_user($USER->id);
  90. $dummysession->user->load_linked_avatar();
  91. $auth_obj->user = $dummysession->user;
  92. include('object_configuration_form_template.php');
  93. // Include the form elements
  94. //require($customconfig);
  95. } else {
  96. // No configuration settings for this object
  97. print_string('noobjectconfig','sloodle');
  98. echo '<br><br>';
  99. }
  100. // Add our other necessary form elements
  101. echo '<input type="hidden" name="sloodlecontrollerid" value="'.$sloodlecontrollerid.'">';
  102. echo '<input type="hidden" name="sloodleobjtype" value="'.$sloodleobjtype.'">';
  103. echo '<input type="submit" value="'.get_string('cfgnotecard:generate','sloodle').'">';
  104. echo '</form>';
  105. echo '</div>';
  106. sloodle_print_box_end();
  107. //---------------------------------------------------------------------------------
  108. sloodle_print_footer();
  109. ?>