--- loncom/interface/lonfeedback.pm 2012/01/04 18:23:38 1.318 +++ loncom/interface/lonfeedback.pm 2023/09/15 23:02:08 1.370.2.7 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.318 2012/01/04 18:23:38 www Exp $ +# $Id: lonfeedback.pm,v 1.370.2.7 2023/09/15 23:02:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,8 +44,8 @@ use HTML::LCParser(); #use HTML::Tidy::libXML; use Apache::lonspeller(); use Apache::longroup; -use Cwd; -use LONCAPA; +use Archive::Zip qw( :ERROR_CODES ); +use LONCAPA qw(:DEFAULT :match); sub discussion_open { my ($status,$symb)=@_; @@ -82,6 +82,26 @@ sub discussion_visible { return 1; } +sub discussion_vote_available { + my ($status,$symb)=@_; + my $canvote=&Apache::lonnet::EXT('resource.0.discussvote',$symb); + if ((lc($canvote) eq 'yes') || + ((lc($canvote) eq 'notended') && (&discussion_open($status,$symb)))) { + return 1; + } +} + +sub get_realsymb { + my ($symb) = @_; + my $realsymb = $symb; + if ($symb=~/^bulletin___/) { + my $filename=(&Apache::lonnet::decode_symb($symb))[2]; + $filename=~s{^adm/wrapper/}{}; + $realsymb=&Apache::lonnet::symbread($filename); + } + return $realsymb; +} + sub list_discussion { my ($mode,$status,$ressymb,$imsextras,$group)=@_; unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); } @@ -257,14 +277,15 @@ sub list_discussion { $visit ++; my $seeid; - if (($group ne '') && ($mode eq 'board') && - ($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); + if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + $seeid = 1; } + my $seehidden = &can_see_hidden($mode,$ressymb,undef,$group,$cdom,$cnum,$crs); + +# Is voting on discussions available + my $realsymb = &get_realsymb($ressymb); + my $canvote = &discussion_vote_available($status,$realsymb); + my @discussionitems=(); my %shown = (); my @posteridentity=(); @@ -286,7 +307,7 @@ sub list_discussion { $discinfo{$visitkey} = $visit; &Apache::lonnet::put('nohist_'.$cid.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'}); - &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$encsymb,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group); + &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$seehidden,$canvote,$prevread,$sortposts,$encsymb,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group); my $discussion=''; my $manifestfile; @@ -315,12 +336,15 @@ sub list_discussion { 'aner' => 'An error occurred opening the manifest file.', 'difo' => 'Discussion for', 'aerr' => 'An error occurred opening the export file for posting', + 'discussions' => 'DISCUSSIONS' + ); + my %js_lt = &Apache::lonlocal::texthash( 'aysu' => 'Are you sure you want to delete this post?', 'dpwn' => 'Deleted posts will no longer be visible to you and other students', 'bwco' => 'but will continue to be visible to your instructor', 'depo' => 'Deleted posts will no longer be visible to you or anyone else.', - 'discussions' => 'DISCUSSIONS' ); + &js_escape(\%js_lt); my $currdisp = $lt{'allposts'}; my $currmark = $lt{'onmark'}; @@ -426,12 +450,12 @@ imscp_v1p1.xsd http://www.imsglobal.org/ prevparm = "&previous="+previous } if (caller == 'studentdelete') { - if (confirm("$lt{'aysu'}\\n$lt{'dpwn'},\\n$lt{'bwco'}")) { + if (confirm("$js_lt{'aysu'}\\n$js_lt{'dpwn'},\\n$js_lt{'bwco'}")) { document.location.href = "/adm/feedback?hide="+symbparm+prevparm+groupparm } } else { if (caller == 'seeiddelete') { - if (confirm("$lt{'aysu'}\\n$lt{'depo'}")) { + if (confirm("$js_lt{'aysu'}\\n$js_lt{'depo'}")) { document.location.href = "/adm/feedback?deldisc="+symbparm+prevparm+groupparm } } @@ -442,23 +466,23 @@ imscp_v1p1.xsd http://www.imsglobal.org/ "\n".''; $discussion .= &action_links_bar($colspan,$ressymb,$visible, $newpostsflag,$group, - $prevread,$markondisp); + $prevread,$markondisp,$seehidden); my $escsymb=&escape($ressymb); my $numhidden = keys(%notshown); if ($numhidden > 0) { my $colspan = $maxdepth+1; - $discussion.="\n".''; } @@ -492,7 +516,9 @@ imscp_v1p1.xsd http://www.imsglobal.org/ my $currdepth = 0; my $firstidx = $alldiscussion{$showposts[0]}; foreach my $post (@showposts) { - unless (($sortposts eq 'thread') || (($sortposts eq '') && ($env{'environment.threadeddiscussion'})) || ($outputtarget eq 'export')) { + unless (($sortposts eq 'thread') || + (($sortposts eq '') && (!$env{'environment.unthreadeddiscussion'})) || + ($outputtarget eq 'export')) { $alldiscussion{$post} = $post; } unless ( ($notshown{$alldiscussion{$post}} eq '1') || ($shown{$alldiscussion{$post}} == 0) ) { @@ -539,7 +565,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ my $postingfile; my $postingfilename = $tempexport.'/'.$postfilename; if ($postingfile = Apache::File->new('>'.$postingfilename)) { - print $postingfile 'Discussion Post'. + print $postingfile ''.&mt('Discussion Post').''. $imsitems{$alldiscussion{$post}}{'title'}.' '. $imsitems{$alldiscussion{$post}}{'sender'}. $imsitems{$alldiscussion{$post}}{'timestamp'}.'

'. @@ -646,7 +672,7 @@ END END $discussion .= &action_links_bar($colspan,$ressymb,$visible, $newpostsflag,$group, - $prevread,$markondisp); + $prevread,$markondisp,$seehidden); $discussion .= "
'. - ''; + my $href = '/adm/feedback?allposts=1&symb='.$escsymb; if ($newpostsflag) { - $discussion .= '&previous='.$prevread; + $href .= '&previous='.$prevread; } - $discussion .= &group_args($group); - $discussion .= '">'.&mt('Show all posts').' '.&mt('to display').' '. - $numhidden.' '; + $href .= &group_args($group); if ($showunmark) { - $discussion .= &mt('posts previously marked read'); + $discussion .= &mt('[_1]Show all posts[_2] to display [quant,_3,post] previously marked read', + '','',$numhidden); } else { - $discussion .= &mt('previously viewed posts'); + $discussion .= &mt('[_1]Show all posts[_2] to display [quant,_3,post] previously viewed', + '','',$numhidden); } $discussion .= '
\n"; } if ($outputtarget eq 'export') { @@ -670,22 +696,34 @@ END #Create zip file in prtspool - my $imszipfile = '/prtspool/'. - $env{'user.name'}.'_'.$env{'user.domain'}.'_'. - time.'_'.rand(1000000000).'.zip'; - my $cwd = &getcwd(); - my $imszip = '/home/httpd/'.$imszipfile; - chdir $tempexport; - open(OUTPUT, "zip -r $imszip * 2> /dev/null |"); - close(OUTPUT); - chdir $cwd; - $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive','').'
'; - if ($copyresult) { - $discussion .= &mt('The following errors occurred during export').' -
'.$copyresult; + if (($env{'user.name'} =~ /^$match_username$/) + && ($env{'user.domain'} =~ /^$match_domain$/)) { + my $now = time(); + my $imszipfile = '/prtspool/'. + join('_',$env{'user.name'},$env{'user.domain'},$now). + '_'.rand(1000000000).'.zip'; + my $zip = Archive::Zip->new(); + $zip->addTree($tempexport); + my $imszip = '/home/httpd/'.$imszipfile; + if ($zip->writeToFileNamed($imszip) == AZ_OK) { + $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive[_2]', + '','').'
'; + } else { + $discussion .= &mt('Failed to create zip file').'
'; + } + if ($copyresult) { + $discussion .= ''. + &mt('The following errors occurred during export:'). + '
'.$copyresult; + } + } else { + $discussion .= '

'. + &mt('Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating the zip file.').'

'; } } } else { - $discussion .= '
'.&mt('Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating a manifest file.').'
'; + $discussion .= '

'. + &mt('Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating a manifest file.').'

'; } return $discussion; } @@ -744,9 +782,15 @@ END $discussion.= &send_feedback_link($ressymb); if ($env{'request.role.adv'}) { my $close = &Apache::lonnet::EXT('resource.0.discussend',$ressymb); + my $canvote = &Apache::lonnet::EXT('resource.0.discussvote',$ressymb); if (defined($close) && $close ne '' && $close < time) { - $discussion .= ' '.&mt('(Closed for [_1] roles)', - &Apache::lonnet::plaintext('st',$crstype)); + if ($canvote eq 'notended') { + $discussion .= ' '.&mt('(Posting and voting closed for [_1] roles)', + &Apache::lonnet::plaintext('st',$crstype)); + } else { + $discussion .= ' '.&mt('(Closed for [_1] roles)', + &Apache::lonnet::plaintext('st',$crstype)); + } } } } else { @@ -757,13 +801,51 @@ END return $discussion; } +sub can_see_hidden { + my ($mode,$ressymb,$feedurl,$group,$cdom,$cnum,$crs) = @_; + my $seehidden; + if ($env{'request.course.id'}) { + unless ($cdom ne '' && $cnum ne '') { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + } + if ($crs eq '') { + $crs = '/'.$env{'request.course.id'}; + if ($env{'request.course.sec'}) { + $crs.='_'.$env{'request.course.sec'}; + } + $crs=~s{_}{/}g; + } + if ($mode eq '') { + $mode='board'; + if ($feedurl =~ /$LONCAPA::assess_re/) { + $mode='problem'; + } + } + if (($group ne '') && ($mode eq 'board') && + ($ressymb =~ m{^bulletin___\d+\Q___adm/wrapper/adm/$cdom/$cnum/\E\d+/bulletinboard$})) { + if (&check_group_priv($group,'dgp') eq 'ok') { + $seehidden = 1; + } + } else { + $seehidden=&Apache::lonnet::allowed('rin',$crs); + } + } + return $seehidden; +} sub discussion_link { - my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds)=@_; - my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; + my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds,$title)=@_; + my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; if ($flag) { $link .= '&previous='.$prev; } if ($adds) { $link .= $adds; } - return &Apache::loncommon::modal_link($link,$linktext,600,600); + my $width=600; + my $height=600; + if (($cmd eq 'hide') || ($cmd eq 'unhide') || ($cmd eq 'like') || ($cmd eq 'unlike')) { + $width=300; + $height=200; + } + return &Apache::loncommon::modal_link($link,$linktext,$width,$height,undef,undef,$title); } @@ -773,7 +855,7 @@ sub send_feedback_link { &discussion_link($ressymb, ''.&mt('Post Discussion').'', + '" />'.&mt('Post Discussion').'', 'replydisc'). ''; } @@ -781,15 +863,18 @@ sub send_feedback_link { sub send_message_link { my ($ressymb) = @_; my $output = ''. - ' '.&mt('Send Feedback').''; + &discussion_link($ressymb, + ''.&mt('Send Feedback').'', + 'sendmessageonly'). + ''; return $output; } sub action_links_bar { - my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_; + my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp, + $seehidden) = @_; my $discussion = ''. ''. ''; + $discussion .= '">'.&mt('Export').''; + if ($seehidden) { + $discussion .= '  '; + $discussion .=''.&mt('Undelete all deleted entries').''; + } + $discussion.=''; if ($newpostsflag) { if (!$markondisp) { $discussion .=' @@ -2421,29 +2703,46 @@ sub get_post_attachments { $$attachments{'0'}{'filename'} = $attachmenturls; $$attachments{'0'}{'0'} = 'n'; } - return; } sub fail_redirect { - my ($r,$feedurl) = @_; + my ($r,$feedurl,$delay) = @_; if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' }; my %lt = &Apache::lonlocal::texthash( 'sorr' => 'Sorry, no recipients ...', ); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); - $r->print(&Apache::loncommon::start_page('Feedback not sent',undef, - {'redirect' => [2,$feedurl], - 'only_body' => 1,})); + my %parms=('only_body' => 1); + if ($delay !~ /^\d+(|\.\d+)$/) { + $delay = 2; + } + if ($env{'form.modal'}) { + my $onload = 'document.forms.reldt.submit()'; + if ($delay) { + my $js_delay = int(1000 * $delay); + $onload = "setTimeout(function(){ + document.forms.reldt.submit(); + },$js_delay);"; + } + $parms{'add_entries'}={'onload' => $onload}; + } else { + $parms{'redirect'}=[$delay,$feedurl]; + } + $r->print(&Apache::loncommon::start_page('Feedback not sent',undef,\%parms)); + my $windowname = 'loncapaclient'; $r->print(< -$lt{'sorr'} +

$lt{'sorr'}

+ + ENDFAILREDIR $r->print(&Apache::loncommon::end_page()); } sub redirect_back { - my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_; + my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort, + $rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge,$delay) = @_; my $sorttag = ''; my $roletag = ''; my $statustag = ''; @@ -2542,10 +2841,20 @@ sub redirect_back { &Apache::lonenc::check_encrypt(\$feedurl); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); my %parms=('only_body' => 1); + if ($delay !~ /^\d+(|\.\d+)$/) { + $delay = 0; + } if ($env{'form.modal'}) { - $parms{'add_entries'}={'onLoad' => 'document.forms.reldt.submit()'}; + my $onload = 'document.forms.reldt.submit()'; + if ($delay) { + my $js_delay = int(1000 * $delay); + $onload = "setTimeout(function(){ + document.forms.reldt.submit(); + },$js_delay);"; + } + $parms{'add_entries'}={'onload' => $onload}; } else { - $parms{'redirect'}=[0,$feedurl]; + $parms{'redirect'}=[$delay,$feedurl]; } my $start_page= &Apache::loncommon::start_page('Feedback sent',undef,\%parms); @@ -2573,39 +2882,59 @@ ENDREDIR } sub no_redirect_back { - my ($r,$feedurl) = @_; + my ($r,$feedurl,$delay) = @_; my $nofeed=&mt('Sorry, no feedback possible on this resource ...'); - - my %onload; - - my %body_options = ('only_body' => 1, - 'bgcolor' => '#FFFFFF', - 'add_entries' => \%onload,); - - if ($feedurl !~ m{^/adm/feedback}) { - $body_options{'rediect'} = [2,$feedurl]; + my $form_for_modal; + my %parms=('only_body' => 1, + 'bgcolor' => '#FFFFFF',); + if ($delay !~ /^\d+(|\.\d+)$/) { + $delay = 0; + } + if ($env{'form.modal'}) { + if (($feedurl !~ m{^/adm/feedback}) && ($feedurl ne '')) { + my $onload = 'document.forms.reldt.submit()'; + if ($delay) { + my $js_delay = int(1000 * $delay); + $onload = "setTimeout(function(){ + document.forms.reldt.submit(); + },$js_delay);"; + } + $parms{'add_entries'}={'onload' => $onload}; + my $windowname = 'loncapaclient'; + $form_for_modal = < + +ENDFORM + } + } else { + if (($feedurl !~ m{^/adm/feedback}) && ($feedurl ne '')) { + $parms{'redirect'}=[$delay,$feedurl]; + } } my $start_page= &Apache::loncommon::start_page('Feedback not sent',undef, - \%body_options); - + \%parms); + my $end_page = &Apache::loncommon::end_page(); - &Apache::lonenc::check_encrypt(\$feedurl); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); $r->print (< $nofeed
+$form_for_modal $end_page ENDNOREDIRTWO } sub screen_header { my ($feedurl,$symb,$group) = @_; - my $crscontent = &mt('Question/Comment/Feedback about course content'); - my $crspolicy = &mt('Question/Comment/Feedback about course policy'); + my %default = &Apache::lonlocal::texthash ( + question => 'Question about resource content', + comment => 'Question/Comment/Feedback about course content', + policy => 'Question/Comment/Feedback about course policy', + ); my $contribdisc = &mt('Contribution to course discussion of resource'); my $anoncontrib = &mt('Anonymous contribution to course discussion of resource'); my $namevis = &mt('name only visible to course faculty'); @@ -2613,8 +2942,8 @@ sub screen_header { if ($env{'request.course.id'}) { $crstype = &Apache::loncommon::course_type(); if ($crstype eq 'Community') { - $crscontent = &mt('Question/Comment/Feedback about community content'); - $crspolicy = &mt('Question/Comment/Feedback about community policy'); + $default{'comment'} = &mt('Question/Comment/Feedback about community content'); + $default{'policy'} = &mt('Question/Comment/Feedback about community policy'); $contribdisc = &mt('Contribution to community discussion of resource'); $anoncontrib = &mt('Anonymous contribution to community discussion of resource'); $namevis = &mt('name only visible to community facilitators'); @@ -2622,61 +2951,78 @@ sub screen_header { } my $msgoptions=''; my $discussoptions=''; + my $checkradio = ''; + my $blockblog; + my (%fdbkoptions,%discoptions); unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) { - if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) { - $msgoptions= - '

'; - } - my %optionhash=(); - foreach my $type ('question','comment','policy') { - $optionhash{$type}=$env{'course.'.$env{'request.course.id'}.'.'.$type.'.email.text'}; - } - if (&feedback_available(1)) { - $msgoptions.= - '

'; - } - if (&feedback_available(0,1)) { - $msgoptions.= - '

'; - } - if (&feedback_available(0,0,1)) { - $msgoptions.= - '

'; - } + if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) { + $fdbkoptions{'author'} = 1; + } + if (&feedback_available(1)) { + $fdbkoptions{'question'} = 1; + } + if (&feedback_available(0,1)) { + $fdbkoptions{'course'} = 1; + } + if (&feedback_available(0,0,1)) { + $fdbkoptions{'policy'} = 1; + } } if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) { 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); - } - if (!$blocked && &discussion_open(undef,$realsymb) && - (&Apache::lonnet::allowed('pch', - $env{'request.course.id'}. - ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) || + my $realsymb = &get_realsymb($symb); + if (!$blocked && &discussion_open(undef,$realsymb) && + (&Apache::lonnet::allowed('pch', + $env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) || (($group ne '') && ($symb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$}) && (&check_group_priv($group,'pgd') eq 'ok')))) { - $discussoptions='
'. - ''.&mt('Change Screenname').''; - my $blockblog = &Apache::loncommon::blocking_status('blogs'); - if (!$blockblog) { - $discussoptions.= &add_blog_checkbox($crstype); + $discoptions{'nonanon'} = 1; + $discoptions{'anon'} = 1; + $blockblog = &Apache::loncommon::blocking_status('blogs'); + } + } + my $total = scalar(keys(%fdbkoptions)) + scalar(keys(%discoptions)); + return if (!$total); + if ($total == 1) { + $checkradio = ' checked="checked"'; + } + if (keys(%fdbkoptions)) { + if ($fdbkoptions{'author'}) { + $msgoptions = + '
'; + } + foreach my $item ('question','comment','policy') { + my $type = $item; + if ($item eq 'comment') { + $type = 'course'; + } + my $optionhash=$env{'course.'.$env{'request.course.id'}.'.'.$item.'.email.text'}; + if ($fdbkoptions{$type}) { + $msgoptions .= + '
'; } } } + if (keys(%discoptions)) { + if ($discoptions{'nonanon'}) { + $discussoptions=''; + } + if ($discoptions{'anon'}) { + $discussoptions .= '
'. + ''.&mt('Change Screenname').''; + } + if (!$blockblog) { + $discussoptions.= &add_blog_checkbox($crstype); + } + } if ($msgoptions) { $msgoptions='
'. @@ -2762,9 +3108,17 @@ sub feedback_available { } sub send_msg { - my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,%to)=@_; + my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,$clientip,%to)=@_; my $status=''; my $sendsomething=0; + my $delay; + my $senthide; + my %setters; + my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) = + &Apache::loncommon::blockcheck(\%setters,'com',$clientip); + if ($by_ip) { + $senthide = 1; + } my $restitle = &get_resource_title($symb,$feedurl); if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; } unless ($title=~/\w/) { $title=&mt('Feedback'); } @@ -2778,7 +3132,8 @@ sub send_msg { } else { unless (&Apache::lonmsg::user_normal_msg($user,$domain, $title.' ['.$restitle.']',$email,$citations,$feedurl, - $attachmenturl,undef,undef,$symb,$restitle)=~/ok/) { + $attachmenturl,undef,undef,$symb,$restitle,undef, + undef,undef,undef,$senthide)=~/ok/) { $status.='
'.&mt('Error sending message to').' '.$key.'
'; } else { $sendsomething++; @@ -2786,45 +3141,101 @@ sub send_msg { } } } + if ($sendsomething && $senthide) { + if ($by_ip) { + my $showdom = &Apache::lonnet::domain($blockdom); + if ($showdom eq '') { + $showdom = $blockdom; + } + $delay = 4; + $status.='
'.&mt("Message content of feedback you send to instructor(s) from your current IP address: [_1] will be unavailable in your 'Sent' folder.",$clientip). + '
'; + } + } -# Records of number of postings, etc, are kept under the "symb" called "_feedback" +# Records of number of feedback messages are kept under the "symb" called "_feedback" # There are two entries within the framework of a course: # - the URLs for which feedback was provided # - the total number of contributions - my %record=&Apache::lonnet::restore('_feedback'); - my ($temp)=keys(%record); - unless ($temp=~/^error\:/) { - my %newrecord=(); - $newrecord{'resource'}=$feedurl; - $newrecord{'subnumber'}=$record{'subnumber'}+1; - unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') { - $status.='
'.&mt('Not registered').'
'; - } + if ($sendsomething) { + my %record=&getfeedbackrecords(); + my ($temp)=keys(%record); + unless ($temp=~/^error\:/) { + my %newrecord=(); + $newrecord{'resource'}=$feedurl; + $newrecord{'subnumber'}=$record{'subnumber'}+1; + unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') { + $status.='
'.&mt('Not registered').'
'; + } + } } - - return ($status,$sendsomething); + return ($status,$sendsomething,$delay); } -# Routine to get the complete discussion records +# Routine to get the complete feedback records -sub getdiscrecords { +sub getfeedbackrecords { 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('_feedback',$course,$udom,$uname); - return %record; + return %record; +} + +# Routine to get feedback statistics + +sub getfeedbackstats { + my %record=&getfeedbackrecords(@_); + return ($record{'subnumber'},$record{'points'},$record{'totallikes'}); +} + +# Store feedback credit + +sub storefeedbackpoints { + my ($points,$uname,$udom,$course)=@_; + unless ($points) { $points=0; } + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my %record=('grader_user' => $env{'user.name'}, + 'grader_domain' => $env{'user.domain'}, + 'points' => $points); + return &Apache::lonnet::cstore(\%record,'_feedback',$course,$udom,$uname); +} + +# 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 { 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'}; @@ -2855,7 +3266,7 @@ sub adddiscuss { if (($symb) && ($email)) { my $now = time; if ($env{'form.editdisc'}) { - $contrib{'ip'}=$ENV{'REMOTE_ADDR'}; + $contrib{'ip'}=&Apache::lonnet::get_requestor_ip(); $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'}; $contrib{'timestamp'} = $now; $contrib{'history'} = ''; @@ -2914,7 +3325,7 @@ sub adddiscuss { $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); } - my %record=&Apache::lonnet::restore('_discussion'); + my %record=&getdiscussionrecords(); my ($temp)=keys(%record); unless ($temp=~/^error\:/) { my %newrecord=(); @@ -2922,6 +3333,7 @@ sub adddiscuss { $newrecord{'subnumber'}=$record{'subnumber'}+1; $status.='
'.&mt('Registering').': '. &Apache::lonnet::cstore(\%newrecord,'_discussion'); + &updatekarma(); } } else { $status.='Failed.'; @@ -2929,6 +3341,108 @@ sub adddiscuss { return $status.'
'; } + +# 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; +} + +# Routine to get discussion statistics + +sub getdiscussionstats { + my %record=&getdiscussionrecords(@_); + 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 + +sub storediscussionpoints { + my ($points,$uname,$udom,$course)=@_; + unless ($points) { $points=0; } + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my %record=('grader_user' => $env{'user.name'}, + 'grader_domain' => $env{'user.domain'}, + 'points' => $points); + return &Apache::lonnet::cstore(\%record,'_discussion',$course,$udom,$uname); +} + +# Store discussion "likes" + +sub storediscussionlikes { + 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'}; + my $totalunlikes=$record{'totalunlikes'}; + $totallikes += $chglikes; + $totalunlikes += $chgunlikes; + my %newrecord=('likes_user' => $env{'user.name'}, + 'likes_domain' => $env{'user.domain'}, + '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 { my ($idx,%contrib) = @_; my $changelast = 0; @@ -3074,11 +3588,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 = < @@ -3086,14 +3600,15 @@ sub modify_attachments { document.modattachments.action = document.modattachments.origpage.value; document.modattachments.submit(); } - + + 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); @@ -3120,45 +3635,46 @@ END $start_page $toolarge
-
-
'; @@ -821,7 +906,17 @@ sub action_links_bar { $discussion .= '&previous='.$prevread; } $discussion .= &group_args($group); - $discussion .= '">'.&mt('Export').' -
+ $lt{'note'}
-$lt{'title'}: 

+$lt{'title'}: 
ENDDISCUSS if ($env{'form.origpage'}) { @@ -919,22 +1014,38 @@ ENDDISCUSS } sub build_posting_display { - my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_; + my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$seehidden,$canvote,$prevread,$sortposts,$ressymb,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_; my @original=(); my @index=(); my $skip_group_check = 0; my $symb=&Apache::lonenc::check_decrypt($ressymb); my $escsymb=&escape($ressymb); +# These are the discussion contributions my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); - + my (%likes,%userlikes,%userunlikes,@theselikes,$oneplus,$twoplus,$oneminus,$twominus); + my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; + if ($seeid || $canvote) { +# And these are the likes/unlikes + %likes=&Apache::lonnet::dump('disclikes', + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}, + '^'.$symb.':'); +# Array with likes to figure out averages, etc. + @theselikes=(); +# Hashes containing likes and unlikes for this user. + %userlikes=(); + %userunlikes=(); + } +# Is the user allowed to see the real name behind anonymous postings? my $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) { $skip_group_check = 1; } +# Deletions and hiddens are just lists. Split them up into a hash for quicker lookup my (%deletions,%hiddens); if ($contrib{'deleted'}) { my $deleted = $contrib{'deleted'}; @@ -948,6 +1059,7 @@ sub build_posting_display { $hidden =~ s/\.$//; %hiddens = map { $_ => 1 } (split(/\.\./,$hidden)); } +# Versions if store/restore are used to actually store the messages. if ($contrib{'version'}) { my $oldest = $contrib{'1:timestamp'}; if ($prevread eq '0') { @@ -958,11 +1070,86 @@ sub build_posting_display { ($skiptest,$roleregexp,$secregexp,$statusregexp) = &filter_regexp($rolefilter,$sectionpick,$statusfilter); $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp; - } + } + my %votestyle; + if ($seeid || $canvote) { +# 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}) && (!$seehidden)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) { + push(@theselikes,$likes{$symb.':'.$idx.':likes'}); + if ($likes{$symb.':'.$idx.':likes'} ne '') { + if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') { + if (exists($likes{$symb.':'.$idx.':likers'}{$thisuser})) { + $userlikes{$idx} = 1; + } + } + if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') { + if (exists($likes{$symb.':'.$idx.':unlikers'}{$thisuser})) { + $userunlikes{$idx} = 1; + } + } + } + } + } +# 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 + $oneplus=$ave+$stddev; + $twoplus=$ave+2.*$stddev; + $oneminus=$ave-$stddev; + $twominus=$ave-2.*$stddev; + if ($#theselikes>1) { + foreach my $class ('twoplus','oneplus','zero','oneminus','twominus') { + my $fontstyle = $env{'course.'.$env{'request.course.id'}.'.discussion_post_fonts_'.$class}; + if ($fontstyle ne '') { + my ($size,$weight,$style,$other) = split(/,/,$fontstyle); + if ($size ne '') { + $votestyle{$class} .= 'font-size: '.$size.';'; + } + if ($weight ne '') { + $votestyle{$class} .= 'font-weight: '.$weight.';'; + } + if ($style ne '') { + $votestyle{$class} .= 'font-style: '.$style.';'; + } + if ($other ne '') { + $votestyle{$class} .= $other; + } + if ($votestyle{$class} ne '') { + $votestyle{$class} = 'style="'.$votestyle{$class}.'"'; + } + } + } + } + } +# +# This is now the real loop. Go through all entries, pick up what we need +# for (my $id=1;$id<=$contrib{'version'};$id++) { my $idx=$id; next if ($contrib{$idx.':deleted'}); next if ($contrib{$idx.':hidden'}); +# If we get here, we are actually going to display the message - we don't know where and we don't know if we display +# previous edits, but it counts as one entry my $posttime = $contrib{$idx.':timestamp'}; if ($prevread <= $posttime) { $$newpostsflag = 1; @@ -971,7 +1158,8 @@ sub build_posting_display { my $origindex='0.'; my $numoldver=0; if ($contrib{$idx.':replyto'}) { - if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) { + if ( ((!$env{'environment.unthreadeddiscussion'}) && ($sortposts eq '')) || + ($sortposts eq 'thread') || ($outputtarget eq 'export')) { # this is a follow-up message $original[$idx]=$original[$contrib{$idx.':replyto'}]; $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1; @@ -991,7 +1179,7 @@ sub build_posting_display { } else { $$replies[$$depth[$idx]]=1; } - unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx})) { + unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx})) { $$visible++; if ($contrib{$idx.':history'}) { if ($contrib{$idx.':history'} =~ /:/) { @@ -1006,7 +1194,7 @@ sub build_posting_display { my %subjects = (); my %attachtxt = (); my %allattachments = (); - my ($screenname,$plainname); + my ($screenname,$plainname,$showaboutme); my $sender = &mt('Anonymous'); # Anonymous users getting number within a discussion # Since idx is in static order, this should give the same sequence every time. @@ -1016,7 +1204,7 @@ sub build_posting_display { $$anonhash{$key}=&mt('Anonymous').' '.$anoncnt; } 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,$seehidden,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,\$showaboutme,$numoldver); # Set up for sorting by subject @@ -1046,12 +1234,18 @@ sub build_posting_display { } } if (!$contrib{$idx.':anonymous'} || $see_anonymous) { - $sender=&Apache::loncommon::aboutmewrapper( - $plainname, - $contrib{$idx.':sendername'}, - $contrib{$idx.':senderdomain'}).' ('. - $contrib{$idx.':sendername'}.':'. - $contrib{$idx.':senderdomain'}.')'; + if ($showaboutme) { + $sender = &Apache::loncommon::aboutmewrapper( + $plainname, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + } else { + $sender = $plainname; + } + if ($see_anonymous) { + $sender .= ' ('.$contrib{$idx.':sendername'}.':'. + $contrib{$idx.':senderdomain'}.')'; + } $sender = ''.$sender.''; if ($contrib{$idx.':anonymous'}) { $sender.=' ['.$$anonhash{$key}.'] '. @@ -1090,26 +1284,32 @@ sub build_posting_display { @{$$namesort{$lastname}{$firstname}} = ("$idx"); } if ($outputtarget ne 'tex') { +# 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.=' '. - &discussion_link($symb,&mt('Edit'),'editdisc',$idx,$$newpostsflag,$prevread,&group_args($group)); - unless ($seeid) { + &discussion_link($ressymb,&mt('Edit'),'editdisc',$idx,$$newpostsflag,$prevread,&group_args($group)); + unless ($seehidden) { my $grpargs = &group_args($group); $sender.=" '; } } } - if ($seeid) { + if ($seehidden) { if ($hiddens{$idx}) { unless ($studenthidden) { $sender.=' '. - &discussion_link($symb,&mt('Make Visible'),'unhide',$idx,$$newpostsflag,$prevread,&group_args($group)); + &discussion_link($ressymb,&mt('Make Visible'),'unhide',$idx,$$newpostsflag,$prevread,&group_args($group)); } } else { $sender.=' '. - &discussion_link($symb,&mt('Hide'),'hide',$idx,$$newpostsflag,$prevread,&group_args($group)); + &discussion_link($ressymb,&mt('Hide'),'hide',$idx,$$newpostsflag,$prevread,&group_args($group)); } my $grpargs = &group_args($group); $sender.= @@ -1148,13 +1348,13 @@ sub build_posting_display { if (($group ne '') && (&check_group_priv($group,'pgd') eq 'ok')) { $sender.=' '. - &discussion_link($symb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread,&group_args($group)); + &discussion_link($ressymb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread,&group_args($group)); } elsif (&Apache::lonnet::allowed('pch', $env{'request.course.id'}. ($env{'request.course.sec'}?'/'. $env{'request.course.sec'}:''))) { $sender.=' '. - &discussion_link($symb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread); + &discussion_link($ressymb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread); } } if ($viewgrades) { @@ -1172,7 +1372,8 @@ sub build_posting_display { } if ($outputtarget eq 'export' || $message) { my $thisindex=$idx; - if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) { + if ( ((!$env{'environment.unthreadeddiscussion'}) && ($sortposts eq '')) || + ($sortposts eq 'thread') || ($outputtarget eq 'export')) { $thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2); } $$alldiscussion{$thisindex}=$idx; @@ -1204,14 +1405,15 @@ sub build_posting_display { } else { if ($message) { my $spansize = 2; + my ($uname,$udom); if ($showonlyunread && $prevread > $posttime) { $$notshown{$idx} = 1; } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) { $$notshown{$idx} = 1; } else { # apply filters - my $uname = $contrib{$idx.':sendername'}; - my $udom = $contrib{$idx.':senderdomain'}; + $uname = $contrib{$idx.':sendername'}; + $udom = $contrib{$idx.':senderdomain'}; my $poster = $uname.':'.$udom; if ($env{'form.totposters'} ne '') { if ($totposters == 0) { @@ -1272,14 +1474,77 @@ sub build_posting_display { if ($$dischash{$toggkey}) { $$discussionitems[$idx].='  '.$ctlink; } + my $thislikes=$likes{$symb.':'.$idx.':likes'}; + my $likestyle; + if ($seeid || $canvote) { +# Figure out size based on likes + my $class = 'zero'; + my $thislikes=$likes{$symb.':'.$idx.':likes'}; + if ($thislikes>$twoplus) { + $class = 'twoplus'; + } elsif ($thislikes>$oneplus) { + $class = 'oneplus'; + } + if ($thislikes<$twominus) { + $class = 'twominus'; + } elsif ($thislikes<$oneminus) { + $class = 'oneminus'; + } + $likestyle = $votestyle{$class}; + } +# Actually glue in the message itself $$discussionitems[$idx].= '
'. - $message.'
'; + "
". + $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.'); + } + &html_escape(\$novote); + $$discussionitems[$idx].= + '
'. + ''.$novote.' '. + ''.$novote.''; + + } else { + if ($userlikes{$idx}) { + $$discussionitems[$idx].=''.&mt('You like this posting').''; + } else { + $$discussionitems[$idx].=' '.&discussion_link($ressymb,''.&mt('Like').'','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting")); + } + if ($userunlikes{$idx}) { + $$discussionitems[$idx].=''.&mt('You unlike this posting').''; + } else { + $$discussionitems[$idx].=' '.&discussion_link($ressymb,''.&mt('Unlike').'','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)); + &discussion_link($ressymb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group)); } $$discussionitems[$idx].='
'.&mt('Earlier version(s) were posted on: '); if ($contrib{$idx.':history'} =~ m/:/) { @@ -1292,12 +1557,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 { @@ -1356,13 +1628,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; } @@ -1374,13 +1646,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') { @@ -1496,11 +1775,13 @@ sub mail_screen { } my %lt = &Apache::lonlocal::texthash( - 'myqu' => 'My question/comment/feedback:', - 'title' => 'Title', + 'myqu' => 'Question/comment/feedback:', 'reta' => 'Retained attachments', 'atta' => 'Attachment', ); + if ($env{'form.editdisc'} || $env{'form.replydisc'}){ + $lt{'myqu'} = &mt('Post Discussion'); + } my $restitle = &get_resource_title($caller_symb,$feedurl); my $quote=''; my $subject = ''; @@ -1565,6 +1846,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'}); @@ -1573,36 +1855,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'}; } @@ -1638,6 +1909,7 @@ END my $latexHelp=&Apache::loncommon::helpLatexCheatsheet(undef,undef,1,($env{'form.modal'}?'popup':0)); my $send=&mt('Send'); my $alert = &mt('Please select a feedback type.'); + &js_escape(\$alert); my $js= < // + END my ($textareaheader,$textareaclass); @@ -1694,7 +1967,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); @@ -1703,7 +1976,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'}) { @@ -1711,6 +1988,7 @@ END } $r->print(<$lt{'myqu'} $header
@@ -1730,19 +2008,32 @@ END } $r->print(< +END +$r->print(&Apache::lonhtmlcommon::start_pick_box()); +$r->print(<$lt{'myqu'} +

$textareaheader

$latexHelp

-$lt{'title'}:

-

-

END + + + $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) { @@ -1764,7 +2055,8 @@ END } else { $r->print(< -$lt{'atta'} $attachmaxtext: +$lt{'atta'} $attachmaxtext: +

END } @@ -1775,10 +2067,8 @@ END $r->print(''); } $r->print(< -

END if ($env{'form.editdisc'} || $env{'form.replydisc'}) { @@ -1793,7 +2083,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').'
'; @@ -1813,9 +2102,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()); @@ -1855,6 +2145,11 @@ sub print_display_options { 'yhni' => 'You have not indicated that you wish to change any of the discussion settings', 'ywbr' => 'You will be returned to the previous page if you click OK.' ); + my %js_lt = &Apache::lonlocal::texthash( + 'yhni' => 'You have not indicated that you wish to change any of the discussion settings', + 'ywbr' => 'You will be returned to the previous page if you click OK.' + ); + &js_escape(\%js_lt); my $dispchangeA = $lt{'unread'}; my $dispchangeB = $lt{'unmark'}; @@ -1948,7 +2243,7 @@ function setDisp() { if (chktotal > 0) { document.modifydisp.submit() } else { - if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) { + if(confirm("$js_lt{'yhni'}. \\n$js_lt{'ywbr'}")) { if (prev > 0) { location.href = "$feedurl?previous=$previous" } else { @@ -2256,24 +2551,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 = (); @@ -2289,7 +2571,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'}; @@ -2314,14 +2596,14 @@ sub print_showposters { } } } - } + } } my $start_page = &Apache::loncommon::start_page('Discussion options'); my $table_start =&Apache::loncommon::start_data_table(); $r->print(< +

$table_start
' .'
'.&mt('Send Feedback').'
'.&Apache::lonhtmlcommon::coursepreflink(&mt('Feedback Settings'),'feedback').'
- - - - - - - - -
- 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
@@ -3216,12 +3732,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'}:  'resources/bulletin boards.', 'twnp' => 'There are currently no resources or discussion boards with unread discussion postings.' ); foreach my $res (@resources) { @@ -3605,7 +4111,10 @@ sub handler { my $lastkey = $ressymb.'_lastread'; $discinfo{$lastkey} = $env{'form.navtime'}; } - my $textline = "$lt{'mnpa'} $numitems $lt{'robb'}"; + my $textline = ''. + &mt('Marked "New" posts as read in a total of [_1] resources/discussion boards.', + $numitems). + ''; if ($numitems > 0) { &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss', \%discinfo,$env{'user.domain'},$env{'user.name'}); @@ -3681,37 +4190,32 @@ ENDREDIR my $entry=$env{'form.hide'}?$env{'form.hide'}:$env{'form.unhide'}; my ($symb,$idx)=split(/\:\:\:/,$entry); ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); + my $ressymb = &wrap_symb($symb); - my $crs='/'.$env{'request.course.id'}; - if ($env{'request.course.sec'}) { - $crs.='_'.$env{'request.course.sec'}; - } - $crs=~s/\_/\//g; - my $seeid=&Apache::lonnet::allowed('rin',$crs); - - if ($env{'form.hide'} && !$seeid && !(&editing_allowed($env{'form.hide'},$env{'form.group'}))) { - &redirect_back($r,$feedurl,&mt('Deletion not permitted').'
', '0','0','','',$env{'form.previous'},'','','','', - undef,undef,$group,); + my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum); + unless (($seehidden) || (&editing_allowed($env{'form.hide'},$group))) { + &redirect_back($r,$feedurl,&mt('Hiding not permitted').'
', + '0','0','','',$env{'form.previous'},'','','','', + undef,undef,$group); return OK; } my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); my $currenthidden=$contrib{'hidden'}; my $currentstudenthidden=$contrib{'studenthidden'}; if ($env{'form.hide'}) { $currenthidden.='.'.$idx.'.'; - unless ($seeid) { + unless ($seehidden) { $currentstudenthidden.='.'.$idx.'.'; } } else { $currenthidden=~s/\.$idx\.//g; } my %newhash=('hidden' => $currenthidden); - if ( ($env{'form.hide'}) && (!$seeid) ) { + if ( ($env{'form.hide'}) && (!$seehidden) ) { $newhash{'studenthidden'} = $currentstudenthidden; } if ($env{'form.hide'}) { @@ -3720,26 +4224,209 @@ ENDREDIR ($changelast,$newlast) = &get_discussion_info($idx,%contrib); if ($changelast) { &Apache::lonnet::put('discussiontimes',{$symb => $newlast}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); } } - &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); - - &redirect_back($r,$feedurl,&mt('Changed discussion status').'
', - '0','0','','',$env{'form.previous'},undef,undef,undef, + my $result; + if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, + $cdom,$cnum) eq 'ok') { + my $prefix=$symb.':'.$idx.':'; + my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum, + '^'.$prefix); + my ($totallikes,$totalunlikes); + if (ref($likes{$prefix.'likers'}) eq 'HASH') { + $totallikes = scalar(keys(%{$likes{$prefix.'likers'}})); + } + if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { + $totalunlikes = scalar(keys(%{$likes{$prefix.'unlikers'}})); + } + if ($totallikes || $totalunlikes) { + my ($chglikes,$chgunlikes,$context); + if ($env{'form.hide'}) { + $chglikes = -1 * $totallikes; + $chgunlikes = -1 * $totalunlikes; + $context = 'hide'; + } else { + $chglikes = $totallikes; + $chgunlikes = $totalunlikes; + $context = 'unhide'; + } + &storediscussionlikes($chglikes,$chgunlikes, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}, + $env{'request.course.id'}, + $context); + + } + $result = &mt('Changed discussion status'); + } else { + $result = &mt('Discussion status unchanged'); + } + &redirect_back($r,$feedurl,$result.'
','0','0','','', + $env{'form.previous'},undef,undef,undef, + undef,undef,undef,$group); + 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); + my $result; + if ($idx > 0) { + my $realsymb = &get_realsymb($symb); + my $status='OPEN'; + if ($Apache::lonhomework::parsing_a_problem || + $Apache::lonhomework::parsing_a_task) { + $status=$Apache::inputtags::status[-1]; + } + if (&discussion_vote_available($status,$realsymb)) { + my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, + $cdom,$cnum); + my $ownpost; + if (($contrib{$idx.':sendername'} eq $env{'user.name'}) && + ($contrib{$idx.':senderdomain'} eq $env{'user.domain'})) { + $ownpost = 1; + } + if ($ownpost || $contrib{$idx.':hidden'} || $contrib{$idx.':deleted'}) { + $result = &mt('Vote not registered.').' '; + } + if ($ownpost) { + $result .= &mt('No voting for your own posts.'); + } elsif ($contrib{$idx.':hidden'}) { + $result .= &mt('No voting for hidden posts.'); + } elsif ($contrib{$idx.':deleted'}) { + $result .= &mt('No voting for deleted posts.'); + } else { +# +# 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 %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum, + '^'.$prefix); + +# Get current like or unlike status for the $idx for this user. + my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; + my ($userlikes,$userunlikes); + if (ref($likes{$prefix.'likers'}) eq 'HASH') { + if (exists($likes{$prefix.'likers'}{$thisuser})) { + $userlikes = 1; + } + } + if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { + if (exists($likes{$prefix.'unlikers'}{$thisuser})) { + $userunlikes = 1; + } + } +# Get the current "likes" count + my $likescount=$likes{$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 $votetype; + if ($env{'form.like'}) { + if ($userlikes) { + $alreadyflag=1; + } elsif ($userunlikes) { + delete($likes{$prefix.'unlikers'}{$thisuser}); + $votetype = 'switch'; + $likescount++; + } else { + if (ref($likes{$prefix.'likers'}) eq 'HASH') { + $likes{$prefix.'likers'}{$thisuser} = 1; + } else { + $likes{$prefix.'likers'} = {$thisuser => 1}; + } + $likescount++; + } + } else { + if ($userunlikes) { + $alreadyflag=1; + } elsif ($userlikes) { + delete($likes{$prefix.'likers'}{$thisuser}); + $votetype = 'switch'; + $likescount--; + } else { + if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { + $likes{$prefix.'unlikers'}{$thisuser} = 1; + } else { + $likes{$prefix.'unlikers'} = {$thisuser => 1}; + } + $likescount--; + } + } +# $alreadyflag would be 1 if they tried to double-like or double-unlike + if ($alreadyflag) { + if ($env{'form.like'}) { + $result= &mt("'Like' already registered"); + } else { + $result= &mt("'Unlike' already registered"); + } + } else { + my %newhash=($prefix.'likes' => $likescount, + $prefix.'likers' => $likes{$prefix.'likers'}, + $prefix.'unlikers' => $likes{$prefix.'unlikers'}); +# Store data in db-file "disclikes" + if (&Apache::lonnet::put('disclikes',\%newhash,$cdom,$cnum) eq 'ok') { +# Also store with the person who posted the liked/unliked entry + my ($chglike,$chgunlike); + if ($env{'form.like'}) { + if ($votetype eq 'switch') { + $chglike = 0; + $chgunlike = -1; + } else { + $chglike = 1; + $chgunlike = 0; + } + &storediscussionlikes($chglike,$chgunlike, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}, + $env{'request.course.id'},'like'); + $result=&mt("Registered 'Like'"); + } else { + if ($votetype eq 'switch') { + $chglike = -1; + $chgunlike = 0; + } else { + $chglike = 0; + $chgunlike = 1; + } + &storediscussionlikes($chglike,$chgunlike, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}, + $env{'request.course.id'},'unlike'); + $result=&mt("Registered 'Unlike'"); + } + } else { +# Oops, something went wrong + $result=&mt("Failed to register vote"); + } + } + } + } else { + $result=&mt('Voting unavailable for this discussion'); + } + } else { + $result=&mt('Invalid post number'); + } + &redirect_back($r,$feedurl,$result.'
', + '0','0','','',$env{'form.previous'},undef,undef,undef, undef,undef,undef,$group); return OK; } elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) { my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'}); - if ($env{'form.cmd'} eq 'threadedon') { + if ($env{'form.cmd'} eq 'threadedoff') { + &Apache::lonnet::put('environment',{'unthreadeddiscussion' => 'on'}); + &Apache::lonnet::appenv({'environment.unthreadeddiscussion' => 'on'}); + &Apache::lonnet::del('environment',['threadeddiscussion']); + &Apache::lonnet::delenv('environment.threadeddiscussion'); + } else { &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'}); &Apache::lonnet::appenv({'environment.threadeddiscussion' => 'on'}); - } else { - &Apache::lonnet::del('environment',['threadeddiscussion']); - &Apache::lonnet::delenv('environment.threadeddiscussion'); + &Apache::lonnet::del('environment',['unthreadeddiscussion']); + &Apache::lonnet::delenv('environment.unthreadeddiscussion'); } &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'
', '0','0','','',$env{'form.previous'},undef,undef,undef, @@ -3749,20 +4436,51 @@ ENDREDIR # --------------------------------------------------------------- Hide for good my ($symb,$idx)=split(/\:\:\:/,$env{'form.deldisc'}); ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); + my $ressymb=&wrap_symb($symb); + + unless (&can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum)) { + &redirect_back($r,$feedurl,&mt('Deletion not permitted').'
', + '0','0','','',$env{'form.previous'},'','','','', + undef,undef,$group); + return OK; + } my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); my ($changelast,$newlast) = &get_discussion_info($idx,%contrib); if ($changelast) { &Apache::lonnet::put('discussiontimes',{$symb => $newlast}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); } my %newhash=('deleted' => $contrib{'deleted'}.".$idx."); - &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); - &redirect_back($r,$feedurl,&mt('Changed discussion status').'
', - '0','0','','',$env{'form.previous'},undef,undef,undef, + + my $result; + if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, + $cdom,$cnum) eq 'ok') { + $result = &mt('Changed discussion status'); + my $prefix=$symb.':'.$idx.':'; + my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum, + '^'.$prefix); + my ($totallikes,$totalunlikes); + if (ref($likes{$prefix.'likers'}) eq 'HASH') { + $totallikes = scalar(keys(%{$likes{$prefix.'likers'}})); + } + if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { + $totalunlikes = scalar(keys(%{$likes{$prefix.'unlikers'}})); + } + if ($totallikes || $totalunlikes) { + my $chglikes = -1 * $totallikes; + my $chgunlikes = -1 * $totalunlikes; + &storediscussionlikes($chglikes,$chgunlikes, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}, + $env{'request.course.id'}, + 'delete'); + } + } else { + $result = &mt('Discussion status unchanged'); + } + &redirect_back($r,$feedurl,$result.'
','0','0','','', + $env{'form.previous'},undef,undef,undef, undef,undef,undef,$group); return OK; } elsif ($env{'form.preview'}) { @@ -3790,8 +4508,7 @@ ENDREDIR my $idx = $env{'form.idx'}; if ($idx) { my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); $attachmenturls = $contrib{$idx.':attachmenturl'}; } &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx, @@ -3808,6 +4525,7 @@ ENDREDIR $mode='problem'; $status=$Apache::inputtags::status[-1]; } + my $discussion = &list_discussion($mode,$status,$symb); my $start_page = &Apache::loncommon::start_page('Resource Feedback and Discussion'); @@ -3815,6 +4533,62 @@ 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'}); + my $ressymb=&wrap_symb($symb); + $r->print(&Apache::loncommon::start_page('Undelete all deleted discussion entries')); + if (&can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum)) { + my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, + $cdom,$cnum); + $contrib{'deleted'} =~ s/^\.//; + $contrib{'deleted'} =~ s/\.$//; + my $confirm_msg; + if ($contrib{'deleted'} ne '') { + if (&Apache::lonnet::store({'deleted' => ''},$symb,$env{'request.course.id'}, + $cdom,$cnum) eq 'ok') { + my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,'^'.$symb.':'); + my @ids = split(/\.\./,$contrib{'deleted'}); + my (%chglikes,%chgunlikes); + foreach my $idx (@ids) { + my $uname = $contrib{$idx.':sendername'}; + my $udom = $contrib{$idx.':senderdomain'}; + my ($totallikes,$totalunlikes); + if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') { + $totallikes = scalar(keys(%{$likes{$symb.':'.$idx.':likers'}})); + } + if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') { + $totalunlikes = scalar(keys(%{$likes{$symb.':'.$idx.':unlikers'}})); + } + if ($totallikes || $totalunlikes) { + $chglikes{$uname.':'.$udom} += $totallikes; + $chgunlikes{$uname.':'.$udom} += $totalunlikes; + } + } + foreach my $user (keys(%chglikes)) { + my ($uname,$udom) = split(/:/,$user); + &storediscussionlikes($chglikes{$user},$chgunlikes{$user}, + $uname,$udom,$env{'request.course.id'}, + 'undelete'); + } + $confirm_msg = &Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries")); + } else { + $confirm_msg = &Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1); + } + } else { + $confirm_msg = &Apache::lonhtmlcommon::confirm_success(&mt("No entries to undelete"),1); + } + $r->print( + '
' + .&Apache::loncommon::confirmwrapper($confirm_msg) + .&Apache::lonhtmlcommon::actionbox( + ["".&mt("Return and reload").""]) + ); + } + $r->print(&Apache::loncommon::end_page()); + return OK; } else { # ------------------------------------------------------------- Normal feedback my $feedurl=$env{'form.postdata'}; @@ -3830,6 +4604,8 @@ ENDREDIR $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0]; } elsif ($env{'form.origpage'}) { $symb=""; + } elsif ($env{'form.sendmessageonly'}) { + $symb=(split(/\:\:\:/,$env{'form.sendmessageonly'}))[0]; } else { $symb=&Apache::lonnet::symbread($feedurl); } @@ -3852,6 +4628,12 @@ ENDREDIR $r->internal_redirect('/adm/ambiguous'); return OK; } + if ($feedurl eq '') { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + &no_redirect_back($r); + return OK; + } # Go ahead with feedback, no ambiguous reference unless ( ( @@ -3866,7 +4648,7 @@ ENDREDIR $r->send_http_header; # Unable to give feedback &Apache::lonenc::check_encrypt(\$feedurl); - &no_redirect_back($r,$feedurl); + &no_redirect_back($r,$feedurl,2); return OK; } # --------------------------------------------------- Print login screen header @@ -3886,7 +4668,7 @@ ENDREDIR if ($options) { &mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'}); } else { - &fail_redirect($r,$feedurl); + &fail_redirect($r,$feedurl,2); } return OK; } @@ -3905,7 +4687,7 @@ ENDREDIR my $usersymb = &Apache::lonenc::check_encrypt($symb); my $useranswer= &Apache::loncommon::get_student_answers( - $usersymb,$env{'user.name'},$env{'user.domain'}, + $symb,$env{'user.name'},$env{'user.domain'}, $env{'request.course.id'}); &Apache::lonnet::delenv('allowed.vgr'); # Get attachments, if any, and not too large @@ -3952,9 +4734,10 @@ ENDREDIR my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl); # Actually send mail - my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}), - $feedurl,$email,$citations, - $attachmenturl,$usersymb,%to); + my $clientip = &Apache::lonnet::get_requestor_ip($r); + my ($status,$numsent,$delay)=&send_msg(&clear_out_html($env{'form.subject'}), + $feedurl,$email,$citations, + $attachmenturl,$usersymb,$clientip,%to); # Discussion? Store that. my $numpost=0; @@ -3985,7 +4768,8 @@ ENDREDIR } # Receipt screen and redirect back to where came from - &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group,$toolarge); + &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'}, + undef,undef,undef,undef,undef,undef,$group,$toolarge,$delay); } return OK; } @@ -4008,6 +4792,7 @@ sub wrap_symb { } return $ressymb; } + sub dewrapper { my ($feedurl)=@_; if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { @@ -4161,8 +4946,16 @@ None =item discussion_visible() +=item discussion_vote_available() + +=item get_realsymb() + =item list_discussion() +=item can_see_hidden() + +=item discussion_link() + =item send_feedback_link() =item send_message_link()