--- loncom/interface/lonfeedback.pm 2012/01/05 21:18:49 1.322 +++ loncom/interface/lonfeedback.pm 2012/01/07 03:01:11 1.327 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.322 2012/01/05 21:18:49 www Exp $ +# $Id: lonfeedback.pm,v 1.327 2012/01/07 03:01:11 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -827,7 +827,17 @@ sub action_links_bar { $discussion .= '&previous='.$prevread; } $discussion .= &group_args($group); - $discussion .= '">'.&mt('Export').''; + $discussion .= '">'.&mt('Export').''; + if (&Apache::lonnet::allowed('rin',$env{'request.course.id'})) { + $discussion .= '  '; + $discussion .=''.&mt('Undelete all deleted entries').''; + } + $discussion.=''; if ($newpostsflag) { if (!$markondisp) { $discussion .='0) { + $sender.=' ('.&mt("[_1] likes",$thislikes).')'; + } elsif ($thislikes<0) { + $sender.=' ('.&mt("[_1] unlikes",abs($thislikes)).')'; + } if (&editing_allowed($escsymb.':::'.$idx,$group)) { if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { $sender.=' '. @@ -1289,8 +1348,23 @@ sub build_posting_display { if ($$dischash{$toggkey}) { $$discussionitems[$idx].='  '.$ctlink; } +# 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"; + } $$discussionitems[$idx].= '
'. - $message.'
'; + "
". + $message. + '
'; if ($contrib{$idx.':history'}) { my @postversions = (); $$discussionitems[$idx] .= &mt('This post has been edited by the author.'); @@ -1309,12 +1383,19 @@ sub build_posting_display { $$discussionitems[$idx] .= ''.$version.'. - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' '; } } +# end of unless ($$notshown ...) } +# end of if ($message) ... } +# end of the else-branch of target being export } +# end of unless hidden or deleted } +# end of the loop over all discussion entries } +# end of "if there actually are any discussions } +# end of subroutine "build_posting_display" } sub filter_regexp { @@ -3571,7 +3652,7 @@ sub handler { # --------------------------- Get query string for limited number of parameters &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['like','unlike','modal','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','modal','hide','unhide','deldisc','undeleteall','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 %attachmax = ( text => &mt('(128 KB max size)'), @@ -3851,6 +3932,11 @@ ENDREDIR 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'}, @@ -3859,8 +3945,10 @@ ENDREDIR # 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'}) { @@ -3868,7 +3956,7 @@ ENDREDIR $alreadyflag=1; } else { if ($currentunlikers=~/\,\Q$thisuser\E\,/) { - $currentunlikers=~s/\,\Q$thisuser\E\,//; + $currentunlikers=~s/\,\Q$thisuser\E\,//g; } else { $currentlikers.=','.$thisuser.','; } @@ -3879,7 +3967,7 @@ ENDREDIR $alreadyflag=1; } else { if ($currentlikers=~/\,\Q$thisuser\E\,/) { - $currentlikers=~s/\,\Q$thisuser\E\,//; + $currentlikers=~s/\,\Q$thisuser\E\,//g; } else { $currentunlikers.=','.$thisuser.','; } @@ -3887,14 +3975,17 @@ ENDREDIR } } 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'"); @@ -3903,6 +3994,7 @@ ENDREDIR $result=&mt("Registered 'Unlike'"); } } else { +# Oops, something went wrong $result=&mt("Failed to register vote"); } } @@ -3993,6 +4085,24 @@ ENDREDIR &Apache::loncommon::end_page(); $r->print($start_page.$discussion.$end_page); return OK; + + } elsif ($env{'form.undeleteall'}) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.undeleteall'}); + $r->print(&Apache::loncommon::start_page('Undelete all deleted discussion entries')); + if (&Apache::lonnet::allowed('rin',$env{'request.course.id'})) { + if (&Apache::lonnet::store({'deleted' => ''},$symb,$env{'request.course.id'}, + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries"))); + } else { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1)); + } + $r->print("
".&mt("Return and reload").""); + } + $r->print(&Apache::loncommon::end_page()); + return OK; } else { # ------------------------------------------------------------- Normal feedback my $feedurl=$env{'form.postdata'};