--- loncom/interface/lonmsg.pm 2006/01/05 19:52:52 1.168 +++ loncom/interface/lonmsg.pm 2006/01/10 15:29:13 1.172 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.168 2006/01/05 19:52:52 albertel Exp $ +# $Id: lonmsg.pm,v 1.172 2006/01/10 15:29:13 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -267,16 +267,20 @@ sub buildmsgid { } sub unpackmsgid { - my ($msgid,$folder,$skipstatus)=@_; + my ($msgid,$folder,$skipstatus,$status_cache)=@_; $msgid=&Apache::lonnet::unescape($msgid); my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid, $processid)=split(/\:/,&Apache::lonnet::unescape($msgid)); if (!defined($processid)) { $fromcid = ''; } my %status=(); unless ($skipstatus) { - my $suffix=&foldersuffix($folder); - %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]); - if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } + if (ref($status_cache)) { + $status{$msgid} = $status_cache->{$msgid}; + } else { + my $suffix=&foldersuffix($folder); + %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]); + } + if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } unless ($status{$msgid}) { $status{$msgid}='new'; } } return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid); @@ -554,7 +558,9 @@ sub user_normal_msg_raw { unless (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group') || (($env{'form.critmsg'}) || ($env{'form.sendbck'})) && - (&Apache::lonnet::allowed('srm',$env{'request.course.id'})))) { + (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) + || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + '/'.$env{'request.course.sec'})))) { $status .= &store_sent_mail($msgid,$message); } } else { @@ -603,26 +609,28 @@ sub user_normal_msg { $domain,$user); my $msgforward=$userenv{'msgforward'}; if ($msgforward) { - foreach (split(/\,/,$msgforward)) { - my ($forwuser,$forwdomain)=split(/\:/,$_); - $status.= - &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message, - $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage).' '; - } + foreach (split(/\,/,$msgforward)) { + my ($forwuser,$forwdomain)=split(/\:/,$_); + $status.= + &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message, + $citation,$baseurl,$attachmenturl,$toperm, + undef,undef,$sentmessage).' '; + } } else { $status=&user_normal_msg_raw($user,$domain,$subject,$message, - $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage); + $citation,$baseurl,$attachmenturl,$toperm, + undef,undef,$sentmessage); } return $status; } sub store_sent_mail { my ($msgid,$message) = @_; - my $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'}); + my $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'}); return $status; } @@ -859,10 +867,13 @@ sub sortedmessages { #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,$fromcid)= - &Apache::lonmsg::unpackmsgid($msgid,$folder); + &Apache::lonmsg::unpackmsgid($msgid,$folder,undef, + \%status_cache); my $description = &get_course_desc($fromcid,\%descriptions); my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status, $msgid,$description); @@ -951,10 +962,7 @@ sub disnew { 'op' => 'Open', 'do' => 'Domain' ); - my @msgids = sort split(/\&/,&Apache::lonnet::reply - ('keys:'.$env{'user.domain'}.':'. - $env{'user.name'}.':nohist_email', - $env{'user.home'})); + my @msgids = sort(&Apache::lonnet::getkeys('nohist_email')); my @newmsgs; my %setters = (); my $startblock = 0; @@ -963,10 +971,13 @@ sub disnew { 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($_); + &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache); if (defined($sendtime) && $sendtime!~/error/) { my $description = &get_course_desc($fromcid,\%descriptions); my $numsendtime = $sendtime; @@ -977,7 +988,7 @@ sub disnew { $numblocked ++; } else { push @newmsgs, { - msgid => $_, + msgid => $msgid, sendtime => $sendtime, shortsub => &Apache::lonnet::unescape($shortsubj), from => $fromname, @@ -1221,7 +1232,9 @@ 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= '

' . $crithelp . @@ -1347,7 +1360,7 @@ $dispcrit ENDUPLOAD } if ($broadcast eq 'group') { - &discourse; + &discourse($r); } $r->print(''. &Apache::lonfeedback::generate_preview_button('compemail','message'). @@ -1360,7 +1373,9 @@ 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'})) { + 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', @@ -1385,7 +1400,10 @@ 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'})) { + 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', @@ -1439,7 +1457,10 @@ $content{'sendername'}.'@'. 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, @@ -1514,7 +1535,12 @@ ENDBFORM sub examblock { my ($r,$action) = @_; unless ($env{'request.course.id'}) { return;} - unless (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) { $r->print('Not allowed'); } + 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 %lt=&Apache::lonlocal::texthash( 'comb' => 'Communication Blocking', 'cbds' => 'Communication blocking during scheduled exams', @@ -2130,7 +2156,10 @@ sub sendoffmail { my $msgtype; my %sentmessage; if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) && - (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) { + (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) + || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + '/'.$env{'request.course.sec'}) + )) { $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1); $msgtype = 'critical'; } else { @@ -2143,7 +2172,9 @@ sub sendoffmail { if ($toaddr{$_}) { $msgtxt.='


'.$toaddr{$_}; } my $thismsg; if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) && - (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) { + (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) + || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + '/'.$env{'request.course.sec'}))) { $r->print(&mt('Sending critical message').' '.$recuname.'@'.$recdomain.': '); $thismsg=&user_crit_msg($recuname,$recdomain, &Apache::lonfeedback::clear_out_html($env{'form.subject'}),