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

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

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