'.
'';
my $escsymb=&escape($ressymb);
- if ($visible) {
+ if ($visible>2) {
$discussion .= ''.&mt('Export').' ';
- if ($seehidden) {
- $discussion .= ' ';
- $discussion .=''.&mt('Undelete all deleted entries').' ';
- }
- $discussion.=' ';
+ $discussion .= '">'.&mt('Export').'? ';
if ($newpostsflag) {
if (!$markondisp) {
$discussion .='
@@ -962,7 +843,7 @@ sub postingform_display {
$lt{'note'}
$lt{'title'}:
-
+
ENDDISCUSS
if ($env{'form.origpage'}) {
$postingform .= ' \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";
+ 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";
}
- $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,$seehidden,$canvote,$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,$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') {
@@ -1062,65 +917,16 @@ 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'})) {
- 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;
- }
-#
-# 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'}) {
@@ -1144,7 +950,7 @@ sub build_posting_display {
} else {
$$replies[$$depth[$idx]]=1;
}
- unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx})) {
+ unless ((($hidden) && (!$seeid)) || ($deleted)) {
$$visible++;
if ($contrib{$idx.':history'}) {
if ($contrib{$idx.':history'} =~ /:/) {
@@ -1159,7 +965,7 @@ sub build_posting_display {
my %subjects = ();
my %attachtxt = ();
my %allattachments = ();
- my ($screenname,$plainname,$showaboutme);
+ my ($screenname,$plainname);
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.
@@ -1169,7 +975,7 @@ sub build_posting_display {
$$anonhash{$key}=&mt('Anonymous').' '.$anoncnt;
}
my ($message,$subject,$vgrlink,$ctlink);
- &get_post_contents(\%contrib,$idx,$seeid,$seehidden,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,\$showaboutme,$numoldver);
+ &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver);
# Set up for sorting by subject
@@ -1178,7 +984,7 @@ sub build_posting_display {
$message.=$attachtxt{$numoldver};
$subject=$subjects{$numoldver};
if ($message) {
- if ($hiddens{$idx}) {
+ if ($hidden) {
$message=''.$message.' ';
if ($studenthidden) {
$message .=' Deleted by poster (student).';
@@ -1199,18 +1005,12 @@ sub build_posting_display {
}
}
if (!$contrib{$idx.':anonymous'} || $see_anonymous) {
- 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=&Apache::loncommon::aboutmewrapper(
+ $plainname,
+ $contrib{$idx.':sendername'},
+ $contrib{$idx.':senderdomain'}).' ('.
+ $contrib{$idx.':sendername'}.':'.
+ $contrib{$idx.':senderdomain'}.')';
$sender = ''.$sender.' ';
if ($contrib{$idx.':anonymous'}) {
$sender.=' ['.$$anonhash{$key}.'] '.
@@ -1248,48 +1048,46 @@ sub build_posting_display {
} else {
@{$$namesort{$lastname}{$firstname}} = ("$idx");
}
- 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').' ';
+ 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 ($seehidden) {
- my $grpargs = &group_args($group);
- $sender.=" ';
- }
+ unless ($seeid) {
+ my $grpargs = &group_args($group);
+ $sender.=" ';
}
}
- if ($seehidden) {
- if ($hiddens{$idx}) {
- unless ($studenthidden) {
- $sender.=' '.&mt('Make Visible').' ';
- }
- } else {
- $sender.=' ';
- }
- my $grpargs = &group_args($group);
- $sender.=
- " ";
- $sender .= &mt('Delete').' ';
- }
+ $sender .= '">'.&mt('Make Visible').'';
+ }
+ } else {
+ $sender.=' '.&mt('Hide').' ';
+ }
+ my $grpargs = &group_args($group);
+ $sender.=
+ " ";
+ $sender .= &mt('Delete').' ';
}
} else {
if ($screenname) {
@@ -1317,38 +1115,36 @@ sub build_posting_display {
@{$$namesort{'__anon'}{'__anon'}} = ("$idx");
}
}
- if ($outputtarget ne 'tex') {
- 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 (&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) {
+ }
+ 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').'? ';
- }
+ $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
@@ -1365,7 +1161,7 @@ sub build_posting_display {
if ($outputtarget eq 'export') {
%{$$imsitems{$idx}} = ();
$$imsitems{$idx}{'isvisible'}='true';
- if ($hiddens{$idx}) {
+ if ($hidden) {
$$imsitems{$idx}{'isvisible'}='false';
}
$$imsitems{$idx}{'title'}=$subjects{$numoldver};
@@ -1387,15 +1183,14 @@ 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
- $uname = $contrib{$idx.':sendername'};
- $udom = $contrib{$idx.':senderdomain'};
+ my $uname = $contrib{$idx.':sendername'};
+ my $udom = $contrib{$idx.':senderdomain'};
my $poster = $uname.':'.$udom;
if ($env{'form.totposters'} ne '') {
if ($totposters == 0) {
@@ -1448,7 +1243,7 @@ sub build_posting_display {
$$newitem{$idx} = 1;
$$discussionitems[$idx] .= '
- '.&mt('NEW').' ';
+ '.&mt('NEW').' ';
} else {
$$newitem{$idx} = 0;
$$discussionitems[$idx] .= '
@@ -1463,70 +1258,12 @@ 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.
- '
';
- 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
+ $message.'';
if ($contrib{$idx.':history'}) {
my @postversions = ();
$$discussionitems[$idx] .= &mt('This post has been edited by the author.');
- if ($seehidden) {
+ if ($seeid) {
$$discussionitems[$idx] .= ' '.&mt('Display all versions').' ';
@@ -1606,13 +1343,13 @@ sub filter_regexp {
sub get_post_contents {
- my ($contrib,$idx,$seeid,$seehidden,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$numver) = @_;
+ my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_;
my $discussion = '';
my $start=$numver;
my $end=$numver + 1;
%{$$imsfiles{$idx}}=();
if ($type eq 'allversions') {
- unless($seehidden) {
+ unless($seeid) {
$discussion=&mt('You do not have privileges to view all versions of posts.').' '.&mt('Please select a different role.');
return $discussion;
}
@@ -1624,20 +1361,13 @@ sub get_post_contents {
$$contrib{$idx.':sendername'},
$$contrib{$idx.':senderdomain'});
$$screenname=$$contrib{$idx.':screenname'};
- $$showaboutme = &Apache::lonnet::usertools_access($$contrib{$idx.':sendername'},
- $$contrib{$idx.':senderdomain'},
- 'aboutme');
- my $sender = $$plainname;
- if ($$showaboutme) {
- $sender = &Apache::loncommon::aboutmewrapper(
+
+ my $sender=&Apache::loncommon::aboutmewrapper(
$$plainname,
$$contrib{$idx.':sendername'},
- $$contrib{$idx.':senderdomain'});
- }
- if ($seeid) {
- $sender .= ' ('.$$contrib{$idx.':sendername'}.':'.
- $$contrib{$idx.':senderdomain'}.')';
- }
+ $$contrib{$idx.':senderdomain'}).' ('.
+ $$contrib{$idx.':sendername'}.':'.
+ $$contrib{$idx.':senderdomain'}.')';
my $attachmenturls = $$contrib{$idx.':attachmenturl'};
my @postversions = ();
if ($type eq 'allversions' || $type eq 'export') {
@@ -1822,7 +1552,6 @@ 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'});
@@ -1831,25 +1560,36 @@ END
$numoldver = 1;
}
}
- if ($idx > 0) {
- my (%msgversions,%subversions,$htmldecode);
- $htmldecode = 0;
- if ($env{'form.replydisc'}) {
- $htmldecode = 1;
+ if ($env{'form.replydisc'}) {
+ if ($contrib{$idx.':history'}) {
+ if ($contrib{$idx.':history'} =~ /:/) {
+ my @oldversions = split(/:/,$contrib{$idx.':history'});
+ $numoldver = @oldversions;
+ } else {
+ $numoldver = 1;
+ }
}
- &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'}) {
+ if ($idx > 0) {
+ my %msgversions = ();
+ &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
$quote = $msgversions{$numoldver};
- $subject = &HTML::Entities::encode(&mt('Re: ').$subject,'<>&"');
- } else {
- $comment = $msgversions{$numoldver};
}
- }
- if ($env{'form.editdisc'}) {
+ 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);
+ $comment = $msgversions{$numoldver};
+ my %subversions = ();
+ &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
+ $subject = $subversions{$numoldver};
+ }
if (defined($contrib{$idx.':replyto'})) {
$parentmsg = $contrib{$idx.':replyto'};
}
@@ -1924,17 +1664,6 @@ 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'}];
@@ -1974,16 +1703,14 @@ END
$r->print(<
$quote
-$lt{'myqu'}
-$textareaheader
-
+$lt{'myqu'}
$latexHelp
$lt{'title'}:
-
END
if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
@@ -2061,6 +1788,7 @@ END
}
}
$r->print(&generate_preview_button().
+ &Apache::lonhtmlcommon::htmlareaselectactive('comment').
&Apache::loncommon::end_page());
}
@@ -2498,11 +2226,24 @@ 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);
- my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
+ 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 %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
$cdom,$cnum);
my %namesort = ();
@@ -2518,7 +2259,7 @@ sub print_showposters {
for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
my $hidden=($contrib{'hidden'}=~/\.$idx\./);
my $deleted=($contrib{'deleted'}=~/\.$idx\./);
- unless ((($hidden) && (!$seehidden)) || ($deleted)) {
+ unless ((($hidden) && (!$seeid)) || ($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'};
@@ -2770,10 +2511,6 @@ sub redirect_back {
&Apache::lonenc::check_encrypt(\$feedurl);
my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
my %onload;
- if ($env{'environment.remote'} ne 'off') {
- $onload{'onload'} =
- "if (window.name!='loncapaclient') { this.document.reldt.submit(); self.window.close(); }";
- }
my $start_page=
&Apache::loncommon::start_page('Feedback sent',undef,
{'redirect' => [0,$feedurl],
@@ -2807,17 +2544,13 @@ sub no_redirect_back {
my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
my %onload;
- if ($env{'environment.remote'} ne 'off') {
- $onload{'onload'} =
- "if (window.name!='loncapaclient') { self.window.close(); }";
- }
my %body_options = ('only_body' => 1,
'bgcolor' => '#FFFFFF',
'add_entries' => \%onload,);
if ($feedurl !~ m{^/adm/feedback}) {
- $body_options{'redirect'} = [2,$feedurl];
+ $body_options{'rediect'} = [2,$feedurl];
}
my $start_page=
&Apache::loncommon::start_page('Feedback not sent',undef,
@@ -2837,7 +2570,7 @@ ENDNOREDIRTWO
}
sub screen_header {
- my ($feedurl,$symb,$group) = @_;
+ my ($feedurl,$symb) = @_;
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');
@@ -2886,14 +2619,10 @@ sub screen_header {
}
if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards');
- 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',
+ if (!$blocked && &discussion_open(undef,$symb) &&
+ &Apache::lonnet::allowed('pch',
$env{'request.course.id'}.
- ($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')))) {
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
$discussoptions=' '.
$contribdisc.
' '.
@@ -2907,7 +2636,7 @@ sub screen_header {
}
}
if ($msgoptions) {
- $msgoptions=' '
+ $msgoptions=' '
.' '.&mt('Send Feedback').''.&Apache::lonhtmlcommon::coursepreflink(&mt('Feedback Settings'),'feedback').'
'
.$msgoptions;
}
@@ -2933,7 +2662,9 @@ sub resource_output {
}
sub clear_out_html {
- my ($message,$override)=@_;
+ my ($message,$override,$ignore_htmlarea)=@_;
+ if (!$ignore_htmlarea
+ && !&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
# Always allow the -tag
my %html=(M=>1);
# Check if more is allowed
@@ -2944,8 +2675,8 @@ 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, PRE=>1, DIV=>1, IMG=>1,
- M=>1, CHEM=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>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, H6=>1,
TABLE=>1, TR=>1, TD=>1, TH=>1, TBODY=>1);
}
@@ -3031,41 +2762,18 @@ 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,$group)=@_;
+ my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
my $status='';
- 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 ($symb=~/^bulletin___/) {
+ my $filename=(&Apache::lonnet::decode_symb($symb))[2];
+ $filename=~s|^adm/wrapper/||;
+ $realsymb=&Apache::lonnet::symbread($filename);
+ }
if (&discussion_open(undef,$realsymb) &&
- (&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$})))) {
+ &Apache::lonnet::allowed('pch',$env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
my %contrib=('message' => $email,
'sendername' => $env{'user.name'},
@@ -3145,7 +2853,7 @@ sub adddiscuss {
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
}
- my %record=&getdiscussionrecords();
+ my %record=&Apache::lonnet::restore('_discussion');
my ($temp)=keys(%record);
unless ($temp=~/^error\:/) {
my %newrecord=();
@@ -3153,7 +2861,6 @@ sub adddiscuss {
$newrecord{'subnumber'}=$record{'subnumber'}+1;
$status.=' '.&mt('Registering').': '.
&Apache::lonnet::cstore(\%newrecord,'_discussion');
- &updatekarma();
}
} else {
$status.='Failed.';
@@ -3161,107 +2868,6 @@ 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;
@@ -3318,7 +2924,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'});
+ my $subject=&clear_out_html($env{'form.subject'},undef,1);
$subject=~s/\n/\ /g;
$subject=&Apache::lontexconvert::msgtexconverted($subject);
@@ -3430,7 +3036,7 @@ END
{'bread_crumbs' => $brcrum,});
my $orig_subject = &unescape($env{'form.subject'});
- my $subject=&clear_out_html($orig_subject);
+ my $subject=&clear_out_html($orig_subject,undef,1);
$subject=~s/\n/\ /g;
$subject=&Apache::lontexconvert::msgtexconverted($subject);
my $timestamp=$env{'form.timestamp'};
@@ -3788,16 +3394,14 @@ sub handler {
# --------------------------- Get query string for limited number of parameters
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['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']);
+ ['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']);
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'},$group))) {
+ if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) {
my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
my $feedurl=&Apache::lonnet::clutter($url);
@@ -3846,24 +3450,36 @@ 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, my $feedurl)=&get_feedurl_and_clean_symb($symb);
+ ($symb)=&get_feedurl_and_clean_symb($symb);
my $ressymb = &wrap_symb($symb);
+ my $group = $env{'form.group'};
my $seeid;
- if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
- $seeid = 1;
+ 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);
if ($idx > 0) {
my %messages = ();
my %subjects = ();
my %attachmsgs = ();
my %allattachments = ();
my %imsfiles = ();
- my ($screenname,$plainname,$showaboutme);
+ my ($screenname,$plainname);
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
- $cdom,$cnum);
- $r->print(&get_post_contents(\%contrib,$idx,$seeid,$seehidden,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname,\$showaboutme));
+ $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));
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -3936,10 +3552,6 @@ sub handler {
$r->send_http_header;
my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
my %onload;
- if ($env{'environment.remote'} ne 'off') {
- $onload{'onload'} =
- "if (window.name!='loncapaclient') { this.document.reldt.submit(); self.window.close(); }";
- }
my $start_page=
&Apache::loncommon::start_page('New posts marked as read',undef,
@@ -4005,32 +3617,37 @@ 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 $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,);
+ 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,);
return OK;
}
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
- $cdom,$cnum);
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
my $currenthidden=$contrib{'hidden'};
my $currentstudenthidden=$contrib{'studenthidden'};
if ($env{'form.hide'}) {
$currenthidden.='.'.$idx.'.';
- unless ($seehidden) {
+ unless ($seeid) {
$currentstudenthidden.='.'.$idx.'.';
}
} else {
$currenthidden=~s/\.$idx\.//g;
}
my %newhash=('hidden' => $currenthidden);
- if ( ($env{'form.hide'}) && (!$seehidden) ) {
+ if ( ($env{'form.hide'}) && (!$seeid) ) {
$newhash{'studenthidden'} = $currentstudenthidden;
}
if ($env{'form.hide'}) {
@@ -4039,195 +3656,16 @@ ENDREDIR
($changelast,$newlast) = &get_discussion_info($idx,%contrib);
if ($changelast) {
&Apache::lonnet::put('discussiontimes',{$symb => $newlast},
- $cdom,$cnum);
+ $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);
+ &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
- }
- $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,
+ &redirect_back($r,$feedurl,&mt('Changed discussion status').' ',
+ '0','0','','',$env{'form.previous'},undef,undef,undef,
undef,undef,undef,$group);
return OK;
} elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) {
@@ -4247,50 +3685,20 @@ 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'},
- $cdom,$cnum);
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
my ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
if ($changelast) {
&Apache::lonnet::put('discussiontimes',{$symb => $newlast},
- $cdom,$cnum);
+ $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
}
my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
-
- 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,
+ &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,
undef,undef,undef,$group);
return OK;
} elsif ($env{'form.preview'}) {
@@ -4318,7 +3726,8 @@ ENDREDIR
my $idx = $env{'form.idx'};
if ($idx) {
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
- $cdom,$cnum);
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
$attachmenturls = $contrib{$idx.':attachmenturl'};
}
&modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
@@ -4342,55 +3751,6 @@ 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'};
@@ -4405,7 +3765,7 @@ ENDREDIR
} elsif ($env{'form.editdisc'}) {
$symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
} elsif ($env{'form.origpage'}) {
- $symb="";
+ $symb="";
} else {
$symb=&Apache::lonnet::symbread($feedurl);
}
@@ -4458,7 +3818,7 @@ ENDREDIR
return OK;
}
}
- my $options=&screen_header($feedurl,$symb,$group);
+ my $options=&screen_header($feedurl,$symb);
if ($options) {
&mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'});
} else {
@@ -4514,12 +3874,7 @@ ENDREDIR
}
}
# Filter HTML out of message (could be nasty)
- my $override;
- if ($env{'form.discuss'} =~ /^(?:author|question|course|policy)$/) {
- $override = 1;
- }
- my $message=&clear_out_html($env{'form.comment'},$override);
-
+ my $message=&clear_out_html($env{'form.comment'});
# Assemble email
my ($email,$citations)=&assemble_email($message,$prevattempts,
@@ -4529,7 +3884,8 @@ ENDREDIR
my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl);
# Actually send mail
- my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}),
+ my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'},
+ undef,1),
$feedurl,$email,$citations,
$attachmenturl,$usersymb,%to);
@@ -4538,10 +3894,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'});
+ my $subject = &clear_out_html($env{'form.subject'},undef,1);
my $anonmode=($env{'form.discuss'} eq 'anon' || $env{'form.anondiscuss'} );
$typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl,
- $subject,$group);
+ $subject);
$numpost++;
}
@@ -4549,7 +3905,7 @@ ENDREDIR
my $blog='';
if ($env{'form.blog'}) {
- my $subject = &clear_out_html($env{'form.subject'});
+ my $subject = &clear_out_html($env{'form.subject'},undef,1);
$status.=&Apache::lonrss::addentry($env{'user.name'},
$env{'user.domain'},
'CourseBlog_'.$env{'request.course.id'},
@@ -4585,7 +3941,6 @@ sub wrap_symb {
}
return $ressymb;
}
-
sub dewrapper {
my ($feedurl)=@_;
if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
@@ -4739,16 +4094,8 @@ 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()