File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.96: download - view: text, annotated - select for diffs
Mon Jun 28 16:41:08 2004 UTC (19 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- saving some notes

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

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