--- loncom/interface/lonfeedback.pm 2012/03/16 18:32:47 1.347
+++ loncom/interface/lonfeedback.pm 2012/04/29 22:02:02 1.352
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.347 2012/03/16 18:32:47 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.352 2012/04/29 22:02:02 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -513,7 +513,9 @@ imscp_v1p1.xsd http://www.imsglobal.org/
my $currdepth = 0;
my $firstidx = $alldiscussion{$showposts[0]};
foreach my $post (@showposts) {
- unless (($sortposts eq 'thread') || (($sortposts eq '') && ($env{'environment.threadeddiscussion'})) || ($outputtarget eq 'export')) {
+ unless (($sortposts eq 'thread') ||
+ (($sortposts eq '') && (!$env{'environment.unthreadeddiscussion'})) ||
+ ($outputtarget eq 'export')) {
$alldiscussion{$post} = $post;
}
unless ( ($notshown{$alldiscussion{$post}} eq '1') || ($shown{$alldiscussion{$post}} == 0) ) {
@@ -1117,7 +1119,8 @@ sub build_posting_display {
my $origindex='0.';
my $numoldver=0;
if ($contrib{$idx.':replyto'}) {
- if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+ if ( ((!$env{'environment.unthreadeddiscussion'}) && ($sortposts eq '')) ||
+ ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
# this is a follow-up message
$original[$idx]=$original[$contrib{$idx.':replyto'}];
$$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
@@ -1330,7 +1333,8 @@ sub build_posting_display {
}
if ($outputtarget eq 'export' || $message) {
my $thisindex=$idx;
- if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+ if ( ((!$env{'environment.unthreadeddiscussion'}) && ($sortposts eq '')) ||
+ ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
$thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
}
$$alldiscussion{$thisindex}=$idx;
@@ -1453,13 +1457,24 @@ sub build_posting_display {
$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 (($uname eq $env{'user.name'}) && ($udom eq $env{'user.domain'})) {
- my $novote = &mt('No voting for your own posts');
+ 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].='
';
@@ -1792,6 +1807,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'});
@@ -1800,36 +1816,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'};
}
@@ -3204,7 +3209,8 @@ sub getdiscussionrecords {
sub getdiscussionstats {
my %record=&getdiscussionrecords(@_);
- return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$record{'totalvotes'});
+ my $totalvotes = $record{'totallikes'} + $record{'totalunlikes'};
+ return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$totalvotes);
}
# Calculate discussion karma
@@ -3268,23 +3274,20 @@ sub storediscussionpoints {
# 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);
@@ -4033,7 +4036,7 @@ 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);
+ my $ressymb = &wrap_symb($symb);
my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
unless (($seehidden) || (&editing_allowed($env{'form.hide'},$group))) {
@@ -4070,11 +4073,43 @@ ENDREDIR
$cdom,$cnum);
}
}
- &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
- $cdom,$cnum);
-
- &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') {
+ 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);
+
+ }
+ $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'})) {
@@ -4093,11 +4128,21 @@ ENDREDIR
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'})) {
- $result = &mt("Vote not registered. No voting for your own posts.");
+ $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,
@@ -4126,11 +4171,13 @@ ENDREDIR
# 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') {
@@ -4145,6 +4192,7 @@ ENDREDIR
$alreadyflag=1;
} elsif ($userlikes) {
delete($likes{$prefix.'likers'}{$thisuser});
+ $votetype = 'switch';
$likescount--;
} else {
if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
@@ -4169,11 +4217,32 @@ ENDREDIR
# 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'}) {
- &storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
+ 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 {
- &storediscussionlikes(-1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
+ 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 {
@@ -4194,12 +4263,16 @@ ENDREDIR
return OK;
} elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) {
my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
- if ($env{'form.cmd'} eq 'threadedon') {
+ if ($env{'form.cmd'} eq 'threadedoff') {
+ &Apache::lonnet::put('environment',{'unthreadeddiscussion' => 'on'});
+ &Apache::lonnet::appenv({'environment.unthreadeddiscussion' => 'on'});
+ &Apache::lonnet::del('environment',['threadeddiscussion']);
+ &Apache::lonnet::delenv('environment.threadeddiscussion');
+ } else {
&Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
&Apache::lonnet::appenv({'environment.threadeddiscussion' => 'on'});
- } else {
- &Apache::lonnet::del('environment',['threadeddiscussion']);
- &Apache::lonnet::delenv('environment.threadeddiscussion');
+ &Apache::lonnet::del('environment',['unthreadeddiscussion']);
+ &Apache::lonnet::delenv('environment.unthreadeddiscussion');
}
&redirect_back($r,$feedurl,&mt('Changed discussion view mode').'
',
'0','0','','',$env{'form.previous'},undef,undef,undef,
@@ -4225,10 +4298,35 @@ ENDREDIR
$cdom,$cnum);
}
my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
- &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
- $cdom,$cnum);
- &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'}) {
@@ -4289,13 +4387,45 @@ ENDREDIR
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)) {
- if (&Apache::lonnet::store({'deleted' => ''},$symb,$env{'request.course.id'},
- $cdom,$cnum) eq 'ok') {
- $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries")));
- } else {
- $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1));
- }
- $r->print("
".&mt("Return and reload")."");
+ 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;
@@ -4654,6 +4784,8 @@ None
=item list_discussion()
+=item can_see_discussion()
+
=item send_feedback_link()
=item send_message_link()