--- loncom/interface/lonmsg.pm 2004/09/10 06:38:24 1.106
+++ loncom/interface/lonmsg.pm 2006/03/21 20:54:35 1.179
@@ -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.179 2006/03/21 20:54:35 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -90,13 +90,24 @@ also has a student role in the course, A
Users can ask LON-CAPA to forward messages to conventional e-mail
addresses on their B
ENDDISHEADER
- my %coursepersonnel=
- &Apache::lonnet::get_course_adv_roles();
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
+ $r->print(' 'Username',
'do' => 'Domain',
@@ -903,20 +1248,26 @@ sub compout {
'ca' => 'Cancel',
'ma' => 'Mail');
- if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
+ if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
+ || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'})) {
my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
$dispcrit=
- ' '.&mt('Send as critical message').' ' . $crithelp .
- ' ';
+ ' ' . $crithelp .
+ ' '.
+ '' . $crithelp .
+ '
'.
+ ''.
+ ($folder=~/^(new|critical)/?'':'');
+}
+
+sub scrollbuttons {
+ my ($start,$maxdis,$first,$finish,$total)=@_;
+ unless ($total>0) { return ''; }
+ $start++; $maxdis++;$first++;$finish++;
+ return
+ &mt('Page').': '.
+ ''.
+ ''.
+ ' of '.$maxdis.
+ ''.
+ '
'.
+ &mt('Showing messages [_1] through [_2] of [_3]',$first,$finish,$total).'';
}
+
# =============================================================== Folder suffix
sub foldersuffix {
@@ -539,12 +711,19 @@ sub statuschange {
if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
}
+ if ($newstatus eq 'deleted') {
+ &movemsg(&Apache::lonnet::unescape($msgid),$folder,'trash');
+ }
}
# ============================================================= Make new folder
sub makefolder {
my ($newfolder)=@_;
+ if (($newfolder eq 'sent')
+ || ($newfolder eq 'critical')
+ || ($newfolder eq 'trash')
+ || ($newfolder eq 'new')) { return; }
&Apache::lonnet::put('email_folders',{$newfolder => time});
}
@@ -552,15 +731,20 @@ sub makefolder {
sub movemsg {
my ($msgid,$srcfolder,$trgfolder)=@_;
+ if ($srcfolder eq 'new') { $srcfolder=''; }
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
+ 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,[$msgid]);
}
@@ -569,14 +753,11 @@ sub movemsg {
sub discourse {
my $r=shift;
- my %courselist=&Apache::lonnet::dump(
- 'classlist',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ my $classlist = &Apache::loncoursedata::get_classlist();
my $now=time;
- my %lt=&Apache::lonlocal::texthash('cfa' => 'Check for All',
- 'cfs' => 'Check for Section/Group',
- 'cfn' => 'Check for None');
+ my %lt=&Apache::lonlocal::texthash('cfa' => 'Check All',
+ 'cfs' => 'Check Section/Group',
+ 'cfn' => 'Uncheck All');
$r->print(<');
foreach my $role (sort keys %coursepersonnel) {
- foreach (split(/\,/,$coursepersonnel{$role})) {
- my ($puname,$pudom)=split(/\:/,$_);
- $r->print(
- '
'.
- &Apache::loncommon::plainname($puname,
- $pudom).' ('.$_.'), '.$role.'');
- }
+ foreach (split(/\,/,$coursepersonnel{$role})) {
+ my ($puname,$pudom)=split(/\:/,$_);
+ $r->print(' ');
+ }
}
-
- foreach (sort keys %courselist) {
- my ($end,$start)=split(/\:/,$courselist{$_});
- my $active=1;
- if (($end) && ($now>$end)) { $active=0; }
- if ($active) {
- my ($sname,$sdom)=split(/\:/,$_);
- my %reply=&Apache::lonnet::get('environment',
- ['firstname','middlename','lastname','generation'],
- $sdom,$sname);
- my $section=&Apache::lonnet::usection
- ($sdom,$sname,$ENV{'request.course.id'});
- $r->print(
- ''.
+ ' ('.$_.'), '.$role.'
'.
- $reply{'firstname'}.' '.
- $reply{'middlename'}.' '.
- $reply{'lastname'}.' '.
- $reply{'generation'}.
- ' ('.$_.') '.$section);
- }
+ $r->print('');
+ my $sort = sub {
+ my $aname=lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]);
+ if (!$aname) { $aname=$a; }
+ my $bname=lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]);
+ if (!$bname) { $bname=$b; }
+ return $aname cmp $bname;
+ };
+ foreach my $student (sort $sort (keys(%{$classlist}))) {
+ my $info=$classlist->{$student};
+ my ($sname,$sdom,$status,$fullname,$section) =
+ (@{$info}[&Apache::loncoursedata::CL_SNAME(),
+ &Apache::loncoursedata::CL_SDOM(),
+ &Apache::loncoursedata::CL_STATUS(),
+ &Apache::loncoursedata::CL_FULLNAME(),
+ &Apache::loncoursedata::CL_SECTION()]);
+ next if ($status ne 'Active');
+ next if ($env{'request.course.sec'} &&
+ $section ne $env{'request.course.sec'});
+ my $key = 'send_to_&&&'.$section.'&&&_'.$student;
+ if (! defined($fullname) || $fullname eq '') { $fullname = $sname; }
+ $r->print('
');
}
# ==================================================== Display Critical Message
@@ -654,28 +842,27 @@ ENDDISHEADER
sub discrit {
my $r=shift;
my $header = ' ');
}
+ $r->print(''.$sname.'@'.$sdom.' '.$section.
+ ' '.&mt('Critical Messages').'
'.
- '');
+ $r->print('');
}
sub sortedmessages {
@@ -695,12 +882,17 @@ sub sortedmessages {
my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
#unpack the varibles and repack into temp for sorting
my @temp;
+ my %descriptions;
+ my %status_cache =
+ &Apache::lonnet::get('email_status'.&foldersuffix($folder),\@messages);
foreach (@messages) {
my $msgid=&Apache::lonnet::escape($_);
- my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
- &Apache::lonmsg::unpackmsgid($msgid);
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
+ &Apache::lonmsg::unpackmsgid($msgid,$folder,undef,
+ \%status_cache);
+ my $description = &get_course_desc($fromcid,\%descriptions);
my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
- $msgid);
+ $msgid,$description);
# Check whether message was sent during blocking period.
if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
my $escid = &Apache::lonnet::unescape($msgid);
@@ -712,43 +904,173 @@ sub sortedmessages {
}
#default sort
@temp = sort {$a->[0] <=> $b->[0]} @temp;
- if ($ENV{'form.sortedby'} eq "date"){
+ if ($env{'form.sortedby'} eq "date"){
@temp = sort {$a->[0] <=> $b->[0]} @temp;
}
- if ($ENV{'form.sortedby'} eq "revdate"){
+ if ($env{'form.sortedby'} eq "revdate"){
@temp = sort {$b->[0] <=> $a->[0]} @temp;
}
- if ($ENV{'form.sortedby'} eq "user"){
+ if ($env{'form.sortedby'} eq "user"){
@temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
}
- if ($ENV{'form.sortedby'} eq "revuser"){
+ if ($env{'form.sortedby'} eq "revuser"){
@temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
}
- if ($ENV{'form.sortedby'} eq "domain"){
+ if ($env{'form.sortedby'} eq "domain"){
@temp = sort {$a->[3] cmp $b->[3]} @temp;
}
- if ($ENV{'form.sortedby'} eq "revdomain"){
+ if ($env{'form.sortedby'} eq "revdomain"){
@temp = sort {$b->[3] cmp $a->[3]} @temp;
}
- if ($ENV{'form.sortedby'} eq "subject"){
+ if ($env{'form.sortedby'} eq "subject"){
@temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
}
- if ($ENV{'form.sortedby'} eq "revsubject"){
+ if ($env{'form.sortedby'} eq "revsubject"){
@temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
}
- if ($ENV{'form.sortedby'} eq "status"){
+ if ($env{'form.sortedby'} eq "course"){
+ @temp = sort {lc($a->[6]) cmp lc($b->[6])} @temp;
+ }
+ if ($env{'form.sortedby'} eq "revcourse"){
+ @temp = sort {lc($b->[6]) cmp lc($a->[6])} @temp;
+ }
+ if ($env{'form.sortedby'} eq "status"){
@temp = sort {$a->[4] cmp $b->[4]} @temp;
}
- if ($ENV{'form.sortedby'} eq "revstatus"){
+ if ($env{'form.sortedby'} eq "revstatus"){
@temp = sort {$b->[4] cmp $a->[4]} @temp;
}
return @temp;
}
+sub get_course_desc {
+ my ($fromcid,$descriptions) = @_;
+ my $description;
+ if (!$fromcid) {
+ return $description;
+ } else {
+ if (defined($$descriptions{$fromcid})) {
+ $description = $$descriptions{$fromcid};
+ } else {
+ if (defined($env{'course.'.$fromcid.'.description'})) {
+ $description = $env{'course.'.$fromcid.'.description'};
+ } else {
+ my %courseinfo=&Apache::lonnet::coursedescription($fromcid); $description = $courseinfo{'description'};
+ $description = $courseinfo{'description'};
+ }
+ $$descriptions{$fromcid} = $description;
+ }
+ return $description;
+ }
+}
+
+# ======================================================== Display new messages
+
+
+sub disnew {
+ my $r=shift;
+ my %lt=&Apache::lonlocal::texthash(
+ 'nm' => 'New Messages',
+ 'su' => 'Subject',
+ 'co' => 'Course',
+ 'da' => 'Date',
+ 'us' => 'Username',
+ 'op' => 'Open',
+ 'do' => 'Domain'
+ );
+ my @msgids = sort(&Apache::lonnet::getkeys('nohist_email'));
+ my @newmsgs;
+ my %setters = ();
+ my $startblock = 0;
+ my $endblock = 0;
+ my %blocked = ();
+ my $numblocked = 0;
+ # Check for blocking of display because of scheduled online exams.
+ &blockcheck(\%setters,\$startblock,\$endblock);
+ my %status_cache =
+ &Apache::lonnet::get('email_status',\@msgids);
+ my %descriptions;
+ foreach (@msgids) {
+ my $msgid=&Apache::lonnet::escape($_);
+ my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
+ &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache);
+ if (defined($sendtime) && $sendtime!~/error/) {
+ my $description = &get_course_desc($fromcid,\%descriptions);
+ my $numsendtime = $sendtime;
+ $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
+ if ($status eq 'new') {
+ if ($numsendtime >= $startblock && ($numsendtime <= $endblock && $endblock > 0) ) {
+ $blocked{$_} = 'ON';
+ $numblocked ++;
+ } else {
+ push @newmsgs, {
+ msgid => $msgid,
+ sendtime => $sendtime,
+ shortsub => &Apache::lonnet::unescape($shortsubj),
+ from => $fromname,
+ fromdom => $fromdom,
+ course => $description
+ }
+ }
+ }
+ }
+ }
+ if ($#newmsgs >= 0) {
+ $r->print(<
');
+ } elsif ($numblocked == 0) {
+ $r->print("
+TABLEHEAD
+ foreach my $msg (@newmsgs) {
+ $r->print(<<"ENDLINK");
+ 
+$lt{'da'} $lt{'us'} $lt{'do'} $lt{'su'} $lt{'co'}
+ ");
+ }
+ $r->print('$lt{'op'}
+ENDLINK
+ foreach ('sendtime','from','fromdom','shortsub','course') {
+ $r->print("$msg->{$_} ");
+ }
+ $r->print("".&mt('You have no unread messages')."
");
+ }
+ if ($numblocked > 0) {
+ my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
+ my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
+ if ($numblocked == 1) {
+ $r->print("".&mt('You have').' '.$numblocked.' '.&mt('blocked unread message').".
");
+ $r->print(&mt('This message is not viewable because').' ');
+ } else {
+ $r->print("".&mt('You have').' '.$numblocked.' '.&mt('blocked unread messages').".
");
+ $r->print(&mt('These').' '.$numblocked.' '.&mt('messages are not viewable because '));
+ }
+ $r->print(
+&mt('display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams').'.');
+ &build_block_table($r,$startblock,$endblock,\%setters);
+ }
+}
+
+
# ======================================================== Display all messages
sub disall {
my ($r,$folder)=@_;
+ $r->print(&folderlist($folder));
+ if ($folder eq 'new') {
+ &disnew($r);
+ } elsif ($folder eq 'critical') {
+ &discrit($r);
+ } else {
+ &disfolder($r,$folder);
+ }
+}
+
+# ============================================================ Display a folder
+
+sub disfolder {
+ my ($r,$folder)=@_;
my %blocked = ();
my %setters = ();
my $startblock;
@@ -776,82 +1098,103 @@ sub disall {
}
ENDDISHEADER
- $r->print(''.&mt('Display All Messages').'
'.
- &folderlist($folder).
- '');
+ my $postedstartdis=$startdis+1;
+ $r->print('');
if ($numblocked > 0) {
my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
@@ -864,7 +1207,8 @@ $r->print('
'.
- ' '.&mt('Send as critical message').' ' .
- &mt('and return receipt') . $crithelp . '
';
+ }
+ }
}
- if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; }
+ my $citation=&displayresource(%content);
+ if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
$r->print(
'
General message text
-
The file format for the uploaded portion of the message is:
@@ -1009,31 +1377,35 @@ $dispcrit
ENDUPLOAD
}
if ($broadcast eq 'group') {
- &discourse;
+ &discourse($r);
}
- $r->print('');
+ $r->print(''.
+ &Apache::lonfeedback::generate_preview_button('compemail','message').
+ &Apache::lonhtmlcommon::htmlareaselectactive('message'));
}
# ---------------------------------------------------- Display all face to face
sub retrieve_instructor_comments {
my ($user,$domain)=@_;
- my $target=$ENV{'form.grade_target'};
- if (! $ENV{'request.course.id'}) { return; }
- if (! &Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
+ my $target=$env{'form.grade_target'};
+ if (! $env{'request.course.id'}) { return; }
+ if (! &Apache::lonnet::allowed('srm',$env{'request.course.id'})
+ && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'})) {
return;
}
my %records=&Apache::lonnet::dump('nohist_email',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'},
'%255b'.$user.'%253a'.$domain.'%255d');
my $result='';
foreach (sort(keys(%records))) {
my %content=&unpackagemsg($records{$_});
next if ($content{'senderdomain'} eq '');
next if ($content{'subject'} !~ /^Record/);
- # $content{'message'}=~s/\n/\
/g;
- $result.='Recorded by '.
+ # &Apache::lonfeedback::newline_to_br(\$content{'message'});
+ $result.='Recorded by '.
$content{'sendername'}.'@'.$content{'senderdomain'}."\n";
$result.=
&Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
@@ -1043,39 +1415,60 @@ sub retrieve_instructor_comments {
sub disfacetoface {
my ($r,$user,$domain)=@_;
- my $target=$ENV{'form.grade_target'};
- unless ($ENV{'request.course.id'}) { return; }
- unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
+ my $target=$env{'form.grade_target'};
+ unless ($env{'request.course.id'}) { return; }
+ if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
+ && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'})) {
+ $r->print('Not allowed');
return;
}
my %records=&Apache::lonnet::dump('nohist_email',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'},
'%255b'.$user.'%253a'.$domain.'%255d');
my $result='';
foreach (sort keys %records) {
my %content=&unpackagemsg($records{$_});
next if ($content{'senderdomain'} eq '');
- $content{'message'}=~s/\n/\
/g;
+ &Apache::lonfeedback::newline_to_br(\$content{'message'});
if ($content{'subject'}=~/^Record/) {
$result.='
'. + ''; + ''; } # Check to see if there were any messages. if ($result eq '') { @@ -1089,11 +1482,26 @@ $content{'sendername'}.'@'. } } +sub general_message { + my ($crsmsgid) = @_; + my %general_content; + if ($crsmsgid) { + my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid], + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}); + %general_content = &unpackagemsg($course_content{$crsmsgid}); + } + return $general_content{'message'}; +} + # ---------------------------------------------------------------- Face to face sub facetoface { my ($r,$stage)=@_; - unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { + if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'}) + && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + '/'.$env{'request.course.sec'})) { + $r->print('Not allowed'); return; } &printheader($r, @@ -1101,12 +1509,12 @@ sub facetoface { "User Notes, Face-to-Face, Critical Messages, Broadcast Messages"); # from query string - if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; } - if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; } + if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; } + if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; } - my $defdom=$ENV{'user.domain'}; + my $defdom=$env{'user.domain'}; # already filled in - if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; } + if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; } # generate output my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain'); my $stdbrws = &Apache::loncommon::selectstudent_link @@ -1122,7 +1530,7 @@ sub facetoface {'. &Apache::lontexconvert::msgtexconverted($content{'message'}). - '