notecard_configuration_view.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org)
  3. /**
  4. * This page lets an educator/admin view a configuration notecard.
  5. * The data will first arrive as POST data, but will be converted
  6. * over to SESSION data, and the page reloaded.
  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. // Fetch our required parameters
  22. $sloodlecontrollerid = required_param('sloodlecontrollerid', PARAM_INT);
  23. $sloodleobjtype = required_param('sloodleobjtype', PARAM_TEXT);
  24. // Has HTTP form data been submitted?
  25. if (isset($_REQUEST['formsubmitted'])) {
  26. // Convert all the form data to session data
  27. foreach ($_REQUEST as $k => $v) {
  28. // Ignore anything that doesn't start with 'sloodle'
  29. if (strpos($k, 'sloodle') !== 0) {
  30. continue;
  31. }
  32. // Store it in session data
  33. $_SESSION[$k] = $v;
  34. }
  35. // Make sure we know about the form in session data
  36. $_SESSION['formsubmitted'] = true;
  37. // Reload this page
  38. redirect("{$CFG->wwwroot}/mod/sloodle/classroom/notecard_configuration_view.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype");
  39. exit();
  40. } else if (!isset($_SESSION['formsubmitted'])) {
  41. // No, and there is no session form data either.
  42. // Re-direct back to the notecard page
  43. redirect("{$CFG->wwwroot}/mod/sloodle/classroom/notecard_configuration_form.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype");
  44. exit();
  45. }
  46. // Clear the form submission
  47. unset($_SESSION['formsubmitted']);
  48. // Fetch string table text
  49. $strsloodle = get_string('modulename', 'sloodle');
  50. $strsloodles = get_string('modulenameplural', 'sloodle');
  51. $pagename = get_string('cfgnotecard:header', 'sloodle');
  52. $strsavechanges = get_string('savechanges');
  53. $stryes = get_string('yes');
  54. $strno = get_string('no');
  55. // Attempt to fetch the course module instance
  56. if (! $cm = get_coursemodule_from_id('sloodle', $sloodlecontrollerid)) {
  57. error("Failed to load course module");
  58. }
  59. // Get the course data
  60. if (! $course = sloodle_get_record("course", "id", $cm->course)) {
  61. error("Course is misconfigured");
  62. }
  63. // Get the Sloodle instance
  64. if (! $sloodle = sloodle_get_record('sloodle', 'id', $cm->instance)) {
  65. error('Failed to find Sloodle module instance.');
  66. }
  67. // Get the Sloodle course data
  68. $sloodle_course = new SloodleCourse();
  69. if (!$sloodle_course->load($course)) error(get_string('failedcourseload','sloodle'));
  70. if (!$sloodle_course->controller->load($sloodlecontrollerid)) error('Failed to load Controller data');
  71. // Ensure that the user is logged-in for this course
  72. require_course_login($course, true, $cm);
  73. // Is the user allowed to edit the module?
  74. $module_context = get_context_instance(CONTEXT_MODULE, $cm->id);
  75. $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
  76. require_capability('moodle/course:manageactivities', $module_context);
  77. // Display the page header
  78. //$navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id=$course->id\">$strsloodles</a> ->";
  79. $navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?id=$sloodlecontrollerid\">".format_string($sloodle->name)."</a> ->";
  80. sloodle_print_header_simple($pagename, "&nbsp;", "$navigation ". $pagename, "", "", true, '', navmenu($course, $cm));
  81. // We can display the Sloodle module info... log the view
  82. add_to_log($course->id, 'sloodle', 'view sloodle config', "classroom/notecard_configuration.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype", $sloodleobjtype, $cm->id);
  83. // Make sure the object type is recognised
  84. $objectpath = SLOODLE_DIRROOT."/mod/$sloodleobjtype";
  85. if (!file_exists($objectpath)) error("ERROR: object \"$sloodleobjtype\" is not installed.");
  86. // Determine if we have a custom configuration page
  87. $customconfig = $objectpath.'/object_config.php';
  88. $hascustomconfig = file_exists($customconfig);
  89. // Split up the object identifier into name and version number, then get the translated name
  90. list($objectname, $objectversion) = SloodleObjectConfig::ParseModIdentifier($sloodleobjtype);
  91. $strobjectname = get_string("object:$objectname", 'sloodle');
  92. //---------------------------------------------------------------------------------
  93. // Display intro information
  94. sloodle_print_box_start('generalbox boxwidthwide boxaligncenter');
  95. echo '<div style="text-align:center;">';
  96. echo "<h1>$pagename</h1>";
  97. echo "<h2>$strobjectname $objectversion</h2>";
  98. print_string('cfgnotecard:instructions', 'sloodle');
  99. echo '<br><br>';
  100. print_string('cfgnotecard:security', 'sloodle');
  101. echo '<br><br><br>';
  102. // Fetch all our custom configuration settings into a separate array
  103. $customsettings = array();
  104. if (count($_SESSION) > 0) {
  105. foreach ($_SESSION as $k => $v) {
  106. // Ignore anything that doesn't start with 'sloodle'
  107. if (strpos($k, 'sloodle') !== 0) continue;
  108. // Ignore anything we will add in later
  109. if ($k != 'sloodleobjtype' && $k != 'sloodlecontrollerid') $customsettings[$k] = $v;
  110. // Remove the setting so it doesn't appear later
  111. unset($_SESSION[$k]);
  112. }
  113. }
  114. // Figure out how many lines we need
  115. $numlines = count($customsettings) + 6;
  116. // The configuration text
  117. echo '<textarea cols="60" rows="'.$numlines.'" readonly="true" onclick="">';
  118. // Add the standard stuff in
  119. echo "set:sloodleobjtype|$sloodleobjtype\n";
  120. echo "set:sloodleserverroot|{$CFG->wwwroot}\n";
  121. echo "set:sloodlecontrollerid|$sloodlecontrollerid\n";
  122. echo "set:sloodlepwd|".$sloodle_course->controller->get_password()."\n";
  123. echo "set:sloodlecoursename_short|".$sloodle_course->get_short_name()."\n";
  124. echo "set:sloodlecoursename_full|".$sloodle_course->get_full_name()."\n";
  125. // Go through each session parameter
  126. foreach ($customsettings as $k => $v) {
  127. // Output the value
  128. echo "set:$k|$v\n";
  129. }
  130. echo '</textarea><br><br>';
  131. echo "<a href=\"notecard_configuration_form.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype\">&lt;&lt; ".get_string('objectconfig:backtoform','sloodle')."</a>";
  132. echo '</div>';
  133. sloodle_print_box_end();
  134. //---------------------------------------------------------------------------------
  135. sloodle_print_footer();
  136. ?>