File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.94: download - view: text, annotated - select for diffs
Sat Jun 12 01:07:10 2004 UTC (19 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #3082: submission of feedback in non-htmlarea mode

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

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