store_object_config.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Sloodle object configuration storage script.
  4. *
  5. * When passed a list of object configuration settings, it will store them.
  6. * User must be logged-in and authorised to manage activities on the specified course.
  7. *
  8. * @package sloodleclassroom
  9. * @copyright Copyright (c) 2007-8 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. // The following parameter is required:
  16. //
  17. // sloodleauthid = identifies which authorisation (active obejct) entry is being configured
  18. //
  19. // All other parameters which start with "sloodle", except for "sloodledebug", are treated
  20. // as configuration settings and stored accordingly.
  21. //
  22. /** Include the Sloodle/Moodle configuration. */
  23. require_once('../init.php');
  24. /** Include the Sloodle API. */
  25. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  26. // Make sure the user is logged-in and is not a guest
  27. if (isloggedin() == false || isguestuser() == true) {
  28. error(get_string('noguestaccess','sloodle'));
  29. exit();
  30. }
  31. // We need to know which object is being configured
  32. $sloodleauthid = required_param('sloodleauthid', PARAM_INT);
  33. $auth_obj = SloodleController::get_object($sloodleauthid);
  34. if (!$auth_obj) {
  35. error(get_string('objectauthnotfound','sloodle'));
  36. exit();
  37. }
  38. // Make sure the object is authorised
  39. if ($auth_obj->course->controller->is_loaded() == false) {
  40. //TODO: more appropriate error message?
  41. error(get_string('objectauthnotfound','sloodle'));
  42. exit();
  43. }
  44. // Make sure the user has permission to manage activities on this course
  45. $course_context = get_context_instance(CONTEXT_COURSE, $auth_obj->course->get_course_id());
  46. require_capability('moodle/course:manageactivities', $course_context);
  47. // Delete all configuration options already associated with the object
  48. sloodle_delete_records('sloodle_object_config', 'object', $sloodleauthid);
  49. // Define parameter names we will ignore
  50. $IGNORE_PARAMS = array('sloodleauthid', 'sloodledebug');
  51. // This structure will store our values
  52. $config_setting = new stdClass();
  53. $config_setting->object = $sloodleauthid;
  54. // Add the new ones
  55. $numstored = 0;
  56. foreach ($_REQUEST as $k => $v) {
  57. // Ignore anything which does not start with "sloodle"
  58. if (strpos($k, 'sloodle') !== 0) continue;
  59. // Ignore certain parameters
  60. if (in_array($k, $IGNORE_PARAMS)) continue;
  61. // Store the setting
  62. $config_setting->name = $k;
  63. $config_setting->value = $v;
  64. if (sloodle_insert_record('sloodle_object_config', $config_setting)) {
  65. $numstored++;
  66. }
  67. }
  68. // Construct a breadcrumb navigation menu
  69. $nav = get_string('modulename', 'sloodle').' -> ';
  70. $nav .= get_string('objectconfiguration','sloodle');
  71. // Display the page header
  72. sloodle_print_header(get_string('objectconfiguration','sloodle'), get_string('objectconfiguration','sloodle'), $nav, '', '', false);
  73. // Display the information about the object
  74. sloodle_print_box_start('generalbox boxaligncenter boxwidthnarrow');
  75. echo '<div style="text-align:center;">';
  76. echo '<span style="font-weight:bold; font-size:110%;">'.get_string('objectdetails','sloodle').'</span><br>';
  77. echo get_string('objectname','sloodle').': '.$auth_obj->name.'<br>';
  78. echo get_string('objectuuid','sloodle').': '.$auth_obj->uuid.'<br>';
  79. echo get_string('objecttype','sloodle').': '.$auth_obj->type.'<br>';
  80. echo get_string('authorizedfor', 'sloodle').$auth_obj->course->get_full_name().' &gt; '.$auth_obj->course->controller->get_name().'<br>';
  81. // Indicate how many settings were stored
  82. echo '<br><span style="font-weight:bold;">';
  83. print_string('numsettingsstored','sloodle');
  84. echo " $numstored</span><br>\n";
  85. echo '</div>';
  86. sloodle_print_box_end();
  87. echo '<br>';
  88. // Print a continue button, to go back to the course
  89. echo '<div style="text-align:center;">';
  90. echo "<form action=\"{$CFG->wwwroot}/course/view.php\" method=\"GET\">";
  91. echo '<input type="hidden" name="id" value="'.$auth_obj->course->get_course_id().'"/>';
  92. echo '<input type="submit" value="'.get_string('continue').'"/>';
  93. echo '</form></div>';
  94. sloodle_print_footer();
  95. ?>