--- loncom/interface/lonmsg.pm 2004/11/13 14:45:57 1.117
+++ loncom/interface/lonmsg.pm 2005/01/01 18:36:13 1.128
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.117 2004/11/13 14:45:57 www Exp $
+# $Id: lonmsg.pm,v 1.128 2005/01/01 18:36:13 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -527,17 +527,27 @@ sub folderlist {
'critical' => &mt('Critical'),
'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('Show').
+ ''.
'
'.
- ($folder!~/^(new|critical)/?
+ ''.
+ ($folder=~/^(new|critical)/?'':'');
+}
+
+sub scrollbuttons {
+ my ($start,$maxdis,$first,$finish,$total)=@_;
+ unless ($total>0) { return ''; }
+ $start++; $maxdis++;$first++;$finish++;
+ return
''.
''.
- ''.
+ ' of '.$maxdis.
''.
- '':'').
- '';
+ '
'.
+ &mt('Messages [_1] through [_2] of [_3]',$first,$finish,$total).'';
}
# =============================================================== Folder suffix
@@ -580,7 +590,6 @@ sub makefolder {
sub movemsg {
my ($msgid,$srcfolder,$trgfolder)=@_;
- my $unmsgid=&Apache::lonnet::unescape($msgid);
my $srcsuffix=&foldersuffix($srcfolder);
my $trgsuffix=&foldersuffix($trgfolder);
@@ -589,16 +598,13 @@ sub movemsg {
&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);
+ unless ($trgfolder eq 'trash') {
+ my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
+ &Apache::lonnet::put('email_status'.$trgsuffix,{$msgid => $status{$msgid}});
}
# Delete orginals
&Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
- &Apache::lonnet::del('email_status'.$srcsuffix,[$unmsgid]);
+ &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
}
# ======================================================= Display a course list
@@ -691,7 +697,6 @@ sub discrit {
foreach (sort keys %what) {
my %content=&unpackagemsg($what{$_});
next if ($content{'senderdomain'} eq '');
- $content{'message'}=~s/\n/\
/g;
$result.='
'.&mt('From').': '.
&Apache::loncommon::aboutmewrapper(
&Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
@@ -907,11 +912,20 @@ ENDDISHEADER
my $fsqs='&folder='.$folder;
my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
my $totalnumber=$#temp+1;
- my $number=int($totalnumber/$interdis)+1;
+ unless ($totalnumber>0) {
+ $r->print(''.&mt('Empty Folder').'
');
+ return;
+ }
+ unless ($interdis) {
+ $interdis=20;
+ }
+ my $number=int($totalnumber/$interdis);
+ if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
my $firstdis=$interdis*$startdis;
if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
my $lastdis=$firstdis+$interdis-1;
if ($lastdis>$#temp) { $lastdis=$#temp; }
+ $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber));
$r->print('');
+ my $postedstartdis=$startdis+1;
+ $r->print('');
if ($numblocked > 0) {
my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
@@ -998,6 +1013,7 @@ $r->print('';
@@ -1063,7 +1079,7 @@ sub compout {
}
}
if ($replying) {
- %message=&Apache::lonnet::get('nohist_email',[$replying]);
+ %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
%content=&unpackagemsg($message{$replying},$folder);
$dispcrit.='';
@@ -1077,7 +1093,10 @@ sub compout {
if ($content{'baseurl'}) {
$disbase='';
if ($ENV{'user.adv'}) {
- $disbase=''.&mt('Store message for re-use').'
';
+ $disbase.=''.&mt('Store message for re-use').
+ ' '.
+ &mt('Show re-usable messages').'
';
}
}
}
@@ -1719,9 +1738,8 @@ sub displaymessage {
'">'.&mt('Mark Unread').''.
'
Delete | '.
- ''.&mt('Display all Messages').' | ');
+ ''.&mt('Back to Folder Display').' | ');
if ($counter > 0){
$r->print(''.&mt('Previous').' | ');
@@ -1813,10 +1831,45 @@ sub printheader {
&header($r,$title,$baseurl);
}
+# ------------------------------------------------------------ Store the comment
+
+sub storecomment {
+ my ($r)=@_;
+ my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'});
+ my $cleanmsgtxt='';
+ foreach (split(/[\n\r]/,$msgtxt)) {
+ unless ($_=~/^\s*(\>|\>\;)/) {
+ $cleanmsgtxt.=$_."\n";
+ }
+ }
+ my $key=&Apache::lonnet::escape($ENV{'form.baseurl'}).'___'.time;
+ &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
+}
+
+sub storedcommentlisting {
+ my ($r)=@_;
+ my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
+ '^'.&Apache::lonnet::escape(&Apache::lonnet::escape($ENV{'form.showcommentbaseurl'})));
+ $r->print('');
+ if ((keys %msgs)[0]=~/^error\:/) {
+ $r->print(&mt('No stored comments yet.'));
+ } else {
+ my $found=0;
+ foreach (sort keys %msgs) {
+ $r->print("\n".$msgs{$_}."
");
+ $found=1;
+ }
+ unless ($found) {
+ $r->print(&mt('No stored comments yet for this resource.'));
+ }
+ }
+}
+
# ---------------------------------------------------------------- Send an email
sub sendoffmail {
- my ($r)=@_;
+ my ($r,$folder)=@_;
+ my $suffix=&foldersuffix($folder);
my $sendstatus='';
if ($ENV{'form.send'}) {
&printheader($r,'','Messages being sent.');
@@ -1825,17 +1878,17 @@ sub sendoffmail {
undef %content;
if ($ENV{'form.forwid'}) {
my $msgid=$ENV{'form.forwid'};
- my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
+ my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
%content=&unpackagemsg($message{$msgid},1);
- &statuschange($msgid,'forwarded');
+ &statuschange($msgid,'forwarded',$folder);
$ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
$content{'message'};
}
if ($ENV{'form.replyid'}) {
my $msgid=$ENV{'form.replyid'};
- my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
+ my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
%content=&unpackagemsg($message{$msgid},1);
- &statuschange($msgid,'replied');
+ &statuschange($msgid,'replied',$folder);
}
my %toaddr=();
undef %toaddr;
@@ -1865,7 +1918,13 @@ sub sendoffmail {
foreach (keys %toaddr) {
my ($recuname,$recdomain)=split(/\:/,$_);
- my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'});
+ my $msgtxt;
+ if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
+ (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
+ $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'},1);
+ } else {
+ $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'});
+ }
if ($toaddr{$_}) { $msgtxt.='
'.$toaddr{$_}; }
my $thismsg;
if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
@@ -1926,10 +1985,9 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['display','replyto','forward','markread','markdel','markunread',
'sendreply','compose','sendmail','critical','recname','recdom',
- 'recordftf','sortedby','block','folder','startdis','interdis']);
- $sqs='&sortedby='.$ENV{'form.sortedby'}.
- '&startdis='.$ENV{'form.startdis'}.
- '&interdis='.$ENV{'form.interdis'};
+ 'recordftf','sortedby','block','folder','startdis','interdis',
+ 'showcommentbaseurl']);
+ $sqs='&sortedby='.$ENV{'form.sortedby'};
# ------------------------------------------------------ They checked for email
unless ($ENV{'form.block'}) {
@@ -1950,15 +2008,19 @@ sub handler {
unless ($folder) {
$folder='';
} else {
- $sqs='&folder='.&Apache::lonnet::escape($folder);
+ $sqs.='&folder='.&Apache::lonnet::escape($folder);
}
# --------------------------------------------------------------------- Display
$startdis=$ENV{'form.startdis'};
+ $startdis--;
unless ($startdis) { $startdis=0; }
+
$interdis=$ENV{'form.interdis'};
unless ($interdis) { $interdis=20; }
+ $sqs.='&interdis='.$interdis;
+
if ($ENV{'form.firstview'}) {
$startdis=0;
}
@@ -1971,7 +2033,8 @@ sub handler {
if ($ENV{'form.nextview'}) {
$startdis++;
}
-
+ my $postedstartdis=$startdis+1;
+ $sqs.='&startdis='.$postedstartdis;
# --------------------------------------------------------------- Render Output
@@ -1998,10 +2061,11 @@ sub handler {
&printheader($r,'','Displaying Critical Messages');
&discrit($r);
} elsif ($ENV{'form.forward'}) {
- &compout($r,$ENV{'form.forward'});
+ &compout($r,$ENV{'form.forward'},undef,undef,undef,$folder);
} elsif ($ENV{'form.markdel'}) {
&printheader($r,'','Deleted Message');
&statuschange($ENV{'form.markdel'},'deleted',$folder);
+ &Apache::loncommunicate::menu($r);
&disall($r,$folder);
} elsif ($ENV{'form.markedmove'}) {
my $total=0;
@@ -2014,6 +2078,7 @@ sub handler {
}
&printheader($r,'','Moved Messages');
$r->print('Moved '.$total.' message(s)');
+ &Apache::loncommunicate::menu($r);
&disall($r,$folder);
} elsif ($ENV{'form.markeddel'}) {
my $total=0;
@@ -2025,10 +2090,12 @@ sub handler {
}
&printheader($r,'','Deleted Messages');
$r->print('Deleted '.$total.' message(s)
');
+ &Apache::loncommunicate::menu($r);
&disall($r,$folder);
} elsif ($ENV{'form.markunread'}) {
&printheader($r,'','Marked Message as Unread');
&statuschange($ENV{'form.markunread'},'new');
+ &Apache::loncommunicate::menu($r);
&disall($r,$folder);
} elsif ($ENV{'form.compose'}) {
&compout($r,'','',$ENV{'form.compose'});
@@ -2037,13 +2104,21 @@ sub handler {
} elsif ($ENV{'form.block'}) {
&examblock($r,$ENV{'form.block'});
} elsif ($ENV{'form.sendmail'}) {
- &sendoffmail($r);
+ &sendoffmail($r,$folder);
+ if ($ENV{'form.storebasecomment'}) {
+ &storecomment($r);
+ }
+ &disall($r,$folder);
} elsif ($ENV{'form.newfolder'}) {
&printheader($r,'','New Folder');
&makefolder($ENV{'form.newfolder'});
+ &Apache::loncommunicate::menu($r);
&disall($r,$ENV{'form.newfolder'});
+ } elsif ($ENV{'form.showcommentbaseurl'}) {
+ &storedcommentlisting($r);
} else {
&printheader($r,'','Display All Messages');
+ &Apache::loncommunicate::menu($r);
&disall($r,$folder);
}
$r->print('');