version 1.290.2.7, 2010/12/24 23:18:57
|
version 1.290.2.7.2.2, 2012/03/07 01:26:48
|
Line 777 END
|
Line 777 END
|
return $discussion; |
return $discussion; |
} |
} |
|
|
|
sub discussion_link { |
|
my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds,$title) = @_; |
|
my $link = '<a href="/adm/feedback?'.$cmd.'='.&escape($ressymb).':::'.$item; |
|
if ($flag) { $link .= '&previous='.$prev; } |
|
if ($adds) { $link .= $adds; } |
|
$link .= '"'; |
|
if ($title) { $link .= ' title="'.$title.'"'; } |
|
$link .= '>'.$linktext.'</a>'; |
|
return $link; |
|
} |
|
|
sub send_feedback_link { |
sub send_feedback_link { |
my ($ressymb,$target) = @_; |
my ($ressymb,$target) = @_; |
my $output = '<span class="LC_feedback_link">'. |
my $output = '<span class="LC_feedback_link">'. |
Line 933 sub build_posting_display {
|
Line 944 sub build_posting_display {
|
my $skip_group_check = 0; |
my $skip_group_check = 0; |
my $symb=&Apache::lonenc::check_decrypt($ressymb); |
my $symb=&Apache::lonenc::check_decrypt($ressymb); |
my $escsymb=&escape($ressymb); |
my $escsymb=&escape($ressymb); |
|
# These are the discussion contributions |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
$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'}); |
|
# And these are the likes/unlikes |
|
my %likes=&Apache::lonnet::dump('disclikes', |
|
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
|
$env{'course.'.$env{'request.course.id'}.'.num'}, |
|
'^'.$symb.':'); |
|
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
|
# Array with likes to figure out averages, etc. |
|
my @theselikes=(); |
|
# Is the user allowed to see the real name behind anonymous postings? |
my $see_anonymous = |
my $see_anonymous = |
&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); |
&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); |
|
|
Line 966 sub build_posting_display {
|
Line 986 sub build_posting_display {
|
($skiptest,$roleregexp,$secregexp,$statusregexp) = |
($skiptest,$roleregexp,$secregexp,$statusregexp) = |
&filter_regexp($rolefilter,$sectionpick,$statusfilter); |
&filter_regexp($rolefilter,$sectionpick,$statusfilter); |
$rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp; |
$rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp; |
} |
} |
|
# We need to go through this twice, first to get the likes/dislikes, then to actually build the display |
|
for (my $id=1;$id<=$contrib{'version'};$id++) { |
|
my $idx=$id; |
|
next if ($contrib{$idx.':deleted'}); |
|
next if ($contrib{$idx.':hidden'}); |
|
unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) { |
|
push(@theselikes,$likes{$symb.':'.$idx.':likes'}); |
|
} |
|
} |
|
# Figure out average likes and standard deviation if there are enough discussions to warrant that |
|
my $ave=0; |
|
my $stddev=10000; |
|
if ($#theselikes>1) { |
|
my $sum=0; |
|
my $num=$#theselikes+1; |
|
foreach my $thislike (@theselikes) { |
|
$sum+=$thislike; |
|
} |
|
$ave=$sum/$num; |
|
my $sumsq=0; |
|
foreach my $thislike (@theselikes) { |
|
$sumsq+=($thislike-$ave)*($thislike-$ave); |
|
} |
|
$stddev=sqrt($sumsq/$num); |
|
} |
|
# Now we know the average likes $ave and the standard deviation $stddev |
|
# Get the boundaries for markup |
|
my $oneplus=$ave+$stddev; |
|
my $twoplus=$ave+2.*$stddev; |
|
my $oneminus=$ave-$stddev; |
|
my $twominus=$ave-2.*$stddev; |
|
# |
|
# This is now the real loop. Go through all entries, pick up what we need |
|
# |
for (my $id=1;$id<=$contrib{'version'};$id++) { |
for (my $id=1;$id<=$contrib{'version'};$id++) { |
my $idx=$id; |
my $idx=$id; |
next if ($contrib{$idx.':deleted'}); |
next if ($contrib{$idx.':deleted'}); |
Line 1014 sub build_posting_display {
|
Line 1068 sub build_posting_display {
|
my %subjects = (); |
my %subjects = (); |
my %attachtxt = (); |
my %attachtxt = (); |
my %allattachments = (); |
my %allattachments = (); |
my ($screenname,$plainname); |
my ($screenname,$plainname,$showaboutme); |
my $sender = &mt('Anonymous'); |
my $sender = &mt('Anonymous'); |
# Anonymous users getting number within a discussion |
# Anonymous users getting number within a discussion |
# Since idx is in static order, this should give the same sequence every time. |
# Since idx is in static order, this should give the same sequence every time. |
Line 1024 sub build_posting_display {
|
Line 1078 sub build_posting_display {
|
$$anonhash{$key}=&mt('Anonymous').' '.$anoncnt; |
$$anonhash{$key}=&mt('Anonymous').' '.$anoncnt; |
} |
} |
my ($message,$subject,$vgrlink,$ctlink); |
my ($message,$subject,$vgrlink,$ctlink); |
&get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver); |
&get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,\$showaboutme,$numoldver); |
|
|
|
|
# Set up for sorting by subject |
# Set up for sorting by subject |
Line 1054 sub build_posting_display {
|
Line 1108 sub build_posting_display {
|
} |
} |
} |
} |
if (!$contrib{$idx.':anonymous'} || $see_anonymous) { |
if (!$contrib{$idx.':anonymous'} || $see_anonymous) { |
$sender=&Apache::loncommon::aboutmewrapper( |
if ($showaboutme) { |
$plainname, |
$sender = &Apache::loncommon::aboutmewrapper( |
$contrib{$idx.':sendername'}, |
$plainname, |
$contrib{$idx.':senderdomain'}).' ('. |
$contrib{$idx.':sendername'}, |
$contrib{$idx.':sendername'}.':'. |
$contrib{$idx.':senderdomain'}); |
$contrib{$idx.':senderdomain'}.')'; |
} else { |
|
$sender = $plainname; |
|
} |
|
if ($see_anonymous) { |
|
$sender .= ' ('.$contrib{$idx.':sendername'}.':'. |
|
$contrib{$idx.':senderdomain'}.')'; |
|
} |
$sender = '<b>'.$sender.'</b>'; |
$sender = '<b>'.$sender.'</b>'; |
if ($contrib{$idx.':anonymous'}) { |
if ($contrib{$idx.':anonymous'}) { |
$sender.=' <font color="red"><b>['.$$anonhash{$key}.']</b></font> '. |
$sender.=' <font color="red"><b>['.$$anonhash{$key}.']</b></font> '. |
Line 1311 sub build_posting_display {
|
Line 1371 sub build_posting_display {
|
$$discussionitems[$idx].='<td align="right"> '. |
$$discussionitems[$idx].='<td align="right"> '. |
$ctlink.'</td>'; |
$ctlink.'</td>'; |
} |
} |
|
# Figure out size based on likes |
|
my $thislikes=$likes{$symb.':'.$idx.':likes'}; |
|
my $likesize="100"; |
|
if ($thislikes>$twoplus) { |
|
$likesize="200"; |
|
} elsif ($thislikes>$oneplus) { |
|
$likesize="150"; |
|
} |
|
if ($thislikes<$twominus) { |
|
$likesize="50"; |
|
} elsif ($thislikes<$oneminus) { |
|
$likesize="75"; |
|
} |
|
# Actually glue in the message itself |
$$discussionitems[$idx].= '</tr></table><blockquote>'. |
$$discussionitems[$idx].= '</tr></table><blockquote>'. |
$message.'</blockquote>'; |
"<div style='font-size:$likesize%'>". |
|
$message. |
|
'</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 ($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.'); |
Line 1396 sub filter_regexp {
|
Line 1489 sub filter_regexp {
|
|
|
|
|
sub get_post_contents { |
sub get_post_contents { |
my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_; |
my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$numver) = @_; |
my $discussion = ''; |
my $discussion = ''; |
my $start=$numver; |
my $start=$numver; |
my $end=$numver + 1; |
my $end=$numver + 1; |
Line 1414 sub get_post_contents {
|
Line 1507 sub get_post_contents {
|
$$contrib{$idx.':sendername'}, |
$$contrib{$idx.':sendername'}, |
$$contrib{$idx.':senderdomain'}); |
$$contrib{$idx.':senderdomain'}); |
$$screenname=$$contrib{$idx.':screenname'}; |
$$screenname=$$contrib{$idx.':screenname'}; |
|
$$showaboutme = &Apache::lonnet::usertools_access($$contrib{$idx.':sendername'}, |
my $sender=&Apache::loncommon::aboutmewrapper( |
$$contrib{$idx.':senderdomain'}, |
$$plainname, |
'aboutme'); |
$$contrib{$idx.':sendername'}, |
my $sender = $$plainname; |
$$contrib{$idx.':senderdomain'}).' ('. |
if ($$showaboutme) { |
$$contrib{$idx.':sendername'}.':'. |
$sender = &Apache::loncommon::aboutmewrapper( |
$$contrib{$idx.':senderdomain'}.')'; |
$$plainname, |
|
$$contrib{$idx.':sendername'}, |
|
$$contrib{$idx.':senderdomain'}); |
|
} |
|
if ($seeid) { |
|
$sender .= ' ('. $$contrib{$idx.':sendername'}.':'. |
|
$$contrib{$idx.':senderdomain'}.')'; |
|
} |
my $attachmenturls = $$contrib{$idx.':attachmenturl'}; |
my $attachmenturls = $$contrib{$idx.':attachmenturl'}; |
my @postversions = (); |
my @postversions = (); |
if ($type eq 'allversions' || $type eq 'export') { |
if ($type eq 'allversions' || $type eq 'export') { |
Line 2842 sub send_msg {
|
Line 2942 sub send_msg {
|
return ($status,$sendsomething); |
return ($status,$sendsomething); |
} |
} |
|
|
|
# Store feedback "likes" |
|
|
|
sub storefeedbacklikes { |
|
my ($likes,$uname,$udom,$course)=@_; |
|
unless ($likes) { $likes=0; } |
|
if ($likes>0) { $likes=1; } |
|
if ($likes<0) { $likes=-1; } |
|
unless ($uname) { $uname=$env{'user.name'}; } |
|
unless ($udom) { $udom=$env{'user.domain'}; } |
|
unless ($course) { $course=$env{'request.course.id'}; } |
|
my %record=&getfeedbackrecords($uname,$udom,$course); |
|
my $totallikes=$record{'totallikes'}; |
|
$totallikes+=$likes; |
|
my %newrecord=('likes_user' => $env{'user.name'}, |
|
'likes_domain' => $env{'user.domain'}, |
|
'likes' => $likes, |
|
'totallikes' => $totallikes); |
|
return &Apache::lonnet::cstore(\%newrecord,'_feedback',$course,$udom,$uname); |
|
} |
|
|
sub adddiscuss { |
sub adddiscuss { |
my ($symb,$email,$anon,$attachmenturl,$subject,$group)=@_; |
my ($symb,$email,$anon,$attachmenturl,$subject,$group)=@_; |
my $status=''; |
my $status=''; |
Line 2940 sub adddiscuss {
|
Line 3060 sub adddiscuss {
|
$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'}); |
} |
} |
my %record=&Apache::lonnet::restore('_discussion'); |
my %record=&getdiscussionrecords(); |
my ($temp)=keys(%record); |
my ($temp)=keys(%record); |
unless ($temp=~/^error\:/) { |
unless ($temp=~/^error\:/) { |
my %newrecord=(); |
my %newrecord=(); |
Line 2955 sub adddiscuss {
|
Line 3075 sub adddiscuss {
|
return $status.'<br />'; |
return $status.'<br />'; |
} |
} |
|
|
|
# Routine to get the complete discussion records |
|
|
|
sub getdiscussionrecords { |
|
my ($uname,$udom,$course)=@_; |
|
unless ($uname) { $uname=$env{'user.name'}; } |
|
unless ($udom) { $udom=$env{'user.domain'}; } |
|
unless ($course) { $course=$env{'request.course.id'}; } |
|
my %record=&Apache::lonnet::restore('_discussion',$course,$udom,$uname); |
|
return %record; |
|
} |
|
|
|
# Store discussion "likes" |
|
|
|
sub storediscussionlikes { |
|
my ($likes,$uname,$udom,$course)=@_; |
|
unless ($likes) { $likes=0; } |
|
if ($likes>0) { $likes=1; } |
|
if ($likes<0) { $likes=-1; } |
|
unless ($uname) { $uname=$env{'user.name'}; } |
|
unless ($udom) { $udom=$env{'user.domain'}; } |
|
unless ($course) { $course=$env{'request.course.id'}; } |
|
my %record=&getdiscussionrecords($uname,$udom,$course); |
|
my $totallikes=$record{'totallikes'}; |
|
my $totalvotes=$record{'totalvotes'}; |
|
$totallikes+=$likes; |
|
$totalvotes++; |
|
my %newrecord=('likes_user' => $env{'user.name'}, |
|
'likes_domain' => $env{'user.domain'}, |
|
'likes' => $likes, |
|
'totallikes' => $totallikes, |
|
'totalvotes' => $totalvotes); |
|
my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname); |
|
return $status; |
|
} |
|
|
sub get_discussion_info { |
sub get_discussion_info { |
my ($idx,%contrib) = @_; |
my ($idx,%contrib) = @_; |
my $changelast = 0; |
my $changelast = 0; |
Line 3481 sub handler {
|
Line 3636 sub handler {
|
# --------------------------- Get query string for limited number of parameters |
# --------------------------- Get query string for limited number of parameters |
|
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']); |
['like','unlike','hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']); |
my $group = $env{'form.group'}; |
my $group = $env{'form.group'}; |
my %attachmax = ( |
my %attachmax = ( |
text => &mt('(128 KB max size)'), |
text => &mt('(128 KB max size)'), |
Line 3562 sub handler {
|
Line 3717 sub handler {
|
my %attachmsgs = (); |
my %attachmsgs = (); |
my %allattachments = (); |
my %allattachments = (); |
my %imsfiles = (); |
my %imsfiles = (); |
my ($screenname,$plainname); |
my ($screenname,$plainname,$showaboutme); |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
$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'}); |
$r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname)); |
$r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname,\$showaboutme)); |
} |
} |
$r->print(&Apache::loncommon::end_page()); |
$r->print(&Apache::loncommon::end_page()); |
return OK; |
return OK; |
Line 3759 ENDREDIR
|
Line 3914 ENDREDIR
|
'0','0','','',$env{'form.previous'},undef,undef,undef, |
'0','0','','',$env{'form.previous'},undef,undef,undef, |
undef,undef,undef,$group); |
undef,undef,undef,$group); |
return OK; |
return OK; |
|
} elsif (($env{'form.like'}) || ($env{'form.unlike'})) { |
|
# ----------------------------------------------------------------- Like/unlike |
|
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); |
|
# |
|
# 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 %contrib=&Apache::lonnet::dump('disclikes', |
|
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
|
$env{'course.'.$env{'request.course.id'}.'.num'}, |
|
'^'.$prefix); |
|
# Get all who like or unlike this |
|
my $currentlikers=$contrib{$prefix.'likers'}; |
|
my $currentunlikers=$contrib{$prefix.'unlikers'}; |
|
# Get the current "likes" count |
|
my $likes=$contrib{$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 ($currentlikers=~/\,\Q$thisuser\E\,/) { |
|
$alreadyflag=1; |
|
} else { |
|
if ($currentunlikers=~/\,\Q$thisuser\E\,/) { |
|
$currentunlikers=~s/\,\Q$thisuser\E\,//g; |
|
} else { |
|
$currentlikers.=','.$thisuser.','; |
|
} |
|
$likes++; |
|
} |
|
} else { |
|
if ($currentunlikers=~/\,\Q$thisuser\E\,/) { |
|
$alreadyflag=1; |
|
} else { |
|
if ($currentlikers=~/\,\Q$thisuser\E\,/) { |
|
$currentlikers=~s/\,\Q$thisuser\E\,//g; |
|
} else { |
|
$currentunlikers.=','.$thisuser.','; |
|
} |
|
$likes--; |
|
} |
|
} |
|
my $result; |
|
# $alreadyflag would be 1 if they tried to double-like or double-unlike |
|
unless ($alreadyflag) { |
|
my %newhash=($prefix.'likes' => $likes, |
|
$prefix.'likers' => $currentlikers, |
|
$prefix.'unlikers' => $currentunlikers); |
|
# 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') { |
|
# 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 { |
|
# Oops, something went wrong |
|
$result=&mt("Failed to register vote"); |
|
} |
|
} |
|
&redirect_back($r,$feedurl,$result.'<br />', |
|
'0','0','','',$env{'form.previous'},undef,undef,undef, |
|
undef,undef,undef,$group); |
|
return OK; |
} elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) { |
} elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) { |
my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'}); |
my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'}); |
if ($env{'form.cmd'} eq 'threadedon') { |
if ($env{'form.cmd'} eq 'threadedon') { |