[LON-CAPA-cvs] cvs: loncom /interface lonmsg.pm /lonnet/perl lonnet.pm
www
lon-capa-cvs@mail.lon-capa.org
Fri, 29 Aug 2003 20:38:12 -0000
This is a MIME encoded message
--www1062189492
Content-Type: text/plain
www Fri Aug 29 16:38:12 2003 EDT
Modified files:
/loncom/interface lonmsg.pm
/loncom/lonnet/perl lonnet.pm
Log:
Bug #2031: Next and Previous buttons when viewing messages
Jon Kitzman
combined with functionality bug #788 (Kitzman) to keep sorting order
when doing "Next" and "Previous"
We never had a routine to get the keys of a namespace in lonnet.pm
--www1062189492
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20030829163812.txt"
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.64 loncom/interface/lonmsg.pm:1.65
--- loncom/interface/lonmsg.pm:1.64 Mon Aug 18 13:37:42 2003
+++ loncom/interface/lonmsg.pm Fri Aug 29 16:38:12 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.64 2003/08/18 17:37:42 www Exp $
+# $Id: lonmsg.pm,v 1.65 2003/08/29 20:38:12 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -116,6 +116,9 @@
use HTML::Entities();
use Mail::Send;
+# Querystring component with sorting type
+my $sqs;
+
# ===================================================================== Package
sub packagemsg {
@@ -613,6 +616,53 @@
ENDREPLY
}
+sub sortedmessages {
+ my @messages = &Apache::lonnet::getkeys('nohist_email');
+ #unpack the varibles and repack into temp for sorting
+ my @temp;
+ foreach (@messages) {
+ my $msgid=&Apache::lonnet::escape($_);
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
+ &Apache::lonmsg::unpackmsgid($msgid);
+ my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
+ $msgid);
+ 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;
+ }
+ return @temp;
+}
+
# ======================================================== Display all messages
sub disall {
@@ -671,47 +721,7 @@
$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($_);
- 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;
- }
+ my @temp=sortedmessages();
foreach (@temp){
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @$_;
if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
@@ -724,8 +734,8 @@
} else {
$r->print('<tr bgcolor="#99BBBB">');
}
- $r->print('<td><a href="/adm/email?display='.$origID.
- '">Open</a></td><td><a href="/adm/email?markdel='.$origID.
+ $r->print('<td><a href="/adm/email?display='.$origID.$sqs.
+ '">Open</a></td><td><a href="/adm/email?markdel='.$origID.$sqs.
'">Delete</a><input type=checkbox name="delmark_'.$origID.'"></td>'.
'<td>'.localtime($sendtime).'</td><td>'.
$fromname.'</td><td>'.$fromdomain.'</td><td>'.
@@ -736,6 +746,7 @@
$r->print('</table><p>'.
'<a href="javascript:checkall()">Check All</a> '.
'<a href="javascript:uncheckall()">Uncheck All</a><p>'.
+ '<input type="hidden" name="sortedby" value="'.$ENV{'form.sortedby'}.'" />'.
'<input type=submit name="markeddel" value="Delete Checked">'.
'</form></body></html>');
}
@@ -954,7 +965,7 @@
['display','replyto','forward','markread','markdel','markunread',
'sendreply','compose','sendmail','critical','recname','recdom',
'recordftf','sortedby']);
-
+ $sqs='&sortedby='.$ENV{'form.sortedby'};
# ------------------------------------------------------ They checked for email
&Apache::lonnet::put('email_status',{'recnewemail'=>0});
# --------------------------------------------------------------- Render Output
@@ -968,6 +979,20 @@
&statuschange($msgid,'read');
my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
my %content=&unpackagemsg($message{$msgid});
+# info to generate "next" and "previous" buttons
+ my @messages=&sortedmessages();
+ my $counter=0;
+ $r->print('<pre>');
+ my $escmsgid=&Apache::lonnet::escape($msgid);
+ foreach (@messages) {
+ if ($_->[5] eq $escmsgid){
+ last;
+ }
+ $counter++;
+ }
+ $r->print('</pre>');
+ my $number_of_messages = scalar(@messages); #subtract 1 for last index
+# start output
$r->print('<html><head><title>EMail and Messaging</title>');
if (defined($content{'baseurl'})) {
$r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$content{'baseurl'}\" />");
@@ -984,16 +1009,25 @@
$content{'senderdomain'}.') '.
'<br><b>Time:</b> '.$content{'time'}.'<p>'.
'<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
- '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
+ '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).$sqs.
'"><b>Reply</b></a></td>'.
- '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
+ '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).$sqs.
'"><b>Forward</b></a></td>'.
- '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
+ '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).$sqs.
'"><b>Mark Unread</b></a></td>'.
- '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).
+ '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).$sqs.
'"><b>Delete</b></a></td>'.
- '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
- '</tr></table><p><pre>'.
+ '<td><a href="/adm/email?sortedby='.$ENV{'form.sortedby'}.
+ '"><b>Display all Messages</b></a></td>');
+ if ($counter > 0){
+ $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
+ '"><b>Previous</b></a></td>');
+ }
+ if ($counter < $number_of_messages - 1){
+ $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
+ '"><b>Next</b></a></td>');
+ }
+ $r->print('</tr></table><p><pre>'.
&Apache::lontexconvert::msgtexconverted($content{'message'}).
'</pre><hr>'.$content{'citation'});
} elsif ($ENV{'form.replyto'}) {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.406 loncom/lonnet/perl/lonnet.pm:1.407
--- loncom/lonnet/perl/lonnet.pm:1.406 Tue Aug 26 00:56:30 2003
+++ loncom/lonnet/perl/lonnet.pm Fri Aug 29 16:38:12 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.406 2003/08/26 04:56:30 albertel Exp $
+# $Id: lonnet.pm,v 1.407 2003/08/29 20:38:12 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2134,6 +2134,21 @@
$returnhash{unescape($key)}=unescape($value);
}
return %returnhash;
+}
+
+# -------------------------------------------------------------- keys interface
+
+sub getkeys {
+ my ($namespace,$udomain,$uname)=@_;
+ if (!$udomain) { $udomain=$ENV{'user.domain'}; }
+ if (!$uname) { $uname=$ENV{'user.name'}; }
+ my $uhome=&homeserver($uname,$udomain);
+ my $rep=reply("keys:$udomain:$uname:$namespace",$uhome);
+ my @keyarray=();
+ foreach (split(/\&/,$rep)) {
+ push (@keyarray,&unescape($_));
+ }
+ return @keyarray;
}
# --------------------------------------------------------------- currentdump
--www1062189492--