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

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

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