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('config.php');
  26.     /** General Sloodle functionality. */
  27.     require_once(SLOODLE_DIRROOT.'/lib/sl_generallib.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.     // Are we searching for users?
  74.     if ($searchstr != NULL)
  75.     {
  76.         // Display the search term
  77.         echo '<br/><span style="font-size:16pt; font-weight:bold;">'.get_string('usersearch','sloodle').': '.$searchstr.'</span><br/><br/>';
  78.         // Search the list of users
  79.         $userlist get_users(true$searchstr);
  80.     else {
  81.         // Getting all users in a course
  82.         // Display the name of the course
  83.         echo '<br/><span style="font-size:18pt; font-weight:bold;">'.$coursefullname.'</span><br/><br/>';
  84.         // Obtain a list of all Moodle users enrolled in the specified course
  85.         $userlist get_course_users($courseid'lastname, firstname''''u.id, firstname, lastname');
  86.     }
  87.     
  88.     // Construct and display a table of Sloodle entries
  89.     if ($userlist{
  90.         $sloodletable new stdClass();
  91.         $sloodletable->head array(    get_string('ID''sloodle'),
  92.                                         get_string('name''sloodle'),
  93.                                         get_string('numsloodleentries''sloodle'),
  94.                                         get_string('avatarname''sloodle')
  95.                                     );
  96.         $sloodletable->align array('center''left''left''left');
  97.                 
  98.         // Go through each Sloodle entry for this user
  99.         foreach ($userlist as $u{            
  100.             // Reset the line's content
  101.             $line array();
  102.             
  103.             // Construct a URL to this user's Sloodle profile data
  104.             $url SLOODLE_WWWROOT."/view_user.php?id={$u->id}&amp;course=$courseid";
  105.             
  106.             // Add the ID and Moodle name to the line
  107.             $line[$u->id;
  108.             // Add the Moodle name
  109.             $line["<a href=\"$url\">{$u->firstname} {$u->lastname}</a>";
  110.             
  111.             // Get the Sloodle data for this Moodle user
  112.             $sloodledata get_records('sloodle_users''userid'$u->id);
  113.             if ($sloodledata{
  114.                 // Show the number of records
  115.                 $numrecs count($sloodledata);
  116.                 if ($numrecs <= 1$line[= (string)$numrecs;
  117.                 else $line['<span style="font-weight:bold;color:red;">'.$numrecs.'</span>';
  118.                 
  119.                 // Display all avatars names, if available
  120.                 $avnames '';
  121.                 $firstentry true;
  122.                 foreach ($sloodledata as $sd{
  123.                     // If this entry is empty, then skip it
  124.                     if (empty($sd->avname|| ctype_space($sd->avname)) continue;
  125.                     // Comma separated entries
  126.                     if ($firstentry$firstentry false;
  127.                     else $avnames .= ', ';
  128.                     // Add the current name
  129.                     $avnames .= $sd->avname;
  130.                 }
  131.                 // Add the avatar name(s) to the line
  132.                 $line[$avnames;                
  133.                 
  134.             else {
  135.                 // The query failed - if we are showing only Sloodle-enabled users, then skip the rest
  136.                 if ($sloodleonlycontinue;
  137.                 $line['0';
  138.                 $line['-';
  139.             }
  140.             
  141.             // Add the line to the table
  142.             $sloodletable->data[$line;
  143.         }
  144.         
  145.         // Display the table
  146.         print_table($sloodletable);
  147.     else {
  148.         // Failed to query for list of users
  149.         echo '<div style="font-weight:bold; color:red;">';
  150.         print_string('nouserdata','sloodle');
  151.         echo '</div>';
  152.     }
  153.     echo '</div>';
  154.     
  155.     
  156.  
  157.     
  158.     echo '<br/><center><table style="text-align:left; vertical-align:top;">';
  159. // // SEARCH FORMS // //
  160.     echo '<tr>';
  161.  
  162.     // COURSE SELECT FORM //
  163.     
  164.     echo '<td style="width:350px; border:solid 1px #888888; padding:4px; vertical-align:top;">';
  165.     
  166.     echo "<form action=\"{$CFG->wwwroot}/mod/sloodle/view_users.php\" method=\"get\">";
  167.     echo '<span style="font-weight:bold;">'.get_string('changecourse','sloodle').'</span><br/>';
  168.     
  169.     echo '<select name="course" size="1">';
  170.     
  171.     // Get a list of all courses
  172.     $allcourses get_courses('all''c.shortname''c.id, c.shortname, c.fullname');
  173.     if (!$allcourses$allcourses array();
  174.     foreach ($allcourses as $as{
  175.         // Get if the user is a teacher on this course
  176.         if (isteacher($as->id)) {
  177.             // Output this as an option
  178.             echo "<option value=\"{$as->id}\"";
  179.             if ($as->id == $courseidecho "selected";
  180.             echo ">{$as->fullname}</option>";
  181.         }
  182.     }    
  183.     echo '</select><br/>';
  184.     
  185.     echo '<input type="checkbox" value="true" name="sloodleonly"';
  186.     if ($sloodleonlyecho "checked";
  187.     echo '/>'.get_string('showavatarsonly','sloodle').'<br/>';
  188.     
  189.     echo '<input type="submit" value="'.get_string('submit','sloodle').'" />';
  190.     echo '</form>';
  191.     
  192.     echo '</td>';
  193.     
  194.     // SEARCH FORM //
  195.     echo '<td style="width:350px; border:solid 1px #888888; padding:4px; vertical-align:top;">';    
  196.     
  197.     echo "<form action=\"{$CFG->wwwroot}/mod/sloodle/view_users.php\" method=\"get\">";
  198.     echo '<span style="font-weight:bold;">'.get_string('usersearch','sloodle').'</span><br/>';
  199.     echo '<input type="text" value="'.$searchstr.'" name="search" size="30" maxlength="30"/><br/>';
  200.     
  201.     echo '<input type="checkbox" value="true" name="sloodleonly"';
  202.     if ($sloodleonlyecho "checked";
  203.     echo '/>'.get_string('showavatarsonly','sloodle').'<br/>';
  204.     
  205.     echo '<input type="submit" value="'.get_string('submit','sloodle').'" />';
  206.     echo '</form>';
  207.     
  208.     echo '</td>';
  209.     
  210.     
  211.     
  212.     // SPECIAL PAGES //
  213.     echo '<td style="width:350px; border:solid 1px #888888; padding:4px; vertical-align:top;">';
  214.     echo '<span style="font-weight:bold;">'.get_string('specialpages','sloodle').'</span><br/>';
  215.     
  216.     echo '<p>';
  217.     echo "<a href=\"{$CFG->wwwroot}/mod/sloodle/view_user.php?id=0\" title=\"".get_string('viewunlinked','sloodle')."\">";
  218.     print_string('viewunlinked','sloodle');
  219.     echo '</a><br/>';
  220.     
  221.     echo "<a href=\"{$CFG->wwwroot}/mod/sloodle/view_user.php?id=all\" title=\"".get_string('viewall','sloodle')."\">";
  222.     print_string('viewall','sloodle');
  223.     echo '</a><br/>';
  224.     echo '</p>';
  225.     
  226.     echo '</td>';
  227.     
  228.     
  229.     
  230. // // - END FORMS - // //
  231.     echo '</tr>';
  232.     echo '</table></center>';
  233.     
  234.     // Close the main body section
  235.     echo '</div>';
  236.  
  237.     
  238.     // Display the footer
  239.     print_footer();
  240. ?>

Documentation generated on Tue, 04 Mar 2008 15:09:01 +0000 by phpDocumentor 1.4.0