version 1.330, 2012/01/09 19:56:28
|
version 1.335, 2012/02/20 11:28:01
|
Line 1019 sub build_posting_display {
|
Line 1019 sub build_posting_display {
|
my $twoplus=$ave+2.*$stddev; |
my $twoplus=$ave+2.*$stddev; |
my $oneminus=$ave-$stddev; |
my $oneminus=$ave-$stddev; |
my $twominus=$ave-2.*$stddev; |
my $twominus=$ave-2.*$stddev; |
# &Apache::lonnet::logthis(join(',',@theselikes)." Ave $ave StdDev $stddev $twominus $oneminus $oneplus $twoplus"); |
|
# |
# |
# This is now the real loop. Go through all entries, pick up what we need |
# This is now the real loop. Go through all entries, pick up what we need |
# |
# |
Line 1156 sub build_posting_display {
|
Line 1155 sub build_posting_display {
|
@{$$namesort{$lastname}{$firstname}} = ("$idx"); |
@{$$namesort{$lastname}{$firstname}} = ("$idx"); |
} |
} |
if ($outputtarget ne 'tex') { |
if ($outputtarget ne 'tex') { |
unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) { |
# Add karma stars |
$sender.=' '.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsup.png" alt="'.&mt('Like').'" />','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like")); |
my $karma=&userkarma($contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
} |
for (my $i=1;$i<=$karma;$i++) { |
unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { |
$sender.='<img border="0" src="/res/adm/pages/star.gif" alt="'.&mt('Contributor Kudos').'" />'; |
$sender.=' '.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsdown.png" alt="'.&mt('Unlike').'" />',,'unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike")); |
|
} |
|
my $thislikes=$likes{$symb.':'.$idx.':likes'}; |
|
if ($thislikes>0) { |
|
$sender.=' ('.&mt("[_1] likes",$thislikes).')'; |
|
} elsif ($thislikes<0) { |
|
$sender.=' ('.&mt("[_1] unlikes",abs($thislikes)).')'; |
|
} |
} |
|
# Can people edit this? |
if (&editing_allowed($escsymb.':::'.$idx,$group)) { |
if (&editing_allowed($escsymb.':::'.$idx,$group)) { |
if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { |
if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { |
$sender.=' '. |
$sender.=' '. |
Line 1363 sub build_posting_display {
|
Line 1356 sub build_posting_display {
|
} elsif ($thislikes<$oneminus) { |
} elsif ($thislikes<$oneminus) { |
$likesize="75"; |
$likesize="75"; |
} |
} |
|
# Actually glue in the message itself |
$$discussionitems[$idx].= '<br /><blockquote>'. |
$$discussionitems[$idx].= '<br /><blockquote>'. |
"<div style='font-size:$likesize%'>". |
"<div style='font-size:$likesize%'>". |
$message. |
$message. |
'</div></blockquote>'; |
'</div></blockquote>'; |
|
# Put in the like and unlike buttons |
|
unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) { |
|
$$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].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />'; |
|
} |
|
unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { |
|
$$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")); |
|
} else { |
|
$$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />'; |
|
} |
|
my $thislikes=$likes{$symb.':'.$idx.':likes'}; |
|
if ($thislikes>0) { |
|
$$discussionitems[$idx].=' ('.&mt("[_1] likes",$thislikes).')'; |
|
} elsif ($thislikes<0) { |
|
$$discussionitems[$idx].=' ('.&mt("[_1] unlikes",abs($thislikes)).')'; |
|
} |
|
# If there is any history to this post, inform the reader |
if ($contrib{$idx.':history'}) { |
if ($contrib{$idx.':history'}) { |
my @postversions = (); |
my @postversions = (); |
$$discussionitems[$idx] .= &mt('This post has been edited by the author.'); |
$$discussionitems[$idx] .= ' '.&mt('This post has been edited by the author.'); |
if ($seeid) { |
if ($seeid) { |
$$discussionitems[$idx] .= ' '. |
$$discussionitems[$idx] .= ' '. |
&discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group)); |
&discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group)); |
Line 2683 sub no_redirect_back {
|
Line 2695 sub no_redirect_back {
|
'add_entries' => \%onload,); |
'add_entries' => \%onload,); |
|
|
if ($feedurl !~ m{^/adm/feedback}) { |
if ($feedurl !~ m{^/adm/feedback}) { |
$body_options{'rediect'} = [2,$feedurl]; |
$body_options{'redirect'} = [2,$feedurl]; |
} |
} |
my $start_page= |
my $start_page= |
&Apache::loncommon::start_page('Feedback not sent',undef, |
&Apache::loncommon::start_page('Feedback not sent',undef, |
Line 2935 sub storefeedbackpoints {
|
Line 2947 sub storefeedbackpoints {
|
my %record=('grader_user' => $env{'user.name'}, |
my %record=('grader_user' => $env{'user.name'}, |
'grader_domain' => $env{'user.domain'}, |
'grader_domain' => $env{'user.domain'}, |
'points' => $points); |
'points' => $points); |
return &Apache::lonnet::cstore(\%record,'_feedback'); |
return &Apache::lonnet::cstore(\%record,'_feedback',$course,$udom,$uname); |
} |
} |
|
|
# Store feedback "likes" |
# Store feedback "likes" |
Line 2955 sub storefeedbacklikes {
|
Line 2967 sub storefeedbacklikes {
|
'likes_domain' => $env{'user.domain'}, |
'likes_domain' => $env{'user.domain'}, |
'likes' => $likes, |
'likes' => $likes, |
'totallikes' => $totallikes); |
'totallikes' => $totallikes); |
return &Apache::lonnet::cstore(\%newrecord,'_feedback'); |
return &Apache::lonnet::cstore(\%newrecord,'_feedback',$course,$udom,$uname); |
} |
} |
|
|
|
|
Line 3065 sub adddiscuss {
|
Line 3077 sub adddiscuss {
|
$newrecord{'subnumber'}=$record{'subnumber'}+1; |
$newrecord{'subnumber'}=$record{'subnumber'}+1; |
$status.='<br />'.&mt('Registering').': '. |
$status.='<br />'.&mt('Registering').': '. |
&Apache::lonnet::cstore(\%newrecord,'_discussion'); |
&Apache::lonnet::cstore(\%newrecord,'_discussion'); |
|
&updatekarma(); |
} |
} |
} else { |
} else { |
$status.='Failed.'; |
$status.='Failed.'; |
Line 3088 sub getdiscussionrecords {
|
Line 3101 sub getdiscussionrecords {
|
|
|
sub getdiscussionstats { |
sub getdiscussionstats { |
my %record=&getdiscussionrecords(@_); |
my %record=&getdiscussionrecords(@_); |
return ($record{'subnumber'},$record{'points'},$record{'totallikes'}); |
return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$record{'totalvotes'}); |
|
} |
|
|
|
# Calculate discussion karma |
|
|
|
sub calcdiscussionkarma { |
|
my ($subs,$pts,$likes,$votes)=&getdiscussionstats(@_); |
|
my $karma=0; |
|
if ($votes>0) { |
|
$karma=int(.1+5.*(1.-exp(-$subs/10.))*$likes/$votes); |
|
if ($karma<0) { $karma=0; } |
|
if ($karma>5) { $karma=5; } |
|
} |
|
return $karma; |
|
} |
|
|
|
# Update karma |
|
|
|
sub updatekarma { |
|
my ($uname,$udom,$course)=@_; |
|
unless ($uname) { $uname=$env{'user.name'}; } |
|
unless ($udom) { $udom=$env{'user.domain'}; } |
|
unless ($course) { $course=$env{'request.course.id'}; } |
|
my $karma=&calcdiscussionkarma($uname,$udom,$course); |
|
&Apache::lonnet::cstore({ 'karma' => $karma },'_discussion',$course,$udom,$uname); |
|
&Apache::lonnet::do_cache_new('karma',$uname.':'.$udom.':'.$course,$karma,3600); |
|
return $karma; |
} |
} |
|
|
|
# Retrieve karma |
|
|
|
sub userkarma { |
|
my ($uname,$udom,$course)=@_; |
|
unless ($uname) { $uname=$env{'user.name'}; } |
|
unless ($udom) { $udom=$env{'user.domain'}; } |
|
unless ($course) { $course=$env{'request.course.id'}; } |
|
my $hashkey=$uname.':'.$udom.':'.$course; |
|
my ($karma,$cached)=&Apache::lonnet::is_cached_new('karma',$hashkey); |
|
if ($cached) { |
|
return $karma; |
|
} |
|
my %userdisc=&getdiscussionrecords($uname,$udom,$course); |
|
$karma=$userdisc{'karma'}; |
|
&Apache::lonnet::do_cache_new('karma',$hashkey,$karma,3600); |
|
return $karma; |
|
} |
|
|
# Store discussion credit |
# Store discussion credit |
|
|
Line 3103 sub storediscussionpoints {
|
Line 3159 sub storediscussionpoints {
|
my %record=('grader_user' => $env{'user.name'}, |
my %record=('grader_user' => $env{'user.name'}, |
'grader_domain' => $env{'user.domain'}, |
'grader_domain' => $env{'user.domain'}, |
'points' => $points); |
'points' => $points); |
return &Apache::lonnet::cstore(\%record,'_discussion'); |
return &Apache::lonnet::cstore(\%record,'_discussion',$course,$udom,$uname); |
} |
} |
|
|
# Store discussion "likes" |
# Store discussion "likes" |
Line 3118 sub storediscussionlikes {
|
Line 3174 sub storediscussionlikes {
|
unless ($course) { $course=$env{'request.course.id'}; } |
unless ($course) { $course=$env{'request.course.id'}; } |
my %record=&getdiscussionrecords($uname,$udom,$course); |
my %record=&getdiscussionrecords($uname,$udom,$course); |
my $totallikes=$record{'totallikes'}; |
my $totallikes=$record{'totallikes'}; |
|
my $totalvotes=$record{'totalvotes'}; |
$totallikes+=$likes; |
$totallikes+=$likes; |
|
$totalvotes++; |
my %newrecord=('likes_user' => $env{'user.name'}, |
my %newrecord=('likes_user' => $env{'user.name'}, |
'likes_domain' => $env{'user.domain'}, |
'likes_domain' => $env{'user.domain'}, |
'likes' => $likes, |
'likes' => $likes, |
'totallikes' => $totallikes); |
'totallikes' => $totallikes, |
return &Apache::lonnet::cstore(\%newrecord,'_discussion'); |
'totalvotes' => $totalvotes); |
|
my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname); |
|
if ($status eq 'ok') { |
|
&updatekarma($uname,$udom,$course); |
|
} |
|
return $status; |
} |
} |
|
|
sub get_discussion_info { |
sub get_discussion_info { |
Line 3411 sub generate_attachments_button {
|
Line 3474 sub generate_attachments_button {
|
my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach, |
my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach, |
$numoldver,$mode,$blockblog) = @_; |
$numoldver,$mode,$blockblog) = @_; |
my $origpage = $ENV{'REQUEST_URI'}; |
my $origpage = $ENV{'REQUEST_URI'}; |
my $att=$attachnum.' '.&mt("attachments"); |
|
my %lt = &Apache::lonlocal::texthash( |
my %lt = &Apache::lonlocal::texthash( |
'clic' => 'Click to add/remove attachments', |
'clic' => 'Add/remove attachments', |
); |
); |
my $response = (<<END); |
my $response = (<<END); |
<br /> |
<br /> |
<form name="attachment" action="/adm/feedback?attach=$ressymb" method="post"> |
<form name="attachment" action="/adm/feedback?attach=$ressymb" method="post"> |
$lt{'clic'}: <input type="button" value="$att" |
<input type="button" value="$lt{'clic'}" |
onclick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=escape(document.mailform.comment.value);this.form.subject.value=escape(document.mailform.subject.value); |
onclick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=escape(document.mailform.comment.value);this.form.subject.value=escape(document.mailform.subject.value); |
END |
END |
if (!$blockblog) { |
if (!$blockblog) { |