'.
'';
my $escsymb=&escape($ressymb);
- if ($visible>2) {
+ if ($visible) {
$discussion .= ''.&mt('Export').'? ';
+ $discussion .= '">'.&mt('Export').'';
+ if ($seehidden) {
+ $discussion .= ' ';
+ $discussion .=''.&mt('Undelete all deleted entries').' ';
+ }
+ $discussion.='';
if ($newpostsflag) {
if (!$markondisp) {
$discussion .='
@@ -847,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,$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') {
@@ -921,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'}) {
@@ -954,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'} =~ /:/) {
@@ -969,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.
@@ -979,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
@@ -988,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).';
@@ -1009,12 +1199,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;
@@ -1051,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) {
@@ -1098,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'}} = ();
@@ -1117,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
@@ -1163,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};
@@ -1185,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,7 +1448,7 @@ sub build_posting_display {
$$newitem{$idx} = 1;
$$discussionitems[$idx] .= '
- '.&mt('NEW').' ';
+ '.&mt('NEW').' ';
} else {
$$newitem{$idx} = 0;
$$discussionitems[$idx] .= '
@@ -1254,18 +1457,76 @@ sub build_posting_display {
}
$$discussionitems[$idx] .= ' '.
''.$subject.' '.
- ''.$sender.' '.$vgrlink.' ('.
+ $sender.' '.$vgrlink.' ('.
&Apache::lonlocal::locallocaltime($posttime).') ';
if ($$dischash{$toggkey}) {
$$discussionitems[$idx].=' '.
$ctlink.' ';
}
+ if ($seeid || $canvote) {
+# Figure out size based on likes
+ my $thislikes=$likes{$symb.':'.$idx.':likes'};
+ my $likesize="100";
+ 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').' ';
@@ -1345,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;
}
@@ -1363,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') {
@@ -1396,7 +1664,9 @@ sub get_post_contents {
my ($timesent,$attachmsg);
my %currattach = ();
$timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
- &newline_to_br(\$messages->{$i});
+ unless (&contains_block_html($messages->{$i})) {
+ &newline_to_br(\$messages->{$i});
+ }
$$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
$$subjects{$i}=~s/\n/\ /g;
$$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
@@ -1410,7 +1680,7 @@ sub get_post_contents {
foreach my $key (sort(keys(%currattach))) {
if ($$allattachments{$key}{'filename'} =~ m-^/uploaded/([^/]+/[^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
my $fname = $1.$3.'/'.$4;
- $$imsfiles{$idx}{$i} .= ''."\n";
+ $$imsfiles{$idx}{$i} .= ' '."\n";
$$attachtxt{$i}.= ''.$4.' ';
}
}
@@ -1552,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'});
@@ -1560,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'};
}
@@ -1664,6 +1924,17 @@ 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'}];
@@ -1675,7 +1946,10 @@ END
'bread_crumbs' => $brcrum,});
if ($quote ne '') {
- &newline_to_br(\$quote);
+ $quote = &HTML::Entities::decode($quote);
+ unless (&contains_block_html($quote)) {
+ &newline_to_br(\$quote);
+ }
$quote=''.&Apache::lontexconvert::msgtexconverted($quote).' ';
}
@@ -1700,16 +1974,17 @@ END
$r->print(<
$quote
-$lt{'myqu'}
+$lt{'myqu'}
+$textareaheader
+
$latexHelp
$lt{'title'}:
-
-
END
if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
if ($env{'form.origpage'}) {
@@ -1731,6 +2006,7 @@ END
}
} else {
$r->print(<
$lt{'atta'} $attachmaxtext:
END
@@ -1785,7 +2061,6 @@ END
}
}
$r->print(&generate_preview_button().
- &Apache::lonhtmlcommon::htmlareaselectactive('comment').
&Apache::loncommon::end_page());
}
@@ -2223,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 = ();
@@ -2256,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'};
@@ -2395,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,
@@ -2542,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') {
@@ -2555,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,
@@ -2575,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');
@@ -2624,10 +2886,14 @@ 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.
' '.
@@ -2641,12 +2907,12 @@ sub screen_header {
}
}
if ($msgoptions) {
- $msgoptions=' '
+ $msgoptions=' '
.' '.&mt('Send Feedback').''.&Apache::lonhtmlcommon::coursepreflink(&mt('Feedback Settings'),'feedback').'
'
.$msgoptions;
}
if ($discussoptions) {
- $discussoptions=' '
+ $discussoptions=' '
.' '.&mt('Discussion Contributions').''.&Apache::lonhtmlcommon::coursepreflink(&mt('Discussion Settings'),'discussion').'
'
.$discussoptions;
}
@@ -2667,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
@@ -2678,11 +2942,12 @@ sub clear_out_html {
($override)) {
# allows
#
- #
+ #
%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,
- H1=>1, H2=>1, H3=>1, H4=>1, H5=>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+)[^\>\<]*)/
@@ -2766,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'},
@@ -2857,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=();
@@ -2865,6 +3153,7 @@ sub adddiscuss {
$newrecord{'subnumber'}=$record{'subnumber'}+1;
$status.=' '.&mt('Registering').': '.
&Apache::lonnet::cstore(\%newrecord,'_discussion');
+ &updatekarma();
}
} else {
$status.='Failed.';
@@ -2872,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;
@@ -2928,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);
@@ -2949,18 +3339,31 @@ 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
+ );
+}
+
+sub tidy_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]*>
- )/x );
+# 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;
@@ -3027,7 +3430,7 @@ END
{'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'};
@@ -3385,14 +3788,16 @@ sub handler {
# --------------------------- Get query string for limited number of parameters
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']);
+ ['like','unlike','hide','unhide','deldisc','undeleteall','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']);
my $group = $env{'form.group'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my %attachmax = (
text => &mt('(128 KB max size)'),
num => 131072,
);
if ($env{'form.editdisc'}) {
- if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) {
+ if (!(&editing_allowed($env{'form.editdisc'},$group))) {
my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
my $feedurl=&Apache::lonnet::clutter($url);
@@ -3441,36 +3846,24 @@ sub handler {
{'bread_crumbs' => $brcrum,})
);
- my $crs='/'.$env{'request.course.id'};
- if ($env{'request.course.sec'}) {
- $crs.='_'.$env{'request.course.sec'};
- }
- $crs=~s|_|/|g;
- my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my ($symb,$idx)=split(/\:\:\:/,$env{'form.allversions'});
- ($symb)=&get_feedurl_and_clean_symb($symb);
+ ($symb, my $feedurl)=&get_feedurl_and_clean_symb($symb);
my $ressymb = &wrap_symb($symb);
- my $group = $env{'form.group'};
my $seeid;
- 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);
+ if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
+ $seeid = 1;
}
+ my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
if ($idx > 0) {
my %messages = ();
my %subjects = ();
my %attachmsgs = ();
my %allattachments = ();
my %imsfiles = ();
- my ($screenname,$plainname);
+ my ($screenname,$plainname,$showaboutme);
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
- $r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname));
+ $cdom,$cnum);
+ $r->print(&get_post_contents(\%contrib,$idx,$seeid,$seehidden,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname,\$showaboutme));
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -3612,37 +4005,32 @@ ENDREDIR
my $entry=$env{'form.hide'}?$env{'form.hide'}:$env{'form.unhide'};
my ($symb,$idx)=split(/\:\:\:/,$entry);
($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
+ my $ressymb = &wrap_symb($symb);
- my $crs='/'.$env{'request.course.id'};
- if ($env{'request.course.sec'}) {
- $crs.='_'.$env{'request.course.sec'};
- }
- $crs=~s/\_/\//g;
- my $seeid=&Apache::lonnet::allowed('rin',$crs);
-
- if ($env{'form.hide'} && !$seeid && !(&editing_allowed($env{'form.hide'},$env{'form.group'}))) {
- &redirect_back($r,$feedurl,&mt('Deletion not permitted').' ', '0','0','','',$env{'form.previous'},'','','','',
- undef,undef,$group,);
+ my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
+ unless (($seehidden) || (&editing_allowed($env{'form.hide'},$group))) {
+ &redirect_back($r,$feedurl,&mt('Hiding not permitted').' ',
+ '0','0','','',$env{'form.previous'},'','','','',
+ undef,undef,$group,);
return OK;
}
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
+ $cdom,$cnum);
my $currenthidden=$contrib{'hidden'};
my $currentstudenthidden=$contrib{'studenthidden'};
if ($env{'form.hide'}) {
$currenthidden.='.'.$idx.'.';
- unless ($seeid) {
+ unless ($seehidden) {
$currentstudenthidden.='.'.$idx.'.';
}
} else {
$currenthidden=~s/\.$idx\.//g;
}
my %newhash=('hidden' => $currenthidden);
- if ( ($env{'form.hide'}) && (!$seeid) ) {
+ if ( ($env{'form.hide'}) && (!$seehidden) ) {
$newhash{'studenthidden'} = $currentstudenthidden;
}
if ($env{'form.hide'}) {
@@ -3651,16 +4039,195 @@ ENDREDIR
($changelast,$newlast) = &get_discussion_info($idx,%contrib);
if ($changelast) {
&Apache::lonnet::put('discussiontimes',{$symb => $newlast},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
+ $cdom,$cnum);
}
}
- &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
+ my $result;
+ if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
+ $cdom,$cnum) eq 'ok') {
+ my $prefix=$symb.':'.$idx.':';
+ my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,
+ '^'.$prefix);
+ my ($totallikes,$totalunlikes);
+ if (ref($likes{$prefix.'likers'}) eq 'HASH') {
+ $totallikes = scalar(keys(%{$likes{$prefix.'likers'}}));
+ }
+ if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
+ $totalunlikes = scalar(keys(%{$likes{$prefix.'unlikers'}}));
+ }
+ if ($totallikes || $totalunlikes) {
+ my ($chglikes,$chgunlikes,$context);
+ if ($env{'form.hide'}) {
+ $chglikes = -1 * $totallikes;
+ $chgunlikes = -1 * $totalunlikes;
+ $context = 'hide';
+ } else {
+ $chglikes = $totallikes;
+ $chgunlikes = $totalunlikes;
+ $context = 'unhide';
+ }
+ &storediscussionlikes($chglikes,$chgunlikes,
+ $contrib{$idx.':sendername'},
+ $contrib{$idx.':senderdomain'},
+ $env{'request.course.id'},
+ $context);
- &redirect_back($r,$feedurl,&mt('Changed discussion status').' ',
- '0','0','','',$env{'form.previous'},undef,undef,undef,
+ }
+ $result = &mt('Changed discussion status');
+ } else {
+ $result = &mt('Discussion status unchanged');
+ }
+ &redirect_back($r,$feedurl,$result.' ','0','0','','',
+ $env{'form.previous'},undef,undef,undef,
+ undef,undef,undef,$group);
+ return OK;
+ } elsif (($env{'form.like'}) || ($env{'form.unlike'})) {
+# ----------------------------------------------------------------- Like/unlike
+ my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'};
+ my ($symb,$idx)=split(/\:\:\:/,$entry);
+ ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
+ my $result;
+ if ($idx > 0) {
+ my $realsymb = &get_realsymb($symb);
+ my $status='OPEN';
+ if ($Apache::lonhomework::parsing_a_problem ||
+ $Apache::lonhomework::parsing_a_task) {
+ $status=$Apache::inputtags::status[-1];
+ }
+ if (&discussion_vote_available($status,$realsymb)) {
+ my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
+ $cdom,$cnum);
+ my $ownpost;
+ if (($contrib{$idx.':sendername'} eq $env{'user.name'}) &&
+ ($contrib{$idx.':senderdomain'} eq $env{'user.domain'})) {
+ $ownpost = 1;
+ }
+ if ($ownpost || $contrib{$idx.':hidden'} || $contrib{$idx.':deleted'}) {
+ $result = &mt('Vote not registered.').' ';
+ }
+ if ($ownpost) {
+ $result .= &mt('No voting for your own posts.');
+ } elsif ($contrib{$idx.':hidden'}) {
+ $result .= &mt('No voting for hidden posts.');
+ } elsif ($contrib{$idx.':deleted'}) {
+ $result .= &mt('No voting for deleted posts.');
+ } else {
+#
+# Likes and unlikes are in db-file "disclikes" of the course
+# The prefix is the $symb to identify the resource discussion,
+# and the $idx to identify the entry
+#
+ my $prefix=$symb.':'.$idx.':';
+ my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,
+ '^'.$prefix);
+
+# Get current like or unlike status for the $idx for this user.
+ my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
+ my ($userlikes,$userunlikes);
+ if (ref($likes{$prefix.'likers'}) eq 'HASH') {
+ if (exists($likes{$prefix.'likers'}{$thisuser})) {
+ $userlikes = 1;
+ }
+ }
+ if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
+ if (exists($likes{$prefix.'unlikers'}{$thisuser})) {
+ $userunlikes = 1;
+ }
+ }
+# Get the current "likes" count
+ my $likescount=$likes{$prefix.'likes'};
+# Find out if they already voted
+# Users cannot like a post twice, or unlike it twice.
+# They can change their mind, though.
+ my $alreadyflag=0;
+ my $votetype;
+ if ($env{'form.like'}) {
+ if ($userlikes) {
+ $alreadyflag=1;
+ } elsif ($userunlikes) {
+ delete($likes{$prefix.'unlikers'}{$thisuser});
+ $votetype = 'switch';
+ $likescount++;
+ } else {
+ if (ref($likes{$prefix.'likers'}) eq 'HASH') {
+ $likes{$prefix.'likers'}{$thisuser} = 1;
+ } else {
+ $likes{$prefix.'likers'} = {$thisuser => 1};
+ }
+ $likescount++;
+ }
+ } else {
+ if ($userunlikes) {
+ $alreadyflag=1;
+ } elsif ($userlikes) {
+ delete($likes{$prefix.'likers'}{$thisuser});
+ $votetype = 'switch';
+ $likescount--;
+ } else {
+ if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
+ $likes{$prefix.'unlikers'}{$thisuser} = 1;
+ } else {
+ $likes{$prefix.'unlikers'} = {$thisuser => 1};
+ }
+ $likescount--;
+ }
+ }
+# $alreadyflag would be 1 if they tried to double-like or double-unlike
+ if ($alreadyflag) {
+ if ($env{'form.like'}) {
+ $result= &mt("'Like' already registered");
+ } else {
+ $result= &mt("'Unlike' already registered");
+ }
+ } else {
+ my %newhash=($prefix.'likes' => $likescount,
+ $prefix.'likers' => $likes{$prefix.'likers'},
+ $prefix.'unlikers' => $likes{$prefix.'unlikers'});
+# Store data in db-file "disclikes"
+ if (&Apache::lonnet::put('disclikes',\%newhash,$cdom,$cnum) eq 'ok') {
+# Also store with the person who posted the liked/unliked entry
+ my ($chglike,$chgunlike);
+ if ($env{'form.like'}) {
+ if ($votetype eq 'switch') {
+ $chglike = 0;
+ $chgunlike = -1;
+ } else {
+ $chglike = 1;
+ $chgunlike = 0;
+ }
+ &storediscussionlikes($chglike,$chgunlike,
+ $contrib{$idx.':sendername'},
+ $contrib{$idx.':senderdomain'},
+ $env{'request.course.id'},'like');
+ $result=&mt("Registered 'Like'");
+ } else {
+ if ($votetype eq 'switch') {
+ $chglike = -1;
+ $chgunlike = 0;
+ } else {
+ $chglike = 0;
+ $chgunlike = 1;
+ }
+ &storediscussionlikes($chglike,$chgunlike,
+ $contrib{$idx.':sendername'},
+ $contrib{$idx.':senderdomain'},
+ $env{'request.course.id'},'unlike');
+ $result=&mt("Registered 'Unlike'");
+ }
+ } else {
+# Oops, something went wrong
+ $result=&mt("Failed to register vote");
+ }
+ }
+ }
+ } else {
+ $result=&mt('Voting unavailable for this discussion');
+ }
+ } else {
+ $result=&mt('Invalid post number');
+ }
+ &redirect_back($r,$feedurl,$result.' ',
+ '0','0','','',$env{'form.previous'},undef,undef,undef,
undef,undef,undef,$group);
return OK;
} elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) {
@@ -3680,20 +4247,50 @@ ENDREDIR
# --------------------------------------------------------------- Hide for good
my ($symb,$idx)=split(/\:\:\:/,$env{'form.deldisc'});
($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
+ my $ressymb=&wrap_symb($symb);
+ unless (&can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum)) {
+ &redirect_back($r,$feedurl,&mt('Deletion not permitted').' ',
+ '0','0','','',$env{'form.previous'},'','','','',
+ undef,undef,$group);
+ return OK;
+ }
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
+ $cdom,$cnum);
my ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
if ($changelast) {
&Apache::lonnet::put('discussiontimes',{$symb => $newlast},
- $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
+ $cdom,$cnum);
}
my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
- &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
- &redirect_back($r,$feedurl,&mt('Changed discussion status').' ',
- '0','0','','',$env{'form.previous'},undef,undef,undef,
+
+ my $result;
+ if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
+ $cdom,$cnum) eq 'ok') {
+ $result = &mt('Changed discussion status');
+ my $prefix=$symb.':'.$idx.':';
+ my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,
+ '^'.$prefix);
+ my ($totallikes,$totalunlikes);
+ if (ref($likes{$prefix.'likers'}) eq 'HASH') {
+ $totallikes = scalar(keys(%{$likes{$prefix.'likers'}}));
+ }
+ if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
+ $totalunlikes = scalar(keys(%{$likes{$prefix.'unlikers'}}));
+ }
+ if ($totallikes || $totalunlikes) {
+ my $chglikes = -1 * $totallikes;
+ my $chgunlikes = -1 * $totalunlikes;
+ &storediscussionlikes($chglikes,$chgunlikes,
+ $contrib{$idx.':sendername'},
+ $contrib{$idx.':senderdomain'},
+ $env{'request.course.id'},
+ 'delete');
+ }
+ } else {
+ $result = &mt('Discussion status unchanged');
+ }
+ &redirect_back($r,$feedurl,$result.' ','0','0','','',
+ $env{'form.previous'},undef,undef,undef,
undef,undef,undef,$group);
return OK;
} elsif ($env{'form.preview'}) {
@@ -3721,8 +4318,7 @@ ENDREDIR
my $idx = $env{'form.idx'};
if ($idx) {
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
+ $cdom,$cnum);
$attachmenturls = $contrib{$idx.':attachmenturl'};
}
&modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
@@ -3746,6 +4342,55 @@ ENDREDIR
&Apache::loncommon::end_page();
$r->print($start_page.$discussion.$end_page);
return OK;
+ } elsif ($env{'form.undeleteall'}) {
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+ my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.undeleteall'});
+ my $ressymb=&wrap_symb($symb);
+ $r->print(&Apache::loncommon::start_page('Undelete all deleted discussion entries'));
+ if (&can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum)) {
+ my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
+ $cdom,$cnum);
+ $contrib{'deleted'} =~ s/^\.//;
+ $contrib{'deleted'} =~ s/\.$//;
+ if ($contrib{'deleted'} ne '') {
+ if (&Apache::lonnet::store({'deleted' => ''},$symb,$env{'request.course.id'},
+ $cdom,$cnum) eq 'ok') {
+ my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,'^'.$symb.':');
+ my @ids = split(/\.\./,$contrib{'deleted'});
+ my (%chglikes,%chgunlikes);
+ foreach my $idx (@ids) {
+ my $uname = $contrib{$idx.':sendername'};
+ my $udom = $contrib{$idx.':senderdomain'};
+ my ($totallikes,$totalunlikes);
+ if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') {
+ $totallikes = scalar(keys(%{$likes{$symb.':'.$idx.':likers'}}));
+ }
+ if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') {
+ $totalunlikes = scalar(keys(%{$likes{$symb.':'.$idx.':unlikers'}}));
+ }
+ if ($totallikes || $totalunlikes) {
+ $chglikes{$uname.':'.$udom} += $totallikes;
+ $chgunlikes{$uname.':'.$udom} += $totalunlikes;
+ }
+ }
+ foreach my $user (keys(%chglikes)) {
+ my ($uname,$udom) = split(/:/,$user);
+ &storediscussionlikes($chglikes{$user},$chgunlikes{$user},
+ $uname,$udom,$env{'request.course.id'},
+ 'undelete');
+ }
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries")));
+ } else {
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1));
+ }
+ } else {
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("No entries to undelete"),1));
+ }
+ $r->print("".&mt("Return and reload")." ");
+ }
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
} else {
# ------------------------------------------------------------- Normal feedback
my $feedurl=$env{'form.postdata'};
@@ -3760,7 +4405,7 @@ ENDREDIR
} elsif ($env{'form.editdisc'}) {
$symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
} elsif ($env{'form.origpage'}) {
- $symb="";
+ $symb="";
} else {
$symb=&Apache::lonnet::symbread($feedurl);
}
@@ -3813,7 +4458,7 @@ ENDREDIR
return OK;
}
}
- my $options=&screen_header($feedurl,$symb);
+ my $options=&screen_header($feedurl,$symb,$group);
if ($options) {
&mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'});
} else {
@@ -3869,7 +4514,12 @@ ENDREDIR
}
}
# Filter HTML out of message (could be nasty)
- my $message=&clear_out_html($env{'form.comment'});
+ my $override;
+ if ($env{'form.discuss'} =~ /^(?:author|question|course|policy)$/) {
+ $override = 1;
+ }
+ my $message=&clear_out_html($env{'form.comment'},$override);
+
# Assemble email
my ($email,$citations)=&assemble_email($message,$prevattempts,
@@ -3879,8 +4529,7 @@ ENDREDIR
my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl);
# Actually send mail
- my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'},
- undef,1),
+ my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}),
$feedurl,$email,$citations,
$attachmenturl,$usersymb,%to);
@@ -3889,10 +4538,10 @@ ENDREDIR
if ( ($env{'form.discuss'} ne ''
&& $env{'form.discuss'} !~ /^(?:author|question|course|policy)/)
|| $env{'form.anondiscuss'} ne '') {
- my $subject = &clear_out_html($env{'form.subject'},undef,1);
+ my $subject = &clear_out_html($env{'form.subject'});
my $anonmode=($env{'form.discuss'} eq 'anon' || $env{'form.anondiscuss'} );
$typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl,
- $subject);
+ $subject,$group);
$numpost++;
}
@@ -3900,7 +4549,7 @@ ENDREDIR
my $blog='';
if ($env{'form.blog'}) {
- my $subject = &clear_out_html($env{'form.subject'},undef,1);
+ my $subject = &clear_out_html($env{'form.subject'});
$status.=&Apache::lonrss::addentry($env{'user.name'},
$env{'user.domain'},
'CourseBlog_'.$env{'request.course.id'},
@@ -3936,6 +4585,7 @@ sub wrap_symb {
}
return $ressymb;
}
+
sub dewrapper {
my ($feedurl)=@_;
if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
@@ -4089,8 +4739,16 @@ None
=item discussion_visible()
+=item discussion_vote_available()
+
+=item get_realsymb()
+
=item list_discussion()
+=item can_see_hidden()
+
+=item discussion_link()
+
=item send_feedback_link()
=item send_message_link()
@@ -4145,6 +4803,8 @@ None
=item newline_to_br()
+=item tidy_html()
+
=item generate_preview_button()
=item modify_attachments()