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

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

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