File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.99.2.7: download - view: text, annotated - select for diffs
Wed Sep 15 20:29:37 2004 UTC (19 years, 8 months ago) by albertel
Branches: version_1_2_X
Diff to branchpoint 1.99: preferred, unified
- backport 1.126

    1: # The LearningOnline Network
    2: # Feedback
    3: #
    4: # $Id: lonfeedback.pm,v 1.99.2.7 2004/09/15 20:29:37 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:     if ($ENV{'environment.discdisplay'} eq 'unread') {
  119:         $showonlyunread = 1;
  120:     }
  121:     if ($ENV{'environment.discmarkread'} eq 'ondisp') {
  122:         $markondisp = 1;
  123:     }
  124: 
  125: # Override user's default if user specified display setting for this discussion
  126:     if (defined($dischash{$ondispkey})) {
  127: 	unless ($dischash{$showkey} eq '') {
  128: 	    $markondisp = $dischash{$ondispkey};
  129: 	}
  130:     }
  131:     if ($markondisp) {
  132:         $discinfo{$lastkey} = time;
  133:     }
  134: 
  135:     if (defined($dischash{$showkey})) {
  136: 	unless ($dischash{$showkey} eq '') {
  137: 	    $showonlyunread = $dischash{$showkey};
  138: 	}
  139:     }
  140: 
  141:     if (defined($dischash{$visitkey})) {
  142: 	unless ($dischash{$showkey} eq '') {
  143: 	    $visit = $dischash{$visitkey};
  144: 	}
  145:     }
  146:     $visit ++;
  147: 
  148:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
  149:     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
  150: 	&& ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
  151:     my @discussionitems=();
  152:     my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
  153: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  154: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  155:     my $visible=0;
  156:     my @depth=();
  157:     my @original=();
  158:     my @index=();
  159:     my @replies=();
  160:     my %alldiscussion=();
  161:     my %notshown = ();
  162:     my %newitem = ();
  163:     my $maxdepth=0;
  164: 
  165:     my $target='';
  166:     unless ($ENV{'browser.interface'} eq 'textual' ||
  167: 	    $ENV{'environment.remote'} eq 'off' ) {
  168: 	$target='target="LONcom"';
  169:     }
  170:     
  171:     my $now = time;
  172:     $discinfo{$visitkey} = $visit;
  173: 
  174:     &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
  175: 
  176:     if ($contrib{'version'}) {
  177:         my $oldest = $contrib{'1:timestamp'};
  178:         if ($prevread eq '0') {
  179:             $prevread = $oldest-1;
  180:         }
  181: 	for (my $id=1;$id<=$contrib{'version'};$id++) {
  182: 	    my $idx=$id;
  183:             my $posttime = $contrib{$idx.':timestamp'};
  184:             if ($prevread <= $posttime) {
  185:                 $newpostsflag = 1;
  186:             }
  187: 	    my $hidden=($contrib{'hidden'}=~/\.$idx\./);
  188: 	    my $deleted=($contrib{'deleted'}=~/\.$idx\./);
  189: 	    my $origindex='0.';
  190: 	    if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) {
  191: # this is a follow-up message
  192: 		$original[$idx]=$original[$contrib{$idx.':replyto'}];
  193: 		$depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
  194: 		$origindex=$index[$contrib{$idx.':replyto'}];
  195: 		if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
  196: 	    } else {
  197: # this is an original message
  198: 		$original[$idx]=0;
  199: 		$depth[$idx]=0;
  200: 	    }
  201: 	    if ($replies[$depth[$idx]]) {
  202: 		$replies[$depth[$idx]]++;
  203: 	    } else {
  204: 		$replies[$depth[$idx]]=1;
  205: 	    }
  206: 	    unless ((($hidden) && (!$seeid)) || ($deleted)) {
  207: 		$visible++;
  208: 		my $message=$contrib{$idx.':message'};
  209: 		$message=~s/\n/\<br \/\>/g;
  210: 		$message=&Apache::lontexconvert::msgtexconverted($message);
  211:                 my $subject=$contrib{$idx.':subject'};
  212:                 if (defined($subject)) {
  213:                     $subject=~s/\n/\<br \/\>/g;
  214:                     $subject=&Apache::lontexconvert::msgtexconverted($subject);
  215:                 }
  216: 		if ($contrib{$idx.':attachmenturl'}) {
  217: 		    my ($fname)
  218:                         =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
  219: 		    &Apache::lonnet::allowuploaded('/adm/feedback',
  220: 					   $contrib{$idx.':attachmenturl'});
  221: 		    $message.='<p>'.&mt('Attachment').
  222: 			': <a href="'.$contrib{$idx.':attachmenturl'}.'"><tt>'.
  223: 			$fname.'</tt></a></p>';
  224: 		}
  225: 		if ($message) {
  226: 		    if ($hidden) {
  227: 			$message='<font color="#888888">'.$message.'</font>';
  228: 		    }
  229: #		    my $screenname=&Apache::loncommon::screenname(
  230: #					    $contrib{$idx.':sendername'},
  231: #					    $contrib{$idx.':senderdomain'});
  232: #		    my $plainname=&Apache::loncommon::nickname(
  233: #					    $contrib{$idx.':sendername'},
  234: #					    $contrib{$idx.':senderdomain'});
  235: 		    ($$screenname,$$plainname)=($$contrib{$idx.':screenname'},
  236: 						$$contrib{$idx.':plainname'});
  237: 		    my $sender=&mt('Anonymous');
  238: 		    if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
  239: 			$sender=&Apache::loncommon::aboutmewrapper(
  240: 					 $plainname,
  241: 					 $contrib{$idx.':sendername'},
  242: 					 $contrib{$idx.':senderdomain'}).' ('.
  243: 					 $contrib{$idx.':sendername'}.' at '.
  244: 					 $contrib{$idx.':senderdomain'}.')';
  245: 			if ($contrib{$idx.':anonymous'}) {
  246: 			    $sender.=' ['.&mt('anonymous').'] '.
  247: 				$screenname;
  248: 			}
  249: 			if ($seeid) {
  250: 			    if ($hidden) {
  251: 				$sender.=' <a href="/adm/feedback?unhide='.
  252: 				    $ressymb.':::'.$idx;
  253:                                 if ($newpostsflag) {
  254:                                     $sender .= '&previous='.$prevread;
  255:                                 }
  256:                                 $sender .= '">'.&mt('Make Visible').'</a>';
  257: 			    } else {
  258: 				$sender.=' <a href="/adm/feedback?hide='.
  259: 				    $ressymb.':::'.$idx;
  260:                                 if ($newpostsflag) {
  261:                                     $sender .= '&previous='.$prevread;
  262:                                 }
  263:                                 $sender .= '">'.&mt('Hide').'</a>';
  264: 			    }                     
  265: 			    $sender.=' <a href="/adm/feedback?deldisc='.
  266: 				$ressymb.':::'.$idx;
  267:                                 if ($newpostsflag) {
  268:                                     $sender .= '&previous='.$prevread;
  269:                                 }
  270:                                 $sender .= '">'.&mt('Delete').'</a>';
  271: 			}
  272: 		    } else {
  273: 			if ($screenname) {
  274: 			    $sender='<i>'.$screenname.'</i>';
  275: 			}
  276: 		    }
  277: 		    if (&discussion_open($status) &&
  278: 			&Apache::lonnet::allowed('pch',
  279: 						 $ENV{'request.course.id'}.
  280: 						 ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  281: 			$sender.=' <a href="/adm/feedback?replydisc='.
  282: 			    $ressymb.':::'.$idx;
  283:                         if ($newpostsflag) {
  284:                             $sender .= '&previous='.$prevread;
  285:                         }
  286:                         $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
  287: 		    }
  288: 		    my $vgrlink;
  289: 		    if ($viewgrades) {
  290: 			$vgrlink=&Apache::loncommon::submlink('Submissions',
  291:             $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
  292: 		    }
  293: #figure out at what position this needs to print
  294: 		    my $thisindex=$idx;
  295: 		    if ($ENV{'environment.threadeddiscussion'}) {
  296: 			$thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);	
  297: 		    }
  298: 		    $alldiscussion{$thisindex}=$idx;
  299: 		    $index[$idx]=$thisindex;
  300:                     my $spansize = 2;
  301:                     if ($showonlyunread && $prevread > $posttime) {
  302:                         $notshown{$idx} = 1;
  303:                     } else {
  304:                         if ($prevread > 0 && $prevread <= $posttime) {
  305:                             $newitem{$idx} = 1;
  306:                             $discussionitems[$idx] .= '
  307:                              <p><table border="0" width="100%">
  308:                               <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
  309:                         } else {
  310:                             $newitem{$idx} = 0;
  311:                             $discussionitems[$idx] .= '
  312:                              <p><table border="0" width="100%">
  313:                               <tr><td align="left">&nbsp;</td>';
  314:                         }
  315:                         $discussionitems[$idx] .= '<td align ="left">&nbsp;&nbsp;'.
  316:                             '<b>'.$subject.'</b>&nbsp;&nbsp;'.
  317:                             $sender.'</b> '.$vgrlink.' ('.
  318:                             localtime($posttime).')</td></tr>'.
  319:                             '</table><blockquote>'.$message.'</blockquote></p>';
  320:                     }
  321:                 }
  322:             }
  323: 	}
  324:     }
  325: 
  326:     my $discussion='';
  327: 
  328:     my $function = &Apache::loncommon::get_users_function();
  329:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
  330:                                                     $ENV{'user.domain'});
  331:     my %lt = &Apache::lonlocal::texthash(
  332:         'cuse' => 'Current discussion settings',
  333:         'allposts' => 'All posts',
  334:         'unread' => 'New posts only',
  335:         'ondisp' => 'Once displayed',
  336:         'onmark' => 'Once marked read',
  337:         'disa' => 'Posts to be displayed',
  338:         'npce' => 'Posts cease to be marked "NEW"',
  339:         'chgt' => 'Change',
  340:         'disp' => 'Display',
  341:         'nolo' => 'Not new',
  342:     );
  343: 
  344:     my $currdisp = $lt{'allposts'};
  345:     my $currmark = $lt{'onmark'};
  346:     my $dispchange = $lt{'unread'};
  347:     my $markchange = $lt{'ondisp'};
  348:     my $chglink = '/adm/feedback?modifydisp='.$ressymb;
  349:     my $displink = 'onlyunread';
  350:     my $marklink = 'markondisp';
  351: 
  352:     if ($markondisp) {
  353:         $currmark = $lt{'ondisp'};
  354:         $markchange = $lt{'onmark'};
  355:         $marklink = 'markonread';
  356:     }
  357: 
  358:     if ($showonlyunread) {
  359:         $currdisp = $lt{'unread'};
  360:         $dispchange = $lt{'allposts'};
  361:         $displink = 'allposts';
  362:     }
  363:    
  364:     $chglink .= '&changes='.$displink.'_'.$marklink;
  365: 
  366:     if ($newpostsflag) {
  367:         $chglink .= '&previous='.$prevread;
  368:     }
  369: 
  370:     if ($visible) {
  371: # Print the discusssion
  372: 	if ($outputtarget ne 'tex') {
  373:             my $colspan=$maxdepth+1;
  374: 	    $discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
  375: 	    $discussion .='<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:             my $colspan=$maxdepth+1;
  460:             $discussion .= <<END; 
  461:             <tr bgcolor="#FFFFFF">
  462:              <td colspan="$colspan" valign="top">
  463:               <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
  464:                <tr>
  465:                 <td align="left">
  466:                  <table border="0" cellpadding="0" cellspacing="4">
  467:                   <tr>
  468:                    <td>
  469:                     <font size="-1"><b>$lt{'cuse'}</b>:</td>
  470:                    <td>&nbsp;</td>
  471: END
  472:             if ($newpostsflag) {
  473:                 $discussion .= 
  474:                    '<td><font size="-1">1.&nbsp;'.$lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i>&nbsp;&nbsp;2.&nbsp;'.$lt{'nolo'}.'&nbsp;-&nbsp;<i>'.$currmark.'</i></font></td>';
  475:             } else {
  476:                 $discussion .=
  477:                    '<td><font size="-1">'.$lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i></font></td>';
  478:             }
  479:             $discussion .= <<END;
  480:                    <td>&nbsp;</td>
  481:                    <td>
  482:                     <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b></td>
  483:                   </tr>
  484:                  </table>
  485:                 </td>
  486:                </tr>
  487:               </table>
  488:              </td>
  489:             </tr>
  490:            </table>
  491:            <br /><br />
  492: END
  493: 	}
  494:     }
  495:     if ($discussiononly) {
  496: 	$discussion.=(<<ENDDISCUSS);
  497: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
  498: <input type="submit" name="discuss" value="Post Discussion" />
  499: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
  500: <input type="hidden" name="symb" value="$ressymb" />
  501: <input type="hidden" name="sendit" value="true" />
  502: <br />
  503: <font size="1">Note: in anonymous discussion, your name is visible only to
  504: course faculty</font><br />
  505: <b>Title:</b>&nbsp;<input type="text" name="subject" value="" size="30" /><br /><br />
  506: <textarea name="comment" cols="80" rows="14" wrap="hard"></textarea>
  507: <p>
  508: Attachment (128 KB max size): <input type="file" name="attachment" />
  509: </p>
  510: </form>
  511: ENDDISCUSS
  512:         if ($outputtarget ne 'tex') {
  513: 	    $discussion.=&generate_preview_button();
  514: 	}
  515:     } else {
  516: 	if (&discussion_open($status) &&
  517: 	    &Apache::lonnet::allowed('pch',
  518: 				   $ENV{'request.course.id'}.
  519: 	($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  520: 	    if ($outputtarget ne 'tex') {
  521: 		$discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
  522: 		    $symb.':::" '.$target.'>'.
  523: 		    '<img src="/adm/lonMisc/chat.gif" border="0" />'.
  524: 		    &mt('Post Discussion').'</a></td></tr></table>';
  525: 	    }
  526: 			}
  527:     }
  528:    return $discussion;
  529: }
  530: 
  531: sub mail_screen {
  532:   my ($r,$feedurl,$options) = @_;
  533:   my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
  534:                                           '','onLoad="window.focus();"');
  535:   my $title=&Apache::lonnet::gettitle($feedurl);
  536:   if (!$title) { $title = $feedurl; }
  537:   my $quote='';
  538:   my $subject = '';
  539:   my $prevtag = '';
  540:   if ($ENV{'form.replydisc'}) {
  541:       my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
  542:       my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
  543: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  544: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  545:       unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
  546: 	  my $message=$contrib{$idx.':message'};
  547: 	  $message=~s/\n/\<br \/\>/g;
  548: 	  $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
  549:           if ($idx > 0) {
  550:               $subject = 'Re: '.$contrib{$idx.':subject'};
  551:           }
  552:       }
  553:       if ($ENV{'form.previous'}) {
  554:           $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
  555:       }
  556:   }
  557:   my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
  558:   my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
  559:   my $send=&mt('Send');
  560:   $r->print(<<ENDDOCUMENT);
  561: <html>
  562: <head>
  563: <title>The LearningOnline Network with CAPA</title>
  564: <meta http-equiv="pragma" content="no-cache"></meta>
  565: $htmlheader
  566: <script type="text/javascript">
  567: //<!--
  568:     function gosubmit() {
  569:         var rec=0;
  570:         if (typeof(document.mailform.elements.author)!="undefined") {
  571:           if (document.mailform.elements.author.checked) {
  572:              rec=1;
  573:           } 
  574:         }
  575:         if (typeof(document.mailform.elements.question)!="undefined") {
  576:           if (document.mailform.elements.question.checked) {
  577:              rec=1;
  578:           } 
  579:         }
  580:         if (typeof(document.mailform.elements.course)!="undefined") {
  581:           if (document.mailform.elements.course.checked) {
  582:              rec=1;
  583:           } 
  584:         }
  585:         if (typeof(document.mailform.elements.policy)!="undefined") {
  586:           if (document.mailform.elements.policy.checked) {
  587:              rec=1;
  588:           } 
  589:         }
  590:         if (typeof(document.mailform.elements.discuss)!="undefined") {
  591:           if (document.mailform.elements.discuss.checked) {
  592:              rec=1;
  593:           } 
  594:         }
  595:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
  596:           if (document.mailform.elements.anondiscuss.checked) {
  597:              rec=1;
  598:           } 
  599:         }
  600: 
  601:         if (rec) {
  602:             if (typeof(document.mailform.onsubmit)=='function') {
  603: 		document.mailform.onsubmit();
  604: 	    }
  605: 	    document.mailform.submit();
  606:         } else {
  607:             alert('Please check a feedback type.');
  608: 	}
  609:     }
  610: //-->
  611: </script>
  612: </head>
  613: $bodytag
  614: <h2><tt>$title</tt></h2>
  615: <form action="/adm/feedback" method="post" name="mailform"
  616: enctype="multipart/form-data">
  617: $prevtag
  618: <input type="hidden" name="postdata" value="$feedurl" />
  619: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
  620: Please check at least one of the following feedback types:
  621: $options<hr />
  622: $quote
  623: <p>My question/comment/feedback:</p>
  624: <p>
  625: $latexHelp
  626: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
  627: <p>
  628: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">
  629: </textarea></p>
  630: <p>
  631: Attachment (128 KB max size): <input type="file" name="attachment" />
  632: </p>
  633: <p>
  634: <input type="hidden" name="sendit" value="1" />
  635: <input type="button" value="$send" onClick='gosubmit();' />
  636: </p>
  637: </form>
  638: ENDDOCUMENT
  639: $r->print(&generate_preview_button().
  640: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
  641: '</body></html>');
  642: }
  643: 
  644: sub print_display_options {
  645:     my ($r,$symb,$previous,$dispchg,$markchg,$feedurl) = @_;
  646:  # backward compatibility (bulletin boards used to be 'wrapped')
  647:     if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
  648:         $feedurl=~s|^/adm/wrapper||;
  649:     }
  650: 
  651:     my $function = &Apache::loncommon::get_users_function();
  652:     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
  653:                                                     $ENV{'user.domain'});
  654:     my $bodytag=&Apache::loncommon::bodytag('Discussion options',
  655:                                           '','');
  656: 
  657:     my %lt = &Apache::lonlocal::texthash(
  658:         'dido' => 'Discussion display options',
  659:         'pref' => 'Display Preference',
  660:         'curr' => 'Current setting ',
  661:         'actn' => 'Action',
  662:         'deff' => 'Default for all discussions',
  663:         'prca' => 'Preferences can be set for this discussion that determine ....',
  664:         'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
  665:         'unwh' => 'Under what circumstances posts are identfied as "New."',
  666:         'allposts' => 'All posts',
  667:         'unread' => 'New posts only',
  668:         'ondisp' => 'Once displayed',
  669:         'onmark' => 'Once marked as read',
  670:         'disa' => 'Posts displayed?',
  671:         'npmr' => 'New posts cease to be identified as "New"?',
  672:         'chgt' => 'Change to ',
  673:         'mkdf' => 'Set to ',
  674:         'yhni' => 'You have not indicated that you wish to change either of the discussion settings',
  675:         'ywbr' => 'You will be returned to the previous page if you click OK.'
  676:     );
  677: 
  678:     my $dispchange = $lt{'unread'};
  679:     my $markchange = $lt{'ondisp'};
  680:     my $currdisp = $lt{'allposts'};
  681:     my $currmark = $lt{'onmark'};
  682:     my $discdisp = 'allposts';
  683:     my $discmark = 'onmark';
  684:                                                                                       
  685:     if ($dispchg eq 'allposts') {
  686:         $dispchange = $lt{'allposts'};
  687:         $currdisp = $lt{'unread'};
  688:         $discdisp = 'unread';
  689:     }
  690:                                                                                       
  691:     if ($markchg eq 'markonread') {
  692:         $markchange = $lt{'onmark'};
  693:         $currmark = $lt{'ondisp'};
  694:         $discmark = 'ondisp';
  695:     }
  696:     $r->print(<<END);
  697: <html>
  698: <head>
  699: <title>$lt{'dido'}</title>
  700: <meta http-equiv="pragma" content="no-cache" />
  701: <script>
  702: function setDisp() {
  703:     var prev = "$previous"
  704:     var chktotal = 0
  705:     if (document.modifydisp.discdisp.checked == true) {
  706:         document.modifydisp.$dispchg.value = "$symb"
  707:         chktotal ++
  708:     }
  709:     if (document.modifydisp.discmark.checked == true) {
  710:         document.modifydisp.$markchg.value = "$symb"
  711:         chktotal ++
  712:     }
  713:     if (chktotal > 0) { 
  714:         document.modifydisp.submit()
  715:     } else {
  716:         if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}"))      {
  717:             if (prev > 0) {
  718:                 location.href = "$feedurl?previous=$previous"
  719:             } else {
  720:                 location.href = "$feedurl"
  721:             }
  722:         }
  723:     }
  724: }
  725: </script>
  726: </head>
  727: $bodytag
  728: <form name="modifydisp" method="post" action="/adm/feedback">
  729: $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
  730: <br />
  731: <table border="0" cellpadding="0" cellspacing="0">
  732:  <tr>
  733:   <td width="100%" bgcolor="#000000">
  734:    <table width="100%" border="0" cellpadding="1" cellspacing="0">
  735:     <tr>
  736:      <td width="100%" bgcolor="#000000">
  737:       <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  738:        <tr bgcolor="$tabcolor">
  739:         <td><b>$lt{'pref'}</b></td>
  740:         <td><b>$lt{'curr'}</b></td>
  741:         <td><b>$lt{'actn'}?</b></td>
  742:        </tr>
  743:        <tr bgcolor="#dddddd">
  744:        <td>$lt{'disa'}</td>
  745:        <td>$lt{$discdisp}</td>
  746:        <td><input type="checkbox" name="discdisp" />&nbsp;$lt{'chgt'} "$dispchange"</td>
  747:       </tr><tr bgcolor="#eeeeee">
  748:        <td>$lt{'npmr'}</td>
  749:        <td>$lt{$discmark}</td>
  750:        <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
  751:       </tr>
  752:      </table>
  753:     </td>
  754:    </tr>
  755:   </table>
  756:  </td>
  757: </tr>
  758: </table>
  759: <br />
  760: <br />
  761: <input type="hidden" name="previous" value="$previous" />
  762: <input type="hidden" name="$dispchg" value=""/>
  763: <input type="hidden" name="$markchg" value=""/>
  764: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
  765: <br />
  766: <br />
  767: </form>
  768: </body>
  769: </html>
  770: END
  771:     return;
  772: }
  773: 
  774: sub fail_redirect {
  775:   my ($r,$feedurl) = @_;
  776:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
  777:   $r->print (<<ENDFAILREDIR);
  778: <html>
  779: <head><title>Feedback not sent</title>
  780: <meta http-equiv="pragma" content="no-cache" />
  781: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
  782: </head>
  783: <body bgcolor="#FFFFFF">
  784: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
  785: <b>Sorry, no recipients  ...</b>
  786: <br /><a href="$feedurl">Continue</a>
  787: </body>
  788: </html>
  789: ENDFAILREDIR
  790: }
  791: 
  792: sub redirect_back {
  793:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_;
  794:   my $prevtag = '';
  795:   my $qrystr = '';
  796:  # backward compatibility (bulletin boards used to be 'wrapped')
  797:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
  798:       $feedurl=~s|^/adm/wrapper||;
  799:   }
  800: 
  801:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
  802:   if ($previous > 0) {
  803:       $qrystr = 'previous='.$previous;
  804:       if ($feedurl =~ /\?register=1/) {
  805:           $feedurl .= '&'.$qrystr;
  806:       } else {
  807:           $feedurl .= '?'.$qrystr;
  808:       }
  809:       $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
  810:   }
  811:   $r->print (<<ENDREDIR);
  812: <html>
  813: <head>
  814: <title>Feedback sent</title>
  815: <meta http-equiv="pragma" content="no-cache" />
  816: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
  817: </head>
  818: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
  819: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
  820: $typestyle
  821: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
  822: <font color="red">$status</font>
  823: <form name="reldt" action="$feedurl" target="loncapaclient">
  824: $prevtag
  825: </form>
  826: <br /><a href="$feedurl">Continue</a>
  827: </body>
  828: </html>
  829: ENDREDIR
  830: }
  831: 
  832: sub no_redirect_back {
  833:   my ($r,$feedurl) = @_;
  834:   $r->print (<<ENDNOREDIR);
  835: <html>
  836: <head><title>Feedback not sent</title>
  837: <meta http-equiv="pragma" content="no-cache" />
  838: ENDNOREDIR
  839: 
  840:   if ($feedurl!~/^\/adm\/feedback/) { 
  841:     $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
  842:   }
  843:   
  844:   $r->print (<<ENDNOREDIRTWO);
  845: </head>
  846: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
  847: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
  848: <b>Sorry, no feedback possible on this resource  ...</b>
  849: <br /><a href="$feedurl">Continue</a>
  850: </body>
  851: </html>
  852: ENDNOREDIRTWO
  853: }
  854: 
  855: sub screen_header {
  856:     my ($feedurl) = @_;
  857:     my $msgoptions='';
  858:     my $discussoptions='';
  859:     unless ($ENV{'form.replydisc'}) {
  860: 	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
  861: 	    $msgoptions= 
  862: 		'<p><input type="checkbox" name="author" /> '.
  863: 		&mt('Feedback to resource author').'</p>';
  864: 	}
  865: 	if (&feedback_available(1)) {
  866: 	    $msgoptions.=
  867: 		'<br /><input type="checkbox" name="question" /> '.
  868: 		&mt('Question about resource content');
  869: 	}
  870: 	if (&feedback_available(0,1)) {
  871: 	    $msgoptions.=
  872: 		'<br /><input type="checkbox" name="course" /> '.
  873: 		&mt('Question/Comment/Feedback about course content');
  874: 	}
  875: 	if (&feedback_available(0,0,1)) {
  876: 	    $msgoptions.=
  877: 		'<br /><input type="checkbox" name="policy" /> '.
  878: 		&mt('Question/Comment/Feedback about course policy');
  879: 	}
  880:     }
  881:     if ($ENV{'request.course.id'}) {
  882: 	if (&discussion_open() &&
  883: 	    &Apache::lonnet::allowed('pch',
  884: 				     $ENV{'request.course.id'}.
  885: 				     ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  886: 	    $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
  887: 		($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
  888: 		&mt('Contribution to course discussion of resource');
  889: 	    $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
  890: 		&mt('Anonymous contribution to course discussion of resource').
  891: 		' <i>('.&mt('name only visible to course faculty').')</i>';
  892:       }
  893:     }
  894:     if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
  895:     if ($discussoptions) { 
  896: 	$discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
  897:     return $msgoptions.$discussoptions;
  898: }
  899: 
  900: sub resource_output {
  901:   my ($feedurl) = @_;
  902:   my $usersaw=&Apache::lonnet::ssi_body($feedurl);
  903:   $usersaw=~s/\<body[^\>]*\>//gi;
  904:   $usersaw=~s/\<\/body\>//gi;
  905:   $usersaw=~s/\<html\>//gi;
  906:   $usersaw=~s/\<\/html\>//gi;
  907:   $usersaw=~s/\<head\>//gi;
  908:   $usersaw=~s/\<\/head\>//gi;
  909:   $usersaw=~s/action\s*\=/would_be_action\=/gi;
  910:   return $usersaw;
  911: }
  912: 
  913: sub clear_out_html {
  914:   my ($message,$override)=@_;
  915:   unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
  916:   my $cid=$ENV{'request.course.id'};
  917:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
  918:       ($override)) {
  919:       # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> 
  920:       # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
  921:       # <SUP>
  922:       my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
  923: 		BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
  924:                 M=>1, SUB=>1, SUP=>1, SPAN=>1, 
  925: 		H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
  926: 
  927:       $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
  928: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
  929:       $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
  930: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
  931:   } else {
  932:       $message=~s/\</\&lt\;/g;
  933:       $message=~s/\>/\&gt\;/g;
  934:   }
  935:   return $message;
  936: }
  937: 
  938: sub assemble_email {
  939:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
  940:   my $email=<<"ENDEMAIL";
  941: Refers to <a href="$feedurl">$feedurl</a>
  942: 
  943: $message
  944: ENDEMAIL
  945:     my $citations=<<"ENDCITE";
  946: <h2>Previous attempts of student (if applicable)</h2>
  947: $prevattempts
  948: <br /><hr />
  949: <h2>Original screen output (if applicable)</h2>
  950: $usersaw
  951: <h2>Correct Answer(s) (if applicable)</h2>
  952: $useranswer
  953: ENDCITE
  954:   return ($email,$citations);
  955: }
  956: 
  957: sub secapply {
  958:     my $rec=shift;
  959:     my $defaultflag=shift;
  960:     $rec=~s/\s+//g;
  961:     $rec=~s/\@/\:/g;
  962:     my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
  963:     if ($sections) {
  964: 	foreach (split(/\;/,$sections)) {
  965:             if (($_ eq $ENV{'request.course.sec'}) ||
  966:                 ($defaultflag && ($_ eq '*'))) {
  967:                 return $adr; 
  968:             }
  969:         }
  970:     } else {
  971:        return $rec;
  972:     }
  973:     return '';
  974: }
  975: 
  976: sub decide_receiver {
  977:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
  978:   my $typestyle='';
  979:   my %to=();
  980:   if ($ENV{'form.author'}||$author) {
  981:     $typestyle.='Submitting as Author Feedback<br>';
  982:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
  983:     $to{$2.':'.$1}=1;
  984:   }
  985:   if ($ENV{'form.question'}||$question) {
  986:     $typestyle.='Submitting as Question<br>';
  987:     foreach (split(/\,/,
  988: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
  989: 	     ) {
  990: 	my $rec=&secapply($_,$defaultflag);
  991:         if ($rec) { $to{$rec}=1; }
  992:     } 
  993:   }
  994:   if ($ENV{'form.course'}||$course) {
  995:     $typestyle.='Submitting as Comment<br />';
  996:     foreach (split(/\,/,
  997: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
  998: 	     ) {
  999: 	my $rec=&secapply($_,$defaultflag);
 1000:         if ($rec) { $to{$rec}=1; }
 1001:     } 
 1002:   }
 1003:   if ($ENV{'form.policy'}||$policy) {
 1004:     $typestyle.='Submitting as Policy Feedback<br />';
 1005:     foreach (split(/\,/,
 1006: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
 1007: 	     ) {
 1008: 	my $rec=&secapply($_,$defaultflag);
 1009:         if ($rec) { $to{$rec}=1; }
 1010:     } 
 1011:   }
 1012:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
 1013:      ($typestyle,%to)=
 1014: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
 1015:   }
 1016:   return ($typestyle,%to);
 1017: }
 1018: 
 1019: sub feedback_available {
 1020:     my ($question,$course,$policy)=@_;
 1021:     my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
 1022:     return scalar(%to);
 1023: }
 1024: 
 1025: sub send_msg {
 1026:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
 1027:   my $status='';
 1028:   my $sendsomething=0;
 1029:   foreach (keys %to) {
 1030:     if ($_) {
 1031:       my $declutter=&Apache::lonnet::declutter($feedurl);
 1032:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
 1033:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
 1034:                 $attachmenturl)=~/ok/) {
 1035: 	$status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
 1036:       } else {
 1037: 	$sendsomething++;
 1038:       }
 1039:     }
 1040:   }
 1041: 
 1042:     my %record=&Apache::lonnet::restore('_feedback');
 1043:     my ($temp)=keys %record;
 1044:     unless ($temp=~/^error\:/) {
 1045:        my %newrecord=();
 1046:        $newrecord{'resource'}=$feedurl;
 1047:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
 1048:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
 1049: 	   $status.='<br />'.&mt('Not registered').'<br />';
 1050:        }
 1051:     }
 1052:        
 1053:   return ($status,$sendsomething);
 1054: }
 1055: 
 1056: sub adddiscuss {
 1057:     my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
 1058:     my $status='';
 1059:     if (&discussion_open() &&
 1060: 	&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
 1061:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
 1062: 
 1063:     my %contrib=('message'      => $email,
 1064:                  'sendername'   => $ENV{'user.name'},
 1065:                  'senderdomain' => $ENV{'user.domain'},
 1066:                  'screenname'   => $ENV{'environment.screenname'},
 1067:                  'plainname'    => $ENV{'environment.firstname'}.' '.
 1068: 		                   $ENV{'environment.middlename'}.' '.
 1069:                                    $ENV{'environment.lastname'}.' '.
 1070:                                    $ENV{'enrironment.generation'},
 1071:                  'attachmenturl'=> $attachmenturl,
 1072:                  'subject'      => $subject);
 1073:     if ($ENV{'form.replydisc'}) {
 1074: 	$contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
 1075:     }
 1076:     if ($anon) {
 1077: 	$contrib{'anonymous'}='true';
 1078:     }
 1079:     if (($symb) && ($email)) {
 1080:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
 1081:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
 1082:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1083: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1084:         my %storenewentry=($symb => time);
 1085:         $status.='<br />'.&mt('Updating discussion time').': '.
 1086:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
 1087:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1088: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1089:     }
 1090:     my %record=&Apache::lonnet::restore('_discussion');
 1091:     my ($temp)=keys %record;
 1092:     unless ($temp=~/^error\:/) {
 1093:        my %newrecord=();
 1094:        $newrecord{'resource'}=$symb;
 1095:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
 1096:        $status.='<br />'.&mt('Registering').': '.
 1097:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
 1098:     }
 1099:     } else {
 1100: 	$status.='Failed.';
 1101:     }
 1102:     return $status.'<br />';   
 1103: }
 1104: 
 1105: # ----------------------------------------------------------- Preview function
 1106: 
 1107: sub show_preview {
 1108:     my $r=shift;
 1109:     my $message=&clear_out_html($ENV{'form.comment'});
 1110:     $message=~s/\n/\<br \/\>/g;
 1111:     $message=&Apache::lontexconvert::msgtexconverted($message);
 1112:     my $subject=&clear_out_html($ENV{'form.subject'});
 1113:     $subject=~s/\n/\<br \/\>/g;
 1114:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
 1115:     $r->print('<table border="2"><tr><td>'.
 1116:        '<b>Subject:</b> '.$subject.'<br /><br />'.
 1117:        $message.'</td></tr></table>');
 1118: }
 1119: 
 1120: sub generate_preview_button {
 1121:     my $pre=&mt("Show Preview");
 1122:     return(<<ENDPREVIEW);
 1123: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
 1124: <input type="hidden" name="subject">
 1125: <input type="hidden" name="comment" />
 1126: <input type="button" value="$pre"
 1127: onClick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
 1128: </form>
 1129: ENDPREVIEW
 1130: }
 1131: 
 1132: sub handler {
 1133:   my $r = shift;
 1134:   if ($r->header_only) {
 1135:      &Apache::loncommon::content_type($r,'text/html');
 1136:      $r->send_http_header;
 1137:      return OK;
 1138:   }
 1139: 
 1140: # --------------------------- Get query string for limited number of parameters
 1141: 
 1142:   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1143:          ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes','navmaps','navurl']);
 1144:   if ($ENV{'form.navmaps'}) {
 1145:       my %discinfo = ();
 1146:       my @resources = ();
 1147:       if ($ENV{'form.navmaps'} =~ /:/) {
 1148:           @resources = split/:/,$ENV{'form.navmaps'};
 1149:       } else {
 1150:           @resources = ("$ENV{'form.navmaps'}");
 1151:       }
 1152:       my $numitems = @resources;
 1153:       my $feedurl = '/adm/navmaps';
 1154:       if ($ENV{'form.navurl'}) {
 1155:           $feedurl .= '?'.$ENV{'form.navurl'};
 1156:       }
 1157:       my %lt = &Apache::lonlocal::texthash(
 1158:           'mnpa' => 'Marked "New" posts as read in a total of',
 1159:           'robb' => 'resources/bulletin boards.'
 1160:       );       
 1161:       foreach (@resources) {
 1162: # backward compatibility (bulletin boards used to be 'wrapped')
 1163:           my $ressymb=$_;
 1164:           if ($ressymb =~ m/bulletin___\d+___/) {
 1165:               unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 1166:                   $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
 1167:               }
 1168:           }
 1169:           my $lastkey = $ressymb.'_lastread';
 1170:           $discinfo{$lastkey} = time;
 1171:       }
 1172:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 1173:       &Apache::loncommon::content_type($r,'text/html');
 1174:       $r->send_http_header;
 1175:       $r->print (<<ENDREDIR);
 1176: <html>
 1177: <head>
 1178: <title>New posts marked as read</title>
 1179: <meta http-equiv="pragma" content="no-cache" />
 1180: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
 1181: </head>
 1182: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
 1183: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
 1184: <b>$lt{'mnpa'} $numitems $lt{'robb'}</b>
 1185: <form name="reldt" action="$feedurl" target="loncapaclient">
 1186: </form>
 1187: <br /><a href="$feedurl">Continue</a>
 1188: </body>
 1189: </html>
 1190: ENDREDIR
 1191:       return OK;
 1192:   } elsif ($ENV{'form.modifydisp'}) {
 1193:       &Apache::loncommon::content_type($r,'text/html');
 1194:       $r->send_http_header;
 1195:       my $symb=$ENV{'form.modifydisp'};
 1196:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 1197:       my $previous=$ENV{'form.previous'};
 1198:       my ($dispchg,$markchg) = split/_/,$ENV{'form.changes'};
 1199:       my $feedurl = &Apache::lonnet::clutter($url);
 1200:  # backward compatibility (bulletin boards used to be 'wrapped')  
 1201:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 1202:           $feedurl=~s|^/adm/wrapper||;
 1203:       }
 1204:       &print_display_options($r,$symb,$previous,$dispchg,$markchg,$feedurl);
 1205:       return OK;
 1206:   } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
 1207:       &Apache::loncommon::content_type($r,'text/html');
 1208:       $r->send_http_header;
 1209:       my $previous=$ENV{'form.previous'};
 1210:       my ($map,$ind,$url);
 1211:       if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
 1212: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
 1213:           my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
 1214:           my $ressymb = $symb;
 1215:           ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 1216:           unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 1217:               $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 1218:           }
 1219:           my %discinfo = ();
 1220:           my $lastkey = $ressymb.'_lastread';
 1221:           my $ondispkey = $ressymb.'_markondisp';
 1222:           if ($ENV{'form.markondisp'}) {
 1223:               $discinfo{$lastkey} = time;
 1224:               $discinfo{$ondispkey} = 1;
 1225:           } elsif ($ENV{'form.markonread'}) {
 1226:               if ( $previous > 0 ) {
 1227:                   $discinfo{$lastkey} = $previous;
 1228:               }
 1229:               $discinfo{$ondispkey} = 0;
 1230:           }
 1231:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 1232:       }
 1233:       if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
 1234: # ----------------------------------------------------------------- Modify display setting for this discussion 
 1235:           my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
 1236:           my $ressymb = $symb;
 1237:           ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 1238:           unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 1239:               $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 1240:           }
 1241:           my %discinfo = ();
 1242:           if ($ENV{'form.allposts'}) {
 1243:               $discinfo{$ressymb.'_showonlyunread'} = 0;
 1244:           } elsif ($ENV{'form.onlyunread'}) {
 1245:               $discinfo{$ressymb.'_showonlyunread'} = 1;
 1246:           }
 1247:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 1248:       }
 1249:       if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
 1250:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
 1251:       } else {
 1252:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
 1253:       }
 1254:       return OK;
 1255:   } elsif ($ENV{'form.markread'}) {
 1256: # ----------------------------------------------------------------- Mark new posts as read
 1257:       &Apache::loncommon::content_type($r,'text/html');
 1258:       $r->send_http_header;
 1259:       my $symb=$ENV{'form.markread'};
 1260:       my $ressymb = $symb;
 1261:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 1262:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 1263:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 1264:       }
 1265:       my %discinfo = ();
 1266:       my $lastkey = $ressymb.'_lastread';
 1267:       $discinfo{$lastkey} = time;
 1268:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 1269:       &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
 1270:       return OK;
 1271:   } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
 1272: # ----------------------------------------------------------------- Hide/unhide
 1273:     &Apache::loncommon::content_type($r,'text/html');
 1274:     $r->send_http_header;
 1275: 
 1276:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
 1277: 
 1278:     my ($symb,$idx)=split(/\:\:\:/,$entry);
 1279:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 1280: 
 1281:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
 1282:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1283: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1284: 
 1285:         
 1286:     my $currenthidden=$contrib{'hidden'};
 1287:     
 1288:     if ($ENV{'form.hide'}) {
 1289: 	$currenthidden.='.'.$idx.'.';
 1290:     } else {
 1291:         $currenthidden=~s/\.$idx\.//g;
 1292:     }
 1293:     my %newhash=('hidden' => $currenthidden);
 1294: 
 1295:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
 1296:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1297: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1298: 
 1299:     &redirect_back($r,&Apache::lonnet::clutter($url),
 1300:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
 1301:   } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
 1302:       &Apache::loncommon::content_type($r,'text/html');
 1303:       $r->send_http_header;
 1304:       if ($ENV{'form.threadedon'}) {
 1305: 	  &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
 1306: 	  &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
 1307:       } else {
 1308:  	  &Apache::lonnet::del('environment',['threadeddiscussion']);
 1309: 	  &Apache::lonnet::delenv('environment\.threadeddiscussion');
 1310:       }
 1311:       my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
 1312:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 1313:       &redirect_back($r,&Apache::lonnet::clutter($url),
 1314: 		     &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
 1315:   } elsif ($ENV{'form.deldisc'}) {
 1316: # --------------------------------------------------------------- Hide for good
 1317:     &Apache::loncommon::content_type($r,'text/html');
 1318:     $r->send_http_header;
 1319: 
 1320:     my $entry=$ENV{'form.deldisc'};
 1321: 
 1322:     my ($symb,$idx)=split(/\:\:\:/,$entry);
 1323:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 1324: 
 1325:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
 1326:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1327: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1328: 
 1329:         
 1330:     my $currentdeleted=$contrib{'deleted'};
 1331:     
 1332:     $currentdeleted.='.'.$idx.'.';
 1333: 
 1334:     my %newhash=('deleted' => $currentdeleted);
 1335: 
 1336:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
 1337:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1338: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1339: 
 1340:     &redirect_back($r,&Apache::lonnet::clutter($url),
 1341:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
 1342:   } elsif ($ENV{'form.preview'}) {
 1343: # -------------------------------------------------------- User wants a preview
 1344:       $r->content_type('text/html');
 1345:       $r->send_http_header;
 1346:       &show_preview($r);
 1347:   } else {
 1348: # ------------------------------------------------------------- Normal feedback
 1349:   my $feedurl=$ENV{'form.postdata'};
 1350:   $feedurl=~s/^http\:\/\///;
 1351:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
 1352:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
 1353:   $feedurl=~s/\?.+$//;
 1354: 
 1355:   my $symb;
 1356:   if ($ENV{'form.replydisc'}) {
 1357:       $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
 1358:       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
 1359:       $feedurl=&Apache::lonnet::clutter($url);
 1360:   } else {
 1361:       $symb=&Apache::lonnet::symbread($feedurl);
 1362:   }
 1363:   unless ($symb) {
 1364:       $symb=$ENV{'form.symb'};
 1365:       if ($symb) {
 1366: 	  my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
 1367:           $feedurl=&Apache::lonnet::clutter($url);
 1368:       }
 1369:   }
 1370:   my $goahead=1;
 1371:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
 1372:       unless ($symb) { $goahead=0; }
 1373:   }
 1374:   # backward compatibility (bulletin boards used to be 'wrapped')
 1375:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 1376:       $feedurl=~s|^/adm/wrapper||;
 1377:   }
 1378:   if ($goahead) {
 1379: # Go ahead with feedback, no ambiguous reference
 1380:     &Apache::loncommon::content_type($r,'text/html');
 1381:     $r->send_http_header;
 1382:   
 1383:     if (
 1384:       (
 1385:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
 1386:       ) 
 1387:       || 
 1388:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
 1389:       ||
 1390:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
 1391:      ) {
 1392: # --------------------------------------------------- Print login screen header
 1393:     unless ($ENV{'form.sendit'}) {
 1394:       my $options=&screen_header($feedurl);
 1395:       if ($options) {
 1396: 	&mail_screen($r,$feedurl,$options);
 1397:       } else {
 1398: 	&fail_redirect($r,$feedurl);
 1399:       }
 1400:     } else {
 1401:       
 1402: # Get previous user input
 1403:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
 1404:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
 1405:             $ENV{'request.course.id'});
 1406: 
 1407: # Get output from resource
 1408:       my $usersaw=&resource_output($feedurl);
 1409: 
 1410: # Get resource answer (need to allow student to view grades for this to work)
 1411:       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
 1412:       my $useranswer=&Apache::loncommon::get_student_answers(
 1413:                        $symb,$ENV{'user.name'},$ENV{'user.domain'},
 1414: 		       $ENV{'request.course.id'});
 1415:       &Apache::lonnet::delenv('allowed.vgr');
 1416: # Get attachments, if any, and not too large
 1417:       my $attachmenturl='';
 1418:       if ($ENV{'form.attachment.filename'}) {
 1419: 	  unless (length($ENV{'form.attachment'})>131072) {
 1420: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
 1421: 	  }
 1422:       }
 1423: # Filter HTML out of message (could be nasty)
 1424:       my $message=&clear_out_html($ENV{'form.comment'});
 1425: 
 1426: # Assemble email
 1427:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
 1428:           $usersaw,$useranswer);
 1429:  
 1430: # Who gets this?
 1431:       my ($typestyle,%to) = &decide_receiver($feedurl);
 1432: 
 1433: # Actually send mail
 1434:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
 1435:           $attachmenturl,%to);
 1436: 
 1437: # Discussion? Store that.
 1438: 
 1439:       my $numpost=0;
 1440:       if ($ENV{'form.discuss'}) {
 1441:           my $subject = &clear_out_html($ENV{'form.subject'});
 1442: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
 1443: 	  $numpost++;
 1444:       }
 1445: 
 1446:       if ($ENV{'form.anondiscuss'}) {
 1447:           my $subject = &clear_out_html($ENV{'form.subject'});
 1448: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
 1449: 	  $numpost++;
 1450:       }
 1451: 
 1452: 
 1453: # Receipt screen and redirect back to where came from
 1454:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
 1455: 
 1456:     }
 1457:    } else {
 1458: # Unable to give feedback
 1459:     &no_redirect_back($r,$feedurl);
 1460:    }
 1461:   } else {
 1462: # Ambiguous Problem Resource
 1463:       if ( &Apache::lonnet::mod_perl_version() == 2 ) {
 1464: 	  &Apache::lonnet::cleanenv();
 1465:       }
 1466:       $r->internal_redirect('/adm/ambiguous');
 1467:   }
 1468: }
 1469:   return OK;
 1470: } 
 1471: 
 1472: 1;
 1473: __END__

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