File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.99.2.6: download - view: text, annotated - select for diffs
Mon Sep 13 18:20:38 2004 UTC (19 years, 9 months ago) by albertel
Branches: version_1_2_X
Diff to branchpoint 1.99: preferred, unified
- backport 1.123

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

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