--- loncom/interface/lonfeedback.pm 2012/03/15 21:55:13 1.344
+++ loncom/interface/lonfeedback.pm 2012/03/16 02:59:01 1.346
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.344 2012/03/15 21:55:13 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.346 2012/03/16 02:59:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1333,14 +1333,15 @@ sub build_posting_display {
} else {
if ($message) {
my $spansize = 2;
+ my ($uname,$udom);
if ($showonlyunread && $prevread > $posttime) {
$$notshown{$idx} = 1;
} elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
$$notshown{$idx} = 1;
} else {
# apply filters
- my $uname = $contrib{$idx.':sendername'};
- my $udom = $contrib{$idx.':senderdomain'};
+ $uname = $contrib{$idx.':sendername'};
+ $udom = $contrib{$idx.':senderdomain'};
my $poster = $uname.':'.$udom;
if ($env{'form.totposters'} ne '') {
if ($totposters == 0) {
@@ -1424,15 +1425,23 @@ sub build_posting_display {
'';
if ($canvote) {
# Put in the like and unlike buttons
- if ($userlikes{$idx}) {
- $$discussionitems[$idx].='
';
+ if (($uname eq $env{'user.name'}) && ($udom eq $env{'user.domain'})) {
+ my $novote = &mt('No voting for your own posts');
+ $$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 ($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) {
@@ -3800,7 +3809,7 @@ sub handler {
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);
@@ -3860,7 +3869,6 @@ sub handler {
my ($symb,$idx)=split(/\:\:\:/,$env{'form.allversions'});
($symb)=&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') {
@@ -4025,7 +4033,7 @@ ENDREDIR
$crs=~s/\_/\//g;
my $seeid=&Apache::lonnet::allowed('rin',$crs);
- if ($env{'form.hide'} && !$seeid && !(&editing_allowed($env{'form.hide'},$env{'form.group'}))) {
+ if ($env{'form.hide'} && !$seeid && !(&editing_allowed($env{'form.hide'},$group))) {
&redirect_back($r,$feedurl,&mt('Deletion not permitted').'
', '0','0','','',$env{'form.previous'},'','','','',
undef,undef,$group,);
return OK;
@@ -4073,102 +4081,117 @@ 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 $status='OPEN';
- if ($Apache::lonhomework::parsing_a_problem ||
- $Apache::lonhomework::parsing_a_task) {
- $status=$Apache::inputtags::status[-1];
- }
my $result;
- my $realsymb = &get_realsymb($symb);
- if (&discussion_vote_available($status,$realsymb)) {
- my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'});
+ 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'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
+ 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.");
+ } 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',
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'},
- '^'.$prefix);
+ my $prefix=$symb.':'.$idx.':';
+ my %likes=&Apache::lonnet::dump('disclikes',
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'},
+ '^'.$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;
- }
- }
+ 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'};
+ 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 ($userlikes) {
- $alreadyflag=1;
- } elsif ($userunlikes) {
- delete($likes{$prefix.'unlikers'}{$thisuser});
- $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});
- $likescount--;
- } else {
- if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
- $likes{$prefix.'unlikers'}{$thisuser} = 1;
+ my $alreadyflag=0;
+ if ($env{'form.like'}) {
+ if ($userlikes) {
+ $alreadyflag=1;
+ } elsif ($userunlikes) {
+ delete($likes{$prefix.'unlikers'}{$thisuser});
+ $likescount++;
+ } else {
+ if (ref($likes{$prefix.'likers'}) eq 'HASH') {
+ $likes{$prefix.'likers'}{$thisuser} = 1;
+ } else {
+ $likes{$prefix.'likers'} = {$thisuser => 1};
+ }
+ $likescount++;
+ }
} else {
- $likes{$prefix.'unlikers'} = {$thisuser => 1};
+ if ($userunlikes) {
+ $alreadyflag=1;
+ } elsif ($userlikes) {
+ delete($likes{$prefix.'likers'}{$thisuser});
+ $likescount--;
+ } else {
+ if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
+ $likes{$prefix.'unlikers'}{$thisuser} = 1;
+ } else {
+ $likes{$prefix.'unlikers'} = {$thisuser => 1};
+ }
+ $likescount--;
+ }
}
- $likescount--;
- }
- }
# $alreadyflag would be 1 if they tried to double-like or double-unlike
- unless ($alreadyflag) {
- my %newhash=($prefix.'likes' => $likescount,
- $prefix.'likers' => $likes{$prefix.'likers'},
- $prefix.'unlikers' => $likes{$prefix.'unlikers'});
+ 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,
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'}) 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'");
- }
- } else {
+ 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'");
+ }
+ } else {
# Oops, something went wrong
- $result=&mt("Failed to register vote");
+ $result=&mt("Failed to register vote");
+ }
+ }
}
+ } else {
+ $result=&mt('Voting unavailable for this discussion');
}
} else {
- $result=&mt('Voting unavailable for this discussion');
+ $result=&mt('Invalid post number');
}
&redirect_back($r,$feedurl,$result.'
',
'0','0','','',$env{'form.previous'},undef,undef,undef,