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

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

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