[LON-CAPA-cvs] cvs: loncom /interface lonmsgdisplay.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 01 May 2006 05:57:27 -0000


This is a MIME encoded message

--raeburn1146463047
Content-Type: text/plain

raeburn		Mon May  1 01:57:27 2006 EDT

  Modified files:              
    /loncom/interface	lonmsgdisplay.pm 
  Log:
  Can select message recipients based on group affiliation.
  
  
--raeburn1146463047
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060501015727.txt"

Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.19 loncom/interface/lonmsgdisplay.pm:1.20
--- loncom/interface/lonmsgdisplay.pm:1.19	Wed Apr 26 10:43:03 2006
+++ loncom/interface/lonmsgdisplay.pm	Mon May  1 01:57:26 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging display
 #
-# $Id: lonmsgdisplay.pm,v 1.19 2006/04/26 14:43:03 albertel Exp $
+# $Id: lonmsgdisplay.pm,v 1.20 2006/05/01 05:57:26 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -261,10 +261,15 @@
 sub discourse {
     my $r=shift;
     my $classlist = &Apache::loncoursedata::get_classlist();
-    my $now=time;
+    my ($classgroups,$studentgroups) = 
+            &Apache::loncoursedata::get_group_memberships($classlist);
     my %lt=&Apache::lonlocal::texthash('cfa' => 'Check All',
             'cfs' => 'Check Section/Group',
             'cfn' => 'Uncheck All');
+    if (defined($env{'form.group'})) {
+        $r->print('<input type="hidden" name="group" value="'.
+                  $env{'form.group'}.'" />'."\n");
+    }
     $r->print(<<ENDDISHEADER);
 <input type="hidden" name="sendmode" value="group" />
 <script pe="text/javascript">
@@ -284,6 +289,12 @@
            ('send_to_&&&'+document.forms.compemail.chksec.value+'&&&')==0) {
 	      document.forms.compemail.elements[i].checked=true;
             }
+            if
+          (document.forms.compemail.elements[i].name.indexOf
+           ('group_&&&'+document.forms.compemail.chksec.value+'&&&_')==0) {
+              var count = i - document.forms.compemail.elements[i].value;
+              document.forms.compemail.elements[count].checked=true;
+            }
         }
     }
 
@@ -298,50 +309,86 @@
 </script>
 <input type="button" onClick="checkall()" value="$lt{'cfa'}" />&nbsp;
 <input type="button" onClick="checksec()" value="$lt{'cfs'}" />
-<input type="text" size="5" name="chksec" />&nbsp;
+<input type="text" size="15" name="chksec" value="$env{'form.group'}" />&nbsp;
 <input type="button" onClick="uncheckall()" value="$lt{'cfn'}" />
 <p>
 ENDDISHEADER
     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
-    $r->print('<table>');
-    foreach my $role (sort keys %coursepersonnel) {
-        foreach (split(/\,/,$coursepersonnel{$role})) {
-            my ($puname,$pudom)=split(/\:/,$_);
-            $r->print('<tr><td><label>'.
-                      '<input type="checkbox" name="send_to_&&&&&&_'.
-                      $puname.':'.$pudom.'" /> '.
-                      &Apache::loncommon::plainname($puname,$pudom).
-                      '</label></td>'.
-                      '<td>('.$_.'),</td><td><i>'.$role.'</i></td></tr>');
-        }
-    }
-    $r->print('</table><table>');
-    my $sort = sub {
-	my $aname=lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]);
-	if (!$aname) { $aname=$a; }
-	my $bname=lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]);
-	if (!$bname) { $bname=$b; }
-	return $aname cmp $bname;
-    };
-    foreach my $student (sort $sort (keys(%{$classlist}))) {
-	my $info=$classlist->{$student};
-        my ($sname,$sdom,$status,$fullname,$section) =
-            (@{$info}[&Apache::loncoursedata::CL_SNAME(),
-                      &Apache::loncoursedata::CL_SDOM(),
-                      &Apache::loncoursedata::CL_STATUS(),
-                      &Apache::loncoursedata::CL_FULLNAME(),
-                      &Apache::loncoursedata::CL_SECTION()]);
-        next if ($status ne 'Active');
-	next if ($env{'request.course.sec'} &&
-		 $section ne $env{'request.course.sec'});
-        my $key = 'send_to_&&&'.$section.'&&&_'.$student;
-        if (! defined($fullname) || $fullname eq '') { $fullname = $sname; }
-        $r->print('<tr><td><label>'.
-                  qq{<input type="checkbox" name="$key" />}.('&nbsp;'x2).
-                  $fullname.'</label></td><td>'.$sname.':'.$sdom.'</td><td>'.$section.
-                  '</td></tr>');
+    $r->print(&Apache::loncommon::start_data_table());
+    if (keys(%coursepersonnel) > 0) {
+        $r->print('<h3>Non-students</h3>');
+        $r->print(&Apache::loncommon::start_data_table());
+        $r->print(&Apache::loncommon::start_data_table_row());
+        $r->print('<th>Name</th><th>Username:Domain</th><th>Role</th>');
+        $r->print(&Apache::loncommon::end_data_table_row());
+        foreach my $role (sort keys %coursepersonnel) {
+            foreach (split(/\,/,$coursepersonnel{$role})) {
+                my ($puname,$pudom)=split(/\:/,$_);
+                $r->print(&Apache::loncommon::start_data_table_row());
+                $r->print('<td><label>'.
+                          '<input type="checkbox" name="send_to_&&&&&&_'.
+                          $puname.':'.$pudom.'" /> '.
+                          &Apache::loncommon::plainname($puname,$pudom).
+                          '</label></td>'.
+                          '<td>('.$_.'),</td><td><i>'.$role.'</i></td>');
+                $r->print(&Apache::loncommon::end_data_table_row());
+            }
+        }
+        $r->print(&Apache::loncommon::end_data_table());
+    }
+    if (keys(%{$classlist}) > 0) {
+        $r->print('<h3>Students</h3>');
+        $r->print(&Apache::loncommon::start_data_table());
+        $r->print(&Apache::loncommon::start_data_table_row());
+        $r->print('<th>Name</th><th>Username:Domain</th><th>Section</th><th>Groups</th>');
+        $r->print(&Apache::loncommon::end_data_table_row());
+        my $sort = sub {
+	    my $aname=lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]);
+	    if (!$aname) { $aname=$a; }
+	    my $bname=lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]);
+	    if (!$bname) { $bname=$b; }
+	    return $aname cmp $bname;
+        };
+        foreach my $student (sort $sort (keys(%{$classlist}))) {
+	    my $info=$classlist->{$student};
+            my ($sname,$sdom,$status,$fullname,$section) =
+                (@{$info}[&Apache::loncoursedata::CL_SNAME(),
+                          &Apache::loncoursedata::CL_SDOM(),
+                          &Apache::loncoursedata::CL_STATUS(),
+                          &Apache::loncoursedata::CL_FULLNAME(),
+                          &Apache::loncoursedata::CL_SECTION()]);
+            next if ($status ne 'Active');
+	    next if ($env{'request.course.sec'} &&
+		     $section ne $env{'request.course.sec'});
+            my @studentsgroups = &Apache::loncoursedata::get_students_groups(
+                                               $student,$status,$classgroups);
+            my $grouplist = join(', ',@studentsgroups);
+            my $key = 'send_to_&&&'.$section.'&&&_'.$student;
+            if (! defined($fullname) || $fullname eq '') {$fullname = $sname;}
+            my $checked = '';
+            my $groupcount = 0;
+            my $groupitems;
+            $r->print(&Apache::loncommon::start_data_table_row());
+            $r->print('<td><label>');
+            foreach my $group (@studentsgroups) {
+                $groupcount ++;
+                $groupitems .= ('<input type="hidden" name="group_&&&'.
+                                $group.'&&&_'.$student.'" value="'.
+                                $groupcount.'" />');
+                if (defined($env{'form.group'})) {
+                    if ($env{'form.group'} eq $group) {
+                        $checked = 'checked=checked';
+                    }
+                }
+            }
+            $r->print(qq{<input type="checkbox" name="$key" $checked />}.
+                      ('&nbsp;'x2).$fullname.'</label>'.$groupitems.
+                      '</td><td>'.$sname.':'.$sdom.'</td><td>'.$section.
+                      '</td><td>'.$grouplist.'</td>');
+            $r->print(&Apache::loncommon::end_data_table_row());
+        }
+        $r->print(&Apache::loncommon::end_data_table());
     }
-    $r->print('</table>');
 }
 
 # ==================================================== Display Critical Message
@@ -1858,7 +1905,7 @@
         ['display','replyto','forward','markread','markdel','markunread',
          'sendreply','compose','sendmail','critical','recname','recdom',
          'recordftf','sortedby','block','folder','startdis','interdis',
-	 'showcommentbaseurl','dismode']);
+	 'showcommentbaseurl','dismode','group']);
     $sqs='&sortedby='.$env{'form.sortedby'};
 
 # ------------------------------------------------------ They checked for email

--raeburn1146463047--