--- loncom/interface/lonmsg.pm 2004/11/17 21:31:37 1.121 +++ loncom/interface/lonmsg.pm 2005/02/17 04:02:47 1.135 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.121 2004/11/17 21:31:37 www Exp $ +# $Id: lonmsg.pm,v 1.135 2005/02/17 04:02:47 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -90,7 +90,7 @@ 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 screen, but generally, LON-CAPA messages -are much more useful then traditional email can be made to be, even +are much more useful than traditional email can be made to be, even with HTML support. Right now, this document will cover just how to send a message, since @@ -239,9 +239,15 @@ sub sendemail { # ==================================================== Send notification emails sub sendnotification { - my ($to,$touname,$toudom,$subj,$crit)=@_; + my ($to,$touname,$toudom,$subj,$crit,$text)=@_; my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'}; + unless ($sender=~/\w/) { + $sender=$ENV{'user.name'}.'@'.$ENV{'user.domain'}; + } my $critical=($crit?' critical':''); + $text=~s/\<\;/\/gs; + $text=~s/\<\/*[^\>]+\>//gs; my $url='http://'. $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}. '/adm/email?username='.$touname.'&domain='.$toudom; @@ -250,11 +256,15 @@ You received a$critical message from $se $subj +=== Excerpt ============================================================ +$text +======================================================================== + Use $url -to access this message. +to access the full message. ENDMSG &sendemail($to,'New'.$critical.' message from '.$sender,$body); } @@ -346,11 +356,12 @@ sub all_url_author_res_msg { # ================================================== Critical message to a user sub user_crit_msg_raw { - my ($user,$domain,$subject,$message,$sendback)=@_; + my ($user,$domain,$subject,$message,$sendback,$toperm)=@_; # Check if allowed missing my $status=''; my $msgid='undefined'; unless (($message)&&($user)&&($domain)) { $status='empty'; }; + my $text=$message; my $homeserver=&Apache::lonnet::homeserver($user,$domain); if ($homeserver ne 'no_host') { ($msgid,$message)=&packagemsg($subject,$message); @@ -370,10 +381,16 @@ sub user_crit_msg_raw { $status='no_host'; } # Notifications - my %userenv = &Apache::lonnet::get('environment',['critnotification'], + my %userenv = &Apache::lonnet::get('environment',['critnotification', + 'permanentemail'], $domain,$user); if ($userenv{'critnotification'}) { - &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1); + &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1, + $text); + } + if ($toperm && $userenv{'permanentemail'}) { + &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1, + $text); } # Log this &Apache::lonnet::logthis( @@ -397,7 +414,7 @@ sub user_crit_msg_raw { =cut sub user_crit_msg { - my ($user,$domain,$subject,$message,$sendback)=@_; + my ($user,$domain,$subject,$message,$sendback,$toperm)=@_; my $status=''; my %userenv = &Apache::lonnet::get('environment',['msgforward'], $domain,$user); @@ -407,10 +424,10 @@ sub user_crit_msg { my ($forwuser,$forwdomain)=split(/\:/,$_); $status.= &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message, - $sendback).' '; + $sendback,$toperm).' '; } } else { - $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback); + $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm); } return $status; } @@ -444,10 +461,12 @@ sub user_crit_received { # ======================================================== Normal communication sub user_normal_msg_raw { - my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_; + my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, + $toperm)=@_; # Check if allowed missing my $status=''; my $msgid='undefined'; + my $text=$message; unless (($message)&&($user)&&($domain)) { $status='empty'; }; my $homeserver=&Apache::lonnet::homeserver($user,$domain); if ($homeserver ne 'no_host') { @@ -471,10 +490,16 @@ sub user_normal_msg_raw { $status='no_host'; } # Notifications - my %userenv = &Apache::lonnet::get('environment',['notification'], + my %userenv = &Apache::lonnet::get('environment',['notification', + 'permanentemail'], $domain,$user); if ($userenv{'notification'}) { - &sendnotification($userenv{'notification'},$user,$domain,$subject,0); + &sendnotification($userenv{'notification'},$user,$domain,$subject,0, + $text); + } + if ($toperm && $userenv{'permanentemail'}) { + &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0, + $text); } &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'}, $ENV{'user.home'}, @@ -493,7 +518,8 @@ sub user_normal_msg_raw { =cut sub user_normal_msg { - my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_; + my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, + $toperm)=@_; my $status=''; my %userenv = &Apache::lonnet::get('environment',['msgforward'], $domain,$user); @@ -503,11 +529,11 @@ sub user_normal_msg { my ($forwuser,$forwdomain)=split(/\:/,$_); $status.= &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message, - $citation,$baseurl,$attachmenturl).' '; + $citation,$baseurl,$attachmenturl,$toperm).' '; } } else { $status=&user_normal_msg_raw($user,$domain,$subject,$message, - $citation,$baseurl,$attachmenturl); + $citation,$baseurl,$attachmenturl,$toperm); } return $status; } @@ -527,9 +553,11 @@ 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)/?'':''); @@ -537,7 +565,9 @@ sub folderlist { sub scrollbuttons { my ($start,$maxdis,$first,$finish,$total)=@_; + unless ($total>0) { return ''; } $start++; $maxdis++;$first++;$finish++; + return ''. ''. ' of '.$maxdis. @@ -586,7 +616,6 @@ sub makefolder { sub movemsg { my ($msgid,$srcfolder,$trgfolder)=@_; - my $unmsgid=&Apache::lonnet::unescape($msgid); my $srcsuffix=&foldersuffix($srcfolder); my $trgsuffix=&foldersuffix($trgfolder); @@ -595,16 +624,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 @@ -667,7 +693,15 @@ ENDDISHEADER } } $r->print(''); - while (my ($student,$info) = each(%$classlist)) { + 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(), @@ -675,7 +709,7 @@ ENDDISHEADER &Apache::loncoursedata::CL_FULLNAME(), &Apache::loncoursedata::CL_SECTION()]); next if ($status ne 'Active'); - my $key = 'send_to_&&&'.$section.'&&&'.$student; + my $key = 'send_to_&&&'.$section.'&&&_'.$student; if (! defined($fullname) || $fullname eq '') { $fullname = $sname; } $r->print(' - + ENDLINK foreach ('sendtime','from','fromdom','shortsub') { $r->print(""); @@ -913,6 +946,13 @@ ENDDISHEADER my $fsqs='&folder='.$folder; my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); my $totalnumber=$#temp+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; @@ -947,11 +987,11 @@ ENDDISHEADER } $r->print(''); + $r->print(''.&mt('Status').''); } else { - $r->print(''.&mt('Status').''); + $r->print(''.&mt('Status').''); } - $r->print(''); + $r->print("\n"); for (my $n=$firstdis;$n<=$lastdis;$n++) { my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @{$temp[$n]}; if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) { @@ -964,20 +1004,20 @@ ENDDISHEADER } else { $r->print(''); } - $r->print(''. + '">'.&mt('Delete'):' ').''. ''); + $status."\n"); } elsif ($status eq 'deleted') { # purge &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash'); } } - $r->print('
$lt{'op'}$lt{'op'}$msg->{$_}'); if ($ENV{'form.sortedby'} eq "revstatus") { - $r->print(''.&mt('Status').'
'.&mt('Open').''. ($folder ne 'trash'?''.&mt('Delete'):' ').''.&Apache::lonlocal::locallocaltime($sendtime).''. $fromname.''.$fromdomain.''. &Apache::lonnet::unescape($shortsubj).''. - $status.'

'. + $r->print("\n

". ''.&mt('Check All').' '. ''.&mt('Uncheck All').'

'. ''); @@ -992,7 +1032,8 @@ ENDDISHEADER &Apache::loncommon::select_form('','movetofolder', ( map { $_ => $_ } @allfolders)) ); - $r->print(''); + my $postedstartdis=$startdis+1; + $r->print(''); if ($numblocked > 0) { my $beginblock = &Apache::lonlocal::locallocaltime($startblock); my $finishblock = &Apache::lonlocal::locallocaltime($endblock); @@ -1050,9 +1091,11 @@ sub compout { my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message"); $dispcrit= ' '.&mt('Send as critical message').' ' . $crithelp . - '
'. + '
'. ' '.&mt('Send as critical message').' ' . - &mt('and return receipt') . $crithelp . '

'; + &mt('and return receipt') . $crithelp . + '
'. +&mt('Send copy to permanent email address (if known)').'

'; } my %message; my %content; @@ -1231,9 +1274,9 @@ sub disfacetoface { &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. $content{'sendername'}.'@'. $content{'senderdomain'}.') '.$content{'time'}. - '

'. + '
'.
               &Apache::lontexconvert::msgtexconverted($content{'message'}).
-	      '
'; + ''; } # Check to see if there were any messages. if ($result eq '') { @@ -1731,9 +1774,9 @@ sub displaymessage { '">'.&mt('Mark Unread').''. 'Delete'. - ''.&mt('Display all Messages').''); + ''.&mt('Back to Folder Display').''); if ($counter > 0){ $r->print(''.&mt('Previous').''); @@ -1912,7 +1955,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'})) && @@ -1921,13 +1970,13 @@ sub sendoffmail { $thismsg=&user_crit_msg($recuname,$recdomain, &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), $msgtxt, - $ENV{'form.sendbck'}); + $ENV{'form.sendbck'},$ENV{'form.permanent'}); } else { $r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': '); $thismsg=&user_normal_msg($recuname,$recdomain, &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), $msgtxt, - $content{'citation'}); + $content{'citation'},undef,undef,$ENV{'form.permanent'}); if (($ENV{'request.course.id'}) && ($ENV{'form.sendmode'} eq 'group')) { &user_normal_msg_raw( $ENV{'course.'.$ENV{'request.course.id'}.'.num'}, @@ -1974,10 +2023,8 @@ sub handler { ['display','replyto','forward','markread','markdel','markunread', 'sendreply','compose','sendmail','critical','recname','recdom', 'recordftf','sortedby','block','folder','startdis','interdis', - 'showcommentbaseurl']); - $sqs='&sortedby='.$ENV{'form.sortedby'}. - '&startdis='.$ENV{'form.startdis'}. - '&interdis='.$ENV{'form.interdis'}; + 'showcommentbaseurl','dismode']); + $sqs='&sortedby='.$ENV{'form.sortedby'}; # ------------------------------------------------------ They checked for email unless ($ENV{'form.block'}) { @@ -1998,7 +2045,7 @@ sub handler { unless ($folder) { $folder=''; } else { - $sqs='&folder='.&Apache::lonnet::escape($folder); + $sqs.='&folder='.&Apache::lonnet::escape($folder); } # --------------------------------------------------------------------- Display @@ -2006,8 +2053,11 @@ sub handler { $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; } @@ -2020,7 +2070,8 @@ sub handler { if ($ENV{'form.nextview'}) { $startdis++; } - + my $postedstartdis=$startdis+1; + $sqs.='&startdis='.$postedstartdis; # --------------------------------------------------------------- Render Output