[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/forum/ -> user.php (source)

   1  <?php // $Id: user.php,v 1.30.2.7 2008/07/05 14:53:31 skodak Exp $
   2  
   3  // Display user activity reports for a course
   4  
   5      require_once('../../config.php');
   6      require_once ('lib.php');
   7      // Course ID
   8      $course  = required_param('course', PARAM_INT);
   9      // User ID
  10      $id      = optional_param('id', 0, PARAM_INT);
  11      $mode    = optional_param('mode', 'posts', PARAM_ALPHA);
  12      $page    = optional_param('page', 0, PARAM_INT);
  13      $perpage = optional_param('perpage', 5, PARAM_INT);
  14  
  15      if (empty($id)) {         // See your own profile by default
  16          require_login();
  17          $id = $USER->id;
  18      }
  19  
  20      if (! $user = get_record("user", "id", $id)) {
  21          error("User ID is incorrect");
  22      }
  23  
  24      if (! $course = get_record("course", "id", $course)) {
  25          error("Course id is incorrect.");
  26      }
  27  
  28      $syscontext = get_context_instance(CONTEXT_SYSTEM);
  29      $usercontext   = get_context_instance(CONTEXT_USER, $id);
  30  
  31      // do not force parents to enrol
  32      if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
  33          require_course_login($course);
  34      }
  35  
  36      if ($user->deleted) {
  37          print_header();
  38          print_heading(get_string('userdeleted'));
  39          print_footer($course);
  40          die;
  41      }
  42  
  43      add_to_log($course->id, "forum", "user report",
  44              "user.php?course=$course->id&amp;id=$user->id&amp;mode=$mode", "$user->id"); 
  45  
  46      $strforumposts   = get_string('forumposts', 'forum');
  47      $strparticipants = get_string('participants');
  48      $strmode         = get_string($mode, 'forum');
  49      $fullname        = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
  50  
  51      $navlinks = array();
  52      if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id)) || has_capability('moodle/site:viewparticipants', $syscontext)) {
  53          $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'core');
  54      }
  55      $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id", 'type' => 'title');
  56      $navlinks[] = array('name' => $strforumposts, 'link' => '', 'type' => 'title');
  57      $navlinks[] = array('name' => $strmode, 'link' => '', 'type' => 'title');
  58  
  59      $navigation = build_navigation($navlinks);
  60  
  61      print_header("$course->shortname: $fullname: $strmode", $course->fullname,$navigation);
  62  
  63  
  64      $currenttab = $mode;
  65      $showroles = 1;
  66      include($CFG->dirroot.'/user/tabs.php');   /// Prints out tabs as part of user page
  67  
  68  
  69      switch ($mode) {
  70          case 'posts' :
  71              $searchterms = array('userid:'.$user->id);
  72              $extrasql = '';
  73              break;
  74  
  75          default:
  76              $searchterms = array('userid:'.$user->id);
  77              $extrasql = 'AND p.parent = 0';
  78              break;
  79      }
  80  
  81      echo '<div class="user-content">';
  82  
  83      if ($course->id == SITEID) {
  84          if (empty($CFG->forceloginforprofiles) || isloggedin()) {
  85              // Search throughout the whole site.
  86              $searchcourse = 0;
  87          } else {
  88              $searchcourse = SITEID;
  89          }
  90      } else {
  91          // Search only for posts the user made in this course.
  92          $searchcourse = $course->id;
  93      }
  94  
  95      // Get the posts.
  96      if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
  97                                      $totalcount, $extrasql)) {
  98  
  99          print_paging_bar($totalcount, $page, $perpage,
 100                           "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
 101  
 102          $discussions = array();
 103          $forums      = array();
 104          $cms         = array();
 105  
 106          foreach ($posts as $post) {
 107  
 108              if (!isset($discussions[$post->discussion])) {
 109                  if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
 110                      error('Discussion ID was incorrect');
 111                  }
 112                  $discussions[$post->discussion] = $discussion;
 113              } else {
 114                  $discussion = $discussions[$post->discussion];
 115              }
 116  
 117              if (!isset($forums[$discussion->forum])) {
 118                  if (! $forum = get_record('forum', 'id', $discussion->forum)) {
 119                      error("Could not find forum $discussion->forum");
 120                  }
 121                  $forums[$discussion->forum] = $forum;
 122              } else {
 123                  $forum = $forums[$discussion->forum];
 124              }
 125  
 126              $ratings = null;
 127              if ($forum->assessed) {
 128                  if ($scale = make_grades_menu($forum->scale)) {
 129                      $ratings =new object();
 130                      $ratings->scale = $scale;
 131                      $ratings->assesstimestart = $forum->assesstimestart;
 132                      $ratings->assesstimefinish = $forum->assesstimefinish;
 133                      $ratings->allow = false;
 134                  }
 135              }
 136  
 137              if (!isset($cms[$forum->id])) {
 138                  if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
 139                      error('Course Module ID was incorrect');
 140                  }
 141                  $cms[$forum->id] = $cm;
 142                  unset($cm); // do not use cm directly, it would break caching
 143              }
 144  
 145              $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
 146              if ($forum->type != 'single') {
 147                  $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
 148                  if ($post->parent != 0) {
 149                      $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
 150                  }
 151              }
 152  
 153              if ($course->id == SITEID && has_capability('moodle/site:config', $syscontext)) {
 154                  $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
 155                  $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
 156              }
 157  
 158              $post->subject = $fullsubject;
 159  
 160              $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
 161                           get_string("postincontext", "forum")."</a>";
 162  
 163              forum_print_post($post, $discussion, $forum, $cms[$forum->id], $course, false, false, false, $ratings, $fulllink);
 164              echo "<br />";
 165          }
 166  
 167          print_paging_bar($totalcount, $page, $perpage,
 168                           "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
 169      } else {
 170          if ($mode == 'posts') {
 171              print_heading(get_string('noposts', 'forum'));
 172          } else {
 173              print_heading(get_string('nodiscussionsstartedby', 'forum'));
 174          }
 175      }
 176      echo '</div>';
 177      print_footer($course);
 178  
 179  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7