Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • /course/ -> user.php (source)

    Differences Between: [Versions 28 and 29] [Versions 28 and 30] [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       1  <?php
       2  // This file is part of Moodle - http://moodle.org/
       3  //
       4  // Moodle is free software: you can redistribute it and/or modify
       5  // it under the terms of the GNU General Public License as published by
       6  // the Free Software Foundation, either version 3 of the License, or
       7  // (at your option) any later version.
       8  //
       9  // Moodle is distributed in the hope that it will be useful,
      10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12  // GNU General Public License for more details.
      13  //
      14  // You should have received a copy of the GNU General Public License
      15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
      16  
      17  /**
      18   * Display user activity reports for a course
      19   *
      20   * @copyright 1999 Martin Dougiamas  http://dougiamas.com
      21   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      22   * @package course
      23   */
      24  
      25  require_once("../config.php");
      26  require_once ("lib.php");
      27  
      28  $id      = required_param('id',PARAM_INT);       // course id
      29  $user    = required_param('user',PARAM_INT);     // user id
      30  $mode    = optional_param('mode', "todaylogs", PARAM_ALPHA);
      31  
      32  $url = new moodle_url('/course/user.php', array('id'=>$id,'user'=>$user, 'mode'=>$mode));
      33  
      34  $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
      35  $user = $DB->get_record("user", array("id"=>$user, 'deleted'=>0), '*', MUST_EXIST);
      36  
      37  if ($mode === 'outline' or $mode === 'complete') {
      38      $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode));
      39      redirect($url);
      40  }
      41  if ($mode === 'todaylogs' or $mode === 'alllogs') {
      42      $logmode = ($mode === 'todaylogs') ? 'today' : 'all';
      43      $url = new moodle_url('/report/log/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$logmode));
      44      redirect($url);
      45  }
      46  if ($mode === 'stats') {
      47      $url = new moodle_url('/report/stats/user.php', array('id'=>$user->id, 'course'=>$course->id));
      48      redirect($url);
      49  }
      50  if ($mode === 'coursecompletions' or $mode === 'coursecompletion') {
      51      $url = new moodle_url('/report/completion/user.php', array('id'=>$user->id, 'course'=>$course->id));
      52      redirect($url);
      53  }
      54  
      55  $coursecontext   = context_course::instance($course->id);
      56  $personalcontext = context_user::instance($user->id);
      57  
      58  $PAGE->set_url('/course/user.php', array('id'=>$id, 'user'=>$user->id, 'mode'=>$mode));
      59  
      60  require_login();
      61  $PAGE->set_pagelayout('report');
      62  if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !is_enrolled($coursecontext)) {
      63      // do not require parents to be enrolled in courses ;-)
      64      $PAGE->set_course($course);
      65  } else {
      66      require_login($course);
      67  }
      68  
      69  if ($user->deleted) {
      70      echo $OUTPUT->header();
      71      echo $OUTPUT->heading(get_string('userdeleted'));
      72      echo $OUTPUT->footer();
      73      die;
      74  }
      75  
      76  // prepare list of allowed modes
      77  $myreports  = ($course->showreports and $USER->id == $user->id);
      78  $anyreport  = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
      79  
      80  $modes = array();
      81  
      82  // Used for grade reports, it represents whether we should be viewing the report as ourselves, or as the targetted user.
      83  $viewasuser = false;
      84  
      85  if (has_capability('moodle/grade:viewall', $coursecontext)) {
      86      //ok - can view all course grades
      87      $modes[] = 'grade';
      88  
      89  } else if ($course->showgrades and $user->id == $USER->id and has_capability('moodle/grade:view', $coursecontext)) {
      90      //ok - can view own grades
      91      $modes[] = 'grade';
      92  
      93  } else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) {
      94      // ok - can view grades of this user - parent most probably
      95      $modes[] = 'grade';
      96      $viewasuser = true;
      97  
      98  } else if ($course->showgrades and $anyreport) {
      99      // ok - can view grades of this user - parent most probably
     100      $modes[] = 'grade';
     101      $viewasuser = true;
     102  }
     103  
     104  if (empty($modes)) {
     105      require_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
     106  }
     107  
     108  if (!in_array($mode, $modes)) {
     109      // forbidden or non-existent mode
     110      $mode = reset($modes);
     111  }
     112  
     113  $eventdata = array(
     114      'context' => $coursecontext,
     115      'relateduserid' => $user->id,
     116      'other' => array('mode' => $mode),
     117  );
     118  $event = \core\event\course_user_report_viewed::create($eventdata);
     119  $event->trigger();
     120  
     121  $stractivityreport = get_string("activityreport");
     122  
     123  $PAGE->navigation->extend_for_user($user);
     124  $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
     125  $PAGE->set_title("$course->shortname: $stractivityreport ($mode)");
     126  $PAGE->set_heading($course->fullname);
     127  echo $OUTPUT->header();
     128  
     129  switch ($mode) {
     130      case "grade":
     131          if (empty($CFG->grade_profilereport) or !file_exists($CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php')) {
     132              $CFG->grade_profilereport = 'user';
     133          }
     134          require_once $CFG->libdir.'/gradelib.php';
     135          require_once $CFG->dirroot.'/grade/lib.php';
     136          require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php';
     137  
     138          $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport';
     139          if (function_exists($functionname)) {
     140              $functionname($course, $user, $viewasuser);
     141          }
     142          break;
     143  
     144          break;
     145      default:
     146          // can not be reached ;-)
     147  }
     148  
     149  
     150  echo $OUTPUT->footer();
    

    Search This Site: