--- loncom/interface/lonfeedback.pm 2012/03/07 01:26:48 1.290.2.7.2.2
+++ loncom/interface/lonfeedback.pm 2012/05/01 15:56:16 1.290.2.7.2.5
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.290.2.7.2.2 2012/03/07 01:26:48 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.290.2.7.2.5 2012/05/01 15:56:16 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -82,6 +82,26 @@ sub discussion_visible {
return 1;
}
+sub discussion_vote_available {
+ my ($status,$symb)=@_;
+ my $canvote=&Apache::lonnet::EXT('resource.0.discussvote',$symb);
+ if ((lc($canvote) eq 'yes') ||
+ ((lc($canvote) eq 'notended') && (&discussion_open($status,$symb)))) {
+ return 1;
+ }
+}
+
+sub get_realsymb {
+ my ($symb) = @_;
+ my $realsymb = $symb;
+ if ($symb=~/^bulletin___/) {
+ my $filename=(&Apache::lonnet::decode_symb($symb))[2];
+ $filename=~s{^adm/wrapper/}{};
+ $realsymb=&Apache::lonnet::symbread($filename);
+ }
+ return $realsymb;
+}
+
sub list_discussion {
my ($mode,$status,$ressymb,$imsextras,$group)=@_;
unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }
@@ -257,14 +277,14 @@ sub list_discussion {
$visit ++;
my $seeid;
- if (($group ne '') && ($mode eq 'board') &&
- ($ressymb =~ m|^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|)) {
- if (&check_group_priv($group,'dgp') eq 'ok') {
- $seeid = 1;
- }
- } else {
- $seeid=&Apache::lonnet::allowed('rin',$crs);
+ if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
+ $seeid = 1;
}
+ my $seehidden = &can_see_hidden($mode,$ressymb,undef,$group,$cdom,$cnum,$crs);
+# Is voting on discussions available
+ my $realsymb = &get_realsymb($ressymb);
+ my $canvote = &discussion_vote_available($status,$realsymb);
+
my @discussionitems=();
my %shown = ();
my @posteridentity=();
@@ -291,7 +311,7 @@ sub list_discussion {
$discinfo{$visitkey} = $visit;
&Apache::lonnet::put('nohist_'.$cid.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'});
- &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$encsymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group);
+ &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$seehidden,$canvote,$prevread,$sortposts,$encsymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group);
my $discussion='';
my $manifestfile;
@@ -450,7 +470,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/
"\n".'
';
$discussion .= &action_links_bar($colspan,$ressymb,$visible,
$newpostsflag,$group,
- $prevread,$markondisp);
+ $prevread,$markondisp,$seehidden);
my $escsymb=&escape($ressymb);
my $numhidden = keys(%notshown);
if ($numhidden > 0) {
@@ -664,7 +684,7 @@ END
END
$discussion .= &action_links_bar($colspan,$ressymb,$visible,
$newpostsflag,$group,
- $prevread,$markondisp);
+ $prevread,$markondisp,$seehidden);
$discussion .= "
\n";
@@ -764,9 +784,15 @@ END
$discussion.= &send_feedback_link($ressymb,$target);
if ($env{'request.role.adv'}) {
my $close = &Apache::lonnet::EXT('resource.0.discussend',$ressymb);
+ my $canvote = &Apache::lonnet::EXT('resource.0.discussvote',$ressymb);
if (defined($close) && $close ne '' && $close < time) {
- $discussion .= ' '.&mt('(Closed for [_1] roles)',
- &Apache::lonnet::plaintext('st',$crstype));
+ if ($canvote eq 'notended') {
+ $discussion .= ' '.&mt('(Posting and voting closed for [_1] roles)',
+ &Apache::lonnet::plaintext('st',$crstype));
+ } else {
+ $discussion .= ' '.&mt('(Closed for [_1] roles)',
+ &Apache::lonnet::plaintext('st',$crstype));
+ }
}
}
} else {
@@ -777,6 +803,39 @@ END
return $discussion;
}
+sub can_see_hidden {
+ my ($mode,$ressymb,$feedurl,$group,$cdom,$cnum,$crs) = @_;
+ my $seehidden;
+ if ($env{'request.course.id'}) {
+ unless ($cdom ne '' && $cnum ne '') {
+ $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ }
+ if ($crs eq '') {
+ $crs = '/'.$env{'request.course.id'};
+ if ($env{'request.course.sec'}) {
+ $crs.='_'.$env{'request.course.sec'};
+ }
+ $crs=~s{_}{/}g;
+ }
+ if ($mode eq '') {
+ $mode='board';
+ if ($feedurl =~ /$LONCAPA::assess_re/) {
+ $mode='problem';
+ }
+ }
+ if (($group ne '') && ($mode eq 'board') &&
+ ($ressymb =~ m{^bulletin___\d+\Q___adm/wrapper/adm/$cdom/$cnum/\E\d+/bulletinboard$})) {
+ if (&check_group_priv($group,'dgp') eq 'ok') {
+ $seehidden = 1;
+ }
+ } else {
+ $seehidden=&Apache::lonnet::allowed('rin',$crs);
+ }
+ }
+ return $seehidden;
+}
+
sub discussion_link {
my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds,$title) = @_;
my $link = ''.
''.
'';
@@ -840,7 +900,17 @@ sub action_links_bar {
$discussion .= '&previous='.$prevread;
}
$discussion .= &group_args($group);
- $discussion .= '">'.&mt('Export').'? | ';
+ $discussion .= '">'.&mt('Export').'';
+ if ($seehidden) {
+ $discussion .= ' ';
+ $discussion .=''.&mt('Undelete all deleted entries').'';
+ }
+ $discussion.='';
if ($newpostsflag) {
if (!$markondisp) {
$discussion .=''.&mt('Edit').'';
- unless ($seeid) {
+ unless ($seehidden) {
my $grpargs = &group_args($group);
$sender.=" ';
}
}
}
- if ($seeid) {
+ if ($seehidden) {
if ($hiddens{$idx}) {
unless ($studenthidden) {
$sender.=' '.
$ctlink.' | ';
}
-# 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";
+ 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
- unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) {
- $$discussionitems[$idx].=' '.&discussion_link($symb,'','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));
- } else {
- $$discussionitems[$idx].='';
- }
- unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) {
- $$discussionitems[$idx].=' '.&discussion_link($symb,'','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting"));
- } else {
- $$discussionitems[$idx].='';
+ 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"));
+ }
+ }
}
- 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 ($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').'';
@@ -1489,13 +1606,13 @@ sub filter_regexp {
sub get_post_contents {
- my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$numver) = @_;
+ my ($contrib,$idx,$seeid,$seehidden,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$numver) = @_;
my $discussion = '';
my $start=$numver;
my $end=$numver + 1;
%{$$imsfiles{$idx}}=();
if ($type eq 'allversions') {
- unless($seeid) {
+ unless($seehidden) {
$discussion=&mt('You do not have privileges to view all versions of posts.').' '.&mt('Please select a different role.');
return $discussion;
}
@@ -1513,12 +1630,12 @@ sub get_post_contents {
my $sender = $$plainname;
if ($$showaboutme) {
$sender = &Apache::loncommon::aboutmewrapper(
- $$plainname,
- $$contrib{$idx.':sendername'},
- $$contrib{$idx.':senderdomain'});
+ $$plainname,
+ $$contrib{$idx.':sendername'},
+ $$contrib{$idx.':senderdomain'});
}
if ($seeid) {
- $sender .= ' ('. $$contrib{$idx.':sendername'}.':'.
+ $sender .= ' ('.$$contrib{$idx.':sendername'}.':'.
$$contrib{$idx.':senderdomain'}.')';
}
my $attachmenturls = $$contrib{$idx.':attachmenturl'};
@@ -1705,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'});
@@ -1713,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'};
}
@@ -2391,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 = ();
@@ -2424,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'};
@@ -2723,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,
@@ -2794,12 +2888,7 @@ sub screen_header {
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 = $symb;
- 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);
if (!$blocked && &discussion_open(undef,$realsymb) &&
(&Apache::lonnet::allowed('pch',
$env{'request.course.id'}.
@@ -2965,17 +3054,13 @@ sub storefeedbacklikes {
sub adddiscuss {
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'}:'')) ||
@@ -3068,6 +3153,7 @@ sub adddiscuss {
$newrecord{'subnumber'}=$record{'subnumber'}+1;
$status.='
'.&mt('Registering').': '.
&Apache::lonnet::cstore(\%newrecord,'_discussion');
+ &updatekarma();
}
} else {
$status.='Failed.';
@@ -3086,27 +3172,93 @@ sub getdiscussionrecords {
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 ($likes,$uname,$udom,$course)=@_;
- unless ($likes) { $likes=0; }
- if ($likes>0) { $likes=1; }
- if ($likes<0) { $likes=-1; }
+ 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 $totalvotes=$record{'totalvotes'};
- $totallikes+=$likes;
- $totalvotes++;
+ my $totalunlikes=$record{'totalunlikes'};
+ $totallikes += $chglikes;
+ $totalunlikes += $chgunlikes;
my %newrecord=('likes_user' => $env{'user.name'},
'likes_domain' => $env{'user.domain'},
- 'likes' => $likes,
- 'totallikes' => $totallikes,
- 'totalvotes' => $totalvotes);
+ '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;
}
@@ -3636,14 +3788,16 @@ sub handler {
# --------------------------- Get query string for limited number of parameters
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['like','unlike','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);
@@ -3692,25 +3846,14 @@ 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 = ();
@@ -3719,9 +3862,8 @@ sub handler {
my %imsfiles = ();
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,\$showaboutme));
+ $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;
@@ -3863,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'}) {
@@ -3902,16 +4039,46 @@ 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'})) {
@@ -3919,71 +4086,145 @@ ENDREDIR
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 %contrib=&Apache::lonnet::dump('disclikes',
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'},
- '^'.$prefix);
-# Get all who like or unlike this
- my $currentlikers=$contrib{$prefix.'likers'};
- my $currentunlikers=$contrib{$prefix.'unlikers'};
+ 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 $likes=$contrib{$prefix.'likes'};
+ 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 $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
- if ($env{'form.like'}) {
- if ($currentlikers=~/\,\Q$thisuser\E\,/) {
- $alreadyflag=1;
- } else {
- if ($currentunlikers=~/\,\Q$thisuser\E\,/) {
- $currentunlikers=~s/\,\Q$thisuser\E\,//g;
- } else {
- $currentlikers.=','.$thisuser.',';
- }
- $likes++;
- }
- } else {
- if ($currentunlikers=~/\,\Q$thisuser\E\,/) {
- $alreadyflag=1;
- } else {
- if ($currentlikers=~/\,\Q$thisuser\E\,/) {
- $currentlikers=~s/\,\Q$thisuser\E\,//g;
- } else {
- $currentunlikers.=','.$thisuser.',';
- }
- $likes--;
- }
- }
- my $result;
+# 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
- unless ($alreadyflag) {
- my %newhash=($prefix.'likes' => $likes,
- $prefix.'likers' => $currentlikers,
- $prefix.'unlikers' => $currentunlikers);
+ 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,
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
+ if (&Apache::lonnet::put('disclikes',\%newhash,$cdom,$cnum) eq 'ok') {
# Also store with the person who posted the liked/unliked entry
- if ($env{'form.like'}) {
- &storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
- $result=&mt("Registered 'Like'");
- } else {
- &storediscussionlikes(-1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
- $result=&mt("Registered 'Unlike'");
+ 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 {
-# Oops, something went wrong
- $result=&mt("Failed to register vote");
+ $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,
@@ -4006,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'}) {
@@ -4047,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,
@@ -4072,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'};
@@ -4086,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);
}
@@ -4200,6 +4519,7 @@ ENDREDIR
$override = 1;
}
my $message=&clear_out_html($env{'form.comment'},$override);
+
# Assemble email
my ($email,$citations)=&assemble_email($message,$prevattempts,
@@ -4265,6 +4585,7 @@ sub wrap_symb {
}
return $ressymb;
}
+
sub dewrapper {
my ($feedurl)=@_;
if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
@@ -4418,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()