Source for file view_users.php

Documentation is available at view_users.php

  1. <?php
  2.     
  3.     /**
  4.     * Sloodle user profile page.
  5.     *
  6.     * Shows a list of users, with links to information about associated avatars/LoginZone allocations
  7.     *
  8.     * @package sloodle
  9.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor Peter R. Bloomfield
  13.     *
  14.     */
  15.     
  16.     // The 'course' parameter is optional, and should be an integer ID of the course to show users from
  17.     // Alternatively, if the 'search' parameter is specified, then 'course' is ignored, the the search string is used to search for Moodle users.
  18.     
  19.     // The 'sloodleonly' parameter is optional, and if 'true', will show only users who have associated Sloodle data
  20.     //
  21.     
  22.     // Note: this page is accessible only by teachers and administrators
  23.        
  24.     /** Sloodle/Moodle configuration. */
  25.     require_once('../sl_config.php');
  26.     /** General Sloodle functionality. */
  27.     require_once(SLOODLE_LIBROOT.'/general.php');
  28.     
  29.     // Enforce login
  30.     require_login();
  31.     // Refuse guest access
  32.     if (isguest()) {
  33.         error(get_string('noguestaccess''sloodle'));
  34.         exit;
  35.     }
  36.     
  37.     // Fetch the parameters
  38.     $courseid optional_param('course'NULLPARAM_INT);
  39.     $searchstr optional_param('search'NULLPARAM_RAW);
  40.     $sloodleonly optional_param('sloodleonly'falsePARAM_BOOL);
  41.     
  42.     // If a search string was specified, then force the course value to the site course
  43.     if ($searchstr != NULL$courseid 1;
  44.     // If neither a search string nor a course was specified, then stop on an error
  45.     if ($searchstr == NULL && $courseid == NULLerror(get_string('error:expectedsearchorcourse''sloodle'));
  46.     
  47.     // Get the course data (if no course specified, use the site course)
  48.     $courserecord get_record('course''id'$courseid);
  49.     if (!$courserecorderror(get_string('invalidcourseid','sloodle'));
  50.     $courseurl $CFG->wwwroot.'/course/view.php?id='.$courseid;
  51.     $courseshortname $courserecord->shortname;
  52.     $coursefullname $courserecord->fullname;
  53.     
  54.     // Only allow teachers and admins
  55.     if (isadmin(== false && isteacherinanycourse(== false{
  56.         error(get_string('insufficientpermissiontoviewpage','sloodle'));
  57.         exit();
  58.     }
  59.     
  60.     // Get the localization strings
  61.     $strsloodle get_string('modulename''sloodle');
  62.     $strsloodles get_string('modulenameplural''sloodle');
  63.     
  64.     // Display the header
  65.     $navigation '';
  66.     if ($courseid != 1$navigation .= "<a href=\"$courseurl\">$courseshortname</a> -> ";
  67.     $navigation .= get_string('sloodleuserprofiles''sloodle');
  68.     print_header(get_string('sloodleuserprofiles''sloodle')get_string('sloodleuserprofiles''sloodle')$navigation""""false);
  69.     
  70.     // Open the main body section
  71.     echo '<div style="text-align:center;padding-left:8px;padding-right:8px;">';
  72.     
  73.     
  74. //------------------------------------------------------
  75.     
  76.     print_box_start('generalbox boxwidthwide boxaligncenter');
  77.     echo '<table style="text-align:left; vertical-align:top; margin-left:auto; margin-right:auto;">';
  78. // // SEARCH FORMS // //
  79.     echo '<tr>';
  80.  
  81.     // COURSE SELECT FORM //
  82.     echo '<td style="width:350px; border:solid 1px #bbbbbb; padding:4px; vertical-align:top; width:33%;">';
  83.     
  84.     echo "<form action=\"{$CFG->wwwroot}/mod/sloodle/view/view_users.php\" method=\"get\">";
  85.     echo '<span style="font-weight:bold;">'.get_string('changecourse','sloodle').'</span><br/>';
  86.     
  87.     echo '<select name="course" size="1">';
  88.     
  89.     // Get a list of all courses
  90.     $allcourses get_courses('all''c.shortname''c.id, c.shortname, c.fullname');
  91.     if (!$allcourses$allcourses array();
  92.     foreach ($allcourses as $as{
  93.         // Get if the user is a teacher on this course
  94.         if (isteacher($as->id)) {
  95.             // Output this as an option
  96.             echo "<option value=\"{$as->id}\"";
  97.             if ($as->id == $courseidecho "selected";
  98.             echo ">{$as->fullname}</option>";
  99.         }
  100.     }    
  101.     echo '</select><br/>';
  102.     
  103.     echo '<input type="checkbox" value="true" name="sloodleonly"';
  104.     if ($sloodleonlyecho "checked";
  105.     echo '/>'.get_string('showavatarsonly','sloodle').'<br/>';
  106.     echo '<input type="submit" value="'.get_string('submit','sloodle').'" />';
  107.     
  108.     echo '</form>';
  109.     
  110.     echo '</td>';
  111.     
  112.     // USER SEARCH FORM //
  113.     echo '<td style="width:350px; border:solid 1px #bbbbbb; padding:4px; vertical-align:top; width:33%;">';    
  114.     
  115.     echo "<form action=\"{$CFG->wwwroot}/mod/sloodle/view/view_users.php\" method=\"get\">";
  116.     echo '<span style="font-weight:bold;">'.get_string('usersearch','sloodle').'</span><br/>';
  117.     echo '<input type="hidden" value="'.$courseid.'" name="course"/>';
  118.     echo '<input type="text" value="'.$searchstr.'" name="search" size="30" maxlength="30"/><br/>';
  119.     
  120.     echo '<input type="checkbox" value="true" name="sloodleonly"';
  121.     if ($sloodleonlyecho "checked";
  122.     echo '/>'.get_string('showavatarsonly','sloodle').'<br/>';
  123.     
  124.     echo '<input type="submit" value="'.get_string('submit','sloodle').'" />';
  125.     echo '</form>';
  126.     
  127.     echo '</td>';
  128.     
  129.     
  130.     
  131.     // AVATAR SEARCH //
  132.     echo '<td style="width:350px; border:solid 1px #bbbbbb; padding:4px; vertical-align:top; width:33%;">';
  133.     //echo '<span style="font-weight:bold;">'.get_string('specialpages','sloodle').'</span><br/>';
  134.     echo '<span style="font-weight:bold;">'.get_string('avatarsearch','sloodle').'</span><br/>';
  135.     
  136.     echo "<form action=\"{$CFG->wwwroot}/mod/sloodle/view/view_user.php\" method=\"get\">";
  137.     echo '<input type="hidden" value="search" name="id"/>';
  138.     echo '<input type="hidden" value="'.$courseid.'" name="course"/>';
  139.     echo '<input type="text" value="'.$searchstr.'" name="search" size="30" maxlength="30"/><br/>';
  140.     echo '<input type="submit" value="'.get_string('submit','sloodle').'" />';
  141.     echo '</form>';
  142.     
  143.     echo '<p>';
  144.     echo "<a href=\"{$CFG->wwwroot}/mod/sloodle/view/view_user.php?id=all\" title=\"".get_string('viewall','sloodle')."\">";
  145.     print_string('viewall','sloodle');
  146.     echo '</a><br/>';
  147.     echo '</p>';
  148.     
  149.     echo '</td>';
  150.     
  151.     
  152.     
  153. // // - END FORMS - // //
  154.     echo '</tr>';
  155.     echo '</table>';
  156.     print_box_end();
  157.  
  158.     
  159. //------------------------------------------------------
  160.  
  161.     
  162.     // Are we searching for users?
  163.     if ($searchstr != NULL)
  164.     {
  165.         // Display the search term
  166.         echo '<br/><span style="font-size:16pt; font-weight:bold;">'.get_string('usersearch','sloodle').': '.$searchstr.'</span><br/><br/>';
  167.         // Search the list of users
  168.         $userlist get_users(true$searchstr);
  169.         
  170.         
  171.     else {
  172.         // Getting all users in a course
  173.         // Display the name of the course
  174.         echo '<br/><span style="font-size:18pt; font-weight:bold;">'.$coursefullname.'</span><br/><br/>';
  175.         // Obtain a list of all Moodle users enrolled in the specified course
  176.         $userlist get_course_users($courseid'lastname, firstname''''u.id, firstname, lastname');
  177.     }
  178.     
  179.     // Construct and display a table of Sloodle entries
  180.     if ($userlist{
  181.         $sloodletable new stdClass();
  182.         $sloodletable->head array(    get_string('ID''sloodle'),
  183.                                         get_string('name''sloodle'),
  184.                                         get_string('numsloodleentries''sloodle'),
  185.                                         get_string('avatarname''sloodle')
  186.                                     );
  187.         $sloodletable->align array('center''left''left''left');
  188.                 
  189.         // Go through each Sloodle entry for this user
  190.         foreach ($userlist as $u{            
  191.             // Reset the line's content
  192.             $line array();
  193.             
  194.             // Construct a URL to this user's Sloodle profile data
  195.             $url SLOODLE_WWWROOT."/view/view_user.php?id={$u->id}&amp;course=$courseid";
  196.             
  197.             // Add the ID and Moodle name to the line
  198.             $line[$u->id;
  199.             // Add the Moodle name
  200.             $line["<a href=\"$url\">{$u->firstname} {$u->lastname}</a>";
  201.             
  202.             // Get the Sloodle data for this Moodle user
  203.             $sloodledata get_records('sloodle_users''userid'$u->id);
  204.             if ($sloodledata{
  205.                 // Show the number of records
  206.                 $numrecs count($sloodledata);
  207.                 if ($numrecs <= 1$line[= (string)$numrecs;
  208.                 else $line['<span style="font-weight:bold;color:red;">'.$numrecs.'</span>';
  209.                 
  210.                 // Display all avatars names, if available
  211.                 $avnames '';
  212.                 $firstentry true;
  213.                 foreach ($sloodledata as $sd{
  214.                     // If this entry is empty, then skip it
  215.                     if (empty($sd->avname|| ctype_space($sd->avname)) continue;
  216.                     // Comma separated entries
  217.                     if ($firstentry$firstentry false;
  218.                     else $avnames .= ', ';
  219.                     // Add the current name
  220.                     $avnames .= $sd->avname;
  221.                 }
  222.                 // Add the avatar name(s) to the line
  223.                 $line[$avnames;                
  224.                 
  225.             else {
  226.                 // The query failed - if we are showing only Sloodle-enabled users, then skip the rest
  227.                 if ($sloodleonlycontinue;
  228.                 $line['0';
  229.                 $line['-';
  230.             }
  231.             
  232.             // Add the line to the table
  233.             $sloodletable->data[$line;
  234.         }
  235.         
  236.         // Display the table
  237.         print_table($sloodletable);
  238.     else {
  239.         // Failed to query for list of users
  240.         echo '<div style="font-weight:bold; color:red;">';
  241.         print_string('nouserdata','sloodle');
  242.         echo '</div>';
  243.     }
  244.     echo '</div>';
  245.     
  246.     
  247.     
  248.     // Close the main body section
  249.     echo '</div>';
  250.  
  251.     
  252.     // Display the footer
  253.     print_footer();
  254. ?>

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