File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.93: download - view: text, annotated - select for diffs
Fri Jun 4 22:54:36 2004 UTC (20 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: version_1_1_99_0, HEAD
- remove debug spew

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

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