--- loncom/interface/lonmsgdisplay.pm 2006/04/22 17:17:49 1.5 +++ loncom/interface/lonmsgdisplay.pm 2006/07/19 16:01:45 1.35.2.4 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.5 2006/04/22 17:17:49 albertel Exp $ +# $Id: lonmsgdisplay.pm,v 1.35.2.4 2006/07/19 16:01:45 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -125,6 +125,9 @@ use Apache::lonlocal; use Apache::loncommunicate; use Apache::lonfeedback; use Apache::lonrss(); +use Apache::lonselstudent(); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; # Querystring component with sorting type my $sqs; @@ -184,8 +187,9 @@ sub statuschange { &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus}); } if ($newstatus eq 'deleted') { - &movemsg(&Apache::lonnet::unescape($msgid),$folder,'trash'); - } + return &movemsg($msgid,$folder,'trash'); + } + return ; } # ============================================================= Make new folder @@ -206,107 +210,269 @@ sub movemsg { if ($srcfolder eq 'new') { $srcfolder=''; } my $srcsuffix=&Apache::lonmsg::foldersuffix($srcfolder); my $trgsuffix=&Apache::lonmsg::foldersuffix($trgfolder); + if ($srcsuffix eq $trgsuffix) { + return (0,&mt('Message not moved, Attempted to move message to the same folder as it already is in.')); + } # Copy message my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]); - &Apache::lonnet::put('nohist_email'.$trgsuffix,{$msgid => $message{$msgid}}); + if (!exists($message{$msgid}) || $message{$msgid} eq '') { + if (&Apache::lonnet::error(%message)) { + return (0,&mt('Message not moved, A network error occurred.')); + } else { + return (0,&mt('Message not moved as the message is no longer in the source folder.')); + } + } + + my $result =&Apache::lonnet::put('nohist_email'.$trgsuffix, + {$msgid => $message{$msgid}}); + if (&Apache::lonnet::error($result)) { + return (0,&mt('Message not moved, A network error occurred.')); + } # Copy status unless ($trgfolder eq 'trash') { - my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]); - &Apache::lonnet::put('email_status'.$trgsuffix,{$msgid => $status{$msgid}}); + my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]); + # a non-existant status is the mark of an unread msg + if (&Apache::lonnet::error(%status)) { + return (0,&mt('Message copied to new folder but status was not, A network error occurred.')); + } + my $result=&Apache::lonnet::put('email_status'.$trgsuffix, + {$msgid => $status{$msgid}}); + if (&Apache::lonnet::error($result)) { + return (0,&mt('Message copied to new folder but status was not, A network error occurred.')); + } } + # Delete orginals - &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]); - &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]); + my $result_del_msg = + &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]); + my $result_del_stat = + &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]); + if (&Apache::lonnet::error($result_del_msg)) { + return (0,&mt('Message copied, but unable to delete the original from the source folder.')); + } + if (&Apache::lonnet::error($result_del_stat)) { + return (0,&mt('Message copied, but unable to delete the original status from the source folder.')); + } + + return (1); } # ======================================================= Display a course list sub discourse { - my $r=shift; - my $classlist = &Apache::loncoursedata::get_classlist(); - my $now=time; - my %lt=&Apache::lonlocal::texthash('cfa' => 'Check All', - 'cfs' => 'Check Section/Group', - 'cfn' => 'Uncheck All'); - $r->print(< - -  - -  - -

-ENDDISHEADER - my %coursepersonnel=&Apache::lonnet::get_course_adv_roles(); - $r->print(''); - foreach my $role (sort keys %coursepersonnel) { - foreach (split(/\,/,$coursepersonnel{$role})) { - my ($puname,$pudom)=split(/\:/,$_); - $r->print(''. - ''); - } - } - $r->print('
('.$_.'),'.$role.'
'); - 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(''); + |; +} + +sub groupmail_header { + my ($action,$group,$cdom,$cnum) = @_; + my ($description,$refarg); + if (!$cdom || !$cnum) { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + } + if (exists($env{'form.ref'})) { + $refarg = 'ref='.$env{'form.ref'}; + } + if (!$group) { + $group = $env{'form.group'}; + } + if ($group eq '') { + return ''; + } else { + my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group); + if (defined($curr_groups{$group})) { + my %groupinfo = + &Apache::longroup::get_group_settings($curr_groups{$group}); + $description = &unescape($groupinfo{'description'}); + } } - $r->print('
'.$sname.'@'.$sdom.''.$section. - '
'); + &Apache::lonhtmlcommon::clear_breadcrumbs(); + if ($refarg) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/coursegroups", + text=>"Groups", + title=>"View course groups"}); + } + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg", + text=>"Group: $description", + title=>"Go to group's home page"}, + {href=>"/adm/email?compose=group&group=". + "$env{'form.group'}&$refarg", + text=>"Send a Message in a Group", + title=>"Compose Group Email Message"},); + if ($action eq 'sending') { + &Apache::lonhtmlcommon::add_breadcrumb + ({text=>"Messages being sent.", + title=>"Messages sent"},); + } + my $groupheader = &Apache::loncommon::start_page('Group Email'); + $groupheader .= &Apache::lonhtmlcommon::breadcrumbs + ('Group - '.$env{'form.group'}.' Email'); + return $groupheader; +} + +sub groupmail_sent { + my ($group,$cdom,$cnum) = @_; + my $refarg; + if (exists($env{'form.ref'})) { + $refarg = 'ref='.$env{'form.ref'}; + } + my $output .= '

'. + &mt('Send another group email').''.'   '. + ''. &mt('Return to group page').''; + return $output; } # ==================================================== Display Critical Message @@ -324,7 +490,7 @@ sub discrit { $result.='


'.&mt('From').': '. &Apache::loncommon::aboutmewrapper( &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. -$content{'sendername'}.'@'. +$content{'sendername'}.':'. $content{'senderdomain'}.') '.$content{'time'}. '
'.&mt('Subject').': '.$content{'subject'}. '
'.
@@ -357,18 +523,30 @@ sub sortedmessages {
     my %descriptions;
     my %status_cache = 
 	&Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
-    foreach (@messages) {
-	my $msgid=&Apache::lonnet::escape($_);
+
+    my $get_received;
+    if ($folder eq 'sent' 
+	&& ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
+	$get_received = 1;
+    }
+
+    foreach my $msgid (@messages) {
+	my $esc_msgid=&escape($msgid);
 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
-	    &Apache::lonmsg::unpackmsgid($msgid,$folder,undef,
+	    &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
 					 \%status_cache);
         my $description = &get_course_desc($fromcid,\%descriptions);
 	my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
-		     $msgid,$description);
+		     $esc_msgid,$description);
+	if ($get_received) {
+	    my %message = &Apache::lonnet::get('nohist_email'.$suffix,
+					       [$msgid]);
+	    my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
+	    push(@temp1,$content{'recuser'},$content{'recdomain'});
+	}
         # Check whether message was sent during blocking period.
         if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
-            my $escid = &Apache::lonnet::unescape($msgid);
-            $$blocked{$escid} = 'ON';
+            $$blocked{$msgid} = 'ON';
             $$numblocked ++;
         } else { 
             push @temp ,\@temp1;
@@ -383,16 +561,32 @@ sub sortedmessages {
     	@temp = sort  {$b->[0] <=> $a->[0]} @temp; 
     }
     if ($env{'form.sortedby'} eq "user"){
-	@temp = sort  {lc($a->[2]) cmp lc($b->[2])} @temp;
+	if ($get_received) {
+	    @temp = sort  {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
+	} else {
+	    @temp = sort  {lc($a->[2])    cmp lc($b->[2])}    @temp;
+	}
     }
     if ($env{'form.sortedby'} eq "revuser"){
-	@temp = sort  {lc($b->[2]) cmp lc($a->[2])} @temp;
+	if ($get_received) {
+	    @temp = sort  {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
+	} else {
+	    @temp = sort  {lc($b->[2])    cmp lc($a->[2])}    @temp;
+	}
     }
     if ($env{'form.sortedby'} eq "domain"){
-        @temp = sort  {$a->[3] cmp $b->[3]} @temp;
+	if ($get_received) {
+	    @temp = sort  {$a->[8][0] cmp $b->[8][0]} @temp;
+	} else {
+	    @temp = sort  {$a->[3]    cmp $b->[3]}    @temp;
+	}
     }
     if ($env{'form.sortedby'} eq "revdomain"){
-        @temp = sort  {$b->[3] cmp $a->[3]} @temp;
+	if ($get_received) {
+	    @temp = sort  {$b->[8][0] cmp $a->[8][0]} @temp;
+	} else {
+	    @temp = sort  {$b->[3]    cmp $a->[3]}    @temp;
+	}
     }
     if ($env{'form.sortedby'} eq "subject"){
         @temp = sort  {lc($a->[1]) cmp lc($b->[1])} @temp;
@@ -463,7 +657,7 @@ sub disnew {
 	&Apache::lonnet::get('email_status',\@msgids);
     my %descriptions;
     foreach (@msgids) {
-	my $msgid=&Apache::lonnet::escape($_);
+	my $msgid=&escape($_);
         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
 	    &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache);
         if (defined($sendtime) && $sendtime!~/error/) {
@@ -478,7 +672,7 @@ sub disnew {
                     push @newmsgs, { 
                         msgid    => $msgid,
                         sendtime => $sendtime,
-                        shortsub => &Apache::lonnet::unescape($shortsubj),
+                        shortsub => $shortsubj,
                         from     => $fromname,
                         fromdom  => $fromdom,
                         course   => $description 
@@ -549,7 +743,7 @@ sub disfolder {
     my $numblocked = 0;
     &blockcheck(\%setters,\$startblock,\$endblock);
     $r->print(<
+