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

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

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