File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.99.2.5: download - view: text, annotated - select for diffs
Tue Aug 31 18:33:44 2004 UTC (19 years, 9 months ago) by albertel
Branches: version_1_2_X
CVS tags: version_1_2_0
Diff to branchpoint 1.99: preferred, unified
- backport 1.120 1.121

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

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