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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.107   ! www         4: # $Id: lonfeedback.pm,v 1.106 2004/07/24 18:19:38 www 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.106     www        39: use Apache::lonspeller();
1.54      www        40: 
1.92      albertel   41: sub discussion_open {
1.90      albertel   42:     my ($status)=@_;
1.92      albertel   43:     if (defined($status) &&
                     44: 	!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
1.77      www        45: 	  || $status eq 'OPEN')) {
1.92      albertel   46: 	return 0;
1.75      albertel   47:     }
1.89      albertel   48:     my $close=&Apache::lonnet::EXT('resource.0.discussend');
                     49:     if (defined($close) && $close ne '' && $close < time) {
1.92      albertel   50: 	return 0;
1.89      albertel   51:     }
1.92      albertel   52:     return 1;
                     53: }
                     54: 
                     55: sub discussion_visible {
                     56:     my ($status)=@_;
                     57:     if (not &discussion_open($status)) {
                     58: 	my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
                     59: 	if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden))  {
                     60: 	    return 0;
                     61: 	}
                     62:     }
                     63:     return 1;
1.90      albertel   64: }
1.84      raeburn    65: 
1.90      albertel   66: sub list_discussion {
                     67:     my ($mode,$status,$symb)=@_;
                     68: 
1.95      sakharuk   69:     my $outputtarget=$ENV{'form.grade_target'};
1.92      albertel   70:     if (not &discussion_visible($status)) { return ''; }
1.84      raeburn    71:     my @bgcols = ("#cccccc","#eeeeee");
1.57      www        72:     my $discussiononly=0;
                     73:     if ($mode eq 'board') { $discussiononly=1; }
1.55      www        74:     unless ($ENV{'request.course.id'}) { return ''; }
                     75:     my $crs='/'.$ENV{'request.course.id'};
1.101     raeburn    76:     my $cid=$ENV{'request.course.id'};
1.55      www        77:     if ($ENV{'request.course.sec'}) {
                     78: 	$crs.='_'.$ENV{'request.course.sec'};
                     79:     }                 
                     80:     $crs=~s/\_/\//g;
1.54      www        81:     unless ($symb) {
                     82: 	$symb=&Apache::lonnet::symbread();
                     83:     }
                     84:     unless ($symb) { return ''; }
1.100     raeburn    85:     my %usernamesort = ();
                     86:     my %namesort =();
                     87:     my %subjectsort = ();
1.80      raeburn    88: # backward compatibility (bulletin boards used to be 'wrapped')
                     89:     my $ressymb=$symb;
                     90:     if ($mode eq 'board') {
                     91:         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                     92:             $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                     93:         }
                     94:     }
                     95: 
                     96: # Get discussion display settings for this discussion
                     97:     my $lastkey = $ressymb.'_lastread';
                     98:     my $showkey = $ressymb.'_showonlyunread';
                     99:     my $visitkey = $ressymb.'_visit';
1.84      raeburn   100:     my $ondispkey = $ressymb.'_markondisp';
1.101     raeburn   101:     my $userpickkey = $ressymb.'_userpick';
                    102:     my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey,$userpickkey],$ENV{'user.domain'},$ENV{'user.name'});
1.84      raeburn   103:     my %discinfo = ();
1.80      raeburn   104:     my $showonlyunread = 0;
1.84      raeburn   105:     my $markondisp = 0;
1.79      raeburn   106:     my $prevread = 0;
1.81      raeburn   107:     my $previous = 0;
1.80      raeburn   108:     my $visit = 0;
                    109:     my $newpostsflag = 0;
1.101     raeburn   110:     my @posters = split/\&/,$dischash{$userpickkey};
1.80      raeburn   111: 
1.81      raeburn   112: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
1.101     raeburn   113:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts','rolefilter','statusfilter','sectionpick','totposters']);
1.100     raeburn   114:     my $sortposts = $ENV{'form.sortposts'};
1.101     raeburn   115:     my $rolefilter = $ENV{'form.rolefilter'};
                    116:     my $statusfilter = $ENV{'form.statusfilter'};
                    117:     my $sectionpick = $ENV{'form.sectionpick'};
                    118:     my $totposters = $ENV{'form.totposters'};
1.81      raeburn   119:     $previous = $ENV{'form.previous'};
1.80      raeburn   120:     if ($previous > 0) {
                    121:         $prevread = $previous;
                    122:     } elsif (defined($dischash{$lastkey})) {
1.84      raeburn   123:         unless ($dischash{$lastkey} eq '') {
                    124:             $prevread = $dischash{$lastkey};
                    125:         }
1.80      raeburn   126:     }
1.79      raeburn   127: 
1.101     raeburn   128: # Get information about students and non-stundents in course for filtering display of posts
                    129:     my %roleshash = ();
                    130:     my %roleinfo = ();
                    131:     if ($rolefilter) {
                    132:         %roleshash = &Apache::lonnet::dump('nohist_userroles',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    133:         foreach (keys %roleshash) {
                    134:             my ($role,$uname,$udom,$sec) = split/:/,$_;
                    135:             my ($end,$start) = split/:/,$roleshash{$_};
                    136:             my $now = time;
                    137:             my $status = 'Active';
                    138:             if (($now < $start) || ($end > 0 && $now > $end)) {
                    139:                 $status = 'Expired';
                    140:             }
                    141:             push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
                    142:         }
                    143:         my ($classlist) = &Apache::loncoursedata::get_classlist(
                    144:                               $ENV{'request.course.id'},
                    145:                               $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    146:                               $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    147:         my $sec_index = &Apache::loncoursedata::CL_SECTION();
                    148:         my $status_index = &Apache::loncoursedata::CL_STATUS();
                    149:         while (my ($student,$data) = each %$classlist) {
                    150:             my ($section,$status) = ($data->[$sec_index],
                    151:                                  $data->[$status_index]);
                    152:             push @{$roleinfo{$student}}, 'st:'.$section.':'.$status;
                    153:         }
                    154:     }
                    155: 
1.84      raeburn   156: # Get discussion display default settings for user
                    157:     my %userenv = &Apache::lonnet::get('environment',['discdisplay','discmarkread'],$ENV{'user.domain'},$ENV{'user.name'});
1.83      raeburn   158:     my $discdisplay=$userenv{'discdisplay'};
                    159:     if ($discdisplay eq 'unread') {
                    160:         $showonlyunread = 1;
                    161:     }
1.84      raeburn   162:     my $discmarkread=$userenv{'discmarkread'};
                    163:     if ($discmarkread eq 'ondisp') {
                    164:         $markondisp = 1;
                    165:     }
                    166: 
                    167: # Override user's default if user specified display setting for this discussion
                    168:     if (defined($dischash{$ondispkey})) {
                    169:         $markondisp = $dischash{$ondispkey};
                    170:     }
                    171:     if ($markondisp) {
                    172:         $discinfo{$lastkey} = time;
                    173:     }
1.83      raeburn   174: 
1.80      raeburn   175:     if (defined($dischash{$showkey})) {
                    176:         $showonlyunread = $dischash{$showkey};
                    177:     }
                    178: 
                    179:     if (defined($dischash{$visitkey})) {
                    180:         $visit = $dischash{$visitkey};
1.78      raeburn   181:     }
1.80      raeburn   182:     $visit ++;
1.78      raeburn   183: 
1.54      www       184:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.77      www       185:     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
                    186: 	&& ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
1.68      www       187:     my @discussionitems=();
1.101     raeburn   188:     my %shown = ();
                    189:     my @posteridentity=();
1.73      albertel  190:     my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1.54      www       191: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    192: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.67      www       193:     my $visible=0;
1.68      www       194:     my @depth=();
                    195:     my @original=();
                    196:     my @index=();
                    197:     my @replies=();
                    198:     my %alldiscussion=();
1.80      raeburn   199:     my %notshown = ();
1.84      raeburn   200:     my %newitem = ();
1.68      www       201:     my $maxdepth=0;
                    202: 
1.69      www       203:     my $target='';
                    204:     unless ($ENV{'browser.interface'} eq 'textual' ||
                    205: 	    $ENV{'environment.remote'} eq 'off' ) {
                    206: 	$target='target="LONcom"';
                    207:     }
1.79      raeburn   208:     
                    209:     my $now = time;
1.80      raeburn   210:     $discinfo{$visitkey} = $visit;
                    211: 
                    212:     &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.79      raeburn   213: 
1.54      www       214:     if ($contrib{'version'}) {
1.84      raeburn   215:         my $oldest = $contrib{'1:timestamp'};
                    216:         if ($prevread eq '0') {
                    217:             $prevread = $oldest-1;
                    218:         }
1.64      www       219: 	for (my $id=1;$id<=$contrib{'version'};$id++) {
                    220: 	    my $idx=$id;
1.80      raeburn   221:             my $posttime = $contrib{$idx.':timestamp'};
1.84      raeburn   222:             if ($prevread <= $posttime) {
1.80      raeburn   223:                 $newpostsflag = 1;
                    224:             }
1.54      www       225: 	    my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1.102     raeburn   226:             my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
1.54      www       227: 	    my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1.68      www       228: 	    my $origindex='0.';
1.102     raeburn   229:             my $numoldver=0;
1.100     raeburn   230: 	    if ($contrib{$idx.':replyto'}) {
                    231:                 if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) {
1.68      www       232: # this is a follow-up message
1.100     raeburn   233: 		    $original[$idx]=$original[$contrib{$idx.':replyto'}];
                    234: 		    $depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
                    235: 		    $origindex=$index[$contrib{$idx.':replyto'}];
                    236: 		    if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
                    237:                 } else {
                    238:                     $original[$idx]=0;
                    239:                     $depth[$idx]=0;
                    240:                 }
1.68      www       241: 	    } else {
                    242: # this is an original message
                    243: 		$original[$idx]=0;
                    244: 		$depth[$idx]=0;
                    245: 	    }
                    246: 	    if ($replies[$depth[$idx]]) {
                    247: 		$replies[$depth[$idx]]++;
                    248: 	    } else {
                    249: 		$replies[$depth[$idx]]=1;
                    250: 	    }
1.54      www       251: 	    unless ((($hidden) && (!$seeid)) || ($deleted)) {
1.67      www       252: 		$visible++;
1.102     raeburn   253:                 if ($contrib{$idx.':history'}) {
                    254:                     if ($contrib{$idx.':history'} =~ /:/) {
                    255:                         my @oldversions = split/:/,$contrib{$idx.':history'};
                    256:                         $numoldver = @oldversions;
                    257:                     } else {
                    258:                         $numoldver = 1;
                    259:                     } 
                    260:                 }
1.54      www       261: 		my $message=$contrib{$idx.':message'};
                    262: 		$message=~s/\n/\<br \/\>/g;
1.102     raeburn   263: 		$message=&Apache::lontexconvert::msgtexconverted($message,undef,$numoldver);
1.78      raeburn   264:                 my $subject=$contrib{$idx.':subject'};
                    265:                 if (defined($subject)) {
                    266:                     $subject=~s/\n/\<br \/\>/g;
1.102     raeburn   267:                     $subject=&Apache::lontexconvert::msgtexconverted($subject,undef,$numoldver);
1.78      raeburn   268:                 }
1.54      www       269: 		if ($contrib{$idx.':attachmenturl'}) {
1.82      albertel  270: 		    my ($fname)
                    271:                         =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
                    272: 		    &Apache::lonnet::allowuploaded('/adm/feedback',
                    273: 					   $contrib{$idx.':attachmenturl'});
                    274: 		    $message.='<p>'.&mt('Attachment').
                    275: 			': <a href="'.$contrib{$idx.':attachmenturl'}.'"><tt>'.
                    276: 			$fname.'</tt></a></p>';
1.54      www       277: 		}
                    278: 		if ($message) {
                    279: 		    if ($hidden) {
                    280: 			$message='<font color="#888888">'.$message.'</font>';
1.102     raeburn   281:                         if ($studenthidden) {
                    282:                             $message .='<br /><br />Deleted by poster (student).';
                    283:                         }
1.54      www       284: 		    }
                    285: 		    my $screenname=&Apache::loncommon::screenname(
                    286: 					    $contrib{$idx.':sendername'},
                    287: 					    $contrib{$idx.':senderdomain'});
                    288: 		    my $plainname=&Apache::loncommon::nickname(
                    289: 					    $contrib{$idx.':sendername'},
                    290: 					    $contrib{$idx.':senderdomain'});
                    291: 		    
1.62      www       292: 		    my $sender=&mt('Anonymous');
1.100     raeburn   293: # Set up for sorting by subject
                    294:                     if ($contrib{$idx.':subject'} eq '') {
                    295:                         if (defined($subjectsort{'__No subject'})) {
                    296:                             push @{$subjectsort{'__No subject'}}, $idx;
                    297:                         } else {
                    298:                             @{$subjectsort{'__No subject'}} = ("$idx");
                    299:                         }
                    300:                     } else {
                    301:                         if (defined($subjectsort{$contrib{$idx.':subject'}})) {
                    302:                             push @{$subjectsort{$contrib{$idx.':subject'}}}, $idx;
                    303:                         } else {
                    304:                             @{$subjectsort{$contrib{$idx.':subject'}}} = ("$idx");
                    305:                         }
                    306:                     }
1.54      www       307: 		    if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
                    308: 			$sender=&Apache::loncommon::aboutmewrapper(
                    309: 					 $plainname,
                    310: 					 $contrib{$idx.':sendername'},
                    311: 					 $contrib{$idx.':senderdomain'}).' ('.
                    312: 					 $contrib{$idx.':sendername'}.' at '.
                    313: 					 $contrib{$idx.':senderdomain'}.')';
                    314: 			if ($contrib{$idx.':anonymous'}) {
1.62      www       315: 			    $sender.=' ['.&mt('anonymous').'] '.
1.54      www       316: 				$screenname;
                    317: 			}
1.100     raeburn   318: # Set up for sorting by domain, then username
                    319:                         unless (defined($usernamesort{$contrib{$idx.':senderdomain'}})) {
                    320:                             %{$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
                    321:                         }
                    322:                         if (defined($usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
                    323:                             push @{$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx;
                    324:                         } else {
                    325:                             @{$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
                    326:                         }
                    327: # Set up for sorting by last name, then first name
                    328:                         my %names = &Apache::lonnet::get('environment',['firstname','lastname'],
                    329:                                   $contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
                    330:                         my $lastname = $names{'lastname'};
                    331:                         my $firstname = $names{'firstname'};
                    332:                         if ($lastname eq '') {
                    333:                             $lastname = '_';
                    334:                         }
                    335:                         if ($firstname eq '') {
                    336:                             $firstname = '_';
                    337:                         }
                    338:                         unless (defined($namesort{$lastname})) {
                    339:                             %{$namesort{$lastname}} = ();
                    340:                         }
                    341:                         if (defined($namesort{$lastname}{$firstname})) {
                    342:                             push @{$namesort{$lastname}{$firstname}}, $idx;
                    343:                         } else {
                    344:                             @{$namesort{$lastname}{$firstname}} = ("$idx");
                    345:                         }
1.102     raeburn   346:                         if ($ENV{"course.$cid.allow_discussion_post_editing"} =~ m/yes/i) {
                    347:                             if (($ENV{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($ENV{'user.name'} eq $contrib{$idx.':sendername'})) {
                    348:                                 $sender.=' <a href="/adm/feedback?editdisc='.
                    349:                                     $ressymb.':::'.$idx;
                    350:                                 if ($newpostsflag) {
                    351:                                     $sender .= '&previous='.$prevread;
                    352:                                 }
                    353:                                 $sender .= '" '.$target.'>'.&mt('Edit').'</a>';                                      unless ($seeid) {
                    354:                                     $sender.=" <a href=\"javascript:studentdelete('$ressymb','$idx','$newpostsflag','$prevread')";
                    355:                                     $sender .= '">'.&mt('Delete').'</a>';
                    356:                                 }
                    357:                             }
                    358:                         }
1.54      www       359: 			if ($seeid) {
                    360: 			    if ($hidden) {
1.102     raeburn   361:                                 unless ($studenthidden) {
                    362: 				    $sender.=' <a href="/adm/feedback?unhide='.
                    363: 				        $ressymb.':::'.$idx;
                    364:                                     if ($newpostsflag) {
                    365:                                         $sender .= '&previous='.$prevread;
                    366:                                     }
                    367:                                     $sender .= '">'.&mt('Make Visible').'</a>';
1.80      raeburn   368:                                 }
1.54      www       369: 			    } else {
                    370: 				$sender.=' <a href="/adm/feedback?hide='.
1.80      raeburn   371: 				    $ressymb.':::'.$idx;
                    372:                                 if ($newpostsflag) {
                    373:                                     $sender .= '&previous='.$prevread;
                    374:                                 }
                    375:                                 $sender .= '">'.&mt('Hide').'</a>';
1.54      www       376: 			    }                     
                    377: 			    $sender.=' <a href="/adm/feedback?deldisc='.
1.102     raeburn   378: 				    $ressymb.':::'.$idx;
1.100     raeburn   379:                             if ($newpostsflag) {
                    380:                                 $sender .= '&previous='.$prevread;
                    381:                             }
                    382:                             $sender .= '">'.&mt('Delete').'</a>';
1.64      www       383: 			}
1.54      www       384: 		    } else {
                    385: 			if ($screenname) {
                    386: 			    $sender='<i>'.$screenname.'</i>';
                    387: 			}
1.100     raeburn   388: # Set up for sorting by domain, then username for anonymous
                    389:                         unless (defined($usernamesort{'__anon'})) {
                    390:                             %{$usernamesort{'__anon'}} = ();
                    391:                         }
                    392:                         if (defined($usernamesort{'__anon'}{'__anon'})) {
                    393:                             push @{$usernamesort{'__anon'}{'__anon'}}, $idx;
                    394:                         } else {
                    395:                             @{$usernamesort{'__anon'}{'__anon'}} = ("$idx");
                    396:                         }
                    397: # Set up for sorting by last name, then first name for anonymous
                    398:                         unless (defined($namesort{'__anon'})) {
                    399:                             %{$namesort{'__anon'}} = ();
                    400:                         }
                    401:                         if (defined($namesort{'__anon'}{'__anon'})) {
                    402:                             push @{$namesort{'__anon'}{'__anon'}}, $idx;
                    403:                         } else {
                    404:                             @{$namesort{'__anon'}{'__anon'}} = ("$idx");
                    405:                         }
1.77      www       406: 		    }
1.92      albertel  407: 		    if (&discussion_open($status) &&
1.90      albertel  408: 			&Apache::lonnet::allowed('pch',
1.77      www       409: 						 $ENV{'request.course.id'}.
                    410: 						 ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
                    411: 			$sender.=' <a href="/adm/feedback?replydisc='.
1.80      raeburn   412: 			    $ressymb.':::'.$idx;
                    413:                         if ($newpostsflag) {
                    414:                             $sender .= '&previous='.$prevread;
                    415:                         }
                    416:                         $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
1.54      www       417: 		    }
                    418: 		    my $vgrlink;
                    419: 		    if ($viewgrades) {
                    420: 			$vgrlink=&Apache::loncommon::submlink('Submissions',
                    421:             $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
                    422: 		    }
1.68      www       423: #figure out at what position this needs to print
                    424: 		    my $thisindex=$idx;
1.100     raeburn   425: 		    if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) {
1.101     raeburn   426: 			$thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);
1.68      www       427: 		    }
                    428: 		    $alldiscussion{$thisindex}=$idx;
1.101     raeburn   429:                     $shown{$idx} = 0;
                    430:                     $index[$idx]=$thisindex;
1.79      raeburn   431:                     my $spansize = 2;
1.80      raeburn   432:                     if ($showonlyunread && $prevread > $posttime) {
                    433:                         $notshown{$idx} = 1;
1.78      raeburn   434:                     } else {
1.101     raeburn   435:                         my $uname = $contrib{$idx.':sendername'};
                    436:                         my $udom = $contrib{$idx.':senderdomain'};
                    437:                         my $poster = $uname.':'.$udom;
                    438:                         my $rolematch = '';
                    439:                         my $skiptest = 1;
                    440:                         if ($totposters > 0) {
                    441:                             if (grep/^$poster$/,@posters) {
                    442:                                 $shown{$idx} = 1;
                    443:                             }
                    444:                         } else {
                    445:                             if ($rolefilter) {
                    446:                                 if ($rolefilter eq 'all') {
                    447:                                     $rolematch = '([^:]+)';
                    448:                                 } else {
                    449:                                     $rolematch = $rolefilter;
                    450:                                     $skiptest = 0;
                    451:                                 }
                    452:                             }
                    453:                             if ($sectionpick) {
                    454:                                 if ($sectionpick eq 'all') {
                    455:                                     $rolematch .= ':([^:]*)';
                    456:                                 } else {
                    457:                                     $rolematch .= ':'.$sectionpick;
                    458:                                     $skiptest = 0;
                    459:                                 }
                    460:                             }
                    461:                             if ($statusfilter) {
                    462:                                 if ($statusfilter eq 'all') {
                    463:                                     $rolematch .= ':([^:]+)';
                    464:                                 } else {
                    465:                                     $rolematch .= ':'.$statusfilter;
                    466:                                     $skiptest = 0;
                    467:                                 }
                    468:                             }
                    469:                             if ($skiptest) {
                    470:                                 $shown{$idx} = 1;
                    471:                             } else {
                    472:                                 foreach my $role (@{$roleinfo{$poster}}) {
                    473:                                     if ($role =~ m/^$rolematch$/) {
                    474:                                         $shown{$idx} = 1;
                    475:                                         last;
                    476:                                     }
                    477:                                 }
                    478:                             }
                    479:                         }
                    480:                     }
                    481:                     unless ($notshown{$idx} == 1) {
1.80      raeburn   482:                         if ($prevread > 0 && $prevread <= $posttime) {
1.84      raeburn   483:                             $newitem{$idx} = 1;
                    484:                             $discussionitems[$idx] .= '
                    485:                              <p><table border="0" width="100%">
                    486:                               <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
                    487:                         } else {
                    488:                             $newitem{$idx} = 0;
                    489:                             $discussionitems[$idx] .= '
                    490:                              <p><table border="0" width="100%">
                    491:                               <tr><td align="left">&nbsp;</td>';
1.80      raeburn   492:                         }
                    493:                         $discussionitems[$idx] .= '<td align ="left">&nbsp;&nbsp;'.
                    494:                             '<b>'.$subject.'</b>&nbsp;&nbsp;'.
                    495:                             $sender.'</b> '.$vgrlink.' ('.
                    496:                             localtime($posttime).')</td></tr>'.
                    497:                             '</table><blockquote>'.$message.'</blockquote></p>';
1.102     raeburn   498:                         if ($contrib{$idx.':history'}) {
                    499:                             my @postversions = ();
                    500:                             $discussionitems[$idx] .= '<br />'.&mt('This post has been edited by the author.').'<br/>'.&mt('Earlier version(s) were posted on: ');
                    501:                             if ($contrib{$idx.':history'} =~ m/:/) {
                    502:                                 @postversions = split/:/,$contrib{$idx.':history'};
                    503:                             } else {
                    504:                                 @postversions = ("$contrib{$idx.':history'}");
                    505:                             }
                    506:                             for (my $i=0; $i<@postversions; $i++) {
                    507:                                 my $version = $i+1;
                    508:                                 $discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).'  ';
                    509:                             }
                    510:                             $discussionitems[$idx] .= '<br />';
                    511:                         }
1.78      raeburn   512:                     }
                    513:                 }
                    514:             }
1.54      www       515: 	}
1.64      www       516:     }
1.80      raeburn   517: 
1.67      www       518:     my $discussion='';
1.84      raeburn   519: 
                    520:     my $function = &Apache::loncommon::get_users_function();
                    521:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
                    522:                                                     $ENV{'user.domain'});
                    523:     my %lt = &Apache::lonlocal::texthash(
1.97      raeburn   524:         'cuse' => 'Current discussion settings',
1.84      raeburn   525:         'allposts' => 'All posts',
                    526:         'unread' => 'New posts only',
                    527:         'ondisp' => 'Once displayed',
                    528:         'onmark' => 'Once marked read',
                    529:         'disa' => 'Posts to be displayed',
                    530:         'npce' => 'Posts cease to be marked "NEW"',
1.97      raeburn   531:         'chgt' => 'Change',
                    532:         'disp' => 'Display',
                    533:         'nolo' => 'Not new',
1.84      raeburn   534:     );
                    535: 
                    536:     my $currdisp = $lt{'allposts'};
                    537:     my $currmark = $lt{'onmark'};
                    538:     my $dispchange = $lt{'unread'};
                    539:     my $markchange = $lt{'ondisp'};
1.97      raeburn   540:     my $chglink = '/adm/feedback?modifydisp='.$ressymb;
                    541:     my $displink = 'onlyunread';
                    542:     my $marklink = 'markondisp';
1.84      raeburn   543: 
                    544:     if ($markondisp) {
                    545:         $currmark = $lt{'ondisp'};
                    546:         $markchange = $lt{'onmark'};
1.97      raeburn   547:         $marklink = 'markonread';
1.84      raeburn   548:     }
                    549: 
                    550:     if ($showonlyunread) {
                    551:         $currdisp = $lt{'unread'};
                    552:         $dispchange = $lt{'allposts'};
1.97      raeburn   553:         $displink = 'allposts';
1.84      raeburn   554:     }
1.97      raeburn   555:    
                    556:     $chglink .= '&changes='.$displink.'_'.$marklink;
1.84      raeburn   557: 
                    558:     if ($newpostsflag) {
1.97      raeburn   559:         $chglink .= '&previous='.$prevread;
1.84      raeburn   560:     }
                    561: 
1.67      www       562:     if ($visible) {
1.80      raeburn   563: # Print the discusssion
1.95      sakharuk  564: 	if ($outputtarget ne 'tex') {
1.97      raeburn   565:             my $colspan=$maxdepth+1;
1.102     raeburn   566:             $discussion.= qq|
                    567: <script>
                    568:    function studentdelete (symb,idx,newflag,previous) {
                    569:        var symbparm = symb+':::'+idx
                    570:        var prevparm = ""
                    571:        if (newflag == 1) {
                    572:            prevparm = "&previous="+previous
                    573:        }
                    574:        if (confirm("Are you sure you want to delete this post?\\nDeleted posts will no longer be visible to you and other students,\\nbut will continue to be visible to your instructor")) {
                    575:            document.location.href = "/adm/feedback?hide="+symbparm+prevparm
                    576:        }  
                    577:    }
                    578: </script>
                    579:             |;
1.95      sakharuk  580: 	    $discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
1.97      raeburn   581: 	    $discussion .='<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
1.95      sakharuk  582: 		'<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
                    583: 	    if ($visible>2) {
                    584: 		$discussion.='<td align="left">'.
                    585: 		    '<a href="/adm/feedback?threadedon='.$ressymb;
                    586: 		if ($newpostsflag) {
                    587: 		    $discussion .= '&previous='.$prevread;
                    588: 		}
                    589: 		$discussion .='">'.&mt('Threaded View').'</a>&nbsp;&nbsp;'.
                    590: 		    '<a href="/adm/feedback?threadedoff='.$ressymb;
                    591: 		if ($newpostsflag) {
                    592: 		    $discussion .= '&previous='.$prevread;
                    593: 		}
1.100     raeburn   594: 		$discussion .='">'.&mt('Chronological View').'</a>&nbsp;&nbsp;
                    595:                               <a href= "/adm/feedback?sortfilter='.$ressymb;
                    596:                 if ($newpostsflag) {
                    597:                     $discussion .= '&previous='.$prevread;
                    598:                 }
                    599:                 $discussion .='">'.&mt('Sorting/Filtering options').'</a>&nbsp;&nbsp';
                    600:             } else {
                    601:                 $discussion .= '<td align="left">';
                    602:             }
                    603:             $discussion .='<a href= "/adm/feedback?export='.$ressymb;
                    604:             if ($newpostsflag) {
                    605:                 $discussion .= '&previous='.$prevread;
                    606:             }
                    607:             $discussion .= '">'.&mt('Export').'?</a>&nbsp;&nbsp;</td>';
1.95      sakharuk  608: 	    if ($newpostsflag) {
                    609: 		if (!$markondisp) {
                    610: 		    $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark new posts as read').'</a>&nbsp;&nbsp;';
                    611: 		} else {
                    612: 		    $discussion .= '<td>&nbsp;</td>';
                    613: 		}
                    614: 	    } else {
                    615: 		$discussion .= '<td>&nbsp;</td>';
                    616: 	    }
                    617: 	    $discussion .= '</tr></table></td></tr>';
                    618: 	} else {
                    619: 	    $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
                    620:                          '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
                    621:                          '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
                    622:                          '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
                    623:                          '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}';
                    624: 	}
1.80      raeburn   625:         my $numhidden = keys %notshown;
                    626:         if ($numhidden > 0) {
                    627:             my $colspan = $maxdepth+1;
                    628:             $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
                    629:                          '<a href="/adm/feedback?allposts='.$ressymb;
                    630:             if ($newpostsflag) {
                    631:                 $discussion .= '&previous='.$prevread;
                    632:             }
                    633:             $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
                    634:                          $numhidden.' '.&mt('previously viewed posts').
                    635:                          '<br/></td></tr>';
                    636:         }
1.100     raeburn   637: 
                    638: # Choose sort mechanism
                    639:         my @showposts = ();
                    640:         if ($sortposts eq 'descdate') {
                    641:             @showposts = (sort { $b <=> $a } keys %alldiscussion);
                    642:         } elsif ($sortposts eq 'thread') {
                    643:             @showposts = (sort { $a <=> $b } keys %alldiscussion);
                    644:         } elsif ($sortposts eq 'subject') {
                    645:             foreach (sort keys %subjectsort) {
                    646:                 push @showposts, @{$subjectsort{$_}};
                    647:             }
                    648:         } elsif ($sortposts eq 'username') {
                    649:             foreach my $domain (sort keys %usernamesort) {
                    650:                 foreach (sort keys %{$usernamesort{$domain}}) {
                    651:                     push @showposts, @{$usernamesort{$domain}{$_}};
                    652:                 }
                    653:             }
                    654:         } elsif ($sortposts eq 'lastfirst') {
                    655:             foreach my $last (sort keys %namesort) {
                    656:                  foreach (sort keys %{$namesort{$last}}) {
                    657:                      push @showposts, @{$namesort{$last}{$_}};
                    658:                  }
                    659:             }
                    660:         } else {
                    661:             $sortposts = 'ascdate';
                    662:             @showposts =  (sort { $a <=> $b } keys %alldiscussion);
                    663:         }
                    664:         foreach (@showposts) {
                    665:             unless (($sortposts eq 'thread') || ($sortposts eq 'ascdate' && $ENV{'environment.threadeddiscussion'})) {
                    666:                 $alldiscussion{$_} = $_;
                    667:             }
1.101     raeburn   668:             unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {
1.95      sakharuk  669:                 if ($outputtarget ne 'tex') {
                    670: 		    $discussion.="\n<tr>";
                    671: 		} else {
                    672: 		    $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}';
                    673: 		}
1.80      raeburn   674: 	        my $thisdepth=$depth[$alldiscussion{$_}];
1.95      sakharuk  675:                 if ($outputtarget ne 'tex') {
                    676: 		    for (1..$thisdepth) {
                    677: 			$discussion.='<td>&nbsp;&nbsp;&nbsp;</td>';
                    678: 		    }
                    679: 		}
1.80      raeburn   680: 	        my $colspan=$maxdepth-$thisdepth+1;
1.95      sakharuk  681:                 if ($outputtarget ne 'tex') {
                    682: 		    $discussion.='<td  bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].'" colspan="'.$colspan.'">'.
1.80      raeburn   683:                              $discussionitems[$alldiscussion{$_}].
                    684: 	                     '</td></tr>';
1.95      sakharuk  685: 		} else {
                    686: 		    #cleanup block
                    687: 		    $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
                    688: 		    $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
                    689:                     my $threadinsert='';
                    690:                     if ($thisdepth > 0) {
                    691: 			$threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
                    692: 		    }
                    693: 		    $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
1.102     raeburn   694: 		    $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;
1.95      sakharuk  695:                     $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
1.96      albertel  696: 		    
                    697:                     #FIXME xmlparse can't be safely called from inside xmlparse
                    698:                     #   due to the global variables that are use, the safe
                    699:                     #   space etc. I expect this has unforseen issues that
                    700:                     #   need resolving.
                    701: 		    
                    702:                     $discussion.=&Apache::lonxml::xmlparse('','tex',$discussionitems[$alldiscussion{$_}]);
1.95      sakharuk  703: 		}
1.69      www       704: 	    }
1.80      raeburn   705:         }
1.95      sakharuk  706: 	if ($outputtarget ne 'tex') {
1.97      raeburn   707:             my $colspan=$maxdepth+1;
                    708:             $discussion .= <<END; 
                    709:             <tr bgcolor="#FFFFFF">
1.98      raeburn   710:              <td colspan="$colspan" valign="top">
1.97      raeburn   711:               <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
                    712:                <tr>
                    713:                 <td align="left">
                    714:                  <table border="0" cellpadding="0" cellspacing="4">
                    715:                   <tr>
                    716:                    <td>
                    717:                     <font size="-1"><b>$lt{'cuse'}</b>:</td>
                    718:                    <td>&nbsp;</td>
                    719: END
                    720:             if ($newpostsflag) {
                    721:                 $discussion .= 
                    722:                    '<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>';
                    723:             } else {
                    724:                 $discussion .=
                    725:                    '<td><font size="-1">'.$lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i></font></td>';
                    726:             }
                    727:             $discussion .= <<END;
                    728:                    <td>&nbsp;</td>
                    729:                    <td>
                    730:                     <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b></td>
                    731:                   </tr>
                    732:                  </table>
                    733:                 </td>
                    734:                </tr>
                    735:               </table>
                    736:              </td>
                    737:             </tr>
                    738:            </table>
                    739:            <br /><br />
                    740: END
1.95      sakharuk  741: 	}
1.54      www       742:     }
                    743:     if ($discussiononly) {
                    744: 	$discussion.=(<<ENDDISCUSS);
                    745: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
                    746: <input type="submit" name="discuss" value="Post Discussion" />
                    747: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
1.73      albertel  748: <input type="hidden" name="symb" value="$ressymb" />
1.54      www       749: <input type="hidden" name="sendit" value="true" />
                    750: <br />
                    751: <font size="1">Note: in anonymous discussion, your name is visible only to
                    752: course faculty</font><br />
1.78      raeburn   753: <b>Title:</b>&nbsp;<input type="text" name="subject" value="" size="30" /><br /><br />
1.94      www       754: <textarea name="comment" cols="80" rows="14" wrap="hard"></textarea>
1.54      www       755: <p>
                    756: Attachment (128 KB max size): <input type="file" name="attachment" />
                    757: </p>
                    758: </form>
                    759: ENDDISCUSS
1.95      sakharuk  760:         if ($outputtarget ne 'tex') {
                    761: 	    $discussion.=&generate_preview_button();
                    762: 	}
1.74      www       763:     } else {
1.92      albertel  764: 	if (&discussion_open($status) &&
1.90      albertel  765: 	    &Apache::lonnet::allowed('pch',
1.74      www       766: 				   $ENV{'request.course.id'}.
                    767: 	($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.95      sakharuk  768: 	    if ($outputtarget ne 'tex') {
                    769: 		$discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
                    770: 		    $symb.':::" '.$target.'>'.
                    771: 		    '<img src="/adm/lonMisc/chat.gif" border="0" />'.
                    772: 		    &mt('Post Discussion').'</a></td></tr></table>';
                    773: 	    }
1.100     raeburn   774: 	}
1.74      www       775:     }
1.54      www       776:    return $discussion;
                    777: }
1.1       www       778: 
1.6       albertel  779: sub mail_screen {
                    780:   my ($r,$feedurl,$options) = @_;
1.45      www       781:   my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
1.102     raeburn   782:                                           '','onLoad="window.focus();setposttype();"');
1.51      albertel  783:   my $title=&Apache::lonnet::gettitle($feedurl);
                    784:   if (!$title) { $title = $feedurl; }
1.69      www       785:   my $quote='';
1.78      raeburn   786:   my $subject = '';
1.102     raeburn   787:   my $oldmessage = '';
1.80      raeburn   788:   my $prevtag = '';
1.102     raeburn   789:   my $parentmsg = '';
                    790:   my $anonscript = (<<END);
                    791:   function setposttype() {
                    792:       return
                    793:   }
                    794: END
                    795:   if (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
                    796:       my ($symb,$idx);
                    797:       if ($ENV{'form.replydisc'}) {
                    798:           ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
                    799:       } else {
                    800:           ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
                    801:       }
1.69      www       802:       my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    803: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    804: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.80      raeburn   805:       unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.102     raeburn   806:           if ($ENV{'form.replydisc'}) {
                    807:               my $numoldver = 0;
                    808:               if ($contrib{$idx.':history'}) {
                    809:                   if ($contrib{$idx.':history'} =~ /:/) {
                    810:                       my @oldversions = split/:/,$contrib{$idx.':history'};
                    811:                       $numoldver = @oldversions;
                    812:                   } else {
                    813:                       $numoldver = 1;
                    814:                   }
                    815:               }
                    816: 	      my $message=$contrib{$idx.':message'};
                    817: 	      $message=~s/\n/\<br \/\>/g;
                    818: 	      $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message,undef,$numoldver).'</blockquote>';
                    819:               if ($idx > 0) {
                    820:                   if ($contrib{'subject'} =~ /::::\d+::::(.+)$/si) {
                    821:                       $subject = $1;
                    822:                   } else {
                    823:                       $subject = $contrib{$idx.':subject'};
                    824:                   }
                    825:                   $subject = 'Re: '.$subject;
                    826:               }
                    827:           } else {
                    828:               if ($contrib{$idx.':message'} =~ /::::\d+::::(.+)$/si) {
                    829:                   $oldmessage = $1;
                    830:               } else {
                    831:                   $oldmessage = $contrib{$idx.':message'};
                    832:               }
1.103     albertel  833: 	      $oldmessage=&HTML::Entities::encode($oldmessage,'<>&"');
1.102     raeburn   834:               if ($contrib{$idx.':subject'} =~ /::::\d+::::(.+)$/si) {
                    835:                   $subject = $1;
                    836:               } else {
                    837:                   $subject = $contrib{$idx.':subject'};
                    838:               }
                    839:               if (defined($contrib{$idx.':replyto'})) {
                    840:                   $parentmsg = $contrib{$idx.':replyto'};
                    841:               }
                    842:               my $anonflag = 0;
                    843:               if ($contrib{$idx.':anonymous'}) {
                    844:                   $anonflag = 1;
                    845:               }
                    846:               $anonscript = (<<END);
                    847:   function setposttype () {
                    848:       var currtype = $anonflag
                    849:       if (currtype == 1) {
                    850:           document.mailform.elements.discuss.checked = false
                    851:           document.mailform.elements.anondiscuss.checked = true
                    852:       }
                    853:       if (currtype == 0) {
                    854:           document.mailform.elements.anondiscuss.checked = false
                    855:           document.mailform.elements.discuss.checked = true
                    856:       }
                    857:       return
                    858:   }
                    859: END
1.79      raeburn   860:           }
1.69      www       861:       }
1.80      raeburn   862:       if ($ENV{'form.previous'}) {
                    863:           $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
                    864:       }
1.69      www       865:   }
1.85      www       866:   my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.86      www       867:   my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
1.74      www       868:   my $send=&mt('Send');
1.102     raeburn   869:   $r->print(<<END);
1.1       www       870: <html>
                    871: <head>
                    872: <title>The LearningOnline Network with CAPA</title>
1.7       albertel  873: <meta http-equiv="pragma" content="no-cache"></meta>
1.85      www       874: $htmlheader
1.63      albertel  875: <script type="text/javascript">
                    876: //<!--
1.5       www       877:     function gosubmit() {
                    878:         var rec=0;
1.12      albertel  879:         if (typeof(document.mailform.elements.author)!="undefined") {
1.5       www       880:           if (document.mailform.elements.author.checked) {
                    881:              rec=1;
                    882:           } 
                    883:         }
1.12      albertel  884:         if (typeof(document.mailform.elements.question)!="undefined") {
1.5       www       885:           if (document.mailform.elements.question.checked) {
                    886:              rec=1;
                    887:           } 
                    888:         }
1.12      albertel  889:         if (typeof(document.mailform.elements.course)!="undefined") {
1.5       www       890:           if (document.mailform.elements.course.checked) {
                    891:              rec=1;
                    892:           } 
                    893:         }
1.12      albertel  894:         if (typeof(document.mailform.elements.policy)!="undefined") {
1.5       www       895:           if (document.mailform.elements.policy.checked) {
                    896:              rec=1;
                    897:           } 
                    898:         }
1.12      albertel  899:         if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10      www       900:           if (document.mailform.elements.discuss.checked) {
                    901:              rec=1;
                    902:           } 
                    903:         }
1.14      www       904:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
                    905:           if (document.mailform.elements.anondiscuss.checked) {
                    906:              rec=1;
                    907:           } 
                    908:         }
1.5       www       909: 
                    910:         if (rec) {
1.105     www       911:             if (typeof(document.mailform.onsubmit)!='undefined') {
                    912: 		document.mailform.onsubmit();
                    913: 	    }
1.5       www       914: 	    document.mailform.submit();
                    915:         } else {
                    916:             alert('Please check a feedback type.');
                    917: 	}
                    918:     }
1.102     raeburn   919:     $anonscript
1.63      albertel  920: //-->
1.5       www       921: </script>
1.1       www       922: </head>
1.29      www       923: $bodytag
1.51      albertel  924: <h2><tt>$title</tt></h2>
1.43      www       925: <form action="/adm/feedback" method="post" name="mailform"
                    926: enctype="multipart/form-data">
1.80      raeburn   927: $prevtag
1.63      albertel  928: <input type="hidden" name="postdata" value="$feedurl" />
1.102     raeburn   929: END
                    930:   if ($ENV{'form.replydisc'}) {
                    931:       $r->print(<<END);
1.68      www       932: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
1.102     raeburn   933: END
                    934:   } elsif ($ENV{'form.editdisc'}) {
                    935:      $r->print(<<END);
                    936: <input type="hidden" name="editdisc" value ="$ENV{'form.editdisc'}" />
                    937: <input type="hidden" name="parentmsg" value ="$parentmsg" />
                    938: END
                    939:   }
                    940:   $r->print(<<ENDDOCUMENT);
1.5       www       941: Please check at least one of the following feedback types:
1.63      albertel  942: $options<hr />
1.69      www       943: $quote
1.63      albertel  944: <p>My question/comment/feedback:</p>
                    945: <p>
1.47      bowersj2  946: $latexHelp
1.78      raeburn   947: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
                    948: <p>
1.102     raeburn   949: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$oldmessage
1.63      albertel  950: </textarea></p>
                    951: <p>
1.42      www       952: Attachment (128 KB max size): <input type="file" name="attachment" />
                    953: </p>
                    954: <p>
                    955: <input type="hidden" name="sendit" value="1" />
1.74      www       956: <input type="button" value="$send" onClick='gosubmit();' />
1.42      www       957: </p>
1.2       www       958: </form>
1.1       www       959: ENDDOCUMENT
1.105     www       960: $r->print(&generate_preview_button().
1.94      www       961: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
1.85      www       962: '</body></html>');
1.6       albertel  963: }
                    964: 
1.97      raeburn   965: sub print_display_options {
                    966:     my ($r,$symb,$previous,$dispchg,$markchg,$feedurl) = @_;
1.98      raeburn   967:  # backward compatibility (bulletin boards used to be 'wrapped')
                    968:     if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                    969:         $feedurl=~s|^/adm/wrapper||;
                    970:     }
                    971: 
1.97      raeburn   972:     my $function = &Apache::loncommon::get_users_function();
                    973:     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
                    974:                                                     $ENV{'user.domain'});
                    975:     my $bodytag=&Apache::loncommon::bodytag('Discussion options',
                    976:                                           '','');
                    977: 
                    978:     my %lt = &Apache::lonlocal::texthash(
                    979:         'dido' => 'Discussion display options',
                    980:         'pref' => 'Display Preference',
                    981:         'curr' => 'Current setting ',
                    982:         'actn' => 'Action',
                    983:         'deff' => 'Default for all discussions',
                    984:         'prca' => 'Preferences can be set for this discussion that determine ....',
                    985:         'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
                    986:         'unwh' => 'Under what circumstances posts are identfied as "New."',
                    987:         'allposts' => 'All posts',
                    988:         'unread' => 'New posts only',
                    989:         'ondisp' => 'Once displayed',
                    990:         'onmark' => 'Once marked as read',
                    991:         'disa' => 'Posts displayed?',
                    992:         'npmr' => 'New posts cease to be identified as "New"?',
                    993:         'chgt' => 'Change to ',
                    994:         'mkdf' => 'Set to ',
                    995:         'yhni' => 'You have not indicated that you wish to change either of the discussion settings',
                    996:         'ywbr' => 'You will be returned to the previous page if you click OK.'
                    997:     );
                    998: 
                    999:     my $dispchange = $lt{'unread'};
                   1000:     my $markchange = $lt{'ondisp'};
                   1001:     my $currdisp = $lt{'allposts'};
                   1002:     my $currmark = $lt{'onmark'};
                   1003:     my $discdisp = 'allposts';
                   1004:     my $discmark = 'onmark';
                   1005:                                                                                       
                   1006:     if ($dispchg eq 'allposts') {
                   1007:         $dispchange = $lt{'allposts'};
                   1008:         $currdisp = $lt{'unread'};
                   1009:         $discdisp = 'unread';
                   1010:     }
                   1011:                                                                                       
                   1012:     if ($markchg eq 'markonread') {
                   1013:         $markchange = $lt{'onmark'};
                   1014:         $currmark = $lt{'ondisp'};
                   1015:         $discmark = 'ondisp';
                   1016:     }
                   1017:     $r->print(<<END);
                   1018: <html>
                   1019: <head>
                   1020: <title>$lt{'dido'}</title>
                   1021: <meta http-equiv="pragma" content="no-cache" />
                   1022: <script>
                   1023: function setDisp() {
                   1024:     var prev = "$previous"
                   1025:     var chktotal = 0
                   1026:     if (document.modifydisp.discdisp.checked == true) {
                   1027:         document.modifydisp.$dispchg.value = "$symb"
                   1028:         chktotal ++
                   1029:     }
                   1030:     if (document.modifydisp.discmark.checked == true) {
                   1031:         document.modifydisp.$markchg.value = "$symb"
                   1032:         chktotal ++
                   1033:     }
                   1034:     if (chktotal > 0) { 
                   1035:         document.modifydisp.submit()
                   1036:     } else {
                   1037:         if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}"))      {
                   1038:             if (prev > 0) {
                   1039:                 location.href = "$feedurl?previous=$previous"
                   1040:             } else {
                   1041:                 location.href = "$feedurl"
                   1042:             }
                   1043:         }
                   1044:     }
                   1045: }
                   1046: </script>
                   1047: </head>
                   1048: $bodytag
                   1049: <form name="modifydisp" method="post" action="/adm/feedback">
                   1050: $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
                   1051: <br />
                   1052: <table border="0" cellpadding="0" cellspacing="0">
                   1053:  <tr>
                   1054:   <td width="100%" bgcolor="#000000">
                   1055:    <table width="100%" border="0" cellpadding="1" cellspacing="0">
                   1056:     <tr>
                   1057:      <td width="100%" bgcolor="#000000">
                   1058:       <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                   1059:        <tr bgcolor="$tabcolor">
                   1060:         <td><b>$lt{'pref'}</b></td>
                   1061:         <td><b>$lt{'curr'}</b></td>
                   1062:         <td><b>$lt{'actn'}?</b></td>
                   1063:        </tr>
                   1064:        <tr bgcolor="#dddddd">
                   1065:        <td>$lt{'disa'}</td>
                   1066:        <td>$lt{$discdisp}</td>
                   1067:        <td><input type="checkbox" name="discdisp" />&nbsp;$lt{'chgt'} "$dispchange"</td>
                   1068:       </tr><tr bgcolor="#eeeeee">
                   1069:        <td>$lt{'npmr'}</td>
                   1070:        <td>$lt{$discmark}</td>
                   1071:        <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
                   1072:       </tr>
                   1073:      </table>
                   1074:     </td>
                   1075:    </tr>
                   1076:   </table>
                   1077:  </td>
                   1078: </tr>
                   1079: </table>
                   1080: <br />
                   1081: <br />
                   1082: <input type="hidden" name="previous" value="$previous" />
                   1083: <input type="hidden" name="$dispchg" value=""/>
                   1084: <input type="hidden" name="$markchg" value=""/>
                   1085: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
                   1086: <br />
                   1087: <br />
                   1088: </form>
                   1089: </body>
                   1090: </html>
                   1091: END
                   1092:     return;
                   1093: }
                   1094: 
1.100     raeburn  1095: sub print_sortfilter_options {
                   1096:     my ($r,$symb,$previous,$feedurl) = @_;
                   1097:  # backward compatibility (bulletin boards used to be 'wrapped')
                   1098:     if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1099:         $feedurl=~s|^/adm/wrapper||;
                   1100:     }
                   1101:     my @sections = ();
                   1102:     my $section_sel = '';
                   1103:     my $numsections = 0;
                   1104:     my $numvisible = 5;
                   1105:     my ($classlist) = &Apache::loncoursedata::get_classlist(
                   1106:                               $ENV{'request.course.id'},
                   1107:                               $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1108:                               $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1109:                                                                                    
                   1110:     my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   1111:     my $status_index = &Apache::loncoursedata::CL_STATUS();
                   1112:     my %sectioncount = ();
                   1113:     while (my ($student,$data) = each %$classlist) {
                   1114:         my ($section,$status) = ($data->[$sec_index],
                   1115:                                  $data->[$status_index]);
                   1116:         unless ($section eq '' || $section =~ /^\s*$/) {
                   1117:             if (!defined($sectioncount{$section})) {
                   1118:                 $sectioncount{$section} = 1;
                   1119:                 $numsections ++;
                   1120:             } else {
                   1121:                 $sectioncount{$section} ++;
                   1122:             }
                   1123:         }
                   1124:     }
                   1125:                                                                                    
                   1126:     if ($ENV{'request.course.sec'} !~ /^\s*$/) {
                   1127:         @sections = ($ENV{'request.course.sec'});
                   1128:         $numvisible = 1;
                   1129:     } else {
                   1130:         @sections = sort {$a cmp $b} keys(%sectioncount);
                   1131:         unshift(@sections,'all'); # Put 'all' at the front of the list
                   1132:         if ($numsections < 4) {
                   1133:             $numvisible = $numsections + 1;
                   1134:         }
                   1135:     }
                   1136:     foreach (@sections) {
                   1137:         $section_sel .= "  <option value=\"$_\" />$_\n";
                   1138:     }
                   1139:                                                                                    
                   1140:     my $function = &Apache::loncommon::get_users_function();
                   1141:     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
                   1142:                                                     $ENV{'user.domain'});
                   1143:     my $bodytag=&Apache::loncommon::bodytag('Discussion options',
                   1144:                                           '','');
                   1145:     my %lt = &Apache::lonlocal::texthash(
                   1146:         'diso' => 'Discussion sorting and filtering options',
                   1147:         'diop' => 'Display Options',
                   1148:         'curr' => 'Current setting ',
                   1149:         'actn' => 'Action',
1.101     raeburn  1150:         'prca' => 'Options can be set that control the sort order of the posts, in addition to which posts are displayed.',
1.100     raeburn  1151:         'soor' => 'Sort order',
                   1152:         'disp' => 'Specific user roles',
                   1153:         'actv' => 'Specific role status',
                   1154:         'spse' => 'Specific sections',
                   1155:         'psub' => 'Pick specific users (by name)',
1.101     raeburn  1156:         'shal' => 'Show a list of current posters'
1.100     raeburn  1157:     );
                   1158:     $r->print(<<END);
                   1159: <html>
                   1160: <head>
                   1161: <title>$lt{'diso'}</title>
                   1162: <meta http-equiv="pragma" content="no-cache" />
                   1163: </head>
                   1164: $bodytag
                   1165: <form name="modifyshown" method="post" action="/adm/feedback">
                   1166: <b>$lt{'diso'}</b><br/> $lt{'prca'}
                   1167: <br /><br />
                   1168: <table border="0">
                   1169:  <tr>
                   1170:   <td><b>$lt{'soor'}</b></td>
                   1171:   <td>&nbsp;</td>
                   1172:   <td><b>$lt{'disp'}</b></td>
                   1173:   <td>&nbsp;</td>
                   1174:   <td><b>$lt{'actv'}</b></td>
                   1175:   <td>&nbsp;</td>
                   1176:   <td><b>$lt{'spse'}</b></td>
                   1177:   <td>&nbsp;</td>
                   1178:   <td><b>$lt{'psub'}</b></td>
                   1179:  </tr>
                   1180:  <tr>
                   1181:   <td>
                   1182:    <select name="sortposts">
                   1183:     <option value="ascdate" />Date order - oldest first
                   1184:     <option value="descdate" />Date order - newest first
                   1185:     <option value="thread" />Threaded
                   1186:     <option value="subject" />By subject
                   1187:     <option value="username" />By domain and username
                   1188:     <option value="lastfirst" />By last name, first name
                   1189:    </select>
                   1190:   </td>
                   1191:   <td>&nbsp;</td>
                   1192:   <td>
1.101     raeburn  1193:    <select name="rolefilter" multiple="true" size="5">
1.100     raeburn  1194:     <option value="all" />All users
                   1195:     <option value="st" />Students
                   1196:     <option value="cc" />Course Coordinators
                   1197:     <option value="in" />Instructors
                   1198:     <option value="ta" />TAs
                   1199:     <option value="pr" />Exam proctors
                   1200:     <option value="cr" />Custom roles
                   1201:    </select>
                   1202:   </td>
                   1203:   <td>&nbsp;</td>
                   1204:   <td>
                   1205:    <select name="statusfilter">
                   1206:     <option value="all" />Roles of any status
1.101     raeburn  1207:     <option value="Active" />Only active roles
                   1208:     <option value="Expired" />Only inactive roles
1.100     raeburn  1209:    </select>
                   1210:   </td>
                   1211:   <td>&nbsp;</td>
                   1212:   <td>
                   1213:    <select name="sectionpick" multiple="true" size="$numvisible">
                   1214:     $section_sel
                   1215:    </select>
                   1216:   </td>
                   1217:   <td>&nbsp;</td>
                   1218:   <td><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</td>
                   1219:  </tr>
                   1220: </table>
                   1221: <br />
                   1222: <br />
                   1223: <input type="hidden" name="previous" value="$previous" />
                   1224: <input type="hidden" name="applysort" value="$symb" />
                   1225: <input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
                   1226: <br />
                   1227: <br />
                   1228: </form>
                   1229: </body>
                   1230: </html>
                   1231: END
                   1232: }
                   1233: 
1.101     raeburn  1234: sub print_showposters {
                   1235:     my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
                   1236:  # backward compatibility (bulletin boards used to be 'wrapped')
                   1237:     if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1238:         $feedurl=~s|^/adm/wrapper||;
                   1239:     }
                   1240: # backward compatibility (bulletin boards used to be 'wrapped')
                   1241:     my $ressymb=$symb;
                   1242:     if ($ressymb =~ /bulletin___\d+___/) {
                   1243:         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                   1244:             $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                   1245:         }
                   1246:     }
                   1247:     my $crs='/'.$ENV{'request.course.id'};
1.102     raeburn  1248:     if ($ENV{'request.course.sec'}) {
                   1249:         $crs.='_'.$ENV{'request.course.sec'};
                   1250:     }
1.101     raeburn  1251:     $crs=~s/\_/\//g;
                   1252:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
                   1253:     my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
                   1254:                           $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1255:                           $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1256:     my %namesort = ();
                   1257:     my %postcounts = ();
                   1258:     my %lt=&Apache::lonlocal::texthash(
                   1259:                      'diso' => 'Discussion filtering options',
                   1260:     );
                   1261:     my $bodytag=&Apache::loncommon::bodytag('Discussion options',
                   1262:                                           '','');
                   1263:     if ($contrib{'version'}) {
                   1264:         for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
                   1265:             my $hidden=($contrib{'hidden'}=~/\.$idx\./);
                   1266:             my $deleted=($contrib{'deleted'}=~/\.$idx\./);
                   1267:             unless ((($hidden) && (!$seeid)) || ($deleted)) {
                   1268:                 if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
                   1269:                     my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
                   1270:                     my $lastname = $names{'lastname'};
                   1271:                     my $firstname = $names{'firstname'};
                   1272:                     if ($lastname eq '') {
                   1273:                         $lastname = '_';
                   1274:                     }
                   1275:                     if ($firstname eq '') {
                   1276:                         $firstname = '_';
                   1277:                     }
                   1278:                     unless (defined($namesort{$lastname})) {
                   1279:                         %{$namesort{$lastname}} = ();
                   1280:                     }
                   1281:                     my $poster =  $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
                   1282:                     $postcounts{$poster} ++;
                   1283:                     if (defined($namesort{$lastname}{$firstname})) {
                   1284:                         if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
                   1285:                             push @{$namesort{$lastname}{$firstname}}, $poster;
                   1286:                         }
                   1287:                     } else {
                   1288:                         @{$namesort{$lastname}{$firstname}} = ("$poster");
                   1289:                     }
                   1290:                 }
                   1291:             }
                   1292:         }
                   1293:     }
                   1294:     $r->print(<<END);
                   1295: <html>
                   1296: <head>
                   1297: <title>$lt{'diso'}</title>
                   1298: <meta http-equiv="pragma" content="no-cache" />
                   1299: </head>
                   1300: $bodytag
                   1301:  <form name="pickpostersform" method="post">
                   1302:   <table border="0">
                   1303:    <tr>
                   1304:     <td bgcolor="#777777">
                   1305:      <table border="0" cellpadding="3">
                   1306:       <tr bgcolor="#e6ffff">
                   1307:        <td><b>No.</b></td>
                   1308:        <td><b>Select</b></td>
                   1309:        <td><b>Fullname</b><font color="#999999">(Username/domain)</font></td>
                   1310:        <td><b>Posts</td>
                   1311:       </tr>
                   1312: END
                   1313:     my $count = 0;
                   1314:     foreach my $last (sort keys %namesort) {
                   1315:         foreach my $first (sort keys %{$namesort{$last}}) {
                   1316:             foreach (sort @{$namesort{$last}{$first}}) {
                   1317:                 my ($uname,$udom) = split/:/,$_;
                   1318:                 if (!$uname || !$udom) { 
                   1319:                     next;
                   1320:                 } else {
                   1321:                     $count ++;
                   1322:                     $r->print('<tr bgcolor="#ffffe6"><td align="right">'.$count.'</td><td align="center"><input name="stuinfo" type="checkbox" value="'.$_.'" /></td><td>'.$last.', '.$first.' ('.$uname.','.$udom.')</td><td>'.$postcounts{$_}.'</td></tr>');
                   1323:                 }
                   1324:             }
                   1325:         }
                   1326:     }
                   1327:     $r->print(<<END);
                   1328:      </table>
                   1329:     </td>
                   1330:    </tr>
                   1331:   </table>
                   1332: <br />
                   1333: <input type="hidden" name="sortposts" value="$sortposts" />
                   1334: <input type="hidden" name="userpick" value="$symb" />
                   1335: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
                   1336: </form>
                   1337: </body>
                   1338: </html>
                   1339: END
                   1340: }
                   1341: 
1.6       albertel 1342: sub fail_redirect {
                   1343:   my ($r,$feedurl) = @_;
1.70      www      1344:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.6       albertel 1345:   $r->print (<<ENDFAILREDIR);
1.72      albertel 1346: <html>
1.5       www      1347: <head><title>Feedback not sent</title>
1.63      albertel 1348: <meta http-equiv="pragma" content="no-cache" />
                   1349: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5       www      1350: </head>
                   1351: <body bgcolor="#FFFFFF">
1.63      albertel 1352: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8       www      1353: <b>Sorry, no recipients  ...</b>
1.5       www      1354: </body>
                   1355: </html>
                   1356: ENDFAILREDIR
                   1357: }
1.4       www      1358: 
1.6       albertel 1359: sub redirect_back {
1.101     raeburn  1360:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$secpick,$numpicks) = @_;
1.100     raeburn  1361:   my $sorttag = '';
1.101     raeburn  1362:   my $roletag = '';
                   1363:   my $statustag = '';
                   1364:   my $sectag = '';
                   1365:   my $userpicktag = '';
                   1366:   my $qrystr = '';
1.80      raeburn  1367:   my $prevtag = '';
1.98      raeburn  1368:  # backward compatibility (bulletin boards used to be 'wrapped')
                   1369:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1370:       $feedurl=~s|^/adm/wrapper||;
                   1371:   }
1.70      www      1372:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80      raeburn  1373:   if ($previous > 0) {
                   1374:       $qrystr = 'previous='.$previous;
                   1375:       if ($feedurl =~ /\?register=1/) {
                   1376:           $feedurl .= '&'.$qrystr;
                   1377:       } else {
                   1378:           $feedurl .= '?'.$qrystr;
                   1379:       }
                   1380:       $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
                   1381:   }
1.100     raeburn  1382:   if (defined($sort)) {
                   1383:       my $sortqry = 'sortposts='.$sort;
                   1384:       if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
                   1385:           $feedurl .= '&'.$sortqry;
                   1386:       } else {
                   1387:           $feedurl .= '?'.$sortqry;
                   1388:       }
                   1389:       $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.101     raeburn  1390:       if ( (defined($numpicks)) && ($numpicks > 0) ) {
                   1391:           my $userpickqry = 'totposters='.$numpicks;
                   1392:           $feedurl .= '&'.$userpickqry;
                   1393:           $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
                   1394:       } else {
                   1395:           my $roleqry = 'rolefilter='.$rolefilter;
                   1396:           $feedurl .= '&'.$roleqry;
                   1397:           $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
                   1398:           $feedurl .= '&statusfilter='.$statusfilter;
                   1399:           $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
                   1400:           $feedurl .= '&sectionpick='.$secpick;
                   1401:           $sectag = '<input type="hidden" name="sectionpick" value="'.$secpick.'" />';
                   1402:       }
1.100     raeburn  1403:   }
1.6       albertel 1404:   $r->print (<<ENDREDIR);
1.72      albertel 1405: <html>
1.3       www      1406: <head>
                   1407: <title>Feedback sent</title>
1.63      albertel 1408: <meta http-equiv="pragma" content="no-cache" />
1.80      raeburn  1409: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2       www      1410: </head>
1.49      www      1411: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63      albertel 1412: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5       www      1413: $typestyle
1.32      albertel 1414: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63      albertel 1415: <font color="red">$status</font>
1.49      www      1416: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80      raeburn  1417: $prevtag
1.100     raeburn  1418: $sorttag
1.101     raeburn  1419: $statustag
                   1420: $roletag
                   1421: $sectag
                   1422: $userpicktag
1.49      www      1423: </form>
1.2       www      1424: </body>
                   1425: </html>
                   1426: ENDREDIR
                   1427: }
1.6       albertel 1428: 
                   1429: sub no_redirect_back {
                   1430:   my ($r,$feedurl) = @_;
1.107   ! www      1431:   my $nofeed=&mt('Sorry, no feedback possible on this resource  ...');
1.6       albertel 1432:   $r->print (<<ENDNOREDIR);
1.72      albertel 1433: <html>
1.2       www      1434: <head><title>Feedback not sent</title>
1.63      albertel 1435: <meta http-equiv="pragma" content="no-cache" />
1.7       albertel 1436: ENDNOREDIR
                   1437: 
1.8       www      1438:   if ($feedurl!~/^\/adm\/feedback/) { 
1.7       albertel 1439:     $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
                   1440:   }
                   1441:   
1.8       www      1442:   $r->print (<<ENDNOREDIRTWO);
1.2       www      1443: </head>
1.49      www      1444: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63      albertel 1445: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.107   ! www      1446: <b>$nofeed</b>
1.2       www      1447: </body>
                   1448: </html>
1.8       www      1449: ENDNOREDIRTWO
1.2       www      1450: }
1.6       albertel 1451: 
                   1452: sub screen_header {
1.65      www      1453:     my ($feedurl) = @_;
                   1454:     my $msgoptions='';
                   1455:     my $discussoptions='';
1.102     raeburn  1456:     unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
1.65      www      1457: 	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
                   1458: 	    $msgoptions= 
                   1459: 		'<p><input type="checkbox" name="author" /> '.
                   1460: 		&mt('Feedback to resource author').'</p>';
                   1461: 	}
                   1462: 	if (&feedback_available(1)) {
                   1463: 	    $msgoptions.=
                   1464: 		'<br /><input type="checkbox" name="question" /> '.
                   1465: 		&mt('Question about resource content');
                   1466: 	}
                   1467: 	if (&feedback_available(0,1)) {
                   1468: 	    $msgoptions.=
                   1469: 		'<br /><input type="checkbox" name="course" /> '.
                   1470: 		&mt('Question/Comment/Feedback about course content');
                   1471: 	}
                   1472: 	if (&feedback_available(0,0,1)) {
                   1473: 	    $msgoptions.=
                   1474: 		'<br /><input type="checkbox" name="policy" /> '.
                   1475: 		&mt('Question/Comment/Feedback about course policy');
                   1476: 	}
                   1477:     }
                   1478:     if ($ENV{'request.course.id'}) {
1.92      albertel 1479: 	if (&discussion_open() &&
1.90      albertel 1480: 	    &Apache::lonnet::allowed('pch',
1.65      www      1481: 				     $ENV{'request.course.id'}.
                   1482: 				     ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74      www      1483: 	    $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
                   1484: 		($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65      www      1485: 		&mt('Contribution to course discussion of resource');
                   1486: 	    $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
                   1487: 		&mt('Anonymous contribution to course discussion of resource').
                   1488: 		' <i>('.&mt('name only visible to course faculty').')</i>';
1.20      www      1489:       }
1.65      www      1490:     }
1.74      www      1491:     if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65      www      1492:     if ($discussoptions) { 
1.74      www      1493: 	$discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65      www      1494:     return $msgoptions.$discussoptions;
1.6       albertel 1495: }
                   1496: 
                   1497: sub resource_output {
                   1498:   my ($feedurl) = @_;
1.46      albertel 1499:   my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6       albertel 1500:   $usersaw=~s/\<body[^\>]*\>//gi;
                   1501:   $usersaw=~s/\<\/body\>//gi;
                   1502:   $usersaw=~s/\<html\>//gi;
                   1503:   $usersaw=~s/\<\/html\>//gi;
                   1504:   $usersaw=~s/\<head\>//gi;
                   1505:   $usersaw=~s/\<\/head\>//gi;
                   1506:   $usersaw=~s/action\s*\=/would_be_action\=/gi;
                   1507:   return $usersaw;
                   1508: }
                   1509: 
                   1510: sub clear_out_html {
1.39      www      1511:   my ($message,$override)=@_;
1.88      www      1512:   unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107   ! www      1513: # Always allow the <m>-tag
        !          1514:   my %html=(M=>1);
        !          1515: # Check if more is allowed
1.37      albertel 1516:   my $cid=$ENV{'request.course.id'};
1.39      www      1517:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
                   1518:       ($override)) {
1.37      albertel 1519:       # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> 
1.88      www      1520:       # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
                   1521:       # <SUP>
1.107   ! www      1522:       %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
        !          1523: 	     BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
        !          1524: 	     M=>1, SUB=>1, SUP=>1, SPAN=>1, 
        !          1525: 	     H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
        !          1526:   }
        !          1527: # Do the substitution of everything that is not explicitly allowed
        !          1528:   $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48      albertel 1529: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
1.107   ! www      1530:   $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48      albertel 1531: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
1.6       albertel 1532:   return $message;
                   1533: }
                   1534: 
                   1535: sub assemble_email {
1.40      albertel 1536:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6       albertel 1537:   my $email=<<"ENDEMAIL";
                   1538: Refers to <a href="$feedurl">$feedurl</a>
                   1539: 
                   1540: $message
                   1541: ENDEMAIL
                   1542:     my $citations=<<"ENDCITE";
                   1543: <h2>Previous attempts of student (if applicable)</h2>
                   1544: $prevattempts
1.63      albertel 1545: <br /><hr />
1.6       albertel 1546: <h2>Original screen output (if applicable)</h2>
                   1547: $usersaw
1.40      albertel 1548: <h2>Correct Answer(s) (if applicable)</h2>
                   1549: $useranswer
1.6       albertel 1550: ENDCITE
                   1551:   return ($email,$citations);
                   1552: }
                   1553: 
1.35      www      1554: sub secapply {
                   1555:     my $rec=shift;
1.36      www      1556:     my $defaultflag=shift;
                   1557:     $rec=~s/\s+//g;
                   1558:     $rec=~s/\@/\:/g;
                   1559:     my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
                   1560:     if ($sections) {
                   1561: 	foreach (split(/\;/,$sections)) {
                   1562:             if (($_ eq $ENV{'request.course.sec'}) ||
                   1563:                 ($defaultflag && ($_ eq '*'))) {
                   1564:                 return $adr; 
                   1565:             }
                   1566:         }
                   1567:     } else {
                   1568:        return $rec;
                   1569:     }
                   1570:     return '';
1.35      www      1571: }
                   1572: 
1.6       albertel 1573: sub decide_receiver {
1.36      www      1574:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6       albertel 1575:   my $typestyle='';
                   1576:   my %to=();
1.36      www      1577:   if ($ENV{'form.author'}||$author) {
1.8       www      1578:     $typestyle.='Submitting as Author Feedback<br>';
1.6       albertel 1579:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
                   1580:     $to{$2.':'.$1}=1;
                   1581:   }
1.36      www      1582:   if ($ENV{'form.question'}||$question) {
1.8       www      1583:     $typestyle.='Submitting as Question<br>';
1.24      harris41 1584:     foreach (split(/\,/,
                   1585: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
                   1586: 	     ) {
1.36      www      1587: 	my $rec=&secapply($_,$defaultflag);
                   1588:         if ($rec) { $to{$rec}=1; }
1.24      harris41 1589:     } 
1.6       albertel 1590:   }
1.36      www      1591:   if ($ENV{'form.course'}||$course) {
1.63      albertel 1592:     $typestyle.='Submitting as Comment<br />';
1.24      harris41 1593:     foreach (split(/\,/,
                   1594: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
                   1595: 	     ) {
1.36      www      1596: 	my $rec=&secapply($_,$defaultflag);
                   1597:         if ($rec) { $to{$rec}=1; }
1.24      harris41 1598:     } 
1.6       albertel 1599:   }
1.36      www      1600:   if ($ENV{'form.policy'}||$policy) {
1.63      albertel 1601:     $typestyle.='Submitting as Policy Feedback<br />';
1.24      harris41 1602:     foreach (split(/\,/,
                   1603: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
                   1604: 	     ) {
1.36      www      1605: 	my $rec=&secapply($_,$defaultflag);
                   1606:         if ($rec) { $to{$rec}=1; }
1.24      harris41 1607:     } 
1.6       albertel 1608:   }
1.36      www      1609:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
                   1610:      ($typestyle,%to)=
                   1611: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
                   1612:   }
1.6       albertel 1613:   return ($typestyle,%to);
1.36      www      1614: }
                   1615: 
                   1616: sub feedback_available {
                   1617:     my ($question,$course,$policy)=@_;
                   1618:     my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
                   1619:     return scalar(%to);
1.6       albertel 1620: }
                   1621: 
                   1622: sub send_msg {
1.43      www      1623:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6       albertel 1624:   my $status='';
                   1625:   my $sendsomething=0;
1.24      harris41 1626:   foreach (keys %to) {
1.6       albertel 1627:     if ($_) {
1.22      www      1628:       my $declutter=&Apache::lonnet::declutter($feedurl);
1.8       www      1629:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43      www      1630:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
                   1631:                 $attachmenturl)=~/ok/) {
1.63      albertel 1632: 	$status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6       albertel 1633:       } else {
                   1634: 	$sendsomething++;
                   1635:       }
                   1636:     }
1.24      harris41 1637:   }
1.18      www      1638: 
                   1639:     my %record=&Apache::lonnet::restore('_feedback');
                   1640:     my ($temp)=keys %record;
                   1641:     unless ($temp=~/^error\:/) {
                   1642:        my %newrecord=();
                   1643:        $newrecord{'resource'}=$feedurl;
                   1644:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
                   1645:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63      albertel 1646: 	   $status.='<br />'.&mt('Not registered').'<br />';
1.18      www      1647:        }
                   1648:     }
                   1649:        
1.6       albertel 1650:   return ($status,$sendsomething);
                   1651: }
                   1652: 
1.13      www      1653: sub adddiscuss {
1.78      raeburn  1654:     my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13      www      1655:     my $status='';
1.92      albertel 1656:     if (&discussion_open() &&
1.90      albertel 1657: 	&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1.23      www      1658:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20      www      1659: 
1.13      www      1660:     my %contrib=('message'      => $email,
                   1661:                  'sendername'   => $ENV{'user.name'},
1.26      www      1662:                  'senderdomain' => $ENV{'user.domain'},
                   1663:                  'screenname'   => $ENV{'environment.screenname'},
                   1664:                  'plainname'    => $ENV{'environment.firstname'}.' '.
                   1665: 		                   $ENV{'environment.middlename'}.' '.
                   1666:                                    $ENV{'environment.lastname'}.' '.
1.42      www      1667:                                    $ENV{'enrironment.generation'},
1.78      raeburn  1668:                  'attachmenturl'=> $attachmenturl,
                   1669:                  'subject'      => $subject);
1.65      www      1670:     if ($ENV{'form.replydisc'}) {
1.66      www      1671: 	$contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65      www      1672:     }
1.14      www      1673:     if ($anon) {
                   1674: 	$contrib{'anonymous'}='true';
                   1675:     }
1.13      www      1676:     if (($symb) && ($email)) {
1.102     raeburn  1677:         if ($ENV{'form.editdisc'}) {
                   1678:             my %newcontrib = ();
                   1679:             $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
                   1680:             $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
                   1681:             $contrib{'timestamp'} = time;
                   1682:             $contrib{'history'} = '';
                   1683:             my $numoldver = 0;
                   1684:             my ($oldsymb,$oldidx)=split(/\:\:\:/,$ENV{'form.editdisc'});
                   1685: # get timestamp for last post and history
                   1686:             my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
                   1687:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1688:                      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1689:             if (defined($oldcontrib{$oldidx.':replyto'})) {
                   1690:                 $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
                   1691:             }
                   1692:             if (defined($oldcontrib{$oldidx.':history'})) {
                   1693:                 if ($oldcontrib{$oldidx.':history'} =~ /:/) {
                   1694:                     my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
                   1695:                     $numoldver = @oldversions;
                   1696:                 } else {
                   1697:                     $numoldver = 1;
                   1698:                 }
                   1699:                 $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
                   1700:             }
                   1701:             if (defined($oldcontrib{$oldidx.':subject'})) {
                   1702:                 $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.'::::'.$numoldver.'::::'.$contrib{'subject'};            
                   1703:             } 
                   1704:             if (defined($oldcontrib{$oldidx.':message'})) {
                   1705:                 $contrib{'message'} = $oldcontrib{$oldidx.':message'}.'::::'.$numoldver.'::::'.$contrib{'message'};
                   1706:             }
                   1707:             $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
                   1708:             foreach (keys %contrib) {
                   1709:                 my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;                                                                               
                   1710:                 $newcontrib{$key} = $contrib{$_};
                   1711:             }
                   1712:             my $put_reply = &Apache::lonnet::putstore($ENV{'request.course.id'},
                   1713:                   \%newcontrib,
                   1714:                   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1715:                   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1716:             $status='Editing class discussion'.($anon?' (anonymous)':'');
                   1717:         } else {
                   1718:            $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
                   1719:            &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1.13      www      1720:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17      www      1721: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.102     raeburn  1722:         }
1.21      www      1723:         my %storenewentry=($symb => time);
1.63      albertel 1724:         $status.='<br />'.&mt('Updating discussion time').': '.
1.21      www      1725:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
                   1726:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1727: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13      www      1728:     }
1.17      www      1729:     my %record=&Apache::lonnet::restore('_discussion');
                   1730:     my ($temp)=keys %record;
                   1731:     unless ($temp=~/^error\:/) {
                   1732:        my %newrecord=();
                   1733:        $newrecord{'resource'}=$symb;
                   1734:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63      albertel 1735:        $status.='<br />'.&mt('Registering').': '.
1.21      www      1736:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20      www      1737:     }
                   1738:     } else {
                   1739: 	$status.='Failed.';
1.17      www      1740:     }
1.63      albertel 1741:     return $status.'<br />';   
1.13      www      1742: }
                   1743: 
1.33      www      1744: # ----------------------------------------------------------- Preview function
                   1745: 
                   1746: sub show_preview {
                   1747:     my $r=shift;
                   1748:     my $message=&clear_out_html($ENV{'form.comment'});
                   1749:     $message=~s/\n/\<br \/\>/g;
1.106     www      1750:     $message=&Apache::lonspeller::markeduptext($message);
1.33      www      1751:     $message=&Apache::lontexconvert::msgtexconverted($message);
1.78      raeburn  1752:     my $subject=&clear_out_html($ENV{'form.subject'});
                   1753:     $subject=~s/\n/\<br \/\>/g;
                   1754:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33      www      1755:     $r->print('<table border="2"><tr><td>'.
1.78      raeburn  1756:        '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33      www      1757:        $message.'</td></tr></table>');
                   1758: }
                   1759: 
                   1760: sub generate_preview_button {
1.107   ! www      1761:     my $pre=&mt("Show Preview and Check Spelling");
1.33      www      1762:     return(<<ENDPREVIEW);
                   1763: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78      raeburn  1764: <input type="hidden" name="subject">
1.33      www      1765: <input type="hidden" name="comment" />
1.65      www      1766: <input type="button" value="$pre"
1.105     www      1767: onClick="if (typeof(document.mailform.onsubmit)!='undefined') {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      1768: </form>
                   1769: ENDPREVIEW
                   1770: }
1.71      www      1771: 
1.6       albertel 1772: sub handler {
                   1773:   my $r = shift;
1.8       www      1774:   if ($r->header_only) {
1.71      www      1775:      &Apache::loncommon::content_type($r,'text/html');
1.8       www      1776:      $r->send_http_header;
                   1777:      return OK;
                   1778:   }
1.15      www      1779: 
                   1780: # --------------------------- Get query string for limited number of parameters
                   1781: 
1.97      raeburn  1782:   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.102     raeburn  1783:          ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick']);
1.101     raeburn  1784:   if ($ENV{'form.posterlist'}) {
                   1785:       &Apache::loncommon::content_type($r,'text/html');
                   1786:       $r->send_http_header;
                   1787:       my $symb=$ENV{'form.posterlist'};
                   1788:       my $sortposts = $ENV{'form.sortposts'};
                   1789:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1790:       my $previous=$ENV{'form.previous'};
                   1791:       my $feedurl = &Apache::lonnet::clutter($url);
                   1792:  # backward compatibility (bulletin boards used to be 'wrapped')
                   1793:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1794:           $feedurl=~s|^/adm/wrapper||;
                   1795:       }
                   1796:       &print_showposters($r,$symb,$previous,$feedurl,$sortposts);
                   1797:       return OK;
                   1798:   }
                   1799:   if ($ENV{'form.userpick'}) {
                   1800:       &Apache::loncommon::content_type($r,'text/html');
                   1801:       $r->send_http_header;
                   1802:       my $symb=$ENV{'form.userpick'};
                   1803:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1804:       my $previous=$ENV{'form.previous'};
                   1805: # backward compatibility (bulletin boards used to be 'wrapped')
                   1806:       my $ressymb=$symb;
                   1807:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                   1808:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                   1809:       }
                   1810:       my $sort=$ENV{'form.sortposts'};
                   1811:       my @posters = ();
                   1812:       if (ref($ENV{'form.stuinfo'}) eq 'ARRAY') {
                   1813:           @posters = $ENV{'form.stuinfo'};
                   1814:       } else {
                   1815:           $posters[0] = $ENV{'form.stuinfo'};
                   1816:       }
                   1817:       my $numpicks = @posters;
                   1818:       if (defined($ENV{'form.userpick'})) {
                   1819:           my %discinfo = ();
                   1820:           $discinfo{$ressymb.'_userpick'} = join('&',@posters);
                   1821:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                   1822:       }
                   1823:       my $feedurl = &Apache::lonnet::clutter($url);
                   1824:  # backward compatibility (bulletin boards used to be 'wrapped')
                   1825:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1826:           $feedurl=~s|^/adm/wrapper||;
                   1827:       }
                   1828:       &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,'','','',$numpicks);
                   1829:       return OK;
                   1830:   }
1.100     raeburn  1831:   if ($ENV{'form.applysort'}) {
                   1832:       &Apache::loncommon::content_type($r,'text/html');
                   1833:       $r->send_http_header;
                   1834:       my $symb=$ENV{'form.applysort'};
                   1835:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1836:       my $previous=$ENV{'form.previous'};
                   1837:       my $sort = $ENV{'form.sortposts'};
1.101     raeburn  1838:       my $rolefilter = $ENV{'form.rolefilter'};
1.100     raeburn  1839:       my $statusfilter = $ENV{'form.statusfilter'};
                   1840:       my $secpick = $ENV{'form.sectionpick'};
                   1841:       my $feedurl = &Apache::lonnet::clutter($url);
                   1842:  # backward compatibility (bulletin boards used to be 'wrapped')
                   1843:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1844:           $feedurl=~s|^/adm/wrapper||;
                   1845:       }
1.101     raeburn  1846:       &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,$rolefilter,$statusfilter,$secpick);
1.100     raeburn  1847:       return OK;
                   1848:   } elsif ($ENV{'form.sortfilter'}) {
                   1849:       &Apache::loncommon::content_type($r,'text/html');
                   1850:       $r->send_http_header;
                   1851:       my $symb=$ENV{'form.sortfilter'};
                   1852:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1853:       my $previous=$ENV{'form.previous'};
                   1854:       my $feedurl = &Apache::lonnet::clutter($url);
                   1855:  # backward compatibility (bulletin boards used to be 'wrapped')
                   1856:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1857:           $feedurl=~s|^/adm/wrapper||;
                   1858:       }
                   1859:       &print_sortfilter_options($r,$symb,$previous,$feedurl);
                   1860:       return OK;
                   1861:   } elsif ($ENV{'form.navmaps'}) {
1.99      raeburn  1862:       my %discinfo = ();
                   1863:       my @resources = ();
                   1864:       if ($ENV{'form.navmaps'} =~ /:/) {
                   1865:           @resources = split/:/,$ENV{'form.navmaps'};
                   1866:       } else {
                   1867:           @resources = ("$ENV{'form.navmaps'}");
                   1868:       }
                   1869:       my $numitems = @resources;
                   1870:       my $feedurl = '/adm/navmaps';
                   1871:       if ($ENV{'form.navurl'}) {
                   1872:           $feedurl .= '?'.$ENV{'form.navurl'};
                   1873:       }
                   1874:       my %lt = &Apache::lonlocal::texthash(
                   1875:           'mnpa' => 'Marked "New" posts as read in a total of',
                   1876:           'robb' => 'resources/bulletin boards.'
                   1877:       );       
                   1878:       foreach (@resources) {
                   1879: # backward compatibility (bulletin boards used to be 'wrapped')
                   1880:           my $ressymb=$_;
                   1881:           if ($ressymb =~ m/bulletin___\d+___/) {
                   1882:               unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                   1883:                   $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
                   1884:               }
                   1885:           }
                   1886:           my $lastkey = $ressymb.'_lastread';
                   1887:           $discinfo{$lastkey} = time;
                   1888:       }
                   1889:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                   1890:       &Apache::loncommon::content_type($r,'text/html');
                   1891:       $r->send_http_header;
                   1892:       $r->print (<<ENDREDIR);
                   1893: <html>
                   1894: <head>
                   1895: <title>New posts marked as read</title>
                   1896: <meta http-equiv="pragma" content="no-cache" />
                   1897: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
                   1898: </head>
                   1899: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
                   1900: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
                   1901: <b>$lt{'mnpa'} $numitems $lt{'robb'}</b>
                   1902: <form name="reldt" action="$feedurl" target="loncapaclient">
                   1903: </form>
                   1904: </body>
                   1905: </html>
                   1906: ENDREDIR
                   1907:       return OK;
                   1908:   } elsif ($ENV{'form.modifydisp'}) {
1.84      raeburn  1909:       &Apache::loncommon::content_type($r,'text/html');
                   1910:       $r->send_http_header;
1.97      raeburn  1911:       my $symb=$ENV{'form.modifydisp'};
1.84      raeburn  1912:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.97      raeburn  1913:       my $previous=$ENV{'form.previous'};
                   1914:       my ($dispchg,$markchg) = split/_/,$ENV{'form.changes'};
                   1915:       my $feedurl = &Apache::lonnet::clutter($url);
1.98      raeburn  1916:  # backward compatibility (bulletin boards used to be 'wrapped')  
                   1917:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1918:           $feedurl=~s|^/adm/wrapper||;
                   1919:       }
1.97      raeburn  1920:       &print_display_options($r,$symb,$previous,$dispchg,$markchg,$feedurl);
                   1921:       return OK;
                   1922:   } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
                   1923:       &Apache::loncommon::content_type($r,'text/html');
                   1924:       $r->send_http_header;
                   1925:       my $previous=$ENV{'form.previous'};
                   1926:       my ($map,$ind,$url);
                   1927:       if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
                   1928: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
                   1929:           my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
                   1930:           my $ressymb = $symb;
                   1931:           ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1932:           unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                   1933:               $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                   1934:           }
                   1935:           my %discinfo = ();
                   1936:           my $lastkey = $ressymb.'_lastread';
                   1937:           my $ondispkey = $ressymb.'_markondisp';
                   1938:           if ($ENV{'form.markondisp'}) {
                   1939:               $discinfo{$lastkey} = time;
                   1940:               $discinfo{$ondispkey} = 1;
                   1941:           } elsif ($ENV{'form.markonread'}) {
                   1942:               if ( $previous > 0 ) {
                   1943:                   $discinfo{$lastkey} = $previous;
                   1944:               }
                   1945:               $discinfo{$ondispkey} = 0;
                   1946:           }
                   1947:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84      raeburn  1948:       }
1.97      raeburn  1949:       if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
                   1950: # ----------------------------------------------------------------- Modify display setting for this discussion 
                   1951:           my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
                   1952:           my $ressymb = $symb;
                   1953:           ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1954:           unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                   1955:               $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                   1956:           }
                   1957:           my %discinfo = ();
                   1958:           if ($ENV{'form.allposts'}) {
                   1959:               $discinfo{$ressymb.'_showonlyunread'} = 0;
                   1960:           } elsif ($ENV{'form.onlyunread'}) {
                   1961:               $discinfo{$ressymb.'_showonlyunread'} = 1;
1.84      raeburn  1962:           }
1.97      raeburn  1963:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84      raeburn  1964:       }
1.97      raeburn  1965:       if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
                   1966:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
                   1967:       } else {
1.84      raeburn  1968:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
                   1969:       }
                   1970:       return OK;
                   1971:   } elsif ($ENV{'form.markread'}) {
                   1972: # ----------------------------------------------------------------- Mark new posts as read
                   1973:       &Apache::loncommon::content_type($r,'text/html');
                   1974:       $r->send_http_header;
                   1975:       my $symb=$ENV{'form.markread'};
                   1976:       my $ressymb = $symb;
                   1977:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1978:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                   1979:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1.78      raeburn  1980:       }
1.84      raeburn  1981:       my %discinfo = ();
                   1982:       my $lastkey = $ressymb.'_lastread';
                   1983:       $discinfo{$lastkey} = time;
                   1984:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                   1985:       &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1.78      raeburn  1986:       return OK;
                   1987:   } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15      www      1988: # ----------------------------------------------------------------- Hide/unhide
1.71      www      1989:     &Apache::loncommon::content_type($r,'text/html');
1.15      www      1990:     $r->send_http_header;
                   1991: 
                   1992:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
                   1993: 
                   1994:     my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52      www      1995:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15      www      1996: 
                   1997:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                   1998:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1999: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   2000: 
                   2001:         
                   2002:     my $currenthidden=$contrib{'hidden'};
1.102     raeburn  2003:     my $currentstudenthidden=$contrib{'studenthidden'};
                   2004: 
                   2005:     my $crs='/'.$ENV{'request.course.id'};
                   2006:     if ($ENV{'request.course.sec'}) {
                   2007:         $crs.='_'.$ENV{'request.course.sec'};
                   2008:     }
                   2009:     $crs=~s/\_/\//g;
                   2010:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.15      www      2011:     
                   2012:     if ($ENV{'form.hide'}) {
                   2013: 	$currenthidden.='.'.$idx.'.';
1.102     raeburn  2014:         unless ($seeid) {
                   2015:             $currentstudenthidden.='.'.$idx.'.';
                   2016:         }
1.15      www      2017:     } else {
                   2018:         $currenthidden=~s/\.$idx\.//g;
                   2019:     }
                   2020:     my %newhash=('hidden' => $currenthidden);
1.102     raeburn  2021:     if ( ($ENV{'form.hide'}) && (!$seeid) ) {
                   2022:         $newhash{'studenthidden'} = $currentstudenthidden;
                   2023:     }
1.38      www      2024: 
                   2025:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                   2026:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   2027: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   2028: 
                   2029:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn  2030:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69      www      2031:   } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72      albertel 2032:       &Apache::loncommon::content_type($r,'text/html');
                   2033:       $r->send_http_header;
1.69      www      2034:       if ($ENV{'form.threadedon'}) {
                   2035: 	  &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
                   2036: 	  &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
                   2037:       } else {
                   2038:  	  &Apache::lonnet::del('environment',['threadeddiscussion']);
                   2039: 	  &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72      albertel 2040:       }
1.69      www      2041:       my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
                   2042:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   2043:       &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn  2044: 		     &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38      www      2045:   } elsif ($ENV{'form.deldisc'}) {
                   2046: # --------------------------------------------------------------- Hide for good
1.71      www      2047:     &Apache::loncommon::content_type($r,'text/html');
1.38      www      2048:     $r->send_http_header;
                   2049: 
                   2050:     my $entry=$ENV{'form.deldisc'};
                   2051: 
                   2052:     my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52      www      2053:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38      www      2054: 
                   2055:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                   2056:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   2057: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   2058: 
                   2059:         
                   2060:     my $currentdeleted=$contrib{'deleted'};
                   2061:     
                   2062:     $currentdeleted.='.'.$idx.'.';
                   2063: 
                   2064:     my %newhash=('deleted' => $currentdeleted);
1.15      www      2065: 
                   2066:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                   2067:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   2068: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   2069: 
1.30      www      2070:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn  2071:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33      www      2072:   } elsif ($ENV{'form.preview'}) {
                   2073: # -------------------------------------------------------- User wants a preview
1.76      albertel 2074:       $r->content_type('text/html');
                   2075:       $r->send_http_header;
1.33      www      2076:       &show_preview($r);
1.15      www      2077:   } else {
                   2078: # ------------------------------------------------------------- Normal feedback
1.6       albertel 2079:   my $feedurl=$ENV{'form.postdata'};
                   2080:   $feedurl=~s/^http\:\/\///;
                   2081:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                   2082:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62      www      2083:   $feedurl=~s/\?.+$//;
1.8       www      2084: 
1.66      www      2085:   my $symb;
                   2086:   if ($ENV{'form.replydisc'}) {
                   2087:       $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
                   2088:       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
                   2089:       $feedurl=&Apache::lonnet::clutter($url);
1.102     raeburn  2090:   } elsif ($ENV{'form.editdisc'}) {
                   2091:       $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
                   2092:       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
                   2093:       $feedurl=&Apache::lonnet::clutter($url);
1.66      www      2094:   } else {
                   2095:       $symb=&Apache::lonnet::symbread($feedurl);
                   2096:   }
1.31      www      2097:   unless ($symb) {
                   2098:       $symb=$ENV{'form.symb'};
                   2099:       if ($symb) {
1.52      www      2100: 	  my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31      www      2101:           $feedurl=&Apache::lonnet::clutter($url);
                   2102:       }
                   2103:   }
1.8       www      2104:   my $goahead=1;
                   2105:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                   2106:       unless ($symb) { $goahead=0; }
                   2107:   }
1.98      raeburn  2108:   # backward compatibility (bulletin boards used to be 'wrapped')
1.73      albertel 2109:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   2110:       $feedurl=~s|^/adm/wrapper||;
                   2111:   }
1.8       www      2112:   if ($goahead) {
                   2113: # Go ahead with feedback, no ambiguous reference
1.71      www      2114:     &Apache::loncommon::content_type($r,'text/html');
1.8       www      2115:     $r->send_http_header;
1.6       albertel 2116:   
1.8       www      2117:     if (
1.7       albertel 2118:       (
                   2119:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
                   2120:       ) 
                   2121:       || 
                   2122:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31      www      2123:       ||
                   2124:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7       albertel 2125:      ) {
1.6       albertel 2126: # --------------------------------------------------- Print login screen header
                   2127:     unless ($ENV{'form.sendit'}) {
                   2128:       my $options=&screen_header($feedurl);
                   2129:       if ($options) {
                   2130: 	&mail_screen($r,$feedurl,$options);
                   2131:       } else {
                   2132: 	&fail_redirect($r,$feedurl);
                   2133:       }
                   2134:     } else {
                   2135:       
                   2136: # Get previous user input
1.9       albertel 2137:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11      albertel 2138:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9       albertel 2139:             $ENV{'request.course.id'});
1.6       albertel 2140: 
                   2141: # Get output from resource
                   2142:       my $usersaw=&resource_output($feedurl);
                   2143: 
1.50      albertel 2144: # Get resource answer (need to allow student to view grades for this to work)
                   2145:       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40      albertel 2146:       my $useranswer=&Apache::loncommon::get_student_answers(
                   2147:                        $symb,$ENV{'user.name'},$ENV{'user.domain'},
                   2148: 		       $ENV{'request.course.id'});
1.50      albertel 2149:       &Apache::lonnet::delenv('allowed.vgr');
1.42      www      2150: # Get attachments, if any, and not too large
                   2151:       my $attachmenturl='';
                   2152:       if ($ENV{'form.attachment.filename'}) {
                   2153: 	  unless (length($ENV{'form.attachment'})>131072) {
1.82      albertel 2154: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42      www      2155: 	  }
                   2156:       }
1.6       albertel 2157: # Filter HTML out of message (could be nasty)
1.39      www      2158:       my $message=&clear_out_html($ENV{'form.comment'});
1.6       albertel 2159: 
                   2160: # Assemble email
1.8       www      2161:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40      albertel 2162:           $usersaw,$useranswer);
                   2163:  
1.6       albertel 2164: # Who gets this?
                   2165:       my ($typestyle,%to) = &decide_receiver($feedurl);
                   2166: 
                   2167: # Actually send mail
1.43      www      2168:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
                   2169:           $attachmenturl,%to);
1.13      www      2170: 
                   2171: # Discussion? Store that.
                   2172: 
1.32      albertel 2173:       my $numpost=0;
1.13      www      2174:       if ($ENV{'form.discuss'}) {
1.78      raeburn  2175:           my $subject = &clear_out_html($ENV{'form.subject'});
                   2176: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32      albertel 2177: 	  $numpost++;
1.13      www      2178:       }
1.6       albertel 2179: 
1.14      www      2180:       if ($ENV{'form.anondiscuss'}) {
1.78      raeburn  2181:           my $subject = &clear_out_html($ENV{'form.subject'});
                   2182: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32      albertel 2183: 	  $numpost++;
1.14      www      2184:       }
                   2185: 
                   2186: 
1.6       albertel 2187: # Receipt screen and redirect back to where came from
1.80      raeburn  2188:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6       albertel 2189: 
                   2190:     }
1.8       www      2191:    } else {
1.7       albertel 2192: # Unable to give feedback
1.6       albertel 2193:     &no_redirect_back($r,$feedurl);
1.8       www      2194:    }
                   2195:   } else {
                   2196: # Ambiguous Problem Resource
1.60      albertel 2197:       if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53      albertel 2198: 	  &Apache::lonnet::cleanenv();
1.58      albertel 2199:       }
1.53      albertel 2200:       $r->internal_redirect('/adm/ambiguous');
1.6       albertel 2201:   }
1.15      www      2202: }
1.6       albertel 2203:   return OK;
1.1       www      2204: } 
                   2205: 
                   2206: 1;
                   2207: __END__

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