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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
                      4: # (Internal Server Error Handler
                      5: #
                      6: # (Login Screen
                      7: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
                      8: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
                      9: #
                     10: # 3/1/1 Gerd Kortemeyer)
                     11: #
1.3     ! www        12: # 3/1,2/3,2/5,2/6 Gerd Kortemeyer
1.1       www        13: #
                     14: package Apache::lonfeedback;
                     15: 
                     16: use strict;
                     17: use Apache::Constants qw(:common);
1.3     ! www        18: use Apache::lonmsg();
1.1       www        19: 
                     20: sub handler {
                     21:     my $r = shift;
                     22:     $r->content_type('text/html');
                     23:     $r->send_http_header;
                     24:     return OK if $r->header_only;
                     25: 
1.2       www        26:     my $feedurl=$ENV{'form.postdata'};
                     27:     $feedurl=~s/^http\:\/\///;
                     28:     $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                     29:     $feedurl=~s/^$ENV{'HTTP_HOST'}//;
                     30: 
                     31:     if (($feedurl=~/^\/res/) || ($ENV{'request.course.id'})) {
1.1       www        32: # --------------------------------------------------- Print login screen header
1.2       www        33:     unless ($ENV{'form.sendit'}) {
                     34: 	my $options='';
                     35:         if ($feedurl=~/^\/res/) {
                     36:            $options= 
                     37:  '<p><input type=checkbox name=author> Feedback to resource author';
                     38:         }
                     39: 	if ($ENV{'course.'.$ENV{'request.course.id'}.'.question.email'}) {
                     40:            $options.=
                     41:  '<br><input type=checkbox name=question> Question about resource content';
                     42:         }
                     43: 	if ($ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'}) {
                     44:            $options.=
1.3     ! www        45:  '<br><input type=checkbox name=comment> '.
1.2       www        46:  'Question/Comment/Feedback about course content';
                     47:         }
                     48: 	if ($ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'}) {
                     49:            $options.=
1.3     ! www        50:  '<br><input type=checkbox name=policy> '.
1.2       www        51:  'Question/Comment/Feedback about course policy';
                     52:         }
                     53:        $r->print(<<ENDDOCUMENT);
1.1       www        54: <html>
                     55: <head>
                     56: <title>The LearningOnline Network with CAPA</title>
                     57: </head>
                     58: <body bgcolor="#FFFFFF">
1.2       www        59: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1       www        60: <h1>Feedback</h1>
1.2       www        61: <h2><tt>$feedurl</tt></h2>
                     62: <form action="/adm/feedback" method=post>
                     63: <input type=hidden name=postdata value="$feedurl">
                     64: Please check at least one of the following:
                     65: $options<hr>
                     66: My question/comment/feedback:<p>
                     67: <textarea name=comment cols=60 rows=10>
                     68: </textarea><p>
                     69: <input type=submit name=sendit value="Send Feedback"></input>
                     70: </form>
1.1       www        71: </body>
                     72: </html>
                     73: ENDDOCUMENT
1.2       www        74: } else {
1.3     ! www        75: #
        !            76: # Get previous user input
        !            77: #
1.2       www        78:     my $symb=&Apache::lonnet::symbread($feedurl);
                     79:     my $prevattempts='';
                     80:     if ($symb) {
                     81:        my $answer=&Apache::lonnet::reply(
                     82:               "restore:".$ENV{'user.domain'}.':'.$ENV{'user.name'}.':'.
                     83:               $ENV{'request.course.id'}.':'.
                     84:               &Apache::lonnet::escape($symb),
                     85:               $ENV{'user.home'});
                     86:        my %returnhash=();
                     87:        map {
                     88: 	  my ($name,$value)=split(/\=/,$_);
                     89:           $returnhash{&Apache::lonnet::unescape($name)}=
                     90:                       &Apache::lonnet::unescape($value);
                     91:        } split(/\&/,$answer);
                     92:        my %lasthash=();
                     93:        my $version;
                     94:        for ($version=1;$version<=$returnhash{'version'};$version++) {
                     95:           map {
                     96:              $lasthash{$_}=$returnhash{$version.':'.$_};
                     97:           } split(/\:/,$returnhash{$version.':keys'});
                     98:        }
                     99:        $prevattempts='<table border=2></tr><th>History</th>';
                    100:        map {
                    101:            $prevattempts.='<th>'.$_.'</th>';
                    102:        } keys %lasthash;
                    103:        for ($version=1;$version<=$returnhash{'version'};$version++) {
                    104: 	   $prevattempts.='</tr><tr><th>Attempt '.$version.'</th>';
                    105:            map {
                    106:                $prevattempts.='<td>'.$returnhash{$version.':'.$_}.'</td>';   
                    107: 	  } keys %lasthash;
                    108:        }
                    109:        $prevattempts.='</tr><tr><th>Current</th>';
                    110:        map {
                    111:            $prevattempts.='<td>'.$lasthash{$_}.'</td>';
                    112:        } keys %lasthash;
                    113:        $prevattempts.='</tr></table>';
                    114:     }
1.3     ! www       115: #
        !           116: # Get output from resource
        !           117: #
1.2       www       118:     my $usersaw=&Apache::lonnet::ssi($feedurl);
                    119:     $usersaw=~s/\<body[^\>]*\>//gi;
                    120:     $usersaw=~s/\<\/body\>//gi;
                    121:     $usersaw=~s/\<html\>//gi;
                    122:     $usersaw=~s/\<\/html\>//gi;
                    123:     $usersaw=~s/\<head\>//gi;
                    124:     $usersaw=~s/\<\/head\>//gi;
                    125:     $usersaw=~s/action\s*\=/would_be_action\=/gi;
1.3     ! www       126: #
        !           127: # Filter HTML out of message (could be nasty)
        !           128: #
        !           129:     my $message=$ENV{'form.comment'};
        !           130:     $message=~s/\</\&lt\;/g;
        !           131:     $message=~s/\>/\&gt\;/g;
        !           132: 
        !           133: #
        !           134: # Assemble email
        !           135: #
        !           136:     my $email=<<"ENDEMAIL";
        !           137: Refers to <a href="$feedurl">$feedurl</a>
        !           138: <hr>
        !           139: <h2>Message</h2>
        !           140: <pre>
        !           141: $message
        !           142: </pre>
        !           143: <hr>
        !           144: <h2>Previous attempts of student (if applicable)</h2>
        !           145: $prevattempts
        !           146: <p><hr>
        !           147: <h2>Original screen output (if applicable)</h2>
        !           148: $usersaw
        !           149: ENDEMAIL
        !           150: #
        !           151: # Who gets this?
        !           152: #
        !           153:     my %to=();
        !           154:     if ($ENV{'form.author'}) {
        !           155: 	$feedurl=~/^\/res\/(\w+)\/(\w+)\//;
        !           156:         $to{$2.':'.$1}=1;
        !           157:     }
        !           158:     if ($ENV{'form.question'}) {
        !           159: 	map {
        !           160:             $to{$_}=1;
        !           161:         } split(/\,/,
        !           162:           $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
        !           163:     }
        !           164:     if ($ENV{'form.comment'}) {
        !           165: 	map {
        !           166:             $to{$_}=1;
        !           167:         } split(/\,/,
        !           168:           $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
        !           169:     }
        !           170:     if ($ENV{'form.policy'}) {
        !           171: 	map {
        !           172:             $to{$_}=1;
        !           173:         } split(/\,/,
        !           174:           $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'});
        !           175:     }
        !           176: #
        !           177: # Actually send mail
        !           178: #
        !           179:     my $status='';
        !           180:     map {
        !           181:        if ($_) {
        !           182:           unless (
        !           183:           &Apache::lonmsg::user_normal_msg(split(/\:/,$_),'Feedback '.$feedurl,
        !           184:                                            $email) eq 'ok') {
        !           185:             $status.='<br>Error sending message to '.$_.'<br>';
        !           186: 	  }
        !           187:        }
        !           188:     } keys %to;
        !           189: #
        !           190: # Receipt screen and redirect back to where came from
        !           191: #
1.2       www       192:     print (<<ENDREDIR);
1.3     ! www       193: <head>
        !           194: <title>Feedback sent</title>
        !           195: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$feedurl">
1.2       www       196: </head>
                    197: <html>
                    198: <body bgcolor="#FFFFFF">
                    199: <b>Feedback sent ...</b>
1.3     ! www       200: <font color=red>$status</font>
1.2       www       201: </body>
                    202: </html>
                    203: ENDREDIR
                    204: }
                    205: } else {
                    206:     print (<<ENDNOREDIR);
                    207: <head><title>Feedback not sent</title>
                    208: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$feedurl">
                    209: </head>
                    210: <html>
                    211: <body bgcolor="#FFFFFF">
                    212: Sorry, no feedback possible on this resource  ...
                    213: </body>
                    214: </html>
                    215: ENDNOREDIR
                    216: }
1.1       www       217:     return OK;
                    218: } 
                    219: 
                    220: 1;
                    221: __END__
1.2       www       222: 
                    223: 
                    224: 

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