Source for file course.php

Documentation is available at course.php

  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.  
  15. /** The base view class */
  16. require_once(SLOODLE_DIRROOT.'/view/base/base_view.php');
  17. /** SLOODLE course data structure */
  18. require_once(SLOODLE_LIBROOT.'/course.php');
  19.  
  20. /**
  21. * Class for rendering a view of SLOODLE course information.
  22. @package sloodle
  23. */
  24. {
  25.     /**
  26.     * The VLE course object, retrieved directly from database.
  27.     * @var object 
  28.     * @access private
  29.     */
  30.     var $course = 0;
  31.  
  32.     /**
  33.     * SLOODLE course object, retrieved directly from database.
  34.     * @var object 
  35.     * @access private
  36.     */
  37.     var $sloodle_course = null;
  38.  
  39.     /**
  40.     * Course context for Moodle permissions.
  41.     * @var object 
  42.     * @access private
  43.     */
  44.     var $course_context = null;
  45.  
  46.  
  47.     /**
  48.     * Constructor.
  49.     */
  50.     function sloodle_view_course()
  51.     {
  52.     }
  53.  
  54.     /**
  55.     * Check the request parameters to see which course was specified.
  56.     */
  57.     function process_request()
  58.     {
  59.         $id required_param('id'PARAM_INT);
  60.         if (!$this->course = get_record('course''id'$id)) error('Could not find course.');
  61.         $this->sloodle_course = new SloodleCourse();
  62.         if (!$this->sloodle_course->load($this->course)) error(get_string('failedcourseload''sloodle'));
  63.     }
  64.  
  65.     /**
  66.     * Check that the user is logged-in and has permission to alter course settings.
  67.     */
  68.     function check_permission()
  69.     {
  70.         // Ensure the user logs in
  71.         require_login($this->course->id);
  72.         if (isguestuser()) error(get_string('noguestaccess''sloodle'));
  73.         add_to_log($this->course->id'course''view sloodle data'''"{$this->course->id}");
  74.  
  75.         // Ensure the user is allowed to update information on this course
  76.         $this->course_context = get_context_instance(CONTEXT_COURSE$this->course->id);
  77.         require_capability('moodle/course:update'$this->course_context);
  78.     }
  79.  
  80.     /**
  81.     * Print the course settings page header.
  82.     */
  83.     function print_header()
  84.     {
  85.         global $CFG;
  86.         $navigation "<a href=\"{$CFG->wwwroot}/mod/sloodle/view_course.php?id={$this->course->id}\">".get_string('courseconfig''sloodle')."</a>";
  87.         print_header_simple(get_string('courseconfig','sloodle')""$navigation""""true''navmenu($this->course));
  88.     }
  89.  
  90.     /**
  91.     * Render the view of the module or feature.
  92.     * This MUST be overridden to provide functionality.
  93.     */
  94.     function render()
  95.     {
  96.         global $CFG;
  97.  
  98.         // Fetch string table text
  99.         $strsloodle get_string('modulename''sloodle');
  100.         $strsloodles get_string('modulenameplural''sloodle');
  101.         $strsavechanges get_string('savechanges');
  102.         $stryes get_string('yes');
  103.         $strno get_string('no');
  104.         $strenabled get_string('enabled','sloodle');
  105.         $strdisabled get_string('disabled','sloodle');
  106.         $strsubmit get_string('submit''sloodle');
  107.  
  108.     //------------------------------------------------------    
  109.         
  110.         // If the form has been submitted, then process the input
  111.         if (isset($_REQUEST['submit_course_options'])) {
  112.             // Get the parameters
  113.             $form_autoreg required_param('autoreg'PARAM_BOOL);
  114.             $form_autoenrol required_param('autoenrol'PARAM_BOOL);
  115.             
  116.             // Update the Sloodle course object
  117.             if ($form_autoreg$this->sloodle_course->enable_autoreg();
  118.             else $this->sloodle_course->disable_autoreg();
  119.             if ($form_autoenrol$this->sloodle_course->enable_autoenrol();
  120.             else $this->sloodle_course->disable_autoenrol();
  121.             
  122.             // Update the database
  123.             if ($this->sloodle_course->write()) {
  124.                 redirect("view_course.php?id={$this->course->id}"get_string('changessaved')4);
  125.                 exit();
  126.             else {
  127.                 print_box(get_string('error')'generalbox boxwidthnarrow boxaligncenter');
  128.             }
  129.         }
  130.         
  131.     //------------------------------------------------------
  132.  
  133.         // Display info about Sloodle course configuration
  134.         echo "<h1 style=\"text-align:center;\">".get_string('courseconfig','sloodle')."</h1>\n";
  135.         print_box(get_string('courseconfig:info','sloodle')'generalbox boxaligncenter boxwidthnormal');
  136.         echo "<br/>\n";
  137.  
  138.     // Get the initial form values
  139.         $val_autoreg = (int)(($this->sloodle_course->get_autoreg()) 0);
  140.         $val_autoenrol = (int)(($this->sloodle_course->get_autoenrol()) 0);
  141.         
  142.         // Make the selection options for enabling/disabling items
  143.         $selection_menu array(=> $strdisabled=> $strenabled);
  144.         
  145.         // Start the box
  146.         print_box_start('generalbox boxaligncenter boxwidthnormal');
  147.         echo '<div style="text-align:center;"><h3>'.get_string('coursesettings','sloodle').'</h3>';
  148.         
  149.         // Start the form (including a course ID hidden parameter)
  150.         echo "<form action=\"view_course.php\" method=\"post\">\n";
  151.         echo "<input type=\"hidden\" name=\"id\" value=\"{$this->course->id}\">\n";
  152.         
  153.     // AUTO REGISTRATION //
  154.         echo "<p>\n";
  155.         helpbutton('auto_registration'get_string('help:autoreg','sloodle')'sloodle'truefalse''false);
  156.         echo get_string('autoreg''sloodle').': ';
  157.         choose_from_menu($selection_menu'autoreg'$val_autoreg''''0false);
  158.         // Add the site status
  159.         if (!sloodle_autoreg_enabled_site()) echo '<br/>&nbsp;<span style="color:red; font-style:italic; font-size:80%;">('.get_string('autoreg:disabled','sloodle').')</span>';
  160.         echo "</p>\n";
  161.         
  162.     // AUTO ENROLMENT //
  163.         echo "<p>\n";
  164.         helpbutton('auto_enrolment'get_string('help:autoenrol','sloodle')'sloodle'truefalse''false);
  165.         echo get_string('autoenrol''sloodle').': ';
  166.         choose_from_menu($selection_menu'autoenrol'$val_autoenrol''''0false);
  167.         // Add the site status
  168.         if (!sloodle_autoenrol_enabled_site()) echo '<br/>&nbsp;<span style="color:red; font-style:italic; font-size:80%;">('.get_string('autoenrol:disabled','sloodle').')</span>';
  169.         echo '</p>';
  170.         
  171.         
  172.         // Close the form, along with a submit button
  173.         echo "<input type=\"submit\" value=\"$strsubmit\" name=\"submit_course_options\"\>\n</form>\n";
  174.         
  175.         // Finish the box
  176.         echo '</div>';
  177.         print_box_end();
  178.  
  179.         
  180.     //------------------------------------------------------
  181.  
  182.         // Loginzone information
  183.         print_box_start('generalbox boxaligncenter boxwidthnarrow');
  184.         echo '<div style="text-align:center;"><h3>'.get_string('loginzonedata','sloodle').'</h3>';
  185.         
  186.         $lastupdated '('.get_string('unknown','sloodle').')';
  187.         if ($this->sloodle_course->get_loginzone_time_updated(0$lastupdated date('Y-m-d H:i:s'$this->sloodle_course->get_loginzone_time_updated());
  188.             
  189.         echo get_string('position','sloodle').': '.$this->sloodle_course->get_loginzone_position().'<br>';
  190.         echo get_string('size','sloodle').': '.$this->sloodle_course->get_loginzone_size().'<br>';
  191.         echo get_string('region','sloodle').': '.$this->sloodle_course->get_loginzone_region().'<br>';
  192.         echo get_string('lastupdated','sloodle').': '.$lastupdated.'<br>';
  193.         echo '<br>';
  194.         
  195.         
  196.         // Have we been instructed to clear all pending allocations?
  197.         if (isset($_REQUEST['clear_loginzone_allocations'])) {
  198.             // Delete all allocations relating to this course
  199.             delete_records('sloodle_loginzone_allocation''course'$this->course->id);
  200.         }
  201.         
  202.         // Create a form
  203.         echo "<form action=\"view_course.php\" method=\"POST\">\n";
  204.         echo "<input type=\"hidden\" name=\"id\" value=\"{$this->course->id}\">\n";
  205.         // Determine how many allocations there are for this course
  206.         $allocs count_records('sloodle_loginzone_allocation''course'$this->course->id);
  207.         echo get_string('pendingallocations','sloodle').': '.$allocs.'&nbsp;&nbsp;';
  208.         echo '<input type="submit" name="clear_loginzone_allocations" value="'.get_string('delete','sloodle').'"/>';
  209.         echo "</form>\n";
  210.         
  211.         
  212.         echo '</div>';
  213.         print_box_end();
  214.  
  215.         
  216.  
  217.  
  218.    
  219. //------------------------------------------------------
  220.  
  221.     // Check the user's permissions regarding layouts
  222.     $layouts_can_use has_capability('mod/sloodle:uselayouts'$this->course_context);
  223.     $layouts_can_edit has_capability('mod/sloodle:editlayouts'$this->course_context);
  224.     $layouts_can_edit true;
  225.     $layouts_can_use true;
  226.    
  227.     $course $this->course;
  228.  
  229.     // Only display the layouts if they can use them
  230.     if ($layouts_can_use{
  231.  
  232.         // Start the section
  233.         echo '<a name="layouts">&nbsp;<a>';
  234.         print_box_start('generalbox boxaligncenter boxwidthnormal');
  235.         echo '<div style="text-align:center;"><h3>'.get_string('storedlayouts','sloodle').'</h3>';
  236.    
  237.         // Has a delete layouts action been requested, and is it permitted for this user?
  238.         if (isset($_REQUEST['delete_layouts']&& $layouts_can_edit == true{
  239.            
  240.             // Count how many layouts we delete
  241.             $numdeleted 0;
  242.            
  243.             // Go through each request parameter
  244.             foreach ($_REQUEST as $name => $val{
  245.                 // Is this a delete objects request?
  246.                 if ($val != 'true'continue;
  247.                 $parts explode('_'$name);
  248.                 if (count($parts== && $parts[0== 'sloodledeletelayout'{
  249.                     // Only delete the layout if it belongs to the course
  250.                     if (delete_records('sloodle_layout''course'$course->id'id'(int)$parts[1])) {
  251.                         $numdeleted++;
  252.                         // Delete associated entries too
  253.                         delete_records('sloodle_layout_entry''layout'(int)$parts[1]);
  254.                     }
  255.                    
  256.                 }
  257.             }
  258.            
  259.             // Indicate our results
  260.             echo '<span style="color:red; font-weight:bold;">'.get_string('numdeleted','sloodle').': '.$numdeleted.'</span><br><br>';
  261.         }
  262.        
  263.         // This will store the "disabled" attribute for our delete controls, if necessary
  264.         $disabledattr ' disabled="true" ';
  265.         if ($layouts_can_edit$disabledattr '';
  266.        
  267.         // Get all layouts stored in this course
  268.         $recs get_records('sloodle_layout''course'$course->id'name');
  269.         if (is_array($recs&& count($recs0{
  270.             // Construct a table
  271.             $layouts_table new stdClass();
  272.             $layouts_table->head array(get_string('name','sloodle'),get_string('numobjects','sloodle'),get_string('lastupdated','sloodle'),'','');
  273.             $layout_table->align array('left''left''left''center');
  274.             foreach ($recs as $layout{
  275.                 // Get the number of objects associated with this layout
  276.                 $numobjects count_records('sloodle_layout_entry''layout'$layout->id);
  277.                 $timeupdated ((int)$layout->timeupdated == 0'('.get_string('unknown','sloodle').')' date('Y-m-d H:i:s'(int)$layout->timeupdated);
  278.                 $layouts_table->data[array($layout->name$numobjects$timeupdated'<a href="view_layout.php?courseid='.$course->id.'&layoutid='.$layout->id.'">Edit</a>',"<input $disabledattr type=\"checkbox\" name=\"sloodledeletelayout_{$layout->id}\" value=\"true\" /");
  279.             }
  280.            
  281.             // Display a form and the table
  282.             echo '<form action="view_course.php" method="POST">';
  283.             echo '<input type="hidden" name="id" value="'.$course->id.'"/>';
  284.            
  285.             print_table($layouts_table);
  286.             if ($layouts_can_editecho '<input type="submit" value="'.get_string('deleteselected','sloodle').'" name="delete_layouts"/>';
  287.            
  288.             echo '</form>';
  289.            
  290.         else {
  291.             echo '<span style="text-align:center;color:red">'.get_string('noentries','sloodle').'</span><br>';
  292.         }
  293.        
  294.         echo '<br />';
  295.         echo '<a href="view_layout.php?layoutid=0&courseid='.$course->id.'">Create a layout for this course</a>';
  296.  
  297.  
  298.         echo '</div>';
  299.         print_box_end();
  300.     }
  301.  
  302.  
  303.  
  304.     }
  305.  
  306.     /**
  307.     * Print the footer for this course.
  308.     */
  309.     function print_footer()
  310.     {
  311.         print_footer($this->course);
  312.     }
  313.  
  314. }
  315.  
  316.  
  317. ?>

Documentation generated on Fri, 17 Jul 2009 11:01:11 +0100 by phpDocumentor 1.4.0