[LON-CAPA-cvs] cvs: loncom /html/res/adm/pages thumbsdown_novote.png thumbsup_novote.png /interface lonfeedback.pm doc/loncapafiles loncapafiles.lpml
raeburn
raeburn at source.lon-capa.org
Thu Mar 15 21:44:04 EDT 2012
raeburn Fri Mar 16 01:44:04 2012 EDT
Added files:
/loncom/html/res/adm/pages thumbsup_novote.png
thumbsdown_novote.png
Modified files:
/loncom/interface lonfeedback.pm
/doc/loncapafiles loncapafiles.lpml
Log:
- Disallow users from voting for their own posts.
- Display information to user in cases where vote was not recorded.
-------------- next part --------------
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.344 loncom/interface/lonfeedback.pm:1.345
--- loncom/interface/lonfeedback.pm:1.344 Thu Mar 15 21:55:13 2012
+++ loncom/interface/lonfeedback.pm Fri Mar 16 01:43:48 2012
@@ -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.345 2012/03/16 01:43:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1333,14 +1333,15 @@
} 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 @@
'</div></blockquote>';
if ($canvote) {
# Put in the like and unlike buttons
- if ($userlikes{$idx}) {
- $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />';
+ if (($uname eq $env{'user.name'}) && ($udom eq $env{'user.domain'})) {
+ my $novote = &mt('No voting for your own posts');
+ $$discussionitems[$idx].=
+ '<a href="javascript:alert('."'$novote'".');" style="text-decoration: none;">'.
+ '<img border="0" src="/res/adm/pages/thumbsup_novote.png" alt="'.$novote.'" /> '.
+ '<img border="0" src="/res/adm/pages/thumbsdown_novote.png" alt="'.$novote.'" /></a>';
} else {
- $$discussionitems[$idx].=' '.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsup.png" alt="'.&mt('Like').'" />','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));
- }
- if ($userunlikes{$idx}) {
- $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />';
- } else {
- $$discussionitems[$idx].=' '.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsdown.png" alt="'.&mt('Unlike').'" />','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting"));
+ if ($userlikes{$idx}) {
+ $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />';
+ } else {
+ $$discussionitems[$idx].=' '.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsup.png" alt="'.&mt('Like').'" />','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));
+ }
+ if ($userunlikes{$idx}) {
+ $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />';
+ } else {
+ $$discussionitems[$idx].=' '.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsdown.png" alt="'.&mt('Unlike').'" />','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting"));
+ }
}
}
if ($seeid || $canvote) {
@@ -4073,102 +4082,117 @@
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.'<br />',
'0','0','','',$env{'form.previous'},undef,undef,undef,
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.792 doc/loncapafiles/loncapafiles.lpml:1.793
--- doc/loncapafiles/loncapafiles.lpml:1.792 Thu Mar 15 00:01:07 2012
+++ doc/loncapafiles/loncapafiles.lpml Fri Mar 16 01:43:56 2012
@@ -2,7 +2,7 @@
"http://lpml.sourceforge.net/DTD/lpml.dtd">
<!-- loncapafiles.lpml -->
-<!-- $Id: loncapafiles.lpml,v 1.792 2012/03/15 00:01:07 raeburn Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.793 2012/03/16 01:43:56 raeburn Exp $ -->
<!--
@@ -7229,8 +7229,10 @@
subm.png;
thumbsup.png;
thumbsup_gray.png;
+thumbsup_novote.png;
thumbsdown.png;
thumbsdown_gray.png;
+thumbsdown_novote.png;
back.png;
catalog.png;
com.png;
More information about the LON-CAPA-cvs
mailing list