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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.44      www         4: # $Id: lonfeedback.pm,v 1.43 2003/03/30 21:58:17 www 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.45    ! 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.43      www       108: <form action="/adm/feedback" method="post" name="mailform"
                    109: enctype="multipart/form-data">
1.2       www       110: <input type=hidden name=postdata value="$feedurl">
1.5       www       111: Please check at least one of the following feedback types:
1.2       www       112: $options<hr>
                    113: My question/comment/feedback:<p>
1.16      www       114: <textarea name=comment cols=60 rows=10 wrap=hard>
1.2       www       115: </textarea><p>
1.42      www       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>
1.2       www       122: </form>
1.1       www       123: ENDDOCUMENT
1.33      www       124: $r->print(&generate_preview_button().'</body></html>');
1.6       albertel  125: }
                    126: 
                    127: sub fail_redirect {
                    128:   my ($r,$feedurl) = @_;
                    129:   $r->print (<<ENDFAILREDIR);
1.5       www       130: <head><title>Feedback not sent</title>
1.7       albertel  131: <meta http-equiv="pragma" content="no-cache"></meta>
1.5       www       132: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
                    133: </head>
                    134: <html>
                    135: <body bgcolor="#FFFFFF">
1.8       www       136: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    137: <b>Sorry, no recipients  ...</b>
1.5       www       138: </body>
                    139: </html>
                    140: ENDFAILREDIR
                    141: }
1.4       www       142: 
1.6       albertel  143: sub redirect_back {
1.32      albertel  144:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status) = @_;
1.6       albertel  145:   $r->print (<<ENDREDIR);
1.3       www       146: <head>
                    147: <title>Feedback sent</title>
1.7       albertel  148: <meta http-equiv="pragma" content="no-cache"></meta>
1.5       www       149: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
1.2       www       150: </head>
                    151: <html>
                    152: <body bgcolor="#FFFFFF">
1.8       www       153: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.5       www       154: $typestyle
1.32      albertel  155: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.3       www       156: <font color=red>$status</font>
1.2       www       157: </body>
                    158: </html>
                    159: ENDREDIR
                    160: }
1.6       albertel  161: 
                    162: sub no_redirect_back {
                    163:   my ($r,$feedurl) = @_;
                    164:   $r->print (<<ENDNOREDIR);
1.2       www       165: <head><title>Feedback not sent</title>
1.7       albertel  166: <meta http-equiv="pragma" content="no-cache"></meta>
                    167: ENDNOREDIR
                    168: 
1.8       www       169:   if ($feedurl!~/^\/adm\/feedback/) { 
1.7       albertel  170:     $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
                    171:   }
                    172:   
1.8       www       173:   $r->print (<<ENDNOREDIRTWO);
1.2       www       174: </head>
                    175: <html>
                    176: <body bgcolor="#FFFFFF">
1.8       www       177: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    178: <b>Sorry, no feedback possible on this resource  ...</b>
1.2       www       179: </body>
                    180: </html>
1.8       www       181: ENDNOREDIRTWO
1.2       www       182: }
1.6       albertel  183: 
                    184: sub screen_header {
                    185:   my ($feedurl) = @_;
                    186:   my $options='';
1.35      www       187:   if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
1.6       albertel  188:     $options= 
                    189:       '<p><input type=checkbox name=author> Feedback to resource author';
                    190:   }
1.36      www       191:   if (&feedback_available(1)) {
1.6       albertel  192:     $options.=
1.8       www       193:     '<br><input type=checkbox name=question> Question about resource content';
1.6       albertel  194:   }
1.36      www       195:   if (&feedback_available(0,1)) {
1.6       albertel  196:     $options.=
                    197:       '<br><input type=checkbox name=course> '.
                    198: 	'Question/Comment/Feedback about course content';
                    199:   }
1.36      www       200:   if (&feedback_available(0,0,1)) {
1.6       albertel  201:     $options.=
                    202:       '<br><input type=checkbox name=policy> '.
                    203: 	'Question/Comment/Feedback about course policy';
1.10      www       204:   }
1.20      www       205: 
1.10      www       206:   if ($ENV{'request.course.id'}) {
1.23      www       207:       if (&Apache::lonnet::allowed('pch',
                    208:         $ENV{'request.course.id'}.
                    209:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.10      www       210:     $options.='<br><input type=checkbox name=discuss> '.
                    211: 	'<b>Contribution to course discussion of resource</b>';
1.14      www       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)';
1.20      www       215:       }
1.14      www       216:   }
1.6       albertel  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 {
1.39      www       234:   my ($message,$override)=@_;
1.37      albertel  235:   my $cid=$ENV{'request.course.id'};
1.39      www       236:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
                    237:       ($override)) {
1.37      albertel  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:   }
1.6       albertel  252:   return $message;
                    253: }
                    254: 
                    255: sub assemble_email {
1.40      albertel  256:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6       albertel  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
1.40      albertel  268: <h2>Correct Answer(s) (if applicable)</h2>
                    269: $useranswer
1.6       albertel  270: ENDCITE
                    271:   return ($email,$citations);
                    272: }
                    273: 
1.35      www       274: sub secapply {
                    275:     my $rec=shift;
1.36      www       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 '';
1.35      www       291: }
                    292: 
1.6       albertel  293: sub decide_receiver {
1.36      www       294:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6       albertel  295:   my $typestyle='';
                    296:   my %to=();
1.36      www       297:   if ($ENV{'form.author'}||$author) {
1.8       www       298:     $typestyle.='Submitting as Author Feedback<br>';
1.6       albertel  299:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
                    300:     $to{$2.':'.$1}=1;
                    301:   }
1.36      www       302:   if ($ENV{'form.question'}||$question) {
1.8       www       303:     $typestyle.='Submitting as Question<br>';
1.24      harris41  304:     foreach (split(/\,/,
                    305: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
                    306: 	     ) {
1.36      www       307: 	my $rec=&secapply($_,$defaultflag);
                    308:         if ($rec) { $to{$rec}=1; }
1.24      harris41  309:     } 
1.6       albertel  310:   }
1.36      www       311:   if ($ENV{'form.course'}||$course) {
1.8       www       312:     $typestyle.='Submitting as Comment<br>';
1.24      harris41  313:     foreach (split(/\,/,
                    314: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
                    315: 	     ) {
1.36      www       316: 	my $rec=&secapply($_,$defaultflag);
                    317:         if ($rec) { $to{$rec}=1; }
1.24      harris41  318:     } 
1.6       albertel  319:   }
1.36      www       320:   if ($ENV{'form.policy'}||$policy) {
1.8       www       321:     $typestyle.='Submitting as Policy Feedback<br>';
1.24      harris41  322:     foreach (split(/\,/,
                    323: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
                    324: 	     ) {
1.36      www       325: 	my $rec=&secapply($_,$defaultflag);
                    326:         if ($rec) { $to{$rec}=1; }
1.24      harris41  327:     } 
1.6       albertel  328:   }
1.36      www       329:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
                    330:      ($typestyle,%to)=
                    331: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
                    332:   }
1.6       albertel  333:   return ($typestyle,%to);
1.36      www       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);
1.6       albertel  340: }
                    341: 
                    342: sub send_msg {
1.43      www       343:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6       albertel  344:   my $status='';
                    345:   my $sendsomething=0;
1.24      harris41  346:   foreach (keys %to) {
1.6       albertel  347:     if ($_) {
1.22      www       348:       my $declutter=&Apache::lonnet::declutter($feedurl);
1.8       www       349:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43      www       350:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
                    351:                 $attachmenturl)=~/ok/) {
1.6       albertel  352: 	$status.='<br>Error sending message to '.$_.'<br>';
                    353:       } else {
                    354: 	$sendsomething++;
                    355:       }
                    356:     }
1.24      harris41  357:   }
1.18      www       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:        
1.6       albertel  370:   return ($status,$sendsomething);
                    371: }
                    372: 
1.13      www       373: sub adddiscuss {
1.42      www       374:     my ($symb,$email,$anon,$attachmenturl)=@_;
1.13      www       375:     my $status='';
1.23      www       376:     if (&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
                    377:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20      www       378: 
1.13      www       379:     my %contrib=('message'      => $email,
                    380:                  'sendername'   => $ENV{'user.name'},
1.26      www       381:                  'senderdomain' => $ENV{'user.domain'},
                    382:                  'screenname'   => $ENV{'environment.screenname'},
                    383:                  'plainname'    => $ENV{'environment.firstname'}.' '.
                    384: 		                   $ENV{'environment.middlename'}.' '.
                    385:                                    $ENV{'environment.lastname'}.' '.
1.42      www       386:                                    $ENV{'enrironment.generation'},
1.43      www       387:                  'attachmenturl'=> $attachmenturl);
1.14      www       388:     if ($anon) {
                    389: 	$contrib{'anonymous'}='true';
                    390:     }
1.13      www       391:     if (($symb) && ($email)) {
1.14      www       392:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13      www       393:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
                    394:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17      www       395: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.21      www       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'});
1.13      www       401:     }
1.17      www       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;
1.21      www       408:        $status.='<br>Registering: '.
                    409:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20      www       410:     }
                    411:     } else {
                    412: 	$status.='Failed.';
1.17      www       413:     }
                    414:     return $status.'<br>';   
1.13      www       415: }
                    416: 
1.33      www       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: }
1.6       albertel  437: sub handler {
                    438:   my $r = shift;
1.8       www       439:   if ($r->header_only) {
                    440:      $r->content_type('text/html');
                    441:      $r->send_http_header;
                    442:      return OK;
                    443:   }
1.15      www       444: 
                    445: # --------------------------- Get query string for limited number of parameters
                    446: 
1.27      stredwic  447:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.38      www       448:                              ['hide','unhide','deldisc','postdata','preview']);
1.15      www       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);
1.38      www       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);
1.15      www       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: 
1.30      www       505:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.32      albertel  506:        'Changed discussion status<p>','0','0');
1.33      www       507:   } elsif ($ENV{'form.preview'}) {
                    508: # -------------------------------------------------------- User wants a preview
                    509:       &show_preview($r);
1.15      www       510:   } else {
                    511: # ------------------------------------------------------------- Normal feedback
1.6       albertel  512:   my $feedurl=$ENV{'form.postdata'};
                    513:   $feedurl=~s/^http\:\/\///;
                    514:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                    515:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.8       www       516: 
                    517:   my $symb=&Apache::lonnet::symbread($feedurl);
1.31      www       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:   }
1.8       www       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;
1.6       albertel  534:   
1.8       www       535:     if (
1.7       albertel  536:       (
                    537:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
                    538:       ) 
                    539:       || 
                    540:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31      www       541:       ||
                    542:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7       albertel  543:      ) {
1.6       albertel  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
1.9       albertel  555:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11      albertel  556:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9       albertel  557:             $ENV{'request.course.id'});
1.6       albertel  558: 
                    559: # Get output from resource
                    560:       my $usersaw=&resource_output($feedurl);
                    561: 
1.40      albertel  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'});
1.42      www       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) {
1.43      www       570: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment');
1.42      www       571: 	  }
                    572:       }
1.6       albertel  573: # Filter HTML out of message (could be nasty)
1.39      www       574:       my $message=&clear_out_html($ENV{'form.comment'});
1.6       albertel  575: 
                    576: # Assemble email
1.8       www       577:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40      albertel  578:           $usersaw,$useranswer);
                    579:  
1.6       albertel  580: # Who gets this?
                    581:       my ($typestyle,%to) = &decide_receiver($feedurl);
                    582: 
                    583: # Actually send mail
1.43      www       584:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
                    585:           $attachmenturl,%to);
1.13      www       586: 
                    587: # Discussion? Store that.
                    588: 
1.32      albertel  589:       my $numpost=0;
1.13      www       590:       if ($ENV{'form.discuss'}) {
1.42      www       591: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl);
1.32      albertel  592: 	  $numpost++;
1.13      www       593:       }
1.6       albertel  594: 
1.14      www       595:       if ($ENV{'form.anondiscuss'}) {
1.42      www       596: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl);
1.32      albertel  597: 	  $numpost++;
1.14      www       598:       }
                    599: 
                    600: 
1.6       albertel  601: # Receipt screen and redirect back to where came from
1.32      albertel  602:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status);
1.6       albertel  603: 
                    604:     }
1.8       www       605:    } else {
1.7       albertel  606: # Unable to give feedback
1.6       albertel  607:     &no_redirect_back($r,$feedurl);
1.8       www       608:    }
                    609:   } else {
                    610: # Ambiguous Problem Resource
                    611:     $r->internal_redirect('/adm/ambiguous');
1.6       albertel  612:   }
1.15      www       613: }
1.6       albertel  614:   return OK;
1.1       www       615: } 
                    616: 
                    617: 1;
                    618: __END__

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