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

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

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