--- loncom/interface/lonfeedback.pm 2004/04/28 23:59:53 1.79 +++ loncom/interface/lonfeedback.pm 2004/05/05 21:04:14 1.80 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.79 2004/04/28 23:59:53 raeburn Exp $ +# $Id: lonfeedback.pm,v 1.80 2004/05/05 21:04:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,7 +37,7 @@ use Apache::lontexconvert(); use Apache::lonlocal; sub list_discussion { - my ($mode,$status,$symb)=@_; + my ($mode,$status,$symb,$previous)=@_; # &Apache::lonnet::logthis("status is $status"); if (!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER' || $status eq 'OPEN')) { @@ -56,33 +56,43 @@ sub list_discussion { } unless ($symb) { return ''; } - my %dischash = &Apache::lonnet::restore($symb,'nohist_'.$ENV{'request.course.id'}.'_discuss',$ENV{'user.domain'},$ENV{'user.name'}); - my %readids = (); - my $showonlyunread; +# backward compatibility (bulletin boards used to be 'wrapped') + my $ressymb=$symb; + if ($mode eq 'board') { + unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) { + $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|; + } + } + +# Get discussion display settings for this discussion + my $lastkey = $ressymb.'_lastread'; + my $showkey = $ressymb.'_showonlyunread'; + my $visitkey = $ressymb.'_visit'; + my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey],$ENV{'user.domain'},$ENV{'user.name'}); + my $showonlyunread = 0; my $prevread = 0; + my $visit = 0; + my $newpostsflag = 0; - foreach my $key (keys %dischash) { - if ($key eq 'lastread') { - $prevread = $dischash{$key}; - } - if ($key eq 'showonlyunread') { - $showonlyunread = $dischash{$key}; - } else { - if ($dischash{$key} eq 'read') { - $readids{$key} = 1; - } - } + if ($previous > 0) { + $prevread = $previous; + } elsif (defined($dischash{$lastkey})) { + $prevread = $dischash{$lastkey}; + } + + if (defined($dischash{$showkey})) { + $showonlyunread = $dischash{$showkey}; } + if (defined($dischash{$visitkey})) { + $visit = $dischash{$visitkey}; + } + $visit ++; + my $seeid=&Apache::lonnet::allowed('rin',$crs); my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs) && ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/)); 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'}); @@ -92,6 +102,7 @@ sub list_discussion { my @index=(); my @replies=(); my %alldiscussion=(); + my %notshown = (); my $maxdepth=0; my $target=''; @@ -101,14 +112,19 @@ sub list_discussion { } my $now = time; - my %discinfo = ( - 'lastread' => $now, - ); - &Apache::lonnet::cstore(\%discinfo,$symb,'nohist_'.$ENV{'request.course.id'}.'_discuss',$ENV{'user.domain'},$ENV{'user.name'}); + my %discinfo = (); + $discinfo{$visitkey} = $visit; + $discinfo{$lastkey} = $now; + + &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'}); if ($contrib{'version'}) { for (my $id=1;$id<=$contrib{'version'};$id++) { my $idx=$id; + my $posttime = $contrib{$idx.':timestamp'}; + if ($prevread > 0 && $prevread <= $posttime) { + $newpostsflag = 1; + } my $hidden=($contrib{'hidden'}=~/\.$idx\./); my $deleted=($contrib{'deleted'}=~/\.$idx\./); my $origindex='0.'; @@ -172,13 +188,25 @@ sub list_discussion { if ($seeid) { if ($hidden) { $sender.=' '.&mt('Make Visible').''; + $ressymb.':::'.$idx; + if ($newpostsflag) { + $sender .= '&previous='.$prevread; + } + $sender .= '">'.&mt('Make Visible').''; } else { $sender.=' '.&mt('Hide').''; + $ressymb.':::'.$idx; + if ($newpostsflag) { + $sender .= '&previous='.$prevread; + } + $sender .= '">'.&mt('Hide').''; } $sender.=' '.&mt('Delete').''; + $ressymb.':::'.$idx; + if ($newpostsflag) { + $sender .= '&previous='.$prevread; + } + $sender .= '">'.&mt('Delete').''; } } else { if ($screenname) { @@ -189,19 +217,13 @@ sub list_discussion { $ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { $sender.=' '.&mt('Reply').''; + $ressymb.':::'.$idx; + if ($newpostsflag) { + $sender .= '&previous='.$prevread; + } + $sender .= '" '.$target.'>'.&mt('Reply').''; } my $vgrlink; - my $ctlink; - if ($readids{$idx} == 1) { - $ctlink = ''.&mt('Mark unread').'? '. - ''; - } else { - $ctlink = ''.&mt('Mark read').'? '. - ''; - } if ($viewgrades) { $vgrlink=&Apache::loncommon::submlink('Submissions', $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb); @@ -213,70 +235,77 @@ sub list_discussion { } $alldiscussion{$thisindex}=$idx; $index[$idx]=$thisindex; - my $posttime = $contrib{$idx.':timestamp'}; my $spansize = 2; - $discussionitems[$idx]='

'; - if ($prevread > 0 && $prevread < $posttime) { - $discussionitems[$idx] .= ''; - $spansize ++; - } - $discussionitems[$idx] .= ''; - if ($showonlyunread && $readids{$idx}) { - $discussionitems[$idx] .= '
NEW  '. - ''.$subject.'  '. - $sender.' '.$vgrlink.' ('. - localtime($posttime).')'. - '  '. - $ctlink.'
Check "Show all posts?" or "Mark unread?", then "Save read settings" to display message
'; + if ($showonlyunread && $prevread > $posttime) { + $notshown{$idx} = 1; } else { - $discussionitems[$idx] .= '

'.$message.'

'; + $discussionitems[$idx]='

'; + if ($prevread > 0 && $prevread <= $posttime) { + $discussionitems[$idx] .= ''; + } + $discussionitems[$idx] .= ''. + '
NEW  '. + ''.$subject.'  '. + $sender.' '.$vgrlink.' ('. + localtime($posttime).')

'.$message.'

'; } } } } } + my $discussion=''; if ($visible) { -# Print a the discusssion - $discussion .= '
'; +# Print the discusssion $discussion.=''; if ($visible>2) { my $colspan=$maxdepth+1; -my $showoption = ''; } - + my $numhidden = keys %notshown; + if ($numhidden > 0) { + my $colspan = $maxdepth+1; + $discussion.="\n".''; + } foreach (sort { $a <=> $b } keys %alldiscussion) { - $discussion.="\n"; - my $thisdepth=$depth[$alldiscussion{$_}]; - for (1..$thisdepth) { - $discussion.=''; + unless ($notshown{$alldiscussion{$_}} eq '1') { + $discussion.="\n"; + my $thisdepth=$depth[$alldiscussion{$_}]; + for (1..$thisdepth) { + $discussion.=''; + } + my $colspan=$maxdepth-$thisdepth+1; + $discussion.=''; } - my $colspan=$maxdepth-$thisdepth+1; - $discussion.=''; - } - my $colspan=$maxdepth+1; - $discussion.=''; - $discussion .= '
'; - my $showflag = 'all'; + $discussion.='
'. + ''. + ''; + $discussion .= 'allposts='.$ressymb; + if ($newpostsflag) { + $discussion .= '&previous='.$prevread; + } + $discussion .='">'.&mt('Show all posts').'?'; } else { - $showoption .= 'Show only unread posts?'; + $discussion .= 'onlyunread='.$ressymb; + if ($newpostsflag) { + $discussion .= '&previous='.$prevread; + } + $discussion .= '">'.&mt('Show only unread posts').'?'; } - $discussion.=$showoption; - $discussion.=''; + $discussion .= '  
'. + ''.&mt('Threaded View').'  '. + ''.&mt('Chronological View').'  
'. - ''. - '
'. - ''.&mt('Threaded View').'  '. - ''.&mt('Chronological View').'  '.&mt('Mark all read').'  '. - ''.&mt('Mark all unread').'  '. - '
'. + ''.&mt('Show all posts').' '.&mt('to display').' '. + $numhidden.' '.&mt('previously viewed posts'). + '
   
   '. + $discussionitems[$alldiscussion{$_}]. + '
'. - $discussionitems[$alldiscussion{$_}]. - '

'. ''. - '


'; + } + $discussion.='

'; } if ($discussiononly) { $discussion.=(</g; $quote='
'.&Apache::lontexconvert::msgtexconverted($message).'
'; @@ -330,6 +360,9 @@ sub mail_screen { $subject = 'Re: '.$contrib{$idx.':subject'}; } } + if ($ENV{'form.previous'}) { + $prevtag = ''; + } } my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); my $send=&mt('Send'); @@ -386,6 +419,7 @@ $bodytag

$title

+$prevtag Please check at least one of the following feedback types: @@ -428,14 +462,25 @@ ENDFAILREDIR } sub redirect_back { - my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status) = @_; + my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_; + my $prevtag = ''; + my $qrystr = ''; if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' }; + if ($previous > 0) { + $qrystr = 'previous='.$previous; + if ($feedurl =~ /\?register=1/) { + $feedurl .= '&'.$qrystr; + } else { + $feedurl .= '?'.$qrystr; + } + $prevtag = ''; + } $r->print (< Feedback sent - + @@ -443,6 +488,7 @@ $typestyle Sent $sendsomething message(s), and $sendposts post(s). $status +$prevtag @@ -754,75 +800,29 @@ 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']); - ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','markread','markunread','storereads','onlyunread','allposts','chgreads']); + ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous']); - if (($ENV{'form.markread'}) || ($ENV{'form.markunread'})) { -# ----------------------------------------------------------------- Modify read/unread for all + if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) { +# ----------------------------------------------------------------- Modify display setting for this discussion &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - my $symb=$ENV{'form.markread'}?$ENV{'form.markread'}:$ENV{'form.markunread'}; - my $ressymb = $symb; + my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'}; my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); - $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|; - my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'}, + my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); my %readinghash = (); if ($contrib{'version'}) { - for (my $id=1;$id<=$contrib{'version'};$id++) { - my $msgid = $id.':message'; - if (defined($contrib{$msgid})) { - if ($ENV{'form.markread'}) { - $readinghash{$id} = 'read'; - } else { - $readinghash{$id} = 'unread'; - } - } - } if ($ENV{'form.allposts'}) { - $readinghash{'showonlyunread'} = 0; + $readinghash{$symb.'_showonlyunread'} = 0; } elsif ($ENV{'form.onlyunread'}) { - $readinghash{'showonlyunread'} = 1; + $readinghash{$symb.'_showonlyunread'} = 1; } - &Apache::lonnet::cstore(\%readinghash,$symb,'nohist_'.$ENV{'request.course.id'}.'_discuss',$ENV{'user.domain'},$ENV{'user.name'}); + &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'}); } - - &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status'),'0','0'); + &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'
','0','0','',$ENV{'form.previous'}); return OK; - } else { - my $symb = $ENV{'form.discsymb'}; - my %readinghash = (); - my $chgcount = 0; - foreach my $key (keys %ENV) { - if ($key =~ m/^form\.postunread_(\d+)/) { - $readinghash{$1} = 'unread'; - $chgcount ++; - } elsif ($key =~ m/^form\.postread_(\d+)/) { - $readinghash{$1} = 'read'; - $chgcount ++; - } - } - if ($ENV{'form.allposts'}) { - $readinghash{'showonlyunread'} = 0; - $chgcount ++; - } elsif ($ENV{'form.onlyunread'}) { - $readinghash{'showonlyunread'} = 1; - $chgcount ++; - } - - if ($chgcount > 0) { - &Apache::lonnet::cstore(\%readinghash,$symb,'nohist_'.$ENV{'request.course.id'}.'_discuss',$ENV{'user.domain'},$ENV{'user.name'}); - } - } - - if ($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'); } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) { # ----------------------------------------------------------------- Hide/unhide &Apache::loncommon::content_type($r,'text/html'); @@ -852,7 +852,7 @@ sub handler { $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); &redirect_back($r,&Apache::lonnet::clutter($url), - &mt('Changed discussion status').'
','0','0'); + &mt('Changed discussion status').'
','0','0','',$ENV{'form.previous'}); } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; @@ -866,7 +866,7 @@ sub handler { 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'); + &mt('Changed discussion view mode').'
','0','0','',$ENV{'form.previous'}); } elsif ($ENV{'form.deldisc'}) { # --------------------------------------------------------------- Hide for good &Apache::loncommon::content_type($r,'text/html'); @@ -893,7 +893,7 @@ sub handler { $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); &redirect_back($r,&Apache::lonnet::clutter($url), - &mt('Changed discussion status').'
','0','0'); + &mt('Changed discussion status').'
','0','0','',$ENV{'form.previous'}); } elsif ($ENV{'form.preview'}) { # -------------------------------------------------------- User wants a preview $r->content_type('text/html'); @@ -1006,7 +1006,7 @@ sub handler { # Receipt screen and redirect back to where came from - &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status); + &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'}); } } else {