index.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org)
  3. /**
  4. * Index page for listing all instances of the Sloodle module.
  5. * Used as an interface script by the Moodle framework.
  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. /** Sloodle/Moodle configuration script. */
  15. require_once('init.php');
  16. /** Sloodle core library functionality */
  17. require_once(SLOODLE_DIRROOT.'/lib.php');
  18. require_once(SLOODLE_DIRROOT.'/lib/io.php');
  19. // Fetch the course ID from request parameters
  20. $id = optional_param('id', 0, PARAM_INT);
  21. // Fetch the course data
  22. $course = null;
  23. if ($id) {
  24. if (! $course = sloodle_get_record("course", "id", $id)) {
  25. error("Course ID is incorrect");
  26. }
  27. } else {
  28. if (! $course = get_site()) {
  29. error("Could not find a top-level course!");
  30. }
  31. }
  32. // Require that the user logs in
  33. require_login($course, false);
  34. // Log this page view
  35. add_to_log($course->id, "sloodle", "view sloodle modules", "index.php?id=$course->id");
  36. // Fetch our string table data
  37. $strsloodle = get_string('modulename', 'sloodle');
  38. $strsloodles = get_string('modulenameplural', 'sloodle');
  39. $strid = get_string('ID', 'sloodle');
  40. $strname = get_string('name', 'sloodle');
  41. $strdescription = get_string('description');
  42. $strmoduletype = get_string('moduletype', 'sloodle');
  43. // Fetch the full names of each module type
  44. $sloodle_type_names = array();
  45. foreach ($SLOODLE_TYPES as $ST) {
  46. // Get the module type name
  47. $sloodle_type_names[$ST] = get_string("moduletype:$ST", 'sloodle');
  48. }
  49. // We're going to make one table for each module type
  50. $sloodle_tables = array();
  51. // Get all Sloodle modules for the current course
  52. $sloodles = sloodle_get_records('sloodle', 'course', $course->id, 'name');
  53. if (!$sloodles) $sloodles = array();
  54. // Go through each module
  55. foreach ($sloodles as $s) {
  56. // Find out which course module instance this SLOODLE module belongs to
  57. $cm = get_coursemodule_from_instance('sloodle', $s->id);
  58. if ($cm === false) continue;
  59. // Prepare this line of data
  60. $line = array();
  61. $line[] = "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?id={$cm->id}\">$s->name</a>";
  62. $line[] = $s->intro;
  63. // Insert it into the appropriate table
  64. $sloodle_tables[$s->type]->data[] = $line;
  65. }
  66. // Add header information to each table
  67. // (cannot use "foreach" on the $sloodle_tables array as PHP4 doesn't support alteration of the original array that way)
  68. $table_types = array_keys($sloodle_tables);
  69. foreach ($table_types as $k) {
  70. $sloodle_tables[$k]->head = array($strname, $strdescription);
  71. $sloodle_tables[$k]->align = array('left', 'left');
  72. $sloodle_tables[$k]->size = array('50%', '50%');
  73. }
  74. // Page header
  75. if ($course->id != SITEID) {
  76. sloodle_print_header("{$course->shortname}: $strsloodles", $course->fullname,
  77. "<a href=\"../../course/view.php?_type=course&amp;id=$course->id\">$course->shortname</a> -> $strsloodles",
  78. "", "", true, "", navmenu($course));
  79. } else {
  80. sloodle_print_header("$course->shortname: $strsloodles", $course->fullname, "$strsloodles",
  81. "", "", true, "", navmenu($course));
  82. }
  83. //-----------------------------------------------------
  84. // Quick links (top right of page)
  85. // Open the section
  86. /*echo "<div style=\"text-align:right; font-size:80%;\">\n";
  87. // Link to own avatar profile
  88. echo "<a href=\"\" title=\"\">View my avatar details</a><br>\n";
  89. // Course information
  90. if (empty($sloodlecourse->autoreg)) {
  91. echo "This course does not allow auto-registration<br>";
  92. } else {
  93. echo "This course allows auto-registration<br>";
  94. }
  95. // Display the link for editing course settings
  96. $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
  97. if (has_capability('moodle/course:update', $course_context)) {
  98. echo "<a href=\"\" title=\"\">Edit Sloodle course settings</a><br>\n";
  99. }
  100. echo "</div>\n";*/
  101. //-----------------------------------------------------
  102. // Make sure we got some results
  103. if (is_array($sloodle_tables) && count($sloodle_tables) > 0) {
  104. // Go through each Sloodle table
  105. foreach ($sloodle_tables as $type => $table) {
  106. // Output a heading for this type
  107. if (!array_key_exists($type, $sloodle_type_names)) $sloodle_type_names[$type] = get_string("moduletype:{$type}", 'sloodle');
  108. sloodle_print_heading($sloodle_type_names[$type], 'sloodle');
  109. // Display the table
  110. sloodle_print_table($table);
  111. }
  112. } else {
  113. sloodle_print_heading(get_string('noentries', 'sloodle'));
  114. }
  115. // Page footer
  116. sloodle_print_footer($course);
  117. ?>