Source for file index.php

Documentation is available at index.php

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

Documentation generated on Mon, 16 Jun 2008 15:56:22 +0100 by phpDocumentor 1.4.0