--- loncom/interface/lonfeedback.pm 2012/01/10 00:54:05 1.331 +++ loncom/interface/lonfeedback.pm 2012/03/15 12:45:21 1.340 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.331 2012/01/10 00:54:05 www Exp $ +# $Id: lonfeedback.pm,v 1.340 2012/03/15 12:45:21 goltermann Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1019,7 +1019,6 @@ sub build_posting_display { my $twoplus=$ave+2.*$stddev; my $oneminus=$ave-$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 # @@ -1156,18 +1155,12 @@ sub build_posting_display { @{$$namesort{$lastname}{$firstname}} = ("$idx"); } if ($outputtarget ne 'tex') { - unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) { - $sender.=' '.&discussion_link($symb,''.&mt('Like').'','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting")); - } - unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { - $sender.=' '.&discussion_link($symb,''.&mt('Unlike').'',,'unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting")); - } - my $thislikes=$likes{$symb.':'.$idx.':likes'}; - if ($thislikes>0) { - $sender.=' ('.&mt("[_1] likes",$thislikes).')'; - } elsif ($thislikes<0) { - $sender.=' ('.&mt("[_1] unlikes",abs($thislikes)).')'; +# Add karma stars + my $karma=&userkarma($contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); + for (my $i=1;$i<=$karma;$i++) { + $sender.=''.&mt('Contributor Kudos').''; } +# Can people edit this? if (&editing_allowed($escsymb.':::'.$idx,$group)) { if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { $sender.=' '. @@ -1363,13 +1356,32 @@ sub build_posting_display { } elsif ($thislikes<$oneminus) { $likesize="75"; } +# Actually glue in the message itself $$discussionitems[$idx].= '
'. "
". $message. '
'; +# Put in the like and unlike buttons + unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) { + $$discussionitems[$idx].=' '.&discussion_link($symb,''.&mt('Like').'','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting")); + } else { + $$discussionitems[$idx].=''.&mt('You like this posting').''; + } + unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { + $$discussionitems[$idx].=' '.&discussion_link($symb,''.&mt('Unlike').'',,'unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting")); + } else { + $$discussionitems[$idx].=''.&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'}) { 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) { $$discussionitems[$idx] .= '  '. &discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group)); @@ -1596,11 +1608,16 @@ sub mail_screen { } my %lt = &Apache::lonlocal::texthash( - 'myqu' => 'My question/comment/feedback:', + 'myqu' => 'Question/comment/feedback:', 'title' => 'Title', 'reta' => 'Retained attachments', 'atta' => 'Attachment', ); + if($env{'form.editdisc'} || $env{'form.replydisc'}){ + %lt = &Apache::lonlocal::texthash( + 'myqu' => 'Post Discussion', + ); + } my $restitle = &get_resource_title($caller_symb,$feedurl); my $quote=''; my $subject = ''; @@ -1811,6 +1828,7 @@ END } $r->print(<$lt{'myqu'} $header
@@ -1831,18 +1849,26 @@ END $r->print(<$lt{'myqu'} +

$textareaheader

+

$latexHelp

-$lt{'title'}:

-

-

END + +$r->print(&Apache::lonhtmlcommon::start_pick_box()); +$r->print(&Apache::lonhtmlcommon::row_title(&mt('Subject'))); +$r->print('

'); +$r->print(&Apache::lonhtmlcommon::row_closure()); +$r->print(&Apache::lonhtmlcommon::row_title(&mt('Message'))); +$r->print(''); +$r->print(&Apache::lonhtmlcommon::row_closure(1)); +$r->print(&Apache::lonhtmlcommon::end_pick_box()); + if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) { if ($env{'form.origpage'}) { foreach my $attach (@currnewattach) { @@ -2683,7 +2709,7 @@ sub no_redirect_back { 'add_entries' => \%onload,); if ($feedurl !~ m{^/adm/feedback}) { - $body_options{'rediect'} = [2,$feedurl]; + $body_options{'redirect'} = [2,$feedurl]; } my $start_page= &Apache::loncommon::start_page('Feedback not sent',undef, @@ -3065,6 +3091,7 @@ sub adddiscuss { $newrecord{'subnumber'}=$record{'subnumber'}+1; $status.='
'.&mt('Registering').': '. &Apache::lonnet::cstore(\%newrecord,'_discussion'); + &updatekarma(); } } else { $status.='Failed.'; @@ -3112,6 +3139,27 @@ sub updatekarma { 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 @@ -3148,7 +3196,11 @@ sub storediscussionlikes { 'likes' => $likes, 'totallikes' => $totallikes, 'totalvotes' => $totalvotes); - return &Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname); + my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname); + if ($status eq 'ok') { + &updatekarma($uname,$udom,$course); + } + return $status; } sub get_discussion_info { @@ -3296,11 +3348,11 @@ sub modify_attachments { my %lt = &Apache::lonlocal::texthash( 'subj' => 'Subject', - 'thfo' => 'The following attachments were part of the most recent saved version of this posting.', 'chth' => 'Check the checkboxes for any you wish to remove.', 'thef' => 'The following attachments have been uploaded for inclusion with this posting.', - 'adda' => 'Add a new attachment to this post.', + 'adda' => 'Add a new attachment to this post', 'stch' => 'Save Changes', + 'clic' => 'Add/remove attachments', ); my $js = < @@ -3314,7 +3366,7 @@ END # Breadcrumbs my $brcrum = [{'href' => '', 'text' => 'Discussion Post Attachments'}]; - my %parms=(); + my %parms=('only_body' => 1); if ($env{'form.modal'} ne 'yes') { 'bread_crumbs' => $brcrum } my $start_page = @@ -3343,44 +3395,43 @@ $start_page $toolarge
- - - - - - - - - -
- Subject: $subject

+

$lt{'clic'}

END - if ($idx) { - if ($attachmenturls) { - my @currold = keys(%currattach); - if (@currold > 0) { - $r->print($lt{'thfo'}.'
'.$lt{'chth'}.'
'."\n"); - foreach my $id (@currold) { - my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'}); - $attachurl =~ m#/([^/]+)$#; - $r->print('
'."\n"); + $r->print(&Apache::lonhtmlcommon::start_pick_box()); + $r->print(&Apache::lonhtmlcommon::row_title(&mt('Subject'))); + $r->print(''.$subject.''); + $r->print(&Apache::lonhtmlcommon::row_closure()); + $r->print(&Apache::lonhtmlcommon::row_title($lt{'adda'})); + $r->print(' '.$attachmaxtext); + + if(($idx)||(ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)){ + $r->print(&Apache::lonhtmlcommon::row_closure()); + $r->print(&Apache::lonhtmlcommon::row_title(&mt('Attachments'))); + if ($idx) { + if ($attachmenturls) { + my @currold = keys(%currattach); + if (@currold > 0) { + $r->print($lt{'thfo'}.'
'.$lt{'chth'}.'
'."\n"); + foreach my $id (@currold) { + my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'}); + $attachurl =~ m#/([^/]+)$#; + $r->print('
'."\n"); + } + $r->print("
"); } - $r->print("
"); } } - } - if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) { - $r->print($lt{'thef'}.'
'.$lt{'chth'}.'
'."\n"); - foreach my $attach (@{$currnewattach}) { - $attach =~ m#/([^/]+)$#; - $r->print('
'."\n"); + if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) { + $r->print($lt{'chth'}.'
'."\n"); + foreach my $attach (@{$currnewattach}) { + $attach =~ m#/([^/]+)$#; + $r->print('
'."\n"); + } } - $r->print("
"); } + $r->print(&Apache::lonhtmlcommon::row_closure(1)); + $r->print(&Apache::lonhtmlcommon::end_pick_box()); $r->print(<
- $lt{'adda'} -
$attachmaxtext
@@ -3438,12 +3489,12 @@ sub generate_attachments_button { my $origpage = $ENV{'REQUEST_URI'}; my $att=$attachnum.' '.&mt("attachments"); my %lt = &Apache::lonlocal::texthash( - 'clic' => 'Click to add/remove attachments', + 'clic' => 'Add/remove attachments', ); my $response = (< -$lt{'clic'}: