--- loncom/interface/lonfeedback.pm 2013/01/03 20:51:23 1.363 +++ loncom/interface/lonfeedback.pm 2022/01/19 00:44:31 1.390 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.363 2013/01/03 20:51:23 raeburn Exp $ +# $Id: lonfeedback.pm,v 1.390 2022/01/19 00:44:31 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)=@_; @@ -118,10 +118,16 @@ sub list_discussion { $outputtarget = 'export'; } } + my ($nofooter,$nodisclink,$nofdbklink); if (not &discussion_visible($status)) { if ($mode ne 'board') { - &Apache::lonenc::check_encrypt(\$ressymb); - return '
"; + ($nofooter,$nodisclink,$nofdbklink) = &check_menucoll(); + if ($nofooter || $nofdbklink) { + return '
'; + } else { + &Apache::lonenc::check_encrypt(\$ressymb); + return '
"; + } } } if ($group ne '' && $mode eq 'board') { @@ -130,17 +136,27 @@ sub list_discussion { } } - my ($blocked,$blocktext) = - &Apache::loncommon::blocking_status('boards'); - if ($blocked) { - $blocktext = '
'; - }else{ - $blocktext.=""; + unless ($outputtarget eq 'export') { + ($nofooter,$nodisclink,$nofdbklink) = &check_menucoll(); + } + + unless ($nofooter) { + my ($blocked,$blocktext) = + &Apache::loncommon::blocking_status('boards'); + if ($blocked) { + my $footer = '
'; + return $footer; } - return $blocktext; } my @bgcols = ("LC_disc_old_item","LC_disc_new_item"); @@ -336,12 +352,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'}; @@ -447,12 +466,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 } } @@ -468,18 +487,18 @@ imscp_v1p1.xsd http://www.imsglobal.org/ my $numhidden = keys(%notshown); if ($numhidden > 0) { my $colspan = $maxdepth+1; - $discussion.="\n".''. - ''; + 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 .= '
'; } @@ -562,7 +581,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'}.'

'. @@ -671,7 +690,7 @@ END $newpostsflag,$group, $prevread,$markondisp,$seehidden); $discussion .= "\n"; - } + } if ($outputtarget eq 'export') { if ($manifestok) { while ($currdepth > 0) { @@ -693,22 +712,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; } @@ -759,33 +790,60 @@ END &mt('This discussion is closed.').''; } } elsif ($outputtarget ne 'tex') { - $discussion.=''; } return $discussion; } +sub check_menucoll { + my ($nofooter,$nodisclink,$nofdbklink); + my ($menucoll,$deeplinkmenu,$menuref) = &Apache::loncommon::menucoll_in_effect(); + if ($menucoll) { + if (ref($menuref) eq 'HASH') { + if ($menuref->{'foot'} eq 'n') { + $nofooter = 1; + } else { + unless ($menuref->{'disc'}) { + $nodisclink = 1; + } + unless ($menuref->{'fdbk'}) { + $nofdbklink = 1; + } + } + } + } + return ($nofooter,$nodisclink,$nofdbklink); +} + sub can_see_hidden { my ($mode,$ressymb,$feedurl,$group,$cdom,$cnum,$crs) = @_; my $seehidden; @@ -840,7 +898,7 @@ sub send_feedback_link { &discussion_link($ressymb, ''.&mt('Post Discussion').'', + '" />'.&mt('Post Discussion').'', 'replydisc'). ''; } @@ -851,7 +909,7 @@ sub send_message_link { &discussion_link($ressymb, ''.&mt('Send Feedback').'', + '" />'.&mt('Send Feedback').'', 'sendmessageonly'). ''; return $output; @@ -926,7 +984,7 @@ sub postingform_display { $currnewattach,$currdelold,$group,$crstype) = @_; my $newattachmsg; my %lt = &Apache::lonlocal::texthash( - 'note' => 'Note: in anonymous discussion, your name is visible only to course faculty', + 'note' => 'Note: in anonymous discussion, your name is visible only to course faculty', 'title' => 'Title', 'podi' => 'Post Discussion', 'poan' => 'Post Anonymous Discussion', @@ -945,9 +1003,14 @@ sub postingform_display { } } } + my $postanon; + if (&Apache::lonnet::allowed('pac',$env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + $postanon = ''; + } $postingform .= (< - +$postanon @@ -1278,7 +1341,7 @@ sub build_posting_display { 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)); + &discussion_link($ressymb,&mt('Edit'),'editdisc',$idx,$$newpostsflag,$prevread,&group_args($group)); unless ($seehidden) { my $grpargs = &group_args($group); $sender.=" '.&mt('Change Screenname').''; - my $blockblog = &Apache::loncommon::blocking_status('blogs'); - if (!$blockblog) { - $discussoptions.= &add_blog_checkbox($crstype); - } + $discoptions{'nonanon'} = 1; + if (&Apache::lonnet::allowed('pac',$env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + $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) { @@ -3018,9 +3170,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'); } @@ -3034,7 +3194,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++; @@ -3042,6 +3203,24 @@ 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 feedback messages are kept under the "symb" called "_feedback" # There are two entries within the framework of a course: @@ -3059,7 +3238,7 @@ sub send_msg { } } } - return ($status,$sendsomething); + return ($status,$sendsomething,$delay); } # Routine to get the complete feedback records @@ -3149,7 +3328,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'} = ''; @@ -3484,6 +3663,7 @@ sub modify_attachments { document.modattachments.submit(); } + END # Breadcrumbs @@ -3525,7 +3705,10 @@ END $r->print(''.$subject.''); $r->print(&Apache::lonhtmlcommon::row_closure()); $r->print(&Apache::lonhtmlcommon::row_title($lt{'adda'})); - $r->print(' '.$attachmaxtext); + $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'))); @@ -3866,8 +4049,9 @@ sub handler { my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0]; my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); my $feedurl=&Apache::lonnet::clutter($url); - &redirect_back($r,$feedurl,&mt('Editing not permitted').'
', '0','0','','',$env{'form.previous'},undef,undef,undef, - undef,undef,undef,$group); + &redirect_back($r,$feedurl,&mt('Editing not permitted').'
', + '0','0','','',$env{'form.previous'},undef,undef,undef, + undef,undef,undef,$group); return OK; } } @@ -3990,7 +4174,7 @@ sub handler { $discinfo{$lastkey} = $env{'form.navtime'}; } my $textline = ''. - &mt('Marked "New" posts as read in a total of [_1] resources/bulletin boards.', + &mt('Marked "New" posts as read in a total of [_1] resources/discussion boards.', $numitems). ''; if ($numitems > 0) { @@ -4010,11 +4194,15 @@ sub handler { 'only_body' => 1, 'add_entries' => \%onload}); my $end_page = &Apache::loncommon::end_page(); + my $windowname = 'loncapaclient'; + if ($env{'request.lti.login'}) { + $windowname .= 'lti'; + } $r->print (< $textline -
+

$end_page @@ -4074,7 +4262,7 @@ ENDREDIR unless (($seehidden) || (&editing_allowed($env{'form.hide'},$group))) { &redirect_back($r,$feedurl,&mt('Hiding not permitted').'
', '0','0','','',$env{'form.previous'},'','','','', - undef,undef,$group,); + undef,undef,$group); return OK; } @@ -4423,6 +4611,7 @@ ENDREDIR $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') { @@ -4450,14 +4639,19 @@ ENDREDIR $uname,$udom,$env{'request.course.id'}, 'undelete'); } - $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries"))); + $confirm_msg = &Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries")); } else { - $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1)); + $confirm_msg = &Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1); } } else { - $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("No entries to undelete"),1)); + $confirm_msg = &Apache::lonhtmlcommon::confirm_success(&mt("No entries to undelete"),1); } - $r->print("
".&mt("Return and reload").""); + $r->print( + '
' + .&Apache::loncommon::confirmwrapper($confirm_msg) + .&Apache::lonhtmlcommon::actionbox( + ["".&mt("Return and reload").""]) + ); } $r->print(&Apache::loncommon::end_page()); return OK; @@ -4500,6 +4694,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 ( ( @@ -4509,12 +4709,14 @@ ENDREDIR ($env{'request.course.id'} && ($feedurl!~m:^/adm:)) || ($env{'request.course.id'} && ($symb=~/^bulletin\_\_\_/)) + || + (($env{'request.course.id'}) && ($feedurl =~ /ext\.tool$/)) ) { &Apache::loncommon::content_type($r,'text/html'); $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 @@ -4534,7 +4736,7 @@ ENDREDIR if ($options) { &mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'}); } else { - &fail_redirect($r,$feedurl); + &fail_redirect($r,$feedurl,2); } return OK; } @@ -4600,9 +4802,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; @@ -4610,7 +4813,11 @@ ENDREDIR && $env{'form.discuss'} !~ /^(?:author|question|course|policy)/) || $env{'form.anondiscuss'} ne '') { my $subject = &clear_out_html($env{'form.subject'}); - my $anonmode=($env{'form.discuss'} eq 'anon' || $env{'form.anondiscuss'} ); + my $anonmode; + if (&Apache::lonnet::allowed('pac',$env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + $anonmode=($env{'form.discuss'} eq 'anon' || $env{'form.anondiscuss'} ); + } $typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl, $subject,$group); $numpost++; @@ -4633,7 +4840,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; }