File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.50: download - view: text, annotated - select for diffs
Wed Aug 6 17:00:30 2003 UTC (20 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_1_0_3, version_1_0_2, version_1_0_1, version_1_0_0, version_0_99_5, version_0_99_4, HEAD
- fixes BUG#1989, students can generate an answer mode display but only when
  generating a feedback email

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

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