Source for file store_object_config.php

Documentation is available at store_object_config.php

  1. <?php
  2.  
  3.     /**
  4.     * Sloodle object configuration storage script.
  5.     *
  6.     * When passed a list of object configuration settings, it will store them.
  7.     * User must be logged-in and authorised to manage activities on the specified course.
  8.     *
  9.     * @package sloodleclassroom
  10.     * @copyright Copyright (c) 2007-8 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.     // The following parameter is required:
  18.     //
  19.     //  sloodleauthid = identifies which authorisation (active obejct) entry is being configured
  20.     //
  21.     // All other parameters which start with "sloodle", except for "sloodledebug", are treated
  22.     //  as configuration settings and stored accordingly.
  23.     //
  24.     
  25.     /** Include the Sloodle/Moodle configuration. */
  26.     require_once('../sl_config.php');
  27.     /** Include the Sloodle API. */
  28.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  29.     
  30.     // Make sure the user is logged-in and is not a guest
  31.     if (isloggedin(== false || isguestuser(== true{
  32.         error(get_string('noguestaccess','sloodle'));
  33.         exit();
  34.     }
  35.     
  36.     // We need to know which object is being configured
  37.     $sloodleauthid required_param('sloodleauthid'PARAM_INT);
  38.     $auth_obj SloodleController::get_object($sloodleauthid);
  39.     if (!$auth_obj{
  40.         error(get_string('objectauthnotfound','sloodle'));
  41.         exit();
  42.     }
  43.     // Make sure the object is authorised
  44.     if ($auth_obj->course->controller->is_loaded(== false{
  45.         //TODO: more appropriate error message?
  46.         error(get_string('objectauthnotfound','sloodle'));
  47.         exit();
  48.     }
  49.     
  50.     // Make sure the user has permission to manage activities on this course
  51.     $course_context get_context_instance(CONTEXT_COURSE$auth_obj->course->get_course_id());
  52.     require_capability('moodle/course:manageactivities'$course_context);
  53.     
  54.     // Delete all configuration options already associated with the object
  55.     delete_records('sloodle_object_config''object'$sloodleauthid);
  56.     
  57.     // Define parameter names we will ignore
  58.     $IGNORE_PARAMS array('sloodleauthid''sloodledebug');
  59.     // This structure will store our values
  60.     $config_setting new stdClass();
  61.     $config_setting->object $sloodleauthid;
  62.     
  63.     // Add the new ones
  64.     $numstored 0;
  65.     foreach ($_REQUEST as $k => $v{
  66.         // Ignore anything which does not start with "sloodle"
  67.         if (strpos($k'sloodle'!== 0continue;
  68.         // Ignore certain parameters
  69.         if (in_array($k$IGNORE_PARAMS)) continue;
  70.         
  71.         // Store the setting
  72.         $config_setting->name addslashes($k);
  73.         $config_setting->value addslashes($v);
  74.         if (insert_record('sloodle_object_config'$config_setting)) {
  75.             $numstored++;
  76.         }
  77.     }
  78.     
  79.     // Construct a breadcrumb navigation menu
  80.     $nav get_string('modulename''sloodle').' -> ';
  81.     $nav .= get_string('objectconfiguration','sloodle');
  82.     // Display the page header
  83.     print_header(get_string('objectconfiguration','sloodle')get_string('objectconfiguration','sloodle')$nav''''false);
  84.     
  85.     
  86.     // Display the information about the object
  87.     print_box_start('generalbox boxaligncenter boxwidthnarrow');
  88.     echo '<div style="text-align:center;">';
  89.     echo '<span style="font-weight:bold; font-size:110%;">'.get_string('objectdetails','sloodle').'</span><br>';
  90.     
  91.     echo get_string('objectname','sloodle').': '.$auth_obj->name.'<br>';
  92.     echo get_string('objectuuid','sloodle').': '.$auth_obj->uuid.'<br>';
  93.     echo get_string('objecttype','sloodle').': '.$auth_obj->type.'<br>';
  94.     echo get_string('authorizedfor''sloodle').$auth_obj->course->get_full_name().' &gt; '.$auth_obj->course->controller->get_name().'<br>';
  95.     
  96.     // Indicate how many settings were stored
  97.     echo '<br><span style="font-weight:bold;">';
  98.     print_string('numsettingsstored','sloodle');
  99.     echo " $numstored</span><br>\n";
  100.     
  101.     echo '</div>';
  102.     print_box_end();
  103.     echo '<br>';
  104.     
  105.     // Print a continue button, to go back to the course
  106.     echo '<div style="text-align:center;">';
  107.     echo "<form action=\"{$CFG->wwwroot}/course/view.php\" method=\"GET\">";
  108.     echo '<input type="hidden" name="id" value="'.$auth_obj->course->get_course_id().'"/>';
  109.     echo '<input type="submit" value="'.get_string('continue').'"/>';
  110.     echo '</form></div>';
  111.     
  112.     print_footer();
  113.     
  114. ?>

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