Source for file view_course.php

Documentation is available at view_course.php

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

Documentation generated on Mon, 07 Jul 2008 12:33:27 +0100 by phpDocumentor 1.4.0