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

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

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