'.
'';
my $escsymb=&escape($ressymb);
- if ($visible>2) {
+ if ($visible) {
$discussion .= ''.&mt('Threaded View').' '.
''.&mt('Chronological View').'
'.&mt('Sorting/Filtering options').' '.(' ' x2);
}
$discussion .=''.&mt('Export').'? ';
+ $discussion .= '">'.&mt('Export').'';
+ if ($seehidden) {
+ $discussion .= ' ';
+ $discussion .=''.&mt('Undelete all deleted entries').' ';
+ }
+ $discussion.='';
if ($newpostsflag) {
if (!$markondisp) {
$discussion .='
@@ -846,7 +962,7 @@ sub postingform_display {
$lt{'note'}
$lt{'title'}:
-
+
ENDDISCUSS
if ($env{'form.origpage'}) {
$postingform .= ' \n";
- if ($outputtarget ne 'tex') {
- $postingform .= &generate_attachments_button('',$attachnum,$ressymb,
- $now,$currnewattach,
- $currdelold,'',$mode,
- $blockblog);
- if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
- $newattachmsg = ''.$lt{'newa'}.' ';
- if (@{$currnewattach} > 1) {
- $newattachmsg .= '';
- foreach my $item (@{$currnewattach}) {
- $item =~ m#.*/([^/]+)$#;
- $newattachmsg .= ''.$1.' '."\n";
- }
- $newattachmsg .= ' '."\n";
- } else {
- $$currnewattach[0] =~ m#.*/([^/]+)$#;
- $newattachmsg .= ''.$1.' '."\n";
+ $postingform .= &generate_attachments_button('',$attachnum,$ressymb,
+ $now,$currnewattach,
+ $currdelold,'',$mode,
+ $blockblog);
+ if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
+ $newattachmsg = ''.$lt{'newa'}.' ';
+ if (@{$currnewattach} > 1) {
+ $newattachmsg .= '';
+ foreach my $item (@{$currnewattach}) {
+ $item =~ m#.*/([^/]+)$#;
+ $newattachmsg .= ''.$1.' '."\n";
}
+ $newattachmsg .= ' '."\n";
+ } else {
+ $$currnewattach[0] =~ m#.*/([^/]+)$#;
+ $newattachmsg .= ''.$1.' '."\n";
}
- $postingform .= $newattachmsg;
- $postingform .= &generate_preview_button();
}
+ $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,$target,$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);
+# And these are the likes/unlikes
+ my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
+ if ($seeid || $canvote) {
+ %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;
}
+ 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));
+ }
if ($contrib{'version'}) {
my $oldest = $contrib{'1:timestamp'};
if ($prevread eq '0') {
@@ -920,16 +1062,65 @@ sub build_posting_display {
($skiptest,$roleregexp,$secregexp,$statusregexp) =
&filter_regexp($rolefilter,$sectionpick,$statusfilter);
$rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;
- }
+ }
+ 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'})) {
+ if ($likes{$symb.':'.$idx.':likes'} ne '') {
+ push(@theselikes,$likes{$symb.':'.$idx.':likes'});
+ 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;
+ }
+#
+# 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'});
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'}) {
@@ -953,7 +1144,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'} =~ /:/) {
@@ -968,7 +1159,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.
@@ -978,7 +1169,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
@@ -987,7 +1178,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).';
@@ -1008,12 +1199,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}.'] '.
@@ -1022,7 +1219,6 @@ sub build_posting_display {
if ($see_anonymous) {
$sender.=&Apache::loncommon::student_image_tag($contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
}
- $sender = ''.$sender.' ';
# Set up for sorting by domain, then username
unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {
%{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
@@ -1052,46 +1248,48 @@ 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').' ';
+ if ($outputtarget ne 'tex') {
+ 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.=" ';
+ unless ($seehidden) {
+ my $grpargs = &group_args($group);
+ $sender.=" ';
+ }
}
}
- }
- if ($seeid) {
- if ($hidden) {
- unless ($studenthidden) {
- $sender.=' ';
+ }
+ } else {
+ $sender.=' '.&mt('Make Visible').' ';
- }
- } else {
- $sender.=' '.&mt('Hide').' ';
- }
- my $grpargs = &group_args($group);
- $sender.=
- " ";
- $sender .= &mt('Delete').' ';
+ $sender .= &group_args($group);
+ $sender .= '">'.&mt('Hide').'';
+ }
+ my $grpargs = &group_args($group);
+ $sender.=
+ " ";
+ $sender .= &mt('Delete').' ';
+ }
}
} else {
if ($screenname) {
@@ -1099,6 +1297,7 @@ sub build_posting_display {
} else {
$sender=''.$$anonhash{$key}.' ';
}
+ $sender = ''.$sender.' ';
# Set up for sorting by domain, then username for anonymous
unless (defined($$usernamesort{'__anon'})) {
%{$$usernamesort{'__anon'}} = ();
@@ -1118,36 +1317,38 @@ 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').' ';
+ } elsif (&Apache::lonnet::allowed('pch',
+ $env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.
+ $env{'request.course.sec'}:''))) {
+ $sender.=' '.&mt('Reply').' ';
}
- $sender .= '" '.$target.'>'.&mt('Reply').'';
}
- }
- if ($viewgrades) {
- $vgrlink=&Apache::loncommon::submlink('Submissions',
- $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
- }
- if ($$dischash{$readkey}=~/\.$idx\./) {
- $ctlink = ''.&mt('Mark unread').'? ';
- } else {
- $ctlink = ''.&mt('Mark read').'? ';
+ if ($viewgrades) {
+ $vgrlink=&Apache::loncommon::submlink(&mt('Submissions'),
+ $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
+ }
+ if ($$dischash{$readkey}=~/\.$idx\./) {
+ $ctlink = ''.&mt('Mark unread').'? ';
+ } else {
+ $ctlink = ''.&mt('Mark read').'? ';
+ }
}
}
#figure out at what position this needs to print
@@ -1164,7 +1365,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 +1387,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) {
@@ -1245,12 +1447,12 @@ sub build_posting_display {
if ($prevread > 0 && $prevread <= $posttime) {
$$newitem{$idx} = 1;
$$discussionitems[$idx] .= '
-
- '.&mt('NEW').' ';
+
+ '.&mt('NEW').' ';
} else {
$$newitem{$idx} = 0;
$$discussionitems[$idx] .= '
-
+
';
}
$$discussionitems[$idx] .= ' '.
@@ -1261,12 +1463,70 @@ sub build_posting_display {
$$discussionitems[$idx].=' '.
$ctlink.' ';
}
+ my $likesize="100";
+ if ($seeid || $canvote) {
+# Figure out size based on likes
+ my $thislikes=$likes{$symb.':'.$idx.':likes'};
+ if ($thislikes>$twoplus) {
+ $likesize="200";
+ } elsif ($thislikes>$oneplus) {
+ $likesize="150";
+ }
+ if ($thislikes<$twominus) {
+ $likesize="50";
+ } elsif ($thislikes<$oneminus) {
+ $likesize="75";
+ }
+ }
+# 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.');
+ }
+ $$discussionitems[$idx].=
+ ''.
+ ' '.
+ ' ';
+ } else {
+ if ($userlikes{$idx}) {
+ $$discussionitems[$idx].=' ';
+ } else {
+ $$discussionitems[$idx].=' '.&discussion_link($symb,' ','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));
+ }
+ if ($userunlikes{$idx}) {
+ $$discussionitems[$idx].=' ';
+ } else {
+ $$discussionitems[$idx].=' '.&discussion_link($symb,' ','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) {
+ if ($seehidden) {
$$discussionitems[$idx] .= ' '.&mt('Display all versions').' ';
@@ -1346,13 +1606,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;
}
@@ -1364,13 +1624,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') {
@@ -1555,6 +1822,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'});
@@ -1563,36 +1831,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'};
}
@@ -1667,10 +1924,26 @@ END
END
+ my ($textareaheader,$textareaclass);
+ if (&Apache::lonhtmlcommon::htmlareabrowser()) {
+ $textareaheader = &Apache::lonhtmlcommon::htmlareaselectactive();
+ $textareaclass = 'class="LC_richDefaultOff"';
+ if ($env{'request.course.id'}) {
+ unless (($env{'course.'.$env{'request.course.id'}.'.allow_limited_html_in_feedback'} =~ /^\s*yes\s*$/i) || ($env{'form.sendmessageonly'})) {
+ undef($textareaclass);
+ }
+ }
+ }
+
+ # Breadcrumbs
+ my $brcrum = [{'href' => '',
+ 'text' => 'Resource Feedback and Discussion'}];
+
my %onload = ('onload' => 'window.focus();setposttype();');
my $start_page=
&Apache::loncommon::start_page('Resource Feedback and Discussion',$js,
- {'add_entries' => \%onload});
+ {'add_entries' => \%onload,
+ 'bread_crumbs' => $brcrum,});
if ($quote ne '') {
$quote = &HTML::Entities::decode($quote);
@@ -1701,14 +1974,16 @@ END
$r->print(<
$quote
-$lt{'myqu'}
+$lt{'myqu'}
+$textareaheader
+
$latexHelp
$lt{'title'}:
-
END
if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
@@ -1786,7 +2061,6 @@ END
}
}
$r->print(&generate_preview_button().
- &Apache::lonhtmlcommon::htmlareaselectactive('comment').
&Apache::loncommon::end_page());
}
@@ -2021,7 +2295,7 @@ sub print_sortfilter_options {
$ccrole = 'co';
}
push(@courseroles,$ccrole);
-
+
if ($env{'request.course.sec'} !~ /^\s*$/) { #Restrict section choice to current section
@sections = ('all',$env{'request.course.sec'});
$numvisible = 2;
@@ -2224,24 +2498,11 @@ sub print_showposters {
$r->send_http_header;
&Apache::lonenc::check_encrypt(\$symb);
- my $crs='/'.$env{'request.course.id'};
- if ($env{'request.course.sec'}) {
- $crs.='_'.$env{'request.course.sec'};
- }
- $crs=~s/\_/\//g;
- my $seeid;
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $group = $env{'form.group'};
my $ressymb = &wrap_symb($symb);
- if (($group ne '') &&
- ($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);
- }
+ my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
$cdom,$cnum);
my %namesort = ();
@@ -2257,7 +2518,7 @@ sub print_showposters {
for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
my $hidden=($contrib{'hidden'}=~/\.$idx\./);
my $deleted=($contrib{'deleted'}=~/\.$idx\./);
- unless ((($hidden) && (!$seeid)) || ($deleted)) {
+ unless ((($hidden) && (!$seehidden)) || ($deleted)) {
if ((!$contrib{$idx.':anonymous'}) || (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
my $lastname = $names{'lastname'};
@@ -2396,7 +2657,7 @@ sub fail_redirect {
my ($r,$feedurl) = @_;
if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
my %lt = &Apache::lonlocal::texthash(
- 'sorr' => 'Sorry, no recipients ...',
+ 'sorr' => 'Sorry, no recipients ...',
);
my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
$r->print(&Apache::loncommon::start_page('Feedback not sent',undef,
@@ -2447,7 +2708,7 @@ sub redirect_back {
$userpicktag = ' ';
} else {
if (ref($sectionpick) eq 'ARRAY') {
- $feedurl .= '§ionpick=';
+ $feedurl .= '§ionpick=';
$sectag .= ' ';
}
if (ref($grouppick) eq 'ARRAY') {
- $feedurl .= '&grouppick=';
+ $feedurl .= '&grouppick=';
$sectag .= ' ';
}
if (ref($rolefilter) eq 'ARRAY') {
- $feedurl .= '&rolefilter=';
+ $feedurl .= '&rolefilter=';
$roletag .= ' ';
} else {
- $feedurl .= '&rolefilter='.$rolefilter;
+ $feedurl .= '&rolefilter='.$rolefilter;
$roletag = ' ';
}
$feedurl .= '&statusfilter='.$statusfilter;
@@ -2543,7 +2804,7 @@ ENDREDIR
sub no_redirect_back {
my ($r,$feedurl) = @_;
- my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
+ my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
my %onload;
if ($env{'environment.remote'} ne 'off') {
@@ -2556,7 +2817,7 @@ sub no_redirect_back {
'add_entries' => \%onload,);
if ($feedurl !~ m{^/adm/feedback}) {
- $body_options{'rediect'} = [2,$feedurl];
+ $body_options{'redirect'} = [2,$feedurl];
}
my $start_page=
&Apache::loncommon::start_page('Feedback not sent',undef,
@@ -2576,7 +2837,7 @@ ENDNOREDIRTWO
}
sub screen_header {
- my ($feedurl,$symb) = @_;
+ my ($feedurl,$symb,$group) = @_;
my $crscontent = &mt('Question/Comment/Feedback about course content');
my $crspolicy = &mt('Question/Comment/Feedback about course policy');
my $contribdisc = &mt('Contribution to course discussion of resource');
@@ -2625,16 +2886,19 @@ sub screen_header {
}
if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards');
- if (!$blocked && &discussion_open(undef,$symb) &&
- &Apache::lonnet::allowed('pch',
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $realsymb = &get_realsymb($symb);
+ if (!$blocked && &discussion_open(undef,$realsymb) &&
+ (&Apache::lonnet::allowed('pch',
$env{'request.course.id'}.
- ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) ||
+ (($group ne '') && ($symb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$}) && (&check_group_priv($group,'pgd') eq 'ok')))) {
$discussoptions=' '.
- $contribdisc.
- ' '.
- $anoncontrib.
- ' ('.$namevis.') '.
-
+ $contribdisc.
+ ' '.
+ $anoncontrib.
+ ' ('.$namevis.') '.
''.&mt('Change Screenname').' ';
my $blockblog = &Apache::loncommon::blocking_status('blogs');
if (!$blockblog) {
@@ -2643,7 +2907,7 @@ sub screen_header {
}
}
if ($msgoptions) {
- $msgoptions=' '
+ $msgoptions=' '
.' '.&mt('Send Feedback').''.&Apache::lonhtmlcommon::coursepreflink(&mt('Feedback Settings'),'feedback').'
'
.$msgoptions;
}
@@ -2669,9 +2933,7 @@ sub resource_output {
}
sub clear_out_html {
- my ($message,$override,$ignore_htmlarea)=@_;
- if (!$ignore_htmlarea
- && !&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
+ my ($message,$override)=@_;
# Always allow the -tag
my %html=(M=>1);
# Check if more is allowed
@@ -2682,11 +2944,10 @@ sub clear_out_html {
#
#
%html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
- BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
- M=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1,
+ BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, PRE=>1, DIV=>1, IMG=>1,
+ M=>1, CHEM=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1,
H1=>1, H2=>1, H3=>1, H4=>1, H5=>1, H6=>1,
TABLE=>1, TR=>1, TD=>1, TH=>1, TBODY=>1);
-
}
# Do the substitution of everything that is not explicitly allowed
$message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
@@ -2703,6 +2964,9 @@ sub assemble_email {
'orig' => 'Original screen output (if applicable)',
'corr' => 'Correct Answer(s) (if applicable)',
);
+ if (&Apache::loncommon::course_type() eq 'Community') {
+ $lt{'prev'} = &mt('Previous attempts of member (if applicable)');
+ }
my $email=<<"ENDEMAIL";
$message
ENDEMAIL
@@ -2767,18 +3031,41 @@ sub send_msg {
return ($status,$sendsomething);
}
+# Store feedback "likes"
+
+sub storefeedbacklikes {
+ my ($likes,$uname,$udom,$course)=@_;
+ unless ($likes) { $likes=0; }
+ if ($likes>0) { $likes=1; }
+ if ($likes<0) { $likes=-1; }
+ unless ($uname) { $uname=$env{'user.name'}; }
+ unless ($udom) { $udom=$env{'user.domain'}; }
+ unless ($course) { $course=$env{'request.course.id'}; }
+ my %record=&getfeedbackrecords($uname,$udom,$course);
+ my $totallikes=$record{'totallikes'};
+ $totallikes+=$likes;
+ my %newrecord=('likes_user' => $env{'user.name'},
+ 'likes_domain' => $env{'user.domain'},
+ 'likes' => $likes,
+ 'totallikes' => $totallikes);
+ return &Apache::lonnet::cstore(\%newrecord,'_feedback',$course,$udom,$uname);
+}
+
sub adddiscuss {
- my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
+ my ($symb,$email,$anon,$attachmenturl,$subject,$group)=@_;
my $status='';
- my $realsymb;
- if ($symb=~/^bulletin___/) {
- my $filename=(&Apache::lonnet::decode_symb($symb))[2];
- $filename=~s|^adm/wrapper/||;
- $realsymb=&Apache::lonnet::symbread($filename);
+ my $realsymb = &get_realsymb($symb);
+ my ($cnum,$cdom);
+ if ($env{'request.course.id'}) {
+ $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
}
+ my $realsymb;
if (&discussion_open(undef,$realsymb) &&
- &Apache::lonnet::allowed('pch',$env{'request.course.id'}.
- ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
+ (&Apache::lonnet::allowed('pch',$env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) ||
+ (($group ne '') && (&check_group_priv($group,'pgd') eq 'ok') &&
+ ($symb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$})))) {
my %contrib=('message' => $email,
'sendername' => $env{'user.name'},
@@ -2858,7 +3145,7 @@ sub adddiscuss {
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
}
- my %record=&Apache::lonnet::restore('_discussion');
+ my %record=&getdiscussionrecords();
my ($temp)=keys(%record);
unless ($temp=~/^error\:/) {
my %newrecord=();
@@ -2866,6 +3153,7 @@ sub adddiscuss {
$newrecord{'subnumber'}=$record{'subnumber'}+1;
$status.=' '.&mt('Registering').': '.
&Apache::lonnet::cstore(\%newrecord,'_discussion');
+ &updatekarma();
}
} else {
$status.='Failed.';
@@ -2873,6 +3161,107 @@ sub adddiscuss {
return $status.' ';
}
+# Routine to get the complete discussion records
+
+sub getdiscussionrecords {
+ my ($uname,$udom,$course)=@_;
+ unless ($uname) { $uname=$env{'user.name'}; }
+ unless ($udom) { $udom=$env{'user.domain'}; }
+ unless ($course) { $course=$env{'request.course.id'}; }
+ my %record=&Apache::lonnet::restore('_discussion',$course,$udom,$uname);
+ return %record;
+}
+
+# Routine to get discussion statistics
+
+sub getdiscussionstats {
+ my %record=&getdiscussionrecords(@_);
+ my $totalvotes = $record{'totallikes'} + $record{'totalunlikes'};
+ return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$totalvotes);
+}
+
+# Calculate discussion karma
+
+sub calcdiscussionkarma {
+ my ($subs,$pts,$likes,$votes)=&getdiscussionstats(@_);
+ my $karma=0;
+ if ($votes>0) {
+ $karma=int(.1+5.*(1.-exp(-$subs/10.))*$likes/$votes);
+ if ($karma<0) { $karma=0; }
+ if ($karma>5) { $karma=5; }
+ }
+ return $karma;
+}
+
+# Update karma
+
+sub updatekarma {
+ my ($uname,$udom,$course)=@_;
+ unless ($uname) { $uname=$env{'user.name'}; }
+ unless ($udom) { $udom=$env{'user.domain'}; }
+ unless ($course) { $course=$env{'request.course.id'}; }
+ my $karma=&calcdiscussionkarma($uname,$udom,$course);
+ &Apache::lonnet::cstore({ 'karma' => $karma },'_discussion',$course,$udom,$uname);
+ &Apache::lonnet::do_cache_new('karma',$uname.':'.$udom.':'.$course,$karma,3600);
+ return $karma;
+}
+
+# Retrieve karma
+
+sub userkarma {
+ my ($uname,$udom,$course)=@_;
+ unless ($uname) { $uname=$env{'user.name'}; }
+ unless ($udom) { $udom=$env{'user.domain'}; }
+ unless ($course) { $course=$env{'request.course.id'}; }
+ my $hashkey=$uname.':'.$udom.':'.$course;
+ my ($karma,$cached)=&Apache::lonnet::is_cached_new('karma',$hashkey);
+ if ($cached) {
+ return $karma;
+ }
+ my %userdisc=&getdiscussionrecords($uname,$udom,$course);
+ $karma=$userdisc{'karma'};
+ &Apache::lonnet::do_cache_new('karma',$hashkey,$karma,3600);
+ return $karma;
+}
+
+# Store discussion credit
+
+sub storediscussionpoints {
+ my ($points,$uname,$udom,$course)=@_;
+ unless ($points) { $points=0; }
+ unless ($uname) { $uname=$env{'user.name'}; }
+ unless ($udom) { $udom=$env{'user.domain'}; }
+ unless ($course) { $course=$env{'request.course.id'}; }
+ my %record=('grader_user' => $env{'user.name'},
+ 'grader_domain' => $env{'user.domain'},
+ 'points' => $points);
+ return &Apache::lonnet::cstore(\%record,'_discussion',$course,$udom,$uname);
+}
+
+# Store discussion "likes"
+
+sub storediscussionlikes {
+ my ($chglikes,$chgunlikes,$uname,$udom,$course,$context)=@_;
+ unless ($uname) { $uname=$env{'user.name'}; }
+ unless ($udom) { $udom=$env{'user.domain'}; }
+ unless ($course) { $course=$env{'request.course.id'}; }
+ my %record=&getdiscussionrecords($uname,$udom,$course);
+ my $totallikes=$record{'totallikes'};
+ my $totalunlikes=$record{'totalunlikes'};
+ $totallikes += $chglikes;
+ $totalunlikes += $chgunlikes;
+ my %newrecord=('likes_user' => $env{'user.name'},
+ 'likes_domain' => $env{'user.domain'},
+ 'totallikes' => $totallikes,
+ 'totalunlikes' => $totalunlikes,
+ 'context' => $context);
+ my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname);
+ if ($status eq 'ok') {
+ &updatekarma($uname,$udom,$course);
+ }
+ return $status;
+}
+
sub get_discussion_info {
my ($idx,%contrib) = @_;
my $changelast = 0;
@@ -2929,7 +3318,7 @@ sub show_preview {
&newline_to_br(\$message);
$message=&Apache::lonspeller::markeduptext($message);
$message=&Apache::lontexconvert::msgtexconverted($message);
- my $subject=&clear_out_html($env{'form.subject'},undef,1);
+ my $subject=&clear_out_html($env{'form.subject'});
$subject=~s/\n/\ /g;
$subject=&Apache::lontexconvert::msgtexconverted($subject);
@@ -2952,17 +3341,29 @@ sub show_preview {
sub contains_block_html {
my ($message)=@_;
return ($message =~ m{
- <(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)
- \s*
- (\w+\=['"]\w+['"])*
- \s*
- (
- \s*/>|
- >.*\1\s*>
- )}xs
+ <(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)
+ \s*
+ (\w+\=['"]\w+['"])*
+ \s*
+ (
+ \s*/>|
+ >.*\1\s*>
+ )}xs
);
}
+sub tidy_html {
+ my ($message)=@_;
+# my $tidy = HTML::Tidy::libXML->new();
+# my $xhtml = $tidy->clean($message, 'utf-8', 1);
+# $xhtml =~ m/(.*)<\/body>/is;
+# my $clean = $1;
+# # remove any empty block-level tags
+# $clean =~ s/<(table|p|div|tbody|blockquote|m|pre|algebra|center|ol|ul|span|h1|h2|h3|h4|h5|h6)\s*\/>//i;
+# $message=$clean;
+ return $message;
+}
+
sub newline_to_br {
my ($message)=@_;
my $newmessage;
@@ -3021,11 +3422,15 @@ sub modify_attachments {
END
+ # Breadcrumbs
+ my $brcrum = [{'href' => '',
+ 'text' => 'Discussion Post Attachments'}];
my $start_page =
- &Apache::loncommon::start_page('Discussion Post Attachments',$js);
+ &Apache::loncommon::start_page('Discussion Post Attachments',$js,
+ {'bread_crumbs' => $brcrum,});
my $orig_subject = &unescape($env{'form.subject'});
- my $subject=&clear_out_html($orig_subject,undef,1);
+ my $subject=&clear_out_html($orig_subject);
$subject=~s/\n/\ /g;
$subject=&Apache::lontexconvert::msgtexconverted($subject);
my $timestamp=$env{'form.timestamp'};
@@ -3148,7 +3553,7 @@ sub generate_attachments_button {