--- loncom/interface/lonfeedback.pm 2004/07/27 14:29:03 1.99.2.2 +++ loncom/interface/lonfeedback.pm 2004/08/04 18:04:57 1.113 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.99.2.2 2004/07/27 14:29:03 albertel Exp $ +# $Id: lonfeedback.pm,v 1.113 2004/08/04 18:04:57 raeburn 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"); @@ -72,6 +73,7 @@ sub list_discussion { if ($mode eq 'board') { $discussiononly=1; } unless ($ENV{'request.course.id'}) { return ''; } my $crs='/'.$ENV{'request.course.id'}; + my $cid=$ENV{'request.course.id'}; if ($ENV{'request.course.sec'}) { $crs.='_'.$ENV{'request.course.sec'}; } @@ -80,7 +82,9 @@ sub list_discussion { $symb=&Apache::lonnet::symbread(); } unless ($symb) { return ''; } - + my %usernamesort = (); + my %namesort =(); + my %subjectsort = (); # backward compatibility (bulletin boards used to be 'wrapped') my $ressymb=$symb; if ($mode eq 'board') { @@ -92,19 +96,31 @@ 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 %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey],$ENV{'user.domain'},$ENV{'user.name'}); + my $userpickkey = $ressymb.'_userpick'; + 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; my $visit = 0; my $newpostsflag = 0; + my @posters = split/\&/,$dischash{$userpickkey}; # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts. - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous']); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts','rolefilter','statusfilter','sectionpick','totposters']); + my $sortposts = $ENV{'form.sortposts'}; + my $rolefilter = $ENV{'form.rolefilter'}; + my $statusfilter = $ENV{'form.statusfilter'}; + my $sectionpick = $ENV{'form.sectionpick'}; + my $totposters = $ENV{'form.totposters'}; $previous = $ENV{'form.previous'}; if ($previous > 0) { $prevread = $previous; @@ -114,6 +130,34 @@ sub list_discussion { } } +# Get information about students and non-students in course for filtering display of posts + my %roleshash = (); + my %roleinfo = (); + if ($rolefilter) { + %roleshash = &Apache::lonnet::dump('nohist_userroles',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + foreach (keys %roleshash) { + my ($role,$uname,$udom,$sec) = split/:/,$_; + my ($end,$start) = split/:/,$roleshash{$_}; + my $now = time; + my $status = 'Active'; + if (($now < $start) || ($end > 0 && $now > $end)) { + $status = 'Expired'; + } + push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status; + } + my ($classlist) = &Apache::loncoursedata::get_classlist( + $ENV{'request.course.id'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + my $sec_index = &Apache::loncoursedata::CL_SECTION(); + my $status_index = &Apache::loncoursedata::CL_STATUS(); + while (my ($student,$data) = each %$classlist) { + my ($section,$status) = ($data->[$sec_index], + $data->[$status_index]); + push @{$roleinfo{$student}}, 'st:'.$section.':'.$status; + } + } + # Get discussion display default settings for user my %userenv = &Apache::lonnet::get('environment',['discdisplay','discmarkread'],$ENV{'user.domain'},$ENV{'user.name'}); my $discdisplay=$userenv{'discdisplay'}; @@ -137,6 +181,10 @@ sub list_discussion { $showonlyunread = $dischash{$showkey}; } + if (defined($dischash{$markkey})) { + $showunmark = $dischash{$markkey}; + } + if (defined($dischash{$visitkey})) { $visit = $dischash{$visitkey}; } @@ -146,6 +194,8 @@ sub list_discussion { my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs) && ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/)); my @discussionitems=(); + my %shown = (); + my @posteridentity=(); my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'}, $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); @@ -164,7 +214,7 @@ sub list_discussion { $ENV{'environment.remote'} eq 'off' ) { $target='target="LONcom"'; } - + my $now = time; $discinfo{$visitkey} = $visit; @@ -182,14 +232,21 @@ sub list_discussion { $newpostsflag = 1; } my $hidden=($contrib{'hidden'}=~/\.$idx\./); + my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./); my $deleted=($contrib{'deleted'}=~/\.$idx\./); my $origindex='0.'; - if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) { + 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 - $original[$idx]=$original[$contrib{$idx.':replyto'}]; - $depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1; - $origindex=$index[$contrib{$idx.':replyto'}]; - if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; } + $original[$idx]=$original[$contrib{$idx.':replyto'}]; + $depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1; + $origindex=$index[$contrib{$idx.':replyto'}]; + if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; } + } else { + $original[$idx]=0; + $depth[$idx]=0; + } } else { # this is an original message $original[$idx]=0; @@ -202,26 +259,55 @@ 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'} =~ /^/) { + 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); - my $subject=$contrib{$idx.':subject'}; + if ($idx > 0) { + if ($contrib{$idx.':subject'} =~ /^/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'}, @@ -231,6 +317,20 @@ sub list_discussion { $contrib{$idx.':senderdomain'}); my $sender=&mt('Anonymous'); +# Set up for sorting by subject + if ($contrib{$idx.':subject'} eq '') { + if (defined($subjectsort{'__No subject'})) { + push @{$subjectsort{'__No subject'}}, $idx; + } else { + @{$subjectsort{'__No subject'}} = ("$idx"); + } + } else { + if (defined($subjectsort{$contrib{$idx.':subject'}})) { + push @{$subjectsort{$contrib{$idx.':subject'}}}, $idx; + } else { + @{$subjectsort{$contrib{$idx.':subject'}}} = ("$idx"); + } + } if ((!$contrib{$idx.':anonymous'}) || ($seeid)) { $sender=&Apache::loncommon::aboutmewrapper( $plainname, @@ -242,14 +342,57 @@ sub list_discussion { $sender.=' ['.&mt('anonymous').'] '. $screenname; } - 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.=' '.&mt('Delete').''; + $ressymb.':::'.$idx; + if ($newpostsflag) { + $sender .= '&previous='.$prevread; + } + $sender .= '">'.&mt('Delete').''; } } else { if ($screenname) { $sender=''.$screenname.''; } +# Set up for sorting by domain, then username for anonymous + unless (defined($usernamesort{'__anon'})) { + %{$usernamesort{'__anon'}} = (); + } + if (defined($usernamesort{'__anon'}{'__anon'})) { + push @{$usernamesort{'__anon'}{'__anon'}}, $idx; + } else { + @{$usernamesort{'__anon'}{'__anon'}} = ("$idx"); + } +# Set up for sorting by last name, then first name for anonymous + unless (defined($namesort{'__anon'})) { + %{$namesort{'__anon'}} = (); + } + if (defined($namesort{'__anon'}{'__anon'})) { + push @{$namesort{'__anon'}{'__anon'}}, $idx; + } else { + @{$namesort{'__anon'}{'__anon'}} = ("$idx"); + } } if (&discussion_open($status) && &Apache::lonnet::allowed('pch', @@ -286,17 +447,74 @@ 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'}) { - $thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2); + if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) { + $thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2); } $alldiscussion{$thisindex}=$idx; - $index[$idx]=$thisindex; + $shown{$idx} = 0; + $index[$idx]=$thisindex; 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; + my $rolematch = ''; + my $skiptest = 1; + if ($totposters > 0) { + if (grep/^$poster$/,@posters) { + $shown{$idx} = 1; + } + } else { + if ($rolefilter) { + if ($rolefilter eq 'all') { + $rolematch = '([^:]+)'; + } else { + $rolematch = $rolefilter; + $skiptest = 0; + } + } + if ($sectionpick) { + if ($sectionpick eq 'all') { + $rolematch .= ':([^:]*)'; + } else { + $rolematch .= ':'.$sectionpick; + $skiptest = 0; + } + } + if ($statusfilter) { + if ($statusfilter eq 'all') { + $rolematch .= ':([^:]+)'; + } else { + $rolematch .= ':'.$statusfilter; + $skiptest = 0; + } + } + if ($skiptest) { + $shown{$idx} = 1; + } else { + foreach my $role (@{$roleinfo{$poster}}) { + if ($role =~ m/^$rolematch$/) { + $shown{$idx} = 1; + last; + } + } + } + } + } + unless ($notshown{$idx} == 1) { if ($prevread > 0 && $prevread <= $posttime) { $newitem{$idx} = 1; $discussionitems[$idx] .= ' @@ -311,8 +529,29 @@ 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.'); + 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]).' '; + } + } } } } @@ -328,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'}; @@ -354,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; @@ -367,7 +629,21 @@ sub list_discussion { # Print the discusssion if ($outputtarget ne 'tex') { my $colspan=$maxdepth+1; - $discussion.=''; + $discussion.= qq| + + |; + $discussion.='
'; $discussion .='
'. ''; if ($visible>2) { @@ -381,11 +657,23 @@ sub list_discussion { if ($newpostsflag) { $discussion .= '&previous='.$prevread; } - $discussion .='">'.&mt('Chronological View').'  '; - } + $discussion .='">'.&mt('Chronological View').'   + '.&mt('Sorting/Filtering options').'  '; + } else { + $discussion .= ''; if ($newpostsflag) { if (!$markondisp) { - $discussion .=''; } @@ -409,11 +697,46 @@ 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 + my @showposts = (); + if ($sortposts eq 'descdate') { + @showposts = (sort { $b <=> $a } keys %alldiscussion); + } elsif ($sortposts eq 'thread') { + @showposts = (sort { $a <=> $b } keys %alldiscussion); + } elsif ($sortposts eq 'subject') { + foreach (sort keys %subjectsort) { + push @showposts, @{$subjectsort{$_}}; + } + } elsif ($sortposts eq 'username') { + foreach my $domain (sort keys %usernamesort) { + foreach (sort keys %{$usernamesort{$domain}}) { + push @showposts, @{$usernamesort{$domain}{$_}}; + } + } + } elsif ($sortposts eq 'lastfirst') { + foreach my $last (sort keys %namesort) { + foreach (sort keys %{$namesort{$last}}) { + push @showposts, @{$namesort{$last}{$_}}; + } + } + } else { + $sortposts = 'ascdate'; + @showposts = (sort { $a <=> $b } keys %alldiscussion); } - foreach (sort { $a <=> $b } keys %alldiscussion) { - unless ($notshown{$alldiscussion{$_}} eq '1') { + foreach (@showposts) { + unless (($sortposts eq 'thread') || ($sortposts eq 'ascdate' && $ENV{'environment.threadeddiscussion'})) { + $alldiscussion{$_} = $_; + } + unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) { if ($outputtarget ne 'tex') { $discussion.="\n"; } else { @@ -439,7 +762,7 @@ sub list_discussion { $threadinsert='
Reply: '.$thisdepth.''; } $discussionitems[$alldiscussion{$_}]=~s/<\/td>]*)>/$threadinsert<\/td> +END + if ($dischash{$toggkey}) { + my $storebutton = &mt('Store read/unread changes'); + $discussion.=''; + } + $discussion .= (<
'; + } + $discussion .=''.&mt('Export').'?  '.&mt('Mark new posts as read').'  '; + $discussion .=''.&mt('Mark NEW posts no longer new').'  '; } else { $discussion .= ' 
/; - $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 @@ -453,7 +776,7 @@ sub list_discussion { } if ($outputtarget ne 'tex') { my $colspan=$maxdepth+1; - $discussion .= < @@ -464,48 +787,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 { @@ -519,41 +899,175 @@ ENDDISCUSS ''. &mt('Post 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();"'); + '','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 ($contrib{$idx.':history'}) { + if ($contrib{$idx.':history'} =~ /:/) { + my @oldversions = split/:/,$contrib{$idx.':history'}; + $numoldver = @oldversions; + } else { + $numoldver = 1; + } + } + 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'} =~ /^/g; + $quote='
'.&Apache::lontexconvert::msgtexconverted($message).'
'; + if ($idx > 0) { + if ($contrib{$idx.':subject'} =~ /^&"'); + } else { + $attachmenturls = $contrib{$idx.':attachmenturl'}; + if ($contrib{$idx.':message'} =~ /^/) { + my %versions = (); + &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver); + $comment = $versions{$numoldver}; + } else { + $comment = &HTML::Entities::encode($contrib{$idx.':message'},'<>&"'); + } + if ($contrib{$idx.':subject'} =~ //) { + my %versions = (); + &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver); + $subject = $versions{$numoldver}; + } else { + $subject = &HTML::Entities::encode($contrib{$idx.':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 $send=&mt('Send'); - $r->print(<print(< The LearningOnline Network with CAPA @@ -603,6 +1117,8 @@ $htmlheader alert('Please check a feedback type.'); } } + $anonchk + $anonscript //--> @@ -612,7 +1128,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 @@ -621,24 +1148,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||; @@ -658,54 +1243,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) { @@ -1133,8 +2444,204 @@ sub handler { # --------------------------- Get query string for limited number of parameters &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes','navmaps','navurl']); - if ($ENV{'form.navmaps'}) { + ['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; + my $symb=$ENV{'form.posterlist'}; + my $sortposts = $ENV{'form.sortposts'}; + my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); + my $previous=$ENV{'form.previous'}; + 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_showposters($r,$symb,$previous,$feedurl,$sortposts); + return OK; + } + if ($ENV{'form.userpick'}) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my $symb=$ENV{'form.userpick'}; + my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); + my $previous=$ENV{'form.previous'}; +# backward compatibility (bulletin boards used to be 'wrapped') + my $ressymb=$symb; + unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) { + $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|; + } + my $sort=$ENV{'form.sortposts'}; + my @posters = (); + if (ref($ENV{'form.stuinfo'}) eq 'ARRAY') { + @posters = $ENV{'form.stuinfo'}; + } else { + $posters[0] = $ENV{'form.stuinfo'}; + } + my $numpicks = @posters; + if (defined($ENV{'form.userpick'})) { + my %discinfo = (); + $discinfo{$ressymb.'_userpick'} = join('&',@posters); + &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'}); + } + 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||; + } + &redirect_back($r,$feedurl,&mt('Changed sort/filter').'
','0','0','',$previous,$sort,'','','',$numpicks); + return OK; + } + if ($ENV{'form.applysort'}) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my $symb=$ENV{'form.applysort'}; + my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); + my $previous=$ENV{'form.previous'}; + my $sort = $ENV{'form.sortposts'}; + my $rolefilter = $ENV{'form.rolefilter'}; + my $statusfilter = $ENV{'form.statusfilter'}; + my $secpick = $ENV{'form.sectionpick'}; + 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||; + } + &redirect_back($r,$feedurl,&mt('Changed sort/filter').'
','0','0','',$previous,$sort,$rolefilter,$statusfilter,$secpick); + return OK; + } elsif ($ENV{'form.sortfilter'}) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my $symb=$ENV{'form.sortfilter'}; + my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); + my $previous=$ENV{'form.previous'}; + 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_sortfilter_options($r,$symb,$previous,$feedurl); + return OK; + } elsif ($ENV{'form.navmaps'}) { my %discinfo = (); my @resources = (); if ($ENV{'form.navmaps'} =~ /:/) { @@ -1187,19 +2694,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'}; @@ -1222,9 +2746,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|) { @@ -1233,19 +2764,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'}; @@ -1276,13 +2810,27 @@ ENDREDIR my $currenthidden=$contrib{'hidden'}; + my $currentstudenthidden=$contrib{'studenthidden'}; + + 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); if ($ENV{'form.hide'}) { $currenthidden.='.'.$idx.'.'; + unless ($seeid) { + $currentstudenthidden.='.'.$idx.'.'; + } } else { $currenthidden=~s/\.$idx\.//g; } my %newhash=('hidden' => $currenthidden); + if ( ($ENV{'form.hide'}) && (!$seeid) ) { + $newhash{'studenthidden'} = $currentstudenthidden; + } &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'}, $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, @@ -1336,6 +2884,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'}; @@ -1349,6 +2929,12 @@ ENDREDIR $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0]; my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); $feedurl=&Apache::lonnet::clutter($url); + } elsif ($ENV{'form.editdisc'}) { + $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); } @@ -1385,7 +2971,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); } @@ -1407,7 +2993,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'); }