Annotation of loncom/interface/lonfeedback.pm, revision 1.99.2.6

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

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