Source for file user.php

Documentation is available at user.php

  1. <?php
  2. /**
  3. * Defines a base class for viewing information about a specific SLOODLE user (avatar).
  4. * Class is inherited from the base view class.
  5. *
  6. @package sloodle
  7. @copyright Copyright (c) 2009 Sloodle (various contributors)
  8. @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. @contributor Peter R. Bloomfield
  11. */
  12.  
  13. /** The base view class */
  14. require_once(SLOODLE_DIRROOT.'/view/base/base_view.php');
  15. /** SLOODLE course data structure */
  16. require_once(SLOODLE_LIBROOT.'/course.php');
  17. /** Sloodle Session code. */
  18. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  19. /** General Sloodle functionality. */
  20. require_once(SLOODLE_LIBROOT.'/general.php');
  21.  
  22. /**
  23. * Class for rendering a view of SLOODLE user information.
  24. @package sloodle
  25. */
  26. {
  27.     /**
  28.     * Integer ID of the course which is being accessed.
  29.     * @var integer 
  30.     * @access private
  31.     */
  32.     var $courseid = 0;
  33.     
  34.     /**
  35.     * The VLE course object, retrieved directly from database.
  36.     * @var object 
  37.     * @access private
  38.     */
  39.     var $course = 0;
  40.  
  41.     /**
  42.     * SLOODLE course object, retrieved directly from database.
  43.     * @var object 
  44.     * @access private
  45.     */
  46.     var $sloodle_course = null;
  47.     
  48.     /**
  49.     * Integer ID of the Moodle user being viewed.
  50.     * Supplied by request parameter.
  51.     * @var integer 
  52.     * @access private
  53.     */
  54.     var $moodleuserid = null;
  55.     
  56.     /**
  57.     * Integer ID of a SLOODLE user entry to delete, where supplied by request parameter.
  58.     * Null or 0 indicates nothing is to be deleted.
  59.     * @var integer 
  60.     * @access private
  61.     */
  62.     var $deletesloodleentry = null;
  63.     
  64.     /**
  65.     * Indicates a confirmation for certain actions, such as deletion, supplied by request parameter.
  66.     * @var string 
  67.     * @access private
  68.     */
  69.     var $userconfirmed = null;
  70.     
  71.     /**
  72.     * The search string for users where appropriate.
  73.     * @var string 
  74.     * @access private
  75.     */
  76.     var $searchstr = '';
  77.     
  78.     /**
  79.     * List of user objects to be deleted (stored as a string, retrieved from request parameters).
  80.     * @var string 
  81.     * @access private
  82.     */
  83.     var $deleteuserobjects = null;
  84.  
  85.     /**
  86.     * Moodle permissions context for the current course.
  87.     * @var object 
  88.     * @access private
  89.     */
  90.     var $course_context = null;
  91.     
  92.     /**
  93.     * Moodle permissions context for the system.
  94.     * @var object 
  95.     * @access private
  96.     */
  97.     var $system_context = null;
  98.     
  99.     /**
  100.     * Is the user viewing their own profile?
  101.     * @var bool 
  102.     * @access private
  103.     */
  104.     var $viewingself = false;
  105.     
  106.     /**
  107.     * Can the user edit the data they are viewing?
  108.     * @var bool 
  109.     * @access private
  110.     */
  111.     var $canedit = false;
  112.     
  113.     /**
  114.     * The result number to start displaying from
  115.     * @var integer 
  116.     * @access private
  117.     */
  118.     var $start = 0;
  119.  
  120.  
  121.     /**
  122.     * Constructor.
  123.     */
  124.     function sloodle_view_user()
  125.     {
  126.     }
  127.  
  128.     /**
  129.     * Check and process the request parameters.
  130.     */
  131.     function process_request()
  132.     {
  133.         // Fetch some parameters
  134.         $this->moodleuserid = required_param('id'PARAM_RAW);
  135.         $this->deletesloodleentry = optional_param('delete'nullPARAM_INT);
  136.         $this->userconfirmed = optional_param('confirm'nullPARAM_RAW);
  137.         $this->courseid = optional_param('course'SITEIDPARAM_INT);
  138.         $this->searchstr = addslashes(optional_param('search'''PARAM_TEXT));
  139.         $this->deleteuserobjects = optional_param('deleteuserobjects'nullPARAM_TEXT);
  140.         
  141.         // If we are viewing 'all' avatar entries, then revert to the site course
  142.         if (strcasecmp($this->moodleuserid'all'== 0$this->courseid = SITEID;
  143.     
  144.         // Fetch our Moodle and SLOODLE course data
  145.         if (!$this->course = get_record('course''id'$this->courseid)) error('Could not find course.');
  146.         $this->sloodle_course = new SloodleCourse();
  147.         if (!$this->sloodle_course->load($this->course)) error(get_string('failedcourseload''sloodle'));
  148.         $this->start = optional_param('start'0PARAM_INT);
  149.         if ($this->start < 0$this->start = 0;
  150.     }
  151.  
  152.     /**
  153.     * Check that the user is logged-in and has permission to alter course settings.
  154.     */
  155.     function check_permission()
  156.     {
  157.         global $CFG$USER;
  158.         
  159.         // Ensure the user logs in
  160.         require_login();
  161.         if (isguestuser()) error(get_string('noguestaccess''sloodle'));
  162.         //add_to_log($this->course->id, 'course', 'view sloodle user', '', "{$this->course->id}");
  163.         
  164.         // The "all" view should be only available to admins
  165.         if (strcasecmp($this->moodleuserid'all'== && isadmin(== false{
  166.             error(get_string('insufficientpermissiontoviewpage''sloodle'));
  167.             exit();
  168.         }
  169.         
  170.         // We need to establish some permissions here
  171.         $this->course_context = get_context_instance(CONTEXT_COURSE$this->courseid);
  172.         $this->system_context = get_context_instance(CONTEXT_SYSTEM);
  173.         $this->viewingself = false;
  174.         $this->canedit = false;
  175.         // Is the user trying to view their own profile?
  176.         if ($this->moodleuserid == $USER->id{
  177.             $this->viewingself = true;
  178.             $this->canedit = true;
  179.         else {
  180.             // Does the user have permission to edit other peoples' profiles in the system and/or course?
  181.             // If not, can they at least view others' profiles for the system or course?
  182.             if (has_capability('moodle/user:editprofile'$this->system_context|| has_capability('moodle/user:editprofile'$this->course_context)) {
  183.                 // User can edit profiles
  184.                 $this->canedit = true;
  185.             else if (!(has_capability('moodle/user:viewdetails'$this->system_context|| has_capability('moodle/user:viewdetails'$this->course_context))) {
  186.                 // If this is the site course, then let it through anyway
  187.                 if ($this->courseid != SITEID{
  188.                     error(get_string('insufficientpermissiontoviewpage','sloodle'));
  189.                     exit();
  190.                 }
  191.             }
  192.         }
  193.     }
  194.  
  195.     /**
  196.     * Print the course settings page header.
  197.     */
  198.     function print_header()
  199.     {
  200.     }
  201.  
  202.     /**
  203.     * Render the view of the module or feature.
  204.     * This MUST be overridden to provide functionality.
  205.     */
  206.     function render()
  207.     {
  208.         global $CFG$USER;
  209.         
  210.         // Were any of the delete parameters specified in HTTP (e.g. from a form)?
  211.         if (!empty($this->deleteuserobjects|| !empty($this->deletesloodleentry|| !empty($this->userconfirmed)) {
  212.             // Convert them to session parameters
  213.             if (!empty($this->deleteuserobjects)) $_SESSION['deleteuserobjects'$this->deleteuserobjects;
  214.             if (!empty($this->deletesloodleentry)) $_SESSION['deletesloodleentry'$this->deletesloodleentry;
  215.             if (!empty($this->userconfirmed)) $_SESSION['userconfirmed'$this->userconfirmed;
  216.             
  217.             // Construct our full URL, with GET parameters
  218.             $url sloodle_get_web_path();
  219.             $url .= "?_type=user&id={$this->moodleuserid}";
  220.             if (!empty($this->courseid)) $url .= "&course={$this->courseid}";
  221.             if (!empty($this->searchstr)) $url .= "&search={$this->searchstr}";
  222.             if (!empty($this->start)) $url .= "&start={$this->start}";
  223.             // Reload this page without those parameters
  224.             redirect($url);
  225.             exit();
  226.         }
  227.  
  228.         // Extract data from our session parameters
  229.         if (isset($_SESSION['deleteuserobjects'])) {
  230.             $this->deleteuserobjects = $_SESSION['deleteuserobjects'];
  231.             unset($_SESSION['deleteuserobjects']);
  232.         }
  233.         if (isset($_SESSION['deletesloodleentry'])) {
  234.             $this->deletesloodleentry = $_SESSION['deletesloodleentry'];
  235.             unset($_SESSION['deletesloodleentry']);
  236.         }
  237.         if (isset($_SESSION['userconfirmed'])) {
  238.             $this->userconfirmed = $_SESSION['userconfirmed'];
  239.             unset($_SESSION['userconfirmed']);
  240.         }
  241.         
  242.         // Check the mode: all, search, pending, or single
  243.         $allentries = false;
  244.         $searchentries = false;
  245.         if (strcasecmp($this->moodleuserid'all'== 0{
  246.             $allentries = true;
  247.             $this->moodleuserid = -1;
  248.         } else if (strcasecmp($this->moodleuserid'search'== 0{
  249.             $searchentries = true;
  250.             $this->moodleuserid = -1;
  251.         } else {
  252.             // Make sure the Moodle user ID is an integer
  253.             $this->moodleuserid = (integer)$this->moodleuserid;
  254.             if ($this->moodleuserid <= 0error(ucwords(get_string('unknownuser''sloodle')));
  255.         }
  256.         
  257.         
  258.         // Get the URL and names of the course
  259.         $courseurl = $CFG->wwwroot.'/course/view.php?_type=user&amp;id='.$this->courseid;
  260.         $courseshortname $this->course->shortname;
  261.         $coursefullname $this->course->fullname;
  262.         
  263.         // This value will indicate if we are currently confirming a deletion
  264.         $confirmingdeletion false;
  265.         
  266.         // These are localization strings used by the deletion confirmation form
  267.         $form_yes get_string('Yes''sloodle');
  268.         $form_no get_string('No''sloodle');
  269.         
  270.         
  271.         // Are we deleting a Sloodle entry?
  272.         $deletemsg '';    
  273.         if ($this->deletesloodleentry != NULL{
  274.             // Determine if the user is allowed to delete this entry
  275.             $allowdelete = $this->canedit// Just go with the editing ability for now... will maybe change this later. -PRB
  276.             
  277.             // Has the deletion been confirmed?
  278.             if ($this->userconfirmed == $form_yes{
  279.                 if (record_exists('sloodle_users', 'id', $this->deletesloodleentry)) {
  280.                     // Is the user allowed to delete this?
  281.                     if ($allowdelete) {
  282.                         // Make sure it's a valid ID
  283.                         if (is_int($this->deletesloodleentry&& $this->deletesloodleentry > 0{
  284.                             // Attempt to delete the entry
  285.                             $deleteresult = delete_records('sloodle_users', 'id', $this->deletesloodleentry);
  286.                             if ($deleteresult === FALSE{
  287.                                 $deletemsg = get_string('deletionfailed', 'sloodle').': '.get_string('databasequeryfailed', 'sloodle');
  288.                             } else {
  289.                                 $deletemsg = get_string('deletionsuccessful', 'sloodle');
  290.                             }
  291.                         } else {
  292.                             $deletemsg = get_string('deletionfailed', 'sloodle').': '.get_string('invalidid', 'sloodle');
  293.                         }
  294.                     } else {
  295.                         $deletemsg = get_string('deletionfailed', 'sloodle').': '.get_string('insufficientpermission', 'sloodle');
  296.                     }
  297.                 }
  298.             } else if (is_null($this->userconfirmed)) {
  299.                 // User needs to confirm deletion
  300.                 $confirmingdeletion = true;
  301.                 
  302.                 $form_url = SLOODLE_WWWROOT."/view.php";
  303.                 
  304.                 $deletemsg .= '<h3>'.get_string('delete','sloodle').' '.get_string('ID','sloodle').': '.$this->deletesloodleentry.'<br/>'.get_string('confirmdelete','sloodle').'</h3>';
  305.                 $deletemsg .= '<form action="'.$form_url.'" method="get">';
  306.                 $deletemsg .= '<input type="hidden" name="_type" value="user" />';
  307.                 
  308.                 if ($allentries$deletemsg .= '<input type="hidden" name="id" value="all" />';
  309.                 else if ($searchentries$deletemsg .= '<input type="hidden" name="id" value="search" /><input type="hidden" name="search" value="'.$this->searchstr.'" />';
  310.                 else $deletemsg .= '<input type="hidden" name="id" value="'.$this->moodleuserid.'" />';
  311.                 
  312.                 if (!is_null($this->courseid)) $deletemsg .= '<input type="hidden" name="course" value="'.$this->courseid.'" />';
  313.                 $deletemsg .= '<input type="hidden" name="delete" value="'.$this->deletesloodleentry.'" />';
  314.                 $deletemsg .= '<input type="hidden" name="start" value="'.$this->start.'" />';
  315.                 $deletemsg .= '<input style="color:green;" type="submit" value="'.$form_yes.'" name="confirm" />&nbsp;&nbsp;';
  316.                 $deletemsg .= '<input style="color:red;" type="submit" value="'.$form_no.'" name="confirm" />';
  317.                 $deletemsg .= '</form><br/>';
  318.                 
  319.             } else {
  320.                 $deletemsg = get_string('deletecancelled','sloodle');
  321.             }
  322.         }
  323.         
  324.         // Are we getting all entries, searching, or just viewing one?
  325.         if ($allentries) {
  326.             // All entries
  327.             $moodleuserdata = null;
  328.             // Fetch a list of all Sloodle user entries
  329.             $sloodleentries = get_records('sloodle_users');
  330.         } else if ($searchentries && !empty($this->searchstr)) {
  331.             // Search entries
  332.             $moodleuserdata = null;
  333.             $LIKE = sql_ilike();
  334.             $fullsloodleentries = get_records_select('sloodle_users', "avname $LIKE '%{$this->searchstr}%' OR uuid $LIKE '%{$this->searchstr}%'", 'avname');
  335.             if (!$fullsloodleentries) $fullsloodleentries = array();
  336.             $sloodleentries = array();
  337.             // Eliminate entries belonging to avatars who are not in the current course
  338.             foreach ($fullsloodleentries as $fse) {
  339.                 // Does the Moodle user have permission?
  340.                 if (has_capability('moodle/course:view', $this->course_context$fse->userid)) {
  341.                     // Copy it to our filtered list
  342.                     $sloodleentries[] = $fse;
  343.                 }
  344.             }
  345.             
  346.         } else {
  347.             // Attempt to fetch the Moodle user data
  348.             $moodleuserdata = get_record('user', 'id', $this->moodleuserid);
  349.             // Fetch a list of all Sloodle user entries associated with this Moodle account
  350.             $sloodleentries get_records('sloodle_users''userid'$this->moodleuserid);
  351.         }
  352.         // Post-process the query results
  353.         if ($sloodleentries === FALSE) $sloodleentries = array();
  354.         $numsloodleentries = count($sloodleentries);
  355.         
  356.         
  357.         // Get the localization strings
  358.         $strsloodle = get_string('modulename', 'sloodle');
  359.         $strsloodles = get_string('modulenameplural', 'sloodle');
  360.         $strunknown = get_string('unknown', 'sloodle');
  361.         
  362.         // Construct the breadcrumb links
  363.         $navigation = "";
  364.         if ($this->courseid != 1$navigation .= "<a href=\"$courseurl\">$courseshortname</a> -> ";
  365.         $navigation .= "<a href=\"".SLOODLE_WWWROOT."/view.php?_type=users&amp;course={$this->courseid}\">".get_string('sloodleuserprofiles', 'sloodle') . '</a> -> ';
  366.         if ($this->moodleuserid > 0{
  367.             if ($moodleuserdata) $navigation .= $moodleuserdata->firstname.' '.$moodleuserdata->lastname;
  368.             else $navigation .= get_string('unknownuser','sloodle');
  369.         } else if ($searchentries) {
  370.             $navigation .= get_string('avatarsearch', 'sloodle');
  371.         } else {
  372.             $navigation .= get_string('allentries', 'sloodle');
  373.         }
  374.         
  375.         // Display the header
  376.         print_header(get_string('sloodleuserprofile', 'sloodle'), get_string('sloodleuserprofile','sloodle'), $navigation, "", "", true);
  377.         
  378.         echo '<div style="text-align:center;padding-left:8px;padding-right:8px;">';
  379.         // Display the deletion message if we have one
  380.         if (!empty($deletemsg)) {
  381.             echo '<div style="text-align:center; padding:3px; border:solid 1px #aaaaaa; background-color:#dfdfdf; font-weight:bold; color:#dd0000;">';
  382.             echo $deletemsg;
  383.             echo '</div>';
  384.         }
  385.         echo '<br/>';
  386.         
  387.         // Are we dealing with an actual Moodle account?
  388.         if ($this->moodleuserid > 0{
  389.             echo '<p>';
  390.             // Yes - do we have an account?
  391.             if ($moodleuserdata) {
  392.                 // Yes - display the name and other general info
  393.                 echo '<span style="font-size:18pt; font-weight:bold;">'$moodleuserdata->firstname .' '$moodleuserdata->lastname.'</span>';
  394.                 echo " <span style=\"font-size:10pt; color:#444444; font-style:italic;\">(<a href=\"{$CFG->wwwroot}/user/view.php?id={$this->moodleuserid}&amp;course={$this->courseid}\">".get_string('moodleuserprofile','sloodle')."</a>)</span><br/>";
  395.             } else {
  396.                 echo get_string('moodleusernotfound', 'sloodle').'<br/>';
  397.             }        
  398.             echo "<br/><br/>\n";
  399.             
  400.             // Check for issues such as no entries, or multiple entries
  401.             if ($numsloodleentries == 0) {
  402.                 echo '<span style="color:red; font-weight:bold;">';
  403.                 print_string('noentries', 'sloodle');
  404.                 echo '</span>';
  405.                 // If it is the profile owner who is viewing this, then offer a link to the loginzone entry page
  406.                 if ($this->moodleuserid == $USER->id{
  407.                     echo "<br/><br/><p style=\"padding:8px; border:solid 1px #555555;\"><a href=\"{$CFG->wwwroot}/mod/sloodle/classroom/loginzone.php?id={$this->courseid}\">";
  408.                     print_string('getnewloginzoneallocation', 'sloodle');
  409.                     echo '</a></p>';
  410.                 }            
  411.                 
  412.             } else if ($numsloodleentries > 1) {
  413.                 echo '<span style="color:red; font-weight:bold; border:solid 2px #990000; padding:4px; background-color:white;">';
  414.                 print_string('multipleentries', 'sloodle');
  415.                 helpbutton('multiple_entries', get_string('help:multipleentries', 'sloodle'), 'sloodle', true, false);
  416.                 echo '</span>';
  417.             }
  418.             echo '</p>';
  419.             
  420.         } else if ($searchentries) {
  421.             // Searching for users
  422.             echo '<span style="font-size:18pt; font-weight:bold; ">'.get_string('avatarsearch','sloodle').": \"{$this->searchstr}\"</span><br/><br/>";
  423.             // Check to see if there are no entries
  424.             if ($numsloodleentries == 0) {
  425.                 echo '<span style="color:red; font-weight:bold;">';
  426.                 print_string('noentries', 'sloodle');
  427.                 echo '</span>';
  428.             }
  429.             
  430.         } else {
  431.             // Assume we're listing all entries - explain what this means
  432.             echo '<span style="font-size:18pt; font-weight:bold; ">'.get_string('allentries','sloodle').'</span><br/>';
  433.             echo '<center><p style="width:550px; text-align:left;">'.get_string('allentries:info', 'sloodle').'</p></center>';
  434.             
  435.             // Check to see if there are no entries
  436.             if ($numsloodleentries == 0) {
  437.                 echo '<span style="color:red; font-weight:bold;">';
  438.                 print_string('noentries', 'sloodle');
  439.                 echo '</span>';
  440.             }
  441.         }
  442.         
  443.         // Construct and display a table of Sloodle entries
  444.         if ($numsloodleentries > 0) {
  445.             $sloodletable = new stdClass();            
  446.             $sloodletable->head array(    get_string('avatarname''sloodle'),
  447.                                             get_string('avataruuid''sloodle'),
  448.                                             get_string('lastactive''sloodle'),
  449.                                             ''
  450.                                         );
  451.             $sloodletable->align array('left''left''left''left');
  452.             $sloodletable->size array('28%''42%''20%''10%');
  453.             
  454.             $deletestr get_string('delete''sloodle');
  455.             
  456.             // We want to build a list of Sloodle user objects too
  457.             $userobjects array();
  458.             // Create a dummy Sloodle Session
  459.             $sloodle new SloodleSession(false);
  460.             
  461.             // Check if our start is past the end of our results
  462.             if ($this->start >= count($sloodleentries)) $this->start = 0;
  463.                     
  464.             // Go through each Sloodle entry for this user
  465.             $resultnum 0;
  466.             $resultsdisplayed 0;
  467.             $maxperpage 20;
  468.             foreach ($sloodleentries as $su{
  469.             
  470.                 // Only display this result if it is after our starting result number
  471.                 if ($resultnum >= $this->start{
  472.                     // Add this user's Sloodle objects (if we're not in 'all' or search modes)
  473.                     if (!$allentries && !$searchentries) {
  474.                         if ($sloodle->user->load_avatar($su->uuid'')) {
  475.                             $userobjects += $sloodle->user->get_user_objects();
  476.                         }
  477.                     }
  478.                     
  479.                 
  480.                     // Is this entry being deleted (i.e. is the user being asked to confirm its deletion)?
  481.                     $deletingcurrent = ($confirmingdeletion == true && $su->id == $this->deletesloodleentry);
  482.                     
  483.                     // Reset the line's content
  484.                     $line array();
  485.                 
  486.                     // Fetch the avatar name and UUID
  487.                     $curavname '-';
  488.                     $curuuid '-';
  489.                     if (!empty($su->avname)) $curavname $su->avname;
  490.                     if (!empty($su->uuid)) $curuuid $su->uuid;
  491.                     
  492.                     // If we are in all or searching mode, add a link to the Sloodle user profile
  493.                     if ($allentries || $searchentries{
  494.                         //$curavname .= " <span style=\"font-size:10pt; color:#444444; font-style:italic;\">(<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=user&amp;id={$su->userid}&amp;course={$this->courseid}\">".get_string('sloodleuserprofile','sloodle')."</a>)</span>";
  495.                         $curavname = "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=user&amp;id={$su->userid}&amp;course={$this->courseid}\">{$curavname}</a>";
  496.                     }
  497.                     // Add a red cross beside the avatar name if it is being deleted
  498.                     if ($deletingcurrent) $curavname = '<span style="color:red; font-weight:bold;">X</span> '.$curavname;
  499.                     
  500.                     // Add them to the table
  501.                     $line[] = $curavname;
  502.                     $line[] = $curuuid; 
  503.                     
  504.                     // Do we know when the avatar was last active
  505.                     if (!empty($su->lastactive)) {
  506.                         // Calculate the time difference
  507.                         $difference = time() - (int)$su->lastactive;
  508.                         if ($difference 0$difference 0;
  509.                         // Add it to the table
  510.                         $line[sloodle_describe_approx_time($differencetrue);
  511.                     } else {
  512.                         $line[] = '('.$strunknown.')';
  513.                     }
  514.                     
  515.                     // Display the "delete" action
  516.                     if ($this->canedit || $su->userid == $USER->id{
  517.                         if ($allentries) $deleteurl = $CFG->wwwroot."/mod/sloodle/view.php?_type=user&amp;id=all&amp;course={$this->courseid}&amp;delete={$su->id}&amp;start={$this->start}";
  518.                         else if ($searchentries) $deleteurl = $CFG->wwwroot."/mod/sloodle/view.php?_type=user&amp;id=search&amp;course={$this->courseid}&amp;search={$this->searchstr}&amp;delete={$su->id}&amp;start={$this->start}";
  519.                         else $deleteurl = $CFG->wwwroot."/mod/sloodle/view.php?_type=user&amp;id={$this->moodleuserid}&amp;course={$this->courseid}&amp;delete={$su->id}&amp;start={$this->start}";
  520.                         $deletecaption = get_string('clicktodeleteentry','sloodle');
  521.                         $line[] = "<a href=\"$deleteurl\" title=\"$deletecaption\">$deletestr</a>";
  522.                         
  523.                     } else {
  524.                         $line[] = '<span style="color:#777777;" title="'.get_string('nodeletepermission','sloodle').'">'.get_string('delete','sloodle').'</span>';
  525.                     }
  526.                     
  527.                     // Add the line to the table
  528.                     $sloodletable->data[$line;
  529.                     $resultsdisplayed++;
  530.                 }
  531.                 
  532.                 // Have we displayed the maximum number of results for this page?
  533.                 $resultnum++;
  534.                 if ($resultsdisplayed >= $maxperpage) break;
  535.             }
  536.             
  537.             // Construct our basic URL to this page
  538.             $basicurl = SLOODLE_WWWROOT."/view.php?_type=user&amp;course={$this->courseid}";
  539.             if ($searchentries) $basicurl .= "&amp;id=search&amp;search={$this->searchstr}";
  540.             else if ($allentries) $basicurl .= "&amp;id=all";
  541.             else $basicurl .= "&amp;id={$this->moodleuserid}";
  542.             
  543.             // Construct the next/previous links
  544.             $previousstart = max(0, $this->start - $maxperpage);
  545.             $nextstart $this->start + $maxperpage;
  546.             $prevlink null;
  547.             $nextlink null;
  548.             if ($previousstart != $this->start$prevlink "<a href=\"{$basicurl}&amp;start={$previousstart}\" style=\"color:#0000ff;\">&lt;&lt;</a>&nbsp;&nbsp;";            
  549.             if ($nextstart < count($sloodleentries)) $nextlink = "<a href=\"{$basicurl}&amp;start={$nextstart}\" style=\"color:#0000ff;\">&gt;&gt;</a>";
  550.             
  551.             // Display the next/previous links, if we have at least one
  552.             if (!empty($prevlink) || !empty($nextlink)) {
  553.                 echo '<p style="text-align:center; font-size:14pt;">';
  554.                 if (!empty($prevlink)) echo $prevlink;
  555.                 else echo '<span style="color:#777777;">&lt;&lt;</span>&nbsp;&nbsp;';
  556.                 if (!empty($nextlink)) echo $nextlink;
  557.                 else echo '<span style="color:#777777;">&gt;&gt;</span>&nbsp;&nbsp;';
  558.                 echo '</p>';
  559.             }
  560.             
  561.             // Display the table
  562.             print_table($sloodletable);
  563.             
  564.             
  565.             // Now display the section of user-authorized objects
  566.             if (!$allentries && !$searchentries) {
  567.                 echo '<br><h3>'.get_string('userobjects','sloodle');
  568.                 helpbutton('user_objects', get_string('userobjects','sloodle'), 'sloodle', true, false, '', false);
  569.                 echo "</h3>\n";
  570.                 
  571.                 
  572.                 // Have we been asked to delete the user objects?
  573.                 if ($this->deleteuserobjects == 'true'{
  574.                     // Yes - display a confirmation form
  575.                     echo '<h4 style="color:red; font-weight:bold;">'.get_string('confirmdeleteuserobjects','sloodle').'</h4>';
  576.                     
  577.                     echo '<table style="border-style:none; margin-left:auto; margin-right:auto;"><tr><td>';
  578.                     
  579.                     echo '<form action="view_user.php" method="GET">';
  580.                     echo '<input type="hidden" name="_type" value="user" />';
  581.                     echo '<input type="hidden" name="id" value="'.$this->moodleuserid.'" >';
  582.                     if (!empty($courseid)) echo '<input type="hidden" name="course" value="'.$this->courseid.'" >';
  583.                     echo '<input type="hidden" name="deleteuserobjects" value="confirm" >';
  584.                     echo '<input type="hidden" name="start" value="'.$this->start.'" />';
  585.                     echo '<input type="submit" value="'.get_string('yes').'" title="'.get_string('deleteuserobjects:help','sloodle').'" >';
  586.                     echo '</form>';
  587.                     
  588.                     echo '</td><td>';
  589.                     
  590.                     echo '<form action="view_user.php" method="GET">';
  591.                     echo '<input type="hidden" name="id" value="'.$this->moodleuserid.'" >';
  592.                     if (!empty($this->courseid)) echo '<input type="hidden" name="course" value="'.$this->courseid.'" >';
  593.                     echo '<input type="hidden" name="start" value="'.$this->start.'" />';
  594.                     echo '<input type="submit" value="'.get_string('no').'" >';
  595.                     echo '</form>';
  596.                     
  597.                     echo '</td></tr></table><br>';
  598.                     
  599.                 } else if ($this->deleteuserobjects == 'confirm'{
  600.                     // Delete each one
  601.                     $numdeleted = 0;
  602.                     foreach ($userobjects as $obj) {
  603.                         delete_records('sloodle_user_object', 'id', $obj->id);
  604.                         $numdeleted++;
  605.                     }
  606.                     $userobjects = array();
  607.                     echo get_string('numdeleted','sloodle').': '.$numdeleted.'<br><br>';
  608.                 }
  609.                 
  610.                 
  611.                 // Do we have any objects to display?
  612.                 if (count($userobjects) > 0) {
  613.                     
  614.                     // Yes - prepare the table
  615.                     $sloodletable = new stdClass();
  616.                     $sloodletable->head array(    get_string('ID''sloodle'),
  617.                                                     get_string('avataruuid''sloodle'),
  618.                                                     get_string('uuid''sloodle'),
  619.                                                     get_string('name''sloodle'),
  620.                                                     get_string('isauthorized''sloodle'),
  621.                                                     get_string('lastused''sloodle')
  622.                                                 );
  623.                     $sloodletable->align array('center''left''left''left''center''left');
  624.                     //$sloodletable->size = array('5%', '5%', '27%', '35%', '20%', '8%');
  625.                     
  626.                     // Store the current timestamp for consistency
  627.                     $curtime time();
  628.                     
  629.                     // Go through each object
  630.                     foreach ($userobjects as $obj{
  631.                         $line = array();
  632.                         $line[] = $obj->id;
  633.                         $line[$obj->avuuid;
  634.                         $line[$obj->objuuid;
  635.                         $line[$obj->objname;
  636.                         if ($obj->authorized$line[ucwords(get_string('yes'));
  637.                         else $line[ucwords(get_string('no'));
  638.                         
  639.                         $lastused = (int)$obj->timeupdated;
  640.                         if ($lastused 0$line[sloodle_describe_approx_time($curtime $lastusedtrue);
  641.                         else $line['('.get_string('unknown','sloodle').')';
  642.                         
  643.                         $sloodletable->data[$line;
  644.                     }
  645.                     
  646.                     // Display the table
  647.                     print_table($sloodletable);
  648.                     
  649.                     // Display a button to delete all the Sloodle objects
  650.                     if (empty($deleteuserobjects)) {
  651.                         echo '<br><form action="user.php" method="GET">';
  652.                         echo '<input type="hidden" name="_type" value="user" />';
  653.                         echo '<input type="hidden" name="id" value="'.$this->moodleuserid.'" >';
  654.                         if (!empty($this->courseid)) echo '<input type="hidden" name="course" value="'.$this->courseid.'" >';
  655.                         echo '<input type="hidden" name="deleteuserobjects" value="true" >';
  656.                         echo '<input type="hidden" name="start" value="'.$this->start.'" />';
  657.                         echo '<input type="submit" value="'.get_string('deleteuserobjects','sloodle').'" title="'.get_string('deleteuserobjects:help','sloodle').'" >';
  658.                         echo '</form><br>';
  659.                     }
  660.                     
  661.                     
  662.                 } else {
  663.                     // No user objects
  664.                     echo '<span style="color:red; font-weight:bold;">';
  665.                     print_string('noentries', 'sloodle');
  666.                     echo '</span>';
  667.                 }
  668.             }
  669.             
  670.         }
  671.         echo '</div>';
  672.  
  673.     }
  674.  
  675.     /**
  676.     * Print the page footer.
  677.     */
  678.     function print_footer()
  679.     {
  680.         print_footer($this->course);
  681.     }
  682.  
  683. }
  684.  
  685.  

Documentation generated on Fri, 17 Jul 2009 11:02:40 +0100 by phpDocumentor 1.4.0