Source for file view_controller.php

Documentation is available at view_controller.php

  1. <?php
  2.     /**
  3.     * Defines a function to display information about a particular Sloodle controller module.
  4.     *
  5.     * @package sloodle
  6.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  7.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  8.     *
  9.     * @contributor Peter R. Bloomfield
  10.     *
  11.     */
  12.     
  13.     // This file expects that the core Sloodle/Moodle functionality has already been included.
  14.     
  15.     /**
  16.     * Displays information about the given Sloodle module.
  17.     * Note: the user should already be logged-in, with information in the $USER global.
  18.     *
  19.     * @param object $cm A coursemodule object for the module being displayed
  20.     * @param object $sloodle A database record object for a Sloodle instance
  21.     * @param bool $showprotected True if protected data (such as prim password) should be made available
  22.     * @return bool True if successful, or false otherwise (e.g. wrong type of module, or user not logged-in)
  23.     */
  24.     function sloodle_view_controller($cm$sloodle$showprotected false)
  25.     {
  26.         global $CFG;
  27.     
  28.         // Check that there is valid Sloodle data
  29.         if (empty($cm|| empty($sloodle|| $sloodle->type != SLOODLE_TYPE_CTRLreturn false;
  30.         
  31.         // Fetch the controller data
  32.         $controller get_record('sloodle_controller''sloodleid'$sloodle->id);
  33.         if (!$controllerreturn false;
  34.         
  35.         // The name, type and description of the module should already be displayed by the main "view.php" script.
  36.         echo "<div style=\"text-align:center;\">\n";
  37.         
  38.         // Check if some kind of action has been requested
  39.         $action optional_param('action'''PARAM_TEXT);
  40.         
  41.         // Indicate whether or not this module is enabled
  42.         echo '<p style="font-size:14pt;">'.get_string('status''sloodle').': ';
  43.         if ($controller->enabled{
  44.             echo '<span style="color:green; font-weight:bold;">'.get_string('enabled','sloodle').'</span>';
  45.         else {
  46.             echo '<span style="color:red; font-weight:bold;">'.get_string('disabled','sloodle').'</span>';
  47.         }
  48.         echo "</p>\n";
  49.         
  50.         // Should protected data be shown?
  51.         if ($showprotected{
  52.         
  53.             // Display a link to the configuration notecard page, as a popup window
  54.             print_box_start('generalbox boxaligncenter boxwidthnormal');
  55.             echo '<h3>'.get_string('objectconfig:header''sloodle').'</h3>';
  56.             echo '<p>'.get_string('objectconfig:body''sloodle').'<br><br><span style="font-size:14pt;">';
  57.             link_to_popup_window(SLOODLE_WWWROOT."/view/view_configuration_notecard.php?s={$sloodle->id}"'sloodle_config'get_string('createnotecard''sloodle')350570'sloodle_config');
  58.             echo '</span></p>';
  59.             print_box_end();
  60.             
  61.             // Active (authorised) objects
  62.             print_box_start('generalbox boxaligncenter boxwidthwide');
  63.             echo '<h3>'.get_string('authorizedobjects','sloodle').'</h3>';
  64.             
  65.             // Has a delete objects action been requested
  66.             if ($action == 'delete_objects'{
  67.                 
  68.                 // Count how many objects we delete
  69.                 $numdeleted 0;
  70.                 
  71.                 // Go through each request parameter
  72.                 foreach ($_REQUEST as $name => $val{
  73.                     // Is this a delete objects request?
  74.                     if ($val != 'true'continue;
  75.                     $parts explode('_'$name);
  76.                     if (count($parts== && $parts[0== 'sloodledeleteobj'{
  77.                         // Only delete the object if it belongs to this controller
  78.                         if (delete_records('sloodle_active_object''controllerid'$cm->id'id'(int)$parts[1])) {
  79.                             $numdeleted++;
  80.                             // Delete any associated configuration settings too
  81.                             delete_records('sloodle_object_config''object'(int)$parts[1]);
  82.                         }
  83.                         
  84.                     }
  85.                 }
  86.                 
  87.                 // Indicate our results
  88.                 echo '<span style="color:red; font-weight:bold;">'.get_string('numdeleted','sloodle').': '.$numdeleted.'</span><br><br>';
  89.             }
  90.             
  91.             // Get all objects authorised for this controller
  92.             $recs get_records('sloodle_active_object''controllerid'$cm->id'timeupdated DESC');
  93.             if (is_array($recs&& count($recs0{
  94.                 // Construct a table
  95.                 //TODO: add authorising user link
  96.                 $objects_table new stdClass();
  97.                 $objects_table->head array(get_string('objectname','sloodle'),get_string('objectuuid','sloodle'),get_string('objecttype','sloodle'),get_string('lastupdated','sloodle'),'');
  98.                 $objects_table->align array('left''left''left''left''center');
  99.                 foreach ($recs as $obj{
  100.                     // Skip this object if it has no type information
  101.                     if (empty($obj->type)) continue;
  102.                     // Construct a link to this object's configuration page
  103.                     $config_link "<a href=\"{$CFG->wwwroot}/mod/sloodle/classroom/configure_object.php?sloodleauthid={$obj->id}\">";
  104.                     $objects_table->data[array($config_link.$obj->name.'</a>'$obj->uuid$obj->typedate('Y-m-d H:i:s T'(int)$obj->timeupdated)"<input type=\"checkbox\" name=\"sloodledeleteobj_{$obj->id}\" value=\"true\" /");
  105.                 }
  106.                 
  107.                 // Display a form and the table
  108.                 echo '<form action="" method="POST">';
  109.                 echo '<input type="hidden" name="id" value="'.$cm->id.'"/>';
  110.                 echo '<input type="hidden" name="action" value="delete_objects"/>';
  111.                 
  112.                 print_table($objects_table);
  113.                 echo '<input type="submit" value="'.get_string('deleteselected','sloodle').'"/>';
  114.                 
  115.                 echo '</form>';
  116.                 
  117.             else {
  118.                 echo '<span style="text-align:center;color:red">'.get_string('noentries','sloodle').'</span><br>';
  119.             }
  120.             
  121.             print_box_end();
  122.         }
  123.         
  124.         echo "</div>\n";
  125.         
  126.         return true;
  127.     }
  128.     
  129.     
  130. ?>

Documentation generated on Mon, 16 Jun 2008 15:57:08 +0100 by phpDocumentor 1.4.0