version 1.344, 2012/03/15 21:55:13
|
version 1.345, 2012/03/16 01:43:48
|
Line 1333 sub build_posting_display {
|
Line 1333 sub build_posting_display {
|
} else { |
} else { |
if ($message) { |
if ($message) { |
my $spansize = 2; |
my $spansize = 2; |
|
my ($uname,$udom); |
if ($showonlyunread && $prevread > $posttime) { |
if ($showonlyunread && $prevread > $posttime) { |
$$notshown{$idx} = 1; |
$$notshown{$idx} = 1; |
} elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) { |
} elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) { |
$$notshown{$idx} = 1; |
$$notshown{$idx} = 1; |
} else { |
} else { |
# apply filters |
# apply filters |
my $uname = $contrib{$idx.':sendername'}; |
$uname = $contrib{$idx.':sendername'}; |
my $udom = $contrib{$idx.':senderdomain'}; |
$udom = $contrib{$idx.':senderdomain'}; |
my $poster = $uname.':'.$udom; |
my $poster = $uname.':'.$udom; |
if ($env{'form.totposters'} ne '') { |
if ($env{'form.totposters'} ne '') { |
if ($totposters == 0) { |
if ($totposters == 0) { |
Line 1424 sub build_posting_display {
|
Line 1425 sub build_posting_display {
|
'</div></blockquote>'; |
'</div></blockquote>'; |
if ($canvote) { |
if ($canvote) { |
# Put in the like and unlike buttons |
# Put in the like and unlike buttons |
if ($userlikes{$idx}) { |
if (($uname eq $env{'user.name'}) && ($udom eq $env{'user.domain'})) { |
$$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />'; |
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 { |
} 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 ($userlikes{$idx}) { |
} |
$$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />'; |
if ($userunlikes{$idx}) { |
} else { |
$$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />'; |
$$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")); |
} 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 ($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) { |
if ($seeid || $canvote) { |
Line 4073 ENDREDIR
|
Line 4082 ENDREDIR
|
my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'}; |
my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'}; |
my ($symb,$idx)=split(/\:\:\:/,$entry); |
my ($symb,$idx)=split(/\:\:\:/,$entry); |
($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); |
($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 $result; |
my $realsymb = &get_realsymb($symb); |
if ($idx > 0) { |
if (&discussion_vote_available($status,$realsymb)) { |
my $realsymb = &get_realsymb($symb); |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
my $status='OPEN'; |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
if ($Apache::lonhomework::parsing_a_problem || |
$env{'course.'.$env{'request.course.id'}.'.num'}); |
$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 |
# Likes and unlikes are in db-file "disclikes" of the course |
# The prefix is the $symb to identify the resource discussion, |
# The prefix is the $symb to identify the resource discussion, |
# and the $idx to identify the entry |
# and the $idx to identify the entry |
# |
# |
my $prefix=$symb.':'.$idx.':'; |
my $prefix=$symb.':'.$idx.':'; |
my %likes=&Apache::lonnet::dump('disclikes', |
my %likes=&Apache::lonnet::dump('disclikes', |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}, |
'^'.$prefix); |
'^'.$prefix); |
|
|
# Get current like or unlike status for the $idx for this user. |
# Get current like or unlike status for the $idx for this user. |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
my ($userlikes,$userunlikes); |
my ($userlikes,$userunlikes); |
if (ref($likes{$prefix.'likers'}) eq 'HASH') { |
if (ref($likes{$prefix.'likers'}) eq 'HASH') { |
if (exists($likes{$prefix.'likers'}{$thisuser})) { |
if (exists($likes{$prefix.'likers'}{$thisuser})) { |
$userlikes = 1; |
$userlikes = 1; |
} |
} |
} |
} |
if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { |
if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { |
if (exists($likes{$prefix.'unlikers'}{$thisuser})) { |
if (exists($likes{$prefix.'unlikers'}{$thisuser})) { |
$userunlikes = 1; |
$userunlikes = 1; |
} |
} |
} |
} |
# Get the current "likes" count |
# Get the current "likes" count |
my $likescount=$likes{$prefix.'likes'}; |
my $likescount=$likes{$prefix.'likes'}; |
# Find out if they already voted |
# Find out if they already voted |
# Users cannot like a post twice, or unlike it twice. |
# Users cannot like a post twice, or unlike it twice. |
# They can change their mind, though. |
# They can change their mind, though. |
my $alreadyflag=0; |
my $alreadyflag=0; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
if ($env{'form.like'}) { |
if ($env{'form.like'}) { |
if ($userlikes) { |
if ($userlikes) { |
$alreadyflag=1; |
$alreadyflag=1; |
} elsif ($userunlikes) { |
} elsif ($userunlikes) { |
delete($likes{$prefix.'unlikers'}{$thisuser}); |
delete($likes{$prefix.'unlikers'}{$thisuser}); |
$likescount++; |
$likescount++; |
} else { |
} else { |
if (ref($likes{$prefix.'likers'}) eq 'HASH') { |
if (ref($likes{$prefix.'likers'}) eq 'HASH') { |
$likes{$prefix.'likers'}{$thisuser} = 1; |
$likes{$prefix.'likers'}{$thisuser} = 1; |
} else { |
} else { |
$likes{$prefix.'likers'} = {$thisuser => 1}; |
$likes{$prefix.'likers'} = {$thisuser => 1}; |
} |
} |
$likescount++; |
$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; |
|
} else { |
} 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 |
# $alreadyflag would be 1 if they tried to double-like or double-unlike |
unless ($alreadyflag) { |
if ($alreadyflag) { |
my %newhash=($prefix.'likes' => $likescount, |
if ($env{'form.like'}) { |
$prefix.'likers' => $likes{$prefix.'likers'}, |
$result= &mt("'Like' already registered"); |
$prefix.'unlikers' => $likes{$prefix.'unlikers'}); |
} 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" |
# Store data in db-file "disclikes" |
if (&Apache::lonnet::put('disclikes', |
if (&Apache::lonnet::put('disclikes', |
\%newhash, |
\%newhash, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { |
$env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { |
# Also store with the person who posted the liked/unliked entry |
# Also store with the person who posted the liked/unliked entry |
if ($env{'form.like'}) { |
if ($env{'form.like'}) { |
&storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
&storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
$result=&mt("Registered 'Like'"); |
$result=&mt("Registered 'Like'"); |
} else { |
} else { |
&storediscussionlikes(-1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
&storediscussionlikes(-1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
$result=&mt("Registered 'Unlike'"); |
$result=&mt("Registered 'Unlike'"); |
} |
} |
} else { |
} else { |
# Oops, something went wrong |
# 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 { |
} else { |
$result=&mt('Voting unavailable for this discussion'); |
$result=&mt('Invalid post number'); |
} |
} |
&redirect_back($r,$feedurl,$result.'<br />', |
&redirect_back($r,$feedurl,$result.'<br />', |
'0','0','','',$env{'form.previous'},undef,undef,undef, |
'0','0','','',$env{'form.previous'},undef,undef,undef, |