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

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

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