File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.45: download - view: text, annotated - select for diffs
Fri Jun 6 02:24:49 2003 UTC (21 years ago) by www
Branches: MAIN
CVS tags: version_0_99_2, HEAD
Rewinding changes on window registration.
Attempting to overcome JavaScript security by using POST to change window
location.

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

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