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

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

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