--- loncom/interface/lonmsg.pm 2003/08/18 17:37:42 1.64 +++ loncom/interface/lonmsg.pm 2003/08/29 20:38:12 1.65 @@ -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 Apache::lontexconvert(); use HTML::Entities(); use Mail::Send; +# Querystring component with sorting type +my $sqs; + # ===================================================================== Package sub packagemsg { @@ -613,6 +616,53 @@ $dispcrit 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 @@ ENDDISHEADER $r->print('Status'); } $r->print(''); - 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 @@ ENDDISHEADER } else { $r->print(''); } - $r->print('OpenOpenDelete'. ''.localtime($sendtime).''. $fromname.''.$fromdomain.''. @@ -736,6 +746,7 @@ ENDDISHEADER $r->print('

'. 'Check All '. 'Uncheck All

'. + ''. ''. ''); } @@ -954,7 +965,7 @@ sub handler { ['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 @@ sub handler { &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('

');
+      my $escmsgid=&Apache::lonnet::escape($msgid);
+      foreach (@messages) {
+ 	  if ($_->[5] eq $escmsgid){
+ 	      last;
+ 	  }
+ 	  $counter++;
+      }
+      $r->print('
'); + my $number_of_messages = scalar(@messages); #subtract 1 for last index +# start output $r->print('EMail and Messaging'); if (defined($content{'baseurl'})) { $r->print(""); @@ -984,16 +1009,25 @@ $content{'sendername'},$content{'senderd $content{'senderdomain'}.') '. '
Time: '.$content{'time'}.'

'. ''. - ''. - ''. - ''. - ''. - ''. - '
Functions:ReplyForwardMark UnreadDeleteDisplay all Messages

'.
+		'Display all Messages');
+      if ($counter > 0){
+ 	  $r->print('Previous');
+       }
+       if ($counter < $number_of_messages - 1){
+ 	  $r->print('Next');
+       }
+       $r->print('

'.
              &Apache::lontexconvert::msgtexconverted($content{'message'}).
              '

'.$content{'citation'}); } elsif ($ENV{'form.replyto'}) {