--- loncom/interface/lonfeedback.pm 2012/01/06 18:17:44 1.324 +++ loncom/interface/lonfeedback.pm 2017/05/30 02:17:45 1.370.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.324 2012/01/06 18:17:44 www Exp $ +# $Id: lonfeedback.pm,v 1.370.2.1 2017/05/30 02:17:45 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -82,6 +82,26 @@ sub discussion_visible { return 1; } +sub discussion_vote_available { + my ($status,$symb)=@_; + my $canvote=&Apache::lonnet::EXT('resource.0.discussvote',$symb); + if ((lc($canvote) eq 'yes') || + ((lc($canvote) eq 'notended') && (&discussion_open($status,$symb)))) { + return 1; + } +} + +sub get_realsymb { + my ($symb) = @_; + my $realsymb = $symb; + if ($symb=~/^bulletin___/) { + my $filename=(&Apache::lonnet::decode_symb($symb))[2]; + $filename=~s{^adm/wrapper/}{}; + $realsymb=&Apache::lonnet::symbread($filename); + } + return $realsymb; +} + sub list_discussion { my ($mode,$status,$ressymb,$imsextras,$group)=@_; unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); } @@ -257,14 +277,15 @@ sub list_discussion { $visit ++; my $seeid; - if (($group ne '') && ($mode eq 'board') && - ($ressymb =~ m|^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|)) { - if (&check_group_priv($group,'dgp') eq 'ok') { - $seeid = 1; - } - } else { - $seeid=&Apache::lonnet::allowed('rin',$crs); + if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + $seeid = 1; } + my $seehidden = &can_see_hidden($mode,$ressymb,undef,$group,$cdom,$cnum,$crs); + +# Is voting on discussions available + my $realsymb = &get_realsymb($ressymb); + my $canvote = &discussion_vote_available($status,$realsymb); + my @discussionitems=(); my %shown = (); my @posteridentity=(); @@ -286,7 +307,7 @@ sub list_discussion { $discinfo{$visitkey} = $visit; &Apache::lonnet::put('nohist_'.$cid.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'}); - &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$encsymb,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group); + &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$seehidden,$canvote,$prevread,$sortposts,$encsymb,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group); my $discussion=''; my $manifestfile; @@ -315,12 +336,15 @@ sub list_discussion { 'aner' => 'An error occurred opening the manifest file.', 'difo' => 'Discussion for', 'aerr' => 'An error occurred opening the export file for posting', + 'discussions' => 'DISCUSSIONS' + ); + my %js_lt = &Apache::lonlocal::texthash( 'aysu' => 'Are you sure you want to delete this post?', 'dpwn' => 'Deleted posts will no longer be visible to you and other students', 'bwco' => 'but will continue to be visible to your instructor', 'depo' => 'Deleted posts will no longer be visible to you or anyone else.', - 'discussions' => 'DISCUSSIONS' ); + &js_escape(\%js_lt); my $currdisp = $lt{'allposts'}; my $currmark = $lt{'onmark'}; @@ -426,12 +450,12 @@ imscp_v1p1.xsd http://www.imsglobal.org/ prevparm = "&previous="+previous } if (caller == 'studentdelete') { - if (confirm("$lt{'aysu'}\\n$lt{'dpwn'},\\n$lt{'bwco'}")) { + if (confirm("$js_lt{'aysu'}\\n$js_lt{'dpwn'},\\n$js_lt{'bwco'}")) { document.location.href = "/adm/feedback?hide="+symbparm+prevparm+groupparm } } else { if (caller == 'seeiddelete') { - if (confirm("$lt{'aysu'}\\n$lt{'depo'}")) { + if (confirm("$js_lt{'aysu'}\\n$js_lt{'depo'}")) { document.location.href = "/adm/feedback?deldisc="+symbparm+prevparm+groupparm } } @@ -442,23 +466,23 @@ imscp_v1p1.xsd http://www.imsglobal.org/ "\n".''; $discussion .= &action_links_bar($colspan,$ressymb,$visible, $newpostsflag,$group, - $prevread,$markondisp); + $prevread,$markondisp,$seehidden); my $escsymb=&escape($ressymb); my $numhidden = keys(%notshown); if ($numhidden > 0) { my $colspan = $maxdepth+1; - $discussion.="\n".''; } @@ -492,7 +516,9 @@ imscp_v1p1.xsd http://www.imsglobal.org/ my $currdepth = 0; my $firstidx = $alldiscussion{$showposts[0]}; foreach my $post (@showposts) { - unless (($sortposts eq 'thread') || (($sortposts eq '') && ($env{'environment.threadeddiscussion'})) || ($outputtarget eq 'export')) { + unless (($sortposts eq 'thread') || + (($sortposts eq '') && (!$env{'environment.unthreadeddiscussion'})) || + ($outputtarget eq 'export')) { $alldiscussion{$post} = $post; } unless ( ($notshown{$alldiscussion{$post}} eq '1') || ($shown{$alldiscussion{$post}} == 0) ) { @@ -539,7 +565,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ my $postingfile; my $postingfilename = $tempexport.'/'.$postfilename; if ($postingfile = Apache::File->new('>'.$postingfilename)) { - print $postingfile 'Discussion Post'. + print $postingfile ''.&mt('Discussion Post').''. $imsitems{$alldiscussion{$post}}{'title'}.' '. $imsitems{$alldiscussion{$post}}{'sender'}. $imsitems{$alldiscussion{$post}}{'timestamp'}.'

'. @@ -646,7 +672,7 @@ END END $discussion .= &action_links_bar($colspan,$ressymb,$visible, $newpostsflag,$group, - $prevread,$markondisp); + $prevread,$markondisp,$seehidden); $discussion .= "
'. - ''; + my $href = '/adm/feedback?allposts=1&symb='.$escsymb; if ($newpostsflag) { - $discussion .= '&previous='.$prevread; + $href .= '&previous='.$prevread; } - $discussion .= &group_args($group); - $discussion .= '">'.&mt('Show all posts').' '.&mt('to display').' '. - $numhidden.' '; + $href .= &group_args($group); if ($showunmark) { - $discussion .= &mt('posts previously marked read'); + $discussion .= &mt('[_1]Show all posts[_2] to display [quant,_3,post] previously marked read', + '','',$numhidden); } else { - $discussion .= &mt('previously viewed posts'); + $discussion .= &mt('[_1]Show all posts[_2] to display [quant,_3,post] previously viewed', + '','',$numhidden); } $discussion .= '
\n"; } if ($outputtarget eq 'export') { @@ -679,13 +705,17 @@ END open(OUTPUT, "zip -r $imszip * 2> /dev/null |"); close(OUTPUT); chdir $cwd; - $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive','').'
'; + $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive[_2]', + '','').'
'; if ($copyresult) { - $discussion .= &mt('The following errors occurred during export').' -
'.$copyresult; + $discussion .= ''. + &mt('The following errors occurred during export:'). + '
'.$copyresult; } } } else { - $discussion .= '
'.&mt('Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating a manifest file.').'
'; + $discussion .= '

'. + &mt('Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating a manifest file.').'

'; } return $discussion; } @@ -744,9 +774,15 @@ END $discussion.= &send_feedback_link($ressymb); if ($env{'request.role.adv'}) { my $close = &Apache::lonnet::EXT('resource.0.discussend',$ressymb); + my $canvote = &Apache::lonnet::EXT('resource.0.discussvote',$ressymb); if (defined($close) && $close ne '' && $close < time) { - $discussion .= ' '.&mt('(Closed for [_1] roles)', - &Apache::lonnet::plaintext('st',$crstype)); + if ($canvote eq 'notended') { + $discussion .= ' '.&mt('(Posting and voting closed for [_1] roles)', + &Apache::lonnet::plaintext('st',$crstype)); + } else { + $discussion .= ' '.&mt('(Closed for [_1] roles)', + &Apache::lonnet::plaintext('st',$crstype)); + } } } } else { @@ -757,10 +793,42 @@ END return $discussion; } +sub can_see_hidden { + my ($mode,$ressymb,$feedurl,$group,$cdom,$cnum,$crs) = @_; + my $seehidden; + if ($env{'request.course.id'}) { + unless ($cdom ne '' && $cnum ne '') { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + } + if ($crs eq '') { + $crs = '/'.$env{'request.course.id'}; + if ($env{'request.course.sec'}) { + $crs.='_'.$env{'request.course.sec'}; + } + $crs=~s{_}{/}g; + } + if ($mode eq '') { + $mode='board'; + if ($feedurl =~ /$LONCAPA::assess_re/) { + $mode='problem'; + } + } + if (($group ne '') && ($mode eq 'board') && + ($ressymb =~ m{^bulletin___\d+\Q___adm/wrapper/adm/$cdom/$cnum/\E\d+/bulletinboard$})) { + if (&check_group_priv($group,'dgp') eq 'ok') { + $seehidden = 1; + } + } else { + $seehidden=&Apache::lonnet::allowed('rin',$crs); + } + } + return $seehidden; +} sub discussion_link { - my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds)=@_; - my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; + my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds,$title)=@_; + my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; if ($flag) { $link .= '&previous='.$prev; } if ($adds) { $link .= $adds; } my $width=600; @@ -769,7 +837,7 @@ sub discussion_link { $width=300; $height=200; } - return &Apache::loncommon::modal_link($link,$linktext,$width,$height); + return &Apache::loncommon::modal_link($link,$linktext,$width,$height,undef,undef,$title); } @@ -787,15 +855,18 @@ sub send_feedback_link { sub send_message_link { my ($ressymb) = @_; my $output = ''. - ' '.&mt('Send Feedback').''; + &discussion_link($ressymb, + ''.&mt('Send Feedback').'', + 'sendmessageonly'). + ''; return $output; } sub action_links_bar { - my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_; + my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp, + $seehidden) = @_; my $discussion = ''. ''. ''; + $discussion .= '">'.&mt('Export').''; + if ($seehidden) { + $discussion .= '  '; + $discussion .=''.&mt('Undelete all deleted entries').''; + } + $discussion.=''; if ($newpostsflag) { if (!$markondisp) { $discussion .='
'; @@ -827,7 +898,17 @@ sub action_links_bar { $discussion .= '&previous='.$prevread; } $discussion .= &group_args($group); - $discussion .= '">'.&mt('Export').' -
+ $lt{'note'}
-$lt{'title'}: 

+$lt{'title'}: 
ENDDISCUSS if ($env{'form.origpage'}) { @@ -925,7 +1006,7 @@ ENDDISCUSS } sub build_posting_display { - my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_; + my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$seehidden,$canvote,$prevread,$sortposts,$ressymb,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_; my @original=(); my @index=(); my $skip_group_check = 0; @@ -935,14 +1016,20 @@ sub build_posting_display { 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 (%likes,%userlikes,%userunlikes,@theselikes,$oneplus,$twoplus,$oneminus,$twominus); + my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; + if ($seeid || $canvote) { # And these are the likes/unlikes - my %likes=&Apache::lonnet::dump('disclikes', + %likes=&Apache::lonnet::dump('disclikes', $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}, '^'.$symb.':'); - my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; # Array with likes to figure out averages, etc. - my @theselikes=(); + @theselikes=(); +# Hashes containing likes and unlikes for this user. + %userlikes=(); + %userunlikes=(); + } # Is the user allowed to see the real name behind anonymous postings? my $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); @@ -975,7 +1062,80 @@ sub build_posting_display { ($skiptest,$roleregexp,$secregexp,$statusregexp) = &filter_regexp($rolefilter,$sectionpick,$statusfilter); $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp; - } + } + my %votestyle; + if ($seeid || $canvote) { +# We need to go through this twice, first to get the likes/dislikes, then to actually build the display + for (my $id=1;$id<=$contrib{'version'};$id++) { + my $idx=$id; + next if ($contrib{$idx.':deleted'}); + next if ($contrib{$idx.':hidden'}); + unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) { + push(@theselikes,$likes{$symb.':'.$idx.':likes'}); + if ($likes{$symb.':'.$idx.':likes'} ne '') { + if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') { + if (exists($likes{$symb.':'.$idx.':likers'}{$thisuser})) { + $userlikes{$idx} = 1; + } + } + if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') { + if (exists($likes{$symb.':'.$idx.':unlikers'}{$thisuser})) { + $userunlikes{$idx} = 1; + } + } + } + } + } +# Figure out average likes and standard deviation if there are enough +# discussions to warrant that + my $ave=0; + my $stddev=10000; + if ($#theselikes>1) { + my $sum=0; + my $num=$#theselikes+1; + foreach my $thislike (@theselikes) { + $sum+=$thislike; + } + $ave=$sum/$num; + my $sumsq=0; + foreach my $thislike (@theselikes) { + $sumsq+=($thislike-$ave)*($thislike-$ave); + } + $stddev=sqrt($sumsq/$num); + } +# Now we know the average likes $ave and the standard deviation $stddev +# Get the boundaries for markup + $oneplus=$ave+$stddev; + $twoplus=$ave+2.*$stddev; + $oneminus=$ave-$stddev; + $twominus=$ave-2.*$stddev; + if ($#theselikes>1) { + foreach my $class ('twoplus','oneplus','zero','oneminus','twominus') { + my $fontstyle = $env{'course.'.$env{'request.course.id'}.'.discussion_post_fonts_'.$class}; + if ($fontstyle ne '') { + my ($size,$weight,$style,$other) = split(/,/,$fontstyle); + if ($size ne '') { + $votestyle{$class} .= 'font-size: '.$size.';'; + } + if ($weight ne '') { + $votestyle{$class} .= 'font-weight: '.$weight.';'; + } + if ($style ne '') { + $votestyle{$class} .= 'font-style: '.$style.';'; + } + if ($other ne '') { + $votestyle{$class} .= $other; + } + if ($votestyle{$class} ne '') { + $votestyle{$class} = 'style="'.$votestyle{$class}.'"'; + } + } + } + } + } +# +# This is now the real loop. Go through all entries, pick up what we need +# for (my $id=1;$id<=$contrib{'version'};$id++) { my $idx=$id; next if ($contrib{$idx.':deleted'}); @@ -990,7 +1150,8 @@ sub build_posting_display { my $origindex='0.'; my $numoldver=0; if ($contrib{$idx.':replyto'}) { - if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) { + if ( ((!$env{'environment.unthreadeddiscussion'}) && ($sortposts eq '')) || + ($sortposts eq 'thread') || ($outputtarget eq 'export')) { # this is a follow-up message $original[$idx]=$original[$contrib{$idx.':replyto'}]; $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1; @@ -1010,7 +1171,7 @@ sub build_posting_display { } else { $$replies[$$depth[$idx]]=1; } - unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx})) { + unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx})) { $$visible++; if ($contrib{$idx.':history'}) { if ($contrib{$idx.':history'} =~ /:/) { @@ -1025,7 +1186,7 @@ sub build_posting_display { my %subjects = (); my %attachtxt = (); my %allattachments = (); - my ($screenname,$plainname); + my ($screenname,$plainname,$showaboutme); my $sender = &mt('Anonymous'); # Anonymous users getting number within a discussion # Since idx is in static order, this should give the same sequence every time. @@ -1035,7 +1196,7 @@ sub build_posting_display { $$anonhash{$key}=&mt('Anonymous').' '.$anoncnt; } my ($message,$subject,$vgrlink,$ctlink); - &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver); + &get_post_contents(\%contrib,$idx,$seeid,$seehidden,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,\$showaboutme,$numoldver); # Set up for sorting by subject @@ -1065,12 +1226,18 @@ sub build_posting_display { } } if (!$contrib{$idx.':anonymous'} || $see_anonymous) { - $sender=&Apache::loncommon::aboutmewrapper( - $plainname, - $contrib{$idx.':sendername'}, - $contrib{$idx.':senderdomain'}).' ('. - $contrib{$idx.':sendername'}.':'. - $contrib{$idx.':senderdomain'}.')'; + if ($showaboutme) { + $sender = &Apache::loncommon::aboutmewrapper( + $plainname, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + } else { + $sender = $plainname; + } + if ($see_anonymous) { + $sender .= ' ('.$contrib{$idx.':sendername'}.':'. + $contrib{$idx.':senderdomain'}.')'; + } $sender = ''.$sender.''; if ($contrib{$idx.':anonymous'}) { $sender.=' ['.$$anonhash{$key}.'] '. @@ -1109,39 +1276,32 @@ sub build_posting_display { @{$$namesort{$lastname}{$firstname}} = ("$idx"); } if ($outputtarget ne 'tex') { - unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) { - $sender.=' '.&discussion_link($symb,&mt('Like'),'like',$idx,$$newpostsflag,$prevread,&group_args($group)); - } - unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { - $sender.=' '.&discussion_link($symb,&mt('Unlike'),'unlike',$idx,$$newpostsflag,$prevread,&group_args($group)); - } - my $thislikes=$likes{$symb.':'.$idx.':likes'}; - push(@theselikes,$thislikes); - if ($thislikes>0) { - $sender.=' ('.&mt("[_1] likes",$thislikes).')'; - } elsif ($thislikes<0) { - $sender.=' ('.&mt("[_1] unlikes",abs($thislikes)).')'; +# Add karma stars + my $karma=&userkarma($contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); + for (my $i=1;$i<=$karma;$i++) { + $sender.=''.&mt('Contributor Kudos').''; } +# Can people edit this? if (&editing_allowed($escsymb.':::'.$idx,$group)) { if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { $sender.=' '. - &discussion_link($symb,&mt('Edit'),'editdisc',$idx,$$newpostsflag,$prevread,&group_args($group)); - unless ($seeid) { + &discussion_link($ressymb,&mt('Edit'),'editdisc',$idx,$$newpostsflag,$prevread,&group_args($group)); + unless ($seehidden) { my $grpargs = &group_args($group); $sender.=" '; } } } - if ($seeid) { + if ($seehidden) { if ($hiddens{$idx}) { unless ($studenthidden) { $sender.=' '. - &discussion_link($symb,&mt('Make Visible'),'unhide',$idx,$$newpostsflag,$prevread,&group_args($group)); + &discussion_link($ressymb,&mt('Make Visible'),'unhide',$idx,$$newpostsflag,$prevread,&group_args($group)); } } else { $sender.=' '. - &discussion_link($symb,&mt('Hide'),'hide',$idx,$$newpostsflag,$prevread,&group_args($group)); + &discussion_link($ressymb,&mt('Hide'),'hide',$idx,$$newpostsflag,$prevread,&group_args($group)); } my $grpargs = &group_args($group); $sender.= @@ -1180,13 +1340,13 @@ sub build_posting_display { if (($group ne '') && (&check_group_priv($group,'pgd') eq 'ok')) { $sender.=' '. - &discussion_link($symb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread,&group_args($group)); + &discussion_link($ressymb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread,&group_args($group)); } elsif (&Apache::lonnet::allowed('pch', $env{'request.course.id'}. ($env{'request.course.sec'}?'/'. $env{'request.course.sec'}:''))) { $sender.=' '. - &discussion_link($symb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread); + &discussion_link($ressymb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread); } } if ($viewgrades) { @@ -1204,7 +1364,8 @@ sub build_posting_display { } if ($outputtarget eq 'export' || $message) { my $thisindex=$idx; - if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) { + if ( ((!$env{'environment.unthreadeddiscussion'}) && ($sortposts eq '')) || + ($sortposts eq 'thread') || ($outputtarget eq 'export')) { $thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2); } $$alldiscussion{$thisindex}=$idx; @@ -1236,14 +1397,15 @@ sub build_posting_display { } else { if ($message) { my $spansize = 2; + my ($uname,$udom); 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'}; + $uname = $contrib{$idx.':sendername'}; + $udom = $contrib{$idx.':senderdomain'}; my $poster = $uname.':'.$udom; if ($env{'form.totposters'} ne '') { if ($totposters == 0) { @@ -1304,14 +1466,77 @@ sub build_posting_display { if ($$dischash{$toggkey}) { $$discussionitems[$idx].='  '.$ctlink; } + my $thislikes=$likes{$symb.':'.$idx.':likes'}; + my $likestyle; + if ($seeid || $canvote) { +# Figure out size based on likes + my $class = 'zero'; + my $thislikes=$likes{$symb.':'.$idx.':likes'}; + if ($thislikes>$twoplus) { + $class = 'twoplus'; + } elsif ($thislikes>$oneplus) { + $class = 'oneplus'; + } + if ($thislikes<$twominus) { + $class = 'twominus'; + } elsif ($thislikes<$oneminus) { + $class = 'oneminus'; + } + $likestyle = $votestyle{$class}; + } +# Actually glue in the message itself $$discussionitems[$idx].= '
'. - $message.'
'; + "
". + $message. + '
'; + if ($canvote) { + my $ownpost; + if (($uname eq $env{'user.name'}) && + ($udom eq $env{'user.domain'})) { + $ownpost = 1; + } +# Put in the like and unlike buttons + if ($ownpost || (($hiddens{$idx}) && ($seehidden))) { + my $novote; + if ($ownpost) { + $novote = &mt('No voting for your own posts.'); + } else { + $novote = &mt('No voting for hidden posts.'); + } + &html_escape(\$novote); + $$discussionitems[$idx].= + '
'. + ''.$novote.' '. + ''.$novote.''; + + } else { + if ($userlikes{$idx}) { + $$discussionitems[$idx].=''.&mt('You like this posting').''; + } else { + $$discussionitems[$idx].=' '.&discussion_link($ressymb,''.&mt('Like').'','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting")); + } + if ($userunlikes{$idx}) { + $$discussionitems[$idx].=''.&mt('You unlike this posting').''; + } else { + $$discussionitems[$idx].=' '.&discussion_link($ressymb,''.&mt('Unlike').'','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting")); + } + } + } + if ($seeid || $canvote) { + my $thislikes=$likes{$symb.':'.$idx.':likes'}; + if ($thislikes>0) { + $$discussionitems[$idx].=' ('.&mt("[_1] likes",$thislikes).')'; + } elsif ($thislikes<0) { + $$discussionitems[$idx].=' ('.&mt("[_1] unlikes",abs($thislikes)).')'; + } + } +# If there is any history to this post, inform the reader if ($contrib{$idx.':history'}) { my @postversions = (); - $$discussionitems[$idx] .= &mt('This post has been edited by the author.'); - if ($seeid) { + $$discussionitems[$idx] .= '  '.&mt('This post has been edited by the author.'); + if ($seehidden) { $$discussionitems[$idx] .= '  '. - &discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group)); + &discussion_link($ressymb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group)); } $$discussionitems[$idx].='
'.&mt('Earlier version(s) were posted on: '); if ($contrib{$idx.':history'} =~ m/:/) { @@ -1334,22 +1559,7 @@ sub build_posting_display { } # end of the loop over all discussion entries } -# Figure out average likes and standard deviation if there are enough discussions to warrant that - if ($#theselikes>1) { - my $sum=0; - my $num=$#theselikes+1; - foreach my $thislike (@theselikes) { - $sum.=$thislike; - } - my $ave=$sum/$num; - my $sumsq=0; - foreach my $thislike (@theselikes) { - $sumsq+=($thislike-$ave)*($thislike-$ave); - } - my $stddev=sqrt($sumsq/$num); -# &Apache::lonnet::logthis(join(',',@theselikes)." Ave $ave StdDev $stddev"); - } -# end of "if there actually are any discussion +# end of "if there actually are any discussions } # end of subroutine "build_posting_display" } @@ -1410,13 +1620,13 @@ sub filter_regexp { sub get_post_contents { - my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_; + my ($contrib,$idx,$seeid,$seehidden,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$numver) = @_; my $discussion = ''; my $start=$numver; my $end=$numver + 1; %{$$imsfiles{$idx}}=(); if ($type eq 'allversions') { - unless($seeid) { + unless($seehidden) { $discussion=&mt('You do not have privileges to view all versions of posts.').' '.&mt('Please select a different role.'); return $discussion; } @@ -1428,13 +1638,20 @@ sub get_post_contents { $$contrib{$idx.':sendername'}, $$contrib{$idx.':senderdomain'}); $$screenname=$$contrib{$idx.':screenname'}; - - my $sender=&Apache::loncommon::aboutmewrapper( + $$showaboutme = &Apache::lonnet::usertools_access($$contrib{$idx.':sendername'}, + $$contrib{$idx.':senderdomain'}, + 'aboutme'); + my $sender = $$plainname; + if ($$showaboutme) { + $sender = &Apache::loncommon::aboutmewrapper( $$plainname, $$contrib{$idx.':sendername'}, - $$contrib{$idx.':senderdomain'}).' ('. - $$contrib{$idx.':sendername'}.':'. - $$contrib{$idx.':senderdomain'}.')'; + $$contrib{$idx.':senderdomain'}); + } + if ($seeid) { + $sender .= ' ('.$$contrib{$idx.':sendername'}.':'. + $$contrib{$idx.':senderdomain'}.')'; + } my $attachmenturls = $$contrib{$idx.':attachmenturl'}; my @postversions = (); if ($type eq 'allversions' || $type eq 'export') { @@ -1550,11 +1767,16 @@ sub mail_screen { } my %lt = &Apache::lonlocal::texthash( - 'myqu' => 'My question/comment/feedback:', + 'myqu' => 'Question/comment/feedback:', 'title' => 'Title', 'reta' => 'Retained attachments', 'atta' => 'Attachment', ); + if($env{'form.editdisc'} || $env{'form.replydisc'}){ + %lt = &Apache::lonlocal::texthash( + 'myqu' => 'Post Discussion', + ); + } my $restitle = &get_resource_title($caller_symb,$feedurl); my $quote=''; my $subject = ''; @@ -1619,6 +1841,7 @@ END $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) { + my $numoldver = 0; if ($contrib{$idx.':history'}) { if ($contrib{$idx.':history'} =~ /:/) { my @oldversions = split(/:/,$contrib{$idx.':history'}); @@ -1627,36 +1850,25 @@ END $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; - } + if ($idx > 0) { + my (%msgversions,%subversions,$htmldecode); + $htmldecode = 0; + if ($env{'form.replydisc'}) { + $htmldecode = 1; } - if ($idx > 0) { - my %msgversions = (); - &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver); + &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver); + &get_post_versions(\%subversions,$contrib{$idx.':subject'},$htmldecode, + $numoldver); + $subject = $subversions{$numoldver}; + if ($env{'form.replydisc'}) { $quote = $msgversions{$numoldver}; - } - if ($idx > 0) { - my %subversions = (); - &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver); - $subject = &mt('Re: ').$subversions{$numoldver}; - } - $subject = &HTML::Entities::encode($subject,'<>&"'); - } else { - $attachmenturls = $contrib{$idx.':attachmenturl'}; - if ($idx > 0) { - my %msgversions = (); - &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver); + $subject = &HTML::Entities::encode(&mt('Re: ').$subject,'<>&"'); + } else { $comment = $msgversions{$numoldver}; - my %subversions = (); - &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver); - $subject = $subversions{$numoldver}; } + } + if ($env{'form.editdisc'}) { + $attachmenturls = $contrib{$idx.':attachmenturl'}; if (defined($contrib{$idx.':replyto'})) { $parentmsg = $contrib{$idx.':replyto'}; } @@ -1692,6 +1904,7 @@ END my $latexHelp=&Apache::loncommon::helpLatexCheatsheet(undef,undef,1,($env{'form.modal'}?'popup':0)); my $send=&mt('Send'); my $alert = &mt('Please select a feedback type.'); + &js_escape(\$alert); my $js= < //