--- loncom/interface/lonfeedback.pm 2004/06/28 16:41:08 1.96 +++ 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.96 2004/06/28 16:41:08 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"); @@ -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]).' '; + } + } } } } @@ -325,54 +564,87 @@ sub list_discussion { my $color = &Apache::loncommon::designparm($function.'.tabbg', $ENV{'user.domain'}); my %lt = &Apache::lonlocal::texthash( - 'cuse' => 'Current settings for this 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"', - 'chgt' => 'Change to ', + '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 $displink = '/adm/feedback?onlyunread='.$ressymb; - my $marklink = '/adm/feedback?markondisp='.$ressymb; + my $toggchange = $lt{'toggon'}; + my $chglink = '/adm/feedback?modifydisp='.$ressymb; + my $displinkA = 'onlyunread'; + my $displinkB = 'onlyunmark'; + my $marklink = 'markondisp'; + my $togglink = 'toggon'; if ($markondisp) { $currmark = $lt{'ondisp'}; $markchange = $lt{'onmark'}; - $marklink = '/adm/feedback?markonread='.$ressymb; - if ($newpostsflag) { - $marklink .= '&previous='.$prevread; - } + $marklink = 'markonread'; } if ($showonlyunread) { $currdisp = $lt{'unread'}; $dispchange = $lt{'allposts'}; - $displink = '/adm/feedback?allposts='.$ressymb; + $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='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink; + if ($newpostsflag) { - $displink .= '&previous='.$prevread; + $chglink .= '&previous='.$prevread; } if ($visible) { # Print the discusssion if ($outputtarget ne 'tex') { - $discussion.=''; - my $colspan=$maxdepth+1; - $discussion .= ''. - ' + +
'. - ''. - ''. - ''. - ''. - '
'.$lt{'cuse'}.'    '.$lt{'chgt'}.'
'.$lt{'disa'}.': '.$currdisp.'    '.$dispchange.'
'.$lt{'npce'}.': '.$currmark.'    '.$markchange.'
'. + my $colspan=$maxdepth+1; + $discussion.= qq| + + |; + $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) { @@ -413,15 +697,48 @@ 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 .= '
'; } - foreach (sort { $a <=> $b } keys %alldiscussion) { - unless ($notshown{$alldiscussion{$_}} eq '1') { + +# 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 (@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 { - $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'; } my $thisdepth=$depth[$alldiscussion{$_}]; if ($outputtarget ne 'tex') { @@ -443,40 +760,126 @@ sub list_discussion { $threadinsert='
Reply: '.$thisdepth.''; } $discussionitems[$alldiscussion{$_}]=~s/<\/td>]*)>/$threadinsert<\/td>
'. ''; if ($visible>2) { $discussion.=''; - } + $discussion .='">'.&mt('Chronological View').'   + '.&mt('Sorting/Filtering options').'  '; + } else { + $discussion .= ''; if ($newpostsflag) { if (!$markondisp) { - $discussion .=''; } @@ -398,11 +682,11 @@ sub list_discussion { } $discussion .= '
'. @@ -385,11 +657,23 @@ sub list_discussion { if ($newpostsflag) { $discussion .= '&previous='.$prevread; } - $discussion .='">'.&mt('Chronological View').'  '; + } + $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 - # 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') { - $discussion.='


'; - } + my $colspan=$maxdepth+1; + $discussion .= < +
+ + + +END + if ($dischash{$toggkey}) { + my $storebutton = &mt('Store read/unread changes'); + $discussion.=''; + } + $discussion .= (< +
+ + + + + + + + +
+ $lt{'cuse'}:  +END + if ($newpostsflag) { + $discussion .= + '1. '.$lt{'disp'}.' - '.$currdisp.'  2. '.$lt{'nolo'}.' - '.$currmark.''; + if ($dischash{$toggkey}) { + $discussion .= '  3. '.$lt{'togg'}.' - '.$currtogg.''; + } + } else { + if ($dischash{$toggkey}) { + $discussion .= '1. '.$lt{'disp'}.' - '.$currdisp.' 2. '.$lt{'togg'}.' - '.$currtogg.''; + } else { + $discussion .= + $lt{'disp'}.' - '.$currdisp.''; + } + } + $discussion .= <  + $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 { @@ -490,46 +893,175 @@ ENDDISCUSS ''. &mt('Post Discussion').''; } - } + } } - 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();"'); + '','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 $onsubmit=''; - if ((&Apache::lonhtmlcommon::htmlareabrowser()) && - (!&Apache::lonhtmlcommon::htmlareablocked())) { - $onsubmit='document.mailform.onsubmit();'; - } my $send=&mt('Send'); - $r->print(<print(< The LearningOnline Network with CAPA @@ -571,12 +1103,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 //--> @@ -586,7 +1122,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 @@ -595,23 +1142,566 @@ $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,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_; + # backward compatibility (bulletin boards used to be 'wrapped') + if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { + $feedurl=~s|^/adm/wrapper||; + } + + my $function = &Apache::loncommon::get_users_function(); + my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg', + $ENV{'user.domain'}); + my $bodytag=&Apache::loncommon::bodytag('Discussion options', + '',''); + + my %lt = &Apache::lonlocal::texthash( + 'dido' => 'Discussion display options', + 'pref' => 'Display Preference', + 'curr' => 'Current setting ', + 'actn' => 'Action', + '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 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 not NEW ', + 'toggon' => 'Shown', + 'toggoff' => 'Not shown', + 'disa' => 'Posts displayed?', + '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 any of the discussion settings', + 'ywbr' => 'You will be returned to the previous page if you click OK.' + ); + + 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 ($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 +
+$lt{'sdpf'}
$lt{'prca'}
  1. $lt{'whpo'}
  2. $lt{'unwh'}
  3. $lt{'wipa'}
+
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
$lt{'pref'}$lt{'curr'}$lt{'actn'}?
$lt{'disa'}$lt{$discdisp} $lt{'chgt'} "$dispchangeA" +
+  $lt{'chgt'} "$dispchangeB" +
$lt{'npmr'}$lt{$discmark}$lt{'chgt'} "$markchange"
$lt{'dotm'}$lt{$disctogg}$lt{'chgt'} "$toggchange"
+
+
+
+
+ + + + + + +
+
+
+ + +END + return; +} + +sub print_sortfilter_options { + my ($r,$symb,$previous,$feedurl) = @_; + # backward compatibility (bulletin boards used to be 'wrapped') + if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { + $feedurl=~s|^/adm/wrapper||; + } + my @sections = (); + my $section_sel = ''; + my $numsections = 0; + my $numvisible = 5; + 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(); + my %sectioncount = (); + while (my ($student,$data) = each %$classlist) { + my ($section,$status) = ($data->[$sec_index], + $data->[$status_index]); + unless ($section eq '' || $section =~ /^\s*$/) { + if (!defined($sectioncount{$section})) { + $sectioncount{$section} = 1; + $numsections ++; + } else { + $sectioncount{$section} ++; + } + } + } + + if ($ENV{'request.course.sec'} !~ /^\s*$/) { + @sections = ($ENV{'request.course.sec'}); + $numvisible = 1; + } else { + @sections = sort {$a cmp $b} keys(%sectioncount); + unshift(@sections,'all'); # Put 'all' at the front of the list + if ($numsections < 4) { + $numvisible = $numsections + 1; + } + } + foreach (@sections) { + $section_sel .= "