Source for file view_distributor.php

Documentation is available at view_distributor.php

  1. <?php
  2.     /**
  3.     * Defines a function to display information about a particular Sloodle Distributor 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 Distributor.
  17.     * Note: the user should already be logged-in, with information in the $USER global.
  18.     *
  19.     * @uses $USER
  20.     * @param object $cm A coursemodule object for the module being displayed
  21.     * @param object $sloodle A database record object for a Sloodle instance
  22.     * @param bool $showprotected True if protected data (such as prim password) should be made available
  23.     * @return bool True if successful, or false otherwise (e.g. wrong type of module, or user not logged-in)
  24.     */
  25.     function sloodle_view_distributor($cm$sloodle$showprotected false)
  26.     {
  27.         global $USER;
  28.     
  29.         // Check that there is valid Sloodle data
  30.         if (empty($sloodle|| $sloodle->type != SLOODLE_TYPE_DISTRIBreturn false;
  31.         
  32.         // Fetch the Distributor data
  33.         if (!$distributor get_record('sloodle_distributor''sloodleid'$sloodle->id)) return false;
  34.         // Fetch a list of all distributor entries
  35.         $entries get_records('sloodle_distributor_entry''distributorid'$distributor->id'name');
  36.         // If the query failed, then assume there were simply no items available
  37.         if (!is_array($entries)) $entries array();
  38.         $numitems count($entries);
  39.         
  40.         
  41.         // A particular default user can be requested (by avatar name) in the HTTP parameters.
  42.         // This could be used with a "send to this avatar" button on a Sloodle user profile.
  43.         $defaultavatar optional_param('defaultavatar'nullPARAM_TEXT);
  44.         
  45.         
  46.         // // SEND OBJECT // //
  47.         
  48.         // If the user and object parameters are set, then try to send an object
  49.         $send_user optional_param('user'''PARAM_TEXT);
  50.         $send_object optional_param('object'''PARAM_TEXT);
  51.         if (!empty($send_user&& !empty($send_object)) {
  52.             // Construct and send the request
  53.             $request "1|OK\\nSENDOBJECT|$send_user|$send_object";
  54.             $ok sloodle_send_xmlrpc_message($distributor->channel0$request);
  55.             
  56.             // What was the result?
  57.             print_box_start('generalbox boxaligncenter boxwidthnarrow centerpara');
  58.             if ($ok{
  59.                 print '<h3 style="color:green;text-align:center;">'.get_string('sloodleobjectdistributor:successful','sloodle').'</h3>';
  60.             else {
  61.                 print '<h3 style="color:red;text-align:center;">'.get_string('sloodleobjectdistributor:failed','sloodle').'</h3>';
  62.             }
  63.             print '<p style="text-align:center;">';
  64.                 print get_string('Object','sloodle').': '.$send_object.'<br/>';
  65.                 print get_string('uuid','sloodle').': '.$send_user.'<br/>';
  66.                 print get_string('xmlrpc:channel','sloodle').': '.$distributor->channel.'<br/>';
  67.                 print '</p>';
  68.             print_box_end();
  69.         }
  70.         
  71.         // // ----------- // //
  72.         
  73.  
  74.         // If there are no items in the distributor, then simply display an error message
  75.         if ($numitems 1print_box('<span style="font-weight:bold; color:red;">'.get_string('sloodleobjectdistributor:noobjects','sloodle').'</span>''generalbox boxaligncenter boxwidthnormal centerpara');
  76.         //error(get_string('sloodleobjectdistributor:noobjects','sloodle'));
  77.         // If there is no XMLRPC channel specified, then display a warning message
  78.         $disabledattr '';
  79.         if (empty($distributor->channel)) {
  80.             print_box('<span style="font-weight:bold; color:red;">'.get_string('sloodleobjectdistributor:nochannel','sloodle').'</span>''generalbox boxaligncenter boxwidthnormal centerpara');
  81.             $disabledattr 'disabled="true"';
  82.         }
  83.         
  84.         // Construct the selection box of items
  85.         $selection_items '<select name="object" size="1">';
  86.         foreach ($entries as $e{
  87.             $selection_items .= "<option value=\"{$e->name}\">{$e->name}</option>\n";
  88.         }
  89.         $selection_items .= '</select>';
  90.         
  91.         // Get a list of all avatars on the site
  92.         $avatars get_records('sloodle_users''''''avname');
  93.         if (!$avatars$avatars array();
  94.         // Construct the selection box of avatars
  95.         $selection_avatars '<select name="user" size="1">';
  96.         foreach ($avatars as $a{
  97.             if (!empty($a->uuid)) {
  98.                 $sel '';
  99.                 if ($a->avname == $defaultavatar$sel 'selected="true"';
  100.                 $selection_avatars .= "<option value=\"{$a->uuid}\" $sel>{$a->avname}</option>\n";
  101.             }
  102.         }
  103.         $selection_avatars .= '</select>';
  104.         
  105.  
  106.         // There will be 3 forms:
  107.         //  - send to self
  108.         //  - send to another avatar on the site
  109.         //  - send to custom UUID
  110.         // The first 1 will be available to any registered user whose avatar is in the database.
  111.         // The other 2 will only be available to those with the activity management capability.
  112.         // Furthermore, the 2nd form will only be available if there is at least 1 avatar registered on the site.
  113.  
  114.         // Start of the sending forms
  115.         print_box_start('generalbox boxaligncenter boxwidthnormal centerpara');
  116.         
  117.     // // SEND TO SELF // //
  118.         
  119.         // Start the form
  120.         echo '<form action="" method="POST">';
  121.         
  122.         // Use a table for layout
  123.         $table_sendtoself new stdClass();
  124.         $table_sendtoself->head array(get_string('sloodleobjectdistributor:sendtomyavatar','sloodle'));
  125.         $table_sendtoself->align array('center');
  126.         
  127.         // Fetch the current user's Sloodle info
  128.         $sloodleuser get_record('sloodle_users''userid'$USER->id);
  129.         if (!$sloodleuser{
  130.             $table_sendtoself->data[array('<span style="color:red;">'.get_string('avatarnotlinked','sloodle').'</span>');
  131.         else {
  132.             // Output the hidden form data
  133.             echo <<<XXXEODXXX
  134.  <input type="hidden" name="s" value="{$sloodle->id}">
  135.  <input type="hidden" name="user" value="{$sloodleuser->uuid}">
  136. XXXEODXXX;
  137.         
  138.             // Object selection box
  139.             $table_sendtoself->data[array(get_string('selectobject','sloodle').': '.$selection_items);
  140.             // Submit button
  141.             $table_sendtoself->data[array('<input type="submit" '.$disabledattr.' value="'.get_string('sloodleobjectdistributor:sendtomyavatar','sloodle').' ('.$sloodleuser->avname.')" />');
  142.         }
  143.         
  144.         // Print the table
  145.         print_table($table_sendtoself);
  146.         
  147.         // End the form
  148.         echo "</form>";
  149.         
  150.         
  151.         // Only show the other options if protected items are to be shown
  152.         if ($showprotected{
  153.         // // SEND TO ANOTHER AVATAR // //
  154.             
  155.             // Start the form
  156.             echo '<br><form action="" method="POST">';
  157.             
  158.             // Use a table for layout
  159.             $table new stdClass();
  160.             $table->head array(get_string('sloodleobjectdistributor:sendtoanotheravatar','sloodle'));
  161.             $table->align array('center');
  162.             
  163.             // Do we have any avatars?
  164.             if (count($avatars1{
  165.                 $table->data[array('<span style="color:red;">'.get_string('nosloodleusers','sloodle').'</span>');
  166.             else {
  167.                 // Output the hidden form data
  168.                 echo <<<XXXEODXXX
  169.      <input type="hidden" name="s" value="{$sloodle->id}">
  170. XXXEODXXX;
  171.                 // Avatar selection box
  172.                 $table->data[array(get_string('selectuser','sloodle').': '.$selection_avatars);
  173.                 // Object selection box
  174.                 $table->data[array(get_string('selectobject','sloodle').': '.$selection_items);
  175.                 // Submit button
  176.                 $table->data[array('<input type="submit" '.$disabledattr.' value="'.get_string('sloodleobjectdistributor:sendtoanotheravatar','sloodle').'" />');
  177.             }
  178.             
  179.             // Print the table
  180.             print_table($table);
  181.             
  182.             // End the form
  183.             echo "</form>";
  184.             
  185.         // // SEND TO A CUSTOM AVATAR // //
  186.             
  187.             // Start the form
  188.             echo '<br><form action="" method="POST">';
  189.             
  190.             // Use a table for layout
  191.             $table new stdClass();
  192.             $table->head array(get_string('sloodleobjectdistributor:sendtocustomavatar','sloodle'));
  193.             $table->align array('center');
  194.             
  195.             // Output the hidden form data
  196.             echo <<<XXXEODXXX
  197. <input type="hidden" name="s" value="{$sloodle->id}">
  198. XXXEODXXX;
  199.         
  200.             // UUID box
  201.             $table->data[array(get_string('uuid','sloodle').': '.'<input type="text" name="user" size="46" maxlength="36" />');
  202.             // Object selection box
  203.             $table->data[array(get_string('selectobject','sloodle').': '.$selection_items);
  204.             // Submit button
  205.             $table->data[array('<input type="submit" '.$disabledattr.' value="'.get_string('sloodleobjectdistributor:sendtocustomavatar','sloodle').'" />');
  206.             
  207.             // Print the table
  208.             print_table($table);
  209.             
  210.             // End the form
  211.             echo "</form>";
  212.             
  213.         // // ---------- // //
  214.         }
  215.     
  216.         
  217.         print_box_end();
  218.         
  219.         return true;
  220.     }
  221.     
  222.     
  223. ?>

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