diff --git a/mod/dialogue/db/access.php b/mod/dialogue/db/access.php
old mode 100644
new mode 100755
index cf71158..2ecaaca
--- a/mod/dialogue/db/access.php
+++ b/mod/dialogue/db/access.php
@@ -38,6 +38,7 @@ $mod_dialogue_capabilities = array(
         'captype' => 'write',
         'contextlevel' => CONTEXT_MODULE,
         'legacy' => array(
+            'student' => CAP_ALLOW,
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
diff --git a/mod/dialogue/locallib.php b/mod/dialogue/locallib.php
index 3af2c59..ec3666b 100755
--- a/mod/dialogue/locallib.php
+++ b/mod/dialogue/locallib.php
@@ -5,6 +5,10 @@
 // SQL FUNCTIONS ///////////////////////////////////////////////////////////////////
 
 
+define ('DIALOGUETYPE_TEACHERSTUDENT', 0);
+define ('DIALOGUETYPE_STUDENTSTUDENT', 1);
+define ('DIALOGUETYPE_EVERYONE', 2);
+
 //////////////////////////////////////////////////////////////////////////////////////
 function dialogue_count_closed($dialogue, $user, $viewall=false) {
    
@@ -37,21 +41,21 @@ function dialogue_get_available_users($dialogue, $context, $editconversationid)
     
     
     switch ($dialogue->dialoguetype) {
-        case 0 : // teacher to student
+        case DIALOGUETYPE_TEACHERSTUDENT : // teacher to student
             if ($hascapmanage) {
                 return dialogue_get_available_students($dialogue, $context, $editconversationid);
             }
             else {
-                return dialogue_get_available_teachers($dialogue,  $editconversationid);
+                return dialogue_get_available_teachers($dialogue,  $context, $editconversationid);
             }
-        case 1: // student to student
-            if (!$hascapmanage && $hascapopen) {
+        case DIALOGUETYPE_STUDENTSTUDENT: // student to student
+            if (! $hascapmanage && $hascapopen) {
                 return dialogue_get_available_students($dialogue, $context, $editconversationid);
             }
             else {
                 return;
             }
-        case 2: // everyone
+        case DIALOGUETYPE_EVERYONE: // everyone
             if ($teachers = dialogue_get_available_teachers($dialogue, $context, $editconversationid)) {
                 foreach ($teachers as $userid=>$name) {
                     $names[$userid] = $name;
@@ -82,10 +86,17 @@ global $USER, $CFG;
         error("Course Module ID was incorrect");
     }
 
-    $groupid = groups_get_activity_group($cm, true);
+    // get the list of teachers (actually, those who have dialogue:manage capability)
+    $teachers = array();
+    if ($users = get_users_by_capability($context, 'mod/dialogue:manage', '', null, null, null, null, null, null,null,false)) {
+        foreach ($users as $user) {
+            $teachers[$user->id] = 1;
+        }
+    }
 
+    $groupid = groups_get_activity_group($cm, true);
     // add current group before list of students if it's the teacher
-    if (isteacher($course->id) and groups_get_activity_groupmode($cm)) {
+    if ($teachers[$USER->id] and groups_get_activity_groupmode($cm)) {
         // show teacher their current group
         if ($groupid) {
             if (!$group = get_record("groups", "id", $groupid)) {
@@ -97,6 +108,8 @@ global $USER, $CFG;
         }
         $gnames["spacer"] = "------------";
     }
+
+
     // get the students on this course (default sort order)...
     if ($users = get_users_by_capability($context, 'mod/dialogue:participate', null, null, null, null, null, null, null,null,false)) {
         if (!empty($CFG->enablegroupings) && !empty($cm->groupingid) && !empty($users)) {
@@ -110,18 +123,26 @@ global $USER, $CFG;
         foreach ($users as $otheruser) {
             // ...exclude self and...
             if ($USER->id != $otheruser->id) {
+
+                // ...if not a student (eg co-teacher, teacher) then exclude from students list
+                if ($teachers[$otheruser->id] == 1) {
+                    continue;
+                }
+
                 // ...if teacher and groups then exclude students not in the current group
-                if (isteacher($course->id) and groupmode($course, $cm) and $groupid) {
+                if ($teachers[$USER->id] and groupmode($course, $cm) and $groupid) {
                     if (!ismember($groupid, $otheruser->id)) {
                         continue;
                     }
                 }
+
                 // ...if student and groupmode is SEPARATEGROUPS then exclude students not in student's group
-                if (isstudent($course->id) and (groupmode($course, $cm) == SEPARATEGROUPS)) {
+                if (!$teachers[$USER->id] and (groupmode($course, $cm) == SEPARATEGROUPS)) {
                     if (!ismember($groupid, $otheruser->id)) {
                         continue;
                     }
                 }
+
                 // ... and any already in any open conversations unless multiple conversations allowed
                 if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", 
                         "dialogueid = $dialogue->id AND id != $editconversationid AND 
@@ -152,20 +173,32 @@ global $USER, $CFG;
 
 
 //////////////////////////////////////////////////////////////////////////////////////
-function dialogue_get_available_teachers($dialogue, $editconversationid = 0) {
-    global $USER;
-   
+function dialogue_get_available_teachers($dialogue, $context, $editconversationid = 0) {
+    global $USER, $CFG;
+    $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
     if (! $course = get_record("course", "id", $dialogue->course)) {
         error("Course is misconfigured");
         }
     if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
         error("Course Module ID was incorrect");
     }
-
-    $groupid = get_current_group($course->id);
-    // get the teachers on this course (default sort order)...
-    if ($users = get_course_teachers($course->id)) {
-        // $names[0] = "-----------------------";
+    // get the list of teachers (actually, those who have dialogue:manage capability)
+    $hiddenTeachers = array();
+    if ($users = get_users_by_capability($context, 'mod/dialogue:manage', '', null, null, null, null, null, null,true,null)) {
+        foreach ($users as $user) {
+            $userRoles = get_user_roles($context, $user->id, true);
+            foreach ($userRoles as $role) {
+                if ($role->hidden == 1) {
+                    $hiddenTeachers[$user->id] = 1;
+                    break;
+                }
+            }
+        }
+        $canSeeHidden = false;
+        if (has_capability('moodle/role:viewhiddenassigns', $context)) {
+            $canSeeHidden = true;
+        }
+        $groupid = get_current_group($course->id);
         foreach ($users as $otheruser) {
             // ...exclude self and ...
             if ($USER->id != $otheruser->id) {
@@ -175,6 +208,9 @@ function dialogue_get_available_teachers($dialogue, $editconversationid = 0) {
                         continue;
                     }
                 }
+                if (!$canSeeHidden && array_key_exists($otheruser->id, $hiddenTeachers) && ($hiddenTeachers[$otheruser->id] == 1)) {
+                    continue;
+                }
                 // ...any already in open conversations unless multiple conversations allowed 
                 if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", 
                         "dialogueid = $dialogue->id AND id != $editconversationid AND ((userid = $USER->id AND 
@@ -276,7 +312,7 @@ function dialogue_list_conversations_closed($dialogue) {
 function dialogue_print_conversation($dialogue, $conversation) {
 // print a conversation and allow a new entry
     global $USER, $CFG;
-    
+
     if (! $course = get_record("course", "id", $dialogue->course)) {
         error("Course is misconfigured");
     }
diff --git a/mod/dialogue/version.php b/mod/dialogue/version.php
index 47ebfb5..6b26243 100755
--- a/mod/dialogue/version.php
+++ b/mod/dialogue/version.php
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2008081101;
+$module->version  = 2009022401;
 $module->requires = 2007101509;  // Requires this Moodle version
 $module->cron     = 60;
 
diff --git a/mod/dialogue/view.php b/mod/dialogue/view.php
index 38fb732..861a714 100755
--- a/mod/dialogue/view.php
+++ b/mod/dialogue/view.php
@@ -29,6 +29,7 @@
     $hascapopen = has_capability('mod/dialogue:open', $context);
     $hascapparticipate = has_capability('mod/dialogue:participate', $context);
     $hascapviewall = has_capability('mod/dialogue:viewall', $context);
+    $hascapmanage = has_capability('mod/dialogue:manage', $context);
 
     add_to_log($course->id, "dialogue", "view", "view.php?id=$cm->id", $dialogue->id, $cm->id);
 
@@ -54,7 +55,7 @@
     // ...and if necessary set default action
 
     if ($hascapparticipate) { // it's a teacher or student
-        if (!$cm->visible and isstudent($course->id)) {
+        if (!$cm->visible and !$hascapmanage) {
             $params->action = 'notavailable';
         }
         if (empty($params->action)) {
@@ -100,7 +101,16 @@
 
         $tabs = array();
         if ($hascapopen) {
-            $tabs[0][] =  new tabobject (0, "view.php?id=$cm->id&amp;pane=0", $names[0]);
+            $URL = "view.php?id=$cm->id&amp;pane=0";
+            if ((groupmode($course, $cm) == SEPARATEGROUPS) || (groupmode($course, $cm) == VISIBLEGROUPS) ) {
+                // pass the user's groupid if in groups mode to view.php
+                // NOTE: this defaults to users first group, needs to be updated to handle grouping mode also
+                if ($usergroups = groups_get_all_groups($course->id, $USER->id, 0)) {
+                    $firstgroup = reset($usergroups);
+                    $URL .= "&amp;group=" . $firstgroup->id;
+                }
+            }
+            $tabs[0][] =  new tabobject (0, $URL, $names[0]);
         }
         $tabs[0][] =  new tabobject (1, "view.php?id=$cm->id&amp;pane=1", $names[1]);
         $tabs[0][] =  new tabobject (3, "view.php?id=$cm->id&amp;pane=3", $names[3]);
@@ -111,14 +121,13 @@
 
 
         switch ($params->pane) {
-            case 0:
+            case 0: // Open dialogue
             
                 if (!$hascapopen) {
                     print_heading(get_string("opendenied", "dialogue"));
                     print_continue("view.php?id=$cm->id");
                     break;
                 }
-            
                 if (has_capability('mod/dialogue:manage', $context)) {
                     /// Check to see if groups are being used in this dialogue
                     /// and if so, set $currentgroup to reflect the current group
@@ -127,7 +136,6 @@
                     $currentgroup = groups_get_activity_group($cm, true);
                     $groupmode = groups_get_activity_groupmode($cm);
                 }
-
                 if ($names = dialogue_get_available_users($dialogue, $context, 0)) {
                     
                     $mform = new mod_dialogue_open_form('dialogues.php', array('names' => $names));
@@ -140,12 +148,12 @@
                     print_continue("view.php?id=$cm->id");
                 }
                 break;
-            case 1:
+            case 1: // Current dialogues
             case 2:
                 // print active conversations requiring a reply from the other person.
                 dialogue_list_conversations($dialogue);
                 break;
-            case 3:
+            case 3: // Closed dialogues
                 dialogue_list_conversations_closed($dialogue, $USER);
         }
     }
