version 1.342, 2012/03/15 15:02:59
|
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 1931 $latexHelp
|
Line 1940 $latexHelp
|
<p> |
<p> |
END |
END |
|
|
$r->print(&Apache::lonhtmlcommon::start_pick_box()); |
$r->print(&Apache::lonhtmlcommon::start_pick_box()); |
$r->print(&Apache::lonhtmlcommon::row_title(&mt('Subject'))); |
$r->print(&Apache::lonhtmlcommon::row_title(&mt('Subject'))); |
$r->print('<input type="text" name="subject" size="30" value="'."$subject".'" /></p>'); |
$r->print('<input type="text" name="subject" size="30" value="'. |
$r->print(&Apache::lonhtmlcommon::row_closure()); |
$subject.'" /></p>'); |
$r->print(&Apache::lonhtmlcommon::row_title(&mt('Message'))); |
$r->print(&Apache::lonhtmlcommon::row_closure()); |
$r->print('<textarea name="comment" id="comment" cols="60" rows="10" $textareaclass>'."$comment". |
$r->print(&Apache::lonhtmlcommon::row_title(&mt('Message'))); |
'</textarea>'); |
$r->print('<textarea name="comment" id="comment" cols="60" rows="10" '. |
$r->print(&Apache::lonhtmlcommon::row_closure(1)); |
$textareaclass.'>'.$comment. |
$r->print(&Apache::lonhtmlcommon::end_pick_box()); |
'</textarea>'); |
|
$r->print(&Apache::lonhtmlcommon::row_closure(1)); |
|
$r->print(&Apache::lonhtmlcommon::end_pick_box()); |
|
|
if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) { |
if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) { |
if ($env{'form.origpage'}) { |
if ($env{'form.origpage'}) { |
Line 4071 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 $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 |
# 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 %contrib=&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($contrib{$prefix.'likers'}) eq 'HASH') { |
if (ref($likes{$prefix.'likers'}) eq 'HASH') { |
if (exists($contrib{$prefix.'likers'}{$thisuser})) { |
if (exists($likes{$prefix.'likers'}{$thisuser})) { |
$userlikes = 1; |
$userlikes = 1; |
} |
} |
} |
} |
if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') { |
if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { |
if (exists($contrib{$prefix.'unlikers'}{$thisuser})) { |
if (exists($likes{$prefix.'unlikers'}{$thisuser})) { |
$userunlikes = 1; |
$userunlikes = 1; |
} |
} |
} |
} |
# Get the current "likes" count |
# Get the current "likes" count |
my $likes=$contrib{$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($contrib{$prefix.'unlikers'}{$thisuser}); |
$likescount++; |
$likes++; |
} else { |
} else { |
if (ref($likes{$prefix.'likers'}) eq 'HASH') { |
if (ref($contrib{$prefix.'likers'}) eq 'HASH') { |
$likes{$prefix.'likers'}{$thisuser} = 1; |
$contrib{$prefix.'likers'}{$thisuser} = 1; |
} else { |
} else { |
$likes{$prefix.'likers'} = {$thisuser => 1}; |
$contrib{$prefix.'likers'} = {$thisuser => 1}; |
} |
} |
$likescount++; |
$likes++; |
} |
} |
|
} else { |
|
if ($userunlikes) { |
|
$alreadyflag=1; |
|
} elsif ($userlikes) { |
|
delete($contrib{$prefix.'likers'}{$thisuser}); |
|
$likes--; |
|
} else { |
|
if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') { |
|
$contrib{$prefix.'unlikers'}{$thisuser} = 1; |
|
} else { |
} else { |
$contrib{$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--; |
|
} |
} |
} |
$likes--; |
|
} |
|
} |
|
# $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' => $likes, |
if ($env{'form.like'}) { |
$prefix.'likers' => $contrib{$prefix.'likers'}, |
$result= &mt("'Like' already registered"); |
$prefix.'unlikers' => $contrib{$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, |