File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.89: download - view: text, annotated - select for diffs
Thu Jun 3 20:06:15 2004 UTC (20 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- discussend parameter now added, closes and hides discussion
    -BUGS#86,2862,and some of 2636

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

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