--- loncom/interface/lonmsg.pm 2004/09/10 06:38:24 1.106 +++ loncom/interface/lonmsg.pm 2004/09/20 15:01:56 1.108 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.106 2004/09/10 06:38:24 www Exp $ +# $Id: lonmsg.pm,v 1.108 2004/09/20 15:01:56 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -117,11 +117,14 @@ use Apache::loncommunicate; # Querystring component with sorting type my $sqs; +my $startdis; +my $interdis; # ===================================================================== Package sub packagemsg { - my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_; + my ($subject,$message,$citation,$baseurl,$attachmenturl, + $recuser,$recdomain)=@_; $message =&HTML::Entities::encode($message,'<>&"'); $citation=&HTML::Entities::encode($citation,'<>&"'); $subject =&HTML::Entities::encode($subject,'<>&"'); @@ -156,6 +159,8 @@ sub packagemsg { ''.$ENV{'request.role'}.''. ''.$ENV{'request.filename'}.''. ''.$msgid.''. + ''.$recuser.''. + ''.$recdomain.''. ''.$message.''; if (defined($citation)) { $result.=''.$citation.''; @@ -447,13 +452,21 @@ sub user_normal_msg_raw { my $homeserver=&Apache::lonnet::homeserver($user,$domain); if ($homeserver ne 'no_host') { ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl, - $attachmenturl); + $attachmenturl,$user,$domain); +# Store in user folder $status=&Apache::lonnet::critical( 'put:'.$domain.':'.$user.':nohist_email:'. &Apache::lonnet::escape($msgid).'='. &Apache::lonnet::escape($message),$homeserver); +# Save new message received time &Apache::lonnet::put ('email_status',{'recnewemail'=>time},$domain,$user); +# Into sent-mail folder + $status.=' '.&Apache::lonnet::critical( + 'put:'.$ENV{'user.domain'}.':'.$ENV{'user.name'}. + ':nohist_email_sent:'. + &Apache::lonnet::escape($msgid).'='. + &Apache::lonnet::escape($message),$ENV{'user.home'}); } else { $status='no_host'; } @@ -507,15 +520,25 @@ sub folderlist { my @allfolders=&Apache::lonnet::getkeys('email_folders'); if ($allfolders[0]=~/^error:/) { @allfolders=(); } return '
'. - ''. + &mt('Folder').': '. &Apache::loncommon::select_form($folder,'folder', ('' => &mt('INBOX'),'trash' => &mt('TRASH'), 'sent' => &mt('Sent Messages'), map { $_ => $_ } @allfolders)). - ''. + ' '.&mt('Show').' '. + &Apache::loncommon::select_form($interdis,'interdis', +(' 10' => '10', ' 20' => '20', ' 50' => '50', '100' => '100', '200' => '200')). + '
'. + ''. + ''. + ''. + ''. + ''. + '
'. &mt('View Critical Messages').''. - '
'; + ''; } + # =============================================================== Folder suffix sub foldersuffix { @@ -552,17 +575,25 @@ sub makefolder { sub movemsg { my ($msgid,$srcfolder,$trgfolder)=@_; + my $unmsgid=&Apache::lonnet::unescape($msgid); my $srcsuffix=&foldersuffix($srcfolder); my $trgsuffix=&foldersuffix($trgfolder); - my $srcstatus=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]); - my $trgstatus=$srcstatus; - if ($trgstatus eq 'deleted') { $trgstatus='read'; } - &Apache::lonnet::put( - 'nohist_email'.$trgsuffix,{$msgid => - &Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid])}); - &statuschange($msgid,$trgstatus,$trgfolder); + +# Copy message + my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]); + &Apache::lonnet::put('nohist_email'.$trgsuffix,{$msgid => $message{$msgid}}); + +# Copy status + my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$unmsgid]); + &Apache::lonnet::put('email_status'.$trgsuffix,{$unmsgid => $status{$unmsgid}}); +# See if was deleted -> becomes "read" in trash + my $currentstatus=(&unpackmsgid($status{$unmsgid}),$srcfolder); + if ($currentstatus eq 'deleted') { + &statuschange($msgid,'read',$trgfolder); + } +# Delete orginals &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]); - &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]); + &Apache::lonnet::del('email_status'.$srcsuffix,[$unmsgid]); } # ======================================================= Display a course list @@ -686,7 +717,7 @@ $content{'sendername'}.'@'. $r->print($header); } $r->print($result); - $r->print(''); + $r->print(''); } sub sortedmessages { @@ -698,7 +729,7 @@ sub sortedmessages { foreach (@messages) { my $msgid=&Apache::lonnet::escape($_); my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)= - &Apache::lonmsg::unpackmsgid($msgid); + &Apache::lonmsg::unpackmsgid($msgid,$folder); my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status, $msgid); # Check whether message was sent during blocking period. @@ -776,43 +807,50 @@ sub disall { } ENDDISHEADER + my $fsqs='&folder='.$folder; + my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); + my $totalnumber=$#temp+1; + my $number=int($totalnumber/$interdis)+1; + my $firstdis=$interdis*$startdis; + if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; } + my $lastdis=$firstdis+$interdis-1; + if ($lastdis>$#temp) { $lastdis=$#temp; } $r->print('

'.&mt('Display All Messages').'

'. &folderlist($folder). '
'. ''); + $r->print(''.&mt('Date').''); } else { - $r->print(''.&mt('Date').''); + $r->print(''.&mt('Date').''); } $r->print(''); + $r->print(''.&mt('Status').''); } else { - $r->print(''.&mt('Status').''); + $r->print(''.&mt('Status').''); } $r->print(''); - my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); - foreach (@temp){ - my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @$_; + for (my $n=$firstdis;$n<=$lastdis;$n++) { + my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @{$temp[$n]}; if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) { if ($status eq 'new') { $r->print(''); @@ -833,7 +871,7 @@ ENDDISHEADER $status.''); } elsif ($status eq 'deleted') { # purge - &movemsg($origID,$folder,'trash'); + &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash'); } } $r->print('
 '); if ($ENV{'form.sortedby'} eq "revdate") { - $r->print(''.&mt('Date').''); if ($ENV{'form.sortedby'} eq "revuser") { - $r->print(''.&mt('Username').''); + $r->print(''.&mt('Username').''); } else { - $r->print(''.&mt('Username').''); + $r->print(''.&mt('Username').''); } $r->print(''); if ($ENV{'form.sortedby'} eq "revdomain") { - $r->print(''.&mt('Domain').''); + $r->print(''.&mt('Domain').''); } else { - $r->print(''.&mt('Domain').''); + $r->print(''.&mt('Domain').''); } $r->print(''); if ($ENV{'form.sortedby'} eq "revsubject") { - $r->print(''.&mt('Subject').''); + $r->print(''.&mt('Subject').''); } else { - $r->print(''.&mt('Subject').''); + $r->print(''.&mt('Subject').''); } $r->print(''); if ($ENV{'form.sortedby'} eq "revstatus") { - $r->print(''.&mt('Status').'

'. @@ -864,7 +902,7 @@ $r->print('

'; $func=&mt('Forward'); @@ -927,10 +965,10 @@ sub compout { } if ($replying) { %message=&Apache::lonnet::get('nohist_email',[$replying]); - %content=&unpackagemsg($message{$replying}); + %content=&unpackagemsg($message{$replying},$folder); $dispcrit.=''; - $func=&mt('Replying to'); + $func=&mt('Send Reply to'); $dissub=&mt('Reply').': '.$content{'subject'}; $dismsg='> '.$content{'message'}; @@ -1538,16 +1576,17 @@ sub displaymessage { my $numblocked = 0; # info to generate "next" and "previous" buttons and check if message is blocked &blockcheck(\%setters,\$startblock,\$endblock); - my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked); + my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); if ( $blocked{$msgid} eq 'ON' ) { &printheader($r,'/adm/email',&mt('Display a Message')); $r->print(&mt('You attempted to display a message that is currently blocked because you are enrolled in one or more courses for which there is an ongoing online exam.')); &build_block_table($r,$startblock,$endblock,\%setters); return; } - &statuschange($msgid,'read'); + &statuschange($msgid,'read',$folder); my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]); my %content=&unpackagemsg($message{$msgid}); + my $counter=0; $r->print('

');
     my $escmsgid=&Apache::lonnet::escape($msgid);
@@ -1573,6 +1612,7 @@ sub displaymessage {
 	      'Delete'.
 	      ''.&mt('Display all Messages').'');
     if ($counter > 0){
 	$r->print('