File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.91: download - view: text, annotated - select for diffs
Fri Jun 4 18:58:32 2004 UTC (20 years ago) by matthew
Branches: MAIN
CVS tags: HEAD
Misspelled subroutine names are annoying.

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

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