--- loncom/interface/lonfeedback.pm 2004/06/03 20:28:22 1.90 +++ loncom/interface/lonfeedback.pm 2004/08/31 18:33:44 1.99.2.5 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.90 2004/06/03 20:28:22 albertel Exp $ +# $Id: lonfeedback.pm,v 1.99.2.5 2004/08/31 18:33:44 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,25 +37,36 @@ use Apache::lontexconvert(); use Apache::lonlocal; # must not have () use Apache::lonhtmlcommon(); -sub discussion_closed { +sub discussion_open { my ($status)=@_; - if (!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER' + if (defined($status) && + !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER' || $status eq 'OPEN')) { - return '1'; + return 0; } my $close=&Apache::lonnet::EXT('resource.0.discussend'); if (defined($close) && $close ne '' && $close < time) { - return '1' + return 0; } - return 0; + return 1; +} + +sub discussion_visible { + my ($status)=@_; + if (not &discussion_open($status)) { + my $hidden=&Apache::lonnet::EXT('resource.0.discusshide'); + if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden)) { + return 0; + } + } + return 1; } sub list_discussion { my ($mode,$status,$symb)=@_; - if (&discussion_closed($status)) { - return ''; - } + my $outputtarget=$ENV{'form.grade_target'}; + if (not &discussion_visible($status)) { return ''; } my @bgcols = ("#cccccc","#eeeeee"); my $discussiononly=0; if ($mode eq 'board') { $discussiononly=1; } @@ -259,7 +270,7 @@ sub list_discussion { $sender=''.$screenname.''; } } - if (!&discusion_closed($status) && + if (&discussion_open($status) && &Apache::lonnet::allowed('pch', $ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { @@ -314,78 +325,81 @@ 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', 'ondisp' => 'Once displayed', 'onmark' => 'Once marked read', 'disa' => 'Posts to be displayed', 'npce' => 'Posts cease to be marked "NEW"', - 'chgt' => 'Change to ', + 'chgt' => 'Change', + 'disp' => 'Display', + 'nolo' => 'Not new', ); my $currdisp = $lt{'allposts'}; my $currmark = $lt{'onmark'}; my $dispchange = $lt{'unread'}; my $markchange = $lt{'ondisp'}; - my $displink = '/adm/feedback?onlyunread='.$ressymb; - my $marklink = '/adm/feedback?markondisp='.$ressymb; + my $chglink = '/adm/feedback?modifydisp='.$ressymb; + my $displink = 'onlyunread'; + my $marklink = 'markondisp'; 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; + $displink = 'allposts'; } + + $chglink .= '&changes='.$displink.'_'.$marklink; if ($newpostsflag) { - $displink .= '&previous='.$prevread; + $chglink .= '&previous='.$prevread; } if ($visible) { # Print the discusssion - $discussion.=''; - my $colspan=$maxdepth+1; - $discussion .= ''. - ''; - + if ($outputtarget ne 'tex') { + my $colspan=$maxdepth+1; + $discussion.='
'. - ''. - ''. - ''. - ''. - '
'.$lt{'cuse'}.'    '.$lt{'chgt'}.'
'.$lt{'disa'}.': '.$currdisp.'    '.$dispchange.'
'.$lt{'npce'}.': '.$currmark.'    '.$markchange.'
'. - ''; - if ($visible>2) { - $discussion.=''; - } - if ($newpostsflag) { - if (!$markondisp) { - $discussion .=''; - } - } else { - $discussion .= ''; - } - $discussion .= '
'. - ''.&mt('Threaded View').'  '. - ''.&mt('Chronological View').'  '.&mt('Mark new posts as read').'  '; - } else { - $discussion .= '  
'; + $discussion .=''; + } else { + $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.'}'; + } my $numhidden = keys %notshown; if ($numhidden > 0) { my $colspan = $maxdepth+1; @@ -400,18 +414,79 @@ sub list_discussion { } foreach (sort { $a <=> $b } keys %alldiscussion) { unless ($notshown{$alldiscussion{$_}} eq '1') { - $discussion.="\n"; + if ($outputtarget ne 'tex') { + $discussion.="\n"; + } else { + $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'; + } my $thisdepth=$depth[$alldiscussion{$_}]; - for (1..$thisdepth) { - $discussion.=''; - } + if ($outputtarget ne 'tex') { + for (1..$thisdepth) { + $discussion.=''; + } + } my $colspan=$maxdepth-$thisdepth+1; - $discussion.=''; + } else { + #cleanup block + $discussionitems[$alldiscussion{$_}]=~s/]*)>/
'. + ''; + if ($visible>2) { + $discussion.=''; + } + if ($newpostsflag) { + if (!$markondisp) { + $discussion .=''; + } + } else { + $discussion .= ''; + } + $discussion .= '
'. + ''.&mt('Threaded View').'  '. + ''.&mt('Chronological View').'  '.&mt('Mark new posts as read').'  '; + } else { + $discussion .= '  
      '. + if ($outputtarget ne 'tex') { + $discussion.=''. $discussionitems[$alldiscussion{$_}]. '
/; + $discussionitems[$alldiscussion{$_}]=~s/]*)>]*)>/
/; + my $threadinsert=''; + if ($thisdepth > 0) { + $threadinsert='
Reply: '.$thisdepth.''; + } + $discussionitems[$alldiscussion{$_}]=~s/<\/td>]*)>/$threadinsert<\/td>
/; + $discussionitems[$alldiscussion{$_}]=~s/]+)>(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{$_}]); + } } } - $discussion.='


'; + if ($outputtarget ne 'tex') { + my $colspan=$maxdepth+1; + $discussion .= < + + + + + +
+ + + + +END + if ($newpostsflag) { + $discussion .= + ''; + } else { + $discussion .= + ''; + } + $discussion .= <  + + +
+ $lt{'cuse'}: 1. '.$lt{'disp'}.' - '.$currdisp.'  2. '.$lt{'nolo'}.' - '.$currmark.''.$lt{'disp'}.' - '.$currdisp.' + $lt{'chgt'}?
+
+ + + +

+END + } } if ($discussiononly) { $discussion.=(<Note: in anonymous discussion, your name is visible only to course faculty
Title: 

- +

Attachment (128 KB max size):

ENDDISCUSS - $discussion.=&generate_preview_button(); + if ($outputtarget ne 'tex') { + $discussion.=&generate_preview_button(); + } } else { - if (!&discussion_closed($status) && + if (&discussion_open($status) && &Apache::lonnet::allowed('pch', $ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { - $discussion.='
'. - ''. - &mt('Post Discussion').'
'; + if ($outputtarget ne 'tex') { + $discussion.='
'. + ''. + &mt('Post Discussion').'
'; + } } } return $discussion; @@ -516,7 +595,9 @@ $htmlheader } if (rec) { - document.mailform.onsubmit(); + if (typeof(document.mailform.onsubmit)=='function') { + document.mailform.onsubmit(); + } document.mailform.submit(); } else { alert('Please check a feedback type.'); @@ -540,7 +621,7 @@ $quote $latexHelp Title:

-

Attachment (128 KB max size): @@ -552,10 +633,140 @@ Attachment (128 KB max size): ENDDOCUMENT $r->print(&generate_preview_button(). -&Apache::lonhtmlcommon::htmlareaactive(). +&Apache::lonhtmlcommon::htmlareaselectactive('comment'). ''); } +sub print_display_options { + my ($r,$symb,$previous,$dispchg,$markchg,$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 identfied as "New."', + 'allposts' => 'All posts', + 'unread' => 'New posts only', + 'ondisp' => 'Once displayed', + 'onmark' => 'Once marked as read', + 'disa' => 'Posts displayed?', + 'npmr' => 'New posts cease to be identified as "New"?', + 'chgt' => 'Change to ', + 'mkdf' => 'Set to ', + 'yhni' => 'You have not indicated that you wish to change either of the discussion settings', + 'ywbr' => 'You will be returned to the previous page if you click OK.' + ); + + my $dispchange = $lt{'unread'}; + my $markchange = $lt{'ondisp'}; + my $currdisp = $lt{'allposts'}; + my $currmark = $lt{'onmark'}; + my $discdisp = 'allposts'; + my $discmark = 'onmark'; + + if ($dispchg eq 'allposts') { + $dispchange = $lt{'allposts'}; + $currdisp = $lt{'unread'}; + $discdisp = 'unread'; + } + + if ($markchg eq 'markonread') { + $markchange = $lt{'onmark'}; + $currmark = $lt{'ondisp'}; + $discmark = 'ondisp'; + } + $r->print(< + +$lt{'dido'} + + + +$bodytag +

+$lt{'sdpf'}
$lt{'prca'}
  1. $lt{'whpo'}
  2. $lt{'unwh'}
+
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + +
$lt{'pref'}$lt{'curr'}$lt{'actn'}?
$lt{'disa'}$lt{$discdisp} $lt{'chgt'} "$dispchange"
$lt{'npmr'}$lt{$discmark}$lt{'chgt'} "$markchange"
+
+
+
+
+ + + + +
+
+
+ + +END + return; +} + sub fail_redirect { my ($r,$feedurl) = @_; if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' }; @@ -568,6 +779,7 @@ sub fail_redirect { Sorry, no recipients ... +
Continue ENDFAILREDIR @@ -577,6 +789,11 @@ sub redirect_back { my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_; my $prevtag = ''; my $qrystr = ''; + # backward compatibility (bulletin boards used to be 'wrapped') + if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { + $feedurl=~s|^/adm/wrapper||; + } + if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' }; if ($previous > 0) { $qrystr = 'previous='.$previous; @@ -602,6 +819,7 @@ $typestyle
$prevtag
+
Continue ENDREDIR @@ -624,6 +842,7 @@ ENDNOREDIR Sorry, no feedback possible on this resource ... +
Continue ENDNOREDIRTWO @@ -656,7 +875,7 @@ sub screen_header { } } if ($ENV{'request.course.id'}) { - if (not &discussion_closed() && + if (&discussion_open() && &Apache::lonnet::allowed('pch', $ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { @@ -833,7 +1052,7 @@ sub send_msg { sub adddiscuss { my ($symb,$email,$anon,$attachmenturl,$subject)=@_; my $status=''; - if (not &discussion_closed() && + if (&discussion_open() && &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { @@ -901,7 +1120,7 @@ sub generate_preview_button { +onClick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" /> ENDPREVIEW } @@ -916,58 +1135,118 @@ 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']); - - if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) { -# ---------------------- Modify setting for identification of 'NEW' posts in this discussion - - &Apache::loncommon::content_type($r,'text/html'); - $r->send_http_header; - my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'}; - my $ressymb = $symb; - my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); - unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) { - $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|; - } - + &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'}) { my %discinfo = (); - my $lastkey = $ressymb.'_lastread'; - my $ondispkey = $ressymb.'_markondisp'; - if ($ENV{'form.markondisp'}) { - $discinfo{$lastkey} = time; - $discinfo{$ondispkey} = 1; - } elsif ($ENV{'form.markonread'}) { - if ( defined($ENV{'previous'}) ) { - $discinfo{$lastkey} = $ENV{'previous'}; + my @resources = (); + if ($ENV{'form.navmaps'} =~ /:/) { + @resources = split/:/,$ENV{'form.navmaps'}; + } else { + @resources = ("$ENV{'form.navmaps'}"); + } + my $numitems = @resources; + my $feedurl = '/adm/navmaps'; + if ($ENV{'form.navurl'}) { + $feedurl .= '?'.$ENV{'form.navurl'}; + } + my %lt = &Apache::lonlocal::texthash( + 'mnpa' => 'Marked "New" posts as read in a total of', + 'robb' => 'resources/bulletin boards.' + ); + foreach (@resources) { +# backward compatibility (bulletin boards used to be 'wrapped') + my $ressymb=$_; + if ($ressymb =~ m/bulletin___\d+___/) { + unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) { + $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|; + } } - $discinfo{$ondispkey} = 0; + my $lastkey = $ressymb.'_lastread'; + $discinfo{$lastkey} = time; } &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'}); - if ($ENV{'form.markondisp'}) { - &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'
','0','0'); - } else { - &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'
','0','0','',$ENV{'form.previous'}); - } + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + $r->print (< + +New posts marked as read + + + + + +$lt{'mnpa'} $numitems $lt{'robb'} +
+
+
Continue + + +ENDREDIR return OK; - } elsif (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) { -# ----------------------------------------------------------------- Modify display setting for this discussion + } elsif ($ENV{'form.modifydisp'}) { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'}; - my $ressymb = $symb; + my $symb=$ENV{'form.modifydisp'}; my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); - unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) { - $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|; + my $previous=$ENV{'form.previous'}; + my ($dispchg,$markchg) = 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||; } - my %discinfo = (); - if ($ENV{'form.allposts'}) { - $discinfo{$ressymb.'_showonlyunread'} = 0; - } elsif ($ENV{'form.onlyunread'}) { - $discinfo{$ressymb.'_showonlyunread'} = 1; + &print_display_options($r,$symb,$previous,$dispchg,$markchg,$feedurl); + return OK; + } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my $previous=$ENV{'form.previous'}; + my ($map,$ind,$url); + 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'}; + 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 $lastkey = $ressymb.'_lastread'; + my $ondispkey = $ressymb.'_markondisp'; + if ($ENV{'form.markondisp'}) { + $discinfo{$lastkey} = time; + $discinfo{$ondispkey} = 1; + } elsif ($ENV{'form.markonread'}) { + if ( $previous > 0 ) { + $discinfo{$lastkey} = $previous; + } + $discinfo{$ondispkey} = 0; + } + &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'}); + } + if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) { +# ----------------------------------------------------------------- Modify display setting for this discussion + my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'}; + 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 = (); + if ($ENV{'form.allposts'}) { + $discinfo{$ressymb.'_showonlyunread'} = 0; + } elsif ($ENV{'form.onlyunread'}) { + $discinfo{$ressymb.'_showonlyunread'} = 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'}) ) { + &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'); } - &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'}); - &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'
','0','0','',$ENV{'form.previous'}); return OK; } elsif ($ENV{'form.markread'}) { # ----------------------------------------------------------------- Mark new posts as read @@ -1088,7 +1367,7 @@ sub handler { if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) { unless ($symb) { $goahead=0; } } - # backward compatibility (bulltin boards used to be 'wrapped') + # backward compatibility (bulletin boards used to be 'wrapped') if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { $feedurl=~s|^/adm/wrapper||; }