--- loncom/interface/lonfeedback.pm 2004/07/21 23:57:24 1.101 +++ loncom/interface/lonfeedback.pm 2004/07/29 22:42:25 1.110 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.101 2004/07/21 23:57:24 raeburn Exp $ +# $Id: lonfeedback.pm,v 1.110 2004/07/29 22:42:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,6 +36,7 @@ use Apache::loncommon(); use Apache::lontexconvert(); use Apache::lonlocal; # must not have () use Apache::lonhtmlcommon(); +use Apache::lonspeller(); sub discussion_open { my ($status)=@_; @@ -124,7 +125,7 @@ sub list_discussion { } } -# Get information about students and non-stundents in course for filtering display of posts +# Get information about students and non-students in course for filtering display of posts my %roleshash = (); my %roleinfo = (); if ($rolefilter) { @@ -222,8 +223,10 @@ sub list_discussion { $newpostsflag = 1; } my $hidden=($contrib{'hidden'}=~/\.$idx\./); + my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./); my $deleted=($contrib{'deleted'}=~/\.$idx\./); my $origindex='0.'; + my $numoldver=0; if ($contrib{$idx.':replyto'}) { if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) { # this is a follow-up message @@ -247,26 +250,51 @@ sub list_discussion { } unless ((($hidden) && (!$seeid)) || ($deleted)) { $visible++; - my $message=$contrib{$idx.':message'}; + if ($contrib{$idx.':history'}) { + if ($contrib{$idx.':history'} =~ /:/) { + my @oldversions = split/:/,$contrib{$idx.':history'}; + $numoldver = @oldversions; + } else { + $numoldver = 1; + } + } + my ($message,$subject); + if ($idx > 0) { + if ($contrib{$idx.':message'} =~ /.*::::\Q$numoldver\E::::(.+?)$/si) { + $message = $1; + } else { + $message = $contrib{$idx.':message'}; + } + } else { + $message=$contrib{$idx.':message'}; + } + my $attachmenturls = $contrib{$idx.':attachmenturl'}; $message=~s/\n/\
/g; $message=&Apache::lontexconvert::msgtexconverted($message); - my $subject=$contrib{$idx.':subject'}; + if ($idx > 0) { + if ($contrib{$idx.':subject'} =~ /.*::::\Q$numoldver\E::::(.+?)$/si) { + $subject = $1; + } else { + $subject = $contrib{$idx.':subject'}; + } + } else { + $subject=$contrib{$idx.':subject'}; + } if (defined($subject)) { $subject=~s/\n/\
/g; $subject=&Apache::lontexconvert::msgtexconverted($subject); } - if ($contrib{$idx.':attachmenturl'}) { - my ($fname) - =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|); - &Apache::lonnet::allowuploaded('/adm/feedback', - $contrib{$idx.':attachmenturl'}); - $message.='

'.&mt('Attachment'). - ': '. - $fname.'

'; + if ($attachmenturls) { + my @attachments = (); + my %currattach = (); + &extract_attachments($attachmenturls,$idx,$numoldver,\$message,\@attachments,\%currattach); } if ($message) { if ($hidden) { $message=''.$message.''; + if ($studenthidden) { + $message .='

Deleted by poster (student).'; + } } my $screenname=&Apache::loncommon::screenname( $contrib{$idx.':sendername'}, @@ -329,14 +357,29 @@ sub list_discussion { } else { @{$namesort{$lastname}{$firstname}} = ("$idx"); } - if ($seeid) { - if ($hidden) { - $sender.=' '; + $sender .= '" '.$target.'>'.&mt('Edit').''; unless ($seeid) { + $sender.=" '; + } + } + } + if ($seeid) { + if ($hidden) { + unless ($studenthidden) { + $sender.=' '.&mt('Make Visible').''; + } } else { $sender.=' '.&mt('Hide').''; } $sender.='   '. ''.$subject.'  '. $sender.' '.$vgrlink.' ('. - localtime($posttime).')'. + &Apache::lonlocal::locallocaltime($posttime).')'. '
'.$message.'

'; + if ($contrib{$idx.':history'}) { + my @postversions = (); + $discussionitems[$idx] .= '
'.&mt('This post has been edited by the author.'); + if ($seeid) { + $discussionitems[$idx] .= '  
'.&mt('Display all versions').''; + } + $discussionitems[$idx].='
'.&mt('Earlier version(s) were posted on: '); + if ($contrib{$idx.':history'} =~ m/:/) { + @postversions = split/:/,$contrib{$idx.':history'}; + } else { + @postversions = ("$contrib{$idx.':history'}"); + } + for (my $i=0; $i<@postversions; $i++) { + my $version = $i+1; + $discussionitems[$idx] .= ''.$version.'. - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' '; + } + } } } } @@ -520,6 +581,20 @@ sub list_discussion { # Print the discusssion if ($outputtarget ne 'tex') { my $colspan=$maxdepth+1; + $discussion.= qq| + + |; $discussion.=''; $discussion .='
'. ''; @@ -634,7 +709,7 @@ sub list_discussion { $threadinsert='
Reply: '.$thisdepth.''; } $discussionitems[$alldiscussion{$_}]=~s/<\/td>]*)>/$threadinsert<\/td>
/; - $discussionitems[$alldiscussion{$_}]=~s/]+)>(Hide|Delete|Reply|Submissions)<\/a>//g; + $discussionitems[$alldiscussion{$_}]=~s/]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g; $discussionitems[$alldiscussion{$_}]=~s/(|<\/b>|<\/a>|]+)>)//g; #FIXME xmlparse can't be safely called from inside xmlparse @@ -684,23 +759,60 @@ END } } if ($discussiononly) { + my $now = time; + my $attachnum = 0; + my $newattachmsg = ''; + my @currnewattach = (); + my @currdelold = (); + my $comment = ''; + my $subject = ''; + if ($ENV{'form.origpage'}) { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']); + $subject = &HTML::Entities::encode($ENV{'form.subject'},'<>&"'); + $comment = &HTML::Entities::encode($ENV{'form.comment'},'<>&"'); + my @keepold = (); + &process_attachments(\@currnewattach,\@currdelold,\@keepold); + if (@currnewattach > 0) { + $attachnum += @currnewattach; + } + } $discussion.=(< -
-Note: in anonymous discussion, your name is visible only to -course faculty
-Title: 

- -

-Attachment (128 KB max size): -

- + +
+Note: in anonymous discussion, your name is visible only +to course faculty
+Title: 

+ ENDDISCUSS + if ($ENV{'form.origpage'}) { + $discussion.=''."\n"; + foreach (@currnewattach) { + $discussion.=''."\n"; + } + } + $discussion.="\n"; if ($outputtarget ne 'tex') { + $discussion.=&generate_attachments_button('',$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,'',$mode); + if (@currnewattach > 0) { + $newattachmsg .= 'New attachments
'; + if (@currnewattach > 1) { + $newattachmsg .= '
    '; + foreach my $item (@currnewattach) { + $item =~ m#.*/([^/]+)$#; + $newattachmsg .= '
  1. '.$1.'
  2. '."\n"; + } + $newattachmsg .= '
'."\n"; + } else { + $currnewattach[0] =~ m#.*/([^/]+)$#; + $newattachmsg .= ''.$1.'
'."\n"; + } + } + $discussion.=$newattachmsg; $discussion.=&generate_preview_button(); } } else { @@ -721,39 +833,155 @@ ENDDISCUSS sub mail_screen { my ($r,$feedurl,$options) = @_; + if (exists($ENV{'form.origpage'})) { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']); + } my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion', - '','onLoad="window.focus();"'); + '','onLoad="window.focus();setposttype();"'); my $title=&Apache::lonnet::gettitle($feedurl); if (!$title) { $title = $feedurl; } my $quote=''; my $subject = ''; + my $comment = ''; my $prevtag = ''; - if ($ENV{'form.replydisc'}) { - my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'}); + my $parentmsg = ''; + my ($symb,$idx,$attachmenturls); + my $numoldver = 0; + my $attachmsg = ''; + my $newattachmsg = ''; + my @currnewattach = (); + my @currdelold = (); + my @keepold = (); + my @attachments = (); + my %currattach = (); + my $attachnum = 0; + my $anonchk = (</g; - $quote='
'.&Apache::lontexconvert::msgtexconverted($message).'
'; - if ($idx > 0) { - $subject = 'Re: '.$contrib{$idx.':subject'}; + if ($ENV{'form.replydisc'}) { + if ($contrib{$idx.':history'}) { + if ($contrib{$idx.':history'} =~ /:/) { + my @oldversions = split/:/,$contrib{$idx.':history'}; + $numoldver = @oldversions; + } else { + $numoldver = 1; + } + } + my $message; + if ($idx > 0) { + if ($contrib{$idx.':message'} =~ /::::\Q$numoldver\E::::(.+?)$/si) { + $message = $1; + } else { + $message = $contrib{$idx.':message'}; + } + } else { + $message=$contrib{$idx.':message'}; + } + $message=~s/\n/\
/g; + $quote='
'.&Apache::lontexconvert::msgtexconverted($message).'
'; + if ($idx > 0) { + if ($contrib{$idx.':subject'} =~ /::::\Q$numoldver\E::::(.+?)$/si) { + $subject = $1; + } else { + $subject = $contrib{$idx.':subject'}; + } + $subject = 'Re: '.$subject; + } + $subject = &HTML::Entities::encode($subject,'<>&"'); + } else { + $attachmenturls = $contrib{$idx.':attachmenturl'}; + if ($contrib{$idx.':message'} =~ /.*::::(\d+)::::(.*?)$/si) { + $numoldver = $1; + $comment = $2; + } else { + $comment = $contrib{$idx.':message'}; + } + $comment = &HTML::Entities::encode($comment,'<>&"'); + if ($contrib{$idx.':subject'} =~ /.*::::\d+::::(.+?)$/si) { + $subject = $1; + } else { + $subject = $contrib{$idx.':subject'}; + } + $subject = &HTML::Entities::encode($subject,'<>&"'); + if (defined($contrib{$idx.':replyto'})) { + $parentmsg = $contrib{$idx.':replyto'}; + } + unless (exists($ENV{'form.origpage'})) { + my $anonflag = 0; + if ($contrib{$idx.':anonymous'}) { + $anonflag = 1; + } + $anonscript = (<'; } } + + if ($ENV{'form.origpage'}) { + $subject = $ENV{'form.subject'}; + $comment = $ENV{'form.comment'}; + &process_attachments(\@currnewattach,\@currdelold,\@keepold); + } my $latexHelp=&Apache::loncommon::helpLatexCheatsheet(); my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders(); - my $onsubmit=''; - if ((&Apache::lonhtmlcommon::htmlareabrowser()) && - (!&Apache::lonhtmlcommon::htmlareablocked())) { - $onsubmit='document.mailform.onsubmit();'; - } my $send=&mt('Send'); - $r->print(<print(< The LearningOnline Network with CAPA @@ -795,12 +1023,16 @@ $htmlheader } if (rec) { - $onsubmit + if (typeof(document.mailform.onsubmit)!='undefined') { + document.mailform.onsubmit(); + } document.mailform.submit(); } else { alert('Please check a feedback type.'); } } + $anonchk + $anonscript //--> @@ -810,7 +1042,18 @@ $bodytag enctype="multipart/form-data"> $prevtag +END + if ($ENV{'form.replydisc'}) { + $r->print(< +END + } elsif ($ENV{'form.editdisc'}) { + $r->print(< + +END + } + $r->print(< $quote @@ -819,20 +1062,78 @@ $quote $latexHelp Title:

-

+END + if ( ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'}) ) { + if ($ENV{'form.origpage'}) { + foreach (@currnewattach) { + $r->print(''."\n"); + } + foreach (@currdelold) { + $r->print(''."\n"); + } + } + if ($ENV{'form.editdisc'}) { + if ($attachmenturls) { + &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\@attachments,\%currattach,\@currdelold); + $attachnum = scalar(keys %currattach); + foreach (keys %currattach) { + $r->print(''."\n"); + } + } + } + } else { + $r->print(<

+END + } + $r->print(<

-ENDDOCUMENT -$r->print(&generate_preview_button(). -&Apache::lonhtmlcommon::htmlareaselectactive('comment'). -''); +END + if ($ENV{'form.editdisc'} || $ENV{'form.replydisc'}) { + my $now = time; + my $ressymb = $symb; + my $postidx = ''; + if ($ENV{'form.editdisc'}) { + $postidx = $idx; + } + if (@currnewattach > 0) { + $attachnum += @currnewattach; + } + $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver)); + if ($attachnum > 0) { + if (@currnewattach > 0) { + $newattachmsg .= 'New attachments
'; + if (@currnewattach > 1) { + $newattachmsg .= '
    '; + foreach my $item (@currnewattach) { + $item =~ m#.*/([^/]+)$#; + $newattachmsg .= '
  1. '.$1.'
  2. '."\n"; + } + $newattachmsg .= '
'."\n"; + } else { + $currnewattach[0] =~ m#.*/([^/]+)$#; + $newattachmsg .= ''.$1.'
'."\n"; + } + } + if ($attachmsg) { + $r->print("Retained attachments:$attachmsg
\n"); + } + if ($newattachmsg) { + $r->print("$newattachmsg
"); + } + } + } + $r->print(&generate_preview_button(). + &Apache::lonhtmlcommon::htmlareaselectactive('comment'). + ''); } sub print_display_options { @@ -1118,6 +1419,9 @@ sub print_showposters { } } my $crs='/'.$ENV{'request.course.id'}; + if ($ENV{'request.course.sec'}) { + $crs.='_'.$ENV{'request.course.sec'}; + } $crs=~s/\_/\//g; my $seeid=&Apache::lonnet::allowed('rin',$crs); my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'}, @@ -1298,6 +1602,7 @@ ENDREDIR sub no_redirect_back { my ($r,$feedurl) = @_; + my $nofeed=&mt('Sorry, no feedback possible on this resource ...'); $r->print (< Feedback not sent @@ -1312,7 +1617,7 @@ ENDNOREDIR -Sorry, no feedback possible on this resource ... +$nofeed ENDNOREDIRTWO @@ -1322,7 +1627,7 @@ sub screen_header { my ($feedurl) = @_; my $msgoptions=''; my $discussoptions=''; - unless ($ENV{'form.replydisc'}) { + unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) { if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) { $msgoptions= '

'. @@ -1379,25 +1684,25 @@ sub resource_output { sub clear_out_html { my ($message,$override)=@_; unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; } +# Always allow the -tag + my %html=(M=>1); +# Check if more is allowed my $cid=$ENV{'request.course.id'}; if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) || ($override)) { # allows