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

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

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