File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.60: download - view: text, annotated - select for diffs
Wed Sep 17 18:16:39 2003 UTC (20 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- stupid typo
- removing the blind acceptance of the answers target as a form parameter

    1: # The LearningOnline Network
    2: # Feedback
    3: #
    4: # $Id: lonfeedback.pm,v 1.60 2003/09/17 18:16:39 albertel Exp $
    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: #
   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: #
   36: # 3/1,2/3,2/5,2/6,2/8 Gerd Kortemeyer
   37: # 2/9 Guy Albertelli
   38: # 2/10 Gerd Kortemeyer
   39: # 2/13 Guy Albertelli
   40: # 7/25 Gerd Kortemeyer
   41: # 7/26 Guy Albertelli
   42: # 7/26,8/10,10/1,11/5,11/6,12/27,12/29 Gerd Kortemeyer
   43: # YEAR=2002
   44: # 1/1,1/16 Gerd Kortemeyer
   45: #
   46: 
   47: package Apache::lonfeedback;
   48: 
   49: use strict;
   50: use Apache::Constants qw(:common);
   51: use Apache::lonmsg();
   52: use Apache::loncommon();
   53: use Apache::lontexconvert();
   54: 
   55: sub list_discussion {
   56:     my ($mode,$status,$symb)=@_;
   57:     my $discussiononly=0;
   58:     if ($mode eq 'board') { $discussiononly=1; }
   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;
   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: }
  171: 
  172: sub mail_screen {
  173:   my ($r,$feedurl,$options) = @_;
  174:   my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
  175:                                           '','onLoad="window.focus();"');
  176:   my $title=&Apache::lonnet::gettitle($feedurl);
  177:   if (!$title) { $title = $feedurl; }
  178:   my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
  179:   $r->print(<<ENDDOCUMENT);
  180: <html>
  181: <head>
  182: <title>The LearningOnline Network with CAPA</title>
  183: <meta http-equiv="pragma" content="no-cache"></meta>
  184: <script>
  185:     function gosubmit() {
  186:         var rec=0;
  187:         if (typeof(document.mailform.elements.author)!="undefined") {
  188:           if (document.mailform.elements.author.checked) {
  189:              rec=1;
  190:           } 
  191:         }
  192:         if (typeof(document.mailform.elements.question)!="undefined") {
  193:           if (document.mailform.elements.question.checked) {
  194:              rec=1;
  195:           } 
  196:         }
  197:         if (typeof(document.mailform.elements.course)!="undefined") {
  198:           if (document.mailform.elements.course.checked) {
  199:              rec=1;
  200:           } 
  201:         }
  202:         if (typeof(document.mailform.elements.policy)!="undefined") {
  203:           if (document.mailform.elements.policy.checked) {
  204:              rec=1;
  205:           } 
  206:         }
  207:         if (typeof(document.mailform.elements.discuss)!="undefined") {
  208:           if (document.mailform.elements.discuss.checked) {
  209:              rec=1;
  210:           } 
  211:         }
  212:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
  213:           if (document.mailform.elements.anondiscuss.checked) {
  214:              rec=1;
  215:           } 
  216:         }
  217: 
  218:         if (rec) {
  219: 	    document.mailform.submit();
  220:         } else {
  221:             alert('Please check a feedback type.');
  222: 	}
  223:     }
  224: </script>
  225: </head>
  226: $bodytag
  227: <h2><tt>$title</tt></h2>
  228: <form action="/adm/feedback" method="post" name="mailform"
  229: enctype="multipart/form-data">
  230: <input type=hidden name=postdata value="$feedurl">
  231: Please check at least one of the following feedback types:
  232: $options<hr>
  233: My question/comment/feedback:<p>
  234: $latexHelp
  235: <textarea name=comment cols=60 rows=10 wrap=hard>
  236: </textarea><p>
  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>
  243: </form>
  244: ENDDOCUMENT
  245: $r->print(&generate_preview_button().'</body></html>');
  246: }
  247: 
  248: sub fail_redirect {
  249:   my ($r,$feedurl) = @_;
  250:   $r->print (<<ENDFAILREDIR);
  251: <head><title>Feedback not sent</title>
  252: <meta http-equiv="pragma" content="no-cache"></meta>
  253: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
  254: </head>
  255: <html>
  256: <body bgcolor="#FFFFFF">
  257: <img align=right src=/adm/lonIcons/lonlogos.gif>
  258: <b>Sorry, no recipients  ...</b>
  259: </body>
  260: </html>
  261: ENDFAILREDIR
  262: }
  263: 
  264: sub redirect_back {
  265:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status) = @_;
  266:   $r->print (<<ENDREDIR);
  267: <head>
  268: <title>Feedback sent</title>
  269: <meta http-equiv="pragma" content="no-cache"></meta>
  270: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
  271: </head>
  272: <html>
  273: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
  274: <img align=right src=/adm/lonIcons/lonlogos.gif>
  275: $typestyle
  276: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
  277: <font color=red>$status</font>
  278: <form name="reldt" action="$feedurl" target="loncapaclient">
  279: </form>
  280: </body>
  281: </html>
  282: ENDREDIR
  283: }
  284: 
  285: sub no_redirect_back {
  286:   my ($r,$feedurl) = @_;
  287:   $r->print (<<ENDNOREDIR);
  288: <head><title>Feedback not sent</title>
  289: <meta http-equiv="pragma" content="no-cache"></meta>
  290: ENDNOREDIR
  291: 
  292:   if ($feedurl!~/^\/adm\/feedback/) { 
  293:     $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
  294:   }
  295:   
  296:   $r->print (<<ENDNOREDIRTWO);
  297: </head>
  298: <html>
  299: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
  300: <img align=right src=/adm/lonIcons/lonlogos.gif>
  301: <b>Sorry, no feedback possible on this resource  ...</b>
  302: </body>
  303: </html>
  304: ENDNOREDIRTWO
  305: }
  306: 
  307: sub screen_header {
  308:   my ($feedurl) = @_;
  309:   my $msgoptions='';
  310:   my $discussoptions='';
  311:   if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
  312:     $msgoptions= 
  313:       '<p><input type=checkbox name=author> Feedback to resource author';
  314:   }
  315:   if (&feedback_available(1)) {
  316:     $msgoptions.=
  317:     '<br><input type=checkbox name=question> Question about resource content';
  318:   }
  319:   if (&feedback_available(0,1)) {
  320:     $msgoptions.=
  321:       '<br><input type=checkbox name=course> '.
  322: 	'Question/Comment/Feedback about course content';
  323:   }
  324:   if (&feedback_available(0,0,1)) {
  325:     $msgoptions.=
  326:       '<br><input type=checkbox name=policy> '.
  327: 	'Question/Comment/Feedback about course policy';
  328:   }
  329: 
  330:   if ($ENV{'request.course.id'}) {
  331:       if (&Apache::lonnet::allowed('pch',
  332:         $ENV{'request.course.id'}.
  333:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  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>';
  339:       }
  340:   }
  341:   if ($msgoptions) { $msgoptions='<h2>Sending Messages</h2>'.$msgoptions; }
  342:   if ($discussoptions) { 
  343:      $discussoptions='<h2>Discussion Contributions</h2>'.$discussoptions; }
  344:   return $msgoptions.$discussoptions;
  345: }
  346: 
  347: sub resource_output {
  348:   my ($feedurl) = @_;
  349:   my $usersaw=&Apache::lonnet::ssi_body($feedurl);
  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 {
  361:   my ($message,$override)=@_;
  362:   my $cid=$ENV{'request.course.id'};
  363:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
  364:       ($override)) {
  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,
  368: 		BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1);
  369: 
  370:       $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
  371: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
  372:       $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
  373: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
  374:   } else {
  375:       $message=~s/\<\/*m\s*\>//g;
  376:       $message=~s/\</\&lt\;/g;
  377:       $message=~s/\>/\&gt\;/g;
  378:   }
  379:   return $message;
  380: }
  381: 
  382: sub assemble_email {
  383:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
  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
  395: <h2>Correct Answer(s) (if applicable)</h2>
  396: $useranswer
  397: ENDCITE
  398:   return ($email,$citations);
  399: }
  400: 
  401: sub secapply {
  402:     my $rec=shift;
  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 '';
  418: }
  419: 
  420: sub decide_receiver {
  421:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
  422:   my $typestyle='';
  423:   my %to=();
  424:   if ($ENV{'form.author'}||$author) {
  425:     $typestyle.='Submitting as Author Feedback<br>';
  426:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
  427:     $to{$2.':'.$1}=1;
  428:   }
  429:   if ($ENV{'form.question'}||$question) {
  430:     $typestyle.='Submitting as Question<br>';
  431:     foreach (split(/\,/,
  432: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
  433: 	     ) {
  434: 	my $rec=&secapply($_,$defaultflag);
  435:         if ($rec) { $to{$rec}=1; }
  436:     } 
  437:   }
  438:   if ($ENV{'form.course'}||$course) {
  439:     $typestyle.='Submitting as Comment<br>';
  440:     foreach (split(/\,/,
  441: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
  442: 	     ) {
  443: 	my $rec=&secapply($_,$defaultflag);
  444:         if ($rec) { $to{$rec}=1; }
  445:     } 
  446:   }
  447:   if ($ENV{'form.policy'}||$policy) {
  448:     $typestyle.='Submitting as Policy Feedback<br>';
  449:     foreach (split(/\,/,
  450: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
  451: 	     ) {
  452: 	my $rec=&secapply($_,$defaultflag);
  453:         if ($rec) { $to{$rec}=1; }
  454:     } 
  455:   }
  456:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
  457:      ($typestyle,%to)=
  458: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
  459:   }
  460:   return ($typestyle,%to);
  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);
  467: }
  468: 
  469: sub send_msg {
  470:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
  471:   my $status='';
  472:   my $sendsomething=0;
  473:   foreach (keys %to) {
  474:     if ($_) {
  475:       my $declutter=&Apache::lonnet::declutter($feedurl);
  476:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
  477:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
  478:                 $attachmenturl)=~/ok/) {
  479: 	$status.='<br>Error sending message to '.$_.'<br>';
  480:       } else {
  481: 	$sendsomething++;
  482:       }
  483:     }
  484:   }
  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:        
  497:   return ($status,$sendsomething);
  498: }
  499: 
  500: sub adddiscuss {
  501:     my ($symb,$email,$anon,$attachmenturl)=@_;
  502:     my $status='';
  503:     if (&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
  504:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  505: 
  506:     my %contrib=('message'      => $email,
  507:                  'sendername'   => $ENV{'user.name'},
  508:                  'senderdomain' => $ENV{'user.domain'},
  509:                  'screenname'   => $ENV{'environment.screenname'},
  510:                  'plainname'    => $ENV{'environment.firstname'}.' '.
  511: 		                   $ENV{'environment.middlename'}.' '.
  512:                                    $ENV{'environment.lastname'}.' '.
  513:                                    $ENV{'enrironment.generation'},
  514:                  'attachmenturl'=> $attachmenturl);
  515:     if ($anon) {
  516: 	$contrib{'anonymous'}='true';
  517:     }
  518:     if (($symb) && ($email)) {
  519:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
  520:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
  521:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  522: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  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'});
  528:     }
  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;
  535:        $status.='<br>Registering: '.
  536:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
  537:     }
  538:     } else {
  539: 	$status.='Failed.';
  540:     }
  541:     return $status.'<br>';   
  542: }
  543: 
  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: }
  564: sub handler {
  565:   my $r = shift;
  566:   if ($r->header_only) {
  567:      $r->content_type('text/html');
  568:      $r->send_http_header;
  569:      return OK;
  570:   }
  571: 
  572: # --------------------------- Get query string for limited number of parameters
  573: 
  574:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  575:                              ['hide','unhide','deldisc','postdata','preview']);
  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);
  585:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  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);
  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);
  615:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  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);
  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: 
  632:     &redirect_back($r,&Apache::lonnet::clutter($url),
  633:        'Changed discussion status<p>','0','0');
  634:   } elsif ($ENV{'form.preview'}) {
  635: # -------------------------------------------------------- User wants a preview
  636:       &show_preview($r);
  637:   } else {
  638: # ------------------------------------------------------------- Normal feedback
  639:   my $feedurl=$ENV{'form.postdata'};
  640:   $feedurl=~s/^http\:\/\///;
  641:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
  642:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
  643: 
  644:   my $symb=&Apache::lonnet::symbread($feedurl);
  645:   unless ($symb) {
  646:       $symb=$ENV{'form.symb'};
  647:       if ($symb) {
  648: 	  my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
  649:           $feedurl=&Apache::lonnet::clutter($url);
  650:       }
  651:   }
  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;
  661:   
  662:     if (
  663:       (
  664:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
  665:       ) 
  666:       || 
  667:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
  668:       ||
  669:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
  670:      ) {
  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
  682:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
  683:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
  684:             $ENV{'request.course.id'});
  685: 
  686: # Get output from resource
  687:       my $usersaw=&resource_output($feedurl);
  688: 
  689: # Get resource answer (need to allow student to view grades for this to work)
  690:       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
  691:       my $useranswer=&Apache::loncommon::get_student_answers(
  692:                        $symb,$ENV{'user.name'},$ENV{'user.domain'},
  693: 		       $ENV{'request.course.id'});
  694:       &Apache::lonnet::delenv('allowed.vgr');
  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) {
  699: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment');
  700: 	  }
  701:       }
  702: # Filter HTML out of message (could be nasty)
  703:       my $message=&clear_out_html($ENV{'form.comment'});
  704: 
  705: # Assemble email
  706:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
  707:           $usersaw,$useranswer);
  708:  
  709: # Who gets this?
  710:       my ($typestyle,%to) = &decide_receiver($feedurl);
  711: 
  712: # Actually send mail
  713:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
  714:           $attachmenturl,%to);
  715: 
  716: # Discussion? Store that.
  717: 
  718:       my $numpost=0;
  719:       if ($ENV{'form.discuss'}) {
  720: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl);
  721: 	  $numpost++;
  722:       }
  723: 
  724:       if ($ENV{'form.anondiscuss'}) {
  725: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl);
  726: 	  $numpost++;
  727:       }
  728: 
  729: 
  730: # Receipt screen and redirect back to where came from
  731:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status);
  732: 
  733:     }
  734:    } else {
  735: # Unable to give feedback
  736:     &no_redirect_back($r,$feedurl);
  737:    }
  738:   } else {
  739: # Ambiguous Problem Resource
  740:       if ( &Apache::lonnet::mod_perl_version() == 2 ) {
  741: 	  &Apache::lonnet::cleanenv();
  742:       }
  743:       $r->internal_redirect('/adm/ambiguous');
  744:   }
  745: }
  746:   return OK;
  747: } 
  748: 
  749: 1;
  750: __END__

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