--- loncom/interface/lonfeedback.pm 2006/12/08 00:28:59 1.231 +++ loncom/interface/lonfeedback.pm 2010/03/08 17:47:45 1.290 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.231 2006/12/08 00:28:59 raeburn Exp $ +# $Id: lonfeedback.pm,v 1.290 2010/03/08 17:47:45 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,7 @@ use Apache::lonnavmaps; use Apache::lonenc(); use Apache::lonrss(); use HTML::LCParser(); +#use HTML::Tidy::libXML; use Apache::lonspeller(); use Apache::longroup; use Cwd; @@ -74,6 +75,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'}) { @@ -85,19 +89,32 @@ 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 '
"; + } + } if ($group ne '' && $mode eq 'board') { if (&check_group_priv($group,'vgb') ne 'ok') { return ''; } } - my ($blocked,$blocktext) = &blocking_posts('boards',1); + my ($blocked,$blocktext) = + &Apache::loncommon::blocking_status('boards'); if ($blocked) { - return $blocktext; + $blocktext = '
'; + }else{ + $blocktext.=""; + } + return $blocktext; } - my @bgcols = ("#cccccc","#eeeeee"); + my @bgcols = ("LC_disc_old_item","LC_disc_new_item"); my $discussiononly=0; if ($mode eq 'board') { $discussiononly=1; } unless ($env{'request.course.id'}) { return ''; } @@ -107,9 +124,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)$/)); @@ -159,6 +173,7 @@ sub list_discussion { my $cdom = $env{'course.'.$cid.'.domain'}; my $cnum = $env{'course.'.$cid.'.num'}; + my $crstype = &Apache::loncommon::course_type(); # Get information about students and non-students in course for filtering display of posts my %roleshash = (); @@ -342,10 +357,10 @@ sub list_discussion { $togglink = 'toggoff'; } - $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink; + $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink; if ($newpostsflag) { - $chglink .= '&previous='.$prevread; + $chglink .= '&previous='.$prevread; } $chglink.=&group_args($group); @@ -388,8 +403,7 @@ sub list_discussion { my $manifestfilename = $tempexport.$manifest; if ($manifestfile = Apache::File->new('>'.$manifestfilename)) { $manifestok=1; - print $manifestfile qq| - + print $manifestfile qq| - |; - $discussion.='
'; + |); + $discussion.=''. + "\n".'
'; $discussion .= &action_links_bar($colspan,$ressymb,$visible, $newpostsflag,$group, $prevread,$markondisp); @@ -435,7 +449,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ $discussion.="\n".''; } @@ -547,14 +561,14 @@ imscp_v1p1.xsd http://www.imsglobal.org/ my $colspan=$maxdepth+1; $discussion .= < -
'. ''.&mt('Show all posts').' '.&mt('to display').' '. @@ -515,11 +529,11 @@ imscp_v1p1.xsd http://www.imsglobal.org/ print $manifestfile "\n". ''. - ''.$imsitems{$alldiscussion{$post}}{'title'}.''; + ''.$imsitems{$alldiscussion{$post}}{'title'}.''; $imsresources .= "\n". ''."\n". ''."\n". - $imsfiles{$alldiscussion{$post}}{$imsitems{$alldiscussion{$post}}{'currversion'}}."\n". + $imsfiles{$alldiscussion{$post}}{$imsitems{$alldiscussion{$post}}{'currversion'}}.''."\n". ''; } my $postingfile; @@ -537,7 +551,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ } $copyresult.=&replicate_attachments($imsitems{$alldiscussion{$post}}{'allattachments'},$tempexport); } else { - $discussion.=''. $discussionitems[$alldiscussion{$post}]. '
- +
'. - ''; + my $discussion = ' - END $r->print(&Apache::loncommon::end_data_table_row()); @@ -1944,8 +1975,9 @@ END $r->print(<$lt{'dotm'} - + END + my $save = &mt('Save'); $r->print(&Apache::loncommon::end_data_table_row()); $r->print(&Apache::loncommon::end_data_table()); $r->print(< - - - + + + - + END if (exists($env{'form.group'})) { $r->print(''); @@ -1988,7 +2020,14 @@ sub print_sortfilter_options { my $group_sel = ''; my $numgroupvis = 5; my %sectioncount = &Apache::loncommon::get_sections(); - + my @courseroles = qw(st ad ep ta in); + my $crstype = &Apache::loncommon::course_type(); + my $ccrole = 'cc'; + if ($crstype eq 'Community') { + $ccrole = 'co'; + } + push(@courseroles,$ccrole); + if ($env{'request.course.sec'} !~ /^\s*$/) { #Restrict section choice to current section @sections = ('all',$env{'request.course.sec'}); $numvisible = 2; @@ -2045,13 +2084,13 @@ sub print_sortfilter_options { 'spgr' => 'Specific groups', 'psub' => 'Pick specific users (by name)', 'shal' => 'Show a list of current posters', - 'stor' => 'Store changes', + 'stor' => 'Save changes', ); my %sort_types = (); my %role_types = (); my %status_types = (); - &sort_filter_names(\%sort_types,\%role_types,\%status_types); + &sort_filter_names(\%sort_types,\%role_types,\%status_types,$crstype); my $js = < @@ -2098,22 +2137,22 @@ END $r->print(< + $lt{'diso'}
$lt{'prca'}

$lt{$discdisp} +
- +
$lt{$disctogg}
- - - - - - - - - - - + + + + + + + + + + + @@ -2167,7 +2207,7 @@ $start_page
- + END if (exists($env{'form.group'})) { $r->print(''); @@ -2290,7 +2330,7 @@ END
- + $end_page END @@ -2362,7 +2402,7 @@ sub fail_redirect { my ($r,$feedurl) = @_; if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' }; my %lt = &Apache::lonlocal::texthash( - 'sorr' => 'Sorry, no recipients ...', + 'sorr' => 'Sorry, no recipients ...', ); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); $r->print(&Apache::loncommon::start_page('Feedback not sent',undef, @@ -2376,7 +2416,7 @@ ENDFAILREDIR } sub redirect_back { - my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group) = @_; + my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_; my $sorttag = ''; my $roletag = ''; my $statustag = ''; @@ -2393,7 +2433,7 @@ sub redirect_back { if ($previous > 0) { $qrystr = 'previous='.$previous; if ($feedurl =~ /\?register=1/) { - $feedurl .= '&'.$qrystr; + $feedurl .= '&'.$qrystr; } else { $feedurl .= '?'.$qrystr; } @@ -2402,18 +2442,18 @@ sub redirect_back { if (defined($sort)) { my $sortqry = 'sortposts='.$sort; if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) { - $feedurl .= '&'.$sortqry; + $feedurl .= '&'.$sortqry; } else { $feedurl .= '?'.$sortqry; } $sorttag = ''; if (defined($numpicks)) { my $userpickqry = 'totposters='.$numpicks; - $feedurl .= '&'.$userpickqry; + $feedurl .= '&'.$userpickqry; $userpicktag = ''; } else { if (ref($sectionpick) eq 'ARRAY') { - $feedurl .= '§ionpick='; + $feedurl .= '&sectionpick='; $sectag .= ''; } else { - $feedurl .= '§ionpick='.$sectionpick; + $feedurl .= '&sectionpick='.$sectionpick; $sectag = ''; } if (ref($grouppick) eq 'ARRAY') { - $feedurl .= '&grouppick='; + $feedurl .= '&grouppick='; $sectag .= ''; } else { - $feedurl .= '&grouppick='.$grouppick; + $feedurl .= '&grouppick='.$grouppick; $grptag = ''; } if (ref($rolefilter) eq 'ARRAY') { - $feedurl .= '&rolefilter='; + $feedurl .= '&rolefilter='; $roletag .= ''; } else { - $feedurl .= '&rolefilter='.$rolefilter; + $feedurl .= '&rolefilter='.$rolefilter; $roletag = ''; } - $feedurl .= '&statusfilter='.$statusfilter; + $feedurl .= '&statusfilter='.$statusfilter; $statustag =''; } } my $grouptag; if ($group ne '') { - $grouptag = ''; my $refarg; + $grouptag = ''; + my $refarg; if (exists($env{'form.ref'})) { $refarg = '&ref='.$env{'form.ref'}; $grouptag .= ''; @@ -2471,7 +2512,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') { @@ -2490,6 +2531,7 @@ $start_page $typestyle Sent $sendsomething message(s), and $sendposts post(s). $blog +$toolarge $status $prevtag @@ -2507,7 +2549,7 @@ ENDREDIR sub no_redirect_back { my ($r,$feedurl) = @_; - my $nofeed=&mt('Sorry, no feedback possible on this resource ...'); + my $nofeed=&mt('Sorry, no feedback possible on this resource ...'); my %onload; if ($env{'environment.remote'} ne 'off') { @@ -2528,7 +2570,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 (<

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

'; + ($optionhash{'question'}?$optionhash{'question'}:&mt('Question about resource content')).'

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

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

'; } } if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) { - if (&discussion_open(undef,$symb) && + my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards'); + if (!$blocked && &discussion_open(undef,$symb) && &Apache::lonnet::allowed('pch', $env{'request.course.id'}. ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { - my ($blocked) = &blocking_posts('boards'); - if (!$blocked) { - $discussoptions='
'. - ''.&mt('Change Screenname').''; - } - } - my ($blockblog) = &blocking_posts('blogs'); - if (!$blockblog) { - $discussoptions.= &add_blog_checkbox(); + $discussoptions='
'. + ''.&mt('Change Screenname').''; + my $blockblog = &Apache::loncommon::blocking_status('blogs'); + if (!$blockblog) { + $discussoptions.= &add_blog_checkbox($crstype); + } } } - if ($msgoptions) { $msgoptions='

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

'.$msgoptions; } + if ($msgoptions) { + $msgoptions='

' + .' '.&mt('Send Feedback').'

'.&Apache::lonhtmlcommon::coursepreflink(&mt('Feedback Settings'),'feedback').'

' + .$msgoptions; + } if ($discussoptions) { - $discussoptions='

'.&mt('Discussion Contributions').'

'.$discussoptions; } + $discussoptions='

' + .' '.&mt('Discussion Contributions').'

'.&Apache::lonhtmlcommon::coursepreflink(&mt('Discussion Settings'),'discussion').'

' + .$discussoptions; + } return $msgoptions.$discussoptions; } @@ -2618,11 +2685,12 @@ sub clear_out_html { ($override)) { # allows


      • #

        - # + #

  • $lt{'soor'} $lt{'sprs'} $lt{'spur'} $lt{'spse'} $lt{'spgr'} $lt{'psub'}$lt{'soor'} $lt{'sprs'} $lt{'spur'} $lt{'spse'} $lt{'spgr'} $lt{'psub'}
    @@ -2137,25 +2176,26 @@ $start_page   - - + +   - $section_sel   - $group_sel
    %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1, BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1, M=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1, - H1=>1, H2=>1, H3=>1, H4=>1, H5=>1); + H1=>1, H2=>1, H3=>1, H4=>1, H5=>1, H6=>1, + TABLE=>1, TR=>1, TD=>1, TH=>1, TBODY=>1); } # Do the substitution of everything that is not explicitly allowed $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/ @@ -2633,12 +2701,15 @@ 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)', 'corr' => 'Correct Answer(s) (if applicable)', ); + if (&Apache::loncommon::course_type() eq 'Community') { + $lt{'prev'} = &mt('Previous attempts of member (if applicable)'); + } my $email=<<"ENDEMAIL"; $message ENDEMAIL @@ -2654,136 +2725,53 @@ ENDCITE return ($email,$citations); } -sub secapply { - my $rec=shift; - 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 '*'))) { - return $adr; - } - } - } else { - return $rec; - } - return ''; -} - -=pod - -=over 4 - -=item * - -decide_receiver($feedurl,$author,$question,$course,$policy,$defaultflag); - -Arguments - $feedurl - /res/ url of resource (only need if $author is true) - $author,$question,$course,$policy - all true/false parameters - if true will attempt to find the addresses of user that should receive - this type of feedback (author - feedback to author of resource $feedurl, - $question 'Resource Content Questions', $course 'Course Content Question', - $policy 'Course Policy') - (Additionally it also checks $env for whether the corresponding form. - element exists, for ease of use in a html response context) - - $defaultflag - (internal should be left blank) if true gather addresses - that aren't for a section even if I have a section - (used for reccursion internally, first we look for - addresses for our specific section then we recurse - and look for non section addresses) - -Returns - $typestyle - string of html text, describing what addresses were found - %to - a hash, which keys are addresses of users to send messages to - the keys will look like name:domain - -=cut - -sub decide_receiver { - my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_; - my $typestyle=''; - my %to=(); - if ($env{'form.discuss'} eq 'author' ||$author) { - $typestyle.='Submitting as Author Feedback
    '; - $feedurl=~ m{^/res/($LONCAPA::domain_re)/($LONCAPA::username_re)/}; - $to{$2.':'.$1}=1; - } - if ($env{'form.discuss'} eq 'question' ||$question) { - $typestyle.=&mt('Submitting as Question').'
    '; - foreach my $item (split(/\,/, - $env{'course.'.$env{'request.course.id'}.'.question.email'}) - ) { - my $rec=&secapply($item,$defaultflag); - if ($rec) { $to{$rec}=1; } - } - } - if ($env{'form.discuss'} eq 'course' ||$course) { - $typestyle.=&mt('Submitting as Comment').'
    '; - foreach my $item (split(/\,/, - $env{'course.'.$env{'request.course.id'}.'.comment.email'}) - ) { - my $rec=&secapply($item,$defaultflag); - if ($rec) { $to{$rec}=1; } - } - } - if ($env{'form.discuss'} eq 'policy' ||$policy) { - $typestyle.=&mt('Submitting as Policy Feedback').'
    '; - foreach my $item (split(/\,/, - $env{'course.'.$env{'request.course.id'}.'.policy.email'}) - ) { - my $rec=&secapply($item,$defaultflag); - if ($rec) { $to{$rec}=1; } - } - } - if ((scalar(%to) eq '0') && (!$defaultflag)) { - ($typestyle,%to)= - &decide_receiver($feedurl,$author,$question,$course,$policy,1); - } - return ($typestyle,%to); -} sub feedback_available { my ($question,$course,$policy)=@_; - my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy); + my ($typestyle,%to)=&Apache::lonmsg::decide_receiver('',0,$question, + $course,$policy); return scalar(%to); } sub send_msg { - my ($title,$feedurl,$email,$citations,$attachmenturl,%to)=@_; - my $status=''; - my $sendsomething=0; - 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/) { - $status.='
    '.&mt('Error sending message to').' '.$key.'
    '; - } else { - $sendsomething++; - } + 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 ($user,$domain) = split(/\:/,$key,2); + if (!defined($user)) { + $status.='
    '.&mt('Error sending message to [_1], no user specified.',$key); + } elsif (!defined($domain)) { + $status.='
    '.&mt('Error sending message to [_1], no domain specified.',$key); + } else { + unless (&Apache::lonmsg::user_normal_msg($user,$domain, + $title.' ['.$restitle.']',$email,$citations,$feedurl, + $attachmenturl,undef,undef,$symb,$restitle)=~/ok/) { + $status.='
    '.&mt('Error sending message to').' '.$key.'
    '; + } else { + $sendsomething++; + } + } + } } - } + 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').'
    '; - } + 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); } sub adddiscuss { @@ -2954,11 +2942,45 @@ sub show_preview { my $end_page = &Apache::loncommon::end_page(); - $r->print($start_page.'
    '. - ''.&mt('Subject').': '.$subject.'

    '. - $message.'
    '.$end_page); + $r->print($start_page + .'

    '.&mt('Preview').'

    ' + .&Apache::lonhtmlcommon::start_pick_box() + .&Apache::lonhtmlcommon::row_title(&mt('Subject')) + .$subject + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title(&mt('Message')) + .$message + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box() + .$end_page + ); +} + +sub contains_block_html { + my ($message)=@_; + return ($message =~ m{ + <(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div) + \s* + (\w+\=['"]\w+['"])* + \s* + ( + \s*/>| + >.* + )}xs + ); } +sub tidy_html { + my ($message)=@_; +# my $tidy = HTML::Tidy::libXML->new(); +# my $xhtml = $tidy->clean($message, 'utf-8', 1); +# $xhtml =~ m/(.*)<\/body>/is; +# my $clean = $1; +# # remove any empty block-level tags +# $clean =~ s/<(table|p|div|tbody|blockquote|m|pre|algebra|center|ol|ul|span|h1|h2|h3|h4|h5|h6)\s*\/>//i; +# $message=$clean; + return $message; +} sub newline_to_br { my ($message)=@_; @@ -2989,16 +3011,17 @@ sub generate_preview_button { return(< - + +onclick="if (typeof(document.$formname.onsubmit)=='function') {document.$formname.onsubmit();};this.form.comment.value=document.$formname.$fieldname.value;this.form.subject.value=document.$formname.subject.value;this.form.submit();" /> ENDPREVIEW } sub modify_attachments { - my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_; + my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls, + $attachmaxtext,$toolarge)=@_; my %lt = &Apache::lonlocal::texthash( 'subj' => 'Subject', @@ -3006,7 +3029,7 @@ sub modify_attachments { '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.', - 'stch' => 'Store Changes', + 'stch' => 'Save Changes', ); my $js = < @@ -3017,8 +3040,12 @@ sub modify_attachments { END + # Breadcrumbs + my $brcrum = [{'href' => '', + 'text' => 'Discussion Post Attachments'}]; my $start_page = - &Apache::loncommon::start_page('Discussion Post Attachments',$js); + &Apache::loncommon::start_page('Discussion Post Attachments',$js, + {'bread_crumbs' => $brcrum,}); my $orig_subject = &unescape($env{'form.subject'}); my $subject=&clear_out_html($orig_subject,undef,1); @@ -3040,11 +3067,13 @@ END $r->print(< - +
    +
    - + + + + +
    - Subject: $subject

    +
    + Subject: $subject

    END if ($idx) { if ($attachmenturls) { @@ -3069,9 +3098,15 @@ END $r->print("
    "); } $r->print(< +
    + $lt{'adda'}
    $attachmaxtext
    @@ -3089,7 +3124,7 @@ END $r->print(''."\n"); } $r->print(< + $end_page END @@ -3136,7 +3171,7 @@ sub generate_attachments_button {
    $lt{'clic'}:  - - + + ENDATTACH if (defined($deloldattach)) { @@ -3281,7 +3316,8 @@ sub construct_attachmenturl { } sub add_blog_checkbox { - my ($checkstatus); + my ($crstype) = @_; + my $checkstatus; if ($env{'form.blog'}) { $checkstatus = 'checked="checked"'; } @@ -3295,27 +3331,39 @@ function setblogvalue() { } }
    -
    '."\n"; +
    '."\n"; return $output; } sub has_discussion { my $resourcesref = shift; my $navmap = Apache::lonnavmaps::navmap->new(); - my @allres=$navmap->retrieveResources(); - foreach my $resource (@allres) { - if ($resource->hasDiscussion()) { - my $ressymb = $resource->wrap_symb(); - push(@{$resourcesref}, $ressymb); + if (defined($navmap)) { + my @allres=$navmap->retrieveResources(); + foreach my $resource (@allres) { + if ($resource->hasDiscussion()) { + my $ressymb = $resource->wrap_symb(); + if (ref($resourcesref) eq 'ARRAY') { + push(@{$resourcesref}, $ressymb); + } + } } + } else { + &Apache::lonnet::logthis('Has discussion check failed - could not create navmap object.'); } return; } sub sort_filter_names { - my ($sort_types,$role_types,$status_types) = @_; - %{$sort_types} = ( + my ($sort_types,$role_types,$status_types,$crstype) = @_; + if (ref($sort_types) eq 'HASH') { + %{$sort_types} = ( ascdate => 'Date order - oldest first', descdate => 'Date order - newest first', thread => 'Threaded', @@ -3323,22 +3371,28 @@ sub sort_filter_names { username => 'By domain and username', lastfirst => 'By last name, first name' ); - %{$role_types} = ( - all => 'All roles', - st => 'Students', - cc => 'Course Coordinators', - in => 'Instructors', - ta => 'TAs', - ep => 'Exam proctors', - ad => 'Administrators', - cr => 'Custom roles' - ); - %{$status_types} = ( + } + my @courseroles = qw(st in ta ep ad); + if ($crstype eq 'Community') { + push(@courseroles,'co'); + } else { + push(@courseroles,'cc'); + } + if (ref($role_types) eq 'HASH') { + foreach my $role (@courseroles) { + $role_types->{$role} = &Apache::lonnet::plaintext($role,$crstype); + } + $role_types->{'all'} = 'All roles'; + $role_types->{'cr'} = 'Custom role'; + } + if (ref($status_types) eq 'HASH') { + %{$status_types} = ( all => 'Roles of any status', Active => 'Only active roles', Expired => 'Only past roles', Future => 'Only future roles', ); + } } sub handler { @@ -3354,6 +3408,10 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']); my $group = $env{'form.group'}; + my %attachmax = ( + text => &mt('(128 KB max size)'), + num => 131072, + ); if ($env{'form.editdisc'}) { if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) { my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0]; @@ -3396,7 +3454,13 @@ sub handler { &Apache::loncommon::no_cache($r); $r->send_http_header; - $r->print(&Apache::loncommon::start_page('Discussion Post Versions')); + # Breadcrumbs + my $brcrum = [{'href' => '', + 'text' => 'Discussion Post Versions'}]; + + $r->print(&Apache::loncommon::start_page('Discussion Post Versions',undef, + {'bread_crumbs' => $brcrum,}) + ); my $crs='/'.$env{'request.course.id'}; if ($env{'request.course.sec'}) { @@ -3481,7 +3545,7 @@ sub handler { my %lt = &Apache::lonlocal::texthash( 'mnpa' => 'Marked "New" posts as read in a total of', 'robb' => 'resources/bulletin boards.', - 'twnp' => 'There are currently no resources or bulletin boards with unread discussion postings.' + 'twnp' => 'There are currently no resources or discussion boards with unread discussion postings.' ); foreach my $res (@resources) { my $ressymb=$res; @@ -3624,10 +3688,10 @@ ENDREDIR my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'}); if ($env{'form.cmd'} eq 'threadedon') { &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'}); - &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on'); + &Apache::lonnet::appenv({'environment.threadeddiscussion' => 'on'}); } else { &Apache::lonnet::del('environment',['threadeddiscussion']); - &Apache::lonnet::delenv('environment\.threadeddiscussion'); + &Apache::lonnet::delenv('environment.threadeddiscussion'); } &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'
    ', '0','0','','',$env{'form.previous'},undef,undef,undef, @@ -3662,13 +3726,15 @@ ENDREDIR &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','discuss','blog']); - my (@currnewattach,@currdelold,@keepold); + my (@currnewattach,@currdelold,@keepold,$toolarge); &process_attachments(\@currnewattach,\@currdelold,\@keepold); if (exists($env{'form.addnewattach.filename'})) { - unless (length($env{'form.addnewattach'})>131072) { + if (length($env{'form.addnewattach'})<=$attachmax{'num'}) { my $subdir = 'feedback/'.$env{'form.timestamp'}; my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir); push(@currnewattach, $newattachment); + } else { + $toolarge = '

    '.&mt('Attachment not included - exceeded permitted length').'

    '; } } my $attachmenturls; @@ -3681,7 +3747,7 @@ ENDREDIR $attachmenturls = $contrib{$idx.':attachmenturl'}; } &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx, - $attachmenturls); + $attachmenturls,$attachmax{'text'},$toolarge); return OK; } elsif ($env{'form.export'}) { &Apache::loncommon::content_type($r,'text/html'); @@ -3704,7 +3770,7 @@ ENDREDIR } else { # ------------------------------------------------------------- Normal feedback my $feedurl=$env{'form.postdata'}; - $feedurl=~s/^http\:\/\///; + $feedurl=~s/^https?\:\/\///; $feedurl=~s/^$ENV{'SERVER_NAME'}//; $feedurl=~s/^$ENV{'HTTP_HOST'}//; $feedurl=~s/\?.+$//; @@ -3712,12 +3778,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 { @@ -3725,18 +3787,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'); @@ -3755,16 +3817,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,$attachmax{'text'}); } else { &fail_redirect($r,$feedurl); } @@ -3777,16 +3849,20 @@ 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'}); + &Apache::lonnet::appenv({'allowed.vgr'=>'F'}); + my $usersymb = &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=''; + my $toolarge=''; if (($env{'form.origpage'}) || ($env{'form.editdisc'}) || ($env{'form.replydisc'})) { my ($symb,$idx); @@ -3805,25 +3881,29 @@ ENDREDIR $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|; $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx); } elsif ($env{'form.attachment.filename'}) { - unless (length($env{'form.attachment'})>131072) { - $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback'); - } + if (length($env{'form.attachment'})<=$attachmax{'num'}) { + my $now = time; + my $subdir = 'feedback/'.$now; + $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,$subdir); + } else { + $toolarge = '

    '.&mt('Attachment not included - exceeded permitted length').'

    '; + } } # Filter HTML out of message (could be nasty) 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? - my ($typestyle,%to) = &decide_receiver($feedurl); + my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl); # Actually send mail my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}, undef,1), $feedurl,$email,$citations, - $attachmenturl,%to); + $attachmenturl,$usersymb,%to); # Discussion? Store that. my $numpost=0; @@ -3846,13 +3926,26 @@ ENDREDIR $env{'user.domain'}, 'CourseBlog_'.$env{'request.course.id'}, $subject,$message,$feedurl,'public'); - $blog='
    '.&mt('Added to my course blog').'
    '; + if (&Apache::loncommon::course_type() eq 'Community') { + $blog='
    '.&mt('Added to my community blog').'
    '; + } else { + $blog='
    '.&mt('Added to my course blog').'
    '; + } } # 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); + &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group,$toolarge); } 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 { @@ -3957,5 +4050,162 @@ 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__ + + +=pod + +=head1 NAME + +Apache::lonfeedback.pm + +=head1 SYNOPSIS + +Handles feedback from students to instructors and system administrators. + +Provides a screenshot of the current resource, as well as previous attempts if the resource was a homework. + +Used by lonmsg.pm. + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + +=head1 OVERVIEW + +None + +=head1 SUBROUTINES + +=over + +=item discussion_open() + +=item discussion_visible() + +=item list_discussion() + +=item send_feedback_link() + +=item send_message_link() + +=item action_links_bar() + +=item postingform_display() + +=item build_posting_display + +=item filter_regexp() + +=item get_post_contents() + +=item replicate_attachments() + +=item mail_screen() + +=item print_display_options() + +=item print_sortfilter_options() + +=item print_showposters() + +=item get_post_versions() + +=item get_post_attachments() + +=item fail_redirect() + +=item redirect_back() + +=item no_redirect_back() + +=item screen_header() + +=item resource_output() + +=item clear_out_html() + +=item assemble_email() + +=item feedback_available() + +=item send_msg() + +=item adddiscuss() + +=item get_discussion_info() + +=item show_preview() + +=item newline_to_br() + +=item tidy_html() + +=item generate_preview_button() + +=item modify_attachments() + +=item process_attachments() + +=item generate_attachments_button() + +=item extract_attachments() + +=item construct_attachmenturl() + +=item add_blog_checkbox() + +=item has_discussion() + +=item sort_filter_names() + +=item handler() + +=item blocked_reply_or_edit() + +=item wrap_symb() + +=item dewrapper() + +=item get_feedurl() + +=item get_feedurl_and_clean_symb() + +=item editing_allowed() + +=item check_group_priv() + +=item group_args() + +=item get_resource_title() + +=back + +=cut