MDL-43916 - Email addresses incorrectly displayed
authorMaria Torres <maria.torres@totaralms.com>
Mon, 3 Mar 2014 02:35:00 +0000 (10:35 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 3 Mar 2014 02:35:00 +0000 (10:35 +0800)
When capabilities and settings do not allow it.

mod/forum/renderer.php
mod/quiz/override_form.php

index 7fd14ec..9fedf17 100644 (file)
@@ -83,9 +83,14 @@ class mod_forum_renderer extends plugin_renderer_base {
      */
     public function subscriber_overview($users, $forum , $course) {
         $output = '';
+        $modinfo = get_fast_modinfo($course);
         if (!$users || !is_array($users) || count($users)===0) {
             $output .= $this->output->heading(get_string("nosubscribers", "forum"));
+        } else if (!isset($modinfo->instances['forum'][$forum->id])) {
+            $output .= $this->output->heading(get_string("invalidmodule", "error"));
         } else {
+            $cm = $modinfo->instances['forum'][$forum->id];
+            $canviewemail = in_array('email', get_extra_user_fields(context_module::instance($cm->id)));
             $output .= $this->output->heading(get_string("subscribersto","forum", "'".format_string($forum->name)."'"));
             $table = new html_table();
             $table->cellpadding = 5;
@@ -93,7 +98,11 @@ class mod_forum_renderer extends plugin_renderer_base {
             $table->tablealign = 'center';
             $table->data = array();
             foreach ($users as $user) {
-                $table->data[] = array($this->output->user_picture($user, array('courseid'=>$course->id)), fullname($user), $user->email);
+                $info = array($this->output->user_picture($user, array('courseid'=>$course->id)), fullname($user));
+                if ($canviewemail) {
+                    array_push($info, $user->email);
+                }
+                $table->data[] = $info;
             }
             $output .= html_writer::table($table);
         }
index 7b1172a..ca56cd6 100644 (file)
@@ -157,10 +157,15 @@ class quiz_override_form extends moodleform {
                 }
 
                 $userchoices = array();
+                $canviewemail = in_array('email', get_extra_user_fields($this->context));
                 foreach ($users as $id => $user) {
                     if (empty($invalidusers[$id]) || (!empty($override) &&
                             $id == $override->userid)) {
-                        $userchoices[$id] = fullname($user) . ', ' . $user->email;
+                        if ($canviewemail) {
+                            $userchoices[$id] = fullname($user) . ', ' . $user->email;
+                        } else {
+                            $userchoices[$id] = fullname($user);
+                        }
                     }
                 }
                 unset($users);