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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.19    ! albertel    4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
        !             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.18      www        42: # 7/26,8/10,10/1,11/5,11/6 Gerd Kortemeyer
1.13      www        43: 
1.7       albertel   44: 
1.1       www        45: package Apache::lonfeedback;
                     46: 
                     47: use strict;
                     48: use Apache::Constants qw(:common);
1.3       www        49: use Apache::lonmsg();
1.9       albertel   50: use Apache::loncommon();
1.1       www        51: 
1.6       albertel   52: sub mail_screen {
                     53:   my ($r,$feedurl,$options) = @_;
                     54:   $r->print(<<ENDDOCUMENT);
1.1       www        55: <html>
                     56: <head>
                     57: <title>The LearningOnline Network with CAPA</title>
1.7       albertel   58: <meta http-equiv="pragma" content="no-cache"></meta>
1.5       www        59: <script>
                     60:     function gosubmit() {
                     61:         var rec=0;
1.12      albertel   62:         if (typeof(document.mailform.elements.author)!="undefined") {
1.5       www        63:           if (document.mailform.elements.author.checked) {
                     64:              rec=1;
                     65:           } 
                     66:         }
1.12      albertel   67:         if (typeof(document.mailform.elements.question)!="undefined") {
1.5       www        68:           if (document.mailform.elements.question.checked) {
                     69:              rec=1;
                     70:           } 
                     71:         }
1.12      albertel   72:         if (typeof(document.mailform.elements.course)!="undefined") {
1.5       www        73:           if (document.mailform.elements.course.checked) {
                     74:              rec=1;
                     75:           } 
                     76:         }
1.12      albertel   77:         if (typeof(document.mailform.elements.policy)!="undefined") {
1.5       www        78:           if (document.mailform.elements.policy.checked) {
                     79:              rec=1;
                     80:           } 
                     81:         }
1.12      albertel   82:         if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10      www        83:           if (document.mailform.elements.discuss.checked) {
                     84:              rec=1;
                     85:           } 
                     86:         }
1.14      www        87:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
                     88:           if (document.mailform.elements.anondiscuss.checked) {
                     89:              rec=1;
                     90:           } 
                     91:         }
1.5       www        92: 
                     93:         if (rec) {
                     94: 	    document.mailform.submit();
                     95:         } else {
                     96:             alert('Please check a feedback type.');
                     97: 	}
                     98:     }
                     99: </script>
1.1       www       100: </head>
1.5       www       101: <body bgcolor="#FFFFFF" onLoad="window.focus();">
1.2       www       102: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1       www       103: <h1>Feedback</h1>
1.2       www       104: <h2><tt>$feedurl</tt></h2>
1.5       www       105: <form action="/adm/feedback" method=post name=mailform>
1.2       www       106: <input type=hidden name=postdata value="$feedurl">
1.5       www       107: Please check at least one of the following feedback types:
1.2       www       108: $options<hr>
                    109: My question/comment/feedback:<p>
1.16      www       110: <textarea name=comment cols=60 rows=10 wrap=hard>
1.2       www       111: </textarea><p>
1.5       www       112: <input type=hidden name=sendit value=1>
                    113: <input type=button value="Send Feedback" onClick='gosubmit();'></input>
1.2       www       114: </form>
1.1       www       115: </body>
                    116: </html>
                    117: ENDDOCUMENT
1.6       albertel  118: }
                    119: 
                    120: sub fail_redirect {
                    121:   my ($r,$feedurl) = @_;
                    122:   $r->print (<<ENDFAILREDIR);
1.5       www       123: <head><title>Feedback not sent</title>
1.7       albertel  124: <meta http-equiv="pragma" content="no-cache"></meta>
1.5       www       125: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
                    126: </head>
                    127: <html>
                    128: <body bgcolor="#FFFFFF">
1.8       www       129: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    130: <b>Sorry, no recipients  ...</b>
1.5       www       131: </body>
                    132: </html>
                    133: ENDFAILREDIR
                    134: }
1.4       www       135: 
1.6       albertel  136: sub redirect_back {
                    137:   my ($r,$feedurl,$typestyle,$sendsomething,$status) = @_;
                    138:   $r->print (<<ENDREDIR);
1.3       www       139: <head>
                    140: <title>Feedback sent</title>
1.7       albertel  141: <meta http-equiv="pragma" content="no-cache"></meta>
1.5       www       142: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
1.2       www       143: </head>
                    144: <html>
                    145: <body bgcolor="#FFFFFF">
1.8       www       146: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.5       www       147: $typestyle
                    148: <b>Sent $sendsomething message(s).</b>
1.3       www       149: <font color=red>$status</font>
1.2       www       150: </body>
                    151: </html>
                    152: ENDREDIR
                    153: }
1.6       albertel  154: 
                    155: sub no_redirect_back {
                    156:   my ($r,$feedurl) = @_;
                    157:   $r->print (<<ENDNOREDIR);
1.2       www       158: <head><title>Feedback not sent</title>
1.7       albertel  159: <meta http-equiv="pragma" content="no-cache"></meta>
                    160: ENDNOREDIR
                    161: 
1.8       www       162:   if ($feedurl!~/^\/adm\/feedback/) { 
1.7       albertel  163:     $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
                    164:   }
                    165:   
1.8       www       166:   $r->print (<<ENDNOREDIRTWO);
1.2       www       167: </head>
                    168: <html>
                    169: <body bgcolor="#FFFFFF">
1.8       www       170: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    171: <b>Sorry, no feedback possible on this resource  ...</b>
1.2       www       172: </body>
                    173: </html>
1.8       www       174: ENDNOREDIRTWO
1.2       www       175: }
1.6       albertel  176: 
                    177: sub screen_header {
                    178:   my ($feedurl) = @_;
                    179:   my $options='';
                    180:   if (($feedurl=~/^\/res/) && ($feedurl!~/^\/res\/adm/)) {
                    181:     $options= 
                    182:       '<p><input type=checkbox name=author> Feedback to resource author';
                    183:   }
                    184:   if ($ENV{'course.'.$ENV{'request.course.id'}.'.question.email'}) {
                    185:     $options.=
1.8       www       186:     '<br><input type=checkbox name=question> Question about resource content';
1.6       albertel  187:   }
                    188:   if ($ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'}) {
                    189:     $options.=
                    190:       '<br><input type=checkbox name=course> '.
                    191: 	'Question/Comment/Feedback about course content';
                    192:   }
                    193:   if ($ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'}) {
                    194:     $options.=
                    195:       '<br><input type=checkbox name=policy> '.
                    196: 	'Question/Comment/Feedback about course policy';
1.10      www       197:   }
                    198:   if ($ENV{'request.course.id'}) {
                    199:     $options.='<br><input type=checkbox name=discuss> '.
                    200: 	'<b>Contribution to course discussion of resource</b>';
1.6       albertel  201:   }
1.14      www       202:   if ($ENV{'request.course.id'}) {
                    203:     $options.='<br><input type=checkbox name=anondiscuss> '.
                    204: 	'<b>Anonymous contribution to course discussion of resource</b>'.
                    205:         ' (name only visible to course faculty)';
                    206:   }
1.6       albertel  207:   return $options;
                    208: }
                    209: 
                    210: sub resource_output {
                    211:   my ($feedurl) = @_;
                    212:   my $usersaw=&Apache::lonnet::ssi($feedurl);
                    213:   $usersaw=~s/\<body[^\>]*\>//gi;
                    214:   $usersaw=~s/\<\/body\>//gi;
                    215:   $usersaw=~s/\<html\>//gi;
                    216:   $usersaw=~s/\<\/html\>//gi;
                    217:   $usersaw=~s/\<head\>//gi;
                    218:   $usersaw=~s/\<\/head\>//gi;
                    219:   $usersaw=~s/action\s*\=/would_be_action\=/gi;
                    220:   return $usersaw;
                    221: }
                    222: 
                    223: sub clear_out_html {
                    224:   my $message=$ENV{'form.comment'};
                    225:   $message=~s/\</\&lt\;/g;
                    226:   $message=~s/\>/\&gt\;/g;
                    227:   return $message;
                    228: }
                    229: 
                    230: sub assemble_email {
                    231:   my ($feedurl,$message,$prevattempts,$usersaw)=@_;
                    232:   my $email=<<"ENDEMAIL";
                    233: Refers to <a href="$feedurl">$feedurl</a>
                    234: 
                    235: $message
                    236: ENDEMAIL
                    237:     my $citations=<<"ENDCITE";
                    238: <h2>Previous attempts of student (if applicable)</h2>
                    239: $prevattempts
                    240: <p><hr>
                    241: <h2>Original screen output (if applicable)</h2>
                    242: $usersaw
                    243: ENDCITE
                    244:   return ($email,$citations);
                    245: }
                    246: 
                    247: sub decide_receiver {
                    248:   my ($feedurl) = @_;
                    249:   my $typestyle='';
                    250:   my %to=();
                    251:   if ($ENV{'form.author'}) {
1.8       www       252:     $typestyle.='Submitting as Author Feedback<br>';
1.6       albertel  253:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
                    254:     $to{$2.':'.$1}=1;
                    255:   }
                    256:   if ($ENV{'form.question'}) {
1.8       www       257:     $typestyle.='Submitting as Question<br>';
1.6       albertel  258:     map {
                    259:       $to{$_}=1;
                    260:     } split(/\,/,
                    261: 	    $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
                    262:   }
                    263:   if ($ENV{'form.course'}) {
1.8       www       264:     $typestyle.='Submitting as Comment<br>';
1.6       albertel  265:     map {
                    266:       $to{$_}=1;
                    267:     } split(/\,/,
                    268: 	    $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
                    269:   }
                    270:   if ($ENV{'form.policy'}) {
1.8       www       271:     $typestyle.='Submitting as Policy Feedback<br>';
1.6       albertel  272:     map {
                    273:       $to{$_}=1;
                    274:     } split(/\,/,
                    275: 	    $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'});
                    276:   }
                    277:   return ($typestyle,%to);
                    278: }
                    279: 
                    280: sub send_msg {
                    281:   my ($feedurl,$email,$citations,%to)=@_;
                    282:   my $status='';
                    283:   my $sendsomething=0;
                    284:   map {
                    285:     if ($_) {
1.8       www       286:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
                    287:                'Feedback '.$feedurl,$email,$citations) eq 'ok') {
1.6       albertel  288: 	$status.='<br>Error sending message to '.$_.'<br>';
                    289:       } else {
                    290: 	$sendsomething++;
                    291:       }
                    292:     }
1.18      www       293:   } keys %to;
                    294: 
                    295:     my %record=&Apache::lonnet::restore('_feedback');
                    296:     my ($temp)=keys %record;
                    297:     unless ($temp=~/^error\:/) {
                    298:        my %newrecord=();
                    299:        $newrecord{'resource'}=$feedurl;
                    300:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
                    301:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
                    302: 	   $status.='<br>Not registered<br>';
                    303:        }
                    304:     }
                    305:        
1.6       albertel  306:   return ($status,$sendsomething);
                    307: }
                    308: 
1.13      www       309: sub adddiscuss {
1.14      www       310:     my ($symb,$email,$anon)=@_;
1.13      www       311:     my $status='';
                    312:     my %contrib=('message'      => $email,
                    313:                  'sendername'   => $ENV{'user.name'},
                    314:                  'senderdomain' => $ENV{'user.domain'});
1.14      www       315:     if ($anon) {
                    316: 	$contrib{'anonymous'}='true';
                    317:     }
1.13      www       318:     if (($symb) && ($email)) {
1.14      www       319:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13      www       320:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
                    321:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17      www       322: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13      www       323:     }
1.17      www       324:     my %record=&Apache::lonnet::restore('_discussion');
                    325:     my ($temp)=keys %record;
                    326:     unless ($temp=~/^error\:/) {
                    327:        my %newrecord=();
                    328:        $newrecord{'resource'}=$symb;
                    329:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
                    330:        $status.=' '.&Apache::lonnet::cstore(\%newrecord,'_discussion');
                    331:     }
                    332:     return $status.'<br>';   
1.13      www       333: }
                    334: 
1.6       albertel  335: sub handler {
                    336:   my $r = shift;
1.8       www       337:   if ($r->header_only) {
                    338:      $r->content_type('text/html');
                    339:      $r->send_http_header;
                    340:      return OK;
                    341:   }
1.15      www       342: 
                    343: # --------------------------- Get query string for limited number of parameters
                    344: 
                    345:     map {
                    346:        my ($name, $value) = split(/=/,$_);
                    347:        $value =~ tr/+/ /;
                    348:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    349:        if (($name eq 'hide') || ($name eq 'unhide')) {
                    350:            unless ($ENV{'form.'.$name}) {
                    351:               $ENV{'form.'.$name}=$value;
                    352: 	   }
                    353:        }
                    354:     } (split(/&/,$ENV{'QUERY_STRING'}));
                    355: 
                    356:   if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
                    357: # ----------------------------------------------------------------- Hide/unhide
                    358:     $r->content_type('text/html');
                    359:     $r->send_http_header;
                    360: 
                    361:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
                    362: 
                    363:     my ($symb,$idx)=split(/\:\:\:/,$entry);
                    364:     my ($map,$ind,$url)=split(/\_\_\_/,$symb);
                    365: 
                    366:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    367:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    368: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    369: 
                    370:         
                    371:     my $currenthidden=$contrib{'hidden'};
                    372:     
                    373:     if ($ENV{'form.hide'}) {
                    374: 	$currenthidden.='.'.$idx.'.';
                    375:     } else {
                    376:         $currenthidden=~s/\.$idx\.//g;
                    377:     }
                    378:     my %newhash=('hidden' => $currenthidden);
                    379: 
                    380:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                    381:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    382: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    383: 
                    384:     &redirect_back($r,'/res/'.$url,'Changed discussion status<p>','0');
                    385: 
                    386:       
                    387:   } else {
                    388: # ------------------------------------------------------------- Normal feedback
1.6       albertel  389:   my $feedurl=$ENV{'form.postdata'};
                    390:   $feedurl=~s/^http\:\/\///;
                    391:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                    392:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.8       www       393: 
                    394:   my $symb=&Apache::lonnet::symbread($feedurl);
                    395:   my $goahead=1;
                    396:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    397:       unless ($symb) { $goahead=0; }
                    398:   }
                    399: 
                    400:   if ($goahead) {
                    401: # Go ahead with feedback, no ambiguous reference
                    402:     $r->content_type('text/html');
                    403:     $r->send_http_header;
1.6       albertel  404:   
1.8       www       405:     if (
1.7       albertel  406:       (
                    407:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
                    408:       ) 
                    409:       || 
                    410:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
                    411:      ) {
1.6       albertel  412: # --------------------------------------------------- Print login screen header
                    413:     unless ($ENV{'form.sendit'}) {
                    414:       my $options=&screen_header($feedurl);
                    415:       if ($options) {
                    416: 	&mail_screen($r,$feedurl,$options);
                    417:       } else {
                    418: 	&fail_redirect($r,$feedurl);
                    419:       }
                    420:     } else {
                    421:       
                    422: # Get previous user input
1.9       albertel  423:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11      albertel  424:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9       albertel  425:             $ENV{'request.course.id'});
1.6       albertel  426: 
                    427: # Get output from resource
                    428:       my $usersaw=&resource_output($feedurl);
                    429: 
                    430: # Filter HTML out of message (could be nasty)
                    431:       my $message=&clear_out_html;
                    432: 
                    433: # Assemble email
1.8       www       434:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
                    435:           $usersaw);
1.6       albertel  436: 
                    437: # Who gets this?
                    438:       my ($typestyle,%to) = &decide_receiver($feedurl);
                    439: 
                    440: # Actually send mail
                    441:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,%to);
1.13      www       442: 
                    443: # Discussion? Store that.
                    444: 
                    445:       if ($ENV{'form.discuss'}) {
                    446: 	  $typestyle.=&adddiscuss($symb,$message);
                    447:       }
1.6       albertel  448: 
1.14      www       449:       if ($ENV{'form.anondiscuss'}) {
                    450: 	  $typestyle.=&adddiscuss($symb,$message,1);
                    451:       }
                    452: 
                    453: 
1.6       albertel  454: # Receipt screen and redirect back to where came from
1.8       www       455:       &redirect_back($r,$feedurl,$typestyle,$numsent,$status);
1.6       albertel  456: 
                    457:     }
1.8       www       458:    } else {
1.7       albertel  459: # Unable to give feedback
1.6       albertel  460:     &no_redirect_back($r,$feedurl);
1.8       www       461:    }
                    462:   } else {
                    463: # Ambiguous Problem Resource
                    464:     $r->internal_redirect('/adm/ambiguous');
1.6       albertel  465:   }
1.15      www       466: }
1.6       albertel  467:   return OK;
1.1       www       468: } 
                    469: 
                    470: 1;
                    471: __END__
1.14      www       472: 
1.2       www       473: 
                    474: 
                    475: 

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