".
+ "
".
$message.
'
';
+ if ($canvote) {
+ my $ownpost;
+ if (($uname eq $env{'user.name'}) &&
+ ($udom eq $env{'user.domain'})) {
+ $ownpost = 1;
+ }
+# Put in the like and unlike buttons
+ if ($ownpost || (($hiddens{$idx}) && ($seehidden))) {
+ my $novote;
+ if ($ownpost) {
+ $novote = &mt('No voting for your own posts.');
+ } else {
+ $novote = &mt('No voting for hidden posts.');
+ }
+ $$discussionitems[$idx].=
+ '
'.
+ ' '.
+ '';
+
+ } else {
+ if ($userlikes{$idx}) {
+ $$discussionitems[$idx].='
';
+ } else {
+ $$discussionitems[$idx].=' '.&discussion_link($symb,'
','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));
+ }
+ if ($userunlikes{$idx}) {
+ $$discussionitems[$idx].='
';
+ } else {
+ $$discussionitems[$idx].=' '.&discussion_link($symb,'
','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting"));
+ }
+ }
+ }
+ if ($seeid || $canvote) {
+ 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.');
- if ($seeid) {
+ $$discussionitems[$idx] .= ' '.&mt('This post has been edited by the author.');
+ if ($seehidden) {
$$discussionitems[$idx] .= ' '.
&discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group));
}
@@ -1456,13 +1612,13 @@ sub filter_regexp {
sub get_post_contents {
- my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_;
+ my ($contrib,$idx,$seeid,$seehidden,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$numver) = @_;
my $discussion = '';
my $start=$numver;
my $end=$numver + 1;
%{$$imsfiles{$idx}}=();
if ($type eq 'allversions') {
- unless($seeid) {
+ unless($seehidden) {
$discussion=&mt('You do not have privileges to view all versions of posts.').' '.&mt('Please select a different role.');
return $discussion;
}
@@ -1474,13 +1630,20 @@ sub get_post_contents {
$$contrib{$idx.':sendername'},
$$contrib{$idx.':senderdomain'});
$$screenname=$$contrib{$idx.':screenname'};
-
- my $sender=&Apache::loncommon::aboutmewrapper(
+ $$showaboutme = &Apache::lonnet::usertools_access($$contrib{$idx.':sendername'},
+ $$contrib{$idx.':senderdomain'},
+ 'aboutme');
+ my $sender = $$plainname;
+ if ($$showaboutme) {
+ $sender = &Apache::loncommon::aboutmewrapper(
$$plainname,
$$contrib{$idx.':sendername'},
- $$contrib{$idx.':senderdomain'}).' ('.
- $$contrib{$idx.':sendername'}.':'.
- $$contrib{$idx.':senderdomain'}.')';
+ $$contrib{$idx.':senderdomain'});
+ }
+ if ($seeid) {
+ $sender .= ' ('.$$contrib{$idx.':sendername'}.':'.
+ $$contrib{$idx.':senderdomain'}.')';
+ }
my $attachmenturls = $$contrib{$idx.':attachmenturl'};
my @postversions = ();
if ($type eq 'allversions' || $type eq 'export') {
@@ -1596,11 +1759,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 = '';
@@ -1665,6 +1833,7 @@ END
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
+ my $numoldver = 0;
if ($contrib{$idx.':history'}) {
if ($contrib{$idx.':history'} =~ /:/) {
my @oldversions = split(/:/,$contrib{$idx.':history'});
@@ -1673,36 +1842,25 @@ END
$numoldver = 1;
}
}
- if ($env{'form.replydisc'}) {
- if ($contrib{$idx.':history'}) {
- if ($contrib{$idx.':history'} =~ /:/) {
- my @oldversions = split(/:/,$contrib{$idx.':history'});
- $numoldver = @oldversions;
- } else {
- $numoldver = 1;
- }
+ if ($idx > 0) {
+ my (%msgversions,%subversions,$htmldecode);
+ $htmldecode = 0;
+ if ($env{'form.replydisc'}) {
+ $htmldecode = 1;
}
- if ($idx > 0) {
- my %msgversions = ();
- &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
+ &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
+ &get_post_versions(\%subversions,$contrib{$idx.':subject'},$htmldecode,
+ $numoldver);
+ $subject = $subversions{$numoldver};
+ if ($env{'form.replydisc'}) {
$quote = $msgversions{$numoldver};
- }
- if ($idx > 0) {
- my %subversions = ();
- &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
- $subject = &mt('Re: ').$subversions{$numoldver};
- }
- $subject = &HTML::Entities::encode($subject,'<>&"');
- } else {
- $attachmenturls = $contrib{$idx.':attachmenturl'};
- if ($idx > 0) {
- my %msgversions = ();
- &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
+ $subject = &HTML::Entities::encode(&mt('Re: ').$subject,'<>&"');
+ } else {
$comment = $msgversions{$numoldver};
- my %subversions = ();
- &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
- $subject = $subversions{$numoldver};
}
+ }
+ if ($env{'form.editdisc'}) {
+ $attachmenturls = $contrib{$idx.':attachmenturl'};
if (defined($contrib{$idx.':replyto'})) {
$parentmsg = $contrib{$idx.':replyto'};
}
@@ -1794,7 +1952,7 @@ END
my %onload = ('onload' => 'window.focus();setposttype();');
my %parms=('add_entries' => \%onload);
- if ($env{'form.modal'} ne 'yes') { 'bread_crumbs' => $brcrum }
+ if ($env{'form.modal'} ne 'yes') { $parms{'bread_crumbs'} = $brcrum; }
my $start_page=
&Apache::loncommon::start_page('Resource Feedback and Discussion',$js,\%parms);
@@ -1803,7 +1961,11 @@ END
unless (&contains_block_html($quote)) {
&newline_to_br(\$quote);
}
- $quote='
'.&Apache::lontexconvert::msgtexconverted($quote).'
';
+ $quote=&Apache::lonhtmlcommon::start_pick_box().
+ &Apache::lonhtmlcommon::row_title(&mt('Quote')).
+ &Apache::lontexconvert::msgtexconverted($quote).
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::end_pick_box();
}
my $header='';
unless ($env{'form.modal'}) {
@@ -1811,6 +1973,7 @@ END
}
$r->print(<
$lt{'myqu'}
$header
END
if ($env{'form.editdisc'} || $env{'form.replydisc'}) {
@@ -1893,7 +2067,6 @@ END
$attachnum += @currnewattach;
}
my $blockblog = &Apache::loncommon::blocking_status('blogs');
- $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver,'',$blockblog));
if ($attachnum > 0) {
if (@currnewattach > 0) {
$newattachmsg .= '
'.&mt('New attachments').'
';
@@ -1913,9 +2086,10 @@ END
$r->print("
$lt{'reta'}:$attachmsg
\n");
}
if ($newattachmsg) {
- $r->print("$newattachmsg
");
+ $r->print("$newattachmsg");
}
}
+ $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver,'',$blockblog));
}
$r->print(&generate_preview_button().
&Apache::loncommon::end_page());
@@ -2356,24 +2530,11 @@ sub print_showposters {
$r->send_http_header;
&Apache::lonenc::check_encrypt(\$symb);
- my $crs='/'.$env{'request.course.id'};
- if ($env{'request.course.sec'}) {
- $crs.='_'.$env{'request.course.sec'};
- }
- $crs=~s/\_/\//g;
- my $seeid;
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $group = $env{'form.group'};
my $ressymb = &wrap_symb($symb);
- if (($group ne '') &&
- ($ressymb =~ m|^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|)) {
- if (&check_group_priv($group,'dgp') eq 'ok') {
- $seeid = 1;
- }
- } else {
- $seeid=&Apache::lonnet::allowed('rin',$crs);
- }
+ my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
$cdom,$cnum);
my %namesort = ();
@@ -2389,7 +2550,7 @@ sub print_showposters {
for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
my $hidden=($contrib{'hidden'}=~/\.$idx\./);
my $deleted=($contrib{'deleted'}=~/\.$idx\./);
- unless ((($hidden) && (!$seeid)) || ($deleted)) {
+ unless ((($hidden) && (!$seehidden)) || ($deleted)) {
if ((!$contrib{$idx.':anonymous'}) || (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
my $lastname = $names{'lastname'};
@@ -2414,7 +2575,7 @@ sub print_showposters {
}
}
}
- }
+ }
}
my $start_page = &Apache::loncommon::start_page('Discussion options');
@@ -2537,7 +2698,7 @@ sub fail_redirect {
'only_body' => 1,}));
$r->print(<
-$lt{'sorr'}
+$lt{'sorr'}
ENDFAILREDIR
$r->print(&Apache::loncommon::end_page());
}
@@ -2683,7 +2844,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,
@@ -2754,12 +2915,7 @@ sub screen_header {
my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards');
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- my $realsymb = $symb;
- if ($symb=~/^bulletin___/) {
- my $filename=(&Apache::lonnet::decode_symb($symb))[2];
- $filename=~s|^adm/wrapper/||;
- $realsymb=&Apache::lonnet::symbread($filename);
- }
+ my $realsymb = &get_realsymb($symb);
if (!$blocked && &discussion_open(undef,$realsymb) &&
(&Apache::lonnet::allowed('pch',
$env{'request.course.id'}.
@@ -2935,7 +3091,7 @@ sub storefeedbackpoints {
my %record=('grader_user' => $env{'user.name'},
'grader_domain' => $env{'user.domain'},
'points' => $points);
- return &Apache::lonnet::cstore(\%record,'_feedback');
+ return &Apache::lonnet::cstore(\%record,'_feedback',$course,$udom,$uname);
}
# Store feedback "likes"
@@ -2955,19 +3111,14 @@ sub storefeedbacklikes {
'likes_domain' => $env{'user.domain'},
'likes' => $likes,
'totallikes' => $totallikes);
- return &Apache::lonnet::cstore(\%newrecord,'_feedback');
+ return &Apache::lonnet::cstore(\%newrecord,'_feedback',$course,$udom,$uname);
}
sub adddiscuss {
my ($symb,$email,$anon,$attachmenturl,$subject,$group)=@_;
my $status='';
- my $realsymb;
- if ($symb=~/^bulletin___/) {
- my $filename=(&Apache::lonnet::decode_symb($symb))[2];
- $filename=~s|^adm/wrapper/||;
- $realsymb=&Apache::lonnet::symbread($filename);
- }
+ my $realsymb = &get_realsymb($symb);
my ($cnum,$cdom);
if ($env{'request.course.id'}) {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -3065,6 +3216,7 @@ sub adddiscuss {
$newrecord{'subnumber'}=$record{'subnumber'}+1;
$status.='
'.&mt('Registering').': '.
&Apache::lonnet::cstore(\%newrecord,'_discussion');
+ &updatekarma();
}
} else {
$status.='Failed.';
@@ -3088,9 +3240,53 @@ sub getdiscussionrecords {
sub getdiscussionstats {
my %record=&getdiscussionrecords(@_);
- return ($record{'subnumber'},$record{'points'},$record{'totallikes'});
+ my $totalvotes = $record{'totallikes'} + $record{'totalunlikes'};
+ return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$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
@@ -3103,27 +3299,31 @@ sub storediscussionpoints {
my %record=('grader_user' => $env{'user.name'},
'grader_domain' => $env{'user.domain'},
'points' => $points);
- return &Apache::lonnet::cstore(\%record,'_discussion');
+ return &Apache::lonnet::cstore(\%record,'_discussion',$course,$udom,$uname);
}
# Store discussion "likes"
sub storediscussionlikes {
- my ($likes,$uname,$udom,$course)=@_;
- unless ($likes) { $likes=0; }
- if ($likes>0) { $likes=1; }
- if ($likes<0) { $likes=-1; }
+ my ($chglikes,$chgunlikes,$uname,$udom,$course,$context)=@_;
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'};
- $totallikes+=$likes;
+ my $totalunlikes=$record{'totalunlikes'};
+ $totallikes += $chglikes;
+ $totalunlikes += $chgunlikes;
my %newrecord=('likes_user' => $env{'user.name'},
'likes_domain' => $env{'user.domain'},
- 'likes' => $likes,
- 'totallikes' => $totallikes);
- return &Apache::lonnet::cstore(\%newrecord,'_discussion');
+ 'totallikes' => $totallikes,
+ 'totalunlikes' => $totalunlikes,
+ 'context' => $context);
+ my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname);
+ if ($status eq 'ok') {
+ &updatekarma($uname,$udom,$course);
+ }
+ return $status;
}
sub get_discussion_info {
@@ -3271,11 +3471,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 = <
@@ -3289,8 +3489,8 @@ END
# Breadcrumbs
my $brcrum = [{'href' => '',
'text' => 'Discussion Post Attachments'}];
- my %parms=();
- if ($env{'form.modal'} ne 'yes') { 'bread_crumbs' => $brcrum }
+ my %parms=('only_body' => 1);
+ if ($env{'form.modal'} ne 'yes') { $parms{'bread_crumbs'} = $brcrum; }
my $start_page =
&Apache::loncommon::start_page('Discussion Post Attachments',$js,\%parms);
@@ -3317,45 +3517,43 @@ END
$start_page
$toolarge