--- loncom/interface/lonfeedback.pm 2006/11/29 03:55:15 1.221 +++ loncom/interface/lonfeedback.pm 2006/12/24 22:13:19 1.237 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.221 2006/11/29 03:55:15 raeburn Exp $ +# $Id: lonfeedback.pm,v 1.237 2006/12/24 22:13:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,7 +44,6 @@ use HTML::LCParser(); use Apache::lonspeller(); use Apache::longroup; use Cwd; -use lib '/home/httpd/lib/perl/'; use LONCAPA; sub discussion_open { @@ -75,6 +74,9 @@ sub discussion_visible { sub list_discussion { my ($mode,$status,$ressymb,$imsextras,$group)=@_; + unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); } + unless ($ressymb) { return ''; } + $ressymb=&wrap_symb($ressymb); my $outputtarget=$env{'form.grade_target'}; if (defined($env{'form.export'})) { if($env{'form.export'}) { @@ -86,13 +88,28 @@ sub list_discussion { $outputtarget = 'export'; } } - if (not &discussion_visible($status)) { return ''; } + if (not &discussion_visible($status)) { + if ($mode ne 'board') { + &Apache::lonenc::check_encrypt(\$ressymb); + return &send_message_link($ressymb); + } + } if ($group ne '' && $mode eq 'board') { if (&check_group_priv($group,'vgb') ne 'ok') { return ''; } } + my ($blocked,$blocktext) = + &Apache::loncommon::blocking_status('boards'); + if ($blocked) { + &Apache::lonenc::check_encrypt(\$ressymb); + if ($mode ne 'board') { + $blocktext.='
'.&send_message_link($ressymb); + } + return $blocktext; + } + my @bgcols = ("#cccccc","#eeeeee"); my $discussiononly=0; if ($mode eq 'board') { $discussiononly=1; } @@ -103,9 +120,6 @@ sub list_discussion { $crs.='_'.$env{'request.course.sec'}; } $crs=~s/\_/\//g; - unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); } - unless ($ressymb) { return ''; } - $ressymb=&wrap_symb($ressymb); my $encsymb=&Apache::lonenc::check_encrypt($ressymb); my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs) && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form|task)$/)); @@ -421,55 +435,10 @@ imscp_v1p1.xsd http://www.imsglobal.org/ |; $discussion.='
'; - $discussion .=''; - + $discussion .= &action_links_bar($colspan,$ressymb,$visible, + $newpostsflag,$group, + $prevread,$markondisp); + my $escsymb=&escape($ressymb); my $numhidden = keys(%notshown); if ($numhidden > 0) { my $colspan = $maxdepth+1; @@ -680,9 +649,13 @@ END
'. - ''; - my $escsymb=&escape($ressymb); - if ($visible>2) { - $discussion.=''; - if ($newpostsflag) { - if (!$markondisp) { - $discussion .=''; - } - } else { - $discussion .= ''; - } - $discussion .= '
'. - ''.&mt('Threaded View').'  '. - ''.&mt('Chronological View').'   - '.&mt('Sorting/Filtering options').'  '; - } else { - $discussion .= ''; - } - $discussion .=''.&mt('Export').'?  '. - &mt('Preferences on what is marked as NEW'). - '
'.&mt('Mark NEW posts no longer new').''; - } else { - $discussion .= '
  
- -

END + $discussion .= &action_links_bar($colspan,$ressymb,$visible, + $newpostsflag,$group, + $prevread,$markondisp); + $discussion .= " + +

\n"; } if ($outputtarget eq 'export') { if ($manifestok) { @@ -759,26 +732,98 @@ END } } } else { - $discussion.='
'; + $discussion.=''; + if ($outputtarget ne 'tex') { + $discussion.= &send_message_link($ressymb); + } + $discussion.='
'; } return $discussion; } +sub send_feedback_link { + my ($ressymb,$target) = @_; + my $output = ''. + ' '. + ''.&mt('Post Discussion').''; + return $output; +} + +sub send_message_link { + my ($ressymb) = @_; + my $output = ''. + ' '.&mt('Send Message').''; + return $output; +} + +sub action_links_bar { + my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_; + my $discussion = ''. + ''; + my $escsymb=&escape($ressymb); + if ($visible>2) { + $discussion .= ''; + if ($newpostsflag) { + if (!$markondisp) { + $discussion .=''; + } + } else { + $discussion .= ''; + } + $discussion .= '
'. + ''.&mt('Threaded View').'  '. + ''.&mt('Chronological View').'   + '.&mt('Sorting/Filtering options').'  '; + } else { + $discussion .= ''; + } + $discussion .=''.&mt('Export').'?  '. + &mt('Preferences on what is marked as NEW'). + '
'.&mt('Mark NEW posts no longer new').''; + } else { + $discussion .= '
  
'; + return $discussion; +} + sub postingform_display { my ($mode,$ressymb,$now,$subject,$comment,$outputtarget,$attachnum, $currnewattach,$currdelold,$group) = @_; @@ -815,11 +860,16 @@ ENDDISCUSS if ($group ne '') { $postingform .=''; } + my $blockblog = &Apache::loncommon::blocking_status('blogs'); + if (!$blockblog) { + $postingform .= &add_blog_checkbox(); + } $postingform .= "\n"; if ($outputtarget ne 'tex') { $postingform .= &generate_attachments_button('',$attachnum,$ressymb, $now,$currnewattach, - $currdelold,'',$mode); + $currdelold,'',$mode, + $blockblog); if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) { $newattachmsg = '
'.$lt{'newa'}.'
'; if (@{$currnewattach} > 1) { @@ -1418,7 +1468,7 @@ sub replicate_attachments { } sub mail_screen { - my ($r,$feedurl,$options) = @_; + my ($r,$feedurl,$options,$symb) = @_; if (exists($env{'form.origpage'})) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss','blog','group','ref']); } @@ -1429,9 +1479,8 @@ sub mail_screen { 'title' => 'Title', 'reta' => 'Retained attachments', 'atta' => 'Attachment (128 KB max size)', - ); - my $title=&Apache::lonnet::gettitle($feedurl); - if (!$title) { $title = $feedurl; } + ); + my $restitle = &get_resource_title($symb,$feedurl); my $quote=''; my $subject = ''; my $comment = ''; @@ -1520,7 +1569,7 @@ END if ($idx > 0) { my %subversions = (); &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver); - $subject = &mt('Re: ')..$subversions{$numoldver}; + $subject = &mt('Re: ').$subversions{$numoldver}; } $subject = &HTML::Entities::encode($subject,'<>&"'); } else { @@ -1619,7 +1668,7 @@ END $r->print(<$title +

$restitle

$prevtag @@ -1688,6 +1737,7 @@ END if ($env{'form.editdisc'} || $env{'form.replydisc'}) { my $now = time; my $ressymb = $symb; + &Apache::lonenc::check_encrypt(\$ressymb); my $postidx = ''; if ($env{'form.editdisc'}) { $postidx = $idx; @@ -1695,7 +1745,8 @@ END if (@currnewattach > 0) { $attachnum += @currnewattach; } - $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver)); + 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').'
'; @@ -2430,7 +2481,7 @@ sub redirect_back { $feedurl .= '?group='.$group.$refarg; } } - $feedurl=&Apache::lonenc::check_encrypt($feedurl); + &Apache::lonenc::check_encrypt(\$feedurl); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); my %onload; if ($env{'environment.remote'} ne 'off') { @@ -2487,7 +2538,7 @@ sub no_redirect_back { my $end_page = &Apache::loncommon::end_page(); - $feedurl=&Apache::lonenc::check_encrypt($feedurl); + &Apache::lonenc::check_encrypt(\$feedurl); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); $r->print (<('.&mt('name only visible to course faculty').') '. ''.&mt('Change Screenname').''; } - $discussoptions.='
'; + my $blockblog = &Apache::loncommon::blocking_status('blogs'); + if (!$blockblog) { + $discussoptions.= &add_blog_checkbox(); + } } if ($msgoptions) { $msgoptions='

'.&mt('Sending Messages').'

'.$msgoptions; } if ($discussoptions) { @@ -2587,7 +2640,7 @@ sub clear_out_html { } sub assemble_email { - my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_; + my ($message,$prevattempts,$usersaw,$useranswer)=@_; my %lt = &Apache::lonlocal::texthash( 'prev' => 'Previous attempts of student (if applicable)', 'orig' => 'Original screen output (if applicable)', @@ -2613,13 +2666,18 @@ sub secapply { my $defaultflag=shift; $rec=~s/\s+//g; $rec=~s/\@/\:/g; - my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/); - if ($sections) { - foreach my $sec (split(/\;/,$sections)) { - if (($sec eq $env{'request.course.sec'}) || - ($defaultflag && ($sec eq '*'))) { + my ($adr,$sections_or_groups)=($rec=~/^([^\(]+)\(([^\)]+)\)/); + if ($sections_or_groups) { + foreach my $item (split(/\;/,$sections_or_groups)) { + if (($item eq $env{'request.course.sec'}) || + ($defaultflag && ($item eq '*'))) { return $adr; - } + } elsif ($env{'request.course.groups'}) { + my @usersgroups = split(/:/,$env{'request.course.groups'}); + if (grep(/^\Q$item\E$/,@usersgroups)) { + return $adr; + } + } } } else { return $rec; @@ -2660,11 +2718,12 @@ Returns sub decide_receiver { my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_; + &Apache::lonenc::check_decrypt(\$feedurl); my $typestyle=''; my %to=(); if ($env{'form.discuss'} eq 'author' ||$author) { $typestyle.='Submitting as Author Feedback
'; - $feedurl=~/^\/res\/(\w+)\/(\w+)\//; + $feedurl=~ m{^/res/($LONCAPA::domain_re)/($LONCAPA::username_re)/}; $to{$2.':'.$1}=1; } if ($env{'form.discuss'} eq 'question' ||$question) { @@ -2708,17 +2767,17 @@ sub feedback_available { } sub send_msg { - my ($title,$feedurl,$email,$citations,$attachmenturl,%to)=@_; + my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,%to)=@_; my $status=''; my $sendsomething=0; + my $restitle = &get_resource_title($symb,$feedurl); if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; } unless ($title=~/\w/) { $title=&mt('Feedback'); } foreach my $key (keys(%to)) { if ($key) { - my $declutter=&Apache::lonnet::declutter($feedurl); unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$key), - $title.' ['.$declutter.']',$email,$citations,$feedurl, - $attachmenturl)=~/ok/) { + $title.' ['.$restitle.']',$email,$citations,$feedurl, + $attachmenturl,undef,undef,$symb,$restitle)=~/ok/) { $status.='
'.&mt('Error sending message to').' '.$key.'
'; } else { $sendsomething++; @@ -2770,10 +2829,11 @@ sub adddiscuss { $contrib{'anonymous'}='true'; } if (($symb) && ($email)) { + my $now = time; if ($env{'form.editdisc'}) { $contrib{'ip'}=$ENV{'REMOTE_ADDR'}; $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'}; - $contrib{'timestamp'} = time; + $contrib{'timestamp'} = $now; $contrib{'history'} = ''; my $numoldver = 0; my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'}); @@ -2824,7 +2884,7 @@ sub adddiscuss { $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); } - my %storenewentry=($symb => time); + my %storenewentry=($symb => $now); $status.='
'.&mt('Updating discussion time').': '. &Apache::lonnet::put('discussiontimes',\%storenewentry, $env{'course.'.$env{'request.course.id'}.'.domain'}, @@ -2845,6 +2905,48 @@ sub adddiscuss { return $status.'
'; } +sub get_discussion_info { + my ($idx,%contrib) = @_; + my $changelast = 0; + my $count = 0; + my $hiddenflag = 0; + my $deletedflag = 0; + my ($hidden,$deleted,%info,$newlastdisc); + my $version = $contrib{'version'}; + if ($version) { + for (my $id=$version; $id>0; $id--) { + my $vkeys=$contrib{$id.':keys'}; + my @keys=split(/:/,$vkeys); + if (grep(/^hidden$/,@keys)) { + if (!$hiddenflag) { + $hidden = $contrib{$id.':hidden'}; + $hiddenflag = 1; + } + } elsif (grep(/^deleted$/,@keys)) { + if (!$deletedflag) { + $deleted = $contrib{$id.':deleted'}; + $deletedflag = 1; + } + } else { + if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) { + $count++; + $info{$count}{'id'} = $id; + $info{$count}{'timestamp'}=$contrib{$id.':timestamp'}; + } + } + } + if ($info{'1'}{'id'} == $idx) { + $changelast = 1; + if ($count > 1) { + $newlastdisc = $info{'2'}{'timestamp'}; + } else { + $newlastdisc = 0; + } + } + } + return ($changelast,$newlastdisc); +} + # ----------------------------------------------------------- Preview function sub show_preview { @@ -3036,7 +3138,8 @@ sub process_attachments { } sub generate_attachments_button { - my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_; + my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach, + $numoldver,$mode,$blockblog) = @_; my $origpage = $ENV{'REQUEST_URI'}; my $att=$attachnum.' '.&mt("attachments"); my %lt = &Apache::lonlocal::texthash( @@ -3048,6 +3151,9 @@ sub generate_attachments_button { $lt{'clic'}:  '. +&mt('Add to my public course blog').'
'."\n"; + return $output; +} + sub has_discussion { my $resourcesref = shift; my $navmap = Apache::lonnavmaps::navmap->new(); @@ -3489,7 +3615,16 @@ ENDREDIR if ( ($env{'form.hide'}) && (!$seeid) ) { $newhash{'studenthidden'} = $currentstudenthidden; } - + if ($env{'form.hide'}) { + my $changelast = 0; + my $newlast; + ($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'}); + } + } &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); @@ -3518,6 +3653,11 @@ ENDREDIR 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 ($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'}); + } my %newhash=('deleted' => $contrib{'deleted'}.".$idx."); &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, $env{'course.'.$env{'request.course.id'}.'.domain'}, @@ -3585,12 +3725,8 @@ ENDREDIR my $symb; if ($env{'form.replydisc'}) { $symb=(split(/\:\:\:/,$env{'form.replydisc'}))[0]; - my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); - $feedurl=&Apache::lonnet::clutter($url); } elsif ($env{'form.editdisc'}) { $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0]; - my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); - $feedurl=&Apache::lonnet::clutter($url); } elsif ($env{'form.origpage'}) { $symb=""; } else { @@ -3598,18 +3734,18 @@ ENDREDIR } unless ($symb) { $symb=$env{'form.symb'}; - if ($symb) { - my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); - $feedurl=&Apache::lonnet::clutter($url); - } } - &Apache::lonenc::check_decrypt(\$symb); + if (defined($symb)) { + ($symb,$feedurl)=&get_feedurl_and_clean_symb($symb); + } else { + # backward compatibility (bulletin boards used to be 'wrapped') + &Apache::lonenc::check_decrypt(\$feedurl); + &dewrapper(\$feedurl); + } my $goahead=1; if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) { unless ($symb) { $goahead=0; } } - # backward compatibility (bulletin boards used to be 'wrapped') - &dewrapper(\$feedurl); if (!$goahead) { # Ambiguous Problem Resource $r->internal_redirect('/adm/ambiguous'); @@ -3628,16 +3764,26 @@ ENDREDIR &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); return OK; } # --------------------------------------------------- Print login screen header unless ($env{'form.sendit'}) { + &Apache::lonenc::check_encrypt(\$feedurl); &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; + if (($env{'form.replydisc'}) || ($env{'form.editdisc'})) { + my ($blocked,$blocktext) = + &Apache::loncommon::blocking_status('boards'); + if ($blocked) { + $r->print(&blocked_reply_or_edit($blocktext)); + return OK; + } + } my $options=&screen_header($feedurl,$symb); if ($options) { - &mail_screen($r,$feedurl,$options); + &mail_screen($r,$feedurl,$options,$symb); } else { &fail_redirect($r,$feedurl); } @@ -3650,13 +3796,16 @@ ENDREDIR $env{'request.course.id'}); # Get output from resource + &Apache::lonenc::check_encrypt(\$feedurl); my $usersaw=&resource_output($feedurl); # Get resource answer (need to allow student to view grades for this to work) &Apache::lonnet::appenv(('allowed.vgr'=>'F')); - my $useranswer=&Apache::loncommon::get_student_answers( - $symb,$env{'user.name'},$env{'user.domain'}, - $env{'request.course.id'}); + my $usersymmb = &Apache::lonenc::check_encrypt($symb); + my $useranswer= + &Apache::loncommon::get_student_answers( + $usersymb),$env{'user.name'},$env{'user.domain'}, + $env{'request.course.id'}); &Apache::lonnet::delenv('allowed.vgr'); # Get attachments, if any, and not too large my $attachmenturl=''; @@ -3686,7 +3835,7 @@ ENDREDIR my $message=&clear_out_html($env{'form.comment'}); # Assemble email - my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts, + my ($email,$citations)=&assemble_email($message,$prevattempts, $usersaw,$useranswer); # Who gets this? @@ -3696,7 +3845,7 @@ ENDREDIR my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}, undef,1), $feedurl,$email,$citations, - $attachmenturl,%to); + $attachmenturl,$symb,%to); # Discussion? Store that. my $numpost=0; @@ -3726,6 +3875,15 @@ ENDREDIR &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group); } return OK; +} + +sub blocked_reply_or_edit { + my ($blocktext) = @_; + return + &Apache::loncommon::start_page('Resource Feedback and Discussion'). + $blocktext.'

'. + &mt('Back to previous page'). + &Apache::loncommon::end_page(); } sub wrap_symb { @@ -3830,5 +3988,32 @@ sub group_args { return $extra_args; } +sub get_resource_title { + my ($symb,$feedurl) = @_; + my ($restitle,$plainurl); + if (defined($symb)) { + my $plain_symb = &Apache::lonenc::check_decrypt($symb); + $restitle = &Apache::lonnet::gettitle($plain_symb); + } + if (defined($feedurl)) { + $plainurl = &Apache::lonenc::check_decrypt($feedurl); + } + if (!defined($restitle)) { + if (defined($feedurl)) { + $restitle = &Apache::lonnet::gettitle($plainurl); + } + } + if ($plainurl ne $feedurl) { + my ($plain_filename) = ($plainurl =~ m-/([^/]+)$-); + if ($plain_filename eq $restitle) { + $restitle = &mt('Untitled resource'); + } + } + if ($restitle eq '') { + $restitle = &mt('Untitled resource'); + } + return $restitle; +} + 1; __END__