course.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org)
  3. /**
  4. * Defines a class to render a view of SLOODLE course information.
  5. * Class is inherited from the base view class.
  6. *
  7. * @package sloodle
  8. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  9. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10. *
  11. * @contributor Peter R. Bloomfield
  12. *
  13. */
  14. /** The base view class */
  15. require_once(SLOODLE_DIRROOT.'/view/base/base_view.php');
  16. /** SLOODLE course data structure */
  17. require_once(SLOODLE_LIBROOT.'/course.php');
  18. /**
  19. * Class for rendering a view of SLOODLE course information.
  20. * @package sloodle
  21. */
  22. class sloodle_view_course extends sloodle_base_view
  23. {
  24. /**
  25. * The VLE course object, retrieved directly from database.
  26. * @var object
  27. * @access private
  28. */
  29. var $course = 0;
  30. /**
  31. * SLOODLE course object, retrieved directly from database.
  32. * @var object
  33. * @access private
  34. */
  35. var $sloodle_course = null;
  36. /**
  37. * Course context for Moodle permissions.
  38. * @var object
  39. * @access private
  40. */
  41. var $course_context = null;
  42. /**
  43. * Constructor.
  44. */
  45. function sloodle_view_course()
  46. {
  47. }
  48. /**
  49. * Check the request parameters to see which course was specified.
  50. */
  51. function process_request()
  52. {
  53. $id = required_param('id', PARAM_INT);
  54. if (!$this->course = sloodle_get_record('course', 'id', $id)) error('Could not find course.');
  55. $this->sloodle_course = new SloodleCourse();
  56. if (!$this->sloodle_course->load($this->course)) error(get_string('failedcourseload', 'sloodle'));
  57. }
  58. /**
  59. * Check that the user is logged-in and has permission to alter course settings.
  60. */
  61. function check_permission()
  62. {
  63. // Ensure the user logs in
  64. require_login($this->course->id);
  65. if (isguestuser()) error(get_string('noguestaccess', 'sloodle'));
  66. add_to_log($this->course->id, 'course', 'view sloodle data', '', "{$this->course->id}");
  67. // Ensure the user is allowed to update information on this course
  68. $this->course_context = get_context_instance(CONTEXT_COURSE, $this->course->id);
  69. require_capability('moodle/course:update', $this->course_context);
  70. }
  71. /**
  72. * Print the course settings page header.
  73. */
  74. function sloodle_print_header()
  75. {
  76. global $CFG;
  77. $navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=course&id={$this->course->id}\">".get_string('courseconfig', 'sloodle')."</a>";
  78. sloodle_print_header_simple(get_string('courseconfig','sloodle'), "&nbsp;", $navigation, "", "", true, '', navmenu($this->course));
  79. }
  80. /**
  81. * Render the view of the module or feature.
  82. * This MUST be overridden to provide functionality.
  83. */
  84. function render()
  85. {
  86. global $CFG;
  87. // Fetch string table text
  88. $strsloodle = get_string('modulename', 'sloodle');
  89. $strsloodles = get_string('modulenameplural', 'sloodle');
  90. $strsavechanges = get_string('savechanges');
  91. $stryes = get_string('yes');
  92. $strno = get_string('no');
  93. $strenabled = get_string('enabled','sloodle');
  94. $strdisabled = get_string('disabled','sloodle');
  95. $strsubmit = get_string('submit', 'sloodle');
  96. //------------------------------------------------------
  97. // If the form has been submitted, then process the input
  98. if (isset($_REQUEST['submit_course_options'])) {
  99. // Get the parameters
  100. $form_autoreg = required_param('autoreg', PARAM_BOOL);
  101. $form_autoenrol = required_param('autoenrol', PARAM_BOOL);
  102. // Update the Sloodle course object
  103. if ($form_autoreg) $this->sloodle_course->enable_autoreg();
  104. else $this->sloodle_course->disable_autoreg();
  105. if ($form_autoenrol) $this->sloodle_course->enable_autoenrol();
  106. else $this->sloodle_course->disable_autoenrol();
  107. // Update the database
  108. if ($this->sloodle_course->write()) {
  109. redirect("view.php?_type=course&id={$this->course->id}", get_string('changessaved'), 4);
  110. exit();
  111. } else {
  112. sloodle_print_box(get_string('error'), 'generalbox boxwidthnarrow boxaligncenter');
  113. }
  114. }
  115. //------------------------------------------------------
  116. // Display info about Sloodle course configuration
  117. echo "<h1 style=\"text-align:center;\">".get_string('courseconfig','sloodle')."</h1>\n";
  118. echo "<h2 style=\"text-align:center;\">(".get_string('course').": \"<a href=\"{$CFG->wwwroot}/course/view.php?id={$this->course->id}\">".$this->sloodle_course->get_full_name()."</a>\")</h2>";
  119. sloodle_print_box(get_string('courseconfig:info','sloodle'), 'generalbox boxaligncenter boxwidthnormal');
  120. echo "<br/>\n";
  121. // Get the initial form values
  122. $val_autoreg = (int)(($this->sloodle_course->get_autoreg()) ? 1 : 0);
  123. $val_autoenrol = (int)(($this->sloodle_course->get_autoenrol()) ? 1 : 0);
  124. // Make the selection options for enabling/disabling items
  125. $selection_menu = array(0 => $strdisabled, 1 => $strenabled);
  126. // Start the box
  127. sloodle_print_box_start('generalbox boxaligncenter boxwidthnormal');
  128. echo '<div style="text-align:center;"><h3>'.get_string('coursesettings','sloodle').'</h3>';
  129. // Start the form (including a course ID hidden parameter)
  130. echo "<form action=\"view.php\" method=\"post\">\n";
  131. echo "<input type=\"hidden\" name=\"id\" value=\"{$this->course->id}\">\n";
  132. echo "<input type=\"hidden\" name=\"_type\" value=\"course\">\n";
  133. // AUTO REGISTRATION //
  134. echo "<p>\n";
  135. sloodle_helpbutton('auto_registration', get_string('help:autoreg','sloodle'), 'sloodle', true, false, '', false);
  136. echo get_string('autoreg', 'sloodle').': ';
  137. choose_from_menu($selection_menu, 'autoreg', $val_autoreg, '', '', 0, false);
  138. // Add the site status
  139. if (!sloodle_autoreg_enabled_site()) echo '<br/>&nbsp;<span style="color:red; font-style:italic; font-size:80%;">('.get_string('autoreg:disabled','sloodle').')</span>';
  140. echo "</p>\n";
  141. // AUTO ENROLMENT //
  142. echo "<p>\n";
  143. sloodle_helpbutton('auto_enrolment', get_string('help:autoenrol','sloodle'), 'sloodle', true, false, '', false);
  144. echo get_string('autoenrol', 'sloodle').': ';
  145. choose_from_menu($selection_menu, 'autoenrol', $val_autoenrol, '', '', 0, false);
  146. // Add the site status
  147. if (!sloodle_autoenrol_enabled_site()) echo '<br/>&nbsp;<span style="color:red; font-style:italic; font-size:80%;">('.get_string('autoenrol:disabled','sloodle').')</span>';
  148. echo '</p>';
  149. // Close the form, along with a submit button
  150. echo "<input type=\"submit\" value=\"$strsubmit\" name=\"submit_course_options\"\>\n</form>\n";
  151. // Finish the box
  152. echo '</div>';
  153. sloodle_print_box_end();
  154. //------------------------------------------------------
  155. // Loginzone information
  156. sloodle_print_box_start('generalbox boxaligncenter boxwidthnarrow');
  157. echo '<div style="text-align:center;"><h3>'.get_string('loginzonedata','sloodle').'</h3>';
  158. $lastupdated = '('.get_string('unknown','sloodle').')';
  159. if ($this->sloodle_course->get_loginzone_time_updated() > 0) $lastupdated = date('Y-m-d H:i:s', $this->sloodle_course->get_loginzone_time_updated());
  160. echo get_string('position','sloodle').': '.$this->sloodle_course->get_loginzone_position().'<br>';
  161. echo get_string('size','sloodle').': '.$this->sloodle_course->get_loginzone_size().'<br>';
  162. echo get_string('region','sloodle').': '.$this->sloodle_course->get_loginzone_region().'<br>';
  163. echo get_string('lastupdated','sloodle').': '.$lastupdated.'<br>';
  164. echo '<br>';
  165. // Have we been instructed to clear all pending allocations?
  166. if (isset($_REQUEST['clear_loginzone_allocations'])) {
  167. // Delete all allocations relating to this course
  168. sloodle_delete_records('sloodle_loginzone_allocation', 'course', $this->course->id);
  169. }
  170. // Create a form
  171. echo "<form action=\"view.php\" method=\"POST\">\n";
  172. echo "<input type=\"hidden\" name=\"id\" value=\"{$this->course->id}\">\n";
  173. echo "<input type=\"hidden\" name=\"_type\" value=\"course\">\n";
  174. // Determine how many allocations there are for this course
  175. $allocs = sloodle_count_records('sloodle_loginzone_allocation', 'course', $this->course->id);
  176. echo get_string('pendingallocations','sloodle').': '.$allocs.'&nbsp;&nbsp;';
  177. echo '<input type="submit" name="clear_loginzone_allocations" value="'.get_string('delete','sloodle').'"/>';
  178. echo "</form>\n";
  179. echo '</div>';
  180. sloodle_print_box_end();
  181. //------------------------------------------------------
  182. $course = $this->course;
  183. }
  184. /**
  185. * Print the footer for this course.
  186. */
  187. function sloodle_print_footer()
  188. {
  189. global $CFG;
  190. echo "<p style=\"text-align:center; margin-top:32px; font-size:90%;\"><a href=\"{$CFG->wwwroot}/course/view.php?id={$this->course->id}\">&lt;&lt;&lt; ".get_string('backtocoursepage','sloodle')."</a></h2>";
  191. sloodle_print_footer($this->course);
  192. }
  193. }
  194. ?>