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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.25    ! www         4: # $Id: lonfeedback.pm,v 1.24 2002/03/02 03:50:27 harris41 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.1       www        53: 
1.6       albertel   54: sub mail_screen {
                     55:   my ($r,$feedurl,$options) = @_;
                     56:   $r->print(<<ENDDOCUMENT);
1.1       www        57: <html>
                     58: <head>
                     59: <title>The LearningOnline Network with CAPA</title>
1.7       albertel   60: <meta http-equiv="pragma" content="no-cache"></meta>
1.5       www        61: <script>
                     62:     function gosubmit() {
                     63:         var rec=0;
1.12      albertel   64:         if (typeof(document.mailform.elements.author)!="undefined") {
1.5       www        65:           if (document.mailform.elements.author.checked) {
                     66:              rec=1;
                     67:           } 
                     68:         }
1.12      albertel   69:         if (typeof(document.mailform.elements.question)!="undefined") {
1.5       www        70:           if (document.mailform.elements.question.checked) {
                     71:              rec=1;
                     72:           } 
                     73:         }
1.12      albertel   74:         if (typeof(document.mailform.elements.course)!="undefined") {
1.5       www        75:           if (document.mailform.elements.course.checked) {
                     76:              rec=1;
                     77:           } 
                     78:         }
1.12      albertel   79:         if (typeof(document.mailform.elements.policy)!="undefined") {
1.5       www        80:           if (document.mailform.elements.policy.checked) {
                     81:              rec=1;
                     82:           } 
                     83:         }
1.12      albertel   84:         if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10      www        85:           if (document.mailform.elements.discuss.checked) {
                     86:              rec=1;
                     87:           } 
                     88:         }
1.14      www        89:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
                     90:           if (document.mailform.elements.anondiscuss.checked) {
                     91:              rec=1;
                     92:           } 
                     93:         }
1.5       www        94: 
                     95:         if (rec) {
                     96: 	    document.mailform.submit();
                     97:         } else {
                     98:             alert('Please check a feedback type.');
                     99: 	}
                    100:     }
                    101: </script>
1.1       www       102: </head>
1.5       www       103: <body bgcolor="#FFFFFF" onLoad="window.focus();">
1.2       www       104: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1       www       105: <h1>Feedback</h1>
1.2       www       106: <h2><tt>$feedurl</tt></h2>
1.5       www       107: <form action="/adm/feedback" method=post name=mailform>
1.2       www       108: <input type=hidden name=postdata value="$feedurl">
1.5       www       109: Please check at least one of the following feedback types:
1.2       www       110: $options<hr>
                    111: My question/comment/feedback:<p>
1.16      www       112: <textarea name=comment cols=60 rows=10 wrap=hard>
1.2       www       113: </textarea><p>
1.5       www       114: <input type=hidden name=sendit value=1>
                    115: <input type=button value="Send Feedback" onClick='gosubmit();'></input>
1.2       www       116: </form>
1.1       www       117: </body>
                    118: </html>
                    119: ENDDOCUMENT
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 {
                    139:   my ($r,$feedurl,$typestyle,$sendsomething,$status) = @_;
                    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
                    150: <b>Sent $sendsomething message(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='';
                    182:   if (($feedurl=~/^\/res/) && ($feedurl!~/^\/res\/adm/)) {
                    183:     $options= 
                    184:       '<p><input type=checkbox name=author> Feedback to resource author';
                    185:   }
                    186:   if ($ENV{'course.'.$ENV{'request.course.id'}.'.question.email'}) {
                    187:     $options.=
1.8       www       188:     '<br><input type=checkbox name=question> Question about resource content';
1.6       albertel  189:   }
                    190:   if ($ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'}) {
                    191:     $options.=
                    192:       '<br><input type=checkbox name=course> '.
                    193: 	'Question/Comment/Feedback about course content';
                    194:   }
                    195:   if ($ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'}) {
                    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 {
                    229:   my $message=$ENV{'form.comment'};
                    230:   $message=~s/\</\&lt\;/g;
                    231:   $message=~s/\>/\&gt\;/g;
                    232:   return $message;
                    233: }
                    234: 
                    235: sub assemble_email {
                    236:   my ($feedurl,$message,$prevattempts,$usersaw)=@_;
                    237:   my $email=<<"ENDEMAIL";
                    238: Refers to <a href="$feedurl">$feedurl</a>
                    239: 
                    240: $message
                    241: ENDEMAIL
                    242:     my $citations=<<"ENDCITE";
                    243: <h2>Previous attempts of student (if applicable)</h2>
                    244: $prevattempts
                    245: <p><hr>
                    246: <h2>Original screen output (if applicable)</h2>
                    247: $usersaw
                    248: ENDCITE
                    249:   return ($email,$citations);
                    250: }
                    251: 
                    252: sub decide_receiver {
                    253:   my ($feedurl) = @_;
                    254:   my $typestyle='';
                    255:   my %to=();
                    256:   if ($ENV{'form.author'}) {
1.8       www       257:     $typestyle.='Submitting as Author Feedback<br>';
1.6       albertel  258:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
                    259:     $to{$2.':'.$1}=1;
                    260:   }
                    261:   if ($ENV{'form.question'}) {
1.8       www       262:     $typestyle.='Submitting as Question<br>';
1.24      harris41  263:     foreach (split(/\,/,
                    264: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
                    265: 	     ) {
1.6       albertel  266:       $to{$_}=1;
1.24      harris41  267:     } 
1.6       albertel  268:   }
                    269:   if ($ENV{'form.course'}) {
1.8       www       270:     $typestyle.='Submitting as Comment<br>';
1.24      harris41  271:     foreach (split(/\,/,
                    272: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
                    273: 	     ) {
1.6       albertel  274:       $to{$_}=1;
1.24      harris41  275:     } 
1.6       albertel  276:   }
                    277:   if ($ENV{'form.policy'}) {
1.8       www       278:     $typestyle.='Submitting as Policy Feedback<br>';
1.24      harris41  279:     foreach (split(/\,/,
                    280: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
                    281: 	     ) {
1.6       albertel  282:       $to{$_}=1;
1.24      harris41  283:     } 
1.6       albertel  284:   }
                    285:   return ($typestyle,%to);
                    286: }
                    287: 
                    288: sub send_msg {
                    289:   my ($feedurl,$email,$citations,%to)=@_;
                    290:   my $status='';
                    291:   my $sendsomething=0;
1.24      harris41  292:   foreach (keys %to) {
1.6       albertel  293:     if ($_) {
1.22      www       294:       my $declutter=&Apache::lonnet::declutter($feedurl);
1.8       www       295:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.22      www       296:                'Feedback ['.$declutter.']',$email,$citations) eq 'ok') {
1.6       albertel  297: 	$status.='<br>Error sending message to '.$_.'<br>';
                    298:       } else {
                    299: 	$sendsomething++;
                    300:       }
                    301:     }
1.24      harris41  302:   }
1.18      www       303: 
                    304:     my %record=&Apache::lonnet::restore('_feedback');
                    305:     my ($temp)=keys %record;
                    306:     unless ($temp=~/^error\:/) {
                    307:        my %newrecord=();
                    308:        $newrecord{'resource'}=$feedurl;
                    309:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
                    310:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
                    311: 	   $status.='<br>Not registered<br>';
                    312:        }
                    313:     }
                    314:        
1.6       albertel  315:   return ($status,$sendsomething);
                    316: }
                    317: 
1.13      www       318: sub adddiscuss {
1.14      www       319:     my ($symb,$email,$anon)=@_;
1.13      www       320:     my $status='';
1.23      www       321:     if (&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
                    322:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20      www       323: 
1.13      www       324:     my %contrib=('message'      => $email,
                    325:                  'sendername'   => $ENV{'user.name'},
                    326:                  'senderdomain' => $ENV{'user.domain'});
1.14      www       327:     if ($anon) {
                    328: 	$contrib{'anonymous'}='true';
                    329:     }
1.13      www       330:     if (($symb) && ($email)) {
1.14      www       331:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13      www       332:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
                    333:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17      www       334: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.21      www       335:         my %storenewentry=($symb => time);
                    336:         $status.='<br>Updating discussion time: '.
                    337:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
                    338:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    339: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13      www       340:     }
1.17      www       341:     my %record=&Apache::lonnet::restore('_discussion');
                    342:     my ($temp)=keys %record;
                    343:     unless ($temp=~/^error\:/) {
                    344:        my %newrecord=();
                    345:        $newrecord{'resource'}=$symb;
                    346:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.21      www       347:        $status.='<br>Registering: '.
                    348:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20      www       349:     }
                    350:     } else {
                    351: 	$status.='Failed.';
1.17      www       352:     }
                    353:     return $status.'<br>';   
1.13      www       354: }
                    355: 
1.6       albertel  356: sub handler {
                    357:   my $r = shift;
1.8       www       358:   if ($r->header_only) {
                    359:      $r->content_type('text/html');
                    360:      $r->send_http_header;
                    361:      return OK;
                    362:   }
1.15      www       363: 
                    364: # --------------------------- Get query string for limited number of parameters
                    365: 
1.24      harris41  366:     foreach (split(/&/,$ENV{'QUERY_STRING'})) {
1.15      www       367:        my ($name, $value) = split(/=/,$_);
                    368:        $value =~ tr/+/ /;
                    369:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.25    ! www       370:        if (($name eq 'hide') || ($name eq 'unhide') || ($name eq 'postdata')) {
1.15      www       371:            unless ($ENV{'form.'.$name}) {
                    372:               $ENV{'form.'.$name}=$value;
                    373: 	   }
                    374:        }
1.24      harris41  375:     }
1.15      www       376: 
                    377:   if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
                    378: # ----------------------------------------------------------------- Hide/unhide
                    379:     $r->content_type('text/html');
                    380:     $r->send_http_header;
                    381: 
                    382:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
                    383: 
                    384:     my ($symb,$idx)=split(/\:\:\:/,$entry);
                    385:     my ($map,$ind,$url)=split(/\_\_\_/,$symb);
                    386: 
                    387:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    388:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    389: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    390: 
                    391:         
                    392:     my $currenthidden=$contrib{'hidden'};
                    393:     
                    394:     if ($ENV{'form.hide'}) {
                    395: 	$currenthidden.='.'.$idx.'.';
                    396:     } else {
                    397:         $currenthidden=~s/\.$idx\.//g;
                    398:     }
                    399:     my %newhash=('hidden' => $currenthidden);
                    400: 
                    401:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                    402:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    403: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    404: 
                    405:     &redirect_back($r,'/res/'.$url,'Changed discussion status<p>','0');
                    406: 
                    407:       
                    408:   } else {
                    409: # ------------------------------------------------------------- Normal feedback
1.6       albertel  410:   my $feedurl=$ENV{'form.postdata'};
                    411:   $feedurl=~s/^http\:\/\///;
                    412:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                    413:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.8       www       414: 
                    415:   my $symb=&Apache::lonnet::symbread($feedurl);
                    416:   my $goahead=1;
                    417:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    418:       unless ($symb) { $goahead=0; }
                    419:   }
                    420: 
                    421:   if ($goahead) {
                    422: # Go ahead with feedback, no ambiguous reference
                    423:     $r->content_type('text/html');
                    424:     $r->send_http_header;
1.6       albertel  425:   
1.8       www       426:     if (
1.7       albertel  427:       (
                    428:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
                    429:       ) 
                    430:       || 
                    431:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
                    432:      ) {
1.6       albertel  433: # --------------------------------------------------- Print login screen header
                    434:     unless ($ENV{'form.sendit'}) {
                    435:       my $options=&screen_header($feedurl);
                    436:       if ($options) {
                    437: 	&mail_screen($r,$feedurl,$options);
                    438:       } else {
                    439: 	&fail_redirect($r,$feedurl);
                    440:       }
                    441:     } else {
                    442:       
                    443: # Get previous user input
1.9       albertel  444:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11      albertel  445:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9       albertel  446:             $ENV{'request.course.id'});
1.6       albertel  447: 
                    448: # Get output from resource
                    449:       my $usersaw=&resource_output($feedurl);
                    450: 
                    451: # Filter HTML out of message (could be nasty)
                    452:       my $message=&clear_out_html;
                    453: 
                    454: # Assemble email
1.8       www       455:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
                    456:           $usersaw);
1.6       albertel  457: 
                    458: # Who gets this?
                    459:       my ($typestyle,%to) = &decide_receiver($feedurl);
                    460: 
                    461: # Actually send mail
                    462:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,%to);
1.13      www       463: 
                    464: # Discussion? Store that.
                    465: 
                    466:       if ($ENV{'form.discuss'}) {
                    467: 	  $typestyle.=&adddiscuss($symb,$message);
                    468:       }
1.6       albertel  469: 
1.14      www       470:       if ($ENV{'form.anondiscuss'}) {
                    471: 	  $typestyle.=&adddiscuss($symb,$message,1);
                    472:       }
                    473: 
                    474: 
1.6       albertel  475: # Receipt screen and redirect back to where came from
1.8       www       476:       &redirect_back($r,$feedurl,$typestyle,$numsent,$status);
1.6       albertel  477: 
                    478:     }
1.8       www       479:    } else {
1.7       albertel  480: # Unable to give feedback
1.6       albertel  481:     &no_redirect_back($r,$feedurl);
1.8       www       482:    }
                    483:   } else {
                    484: # Ambiguous Problem Resource
                    485:     $r->internal_redirect('/adm/ambiguous');
1.6       albertel  486:   }
1.15      www       487: }
1.6       albertel  488:   return OK;
1.1       www       489: } 
                    490: 
                    491: 1;
                    492: __END__
1.14      www       493: 
1.2       www       494: 
                    495: 
                    496: 

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