Source for file notecard_configuration_form.php

Documentation is available at notecard_configuration_form.php

  1. <?php
  2.     // This file is part of the Sloodle project (www.sloodle.org)
  3.  
  4.     /**
  5.     * This page lets an educator/admin create a configuration notecard.
  6.     * It will be accessed by a link from a Controller page, and will
  7.     *  display a form based on scripts in the Sloodle "mod" folder.
  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.     // Fetch string table text
  29.     $strsloodle get_string('modulename''sloodle');
  30.     $strsloodles get_string('modulenameplural''sloodle');
  31.     $pagename get_string('objectconfig:header''sloodle');
  32.     $strsavechanges get_string('savechanges');
  33.     $stryes get_string('yes');
  34.     $strno get_string('no');
  35.     
  36.     
  37.     // Attempt to fetch the course module instance
  38.     if ($cm get_coursemodule_from_id('sloodle'$sloodlecontrollerid)) {
  39.         error("Failed to load course module");
  40.     }
  41.     // Get the course data
  42.     if ($course get_record("course""id"$cm->course)) {
  43.         error("Course is misconfigured");
  44.     }
  45.     // Get the Sloodle instance
  46.     if ($sloodle get_record('sloodle''id'$cm->instance)) {
  47.         error('Failed to find Sloodle module instance.');
  48.     }
  49.     
  50.     // Get the Sloodle course data
  51.     $sloodle_course new SloodleCourse();
  52.     if (!$sloodle_course->load($course)) error(get_string('failedcourseload','sloodle'));
  53.     if (!$sloodle_course->controller->load($sloodlecontrollerid)) error('Failed to load Sloodle Controller.');
  54.     
  55.     // Ensure that the user is logged-in for this course
  56.     require_course_login($coursetrue$cm);
  57.     // Is the user allowed to edit the module?
  58.     $module_context get_context_instance(CONTEXT_MODULE$cm->id);
  59.     $course_context get_context_instance(CONTEXT_COURSE$course->id);
  60.     require_capability('moodle/course:manageactivities'$module_context);
  61.  
  62.     // Display the page header
  63.     //$navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id=$course->id\">$strsloodles</a> ->";
  64.     $navigation "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?id=$sloodlecontrollerid\">".format_string($sloodle->name)."</a> ->";
  65.     print_header_simple($pagename"""$navigation "$pagename""""true''navmenu($course$cm));
  66.  
  67.     // We can display the Sloodle module info... log the view
  68.     add_to_log($course->id'sloodle''view sloodle config'"classroom/notecard_configuration.php?sloodlecontrollerid=$sloodlecontrollerid&sloodleobjtype=$sloodleobjtype"$sloodleobjtype$cm->id);
  69.     
  70.     
  71.     // Make sure the object type is recognised
  72.     $objectpath SLOODLE_DIRROOT."/mod/$sloodleobjtype";
  73.     if (!file_exists($objectpath)) error("ERROR: object \"$sloodleobjtype\" is not installed.");
  74.     // Determine if we have a custom configuration page
  75.     $customconfig $objectpath.'/object_config.php';
  76.     $hascustomconfig file_exists($customconfig);
  77.     
  78.     // Split up the object identifier into name and version number, then get the translated name
  79.     list($objectname$objectversionsloodle_parse_object_identifier($sloodleobjtype);
  80.     $strobjectname get_string("object:$objectname"'sloodle');
  81.     
  82. //---------------------------------------------------------------------------------
  83.     
  84.     // Display intro information
  85.     print_box_start('generalbox boxwidthwide boxaligncenter');
  86.     echo '<div style="text-align:center;">';
  87.     
  88.     echo "<h1>$pagename</h1>";
  89.     echo "<h2>$strobjectname $objectversion</h2>";
  90.     
  91.     // Display our configuration form
  92.     echo '<form action="'.SLOODLE_WWWROOT.'/classroom/notecard_configuration_view.php" method="POST">';
  93.     echo '<input type="hidden" name="formsubmitted" value="true">';
  94.     
  95.     // Are there any custom configuration options?
  96.     if ($hascustomconfig{
  97.     
  98.         // We need to create some dummy data for the form
  99.         // (basically pretend we have an authorised object, and hope nobody tries to use the missing data anywhere!)
  100.         // (not the best idea, I know, but the notecard stuff was added late... :-\)
  101.         $sloodleauthid 0;
  102.         $auth_obj new SloodleActiveObject();
  103.         $auth_obj->course $sloodle_course;
  104.         $auth_obj->type $sloodleobjtype;
  105.         $dummysession new SloodleSession(false);
  106.         $dummysession->user->load_user($USER->id);
  107.         $dummysession->user->load_linked_avatar();
  108.         $auth_obj->user $dummysession->user;
  109.         
  110.         // Include the form elements
  111.         require($customconfig);
  112.         
  113.     else {
  114.         // No configuration settings for this object
  115.         print_string('noobjectconfig','sloodle');
  116.         echo '<br><br>';
  117.     }
  118.     
  119.     // Add our other necessary form elements
  120.     echo '<input type="hidden" name="sloodlecontrollerid" value="'.$sloodlecontrollerid.'">';
  121.     echo '<input type="hidden" name="sloodleobjtype" value="'.$sloodleobjtype.'">';
  122.     echo '<input type="submit" value="'.get_string('cfgnotecard:generate','sloodle').'">';
  123.     echo '</form>';
  124.     
  125.     echo '</div>';
  126.     print_box_end();
  127.     
  128. //---------------------------------------------------------------------------------    
  129.     
  130.     print_footer();
  131. ?>

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