--- loncom/interface/lonfeedback.pm 2004/07/23 16:56:29 1.103 +++ loncom/interface/lonfeedback.pm 2004/08/10 18:25:53 1.115 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.103 2004/07/23 16:56:29 albertel Exp $ +# $Id: lonfeedback.pm,v 1.115 2004/08/10 18:25:53 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,6 +36,8 @@ use Apache::loncommon(); use Apache::lontexconvert(); use Apache::lonlocal; # must not have () use Apache::lonhtmlcommon(); +use HTML::LCParser(); +use Apache::lonspeller(); sub discussion_open { my ($status)=@_; @@ -64,7 +66,6 @@ sub discussion_visible { sub list_discussion { my ($mode,$status,$symb)=@_; - my $outputtarget=$ENV{'form.grade_target'}; if (not &discussion_visible($status)) { return ''; } my @bgcols = ("#cccccc","#eeeeee"); @@ -95,12 +96,17 @@ sub list_discussion { # Get discussion display settings for this discussion my $lastkey = $ressymb.'_lastread'; my $showkey = $ressymb.'_showonlyunread'; + my $markkey = $ressymb.'_showonlyunmark', my $visitkey = $ressymb.'_visit'; my $ondispkey = $ressymb.'_markondisp'; my $userpickkey = $ressymb.'_userpick'; - my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey,$userpickkey],$ENV{'user.domain'},$ENV{'user.name'}); + my $toggkey = $ressymb.'_readtoggle'; + my $readkey = $ressymb.'_read'; + + my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$ENV{'user.domain'},$ENV{'user.name'}); my %discinfo = (); my $showonlyunread = 0; + my $showunmark = 0; my $markondisp = 0; my $prevread = 0; my $previous = 0; @@ -124,7 +130,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) { @@ -175,6 +181,10 @@ sub list_discussion { $showonlyunread = $dischash{$showkey}; } + if (defined($dischash{$markkey})) { + $showunmark = $dischash{$markkey}; + } + if (defined($dischash{$visitkey})) { $visit = $dischash{$visitkey}; } @@ -204,7 +214,7 @@ sub list_discussion { $ENV{'environment.remote'} eq 'off' ) { $target='target="LONcom"'; } - + my $now = time; $discinfo{$visitkey} = $visit; @@ -257,22 +267,40 @@ sub list_discussion { $numoldver = 1; } } - my $message=$contrib{$idx.':message'}; + my ($message,$subject); + if ($idx > 0) { + if ($contrib{$idx.':message'} =~ /^/) { + my %versions = (); + &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver); + $message = &HTML::Entities::decode($versions{$numoldver}); + } else { + $message = $contrib{$idx.':message'}; + } + } else { + $message=$contrib{$idx.':message'}; + } + my $attachmenturls = $contrib{$idx.':attachmenturl'}; $message=~s/\n/\
/g; - $message=&Apache::lontexconvert::msgtexconverted($message,undef,$numoldver); - my $subject=$contrib{$idx.':subject'}; + $message=&Apache::lontexconvert::msgtexconverted($message); + if ($idx > 0) { + if ($contrib{$idx.':subject'} =~ /^/g; - $subject=&Apache::lontexconvert::msgtexconverted($subject,undef,$numoldver); + $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) { @@ -419,6 +447,12 @@ sub list_discussion { $vgrlink=&Apache::loncommon::submlink('Submissions', $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb); } + my $ctlink; + if ($dischash{$readkey}=~/\.$idx\./) { + $ctlink = ''.&mt('Mark unread').'? '; + } else { + $ctlink = ''.&mt('Mark read').'? '; + } #figure out at what position this needs to print my $thisindex=$idx; if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) { @@ -430,7 +464,10 @@ sub list_discussion { my $spansize = 2; if ($showonlyunread && $prevread > $posttime) { $notshown{$idx} = 1; + } elsif ($showunmark && $dischash{$readkey}=~/\.$idx\./) { + $notshown{$idx} = 1; } else { +# apply filters my $uname = $contrib{$idx.':sendername'}; my $udom = $contrib{$idx.':senderdomain'}; my $poster = $uname.':'.$udom; @@ -492,11 +529,19 @@ sub list_discussion { $discussionitems[$idx] .= '  '. ''.$subject.'  '. $sender.' '.$vgrlink.' ('. - localtime($posttime).')'. - '
'.$message.'

'; + &Apache::lonlocal::locallocaltime($posttime).')'; + if ($dischash{$toggkey}) { + $discussionitems[$idx].='  '. + $ctlink.''; + } + $discussionitems[$idx].= '
'.$message.'

'; if ($contrib{$idx.':history'}) { my @postversions = (); - $discussionitems[$idx] .= '
'.&mt('This post has been edited by the author.').'
'.&mt('Earlier version(s) were posted on: '); + $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 { @@ -506,7 +551,6 @@ sub list_discussion { my $version = $i+1; $discussionitems[$idx] .= ''.$version.'. - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' '; } - $discussionitems[$idx] .= '
'; } } } @@ -523,22 +567,31 @@ sub list_discussion { 'cuse' => 'Current discussion settings', 'allposts' => 'All posts', 'unread' => 'New posts only', + 'unmark' => 'Unread only', 'ondisp' => 'Once displayed', - 'onmark' => 'Once marked read', + 'onmark' => 'Once marked not NEW', + 'toggoff' => 'Off', + 'toggon' => 'On', 'disa' => 'Posts to be displayed', 'npce' => 'Posts cease to be marked "NEW"', + 'epcb' => 'Each post can be toggled read/unread', 'chgt' => 'Change', 'disp' => 'Display', 'nolo' => 'Not new', + 'togg' => 'Toggle read/unread', ); my $currdisp = $lt{'allposts'}; my $currmark = $lt{'onmark'}; + my $currtogg = $lt{'toggoff'}; my $dispchange = $lt{'unread'}; my $markchange = $lt{'ondisp'}; + my $toggchange = $lt{'toggon'}; my $chglink = '/adm/feedback?modifydisp='.$ressymb; - my $displink = 'onlyunread'; + my $displinkA = 'onlyunread'; + my $displinkB = 'onlyunmark'; my $marklink = 'markondisp'; + my $togglink = 'toggon'; if ($markondisp) { $currmark = $lt{'ondisp'}; @@ -549,10 +602,24 @@ sub list_discussion { if ($showonlyunread) { $currdisp = $lt{'unread'}; $dispchange = $lt{'allposts'}; - $displink = 'allposts'; + $displinkA = 'allposts'; } + + if ($showunmark) { + $currdisp = $lt{'unmark'}; + $dispchange = $lt{'unmark'}; + $displinkA='allposts'; + $displinkB='onlyunread'; + $showonlyunread = 0; + } + + if ($dischash{$toggkey}) { + $currtogg = $lt{'toggon'}; + $toggchange = $lt{'toggoff'}; + $togglink = 'toggoff'; + } - $chglink .= '&changes='.$displink.'_'.$marklink; + $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink; if ($newpostsflag) { $chglink .= '&previous='.$prevread; @@ -576,7 +643,7 @@ sub list_discussion { } |; - $discussion.=''; + $discussion.='
'; $discussion .=''; } else { - $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'. + $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'. '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'. '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'. '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'. - '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}'; + '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}'; } my $numhidden = keys %notshown; if ($numhidden > 0) { @@ -630,8 +697,13 @@ sub list_discussion { $discussion .= '&previous='.$prevread; } $discussion .= '">'.&mt('Show all posts').' '.&mt('to display').' '. - $numhidden.' '.&mt('previously viewed posts'). - '
'; + $numhidden.' '; + if ($showunmark) { + $discussion .= &mt('posts previously marked read'); + } else { + $discussion .= &mt('previously viewed posts'); + } + $discussion .= '
'; } # Choose sort mechanism @@ -667,8 +739,6 @@ sub list_discussion { unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) { if ($outputtarget ne 'tex') { $discussion.="\n"; - } else { - $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'; } my $thisdepth=$depth[$alldiscussion{$_}]; if ($outputtarget ne 'tex') { @@ -692,19 +762,15 @@ sub list_discussion { $discussionitems[$alldiscussion{$_}]=~s/<\/td>]*)>/$threadinsert<\/td> +END + if ($dischash{$toggkey}) { + my $storebutton = &mt('Store read/unread changes'); + $discussion.=''; + } + $discussion .= (<
'. ''; if ($visible>2) { @@ -606,7 +673,7 @@ sub list_discussion { $discussion .= '">'.&mt('Export').'?  '; if ($newpostsflag) { if (!$markondisp) { - $discussion .=''; } @@ -615,11 +682,11 @@ sub list_discussion { } $discussion .= '
'.&mt('Mark new posts as read').'  '; + $discussion .=''.&mt('Mark NEW posts no longer new').'  '; } else { $discussion .= ' 
/; $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 - # due to the global variables that are use, the safe - # space etc. I expect this has unforseen issues that - # need resolving. - - $discussion.=&Apache::lonxml::xmlparse('','tex',$discussionitems[$alldiscussion{$_}]); + + $discussionitems[$alldiscussion{$_}]='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.$discussionitems[$alldiscussion{$_}]; + $discussion.=$discussionitems[$alldiscussion{$_}]; } } } if ($outputtarget ne 'tex') { my $colspan=$maxdepth+1; - $discussion .= < @@ -715,48 +781,105 @@ sub list_discussion { + '; + '1. '.$lt{'disp'}.' - '.$currdisp.'  2. '.$lt{'nolo'}.' - '.$currmark.''; + if ($dischash{$toggkey}) { + $discussion .= '  3. '.$lt{'togg'}.' - '.$currtogg.''; + } } else { - $discussion .= - ''; + if ($dischash{$toggkey}) { + $discussion .= '1. '.$lt{'disp'}.' - '.$currdisp.' 2. '.$lt{'togg'}.' - '.$currtogg.''; + } else { + $discussion .= + $lt{'disp'}.' - '.$currdisp.''; + } } $discussion .= < + $lt{'chgt'}? +
$lt{'cuse'}:   END if ($newpostsflag) { $discussion .= - '1. '.$lt{'disp'}.' - '.$currdisp.'  2. '.$lt{'nolo'}.' - '.$currmark.''.$lt{'disp'}.' - '.$currdisp.'  - $lt{'chgt'}?
'. + ''."\n". + ''."\n". + '
-

+

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 { @@ -772,27 +895,67 @@ ENDDISCUSS } } } - return $discussion; + return $discussion; } 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();setposttype();"'); my $title=&Apache::lonnet::gettitle($feedurl); if (!$title) { $title = $feedurl; } my $quote=''; my $subject = ''; - my $oldmessage = ''; + my $comment = ''; my $prevtag = ''; my $parentmsg = ''; - my $anonscript = (< 0) { + if ($contrib{$idx.':message'} =~ /^/g; - $quote='
'.&Apache::lontexconvert::msgtexconverted($message,undef,$numoldver).'
'; + $quote='
'.&Apache::lontexconvert::msgtexconverted($message).'
'; if ($idx > 0) { - if ($contrib{'subject'} =~ /::::\d+::::(.+)$/si) { - $subject = $1; + if ($contrib{$idx.':subject'} =~ /^&"'); } else { - if ($contrib{$idx.':message'} =~ /::::\d+::::(.+)$/si) { - $oldmessage = $1; + $attachmenturls = $contrib{$idx.':attachmenturl'}; + if ($contrib{$idx.':message'} =~ /^/) { + my %versions = (); + &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver); + $comment = $versions{$numoldver}; } else { - $oldmessage = $contrib{$idx.':message'}; + $comment = &HTML::Entities::encode($contrib{$idx.':message'},'<>&"'); } - $oldmessage=&HTML::Entities::encode($oldmessage,'<>&"'); - if ($contrib{$idx.':subject'} =~ /::::\d+::::(.+)$/si) { - $subject = $1; + if ($contrib{$idx.':subject'} =~ //) { + my %versions = (); + &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver); + $subject = $versions{$numoldver}; } else { - $subject = $contrib{$idx.':subject'}; + $subject = &HTML::Entities::encode($contrib{$idx.':subject'},'<>&"'); } if (defined($contrib{$idx.':replyto'})) { $parentmsg = $contrib{$idx.':replyto'}; } - 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(< @@ -912,12 +1103,15 @@ $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 //--> @@ -939,7 +1133,7 @@ END END } - $r->print(<print(< $quote @@ -948,24 +1142,82 @@ $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 { - my ($r,$symb,$previous,$dispchg,$markchg,$feedurl) = @_; + my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_; # backward compatibility (bulletin boards used to be 'wrapped') if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { $feedurl=~s|^/adm/wrapper||; @@ -985,54 +1237,116 @@ sub print_display_options { 'deff' => 'Default for all discussions', 'prca' => 'Preferences can be set for this discussion that determine ....', 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and', - 'unwh' => 'Under what circumstances posts are identfied as "New."', + 'unwh' => 'Under what circumstances posts are identified as "NEW", and', + 'wipa' => 'Whether individual posts can be marked as read/unread', 'allposts' => 'All posts', 'unread' => 'New posts only', + 'unmark' => 'Posts not marked read', 'ondisp' => 'Once displayed', - 'onmark' => 'Once marked as read', + 'onmark' => 'Once marked not NEW ', + 'toggon' => 'Shown', + 'toggoff' => 'Not shown', 'disa' => 'Posts displayed?', - 'npmr' => 'New posts cease to be identified as "New"?', + 'npmr' => 'New posts cease to be identified as "NEW"?', + 'dotm' => 'Option to mark each post as read/unread?', 'chgt' => 'Change to ', 'mkdf' => 'Set to ', - 'yhni' => 'You have not indicated that you wish to change either of the discussion settings', + 'yhni' => 'You have not indicated that you wish to change any of the discussion settings', 'ywbr' => 'You will be returned to the previous page if you click OK.' ); - my $dispchange = $lt{'unread'}; + my $dispchangeA = $lt{'unread'}; + my $dispchangeB = $lt{'unmark'}; my $markchange = $lt{'ondisp'}; + my $toggchange = $lt{'toggon'}; my $currdisp = $lt{'allposts'}; my $currmark = $lt{'onmark'}; my $discdisp = 'allposts'; my $discmark = 'onmark'; + my $currtogg = $lt{'toggoff'}; + my $disctogg = 'toggoff'; - if ($dispchg eq 'allposts') { - $dispchange = $lt{'allposts'}; + if ($dispchgA eq 'allposts') { + $dispchangeA = $lt{'allposts'}; $currdisp = $lt{'unread'}; $discdisp = 'unread'; } - + if ($markchg eq 'markonread') { $markchange = $lt{'onmark'}; $currmark = $lt{'ondisp'}; $discmark = 'ondisp'; } + + if ($dispchgB eq 'onlyunread') { + $dispchangeB = $lt{'unread'}; + $currdisp = $lt{'unmark'}; + $discdisp = 'unmark'; + } + if ($toggchg eq 'toggoff') { + $toggchange = $lt{'toggoff'}; + $currtogg = $lt{'toggon'}; + $disctogg = 'toggon'; + } $r->print(< $lt{'dido'} + +$bodytag +
+ + + + +
+ Subject:$subject

+END + if ($idx) { + if ($attachmenturls) { + my @currold = keys %currattach; + if (@currold > 0) { + $r->print("The following attachments were part of the most recent saved version of this posting.
Check the checkboxes for any you wish to remove
\n"); + foreach my $id (@currold) { + my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'}); + $attachurl =~ m#/([^/]+)$#; + $r->print(' '.$1.'
'."\n"); + } + $r->print("
"); + } + } + } + if (@{$currnewattach} > 0) { + $r->print("The following attachments have been uploaded for inclusion with this posting.
Check the checkboxes for any you wish to remove
\n"); + foreach (@{$currnewattach}) { + $_ =~ m#/([^/]+)$#; + $r->print(' '.$1.'
'."\n"); + } + $r->print("
"); + } + $r->print(< +
+ + + + + + + + +END + foreach (@{$currnewattach}) { + $r->print(''."\n"); + } + foreach (@{$currdelold}) { + $r->print(''."\n"); + } + $r->print(< + + + +END + return; +} + +sub process_attachments { + my ($currnewattach,$currdelold,$keepold) = @_; + if (exists($ENV{'form.currnewattach'})) { + if (ref($ENV{'form.currnewattach'}) eq 'ARRAY') { + @{$currnewattach} = @{$ENV{'form.currnewattach'}}; + } else { + $$currnewattach[0] = $ENV{'form.currnewattach'}; + } + } + if (exists($ENV{'form.deloldattach'})) { + if (ref($ENV{'form.deloldattach'}) eq 'ARRAY') { + @{$currdelold} = @{$ENV{'form.deloldattach'}}; + } else { + $$currdelold[0] = $ENV{'form.deloldattach'}; + } + } + if (exists($ENV{'form.delnewattach'})) { + my @currdelnew = (); + my @currnew = (); + if (ref($ENV{'form.delnewattach'}) eq 'ARRAY') { + @currdelnew = @{$ENV{'form.delnewattach'}}; + } else { + $currdelnew[0] = $ENV{'form.delnewattach'}; + } + foreach my $newone (@{$currnewattach}) { + my $delflag = 0; + foreach (@currdelnew) { + if ($newone eq $_) { + $delflag = 1; + last; + } + } + unless ($delflag) { + push @currnew, $newone; + } + } + @{$currnewattach} = @currnew; + } + if (exists($ENV{'form.keepold'})) { + if (ref($ENV{'form.keepold'}) eq 'ARRAY') { + @{$keepold} = @{$ENV{'form.keepold'}}; + } else { + $$keepold[0] = $ENV{'form.keepold'}; + } + } +} + +sub generate_attachments_button { + my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_; + my $origpage = $ENV{'REQUEST_URI'}; + my $att=$attachnum.' '.&mt("attachments"); + my $response = (< +Click to add/remove attachments:  + + + + + + +ENDATTACH + if (defined($deloldattach)) { + if (@{$deloldattach} > 0) { + foreach (@{$deloldattach}) { + $response .= ''."\n"; + } + } + } + if (defined($currnewattach)) { + if (@{$currnewattach} > 0) { + foreach (@{$currnewattach}) { + $response .= ''."\n"; + } + } + } + $response .= ''; + return $response; +} + +sub extract_attachments { + my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_; + if ($attachmenturls =~ m/^/) { + &get_post_attachments($attachments,$attachmenturls); + foreach my $id (sort keys %{$attachments}) { + if (exists($$attachments{$id}{$numoldver})) { + if (defined($currdelold)) { + if (@{$currdelold} > 0) { + unless (grep/^$id$/,@{$currdelold}) { + $$currattach{$id} = $$attachments{$id}{$numoldver}; + } + } else { + $$currattach{$id} = $$attachments{$id}{$numoldver}; + } + } else { + $$currattach{$id} = $$attachments{$id}{$numoldver}; + } + } + } + my @attached = (sort { $a <=> $b } keys %{$currattach}); + if (@attached == 1) { + my $id = $attached[0]; + my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'}); + $attachurl=~m|/([^/]+)$|; + $$message.='
'. + $1.'
'; + &Apache::lonnet::allowuploaded('/adm/feedback', + $attachurl); + } elsif (@attached > 1) { + $$message.='
    '; + foreach (@attached) { + my $id = $_; + my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'}); + my ($fname) + =($attachurl=~m|/([^/]+)$|); + $$message .= '
  1. '. + $fname.'
  2. '; + &Apache::lonnet::allowuploaded('/adm/feedback', + $attachurl); + } + $$message .= '

'; + } + } else { + my ($fname) + =($attachmenturls=~m|/([^/]+)$|); + $$message .='

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

'; + $$attachments{0} = $attachmenturls; + $$currattach{'0'} = 'n'; + &Apache::lonnet::allowuploaded('/adm/feedback', + $attachmenturls); + } +} + +sub construct_attachmenturl { + my ($currnewattach,$keepold,$symb,$idx)=@_; + my $oldattachmenturl; + my $newattachmenturl; + my $startnum = 0; + my $currver = 0; + if (($ENV{'form.editdisc'}) && ($idx)) { + my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + $oldattachmenturl = $contrib{$idx.':attachmenturl'}; + if ($contrib{$idx.':history'}) { + if ($contrib{$idx.':history'} =~ /:/) { + my @oldversions = split/:/,$contrib{$idx.':history'}; + $currver = 1 + scalar(@oldversions); + } else { + $currver = 2; + } + } else { + $currver = 1; + } + if ($oldattachmenturl) { + if ($oldattachmenturl =~ m/^/) { + my %attachments = (); + my $prevver = $currver-1; + &get_post_attachments(\%attachments,$oldattachmenturl); + my $numattach = keys %attachments; + $startnum += $numattach; + foreach my $num (sort {$a <=> $b} keys %attachments) { + $newattachmenturl .= ''.$attachments{$num}{'filename'}.''; + foreach (sort {$a <=> $b} keys %{$attachments{$num}}) { + $newattachmenturl .= ''.$attachments{$num}{$_}.''; + } + if (grep/^$num$/,@{$keepold}) { + $newattachmenturl .= ''.$attachments{$num}{$prevver}.''; + } + $newattachmenturl .= ''; + } + } else { + $newattachmenturl = ''.&HTML::Entities::encode($oldattachmenturl).'n'; + unless (grep/^0$/,@{$keepold}) { + $newattachmenturl .= 'n'; + } + $newattachmenturl .= ''; + $startnum ++; + } + } + } + for (my $i=0; $i<@{$currnewattach}; $i++) { + my $attachnum = $startnum + $i; + $newattachmenturl .= ''.&HTML::Entities::encode($$currnewattach[$i]).'n'; + } + return $newattachmenturl; +} + sub handler { my $r = shift; if ($r->header_only) { @@ -1780,7 +2438,126 @@ sub handler { # --------------------------- Get query string for limited number of parameters &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick']); + ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','threadedon','threadedoff','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions']); + if ($ENV{'form.discsymb'}) { + my $symb = $ENV{'form.discsymb'}; + my $readkey = $symb.'_read'; + my %readinghash = (); + my $chgcount = 0; + %readinghash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$readkey],$ENV{'user.domain'},$ENV{'user.name'}); + foreach my $key (keys %ENV) { + if ($key =~ m/^form\.postunread_(\d+)/) { + if ($readinghash{$readkey} =~ /\.$1\./) { + $readinghash{$readkey} =~ s/\.$1\.//; + $chgcount ++; + } + } elsif ($key =~ m/^form\.postread_(\d+)/) { + unless ($readinghash{$readkey} =~ /\.$1\./) { + $readinghash{$readkey} .= '.'.$1.'.'; + $chgcount ++; + } + } + } + if ($chgcount > 0) { + &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'}); + } + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); + my $previous=$ENV{'form.previous'}; + my $feedurl = &Apache::lonnet::clutter($url); + &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'
','0','0','',$previous,'','','',); + return OK; + } + if ($ENV{'form.allversions'}) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions', + '',''); + $r->print (< + +Post Versions + + +$bodytag +END + 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 ($symb,$idx)=split(/\:\:\:/,$ENV{'form.allversions'}); + my $ressymb=$symb; + unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) { + $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|; + } + if ($idx > 0) { + my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + if ($contrib{$idx.':history'}) { + my $attachmenturls = $contrib{$idx.':attachmenturl'}; + my @postversions = (); + my %messages = (); + my %subjects = (); + if ($contrib{$idx.':history'} =~ m/:/) { + @postversions = split/:/,$contrib{$idx.':history'}; + } else { + @postversions = ("$contrib{$idx.':history'}"); + } + if (@postversions > 0) { + &get_post_versions(\%messages,$contrib{$idx.':message'}); + &get_post_versions(\%subjects,$contrib{$idx.':subject'}); + push @postversions,$contrib{$idx.':timestamp'}; + my $screenname=&Apache::loncommon::screenname( + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + my $plainname=&Apache::loncommon::nickname( + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + my $sender=&Apache::loncommon::aboutmewrapper( + $plainname, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}).' ('. + $contrib{$idx.':sendername'}.' at '. + $contrib{$idx.':senderdomain'}.')'; + if ($contrib{$idx.':anonymous'}) { + $sender.=' ['.&mt('anonymous').'] '.$screenname; + } + $r->print(''.$sender.'
    '); + for (my $i=0; $i<@postversions; $i++) { + my ($timesent,$message,$subject,$attachmsg); + $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]); + $message=&HTML::Entities::decode($messages{$i}); + $subject=&HTML::Entities::decode($subjects{$i}); + $message=~s/\n/\
    /g; + $message=&Apache::lontexconvert::msgtexconverted($message); + $subject=~s/\n/\
    /g; + $subject=&Apache::lontexconvert::msgtexconverted($subject); + if ($attachmenturls) { + my %attachments = (); + my %currattach = (); + &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,\%attachments,\%currattach); + } + if ($attachmsg) { + $attachmsg = '
    Attachments:'.$attachmsg.'
    '; + } else { + $attachmsg = '
    '; + } + $r->print (<$subject, $timesent
    +$message
    +$attachmsg +END + } + $r->print('
'); + } + } + } + return OK; + } if ($ENV{'form.posterlist'}) { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; @@ -1911,19 +2688,36 @@ ENDREDIR my $symb=$ENV{'form.modifydisp'}; my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); my $previous=$ENV{'form.previous'}; - my ($dispchg,$markchg) = split/_/,$ENV{'form.changes'}; + my ($dispchgA,$dispchgB,$markchg,$toggchg) = split/_/,$ENV{'form.changes'}; my $feedurl = &Apache::lonnet::clutter($url); # backward compatibility (bulletin boards used to be 'wrapped') if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { $feedurl=~s|^/adm/wrapper||; } - &print_display_options($r,$symb,$previous,$dispchg,$markchg,$feedurl); + &print_display_options($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl); return OK; - } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) { + } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || $ENV{'form.onlyunmark'} || $ENV{'form.toggoff'} || $ENV{'form.toggon'} ) { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; my $previous=$ENV{'form.previous'}; my ($map,$ind,$url); + if ( ($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) { +# ------------------------------ Modify setting for read/unread toggle for each post + my $symb=$ENV{'form.toggoff'}?$ENV{'form.toggoff'}:$ENV{'form.toggon'}; + my $ressymb = $symb; + ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); + unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) { + $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|; + } + my %discinfo = (); + my $toggkey = $ressymb.'_readtoggle'; + if ($ENV{'form.toggon'}) { + $discinfo{$toggkey} = 1; + } elsif ($ENV{'form.toggoff'}) { + $discinfo{$toggkey} = 0; + } + &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'}); + } if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) { # ---------------------- Modify setting for identification of 'NEW' posts in this discussion my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'}; @@ -1946,9 +2740,16 @@ ENDREDIR } &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'}); } - if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) { + if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ) { # ----------------------------------------------------------------- Modify display setting for this discussion - my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'}; + my $symb; + if ($ENV{'form.allposts'}) { + $symb = $ENV{'form.allposts'}; + } elsif ($ENV{'form.onlyunread'}) { + $symb = $ENV{'form.onlyunread'}; + } else { + $symb = $ENV{'form.onlyunmark'}; + } my $ressymb = $symb; ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) { @@ -1957,19 +2758,22 @@ ENDREDIR my %discinfo = (); if ($ENV{'form.allposts'}) { $discinfo{$ressymb.'_showonlyunread'} = 0; + $discinfo{$ressymb.'_showonlyunmark'} = 0; } elsif ($ENV{'form.onlyunread'}) { $discinfo{$ressymb.'_showonlyunread'} = 1; + } else { + $discinfo{$ressymb.'_showonlyunmark'} = 1; } &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'}); } - if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) { + if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ||($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) { &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'
','0','0','',$previous); } else { &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'
','0','0'); } return OK; } elsif ($ENV{'form.markread'}) { -# ----------------------------------------------------------------- Mark new posts as read +# ----------------------------------------------------------------- Mark new posts not NEW &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; my $symb=$ENV{'form.markread'}; @@ -2074,6 +2878,38 @@ ENDREDIR $r->content_type('text/html'); $r->send_http_header; &show_preview($r); + } elsif ($ENV{'form.attach'}) { +# -------------------------------------------------------- Work on attachments + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']); + my @currnewattach = (); + my @currdelold = (); + my @keepold = (); + &process_attachments(\@currnewattach,\@currdelold,\@keepold); + if (exists($ENV{'form.addnewattach.filename'})) { + unless (length($ENV{'form.addnewattach'})>131072) { + my $subdir = 'feedback/'.$ENV{'form.timestamp'}; + my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir); + push @currnewattach, $newattachment; + } + } + my $attachmenturls = ''; + my $idx = $ENV{'form.idx'}; + my $symb = $ENV{'form.attach'}; + if ($idx) { + my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + $attachmenturls = $contrib{$idx.':attachmenturl'}; + } + &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,$attachmenturls); + } elsif ($ENV{'form.chgreads'}) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ENV{'form.chgreads'}); + &redirect_back($r,&Apache::lonnet::clutter($url), + &mt('Changed read status').'
','0','0'); } else { # ------------------------------------------------------------- Normal feedback my $feedurl=$ENV{'form.postdata'}; @@ -2091,6 +2927,8 @@ ENDREDIR $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0]; my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); $feedurl=&Apache::lonnet::clutter($url); + } elsif ($ENV{'form.origpage'}) { + $symb=""; } else { $symb=&Apache::lonnet::symbread($feedurl); } @@ -2127,7 +2965,7 @@ ENDREDIR unless ($ENV{'form.sendit'}) { my $options=&screen_header($feedurl); if ($options) { - &mail_screen($r,$feedurl,$options); + &mail_screen($r,$feedurl,$options); } else { &fail_redirect($r,$feedurl); } @@ -2149,7 +2987,22 @@ ENDREDIR &Apache::lonnet::delenv('allowed.vgr'); # Get attachments, if any, and not too large my $attachmenturl=''; - if ($ENV{'form.attachment.filename'}) { + if (($ENV{'form.origpage'}) || ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'})) { + my ($symb,$idx); + if ($ENV{'form.replydisc'}) { + ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'}); + } elsif ($ENV{'form.editdisc'}) { + ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'}); + } elsif ($ENV{'form.origpage'}) { + $symb = $ENV{'form.symb'}; + } + my @currnewattach = (); + my @deloldattach = (); + my @keepold = (); + &process_attachments(\@currnewattach,\@deloldattach,\@keepold); + $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|; + $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx); + } elsif ($ENV{'form.attachment.filename'}) { unless (length($ENV{'form.attachment'})>131072) { $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback'); }