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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.82    ! albertel    4: # $Id: lonfeedback.pm,v 1.81 2004/05/05 23:04:57 raeburn 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.77      www        28: ###
1.7       albertel   29: 
1.1       www        30: package Apache::lonfeedback;
                     31: 
                     32: use strict;
                     33: use Apache::Constants qw(:common);
1.3       www        34: use Apache::lonmsg();
1.9       albertel   35: use Apache::loncommon();
1.33      www        36: use Apache::lontexconvert();
1.62      www        37: use Apache::lonlocal;
1.54      www        38: 
                     39: sub list_discussion {
1.81      raeburn    40:     my ($mode,$status,$symb)=@_;
1.77      www        41: #    &Apache::lonnet::logthis("status is $status");
                     42:     if (!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
                     43: 	  || $status eq 'OPEN')) {
1.75      albertel   44: 	return '';
                     45:     }
1.57      www        46:     my $discussiononly=0;
                     47:     if ($mode eq 'board') { $discussiononly=1; }
1.55      www        48:     unless ($ENV{'request.course.id'}) { return ''; }
                     49:     my $crs='/'.$ENV{'request.course.id'};
                     50:     if ($ENV{'request.course.sec'}) {
                     51: 	$crs.='_'.$ENV{'request.course.sec'};
                     52:     }                 
                     53:     $crs=~s/\_/\//g;
1.54      www        54:     unless ($symb) {
                     55: 	$symb=&Apache::lonnet::symbread();
                     56:     }
                     57:     unless ($symb) { return ''; }
1.78      raeburn    58: 
1.80      raeburn    59: # backward compatibility (bulletin boards used to be 'wrapped')
                     60:     my $ressymb=$symb;
                     61:     if ($mode eq 'board') {
                     62:         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                     63:             $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                     64:         }
                     65:     }
                     66: 
                     67: # Get discussion display settings for this discussion
                     68:     my $lastkey = $ressymb.'_lastread';
                     69:     my $showkey = $ressymb.'_showonlyunread';
                     70:     my $visitkey = $ressymb.'_visit';
                     71:     my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey],$ENV{'user.domain'},$ENV{'user.name'});
                     72:     my $showonlyunread = 0;
1.79      raeburn    73:     my $prevread = 0;
1.81      raeburn    74:     my $previous = 0;
1.80      raeburn    75:     my $visit = 0;
                     76:     my $newpostsflag = 0;
                     77: 
1.81      raeburn    78: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
                     79:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous']);
                     80:     $previous = $ENV{'form.previous'};
1.80      raeburn    81:     if ($previous > 0) {
                     82:         $prevread = $previous;
                     83:     } elsif (defined($dischash{$lastkey})) {
                     84:         $prevread = $dischash{$lastkey};
                     85:     }
1.79      raeburn    86: 
1.80      raeburn    87:     if (defined($dischash{$showkey})) {
                     88:         $showonlyunread = $dischash{$showkey};
                     89:     }
                     90: 
                     91:     if (defined($dischash{$visitkey})) {
                     92:         $visit = $dischash{$visitkey};
1.78      raeburn    93:     }
1.80      raeburn    94:     $visit ++;
1.78      raeburn    95: 
1.54      www        96:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.77      www        97:     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
                     98: 	&& ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
1.68      www        99:     my @discussionitems=();
1.73      albertel  100:     my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1.54      www       101: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    102: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.67      www       103:     my $visible=0;
1.68      www       104:     my @depth=();
                    105:     my @original=();
                    106:     my @index=();
                    107:     my @replies=();
                    108:     my %alldiscussion=();
1.80      raeburn   109:     my %notshown = ();
1.68      www       110:     my $maxdepth=0;
                    111: 
1.69      www       112:     my $target='';
                    113:     unless ($ENV{'browser.interface'} eq 'textual' ||
                    114: 	    $ENV{'environment.remote'} eq 'off' ) {
                    115: 	$target='target="LONcom"';
                    116:     }
1.79      raeburn   117:     
                    118:     my $now = time;
1.80      raeburn   119:     my %discinfo = ();
                    120:     $discinfo{$visitkey} = $visit;
                    121:     $discinfo{$lastkey} = $now;
                    122: 
                    123:     &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.79      raeburn   124: 
1.54      www       125:     if ($contrib{'version'}) {
1.64      www       126: 	for (my $id=1;$id<=$contrib{'version'};$id++) {
                    127: 	    my $idx=$id;
1.80      raeburn   128:             my $posttime = $contrib{$idx.':timestamp'};
                    129:             if ($prevread > 0 && $prevread <= $posttime) {
                    130:                 $newpostsflag = 1;
                    131:             }
1.54      www       132: 	    my $hidden=($contrib{'hidden'}=~/\.$idx\./);
                    133: 	    my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1.68      www       134: 	    my $origindex='0.';
1.69      www       135: 	    if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) {
1.68      www       136: # this is a follow-up message
                    137: 		$original[$idx]=$original[$contrib{$idx.':replyto'}];
                    138: 		$depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
                    139: 		$origindex=$index[$contrib{$idx.':replyto'}];
                    140: 		if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
                    141: 	    } else {
                    142: # this is an original message
                    143: 		$original[$idx]=0;
                    144: 		$depth[$idx]=0;
                    145: 	    }
                    146: 	    if ($replies[$depth[$idx]]) {
                    147: 		$replies[$depth[$idx]]++;
                    148: 	    } else {
                    149: 		$replies[$depth[$idx]]=1;
                    150: 	    }
1.54      www       151: 	    unless ((($hidden) && (!$seeid)) || ($deleted)) {
1.67      www       152: 		$visible++;
1.54      www       153: 		my $message=$contrib{$idx.':message'};
                    154: 		$message=~s/\n/\<br \/\>/g;
                    155: 		$message=&Apache::lontexconvert::msgtexconverted($message);
1.78      raeburn   156:                 my $subject=$contrib{$idx.':subject'};
                    157:                 if (defined($subject)) {
                    158:                     $subject=~s/\n/\<br \/\>/g;
                    159:                     $subject=&Apache::lontexconvert::msgtexconverted($subject);
                    160:                 }
1.54      www       161: 		if ($contrib{$idx.':attachmenturl'}) {
1.82    ! albertel  162: 		    my ($fname)
        !           163:                         =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
        !           164: 		    &Apache::lonnet::allowuploaded('/adm/feedback',
        !           165: 					   $contrib{$idx.':attachmenturl'});
        !           166: 		    $message.='<p>'.&mt('Attachment').
        !           167: 			': <a href="'.$contrib{$idx.':attachmenturl'}.'"><tt>'.
        !           168: 			$fname.'</tt></a></p>';
1.54      www       169: 		}
                    170: 		if ($message) {
                    171: 		    if ($hidden) {
                    172: 			$message='<font color="#888888">'.$message.'</font>';
                    173: 		    }
                    174: 		    my $screenname=&Apache::loncommon::screenname(
                    175: 					    $contrib{$idx.':sendername'},
                    176: 					    $contrib{$idx.':senderdomain'});
                    177: 		    my $plainname=&Apache::loncommon::nickname(
                    178: 					    $contrib{$idx.':sendername'},
                    179: 					    $contrib{$idx.':senderdomain'});
                    180: 		    
1.62      www       181: 		    my $sender=&mt('Anonymous');
1.54      www       182: 		    if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
                    183: 			$sender=&Apache::loncommon::aboutmewrapper(
                    184: 					 $plainname,
                    185: 					 $contrib{$idx.':sendername'},
                    186: 					 $contrib{$idx.':senderdomain'}).' ('.
                    187: 					 $contrib{$idx.':sendername'}.' at '.
                    188: 					 $contrib{$idx.':senderdomain'}.')';
                    189: 			if ($contrib{$idx.':anonymous'}) {
1.62      www       190: 			    $sender.=' ['.&mt('anonymous').'] '.
1.54      www       191: 				$screenname;
                    192: 			}
                    193: 			if ($seeid) {
                    194: 			    if ($hidden) {
                    195: 				$sender.=' <a href="/adm/feedback?unhide='.
1.80      raeburn   196: 				    $ressymb.':::'.$idx;
                    197:                                 if ($newpostsflag) {
                    198:                                     $sender .= '&previous='.$prevread;
                    199:                                 }
                    200:                                 $sender .= '">'.&mt('Make Visible').'</a>';
1.54      www       201: 			    } else {
                    202: 				$sender.=' <a href="/adm/feedback?hide='.
1.80      raeburn   203: 				    $ressymb.':::'.$idx;
                    204:                                 if ($newpostsflag) {
                    205:                                     $sender .= '&previous='.$prevread;
                    206:                                 }
                    207:                                 $sender .= '">'.&mt('Hide').'</a>';
1.54      www       208: 			    }                     
                    209: 			    $sender.=' <a href="/adm/feedback?deldisc='.
1.80      raeburn   210: 				$ressymb.':::'.$idx;
                    211:                                 if ($newpostsflag) {
                    212:                                     $sender .= '&previous='.$prevread;
                    213:                                 }
                    214:                                 $sender .= '">'.&mt('Delete').'</a>';
1.64      www       215: 			}
1.54      www       216: 		    } else {
                    217: 			if ($screenname) {
                    218: 			    $sender='<i>'.$screenname.'</i>';
                    219: 			}
1.77      www       220: 		    }
                    221: 		    if (&Apache::lonnet::allowed('pch',
                    222: 						 $ENV{'request.course.id'}.
                    223: 						 ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
                    224: 			$sender.=' <a href="/adm/feedback?replydisc='.
1.80      raeburn   225: 			    $ressymb.':::'.$idx;
                    226:                         if ($newpostsflag) {
                    227:                             $sender .= '&previous='.$prevread;
                    228:                         }
                    229:                         $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
1.54      www       230: 		    }
                    231: 		    my $vgrlink;
                    232: 		    if ($viewgrades) {
                    233: 			$vgrlink=&Apache::loncommon::submlink('Submissions',
                    234:             $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
                    235: 		    }
1.68      www       236: #figure out at what position this needs to print
                    237: 		    my $thisindex=$idx;
1.69      www       238: 		    if ($ENV{'environment.threadeddiscussion'}) {
1.68      www       239: 			$thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);	
                    240: 		    }
                    241: 		    $alldiscussion{$thisindex}=$idx;
                    242: 		    $index[$idx]=$thisindex;
1.79      raeburn   243:                     my $spansize = 2;
1.80      raeburn   244:                     if ($showonlyunread && $prevread > $posttime) {
                    245:                         $notshown{$idx} = 1;
1.78      raeburn   246:                     } else {
1.80      raeburn   247:                         $discussionitems[$idx]='<p><table border="0" width="100%"><tr>';
                    248:                         if ($prevread > 0 && $prevread <= $posttime) {
                    249:                             $discussionitems[$idx] .= '<td align="left" bgcolor="#FFFFFF"><font color="#FF0000">NEW</font></td>';
                    250:                         }
                    251:                         $discussionitems[$idx] .= '<td align ="left">&nbsp;&nbsp;'.
                    252:                             '<b>'.$subject.'</b>&nbsp;&nbsp;'.
                    253:                             $sender.'</b> '.$vgrlink.' ('.
                    254:                             localtime($posttime).')</td></tr>'.
                    255:                             '</table><blockquote>'.$message.'</blockquote></p>';
1.78      raeburn   256:                     }
                    257:                 }
                    258:             }
1.54      www       259: 	}
1.64      www       260:     }
1.80      raeburn   261: 
1.67      www       262:     my $discussion='';
                    263:     if ($visible) {
1.80      raeburn   264: # Print the discusssion
1.67      www       265: 	$discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
1.69      www       266: 	if ($visible>2) {
                    267: 	    my $colspan=$maxdepth+1;
1.80      raeburn   268: 	    $discussion.='<tr><td bgcolor="DDDDBB" colspan="'.$colspan.'">'.
                    269:             '<table border="0" width="100%" bgcolor="#DDDDBB"><tr><td align="left">'.
                    270:             '<a href="/adm/feedback?threadedon='.$ressymb.'">'.&mt('Threaded View').'</a>&nbsp;&nbsp;'.
                    271:             '<a href="/adm/feedback?threadedoff='.$ressymb.'">'.&mt('Chronological View').'</a>&nbsp;&nbsp;</td>'.
                    272:             '<td align="right"><a href="/adm/feedback?';
1.78      raeburn   273:             if ($showonlyunread) {
1.80      raeburn   274:                 $discussion .= 'allposts='.$ressymb;
                    275:                 if ($newpostsflag) {
                    276:                     $discussion .= '&previous='.$prevread;
                    277:                 }
                    278:                 $discussion .='">'.&mt('Show all posts').'?';
1.78      raeburn   279:             } else {
1.80      raeburn   280:                 $discussion .= 'onlyunread='.$ressymb;
                    281:                 if ($newpostsflag) {
                    282:                     $discussion .= '&previous='.$prevread;
                    283:                 }
                    284:                 $discussion .= '">'.&mt('Show only unread posts').'?';
1.78      raeburn   285:             }
1.80      raeburn   286:             $discussion .= '</a>&nbsp;&nbsp;</td></tr></table></td></tr>';
1.69      www       287: 	}
1.80      raeburn   288:         my $numhidden = keys %notshown;
                    289:         if ($numhidden > 0) {
                    290:             my $colspan = $maxdepth+1;
                    291:             $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
                    292:                          '<a href="/adm/feedback?allposts='.$ressymb;
                    293:             if ($newpostsflag) {
                    294:                 $discussion .= '&previous='.$prevread;
                    295:             }
                    296:             $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
                    297:                          $numhidden.' '.&mt('previously viewed posts').
                    298:                          '<br/></td></tr>';
                    299:         }
1.68      www       300: 	foreach (sort { $a <=> $b } keys %alldiscussion) {
1.80      raeburn   301:             unless ($notshown{$alldiscussion{$_}} eq '1') {
                    302: 	        $discussion.="\n<tr>";
                    303: 	        my $thisdepth=$depth[$alldiscussion{$_}];
                    304: 	        for (1..$thisdepth) {
                    305: 		    $discussion.='<td>&nbsp;&nbsp;&nbsp;</td>';
                    306: 	        }
                    307: 	        my $colspan=$maxdepth-$thisdepth+1;
                    308:                 $discussion.='<td  bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
                    309:                              $discussionitems[$alldiscussion{$_}].
                    310: 	                     '</td></tr>';
1.69      www       311: 	    }
1.80      raeburn   312:         }
                    313:         $discussion.='</table><br /><br />';
1.54      www       314:     }
                    315:     if ($discussiononly) {
                    316: 	$discussion.=(<<ENDDISCUSS);
                    317: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
                    318: <input type="submit" name="discuss" value="Post Discussion" />
                    319: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
1.73      albertel  320: <input type="hidden" name="symb" value="$ressymb" />
1.54      www       321: <input type="hidden" name="sendit" value="true" />
                    322: <br />
                    323: <font size="1">Note: in anonymous discussion, your name is visible only to
                    324: course faculty</font><br />
1.78      raeburn   325: <b>Title:</b>&nbsp;<input type="text" name="subject" value="" size="30" /><br /><br />
1.63      albertel  326: <textarea name="comment" cols="60" rows="10" wrap="hard"></textarea>
1.54      www       327: <p>
                    328: Attachment (128 KB max size): <input type="file" name="attachment" />
                    329: </p>
                    330: </form>
                    331: ENDDISCUSS
                    332:       $discussion.=&generate_preview_button();
1.74      www       333:     } else {
                    334: 	if (&Apache::lonnet::allowed('pch',
                    335: 				   $ENV{'request.course.id'}.
                    336: 	($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
                    337: 			    $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
                    338: 				$symb.':::" '.$target.'>'.
                    339: 				'<img src="/adm/lonMisc/chat.gif" border="0" />'.
                    340: 				&mt('Post Discussion').'</a></td></tr></table>';
                    341: 			}
                    342:     }
1.54      www       343:    return $discussion;
                    344: }
1.1       www       345: 
1.6       albertel  346: sub mail_screen {
                    347:   my ($r,$feedurl,$options) = @_;
1.45      www       348:   my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
                    349:                                           '','onLoad="window.focus();"');
1.51      albertel  350:   my $title=&Apache::lonnet::gettitle($feedurl);
                    351:   if (!$title) { $title = $feedurl; }
1.69      www       352:   my $quote='';
1.78      raeburn   353:   my $subject = '';
1.80      raeburn   354:   my $prevtag = '';
1.69      www       355:   if ($ENV{'form.replydisc'}) {
                    356:       my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
                    357:       my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    358: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    359: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.80      raeburn   360:       unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.69      www       361: 	  my $message=$contrib{$idx.':message'};
                    362: 	  $message=~s/\n/\<br \/\>/g;
                    363: 	  $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.79      raeburn   364:           if ($idx > 0) {
                    365:               $subject = 'Re: '.$contrib{$idx.':subject'};
                    366:           }
1.69      www       367:       }
1.80      raeburn   368:       if ($ENV{'form.previous'}) {
                    369:           $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
                    370:       }
1.69      www       371:   }
1.47      bowersj2  372:   my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
1.74      www       373:   my $send=&mt('Send');
1.6       albertel  374:   $r->print(<<ENDDOCUMENT);
1.1       www       375: <html>
                    376: <head>
                    377: <title>The LearningOnline Network with CAPA</title>
1.7       albertel  378: <meta http-equiv="pragma" content="no-cache"></meta>
1.63      albertel  379: <script type="text/javascript">
                    380: //<!--
1.5       www       381:     function gosubmit() {
                    382:         var rec=0;
1.12      albertel  383:         if (typeof(document.mailform.elements.author)!="undefined") {
1.5       www       384:           if (document.mailform.elements.author.checked) {
                    385:              rec=1;
                    386:           } 
                    387:         }
1.12      albertel  388:         if (typeof(document.mailform.elements.question)!="undefined") {
1.5       www       389:           if (document.mailform.elements.question.checked) {
                    390:              rec=1;
                    391:           } 
                    392:         }
1.12      albertel  393:         if (typeof(document.mailform.elements.course)!="undefined") {
1.5       www       394:           if (document.mailform.elements.course.checked) {
                    395:              rec=1;
                    396:           } 
                    397:         }
1.12      albertel  398:         if (typeof(document.mailform.elements.policy)!="undefined") {
1.5       www       399:           if (document.mailform.elements.policy.checked) {
                    400:              rec=1;
                    401:           } 
                    402:         }
1.12      albertel  403:         if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10      www       404:           if (document.mailform.elements.discuss.checked) {
                    405:              rec=1;
                    406:           } 
                    407:         }
1.14      www       408:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
                    409:           if (document.mailform.elements.anondiscuss.checked) {
                    410:              rec=1;
                    411:           } 
                    412:         }
1.5       www       413: 
                    414:         if (rec) {
                    415: 	    document.mailform.submit();
                    416:         } else {
                    417:             alert('Please check a feedback type.');
                    418: 	}
                    419:     }
1.63      albertel  420: //-->
1.5       www       421: </script>
1.1       www       422: </head>
1.29      www       423: $bodytag
1.51      albertel  424: <h2><tt>$title</tt></h2>
1.43      www       425: <form action="/adm/feedback" method="post" name="mailform"
                    426: enctype="multipart/form-data">
1.80      raeburn   427: $prevtag
1.63      albertel  428: <input type="hidden" name="postdata" value="$feedurl" />
1.68      www       429: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
1.5       www       430: Please check at least one of the following feedback types:
1.63      albertel  431: $options<hr />
1.69      www       432: $quote
1.63      albertel  433: <p>My question/comment/feedback:</p>
                    434: <p>
1.47      bowersj2  435: $latexHelp
1.78      raeburn   436: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
                    437: <p>
1.63      albertel  438: <textarea name="comment" cols="60" rows="10" wrap="hard">
                    439: </textarea></p>
                    440: <p>
1.42      www       441: Attachment (128 KB max size): <input type="file" name="attachment" />
                    442: </p>
                    443: <p>
                    444: <input type="hidden" name="sendit" value="1" />
1.74      www       445: <input type="button" value="$send" onClick='gosubmit();' />
1.42      www       446: </p>
1.2       www       447: </form>
1.1       www       448: ENDDOCUMENT
1.33      www       449: $r->print(&generate_preview_button().'</body></html>');
1.6       albertel  450: }
                    451: 
                    452: sub fail_redirect {
                    453:   my ($r,$feedurl) = @_;
1.70      www       454:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.6       albertel  455:   $r->print (<<ENDFAILREDIR);
1.72      albertel  456: <html>
1.5       www       457: <head><title>Feedback not sent</title>
1.63      albertel  458: <meta http-equiv="pragma" content="no-cache" />
                    459: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5       www       460: </head>
                    461: <body bgcolor="#FFFFFF">
1.63      albertel  462: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8       www       463: <b>Sorry, no recipients  ...</b>
1.5       www       464: </body>
                    465: </html>
                    466: ENDFAILREDIR
                    467: }
1.4       www       468: 
1.6       albertel  469: sub redirect_back {
1.80      raeburn   470:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_;
                    471:   my $prevtag = '';
                    472:   my $qrystr = '';
1.70      www       473:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80      raeburn   474:   if ($previous > 0) {
                    475:       $qrystr = 'previous='.$previous;
                    476:       if ($feedurl =~ /\?register=1/) {
                    477:           $feedurl .= '&'.$qrystr;
                    478:       } else {
                    479:           $feedurl .= '?'.$qrystr;
                    480:       }
                    481:       $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
                    482:   }
1.6       albertel  483:   $r->print (<<ENDREDIR);
1.72      albertel  484: <html>
1.3       www       485: <head>
                    486: <title>Feedback sent</title>
1.63      albertel  487: <meta http-equiv="pragma" content="no-cache" />
1.80      raeburn   488: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2       www       489: </head>
1.49      www       490: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63      albertel  491: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5       www       492: $typestyle
1.32      albertel  493: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63      albertel  494: <font color="red">$status</font>
1.49      www       495: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80      raeburn   496: $prevtag
1.49      www       497: </form>
1.2       www       498: </body>
                    499: </html>
                    500: ENDREDIR
                    501: }
1.6       albertel  502: 
                    503: sub no_redirect_back {
                    504:   my ($r,$feedurl) = @_;
                    505:   $r->print (<<ENDNOREDIR);
1.72      albertel  506: <html>
1.2       www       507: <head><title>Feedback not sent</title>
1.63      albertel  508: <meta http-equiv="pragma" content="no-cache" />
1.7       albertel  509: ENDNOREDIR
                    510: 
1.8       www       511:   if ($feedurl!~/^\/adm\/feedback/) { 
1.7       albertel  512:     $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
                    513:   }
                    514:   
1.8       www       515:   $r->print (<<ENDNOREDIRTWO);
1.2       www       516: </head>
1.49      www       517: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63      albertel  518: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8       www       519: <b>Sorry, no feedback possible on this resource  ...</b>
1.2       www       520: </body>
                    521: </html>
1.8       www       522: ENDNOREDIRTWO
1.2       www       523: }
1.6       albertel  524: 
                    525: sub screen_header {
1.65      www       526:     my ($feedurl) = @_;
                    527:     my $msgoptions='';
                    528:     my $discussoptions='';
                    529:     unless ($ENV{'form.replydisc'}) {
                    530: 	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
                    531: 	    $msgoptions= 
                    532: 		'<p><input type="checkbox" name="author" /> '.
                    533: 		&mt('Feedback to resource author').'</p>';
                    534: 	}
                    535: 	if (&feedback_available(1)) {
                    536: 	    $msgoptions.=
                    537: 		'<br /><input type="checkbox" name="question" /> '.
                    538: 		&mt('Question about resource content');
                    539: 	}
                    540: 	if (&feedback_available(0,1)) {
                    541: 	    $msgoptions.=
                    542: 		'<br /><input type="checkbox" name="course" /> '.
                    543: 		&mt('Question/Comment/Feedback about course content');
                    544: 	}
                    545: 	if (&feedback_available(0,0,1)) {
                    546: 	    $msgoptions.=
                    547: 		'<br /><input type="checkbox" name="policy" /> '.
                    548: 		&mt('Question/Comment/Feedback about course policy');
                    549: 	}
                    550:     }
                    551:     if ($ENV{'request.course.id'}) {
                    552: 	if (&Apache::lonnet::allowed('pch',
                    553: 				     $ENV{'request.course.id'}.
                    554: 				     ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74      www       555: 	    $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
                    556: 		($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65      www       557: 		&mt('Contribution to course discussion of resource');
                    558: 	    $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
                    559: 		&mt('Anonymous contribution to course discussion of resource').
                    560: 		' <i>('.&mt('name only visible to course faculty').')</i>';
1.20      www       561:       }
1.65      www       562:     }
1.74      www       563:     if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65      www       564:     if ($discussoptions) { 
1.74      www       565: 	$discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65      www       566:     return $msgoptions.$discussoptions;
1.6       albertel  567: }
                    568: 
                    569: sub resource_output {
                    570:   my ($feedurl) = @_;
1.46      albertel  571:   my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6       albertel  572:   $usersaw=~s/\<body[^\>]*\>//gi;
                    573:   $usersaw=~s/\<\/body\>//gi;
                    574:   $usersaw=~s/\<html\>//gi;
                    575:   $usersaw=~s/\<\/html\>//gi;
                    576:   $usersaw=~s/\<head\>//gi;
                    577:   $usersaw=~s/\<\/head\>//gi;
                    578:   $usersaw=~s/action\s*\=/would_be_action\=/gi;
                    579:   return $usersaw;
                    580: }
                    581: 
                    582: sub clear_out_html {
1.39      www       583:   my ($message,$override)=@_;
1.37      albertel  584:   my $cid=$ENV{'request.course.id'};
1.39      www       585:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
                    586:       ($override)) {
1.37      albertel  587:       # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> 
                    588:       # <BLOCKQUOTE> <DIV .*> <DIV> <IMG>
                    589:       my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
1.61      www       590: 		BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
                    591:                 M=>1);
1.37      albertel  592: 
                    593:       $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48      albertel  594: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
1.37      albertel  595:       $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48      albertel  596: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
1.37      albertel  597:   } else {
                    598:       $message=~s/\</\&lt\;/g;
                    599:       $message=~s/\>/\&gt\;/g;
                    600:   }
1.6       albertel  601:   return $message;
                    602: }
                    603: 
                    604: sub assemble_email {
1.40      albertel  605:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6       albertel  606:   my $email=<<"ENDEMAIL";
                    607: Refers to <a href="$feedurl">$feedurl</a>
                    608: 
                    609: $message
                    610: ENDEMAIL
                    611:     my $citations=<<"ENDCITE";
                    612: <h2>Previous attempts of student (if applicable)</h2>
                    613: $prevattempts
1.63      albertel  614: <br /><hr />
1.6       albertel  615: <h2>Original screen output (if applicable)</h2>
                    616: $usersaw
1.40      albertel  617: <h2>Correct Answer(s) (if applicable)</h2>
                    618: $useranswer
1.6       albertel  619: ENDCITE
                    620:   return ($email,$citations);
                    621: }
                    622: 
1.35      www       623: sub secapply {
                    624:     my $rec=shift;
1.36      www       625:     my $defaultflag=shift;
                    626:     $rec=~s/\s+//g;
                    627:     $rec=~s/\@/\:/g;
                    628:     my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
                    629:     if ($sections) {
                    630: 	foreach (split(/\;/,$sections)) {
                    631:             if (($_ eq $ENV{'request.course.sec'}) ||
                    632:                 ($defaultflag && ($_ eq '*'))) {
                    633:                 return $adr; 
                    634:             }
                    635:         }
                    636:     } else {
                    637:        return $rec;
                    638:     }
                    639:     return '';
1.35      www       640: }
                    641: 
1.6       albertel  642: sub decide_receiver {
1.36      www       643:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6       albertel  644:   my $typestyle='';
                    645:   my %to=();
1.36      www       646:   if ($ENV{'form.author'}||$author) {
1.8       www       647:     $typestyle.='Submitting as Author Feedback<br>';
1.6       albertel  648:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
                    649:     $to{$2.':'.$1}=1;
                    650:   }
1.36      www       651:   if ($ENV{'form.question'}||$question) {
1.8       www       652:     $typestyle.='Submitting as Question<br>';
1.24      harris41  653:     foreach (split(/\,/,
                    654: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
                    655: 	     ) {
1.36      www       656: 	my $rec=&secapply($_,$defaultflag);
                    657:         if ($rec) { $to{$rec}=1; }
1.24      harris41  658:     } 
1.6       albertel  659:   }
1.36      www       660:   if ($ENV{'form.course'}||$course) {
1.63      albertel  661:     $typestyle.='Submitting as Comment<br />';
1.24      harris41  662:     foreach (split(/\,/,
                    663: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
                    664: 	     ) {
1.36      www       665: 	my $rec=&secapply($_,$defaultflag);
                    666:         if ($rec) { $to{$rec}=1; }
1.24      harris41  667:     } 
1.6       albertel  668:   }
1.36      www       669:   if ($ENV{'form.policy'}||$policy) {
1.63      albertel  670:     $typestyle.='Submitting as Policy Feedback<br />';
1.24      harris41  671:     foreach (split(/\,/,
                    672: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
                    673: 	     ) {
1.36      www       674: 	my $rec=&secapply($_,$defaultflag);
                    675:         if ($rec) { $to{$rec}=1; }
1.24      harris41  676:     } 
1.6       albertel  677:   }
1.36      www       678:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
                    679:      ($typestyle,%to)=
                    680: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
                    681:   }
1.6       albertel  682:   return ($typestyle,%to);
1.36      www       683: }
                    684: 
                    685: sub feedback_available {
                    686:     my ($question,$course,$policy)=@_;
                    687:     my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
                    688:     return scalar(%to);
1.6       albertel  689: }
                    690: 
                    691: sub send_msg {
1.43      www       692:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6       albertel  693:   my $status='';
                    694:   my $sendsomething=0;
1.24      harris41  695:   foreach (keys %to) {
1.6       albertel  696:     if ($_) {
1.22      www       697:       my $declutter=&Apache::lonnet::declutter($feedurl);
1.8       www       698:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43      www       699:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
                    700:                 $attachmenturl)=~/ok/) {
1.63      albertel  701: 	$status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6       albertel  702:       } else {
                    703: 	$sendsomething++;
                    704:       }
                    705:     }
1.24      harris41  706:   }
1.18      www       707: 
                    708:     my %record=&Apache::lonnet::restore('_feedback');
                    709:     my ($temp)=keys %record;
                    710:     unless ($temp=~/^error\:/) {
                    711:        my %newrecord=();
                    712:        $newrecord{'resource'}=$feedurl;
                    713:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
                    714:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63      albertel  715: 	   $status.='<br />'.&mt('Not registered').'<br />';
1.18      www       716:        }
                    717:     }
                    718:        
1.6       albertel  719:   return ($status,$sendsomething);
                    720: }
                    721: 
1.13      www       722: sub adddiscuss {
1.78      raeburn   723:     my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13      www       724:     my $status='';
1.23      www       725:     if (&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
                    726:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20      www       727: 
1.13      www       728:     my %contrib=('message'      => $email,
                    729:                  'sendername'   => $ENV{'user.name'},
1.26      www       730:                  'senderdomain' => $ENV{'user.domain'},
                    731:                  'screenname'   => $ENV{'environment.screenname'},
                    732:                  'plainname'    => $ENV{'environment.firstname'}.' '.
                    733: 		                   $ENV{'environment.middlename'}.' '.
                    734:                                    $ENV{'environment.lastname'}.' '.
1.42      www       735:                                    $ENV{'enrironment.generation'},
1.78      raeburn   736:                  'attachmenturl'=> $attachmenturl,
                    737:                  'subject'      => $subject);
1.65      www       738:     if ($ENV{'form.replydisc'}) {
1.66      www       739: 	$contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65      www       740:     }
1.14      www       741:     if ($anon) {
                    742: 	$contrib{'anonymous'}='true';
                    743:     }
1.13      www       744:     if (($symb) && ($email)) {
1.14      www       745:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13      www       746:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
                    747:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17      www       748: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.21      www       749:         my %storenewentry=($symb => time);
1.63      albertel  750:         $status.='<br />'.&mt('Updating discussion time').': '.
1.21      www       751:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
                    752:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    753: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13      www       754:     }
1.17      www       755:     my %record=&Apache::lonnet::restore('_discussion');
                    756:     my ($temp)=keys %record;
                    757:     unless ($temp=~/^error\:/) {
                    758:        my %newrecord=();
                    759:        $newrecord{'resource'}=$symb;
                    760:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63      albertel  761:        $status.='<br />'.&mt('Registering').': '.
1.21      www       762:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20      www       763:     }
                    764:     } else {
                    765: 	$status.='Failed.';
1.17      www       766:     }
1.63      albertel  767:     return $status.'<br />';   
1.13      www       768: }
                    769: 
1.33      www       770: # ----------------------------------------------------------- Preview function
                    771: 
                    772: sub show_preview {
                    773:     my $r=shift;
                    774:     my $message=&clear_out_html($ENV{'form.comment'});
                    775:     $message=~s/\n/\<br \/\>/g;
                    776:     $message=&Apache::lontexconvert::msgtexconverted($message);
1.78      raeburn   777:     my $subject=&clear_out_html($ENV{'form.subject'});
                    778:     $subject=~s/\n/\<br \/\>/g;
                    779:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33      www       780:     $r->print('<table border="2"><tr><td>'.
1.78      raeburn   781:        '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33      www       782:        $message.'</td></tr></table>');
                    783: }
                    784: 
                    785: sub generate_preview_button {
1.65      www       786:     my $pre=&mt("Show Preview");
1.33      www       787:     return(<<ENDPREVIEW);
                    788: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78      raeburn   789: <input type="hidden" name="subject">
1.33      www       790: <input type="hidden" name="comment" />
1.65      www       791: <input type="button" value="$pre"
1.78      raeburn   792: onClick="this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
1.33      www       793: </form>
                    794: ENDPREVIEW
                    795: }
1.71      www       796: 
1.6       albertel  797: sub handler {
                    798:   my $r = shift;
1.8       www       799:   if ($r->header_only) {
1.71      www       800:      &Apache::loncommon::content_type($r,'text/html');
1.8       www       801:      $r->send_http_header;
                    802:      return OK;
                    803:   }
1.15      www       804: 
                    805: # --------------------------- Get query string for limited number of parameters
                    806: 
1.27      stredwic  807:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.80      raeburn   808:          ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous']);
1.15      www       809: 
1.80      raeburn   810:   if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
                    811: # ----------------------------------------------------------------- Modify display setting for this discussion 
1.78      raeburn   812:       &Apache::loncommon::content_type($r,'text/html');
                    813:       $r->send_http_header;
1.80      raeburn   814:       my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
1.78      raeburn   815:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.80      raeburn   816:       my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1.78      raeburn   817:                           $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    818:                           $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    819:       my %readinghash = ();
                    820:                                                                                  
                    821:       if ($contrib{'version'}) {
                    822:           if ($ENV{'form.allposts'}) {
1.80      raeburn   823:               $readinghash{$symb.'_showonlyunread'} = 0;
1.78      raeburn   824:           } elsif ($ENV{'form.onlyunread'}) {
1.80      raeburn   825:               $readinghash{$symb.'_showonlyunread'} = 1;
1.78      raeburn   826:           }
1.80      raeburn   827:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'});
1.78      raeburn   828:       }
1.80      raeburn   829:       &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0','',$ENV{'form.previous'});
1.78      raeburn   830:       return OK;
                    831:   } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15      www       832: # ----------------------------------------------------------------- Hide/unhide
1.71      www       833:     &Apache::loncommon::content_type($r,'text/html');
1.15      www       834:     $r->send_http_header;
                    835: 
                    836:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
                    837: 
                    838:     my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52      www       839:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15      www       840: 
                    841:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    842:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    843: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    844: 
                    845:         
                    846:     my $currenthidden=$contrib{'hidden'};
                    847:     
                    848:     if ($ENV{'form.hide'}) {
                    849: 	$currenthidden.='.'.$idx.'.';
                    850:     } else {
                    851:         $currenthidden=~s/\.$idx\.//g;
                    852:     }
                    853:     my %newhash=('hidden' => $currenthidden);
1.38      www       854: 
                    855:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                    856:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    857: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    858: 
                    859:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn   860:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69      www       861:   } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72      albertel  862:       &Apache::loncommon::content_type($r,'text/html');
                    863:       $r->send_http_header;
1.69      www       864:       if ($ENV{'form.threadedon'}) {
                    865: 	  &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
                    866: 	  &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
                    867:       } else {
                    868:  	  &Apache::lonnet::del('environment',['threadeddiscussion']);
                    869: 	  &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72      albertel  870:       }
1.69      www       871:       my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
                    872:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                    873:       &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn   874: 		     &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38      www       875:   } elsif ($ENV{'form.deldisc'}) {
                    876: # --------------------------------------------------------------- Hide for good
1.71      www       877:     &Apache::loncommon::content_type($r,'text/html');
1.38      www       878:     $r->send_http_header;
                    879: 
                    880:     my $entry=$ENV{'form.deldisc'};
                    881: 
                    882:     my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52      www       883:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38      www       884: 
                    885:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    886:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    887: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    888: 
                    889:         
                    890:     my $currentdeleted=$contrib{'deleted'};
                    891:     
                    892:     $currentdeleted.='.'.$idx.'.';
                    893: 
                    894:     my %newhash=('deleted' => $currentdeleted);
1.15      www       895: 
                    896:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                    897:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    898: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    899: 
1.30      www       900:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn   901:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33      www       902:   } elsif ($ENV{'form.preview'}) {
                    903: # -------------------------------------------------------- User wants a preview
1.76      albertel  904:       $r->content_type('text/html');
                    905:       $r->send_http_header;
1.33      www       906:       &show_preview($r);
1.15      www       907:   } else {
                    908: # ------------------------------------------------------------- Normal feedback
1.6       albertel  909:   my $feedurl=$ENV{'form.postdata'};
                    910:   $feedurl=~s/^http\:\/\///;
                    911:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                    912:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62      www       913:   $feedurl=~s/\?.+$//;
1.8       www       914: 
1.66      www       915:   my $symb;
                    916:   if ($ENV{'form.replydisc'}) {
                    917:       $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
                    918:       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
                    919:       $feedurl=&Apache::lonnet::clutter($url);
                    920:   } else {
                    921:       $symb=&Apache::lonnet::symbread($feedurl);
                    922:   }
1.31      www       923:   unless ($symb) {
                    924:       $symb=$ENV{'form.symb'};
                    925:       if ($symb) {
1.52      www       926: 	  my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31      www       927:           $feedurl=&Apache::lonnet::clutter($url);
                    928:       }
                    929:   }
1.8       www       930:   my $goahead=1;
                    931:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    932:       unless ($symb) { $goahead=0; }
                    933:   }
1.74      www       934:   # backward compatibility (bulltin boards used to be 'wrapped')
1.73      albertel  935:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                    936:       $feedurl=~s|^/adm/wrapper||;
                    937:   }
1.8       www       938:   if ($goahead) {
                    939: # Go ahead with feedback, no ambiguous reference
1.71      www       940:     &Apache::loncommon::content_type($r,'text/html');
1.8       www       941:     $r->send_http_header;
1.6       albertel  942:   
1.8       www       943:     if (
1.7       albertel  944:       (
                    945:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
                    946:       ) 
                    947:       || 
                    948:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31      www       949:       ||
                    950:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7       albertel  951:      ) {
1.6       albertel  952: # --------------------------------------------------- Print login screen header
                    953:     unless ($ENV{'form.sendit'}) {
                    954:       my $options=&screen_header($feedurl);
                    955:       if ($options) {
                    956: 	&mail_screen($r,$feedurl,$options);
                    957:       } else {
                    958: 	&fail_redirect($r,$feedurl);
                    959:       }
                    960:     } else {
                    961:       
                    962: # Get previous user input
1.9       albertel  963:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11      albertel  964:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9       albertel  965:             $ENV{'request.course.id'});
1.6       albertel  966: 
                    967: # Get output from resource
                    968:       my $usersaw=&resource_output($feedurl);
                    969: 
1.50      albertel  970: # Get resource answer (need to allow student to view grades for this to work)
                    971:       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40      albertel  972:       my $useranswer=&Apache::loncommon::get_student_answers(
                    973:                        $symb,$ENV{'user.name'},$ENV{'user.domain'},
                    974: 		       $ENV{'request.course.id'});
1.50      albertel  975:       &Apache::lonnet::delenv('allowed.vgr');
1.42      www       976: # Get attachments, if any, and not too large
                    977:       my $attachmenturl='';
                    978:       if ($ENV{'form.attachment.filename'}) {
                    979: 	  unless (length($ENV{'form.attachment'})>131072) {
1.82    ! albertel  980: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42      www       981: 	  }
                    982:       }
1.6       albertel  983: # Filter HTML out of message (could be nasty)
1.39      www       984:       my $message=&clear_out_html($ENV{'form.comment'});
1.6       albertel  985: 
                    986: # Assemble email
1.8       www       987:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40      albertel  988:           $usersaw,$useranswer);
                    989:  
1.6       albertel  990: # Who gets this?
                    991:       my ($typestyle,%to) = &decide_receiver($feedurl);
                    992: 
                    993: # Actually send mail
1.43      www       994:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
                    995:           $attachmenturl,%to);
1.13      www       996: 
                    997: # Discussion? Store that.
                    998: 
1.32      albertel  999:       my $numpost=0;
1.13      www      1000:       if ($ENV{'form.discuss'}) {
1.78      raeburn  1001:           my $subject = &clear_out_html($ENV{'form.subject'});
                   1002: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32      albertel 1003: 	  $numpost++;
1.13      www      1004:       }
1.6       albertel 1005: 
1.14      www      1006:       if ($ENV{'form.anondiscuss'}) {
1.78      raeburn  1007:           my $subject = &clear_out_html($ENV{'form.subject'});
                   1008: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32      albertel 1009: 	  $numpost++;
1.14      www      1010:       }
                   1011: 
                   1012: 
1.6       albertel 1013: # Receipt screen and redirect back to where came from
1.80      raeburn  1014:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6       albertel 1015: 
                   1016:     }
1.8       www      1017:    } else {
1.7       albertel 1018: # Unable to give feedback
1.6       albertel 1019:     &no_redirect_back($r,$feedurl);
1.8       www      1020:    }
                   1021:   } else {
                   1022: # Ambiguous Problem Resource
1.60      albertel 1023:       if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53      albertel 1024: 	  &Apache::lonnet::cleanenv();
1.58      albertel 1025:       }
1.53      albertel 1026:       $r->internal_redirect('/adm/ambiguous');
1.6       albertel 1027:   }
1.15      www      1028: }
1.6       albertel 1029:   return OK;
1.1       www      1030: } 
                   1031: 
                   1032: 1;
                   1033: __END__

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