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 boxwidthwide');
  55.             echo '<h3>'.get_string('objectconfig:header''sloodle').'</h3>';
  56.             echo '<p>'.get_string('objectconfig:body''sloodle').'</p>';
  57.             //link_to_popup_window(SLOODLE_WWWROOT."/view/view_configuration_notecard.php?s={$sloodle->id}", 'sloodle_config', get_string('createnotecard', 'sloodle'), 350, 570, 'sloodle_config');
  58.             
  59.             // Is Prim Password access available?
  60.             if (empty($controller->password)) {
  61.                 // No - display an error message
  62.                 echo '<span style="color:red; font-weight:bold;>'.get_string('objectconfig:noprimpassword','sloodle').'</span>';
  63.             else {
  64.                 print_string('objectconfig:select','sloodle');
  65.                 // Go through each installed type to produce our own array of objects.
  66.                 // (Our array will associate translated names and version numbers with complete object ID's).
  67.                 $objects array();
  68.                 $mods sloodle_get_installed_object_types();
  69.                 if (!$modserror('Error fetching installed object types.');
  70.                 
  71.                 foreach ($mods as $name => $versions{
  72.                     // Get the translated name
  73.                     $translatedname get_string("object:$name"'sloodle');
  74.                     // Reverse-sort the version
  75.                     $sortedversions $versions;
  76.                     krsort($sortedversions);
  77.                     foreach ($sortedversions as $v => $cfg{
  78.                         // Construct and store the complete object ID
  79.                         $objectid "$name-$v";
  80.                         $objects[$translatedname][$v$objectid;
  81.                     }
  82.                 }
  83.                 
  84.                 // Sort the objects by name
  85.                 ksort($objects);
  86.                 
  87.                 // Display our list of objects
  88.                 echo '<br><br><table style="text-align:left; margin-left:auto; margin-right:auto;">';
  89.                 foreach ($objects as $name => $versions{
  90.                     // The primary link will always be the latest version
  91.                     $num 0;
  92.                     echo '<tr><td>';
  93.                     $multipleversions (count($versions1);
  94.                     // Go through each version (this will be latest first)
  95.                     foreach ($versions as $v => $objectid{
  96.                         // Construct a link for this object's configuration
  97.                         $link SLOODLE_WWWROOT."/classroom/notecard_configuration_form.php?sloodlecontrollerid={$cm->id}&sloodleobjtype=$objectid";
  98.                     
  99.                         // Is this the latest version?
  100.                         if ($num == 0{
  101.                             // Yes - display the object name for the link
  102.                             echo "<span style=\"font-size:14pt;\"><a href=\"$link\">$name</a>";
  103.                         }
  104.                         // Do we have multiple versions available?
  105.                         if ($multipleversions{
  106.                             // Yes - add the version in brackets afterwards
  107.                             if ($num == 0echo ' <span style="font-size:11pt; font-style:italic;">[';
  108.                             else if ($num 0echo ', ';
  109.                             echo "<a href=\"$link\">$v</a>";
  110.                         }
  111.                         
  112.                         $num++;
  113.                     }
  114.                     
  115.                     // Close the extra versions section if necessary
  116.                     if ($multipleversionsecho "]</span>";
  117.                     echo "</td></tr>";
  118.                 }
  119.                 
  120.                 echo '</table>';
  121.             }
  122.  
  123.             print_box_end();
  124.             
  125.             // Active (authorised) objects
  126.             print_box_start('generalbox boxaligncenter boxwidthwide');
  127.             echo '<h3>'.get_string('authorizedobjects','sloodle').'</h3>';
  128.             
  129.             // Has a delete objects action been requested
  130.             if ($action == 'delete_objects'{
  131.                 
  132.                 // Count how many objects we delete
  133.                 $numdeleted 0;
  134.                 
  135.                 // Go through each request parameter
  136.                 foreach ($_REQUEST as $name => $val{
  137.                     // Is this a delete objects request?
  138.                     if ($val != 'true'continue;
  139.                     $parts explode('_'$name);
  140.                     if (count($parts== && $parts[0== 'sloodledeleteobj'{
  141.                         // Only delete the object if it belongs to this controller
  142.                         if (delete_records('sloodle_active_object''controllerid'$cm->id'id'(int)$parts[1])) {
  143.                             $numdeleted++;
  144.                             // Delete any associated configuration settings too
  145.                             delete_records('sloodle_object_config''object'(int)$parts[1]);
  146.                         }
  147.                         
  148.                     }
  149.                 }
  150.                 
  151.                 // Indicate our results
  152.                 echo '<span style="color:red; font-weight:bold;">'.get_string('numdeleted','sloodle').': '.$numdeleted.'</span><br><br>';
  153.             }
  154.             
  155.             // Get all objects authorised for this controller
  156.             $recs get_records('sloodle_active_object''controllerid'$cm->id'timeupdated DESC');
  157.             if (is_array($recs&& count($recs0{
  158.                 // Construct a table
  159.                 //TODO: add authorising user link
  160.                 $objects_table new stdClass();
  161.                 $objects_table->head array(get_string('objectname','sloodle'),get_string('objectuuid','sloodle'),get_string('objecttype','sloodle'),get_string('lastupdated','sloodle'),'');
  162.                 $objects_table->align array('left''left''left''left''center');
  163.                 foreach ($recs as $obj{
  164.                     // Skip this object if it has no type information
  165.                     if (empty($obj->type)) continue;
  166.                     // Construct a link to this object's configuration page
  167.                     $config_link "<a href=\"{$CFG->wwwroot}/mod/sloodle/classroom/configure_object.php?sloodleauthid={$obj->id}\">";
  168.                     $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\" /");
  169.                 }
  170.                 
  171.                 // Display a form and the table
  172.                 echo '<form action="" method="POST">';
  173.                 echo '<input type="hidden" name="id" value="'.$cm->id.'"/>';
  174.                 echo '<input type="hidden" name="action" value="delete_objects"/>';
  175.                 
  176.                 print_table($objects_table);
  177.                 echo '<input type="submit" value="'.get_string('deleteselected','sloodle').'"/>';
  178.                 
  179.                 echo '</form>';
  180.                 
  181.             else {
  182.                 echo '<span style="text-align:center;color:red">'.get_string('noentries','sloodle').'</span><br>';
  183.             }
  184.             
  185.             print_box_end();
  186.         }
  187.         
  188.         echo "</div>\n";
  189.         
  190.         return true;
  191.     }
  192.     
  193.     
  194. ?>

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