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

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

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