--- loncom/interface/lonfeedback.pm 2012/03/15 21:55:13 1.344 +++ loncom/interface/lonfeedback.pm 2015/06/09 21:22:56 1.370 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.344 2012/03/15 21:55:13 raeburn Exp $ +# $Id: lonfeedback.pm,v 1.370 2015/06/09 21:22:56 damieng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -277,14 +277,10 @@ 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); @@ -311,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,$canvote,$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; @@ -340,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'}; @@ -451,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 } } @@ -467,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".''; } @@ -517,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) ) { @@ -564,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'}.'

'. @@ -671,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') { @@ -704,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; } @@ -788,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,$title)=@_; - my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; + my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; if ($flag) { $link .= '&previous='.$prev; } if ($adds) { $link .= $adds; } my $width=600; @@ -828,7 +865,8 @@ sub send_message_link { } sub action_links_bar { - my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_; + my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp, + $seehidden) = @_; my $discussion = ''. ''. '
'; @@ -861,7 +899,7 @@ sub action_links_bar { } $discussion .= &group_args($group); $discussion .= '">'.&mt('Export').''; - if (&Apache::lonnet::allowed('rin',$env{'request.course.id'})) { + if ($seehidden) { $discussion .= '  '; $discussion .=''; } } } - if ($seeid) { + if ($seehidden) { if ($hiddens{$idx}) { unless ($studenthidden) { $sender.=' '. @@ -1301,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; @@ -1333,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) { @@ -1402,37 +1467,59 @@ sub build_posting_display { $$discussionitems[$idx].='  '.$ctlink; } my $thislikes=$likes{$symb.':'.$idx.':likes'}; - my $likesize="100"; + my $likestyle; if ($seeid || $canvote) { # Figure out size based on likes + my $class = 'zero'; my $thislikes=$likes{$symb.':'.$idx.':likes'}; if ($thislikes>$twoplus) { - $likesize="200"; + $class = 'twoplus'; } elsif ($thislikes>$oneplus) { - $likesize="150"; + $class = 'oneplus'; } if ($thislikes<$twominus) { - $likesize="50"; + $class = 'twominus'; } elsif ($thislikes<$oneminus) { - $likesize="75"; + $class = 'oneminus'; } + $likestyle = $votestyle{$class}; } # Actually glue in the message itself $$discussionitems[$idx].= '
'. - "
". + "
". $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 ($userlikes{$idx}) { - $$discussionitems[$idx].=''.&mt('You like this posting').''; - } else { - $$discussionitems[$idx].=' '.&discussion_link($symb,''.&mt('Like').'','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting")); - } - if ($userunlikes{$idx}) { - $$discussionitems[$idx].=''.&mt('You unlike this posting').''; + 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 { - $$discussionitems[$idx].=' '.&discussion_link($symb,''.&mt('Unlike').'','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting")); + if ($userlikes{$idx}) { + $$discussionitems[$idx].=''.&mt('You like this posting').''; + } else { + $$discussionitems[$idx].=' '.&discussion_link($symb,''.&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($symb,''.&mt('Unlike').'','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting")); + } } } if ($seeid || $canvote) { @@ -1447,7 +1534,7 @@ sub build_posting_display { if ($contrib{$idx.':history'}) { my @postversions = (); $$discussionitems[$idx] .= '  '.&mt('This post has been edited by the author.'); - if ($seeid) { + if ($seehidden) { $$discussionitems[$idx] .= '  '. &discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group)); } @@ -1533,13 +1620,13 @@ sub filter_regexp { sub get_post_contents { - my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$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; } @@ -1754,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'}); @@ -1762,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'}; } @@ -1827,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= < //