Source for file notecard_configuration_view.php

Documentation is available at notecard_configuration_view.php

  1. <?php
  2.     // This file is part of the Sloodle project (www.sloodle.org)
  3.  
  4.     /**
  5.     * This page lets an educator/admin view a configuration notecard.
  6.     * The data will first arrive as POST data, but will be converted
  7.     *  over to SESSION data, and the page reloaded.
  8.     *
  9.     * @package sloodle
  10.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  11.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  12.     *
  13.     * @contributor Peter R. Bloomfield
  14.     *
  15.     */
  16.     
  17.     /** Sloodle/Moodle configuration script. */
  18.     require_once('../sl_config.php');
  19.     /** Sloodle core library functionality */
  20.     require_once(SLOODLE_DIRROOT.'/lib.php');
  21.     /** Sloodle API. */
  22.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  23.  
  24.     // Fetch our required parameters
  25.     $sloodlecontrollerid required_param('sloodlecontrollerid'PARAM_INT);
  26.     $sloodleobjtype required_param('sloodleobjtype'PARAM_TEXT);
  27.     
  28.     
  29.     // Has HTTP form data been submitted?
  30.     if (isset($_REQUEST['formsubmitted'])) {
  31.         // Convert all the form data to session data
  32.         foreach ($_REQUEST as $k => $v{
  33.             // Ignore anything that doesn't start with 'sloodle'
  34.             if (strpos($k'sloodle'!== 0{
  35.                 continue;
  36.             }
  37.             // Store it in session data
  38.             $_SESSION[$k$v;
  39.         }
  40.         
  41.         // Make sure we know about the form in session data
  42.         $_SESSION['formsubmitted'true;
  43.         
  44.         // Reload this page
  45.         redirect("{$CFG->wwwroot}/mod/sloodle/classroom/notecard_configuration_view.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype");
  46.         exit();
  47.         
  48.     else if (!isset($_SESSION['formsubmitted'])) {
  49.         // No, and there is no session form data either.
  50.         // Re-direct back to the notecard page
  51.         redirect("{$CFG->wwwroot}/mod/sloodle/classroom/notecard_configuration_form.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype");
  52.         exit();
  53.     }
  54.     
  55.     // Clear the form submission
  56.     unset($_SESSION['formsubmitted']);
  57.     
  58.     
  59.     // Fetch string table text
  60.     $strsloodle get_string('modulename''sloodle');
  61.     $strsloodles get_string('modulenameplural''sloodle');
  62.     $pagename get_string('cfgnotecard:header''sloodle');
  63.     $strsavechanges get_string('savechanges');
  64.     $stryes get_string('yes');
  65.     $strno get_string('no');
  66.     
  67.     
  68.     // Attempt to fetch the course module instance
  69.     if ($cm get_coursemodule_from_id('sloodle'$sloodlecontrollerid)) {
  70.         error("Failed to load course module");
  71.     }
  72.     // Get the course data
  73.     if ($course get_record("course""id"$cm->course)) {
  74.         error("Course is misconfigured");
  75.     }
  76.     // Get the Sloodle instance
  77.     if ($sloodle get_record('sloodle''id'$cm->instance)) {
  78.         error('Failed to find Sloodle module instance.');
  79.     }
  80.     
  81.     // Get the Sloodle course data
  82.     $sloodle_course new SloodleCourse();
  83.     if (!$sloodle_course->load($course)) error(get_string('failedcourseload','sloodle'));
  84.     if (!$sloodle_course->controller->load($sloodlecontrollerid)) error('Failed to load Controller data');
  85.     
  86.     // Ensure that the user is logged-in for this course
  87.     require_course_login($coursetrue$cm);
  88.     // Is the user allowed to edit the module?
  89.     $module_context get_context_instance(CONTEXT_MODULE$cm->id);
  90.     $course_context get_context_instance(CONTEXT_COURSE$course->id);
  91.     require_capability('moodle/course:manageactivities'$module_context);
  92.  
  93.     // Display the page header
  94.     //$navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id=$course->id\">$strsloodles</a> ->";
  95.     $navigation "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?id=$sloodlecontrollerid\">".format_string($sloodle->name)."</a> ->";
  96.     print_header_simple($pagename"""$navigation "$pagename""""true''navmenu($course$cm));
  97.  
  98.     // We can display the Sloodle module info... log the view
  99.     add_to_log($course->id'sloodle''view sloodle config'"classroom/notecard_configuration.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype"$sloodleobjtype$cm->id);
  100.     
  101.     // Make sure the object type is recognised
  102.     $objectpath SLOODLE_DIRROOT."/mod/$sloodleobjtype";
  103.     if (!file_exists($objectpath)) error("ERROR: object \"$sloodleobjtype\" is not installed.");
  104.     // Determine if we have a custom configuration page
  105.     $customconfig $objectpath.'/object_config.php';
  106.     $hascustomconfig file_exists($customconfig);
  107.     
  108.     // Split up the object identifier into name and version number, then get the translated name
  109.     list($objectname$objectversionsloodle_parse_object_identifier($sloodleobjtype);
  110.     $strobjectname get_string("object:$objectname"'sloodle');
  111.     
  112.     
  113. //---------------------------------------------------------------------------------
  114.     
  115.     // Display intro information
  116.     print_box_start('generalbox boxwidthwide boxaligncenter');
  117.     echo '<div style="text-align:center;">';
  118.     
  119.     echo "<h1>$pagename</h1>";
  120.     echo "<h2>$strobjectname $objectversion</h2>";
  121.     print_string('cfgnotecard:instructions''sloodle');
  122.     echo '<br><br>';
  123.     print_string('cfgnotecard:security''sloodle');
  124.     echo '<br><br><br>';
  125.     
  126.     
  127.     // Fetch all our custom configuration settings into a separate array
  128.     $customsettings array();
  129.     if (count($_SESSION0{
  130.         foreach ($_SESSION as $k => $v{
  131.             // Ignore anything that doesn't start with 'sloodle'
  132.             if (strpos($k'sloodle'!== 0continue;
  133.             // Ignore anything we will add in later
  134.             if ($k != 'sloodleobjtype' && $k != 'sloodlecontrollerid'$customsettings[$k$v;
  135.             // Remove the setting so it doesn't appear later
  136.             unset($_SESSION[$k]);
  137.         }
  138.     }
  139.     // Figure out how many lines we need
  140.     $numlines count($customsettings6;
  141.     
  142.     
  143.     // The configuration text
  144.     echo '<textarea cols="60" rows="'.$numlines.'" readonly="true" onclick="">';
  145.     
  146.     // Add the standard stuff in
  147.     echo "set:sloodleobjtype|$sloodleobjtype\n";
  148.     echo "set:sloodleserverroot|{$CFG->wwwroot}\n";
  149.     echo "set:sloodlecontrollerid|$sloodlecontrollerid\n";
  150.     echo "set:sloodlepwd|".$sloodle_course->controller->get_password()."\n";
  151.     echo "set:sloodlecoursename_short|".$sloodle_course->get_short_name()."\n";
  152.     echo "set:sloodlecoursename_full|".$sloodle_course->get_full_name()."\n";
  153.     
  154.     // Go through each session parameter
  155.     foreach ($customsettings as $k => $v{
  156.         // Output the value
  157.         echo "set:$k|$v\n";
  158.     }
  159.     
  160.     echo '</textarea><br><br>';
  161.     
  162.     echo "<a href=\"notecard_configuration_form.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype\">&lt;&lt; ".get_string('objectconfig:backtoform','sloodle')."</a>";
  163.     
  164.     echo '</div>';
  165.     print_box_end();
  166.     
  167.     
  168. //---------------------------------------------------------------------------------
  169.     
  170.     
  171.     
  172.     print_footer();
  173. ?>

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