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

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

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