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

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

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