File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.52: download - view: text, annotated - select for diffs
Tue Sep 9 18:46:28 2003 UTC (20 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
Hiding symb-splitting behind &decode_symb

    1: # The LearningOnline Network
    2: # Feedback
    3: #
    4: # $Id: lonfeedback.pm,v 1.52 2003/09/09 18:46:28 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (Internal Server Error Handler
   29: #
   30: # (Login Screen
   31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
   32: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
   33: #
   34: # 3/1/1 Gerd Kortemeyer)
   35: #
   36: # 3/1,2/3,2/5,2/6,2/8 Gerd Kortemeyer
   37: # 2/9 Guy Albertelli
   38: # 2/10 Gerd Kortemeyer
   39: # 2/13 Guy Albertelli
   40: # 7/25 Gerd Kortemeyer
   41: # 7/26 Guy Albertelli
   42: # 7/26,8/10,10/1,11/5,11/6,12/27,12/29 Gerd Kortemeyer
   43: # YEAR=2002
   44: # 1/1,1/16 Gerd Kortemeyer
   45: #
   46: 
   47: package Apache::lonfeedback;
   48: 
   49: use strict;
   50: use Apache::Constants qw(:common);
   51: use Apache::lonmsg();
   52: use Apache::loncommon();
   53: use Apache::lontexconvert();
   54: 
   55: sub mail_screen {
   56:   my ($r,$feedurl,$options) = @_;
   57:   my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
   58:                                           '','onLoad="window.focus();"');
   59:   my $title=&Apache::lonnet::gettitle($feedurl);
   60:   if (!$title) { $title = $feedurl; }
   61:   my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
   62:   $r->print(<<ENDDOCUMENT);
   63: <html>
   64: <head>
   65: <title>The LearningOnline Network with CAPA</title>
   66: <meta http-equiv="pragma" content="no-cache"></meta>
   67: <script>
   68:     function gosubmit() {
   69:         var rec=0;
   70:         if (typeof(document.mailform.elements.author)!="undefined") {
   71:           if (document.mailform.elements.author.checked) {
   72:              rec=1;
   73:           } 
   74:         }
   75:         if (typeof(document.mailform.elements.question)!="undefined") {
   76:           if (document.mailform.elements.question.checked) {
   77:              rec=1;
   78:           } 
   79:         }
   80:         if (typeof(document.mailform.elements.course)!="undefined") {
   81:           if (document.mailform.elements.course.checked) {
   82:              rec=1;
   83:           } 
   84:         }
   85:         if (typeof(document.mailform.elements.policy)!="undefined") {
   86:           if (document.mailform.elements.policy.checked) {
   87:              rec=1;
   88:           } 
   89:         }
   90:         if (typeof(document.mailform.elements.discuss)!="undefined") {
   91:           if (document.mailform.elements.discuss.checked) {
   92:              rec=1;
   93:           } 
   94:         }
   95:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
   96:           if (document.mailform.elements.anondiscuss.checked) {
   97:              rec=1;
   98:           } 
   99:         }
  100: 
  101:         if (rec) {
  102: 	    document.mailform.submit();
  103:         } else {
  104:             alert('Please check a feedback type.');
  105: 	}
  106:     }
  107: </script>
  108: </head>
  109: $bodytag
  110: <h2><tt>$title</tt></h2>
  111: <form action="/adm/feedback" method="post" name="mailform"
  112: enctype="multipart/form-data">
  113: <input type=hidden name=postdata value="$feedurl">
  114: Please check at least one of the following feedback types:
  115: $options<hr>
  116: My question/comment/feedback:<p>
  117: $latexHelp
  118: <textarea name=comment cols=60 rows=10 wrap=hard>
  119: </textarea><p>
  120: Attachment (128 KB max size): <input type="file" name="attachment" />
  121: </p>
  122: <p>
  123: <input type="hidden" name="sendit" value="1" />
  124: <input type=button value="Send Feedback" onClick='gosubmit();' />
  125: </p>
  126: </form>
  127: ENDDOCUMENT
  128: $r->print(&generate_preview_button().'</body></html>');
  129: }
  130: 
  131: sub fail_redirect {
  132:   my ($r,$feedurl) = @_;
  133:   $r->print (<<ENDFAILREDIR);
  134: <head><title>Feedback not sent</title>
  135: <meta http-equiv="pragma" content="no-cache"></meta>
  136: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
  137: </head>
  138: <html>
  139: <body bgcolor="#FFFFFF">
  140: <img align=right src=/adm/lonIcons/lonlogos.gif>
  141: <b>Sorry, no recipients  ...</b>
  142: </body>
  143: </html>
  144: ENDFAILREDIR
  145: }
  146: 
  147: sub redirect_back {
  148:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status) = @_;
  149:   $r->print (<<ENDREDIR);
  150: <head>
  151: <title>Feedback sent</title>
  152: <meta http-equiv="pragma" content="no-cache"></meta>
  153: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
  154: </head>
  155: <html>
  156: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
  157: <img align=right src=/adm/lonIcons/lonlogos.gif>
  158: $typestyle
  159: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
  160: <font color=red>$status</font>
  161: <form name="reldt" action="$feedurl" target="loncapaclient">
  162: </form>
  163: </body>
  164: </html>
  165: ENDREDIR
  166: }
  167: 
  168: sub no_redirect_back {
  169:   my ($r,$feedurl) = @_;
  170:   $r->print (<<ENDNOREDIR);
  171: <head><title>Feedback not sent</title>
  172: <meta http-equiv="pragma" content="no-cache"></meta>
  173: ENDNOREDIR
  174: 
  175:   if ($feedurl!~/^\/adm\/feedback/) { 
  176:     $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
  177:   }
  178:   
  179:   $r->print (<<ENDNOREDIRTWO);
  180: </head>
  181: <html>
  182: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
  183: <img align=right src=/adm/lonIcons/lonlogos.gif>
  184: <b>Sorry, no feedback possible on this resource  ...</b>
  185: </body>
  186: </html>
  187: ENDNOREDIRTWO
  188: }
  189: 
  190: sub screen_header {
  191:   my ($feedurl) = @_;
  192:   my $msgoptions='';
  193:   my $discussoptions='';
  194:   if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
  195:     $msgoptions= 
  196:       '<p><input type=checkbox name=author> Feedback to resource author';
  197:   }
  198:   if (&feedback_available(1)) {
  199:     $msgoptions.=
  200:     '<br><input type=checkbox name=question> Question about resource content';
  201:   }
  202:   if (&feedback_available(0,1)) {
  203:     $msgoptions.=
  204:       '<br><input type=checkbox name=course> '.
  205: 	'Question/Comment/Feedback about course content';
  206:   }
  207:   if (&feedback_available(0,0,1)) {
  208:     $msgoptions.=
  209:       '<br><input type=checkbox name=policy> '.
  210: 	'Question/Comment/Feedback about course policy';
  211:   }
  212: 
  213:   if ($ENV{'request.course.id'}) {
  214:       if (&Apache::lonnet::allowed('pch',
  215:         $ENV{'request.course.id'}.
  216:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  217:     $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;"> '.
  218: 	'Contribution to course discussion of resource';
  219:     $discussoptions.='<br><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;"> '.
  220: 	'Anonymous contribution to course discussion of resource'.
  221:         ' <i>(name only visible to course faculty)</i>';
  222:       }
  223:   }
  224:   if ($msgoptions) { $msgoptions='<h2>Sending Messages</h2>'.$msgoptions; }
  225:   if ($discussoptions) { 
  226:      $discussoptions='<h2>Discussion Contributions</h2>'.$discussoptions; }
  227:   return $msgoptions.$discussoptions;
  228: }
  229: 
  230: sub resource_output {
  231:   my ($feedurl) = @_;
  232:   my $usersaw=&Apache::lonnet::ssi_body($feedurl);
  233:   $usersaw=~s/\<body[^\>]*\>//gi;
  234:   $usersaw=~s/\<\/body\>//gi;
  235:   $usersaw=~s/\<html\>//gi;
  236:   $usersaw=~s/\<\/html\>//gi;
  237:   $usersaw=~s/\<head\>//gi;
  238:   $usersaw=~s/\<\/head\>//gi;
  239:   $usersaw=~s/action\s*\=/would_be_action\=/gi;
  240:   return $usersaw;
  241: }
  242: 
  243: sub clear_out_html {
  244:   my ($message,$override)=@_;
  245:   my $cid=$ENV{'request.course.id'};
  246:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
  247:       ($override)) {
  248:       # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> 
  249:       # <BLOCKQUOTE> <DIV .*> <DIV> <IMG>
  250:       my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
  251: 		BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1);
  252: 
  253:       $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
  254: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
  255:       $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
  256: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
  257:   } else {
  258:       $message=~s/\<\/*m\s*\>//g;
  259:       $message=~s/\</\&lt\;/g;
  260:       $message=~s/\>/\&gt\;/g;
  261:   }
  262:   return $message;
  263: }
  264: 
  265: sub assemble_email {
  266:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
  267:   my $email=<<"ENDEMAIL";
  268: Refers to <a href="$feedurl">$feedurl</a>
  269: 
  270: $message
  271: ENDEMAIL
  272:     my $citations=<<"ENDCITE";
  273: <h2>Previous attempts of student (if applicable)</h2>
  274: $prevattempts
  275: <p><hr>
  276: <h2>Original screen output (if applicable)</h2>
  277: $usersaw
  278: <h2>Correct Answer(s) (if applicable)</h2>
  279: $useranswer
  280: ENDCITE
  281:   return ($email,$citations);
  282: }
  283: 
  284: sub secapply {
  285:     my $rec=shift;
  286:     my $defaultflag=shift;
  287:     $rec=~s/\s+//g;
  288:     $rec=~s/\@/\:/g;
  289:     my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
  290:     if ($sections) {
  291: 	foreach (split(/\;/,$sections)) {
  292:             if (($_ eq $ENV{'request.course.sec'}) ||
  293:                 ($defaultflag && ($_ eq '*'))) {
  294:                 return $adr; 
  295:             }
  296:         }
  297:     } else {
  298:        return $rec;
  299:     }
  300:     return '';
  301: }
  302: 
  303: sub decide_receiver {
  304:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
  305:   my $typestyle='';
  306:   my %to=();
  307:   if ($ENV{'form.author'}||$author) {
  308:     $typestyle.='Submitting as Author Feedback<br>';
  309:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
  310:     $to{$2.':'.$1}=1;
  311:   }
  312:   if ($ENV{'form.question'}||$question) {
  313:     $typestyle.='Submitting as Question<br>';
  314:     foreach (split(/\,/,
  315: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
  316: 	     ) {
  317: 	my $rec=&secapply($_,$defaultflag);
  318:         if ($rec) { $to{$rec}=1; }
  319:     } 
  320:   }
  321:   if ($ENV{'form.course'}||$course) {
  322:     $typestyle.='Submitting as Comment<br>';
  323:     foreach (split(/\,/,
  324: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
  325: 	     ) {
  326: 	my $rec=&secapply($_,$defaultflag);
  327:         if ($rec) { $to{$rec}=1; }
  328:     } 
  329:   }
  330:   if ($ENV{'form.policy'}||$policy) {
  331:     $typestyle.='Submitting as Policy Feedback<br>';
  332:     foreach (split(/\,/,
  333: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
  334: 	     ) {
  335: 	my $rec=&secapply($_,$defaultflag);
  336:         if ($rec) { $to{$rec}=1; }
  337:     } 
  338:   }
  339:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
  340:      ($typestyle,%to)=
  341: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
  342:   }
  343:   return ($typestyle,%to);
  344: }
  345: 
  346: sub feedback_available {
  347:     my ($question,$course,$policy)=@_;
  348:     my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
  349:     return scalar(%to);
  350: }
  351: 
  352: sub send_msg {
  353:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
  354:   my $status='';
  355:   my $sendsomething=0;
  356:   foreach (keys %to) {
  357:     if ($_) {
  358:       my $declutter=&Apache::lonnet::declutter($feedurl);
  359:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
  360:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
  361:                 $attachmenturl)=~/ok/) {
  362: 	$status.='<br>Error sending message to '.$_.'<br>';
  363:       } else {
  364: 	$sendsomething++;
  365:       }
  366:     }
  367:   }
  368: 
  369:     my %record=&Apache::lonnet::restore('_feedback');
  370:     my ($temp)=keys %record;
  371:     unless ($temp=~/^error\:/) {
  372:        my %newrecord=();
  373:        $newrecord{'resource'}=$feedurl;
  374:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
  375:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
  376: 	   $status.='<br>Not registered<br>';
  377:        }
  378:     }
  379:        
  380:   return ($status,$sendsomething);
  381: }
  382: 
  383: sub adddiscuss {
  384:     my ($symb,$email,$anon,$attachmenturl)=@_;
  385:     my $status='';
  386:     if (&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
  387:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  388: 
  389:     my %contrib=('message'      => $email,
  390:                  'sendername'   => $ENV{'user.name'},
  391:                  'senderdomain' => $ENV{'user.domain'},
  392:                  'screenname'   => $ENV{'environment.screenname'},
  393:                  'plainname'    => $ENV{'environment.firstname'}.' '.
  394: 		                   $ENV{'environment.middlename'}.' '.
  395:                                    $ENV{'environment.lastname'}.' '.
  396:                                    $ENV{'enrironment.generation'},
  397:                  'attachmenturl'=> $attachmenturl);
  398:     if ($anon) {
  399: 	$contrib{'anonymous'}='true';
  400:     }
  401:     if (($symb) && ($email)) {
  402:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
  403:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
  404:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  405: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  406:         my %storenewentry=($symb => time);
  407:         $status.='<br>Updating discussion time: '.
  408:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
  409:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  410: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  411:     }
  412:     my %record=&Apache::lonnet::restore('_discussion');
  413:     my ($temp)=keys %record;
  414:     unless ($temp=~/^error\:/) {
  415:        my %newrecord=();
  416:        $newrecord{'resource'}=$symb;
  417:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
  418:        $status.='<br>Registering: '.
  419:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
  420:     }
  421:     } else {
  422: 	$status.='Failed.';
  423:     }
  424:     return $status.'<br>';   
  425: }
  426: 
  427: # ----------------------------------------------------------- Preview function
  428: 
  429: sub show_preview {
  430:     my $r=shift;
  431:     my $message=&clear_out_html($ENV{'form.comment'});
  432:     $message=~s/\n/\<br \/\>/g;
  433:     $message=&Apache::lontexconvert::msgtexconverted($message);
  434:     $r->print('<table border="2"><tr><td>'.
  435:        $message.'</td></tr></table>');
  436: }
  437: 
  438: sub generate_preview_button {
  439:     return(<<ENDPREVIEW);
  440: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
  441: <input type="hidden" name="comment" />
  442: <input type="button" value="Show Preview"
  443: onClick="this.form.comment.value=document.mailform.comment.value;this.form.submit();" />
  444: </form>
  445: ENDPREVIEW
  446: }
  447: sub handler {
  448:   my $r = shift;
  449:   if ($r->header_only) {
  450:      $r->content_type('text/html');
  451:      $r->send_http_header;
  452:      return OK;
  453:   }
  454: 
  455: # --------------------------- Get query string for limited number of parameters
  456: 
  457:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  458:                              ['hide','unhide','deldisc','postdata','preview']);
  459: 
  460:   if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
  461: # ----------------------------------------------------------------- Hide/unhide
  462:     $r->content_type('text/html');
  463:     $r->send_http_header;
  464: 
  465:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
  466: 
  467:     my ($symb,$idx)=split(/\:\:\:/,$entry);
  468:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  469: 
  470:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
  471:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  472: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  473: 
  474:         
  475:     my $currenthidden=$contrib{'hidden'};
  476:     
  477:     if ($ENV{'form.hide'}) {
  478: 	$currenthidden.='.'.$idx.'.';
  479:     } else {
  480:         $currenthidden=~s/\.$idx\.//g;
  481:     }
  482:     my %newhash=('hidden' => $currenthidden);
  483: 
  484:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
  485:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  486: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  487: 
  488:     &redirect_back($r,&Apache::lonnet::clutter($url),
  489:        'Changed discussion status<p>','0','0');
  490:   } elsif ($ENV{'form.deldisc'}) {
  491: # --------------------------------------------------------------- Hide for good
  492:     $r->content_type('text/html');
  493:     $r->send_http_header;
  494: 
  495:     my $entry=$ENV{'form.deldisc'};
  496: 
  497:     my ($symb,$idx)=split(/\:\:\:/,$entry);
  498:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  499: 
  500:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
  501:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  502: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  503: 
  504:         
  505:     my $currentdeleted=$contrib{'deleted'};
  506:     
  507:     $currentdeleted.='.'.$idx.'.';
  508: 
  509:     my %newhash=('deleted' => $currentdeleted);
  510: 
  511:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
  512:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  513: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  514: 
  515:     &redirect_back($r,&Apache::lonnet::clutter($url),
  516:        'Changed discussion status<p>','0','0');
  517:   } elsif ($ENV{'form.preview'}) {
  518: # -------------------------------------------------------- User wants a preview
  519:       &show_preview($r);
  520:   } else {
  521: # ------------------------------------------------------------- Normal feedback
  522:   my $feedurl=$ENV{'form.postdata'};
  523:   $feedurl=~s/^http\:\/\///;
  524:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
  525:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
  526: 
  527:   my $symb=&Apache::lonnet::symbread($feedurl);
  528:   unless ($symb) {
  529:       $symb=$ENV{'form.symb'};
  530:       if ($symb) {
  531: 	  my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
  532:           $feedurl=&Apache::lonnet::clutter($url);
  533:       }
  534:   }
  535:   my $goahead=1;
  536:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  537:       unless ($symb) { $goahead=0; }
  538:   }
  539: 
  540:   if ($goahead) {
  541: # Go ahead with feedback, no ambiguous reference
  542:     $r->content_type('text/html');
  543:     $r->send_http_header;
  544:   
  545:     if (
  546:       (
  547:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
  548:       ) 
  549:       || 
  550:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
  551:       ||
  552:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
  553:      ) {
  554: # --------------------------------------------------- Print login screen header
  555:     unless ($ENV{'form.sendit'}) {
  556:       my $options=&screen_header($feedurl);
  557:       if ($options) {
  558: 	&mail_screen($r,$feedurl,$options);
  559:       } else {
  560: 	&fail_redirect($r,$feedurl);
  561:       }
  562:     } else {
  563:       
  564: # Get previous user input
  565:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
  566:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
  567:             $ENV{'request.course.id'});
  568: 
  569: # Get output from resource
  570:       my $usersaw=&resource_output($feedurl);
  571: 
  572: # Get resource answer (need to allow student to view grades for this to work)
  573:       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
  574:       my $useranswer=&Apache::loncommon::get_student_answers(
  575:                        $symb,$ENV{'user.name'},$ENV{'user.domain'},
  576: 		       $ENV{'request.course.id'});
  577:       &Apache::lonnet::delenv('allowed.vgr');
  578: # Get attachments, if any, and not too large
  579:       my $attachmenturl='';
  580:       if ($ENV{'form.attachment.filename'}) {
  581: 	  unless (length($ENV{'form.attachment'})>131072) {
  582: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment');
  583: 	  }
  584:       }
  585: # Filter HTML out of message (could be nasty)
  586:       my $message=&clear_out_html($ENV{'form.comment'});
  587: 
  588: # Assemble email
  589:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
  590:           $usersaw,$useranswer);
  591:  
  592: # Who gets this?
  593:       my ($typestyle,%to) = &decide_receiver($feedurl);
  594: 
  595: # Actually send mail
  596:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
  597:           $attachmenturl,%to);
  598: 
  599: # Discussion? Store that.
  600: 
  601:       my $numpost=0;
  602:       if ($ENV{'form.discuss'}) {
  603: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl);
  604: 	  $numpost++;
  605:       }
  606: 
  607:       if ($ENV{'form.anondiscuss'}) {
  608: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl);
  609: 	  $numpost++;
  610:       }
  611: 
  612: 
  613: # Receipt screen and redirect back to where came from
  614:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status);
  615: 
  616:     }
  617:    } else {
  618: # Unable to give feedback
  619:     &no_redirect_back($r,$feedurl);
  620:    }
  621:   } else {
  622: # Ambiguous Problem Resource
  623:     $r->internal_redirect('/adm/ambiguous');
  624:   }
  625: }
  626:   return OK;
  627: } 
  628: 
  629: 1;
  630: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>