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

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

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