File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.62: download - view: text, annotated - select for diffs
Wed Oct 15 20:01:48 2003 UTC (20 years, 7 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #2226: remove query string from refers-to-URL

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

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