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

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 07 May 2002 19:24:28 -0000


matthew		Tue May  7 15:24:28 2002 EDT

  Modified files:              
    /loncom/interface	loncommunicate.pm 
  Log:
  Reworked logic to determine if the user has unread messages instead of just
  assuming they do.  Reworked page to use a few fewer <table>'s as well.
  
  
Index: loncom/interface/loncommunicate.pm
diff -u loncom/interface/loncommunicate.pm:1.8 loncom/interface/loncommunicate.pm:1.9
--- loncom/interface/loncommunicate.pm:1.8	Mon Feb  4 19:01:32 2002
+++ loncom/interface/loncommunicate.pm	Tue May  7 15:24:28 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Communicate
 #
-# $Id: loncommunicate.pm,v 1.8 2002/02/05 00:01:32 harris41 Exp $
+# $Id: loncommunicate.pm,v 1.9 2002/05/07 19:24:28 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -50,7 +50,7 @@
 #
 # Start document
 #
-    $r->print(<<ENDDOCUMENT);
+    $r->print(<<END);
 <html>
 <head>
 <title>The LearningOnline Network with CAPA</title>
@@ -58,42 +58,70 @@
 <body bgcolor="#FFFFFF">
 <img align=right src=/adm/lonIcons/lonlogos.gif>
 <h1>Communicate</h1>
-ENDDOCUMENT
-    my $st='<table><tr><td bgcolor="#FFFFAA"><b>';
-    my $en='</b></td><tr></table>';
-   $r->print('<p>'.
- $st.'<a href="/adm/email/">All Messages</a>'.$en.'<p>'.
- $st.'<a href="/adm/email?critical=display">Critical Messages</a>'.$en.'<p>'.
- $st.'<a href="/adm/email?compose=individual">Send message to user(s)</a>'.$en
-     );
+END
+   $r->print(<<END);
+<table cellspacing="10" cellpadding="2">
+<tr><td bgcolor="#FFFFAA">
+  <b><a href="/adm/email/">View All Messages</a></b>
+</td></tr>
+<tr><td bgcolor="#FFFFAA">
+  <b><a href="/adm/email?critical=display">View Critical Messages</a></b>
+</td></tr>
+<tr><td bgcolor="#FFFFAA">
+  <b><a href="/adm/email?compose=individual">Send message to user(s)</a></b>
+</td></tr>
+END
     if (($ENV{'request.course.id'}) && 
         (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
-       $r->print(
-    '<p>'.$st.
-  '<a href="/adm/email?compose=group">Broadcast message to course</a>'.$en.
-    '<p>'.$st.
-  '<a href="/adm/email?compose=upload">Upload messages to course</a>'.$en);
+        $r->print(<<END);
+<tr><td bgcolor="#FFFFAA">
+  <b><a href="/adm/email?compose=group">Broadcast message to course</a></b>
+</td></tr>
+<tr><td bgcolor="#FFFFAA">
+  <b><a href="/adm/email?compose=upload">Upload messages to course</a></b>
+</td></tr>
+END
     }
-    $r->print(<<ENDTABLE);
+    $r->print('</table>');
+    my @msgids = sort split(/\&/,&Apache::lonnet::reply
+                            ('keys:'.$ENV{'user.domain'}.':'.
+                             $ENV{'user.name'}.':nohist_email',
+                             $ENV{'user.home'}));
+    my @newmsgs;
+    foreach (@msgids) {
+        my ($sendtime,$shortsubj,$fromname,$fromdom,$status)=
+	    &Apache::lonmsg::unpackmsgid($_);
+        $sendtime = localtime($sendtime);
+        if ($status eq 'new') {
+            push @newmsgs, { 
+                msgid    => $_,
+                sendtime => $sendtime,
+                shortsub => &Apache::lonnet::unescape($shortsubj),
+                from     => $fromname,
+                fromdom  => $fromdom 
+                }
+        }
+    }
+    if ($#newmsgs >= 0) {
+        $r->print(<<TABLEHEAD);
 <h3>New Messages</h3>
 <table border=2><tr><th>&nbsp</th>
 <th>Date</th><th>Username</th><th>Domain</th><th>Subject</th></tr>
-ENDTABLE
-    foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'.
-					$ENV{'user.domain'}.':'.
-                                        $ENV{'user.name'}.':nohist_email',
-					$ENV{'user.home'}))) {
-        my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
-	    &Apache::lonmsg::unpackmsgid($_);
-        if ($status eq 'new') {
-            $r->print(
-              '<tr bgcolor="#FFBB77"><td><a href="/adm/email?display='.$_.
-                  '">Open</a></td><td>'.localtime($sendtime).'</td><td>'.
-                  $fromname.'</td><td>'.$fromdomain.'</td><td>'.
-		      &Apache::lonnet::unescape($shortsubj).'</td></tr>');
+TABLEHEAD
+        foreach my $msg (@newmsgs) {
+            $r->print(<<"ENDLINK");
+<tr bgcolor="#FFBB77">
+<td><a href="/adm/email?display=$msg->{'msgid'}">Open</a></td>
+ENDLINK
+            foreach ('sendtime','from','fromdom','shortsub') {
+                $r->print("<td>$msg->{$_}</td>");
+            }
+            $r->print("</td></tr>");
         }
+        $r->print('</table></body></html>');
+    } else {
+        $r->print("<h3>You have no unread messages</h3>");
     }
-    $r->print('</table></body></html>');
     return OK;
 }