--- loncom/interface/lonfeedback.pm 2003/11/03 23:23:34 1.66 +++ loncom/interface/lonfeedback.pm 2004/02/11 22:14:10 1.76 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.66 2003/11/03 23:23:34 www Exp $ +# $Id: lonfeedback.pm,v 1.76 2004/02/11 22:14:10 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -55,6 +55,10 @@ use Apache::lonlocal; sub list_discussion { my ($mode,$status,$symb)=@_; + &Apache::lonnet::logthis("status is $status"); + if (!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER')) { + return ''; + } my $discussiononly=0; if ($mode eq 'board') { $discussiononly=1; } unless ($ENV{'request.course.id'}) { return ''; } @@ -69,16 +73,52 @@ sub list_discussion { unless ($symb) { return ''; } my $seeid=&Apache::lonnet::allowed('rin',$crs); my $viewgrades=&Apache::lonnet::allowed('vgr',$crs); - my %discussionitems=(); - my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, + my @discussionitems=(); + # backward compatibility (bulletin boards used to be 'wrapped') + my $ressymb=$symb; + if ($mode eq 'board') { + $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|; + } + my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'}, $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + my $visible=0; + my @depth=(); + my @original=(); + my @index=(); + my @replies=(); + my %alldiscussion=(); + my $maxdepth=0; + + my $target=''; + unless ($ENV{'browser.interface'} eq 'textual' || + $ENV{'environment.remote'} eq 'off' ) { + $target='target="LONcom"'; + } if ($contrib{'version'}) { for (my $id=1;$id<=$contrib{'version'};$id++) { my $idx=$id; my $hidden=($contrib{'hidden'}=~/\.$idx\./); my $deleted=($contrib{'deleted'}=~/\.$idx\./); + my $origindex='0.'; + if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) { +# 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]; } + } else { +# this is an original message + $original[$idx]=0; + $depth[$idx]=0; + } + if ($replies[$depth[$idx]]) { + $replies[$depth[$idx]]++; + } else { + $replies[$depth[$idx]]=1; + } unless ((($hidden) && (!$seeid)) || ($deleted)) { + $visible++; my $message=$contrib{$idx.':message'}; $message=~s/\n/\
/g; $message=&Apache::lontexconvert::msgtexconverted($message); @@ -128,7 +168,7 @@ sub list_discussion { $ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { $sender.=' '.&mt('Reply').''; + $symb.':::'.$idx.'" '.$target.'>'.&mt('Reply').''; } } else { if ($screenname) { @@ -140,7 +180,14 @@ sub list_discussion { $vgrlink=&Apache::loncommon::submlink('Submissions', $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb); } - $discussionitems{$idx}='

'.$sender.' '.$vgrlink.' ('. +#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); + } + $alldiscussion{$thisindex}=$idx; + $index[$idx]=$thisindex; + $discussionitems[$idx]='

'.$sender.' '.$vgrlink.' ('. localtime($contrib{$idx.':timestamp'}). '):

'.$message. '

'; @@ -148,16 +195,36 @@ sub list_discussion { } } } - my $discussion='
'; - foreach (sort { $a <=> $b } keys %discussionitems) { - $discussion.=$discussionitems{$_}; + my $discussion=''; + if ($visible) { +# Print a the discusssion + $discussion.=''; + if ($visible>2) { + my $colspan=$maxdepth+1; + $discussion.=''; + } + + foreach (sort { $a <=> $b } keys %alldiscussion) { + $discussion.="\n"; + my $thisdepth=$depth[$alldiscussion{$_}]; + for (1..$thisdepth) { + $discussion.=''; + } + my $colspan=$maxdepth-$thisdepth+1; + $discussion.=""; + } + $discussion.='
'. + ''.&mt('Threaded View').'  '. + ''.&mt('Chronological View').''. + '
   ".$discussionitems[$alldiscussion{$_}]. + "
'; } if ($discussiononly) { $discussion.=(< - +
Note: in anonymous discussion, your name is visible only to @@ -169,7 +236,16 @@ Attachment (128 KB max size): ENDDISCUSS $discussion.=&generate_preview_button(); - } + } else { + if (&Apache::lonnet::allowed('pch', + $ENV{'request.course.id'}. + ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { + $discussion.='
'. + ''. + &mt('Post Discussion').'
'; + } + } return $discussion; } @@ -179,7 +255,20 @@ sub mail_screen { '','onLoad="window.focus();"'); my $title=&Apache::lonnet::gettitle($feedurl); if (!$title) { $title = $feedurl; } + my $quote=''; + if ($ENV{'form.replydisc'}) { + my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'}); + my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) { + my $message=$contrib{$idx.':message'}; + $message=~s/\n/\
/g; + $quote='
'.&Apache::lontexconvert::msgtexconverted($message).'
'; + } + } my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); + my $send=&mt('Send'); $r->print(< @@ -234,8 +323,10 @@ $bodytag
+ Please check at least one of the following feedback types: $options
+$quote

My question/comment/feedback:

$latexHelp @@ -246,7 +337,7 @@ Attachment (128 KB max size):

- +

ENDDOCUMENT @@ -255,12 +346,13 @@ $r->print(&generate_preview_button().'print (< Feedback not sent - Sorry, no recipients ... @@ -271,13 +363,14 @@ ENDFAILREDIR sub redirect_back { my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status) = @_; + if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' }; $r->print (< Feedback sent - $typestyle @@ -293,6 +386,7 @@ ENDREDIR sub no_redirect_back { my ($r,$feedurl) = @_; $r->print (< Feedback not sent ENDNOREDIR @@ -303,7 +397,6 @@ ENDNOREDIR $r->print (< - Sorry, no feedback possible on this resource ... @@ -342,16 +435,17 @@ sub screen_header { if (&Apache::lonnet::allowed('pch', $ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { - $discussoptions=' '. + $discussoptions=' '. &mt('Contribution to course discussion of resource'); $discussoptions.='
'. &mt('Anonymous contribution to course discussion of resource'). ' ('.&mt('name only visible to course faculty').')'; } } - if ($msgoptions) { $msgoptions='

'.&mt('Sending Messages').'

'.$msgoptions; } + if ($msgoptions) { $msgoptions='

'.&mt('Sending Messages').'

'.$msgoptions; } if ($discussoptions) { - $discussoptions='

'.&mt('Discussion Contributions').'

'.$discussoptions; } + $discussoptions='

'.&mt('Discussion Contributions').'

'.$discussoptions; } return $msgoptions.$discussoptions; } @@ -576,10 +670,11 @@ onClick="this.form.comment.value=documen ENDPREVIEW } + sub handler { my $r = shift; if ($r->header_only) { - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK; } @@ -587,11 +682,11 @@ sub handler { # --------------------------- Get query string for limited number of parameters &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['hide','unhide','deldisc','postdata','preview','replydisc']); + ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff']); if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) { # ----------------------------------------------------------------- Hide/unhide - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'}; @@ -619,9 +714,23 @@ sub handler { &redirect_back($r,&Apache::lonnet::clutter($url), &mt('Changed discussion status').'
','0','0'); + } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + if ($ENV{'form.threadedon'}) { + &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'}); + &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on'); + } else { + &Apache::lonnet::del('environment',['threadeddiscussion']); + &Apache::lonnet::delenv('environment\.threadeddiscussion'); + } + my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'}; + my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); + &redirect_back($r,&Apache::lonnet::clutter($url), + &mt('Changed discussion view mode').'
','0','0'); } elsif ($ENV{'form.deldisc'}) { # --------------------------------------------------------------- Hide for good - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; my $entry=$ENV{'form.deldisc'}; @@ -648,6 +757,8 @@ sub handler { &mt('Changed discussion status').'
','0','0'); } elsif ($ENV{'form.preview'}) { # -------------------------------------------------------- User wants a preview + $r->content_type('text/html'); + $r->send_http_header; &show_preview($r); } else { # ------------------------------------------------------------- Normal feedback @@ -676,10 +787,13 @@ sub handler { if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) { unless ($symb) { $goahead=0; } } - + # backward compatibility (bulltin boards used to be 'wrapped') + if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { + $feedurl=~s|^/adm/wrapper||; + } if ($goahead) { # Go ahead with feedback, no ambiguous reference - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; if (