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

www lon-capa-cvs@mail.lon-capa.org
Fri, 15 Aug 2003 17:57:57 -0000


www		Fri Aug 15 13:57:57 2003 EDT

  Modified files:              
    /loncom/interface	lonmsg.pm 
  Log:
  Bug #788
  Sorting mail
  Jon Kitzman
  - now clickable table headers to sort in different ways.
  
  
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.61 loncom/interface/lonmsg.pm:1.62
--- loncom/interface/lonmsg.pm:1.61	Wed Aug 13 11:57:51 2003
+++ loncom/interface/lonmsg.pm	Fri Aug 15 13:57:57 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.61 2003/08/13 15:57:51 www Exp $
+# $Id: lonmsg.pm,v 1.62 2003/08/15 17:57:57 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -638,24 +638,91 @@
     }
 </script>
 ENDDISHEADER
-   $r->print(
- '<h1>Display All Messages</h1><form method=post name=disall '.
- 'action="/adm/email">'.
-     '<table border=2><tr><th colspan=2>&nbsp</th><th>Date</th>'.
-     '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');
-    foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'.
-					$ENV{'user.domain'}.':'.
-                                        $ENV{'user.name'}.':nohist_email',
-                                        $ENV{'user.home'}))) {
-        my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
+   $r->print('<h1>Display All Messages</h1><form method=post name=disall '.
+             'action="/adm/email">'.
+	     '<table border=2><tr><th colspan=2>&nbsp</th><th>');
+    if ($ENV{'form.sortedby'} eq "revdate") {
+	$r->print('<a href = "?sortedby=date">Date</a></th>');
+    } else {
+       $r->print('<a href = "?sortedby=revdate">Date</a></th>');
+    }
+    $r->print('<th>');
+    if ($ENV{'form.sortedby'} eq "revuser") {
+	$r->print('<a href = "?sortedby=user">Username</a>');
+    } else {
+	$r->print('<a href = "?sortedby=revuser">Username</a>');
+    }
+    $r->print('</th><th>');
+    if ($ENV{'form.sortedby'} eq "revdomain") {
+	$r->print('<a href = "?sortedby=domain">Domain</a>');
+    } else {
+	$r->print('<a href = "?sortedby=revdomain">Domain</a>');
+    }
+    $r->print('</th><th>');
+    if ($ENV{'form.sortedby'} eq "revsubject") {
+	$r->print('<a href = "?sortedby=subject">Subject</a>');
+    } else {
+    	$r->print('<a href = "?sortedby=revsubject">Subject</a>');
+    }
+    $r->print('</th><th>');
+    if ($ENV{'form.sortedby'} eq "revstatus") {
+	$r->print('<a href = "?sortedby=status">Status</th>');
+    } else {
+     	$r->print('<a href = "?sortedby=revstatus">Status</th>');
+    }
+    $r->print('</tr>');
+my @messages = split(/\&/,&Apache::lonnet::reply('keys:'.$ENV{'user.domain'}.':'.$ENV{'user.name'}.':nohist_email',$ENV{'user.home'}));
+#unpack the varibles and repack into temp for sorting
+my @temp;
+foreach (@messages)
+{
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
 	    &Apache::lonmsg::unpackmsgid($_);
-	if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
+my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status);
+ push @temp ,\@temp1;
+}
+#default sort
+ @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
+if ($ENV{'form.sortedby'} eq "date"){
+        @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
+}
+if ($ENV{'form.sortedby'} eq "revdate"){
+    	@temp = sort  {$b->[0] <=> $a->[0]} @temp; 
+}
+if ($ENV{'form.sortedby'} eq "user"){
+	@temp = sort  {lc($a->[2]) cmp lc($b->[2])} @temp;
+}
+if ($ENV{'form.sortedby'} eq "revuser"){
+	@temp = sort  {lc($b->[2]) cmp lc($a->[2])} @temp;
+}
+if ($ENV{'form.sortedby'} eq "domain"){
+        @temp = sort  {$a->[3] cmp $b->[3]} @temp;
+}
+if ($ENV{'form.sortedby'} eq "revdomain"){
+        @temp = sort  {$b->[3] cmp $a->[3]} @temp;
+}
+if ($ENV{'form.sortedby'} eq "subject"){
+        @temp = sort  {lc($a->[1]) cmp lc($b->[1])} @temp;
+}
+if ($ENV{'form.sortedby'} eq "revsubject"){
+        @temp = sort  {lc($b->[1]) cmp lc($a->[1])} @temp;
+}
+if ($ENV{'form.sortedby'} eq "status"){
+        @temp = sort  {$a->[4] cmp $b->[4]} @temp;
+}
+if ($ENV{'form.sortedby'} eq "revstatus"){
+        @temp = sort  {$b->[4] cmp $a->[4]} @temp;
+}
+	foreach (@temp){
+	    my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)= @$_;
+	 if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
 	    if ($status eq 'new') {
 		$r->print('<tr bgcolor="#FFBB77">');
 	    } elsif ($status eq 'read') {
 		$r->print('<tr bgcolor="#BBBB77">');
 	    } elsif ($status eq 'replied') {
-		$r->print('<tr bgcolor="#AAAA88">');
+		$r->print('<tr bgcolor="#AAAA88">'); 
+
 	    } else {
 		$r->print('<tr bgcolor="#99BBBB">');
 	    }
@@ -666,9 +733,9 @@
 		      $fromname.'</td><td>'.$fromdomain.'</td><td>'.
 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
                       $status.'</td></tr>');
-	}
-    }
-    $r->print('</table><p>'.
+	 }
+	}   
+ $r->print('</table><p>'.
               '<a href="javascript:checkall()">Check All</a>&nbsp;'.
               '<a href="javascript:uncheckall()">Uncheck All</a><p>'.
               '<input type=submit name="markeddel" value="Delete Checked">'.
@@ -888,7 +955,7 @@
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
         ['display','replyto','forward','markread','markdel','markunread',
          'sendreply','compose','sendmail','critical','recname','recdom',
-         'recordftf']);
+         'recordftf','sortedby']);
 
 # ------------------------------------------------------ They checked for email
   &Apache::lonnet::put('email_status',{'recnewemail'=>0});