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

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

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