Annotation of loncom/interface/lonfeedback.pm, revision 1.42

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

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