Source for file view.php

Documentation is available at view.php

  1. <?php
  2.     // This file is part of the Sloodle project (www.sloodle.org)
  3.  
  4.     /**
  5.     * Index page for listing a particular 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.     /** General Sloodle functions. */
  21.     require_once(SLOODLE_LIBROOT.'/general.php');
  22.     /** Sloodle course data. */
  23.     require_once(SLOODLE_LIBROOT.'/course.php');
  24.     
  25.     /** Viewing functionality for the Sloodle Controller. */
  26.     require_once(SLOODLE_DIRROOT.'/view/view_controller.php');
  27.     /** Viewing functionality for the Distributor. */
  28.     require_once(SLOODLE_DIRROOT.'/view/view_distributor.php');    
  29.     
  30.     
  31.  
  32.     // Fetch our request parameters
  33.     $id optional_param('id'0PARAM_INT)// Course Module instance ID
  34.     $s optional_param('s'0PARAM_INT)// Sloodle instance ID
  35.     $editing optional_param('edit'0PARAM_BOOL)// Editing mode
  36.     $formsubmit optional_param('formsubmit'0PARAM_BOOL)// Form submission
  37.     
  38.     
  39.     // Fetch string table text
  40.     $strsloodle get_string('modulename''sloodle');
  41.     $strsloodles get_string('modulenameplural''sloodle');
  42.     $strsavechanges get_string('savechanges');
  43.     $stryes get_string('yes');
  44.     $strno get_string('no');
  45.         
  46.     // Attempt to fetch the course module instance
  47.     if ($id{
  48.         if ($cm get_coursemodule_from_id('sloodle'$id)) {
  49.             error("Course Module ID was incorrect");
  50.         }
  51.     else if ($s{       
  52.         if ($cm get_coursemodule_from_instance('sloodle'$s)) {
  53.             error("Instance ID was incorrect");
  54.         }
  55.     else {
  56.         error('Must specify a course module or a module instance');
  57.     }
  58.     
  59.     // Get the course data
  60.     if ($course get_record("course""id"$cm->course)) {
  61.         error("Course is misconfigured");
  62.     }
  63.     // Get the Sloodle instance
  64.     if ($sloodle get_record('sloodle''id'$cm->instance)) {
  65.         error('Failed to find Sloodle module instance.');
  66.     }
  67.     
  68.     // Get the Sloodle course data
  69.     $sloodle_course new SloodleCourse();
  70.     if (!$sloodle_course->load($course)) error(get_string('failedcourseload','sloodle'));
  71.     
  72.     // Ensure that the user is logged-in for this course
  73.     require_course_login($coursetrue$cm);
  74.     $module_context get_context_instance(CONTEXT_MODULE$cm->id);
  75.     $course_context get_context_instance(CONTEXT_COURSE$course->id);
  76.     
  77.     // Is the user allowed to edit the module?
  78.     $canedit false;
  79.     if (has_capability('moodle/course:manageactivities'$module_context)) {
  80.         $canedit true;
  81.     else {
  82.         $editing false;
  83.     }
  84.     
  85.     // Only show the editing button if the user is allowed to edit this stuff
  86.     $editbuttons '';
  87.     if ($canedit$editbuttons $buttontext update_module_button($cm->id$course->id$strsloodle);
  88.  
  89.     // Display the page header
  90.     $navigation "<a href=\"index.php?id=$course->id\">$strsloodles</a> ->";
  91.     print_header_simple(format_string($sloodle->name)"""$navigation ".format_string($sloodle->name)""""true$editbuttonsnavmenu($course$cm));
  92.  
  93.     // We can display the Sloodle module info... log the view
  94.     add_to_log($course->id'sloodle''view sloodle module'"view.php?id=$cm->id""$sloodle->id"$cm->id);
  95.     
  96.     // Get the full Sloodle module type name
  97.     $fulltypename get_string("moduletype:{$sloodle->type}"'sloodle');
  98.     
  99.     
  100.     
  101. //-----------------------------------------------------
  102.     // Quick links and other info (top right of page)
  103.     
  104.     // Open the section
  105.     echo "<div style=\"text-align:right; font-size:80%;\">\n";
  106.     
  107.     // Link to own avatar profile
  108.     echo "<a href=\"{$CFG->wwwroot}/mod/sloodle/view/view_user.php?id={$USER->id}&course={$course->id}\">".get_string('viewmyavatar''sloodle')."</a><br>\n";
  109.     // Link to user management
  110.     if (has_capability('moodle/user:viewdetails'$course_context)) {
  111.         echo "<a href=\"{$CFG->wwwroot}/mod/sloodle/view/view_users.php?course={$course->id}\">".get_string('sloodleuserprofiles''sloodle')."</a><br>\n";
  112.     }
  113.     
  114.     // Auto-registration status
  115.     if (!sloodle_autoreg_enabled_site()) {
  116.         echo '<span style="color:#aa0000;">'.get_string('autoreg:disabled','sloodle')."</span><br>\n";
  117.     else if ($sloodle_course->get_autoreg()) {
  118.         echo '<span style="color:#008800;">'.get_string('autoreg:courseallows','sloodle')."</span><br>\n";
  119.     else {
  120.         echo '<span style="color:#aa0000;">'.get_string('autoreg:coursedisallows','sloodle')."</span><br>\n";
  121.     }
  122.     
  123.     // Auto-enrolment status
  124.     if (!sloodle_autoenrol_enabled_site()) {
  125.         echo '<span style="color:#aa0000;">'.get_string('autoenrol:disabled','sloodle')."</span><br>\n";
  126.     else if ($sloodle_course->get_autoenrol()) {
  127.         echo '<span style="color:#008800;">'.get_string('autoenrol:courseallows','sloodle')."</span><br>\n";
  128.     else {
  129.         echo '<span style="color:#aa0000;">'.get_string('autoenrol:coursedisallows','sloodle')."</span><br>\n";
  130.     }
  131.     
  132.     // Display the link for editing course settings
  133.     if (has_capability('moodle/course:update'$course_context)) {
  134.         echo "<a href=\"{$CFG->wwwroot}/mod/sloodle/view/view_course.php?id={$course->id}\">Edit Sloodle course settings</a><br>\n";
  135.     }
  136.     
  137.     
  138.     echo "</div>\n";
  139.     
  140.     
  141.     
  142. //-----------------------------------------------------
  143.     // Check access
  144.  
  145.     // If the module is hidden, then can the user still view it?
  146.     if (empty($cm->visibleand !has_capability('moodle/course:viewhiddenactivities'$module_context)) {
  147.         // No - issue a notice
  148.         notice(get_string("activityiscurrentlyhidden"));
  149.     }
  150.     
  151.     
  152. //-----------------------------------------------------
  153.     // Module info
  154.  
  155.     // Display the module name
  156.     $img '<img src="icon.gif" width="16" height="16" alt=""/> ';
  157.     print_heading($img.$sloodle->name'center');
  158.     
  159.     // Display the module type and description
  160.     echo '<h4 style="text-align:center;">'.get_string('moduletype''sloodle').': '.$fulltypename;
  161.     echo helpbutton("moduletype_{$sloodle->type}"$fulltypename'sloodle'truefalse''true).'</h4>';
  162.     
  163.     //print_box_start('generalbox boxaligncenter boxwidthnormal', '');
  164.     //echo '<p style="text-align:center;">'.$sloodle->intro.'</p>';
  165.     //print_box_end();
  166.     print_box($sloodle->intro'generalbox''intro')// Let's be consistent with other modules!
  167.     
  168.     
  169. //-----------------------------------------------------
  170.     // Main view
  171.  
  172.     print_box_start('generalbox boxaligncenter boxwidthwide');
  173.  
  174.     // We need to kow the result of the display attempt
  175.     $result false;
  176.     // Check what type the module is
  177.     switch ($sloodle->type{
  178.     case SLOODLE_TYPE_CTRL:
  179.         $result sloodle_view_controller($cm$sloodle$canedit);
  180.         break;
  181.         
  182.     case SLOODLE_TYPE_DISTRIB:
  183.         $result sloodle_view_distributor($cm$sloodle$canedit);
  184.         break;
  185.         
  186.     default:
  187.         // Unknown type
  188.         notice(get_string('moduletypeunknown'));
  189.         break;
  190.     }
  191.     
  192.     // Were we able to display the information?
  193.     if (!$resultnotice(get_string('error'));
  194.     
  195.     print_box_end();
  196.     
  197.     print_footer($course);
  198.     
  199. ?>

Documentation generated on Mon, 16 Jun 2008 15:57:07 +0100 by phpDocumentor 1.4.0