--- loncom/interface/lonfeedback.pm 2009/12/22 06:14:35 1.283
+++ loncom/interface/lonfeedback.pm 2022/01/19 18:08:38 1.370.2.5.2.2
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.283 2009/12/22 06:14:35 faziophi Exp $
+# $Id: lonfeedback.pm,v 1.370.2.5.2.2 2022/01/19 18:08:38 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -44,18 +44,27 @@ use HTML::LCParser();
#use HTML::Tidy::libXML;
use Apache::lonspeller();
use Apache::longroup;
-use Cwd;
-use LONCAPA;
+use Archive::Zip qw( :ERROR_CODES );
+use LONCAPA qw(:DEFAULT :match);
sub discussion_open {
my ($status,$symb)=@_;
+# Advanced roles can always discuss
if ($env{'request.role.adv'}) { return 1; }
+# Get discussion closing date
+ my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb);
+# If it is defined and in the future, the instructor wants this discussion to be open
+ if (defined($close) && $close ne '' && $close > time) {
+ return 1;
+ }
+# It was not explicitly open, check if the problem is available.
+# If the problem is not available, close the discussion
if (defined($status) &&
!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
|| $status eq 'OPEN')) {
return 0;
}
- my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb);
+# The problem is available, but check if the instructor explictly closed discussion
if (defined($close) && $close ne '' && $close < time) {
return 0;
}
@@ -73,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(); }
@@ -89,10 +118,16 @@ sub list_discussion {
$outputtarget = 'export';
}
}
+ my ($nofooter,$nodisclink,$nofdbklink);
if (not &discussion_visible($status)) {
if ($mode ne 'board') {
- &Apache::lonenc::check_encrypt(\$ressymb);
- return '
END
if ($sortposts) {
@@ -603,7 +633,7 @@ END
my %status_types = ();
&sort_filter_names(\%sort_types,\%role_types,\%status_types,$crstype);
- $discussion .= '
\n";
+ }
if ($outputtarget eq 'export') {
if ($manifestok) {
while ($currdepth > 0) {
@@ -683,22 +712,34 @@ END
#Create zip file in prtspool
- my $imszipfile = '/prtspool/'.
- $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
- time.'_'.rand(1000000000).'.zip';
- my $cwd = &getcwd();
- my $imszip = '/home/httpd/'.$imszipfile;
- chdir $tempexport;
- open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
- close(OUTPUT);
- chdir $cwd;
- $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive','').' ';
- if ($copyresult) {
- $discussion .= &mt('The following errors occurred during export').' - '.$copyresult;
+ if (($env{'user.name'} =~ /^$match_username$/)
+ && ($env{'user.domain'} =~ /^$match_domain$/)) {
+ my $now = time();
+ my $imszipfile = '/prtspool/'.
+ join('_',$env{'user.name'},$env{'user.domain'},$now).
+ '_'.rand(1000000000).'.zip';
+ my $zip = Archive::Zip->new();
+ $zip->addTree($tempexport);
+ my $imszip = '/home/httpd/'.$imszipfile;
+ if ($zip->writeToFileNamed($imszip) == AZ_OK) {
+ $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive[_2]',
+ '','').' ';
+ } else {
+ $discussion .= &mt('Failed to create zip file').' ';
+ }
+ if ($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 the zip file.').'
';
}
}
} 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.').'
';
@@ -831,7 +984,7 @@ sub postingform_display {
$currnewattach,$currdelold,$group,$crstype) = @_;
my $newattachmsg;
my %lt = &Apache::lonlocal::texthash(
- 'note' => 'Note: in anonymous discussion, your name is visible only to course faculty',
+ 'note' => 'Note: in anonymous discussion, your name is visible only to course faculty',
'title' => 'Title',
'podi' => 'Post Discussion',
'poan' => 'Post Anonymous Discussion',
@@ -840,15 +993,25 @@ sub postingform_display {
if ($crstype eq 'Community') {
$lt{'note'} = &mt('Note: in anonymous discussion, your name is visible only to community facilitators');
}
- my $postingform = (<
-
+
$lt{'note'}
-$lt{'title'}:
'."\n";
+ }
+ $newattachmsg .= ''."\n";
+ } else {
+ $$currnewattach[0] =~ m#.*/([^/]+)$#;
+ $newattachmsg .= ''.$1.' '."\n";
+ }
}
+ $postingform .= $newattachmsg;
+ $postingform .= &generate_preview_button();
return $postingform;
}
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,$target,$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;
my $symb=&Apache::lonenc::check_decrypt($ressymb);
my $escsymb=&escape($ressymb);
+# These are the discussion contributions
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
+ %likes=&Apache::lonnet::dump('disclikes',
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'},
+ '^'.$symb.':');
+# Array with likes to figure out averages, etc.
+ @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'}:''));
if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) {
$skip_group_check = 1;
}
+# Deletions and hiddens are just lists. Split them up into a hash for quicker lookup
+ my (%deletions,%hiddens);
+ if ($contrib{'deleted'}) {
+ my $deleted = $contrib{'deleted'};
+ $deleted =~ s/^\.//;
+ $deleted =~ s/\.$//;
+ %deletions = map { $_ => 1 } (split(/\.\./,$deleted));
+ }
+ if ($contrib{'hidden'}) {
+ my $hidden = $contrib{'hidden'};
+ $hidden =~ s/^\.//;
+ $hidden =~ s/\.$//;
+ %hiddens = map { $_ => 1 } (split(/\.\./,$hidden));
+ }
+# Versions if store/restore are used to actually store the messages.
if ($contrib{'version'}) {
my $oldest = $contrib{'1:timestamp'};
if ($prevread eq '0') {
@@ -922,20 +1113,96 @@ 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'});
+ next if ($contrib{$idx.':hidden'});
+# If we get here, we are actually going to display the message - we don't know where and we don't know if we display
+# previous edits, but it counts as one entry
my $posttime = $contrib{$idx.':timestamp'};
if ($prevread <= $posttime) {
$$newpostsflag = 1;
}
- my $hidden=($contrib{'hidden'}=~/\.$idx\./);
my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
- my $deleted=($contrib{'deleted'}=~/\.$idx\./);
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;
@@ -955,7 +1222,7 @@ sub build_posting_display {
} else {
$$replies[$$depth[$idx]]=1;
}
- unless ((($hidden) && (!$seeid)) || ($deleted)) {
+ unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx})) {
$$visible++;
if ($contrib{$idx.':history'}) {
if ($contrib{$idx.':history'} =~ /:/) {
@@ -970,7 +1237,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.
@@ -980,7 +1247,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
@@ -989,7 +1256,7 @@ sub build_posting_display {
$message.=$attachtxt{$numoldver};
$subject=$subjects{$numoldver};
if ($message) {
- if ($hidden) {
+ if ($hiddens{$idx}) {
$message=''.$message.'';
if ($studenthidden) {
$message .='
Deleted by poster (student).';
@@ -1010,12 +1277,19 @@ 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}.'] '.
$screenname;
@@ -1052,53 +1326,47 @@ sub build_posting_display {
} else {
@{$$namesort{$lastname}{$firstname}} = ("$idx");
}
- if (&editing_allowed($escsymb.':::'.$idx,$group)) {
- if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
- $sender.=' '.&mt('Edit').'';
-
- unless ($seeid) {
- my $grpargs = &group_args($group);
- $sender.=" ';
- }
+ if ($outputtarget ne 'tex') {
+# Add karma stars
+ my $karma=&userkarma($contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
+ for (my $i=1;$i<=$karma;$i++) {
+ $sender.='';
}
- }
- if ($seeid) {
- if ($hidden) {
- unless ($studenthidden) {
- $sender.=' ';
}
- $sender .= '">'.&mt('Make Visible').'';
- }
- } else {
- $sender.=' '.&mt('Hide').'';
- }
- my $grpargs = &group_args($group);
- $sender.=
- " ";
- $sender .= &mt('Delete').'';
+ }
+ if ($seehidden) {
+ if ($hiddens{$idx}) {
+ unless ($studenthidden) {
+ $sender.=' '.
+ &discussion_link($ressymb,&mt('Make Visible'),'unhide',$idx,$$newpostsflag,$prevread,&group_args($group));
+ }
+ } else {
+ $sender.=' '.
+ &discussion_link($ressymb,&mt('Hide'),'hide',$idx,$$newpostsflag,$prevread,&group_args($group));
+ }
+ my $grpargs = &group_args($group);
+ $sender.=
+ " ";
+ $sender .= &mt('Delete').'';
+ }
}
- } else {
+ } else {
if ($screenname) {
$sender=''.$screenname.'';
} else {
$sender=''.$$anonhash{$key}.'';
}
+ $sender = ''.$sender.'';
# Set up for sorting by domain, then username for anonymous
unless (defined($$usernamesort{'__anon'})) {
%{$$usernamesort{'__anon'}} = ();
@@ -1118,43 +1386,37 @@ sub build_posting_display {
@{$$namesort{'__anon'}{'__anon'}} = ("$idx");
}
}
- if (&discussion_open($status)) {
- if (($group ne '') &&
- (&check_group_priv($group,'pgd') eq 'ok')) {
- $sender.=' '.&mt('Reply').'';
- } elsif (&Apache::lonnet::allowed('pch',
- $env{'request.course.id'}.
- ($env{'request.course.sec'}?'/'.
- $env{'request.course.sec'}:''))) {
- $sender.=' '.&mt('Reply').'';
}
- }
- if ($viewgrades) {
- $vgrlink=&Apache::loncommon::submlink('Submissions',
- $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
- }
- if ($$dischash{$readkey}=~/\.$idx\./) {
- $ctlink = '';
- } else {
- $ctlink = '';
+ if ($viewgrades) {
+ $vgrlink=&Apache::loncommon::submlink(&mt('Submissions'),
+ $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
+ }
+ if ($$dischash{$readkey}=~/\.$idx\./) {
+ $ctlink = '';
+ } else {
+ $ctlink = '';
+ }
}
}
#figure out at what position this needs to print
}
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;
@@ -1164,7 +1426,7 @@ sub build_posting_display {
if ($outputtarget eq 'export') {
%{$$imsitems{$idx}} = ();
$$imsitems{$idx}{'isvisible'}='true';
- if ($hidden) {
+ if ($hiddens{$idx}) {
$$imsitems{$idx}{'isvisible'}='false';
}
$$imsitems{$idx}{'title'}=$subjects{$numoldver};
@@ -1186,14 +1448,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) {
@@ -1244,32 +1507,87 @@ sub build_posting_display {
unless ($$notshown{$idx} == 1) {
if ($prevread > 0 && $prevread <= $posttime) {
$$newitem{$idx} = 1;
- $$discussionitems[$idx] .= '
-
+$header
END
if ($env{'form.editdisc'} || $env{'form.replydisc'}) {
@@ -1761,7 +2126,6 @@ END
$attachnum += @currnewattach;
}
my $blockblog = &Apache::loncommon::blocking_status('blogs');
- $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver,'',$blockblog));
if ($attachnum > 0) {
if (@currnewattach > 0) {
$newattachmsg .= ' '.&mt('New attachments').' ';
@@ -1781,12 +2145,12 @@ END
$r->print(" $lt{'reta'}:$attachmsg \n");
}
if ($newattachmsg) {
- $r->print("$newattachmsg ");
+ $r->print("$newattachmsg");
}
}
+ $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver,'',$blockblog));
}
$r->print(&generate_preview_button().
- &Apache::lonhtmlcommon::htmlareaselectactive('comment').
&Apache::loncommon::end_page());
}
@@ -1824,6 +2188,11 @@ sub print_display_options {
'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
'ywbr' => 'You will be returned to the previous page if you click OK.'
);
+ my %js_lt = &Apache::lonlocal::texthash(
+ 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
+ 'ywbr' => 'You will be returned to the previous page if you click OK.'
+ );
+ &js_escape(\%js_lt);
my $dispchangeA = $lt{'unread'};
my $dispchangeB = $lt{'unmark'};
@@ -1917,7 +2286,7 @@ function setDisp() {
if (chktotal > 0) {
document.modifydisp.submit()
} else {
- if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
+ if(confirm("$js_lt{'yhni'}. \\n$js_lt{'ywbr'}")) {
if (prev > 0) {
location.href = "$feedurl?previous=$previous"
} else {
@@ -2133,7 +2502,7 @@ END
$start_page