File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.130: download - view: text, annotated - select for diffs
Thu Nov 11 22:47:55 2004 UTC (19 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- adding use lonenc in needed places
- reenabling encrypturl in DOCS

    1: # The LearningOnline Network
    2: # Feedback
    3: #
    4: # $Id: lonfeedback.pm,v 1.130 2004/11/11 22:47:55 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::lonfeedback;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common);
   34: use Apache::lonmsg();
   35: use Apache::loncommon();
   36: use Apache::lontexconvert();
   37: use Apache::lonlocal; # must not have ()
   38: use Apache::lonhtmlcommon();
   39: use Apache::lonnavmaps;
   40: use Apache::lonenc();
   41: use HTML::LCParser();
   42: use Apache::lonspeller();
   43: use Cwd;
   44: 
   45: sub discussion_open {
   46:     my ($status,$symb)=@_;
   47:     if (defined($status) &&
   48: 	!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
   49: 	  || $status eq 'OPEN')) {
   50: 	return 0;
   51:     }
   52:     my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb);
   53:     if (defined($close) && $close ne '' && $close < time) {
   54: 	return 0;
   55:     }
   56:     return 1;
   57: }
   58: 
   59: sub discussion_visible {
   60:     my ($status)=@_;
   61:     if (not &discussion_open($status)) {
   62: 	my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
   63: 	if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden))  {
   64: 	    if (!$ENV{'request.role.adv'}) { return 0; }
   65: 	}
   66:     }
   67:     return 1;
   68: }
   69: 
   70: sub list_discussion {
   71:     my ($mode,$status,$symb)=@_;
   72:     my $outputtarget=$ENV{'form.grade_target'};
   73:     if (defined($ENV{'form.export'})) {
   74: 	if($ENV{'form.export'}) {
   75:             $outputtarget = 'export';
   76:         }
   77:     }    
   78:     if (not &discussion_visible($status)) { return ''; }
   79:     my @bgcols = ("#cccccc","#eeeeee");
   80:     my $discussiononly=0;
   81:     if ($mode eq 'board') { $discussiononly=1; }
   82:     unless ($ENV{'request.course.id'}) { return ''; }
   83:     my $crs='/'.$ENV{'request.course.id'};
   84:     my $cid=$ENV{'request.course.id'};
   85:     if ($ENV{'request.course.sec'}) {
   86: 	$crs.='_'.$ENV{'request.course.sec'};
   87:     }                 
   88:     $crs=~s/\_/\//g;
   89:     unless ($symb) {
   90: 	$symb=&Apache::lonnet::symbread();
   91:     }
   92:     unless ($symb) { return ''; }
   93:     my %usernamesort = ();
   94:     my %namesort =();
   95:     my %subjectsort = ();
   96: # backward compatibility (bulletin boards used to be 'wrapped')
   97:     my $ressymb=$symb;
   98:     if ($mode eq 'board') {
   99:         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
  100:             $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
  101:         }
  102:     }
  103:     $ressymb=&Apache::lonenc::check_encrypt($ressymb);
  104: # Get discussion display settings for this discussion
  105:     my $lastkey = $ressymb.'_lastread';
  106:     my $showkey = $ressymb.'_showonlyunread';
  107:     my $markkey = $ressymb.'_showonlyunmark',
  108:     my $visitkey = $ressymb.'_visit';
  109:     my $ondispkey = $ressymb.'_markondisp';
  110:     my $userpickkey = $ressymb.'_userpick';
  111:     my $toggkey = $ressymb.'_readtoggle';
  112:     my $readkey = $ressymb.'_read';
  113: 
  114:     my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$ENV{'user.domain'},$ENV{'user.name'});
  115:     my %discinfo = ();
  116:     my $showonlyunread = 0;
  117:     my $showunmark = 0; 
  118:     my $markondisp = 0;
  119:     my $prevread = 0;
  120:     my $previous = 0;
  121:     my $visit = 0;
  122:     my $newpostsflag = 0;
  123:     my @posters = split/\&/,$dischash{$userpickkey};
  124: 
  125: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
  126:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts','rolefilter','statusfilter','sectionpick','totposters']);
  127:     my $sortposts = $ENV{'form.sortposts'};
  128:     my $rolefilter = $ENV{'form.rolefilter'};
  129:     my $statusfilter = $ENV{'form.statusfilter'};
  130:     my $sectionpick = $ENV{'form.sectionpick'};
  131:     my $totposters = $ENV{'form.totposters'};
  132:     $previous = $ENV{'form.previous'};
  133:     if ($previous > 0) {
  134:         $prevread = $previous;
  135:     } elsif (defined($dischash{$lastkey})) {
  136:         unless ($dischash{$lastkey} eq '') {
  137:             $prevread = $dischash{$lastkey};
  138:         }
  139:     }
  140: 
  141: # Get information about students and non-students in course for filtering display of posts
  142:     my %roleshash = ();
  143:     my %roleinfo = ();
  144:     if ($rolefilter) {
  145:         %roleshash = &Apache::lonnet::dump('nohist_userroles',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  146:         foreach (keys %roleshash) {
  147:             my ($role,$uname,$udom,$sec) = split/:/,$_;
  148:             my ($end,$start) = split/:/,$roleshash{$_};
  149:             my $now = time;
  150:             my $status = 'Active';
  151:             if (($now < $start) || ($end > 0 && $now > $end)) {
  152:                 $status = 'Expired';
  153:             }
  154:             push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
  155:         }
  156:         my ($classlist) = &Apache::loncoursedata::get_classlist(
  157:                               $ENV{'request.course.id'},
  158:                               $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  159:                               $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  160:         my $sec_index = &Apache::loncoursedata::CL_SECTION();
  161:         my $status_index = &Apache::loncoursedata::CL_STATUS();
  162:         while (my ($student,$data) = each %$classlist) {
  163:             my ($section,$status) = ($data->[$sec_index],
  164:                                  $data->[$status_index]);
  165:             push @{$roleinfo{$student}}, 'st:'.$section.':'.$status;
  166:         }
  167:     }
  168: 
  169: # Get discussion display default settings for user
  170:     if ($ENV{'environment.discdisplay'} eq 'unread') {
  171:         $showonlyunread = 1;
  172:     }
  173:     if ($ENV{'environment.discmarkread'} eq 'ondisp') {
  174:         $markondisp = 1;
  175:     }
  176: 
  177: # Override user's default if user specified display setting for this discussion
  178:     if (defined($dischash{$ondispkey})) {
  179:         unless ($dischash{$ondispkey} eq '') {
  180:             $markondisp = $dischash{$ondispkey};
  181:         }
  182:     }
  183:     if ($markondisp) {
  184:         $discinfo{$lastkey} = time;
  185:     }
  186: 
  187:     if (defined($dischash{$showkey})) {
  188:         unless ($dischash{$showkey} eq '') {
  189:             $showonlyunread = $dischash{$showkey};
  190:         }
  191:     }
  192: 
  193:     if (defined($dischash{$markkey})) {
  194:         unless ($dischash{$markkey} eq '') {
  195:             $showunmark = $dischash{$markkey};
  196:         }
  197:     }
  198: 
  199:     if (defined($dischash{$visitkey})) {
  200:         unless ($dischash{$visitkey} eq '') {
  201:             $visit = $dischash{$visitkey};
  202:         }
  203:     }
  204:     $visit ++;
  205: 
  206:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
  207:     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
  208: 	&& ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
  209:     my @discussionitems=();
  210:     my %shown = ();
  211:     my @posteridentity=();
  212: 
  213:     my $current=0;
  214:     my $visible=0;
  215:     my @depth=();
  216:     my @replies = ();
  217:     my %alldiscussion=();
  218:     my %imsitems=();
  219:     my %imsfiles=();
  220:     my %notshown = ();
  221:     my %newitem = ();
  222:     my $maxdepth=0;
  223: 
  224:     my $target='';
  225:     unless ($ENV{'browser.interface'} eq 'textual' ||
  226: 	    $ENV{'environment.remote'} eq 'off' ) {
  227: 	$target='target="LONcom"';
  228:     }
  229: 
  230:     my $now = time;
  231:     $discinfo{$visitkey} = $visit;
  232: 
  233:     &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
  234:     &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$statusfilter,$toggkey,$outputtarget);
  235: 
  236:     my $discussion='';
  237:     my $manifestfile;
  238:     my $manifestok=0;
  239:     my $tempexport;
  240:     my $imsresources;
  241:     my $copyresult;
  242: 
  243:     my $function = &Apache::loncommon::get_users_function();
  244:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
  245:                                                     $ENV{'user.domain'});
  246:     my %lt = &Apache::lonlocal::texthash(
  247:         'cuse' => 'Current discussion settings',
  248:         'allposts' => 'All posts',
  249:         'unread' => 'New posts only',
  250:         'unmark' => 'Unread only',
  251:         'ondisp' => 'Once displayed',
  252:         'onmark' => 'Once marked not NEW',
  253:         'toggoff' => 'Off',
  254:         'toggon' => 'On',
  255:         'disa' => 'Posts to be displayed',
  256:         'npce' => 'Posts cease to be marked "NEW"',
  257:         'epcb' => 'Each post can be toggled read/unread', 
  258:         'chgt' => 'Change',
  259:         'disp' => 'Display',
  260:         'nolo' => 'Not new',
  261:         'togg' => 'Toggle read/unread',
  262:     );
  263: 
  264:     my $currdisp = $lt{'allposts'};
  265:     my $currmark = $lt{'onmark'};
  266:     my $currtogg = $lt{'toggoff'};
  267:     my $dispchange = $lt{'unread'};
  268:     my $markchange = $lt{'ondisp'};
  269:     my $toggchange = $lt{'toggon'};
  270:     my $chglink = '/adm/feedback?modifydisp='.$ressymb;
  271:     my $displinkA = 'onlyunread';
  272:     my $displinkB = 'onlyunmark';
  273:     my $marklink = 'markondisp';
  274:     my $togglink = 'toggon';
  275: 
  276:     if ($markondisp) {
  277:         $currmark = $lt{'ondisp'};
  278:         $markchange = $lt{'onmark'};
  279:         $marklink = 'markonread';
  280:     }
  281: 
  282:     if ($showonlyunread) {
  283:         $currdisp = $lt{'unread'};
  284:         $dispchange = $lt{'allposts'};
  285:         $displinkA = 'allposts';
  286:     }
  287: 
  288:     if ($showunmark) {
  289:         $currdisp = $lt{'unmark'};
  290:         $dispchange = $lt{'unmark'};
  291:         $displinkA='allposts';
  292:         $displinkB='onlyunread';
  293:         $showonlyunread = 0;
  294:     }
  295: 
  296:     if ($dischash{$toggkey}) {
  297:         $currtogg = $lt{'toggon'};
  298:         $toggchange = $lt{'toggoff'};
  299:         $togglink = 'toggoff';
  300:     } 
  301:    
  302:     $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink;
  303: 
  304:     if ($newpostsflag) {
  305:         $chglink .= '&previous='.$prevread;
  306:     }
  307: 
  308:     if ($visible) {
  309: # Print the discusssion
  310:         if ($outputtarget eq 'tex') {
  311:             $discussion.='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
  312:                          '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
  313:                          '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
  314:                          '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
  315:                          '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}</tex>';
  316:         } elsif ($outputtarget eq 'export') {
  317: # Create temporary directory if this is an export
  318:             my $now = time;
  319:             $tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
  320:             if (!-e $tempexport) {
  321:                 mkdir($tempexport,0700);
  322:             }
  323:             $tempexport .= '/'.$now;
  324:             if (!-e $tempexport) {
  325:                 mkdir($tempexport,0700);
  326:             }
  327:             $tempexport .= '/'.$ENV{'user.domain'}.'_'.$ENV{'user.name'};
  328:             if (!-e $tempexport) {
  329:                 mkdir($tempexport,0700);
  330:             }
  331: # open manifest file
  332:             my $manifest = '/imsmanifest.xml';
  333:             my $manifestfilename = $tempexport.$manifest;
  334:             if ($manifestfile = Apache::File->new('>'.$manifestfilename)) {
  335:                 $manifestok=1;
  336:                 print $manifestfile qq|
  337: <?xml version="1.0" encoding="UTF-8"?>
  338: <manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2" 
  339: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  340: identifier="MANIFEST-$ressymb" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 
  341: imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
  342:   <organizations default="$ressymb">
  343:     <organization identifier="$ressymb">
  344:       <title>Discussion for $ressymb</title>\n|;
  345:             } else {
  346:                 $discussion .= 'An error occurred opening the manifest file.<br />';
  347:             }
  348: 	} else {
  349:             my $colspan=$maxdepth+1;
  350:             $discussion.= qq|
  351: <script>
  352:    function studentdelete (symb,idx,newflag,previous) {
  353:        var symbparm = symb+':::'+idx
  354:        var prevparm = ""
  355:        if (newflag == 1) {
  356:            prevparm = "&previous="+previous
  357:        }
  358:        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")) {
  359:            document.location.href = "/adm/feedback?hide="+symbparm+prevparm
  360:        }  
  361:    }
  362: </script>
  363:             |;
  364: 	    $discussion.='<form name="readchoices" method="post" action="/adm/feedback?chgreads='.$ressymb.'"><table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
  365: 	    $discussion .='<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
  366: 		'<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
  367: 	    if ($visible>2) {
  368: 		$discussion.='<td align="left">'.
  369: 		    '<a href="/adm/feedback?threadedon='.$ressymb;
  370: 		if ($newpostsflag) {
  371: 		    $discussion .= '&previous='.$prevread;
  372: 		}
  373: 		$discussion .='">'.&mt('Threaded View').'</a>&nbsp;&nbsp;'.
  374: 		    '<a href="/adm/feedback?threadedoff='.$ressymb;
  375: 		if ($newpostsflag) {
  376: 		    $discussion .= '&previous='.$prevread;
  377: 		}
  378: 		$discussion .='">'.&mt('Chronological View').'</a>&nbsp;&nbsp;
  379:                               <a href= "/adm/feedback?sortfilter='.$ressymb;
  380:                 if ($newpostsflag) {
  381:                     $discussion .= '&previous='.$prevread;
  382:                 }
  383:                 $discussion .='">'.&mt('Sorting/Filtering options').'</a>&nbsp;&nbsp';
  384:             } else {
  385:                 $discussion .= '<td align="left">';
  386:             }
  387:             $discussion .='<a href= "/adm/feedback?export='.$ressymb;
  388:             if ($newpostsflag) {
  389:                 $discussion .= '&previous='.$prevread;
  390:             }
  391:             $discussion .= '">'.&mt('Export').'?</a>&nbsp;&nbsp;</td>';
  392: 	    if ($newpostsflag) {
  393: 		if (!$markondisp) {
  394: 		    $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark NEW posts no longer new').'</a>&nbsp;&nbsp;';
  395: 		} else {
  396: 		    $discussion .= '<td>&nbsp;</td>';
  397: 		}
  398: 	    } else {
  399: 		$discussion .= '<td>&nbsp;</td>';
  400: 	    }
  401: 	    $discussion .= '</tr></table></td></tr>';
  402: 
  403:             my $numhidden = keys %notshown;
  404:             if ($numhidden > 0) {
  405:                 my $colspan = $maxdepth+1;
  406:                 $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
  407:                          '<a href="/adm/feedback?allposts='.$ressymb;
  408:                 if ($newpostsflag) {
  409:                     $discussion .= '&previous='.$prevread;
  410:                 }
  411:                 $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
  412:                          $numhidden.' ';
  413:                 if ($showunmark) {
  414:                     $discussion .= &mt('posts previously marked read');
  415:                 } else {
  416:                     $discussion .= &mt('previously viewed posts');
  417:                 }
  418:                 $discussion .= '<br/></td></tr>';
  419:             }
  420:         }
  421: 
  422: # Choose sort mechanism
  423:         my @showposts = ();
  424:         if ($sortposts eq 'descdate') {
  425:             @showposts = (sort { $b <=> $a } keys %alldiscussion);
  426:         } elsif ($sortposts eq 'thread') {
  427:             @showposts = (sort { $a <=> $b } keys %alldiscussion);
  428:         } elsif ($sortposts eq 'subject') {
  429:             foreach (sort keys %subjectsort) {
  430:                 push @showposts, @{$subjectsort{$_}};
  431:             }
  432:         } elsif ($sortposts eq 'username') {
  433:             foreach my $domain (sort keys %usernamesort) {
  434:                 foreach (sort keys %{$usernamesort{$domain}}) {
  435:                     push @showposts, @{$usernamesort{$domain}{$_}};
  436:                 }
  437:             }
  438:         } elsif ($sortposts eq 'lastfirst') {
  439:             foreach my $last (sort keys %namesort) {
  440:                  foreach (sort keys %{$namesort{$last}}) {
  441:                      push @showposts, @{$namesort{$last}{$_}};
  442:                  }
  443:             }
  444:         } else {
  445:             $sortposts = 'ascdate';
  446:             @showposts =  (sort { $a <=> $b } keys %alldiscussion);
  447:         }
  448:         my $currdepth = 0;
  449:         my $firstidx = $alldiscussion{$showposts[0]};
  450:         foreach (@showposts) {
  451:             unless (($sortposts eq 'thread') || ($sortposts eq 'ascdate' && $ENV{'environment.threadeddiscussion'}) || ($outputtarget eq 'export')) {
  452:                 $alldiscussion{$_} = $_;
  453:             }
  454:             unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {
  455:                 if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
  456: 		    $discussion.="\n<tr>";
  457: 		}
  458: 	        my $thisdepth=$depth[$alldiscussion{$_}];
  459:                 if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
  460: 		    for (1..$thisdepth) {
  461: 			$discussion.='<td>&nbsp;&nbsp;&nbsp;</td>';
  462: 		    }
  463: 		}
  464: 	        my $colspan=$maxdepth-$thisdepth+1;
  465:                 if ($outputtarget eq 'tex') {
  466: 		    #cleanup block
  467: 		    $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
  468: 		    $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
  469:                     my $threadinsert='';
  470:                     if ($thisdepth > 0) {
  471: 			$threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
  472: 		    }
  473: 		    $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
  474: 		    $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;
  475:                     $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
  476: 
  477: 		    $discussionitems[$alldiscussion{$_}]='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}</tex>'.$discussionitems[$alldiscussion{$_}];
  478: 		    $discussion.=$discussionitems[$alldiscussion{$_}];
  479: 		} elsif ($outputtarget eq 'export') {
  480:                     my $postfilename = $alldiscussion{$_}.'-'.$imsitems{$alldiscussion{$_}}{'timestamp'}.'.html';
  481:                     if ($manifestok) {
  482:                         if (($depth[$alldiscussion{$_}] <= $currdepth) && ($alldiscussion{$_} != $firstidx)) {
  483:                             print $manifestfile '  </item>'."\n";
  484:                         }
  485:                         $currdepth = $depth[$alldiscussion{$_}];
  486:                         print $manifestfile "\n". 
  487:       '<item identifier="ITEM-'.$ressymb.'-'.$alldiscussion{$_}.'" isvisible="'.
  488:         $imsitems{$alldiscussion{$_}}{'isvisible'}.'" identifieref="RES-'.$ressymb.'-'.$alldiscussion{$_}.'">'.
  489:         '<title>'.$imsitems{$alldiscussion{$_}}{'title'}.'</title>';
  490:                         $imsresources .= "\n".
  491:     '<resource identifier="RES-'.$ressymb.'-'.$alldiscussion{$_}.'" type="webcontent" href="'.$postfilename.'">'.
  492:       '<file href="'.$alldiscussion{$_}.'.html">'."\n".
  493:       $imsfiles{$alldiscussion{$_}}{$imsitems{$alldiscussion{$_}}{'currversion'}}."\n".
  494:     '</resource>';
  495:                     }
  496:                     my $postingfile;
  497:                     my $postingfilename = $tempexport.'/'.$postfilename;
  498:                     if ($postingfile = Apache::File->new('>'.$postingfilename)) {
  499:                         print $postingfile '<html><head><title>Discussion Post</title></head><body>'.
  500:                                            $imsitems{$alldiscussion{$_}}{'title'}.' '.
  501:                                            $imsitems{$alldiscussion{$_}}{'sender'}.
  502:                                            $imsitems{$alldiscussion{$_}}{'timestamp'}.'<br /><br />'.
  503:                                            $imsitems{$alldiscussion{$_}}{'message'}.'<br />'.
  504:                                            $imsitems{$alldiscussion{$_}}{'attach'}.'</body></html>'."\n"; 
  505:                         close($postingfile);
  506:                     } else {
  507:                         $discussion .= 'An error occurred opening the export file for posting '.$alldiscussion{$_}.'<br />';
  508:                     }
  509:                     $copyresult.=&replicate_attachments($imsitems{$alldiscussion{$_}}{'allattachments'},$tempexport);
  510:                 } else {
  511:                     $discussion.='<td  bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].
  512:                        '" colspan="'.$colspan.'">'. $discussionitems[$alldiscussion{$_}].
  513:                        '</td></tr>';
  514:                 }
  515: 	    }
  516:         }
  517: 	unless ($outputtarget eq 'tex' || $outputtarget eq 'export') {
  518:             my $colspan=$maxdepth+1;
  519:             $discussion .= <<END;
  520:             <tr bgcolor="#FFFFFF">
  521:              <td colspan="$colspan" valign="top">
  522:               <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
  523:                <tr>
  524:                 <td align="left">
  525:                  <table border="0" cellpadding="0" cellspacing="4">
  526:                   <tr>
  527:                    <td>
  528:                     <font size="-1"><b>$lt{'cuse'}</b>:</td>
  529:                    <td>&nbsp;</td>
  530:                    <td><font size="-1">
  531: END
  532:             if ($newpostsflag) {
  533:                 $discussion .= 
  534:                    '1.&nbsp;'.$lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i>&nbsp;&nbsp;2.&nbsp;'.$lt{'nolo'}.'&nbsp;-&nbsp;<i>'.$currmark.'</i>';
  535:                 if ($dischash{$toggkey}) {
  536:                    $discussion .= '&nbsp;&nbsp;3.&nbsp;'.$lt{'togg'}.'&nbsp;-&nbsp;<i>'.$currtogg.'</i>';
  537:                 }
  538:             } else {
  539:                 if ($dischash{$toggkey}) {
  540:                    $discussion .= '1.&nbsp;'.$lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i>&nbsp;2.&nbsp;'.$lt{'togg'}.'&nbsp;-&nbsp;<i>'.$currtogg.'</i>';
  541:                 } else {
  542:                     $discussion .=
  543:                          $lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i>';
  544:                 }
  545:             }
  546:             $discussion .= <<END;
  547:                    </font></td>
  548:                    <td>&nbsp;</td>
  549:                    <td>
  550:                     <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b>
  551:                    </td>
  552:                   </tr>
  553:                  </table>
  554:                 </td>
  555: END
  556:             if ($dischash{$toggkey}) {
  557:                 my $storebutton = &mt('Store read/unread changes');
  558:                 $discussion.='<td align="right">'.
  559:               '<input type="hidden" name="discsymb" value="'.$ressymb.'">'."\n".
  560:               '<input type="button" name="readoptions" value="'.$storebutton.'"'.
  561:               ' onClick="this.form.submit();">'."\n".
  562:               '</td>';
  563:             }
  564:             $discussion .= (<<END);
  565:                </tr>
  566:               </table>
  567:              </td>
  568:             </tr>
  569:            </table>
  570:            <br /><br /></form>
  571: END
  572:         } 
  573:         if ($outputtarget eq 'export') {
  574:             if ($manifestok) {
  575:                 while ($currdepth > 0) {
  576:                     print $manifestfile "    </item>\n";
  577:                     $currdepth --;
  578:                 }
  579:                 print $manifestfile qq|
  580:     </organization>
  581:   </organizations>
  582:   <resources>
  583:     $imsresources
  584:   </resources>
  585: </manifest>
  586:                 |;
  587:                 close($manifestfile);
  588: 
  589: #Create zip file in prtspool
  590: 
  591:                 my $imszipfile = '/prtspool/'.
  592:                 $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
  593:                      time.'_'.rand(1000000000).'.zip';
  594:     # zip can cause an sh launch which can pass along all of %ENV
  595:     # which can be too large for /bin/sh to handle
  596:                 my %oldENV=%ENV;
  597:                 undef(%ENV);
  598:                 my $cwd = &getcwd(); 
  599:                 my $imszip = '/home/httpd/'.$imszipfile;
  600:                 chdir $tempexport;
  601:                 open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
  602:                 close(OUTPUT);
  603:                 chdir $cwd;
  604:                 %ENV=%oldENV;
  605:                 undef(%oldENV);
  606:                 $discussion .= 'Download the zip file from <a href="'.$imszipfile.'">Discussion Posting Archive</a><br />';
  607:                 if ($copyresult) {
  608:                     $discussion .= 'The following errors occurred during export - <br />'.$copyresult;
  609:                 }
  610:             } else {
  611:                 $discussion .= '<br />Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating a manifest file.<br />';
  612:             }
  613:             return $discussion;
  614:         }
  615:     }
  616:     if ($discussiononly) {
  617:         my $now = time;
  618:         my $attachnum = 0;
  619:         my $newattachmsg = '';
  620:         my @currnewattach = ();
  621:         my @currdelold = ();
  622:         my $comment = '';
  623:         my $subject = '';
  624:         if ($ENV{'form.origpage'}) {
  625:             &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']);
  626:             $subject = &Apache::lonnet::unescape($ENV{'form.subject'});
  627:             $comment = &Apache::lonnet::unescape($ENV{'form.comment'});
  628:             my @keepold = ();
  629:             &process_attachments(\@currnewattach,\@currdelold,\@keepold);
  630:             if (@currnewattach > 0) {
  631:                 $attachnum += @currnewattach;
  632:             }
  633:         }
  634: 	if (&discussion_open($status)) {
  635: 	    $discussion.=(<<ENDDISCUSS);
  636: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
  637: <input type="submit" name="discuss" value="Post Discussion" />
  638: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
  639: <input type="hidden" name="symb" value="$ressymb" />
  640: <input type="hidden" name="sendit" value="true" />
  641: <input type="hidden" name="timestamp" value="$now" />
  642: <br /><a name="newpost"></a>
  643: <font size="1">Note: in anonymous discussion, your name is visible only 
  644: to course faculty</font><br />
  645: <b>Title:</b>&nbsp;<input type="text" name="subject" value="$subject" size="30" /><br /><br />
  646: <textarea name="comment" cols="80" rows="14" wrap="hard">$comment</textarea>
  647: ENDDISCUSS
  648:         if ($ENV{'form.origpage'}) {
  649:             $discussion.='<input type="hidden" name="origpage" value="'.$ENV{'form.origpage'}.'" />'."\n";
  650:             foreach (@currnewattach) {
  651:                 $discussion.='<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
  652:             }
  653:         }
  654:         $discussion.="</form>\n";
  655:         if ($outputtarget ne 'tex') {
  656:             $discussion.=&generate_attachments_button('',$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,'',$mode);
  657:             if (@currnewattach > 0) {
  658:                 $newattachmsg .= '<b>New attachments</b><br />';
  659:                 if (@currnewattach > 1) {
  660:                     $newattachmsg .= '<ol>';
  661:                     foreach my $item (@currnewattach) {
  662:                         $item =~ m#.*/([^/]+)$#;
  663:                         $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
  664:                     }
  665:                     $newattachmsg .= '</ol>'."\n";
  666:                 } else {
  667:                     $currnewattach[0] =~ m#.*/([^/]+)$#;
  668:                     $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
  669:                 }
  670:             }
  671:             $discussion.=$newattachmsg;
  672: 	    $discussion.=&generate_preview_button();
  673: 	}
  674: 	}
  675:         } else {
  676: 	if (&discussion_open($status) &&
  677: 	    &Apache::lonnet::allowed('pch',
  678: 				   $ENV{'request.course.id'}.
  679: 	($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  680: 	    if ($outputtarget ne 'tex') {
  681: 		$discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
  682: 		    $ressymb.':::" '.$target.'>'.
  683: 		    '<img src="/adm/lonMisc/chat.gif" border="0" />'.
  684: 		    &mt('Post Discussion').'</a></td></tr></table>';
  685: 	    }
  686: 	}
  687:     }
  688:     return $discussion;
  689: }
  690: 
  691: sub build_posting_display {
  692:     my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$statusfilter,$toggkey,$outputtarget) = @_;
  693: 
  694:     my @original=();
  695:     my @index=();
  696: 
  697:     my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
  698: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  699: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  700: 
  701:     if ($contrib{'version'}) {
  702:         my $oldest = $contrib{'1:timestamp'};
  703:         if ($prevread eq '0') {
  704:             $prevread = $oldest-1;
  705:         }
  706: 	for (my $id=1;$id<=$contrib{'version'};$id++) {
  707: 	    my $idx=$id;
  708:             my $posttime = $contrib{$idx.':timestamp'};
  709:             if ($prevread <= $posttime) {
  710:                 $$newpostsflag = 1;
  711:             }
  712: 	    my $hidden=($contrib{'hidden'}=~/\.$idx\./);
  713:             my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
  714: 	    my $deleted=($contrib{'deleted'}=~/\.$idx\./);
  715: 	    my $origindex='0.';
  716:             my $numoldver=0;
  717: 	    if ($contrib{$idx.':replyto'}) {
  718:                 if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
  719: # this is a follow-up message
  720: 		    $original[$idx]=$original[$contrib{$idx.':replyto'}];
  721: 		    $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
  722: 		    $origindex=$index[$contrib{$idx.':replyto'}];
  723: 		    if ($$depth[$idx]>$$maxdepth) { $$maxdepth=$$depth[$idx]; }
  724:                 } else {
  725:                     $original[$idx]=0;
  726:                     $$depth[$idx]=0;
  727:                 }
  728: 	    } else {
  729: # this is an original message
  730: 		$original[$idx]=0;
  731: 		$$depth[$idx]=0;
  732: 	    }
  733: 	    if ($$replies[$$depth[$idx]]) {
  734: 		$$replies[$$depth[$idx]]++;
  735: 	    } else {
  736: 		$$replies[$$depth[$idx]]=1;
  737: 	    }
  738: 	    unless ((($hidden) && (!$seeid)) || ($deleted)) {
  739: 		$$visible++;
  740:                 if ($contrib{$idx.':history'}) {
  741:                     if ($contrib{$idx.':history'} =~ /:/) {
  742:                         my @oldversions = split/:/,$contrib{$idx.':history'};
  743:                         $numoldver = @oldversions;
  744:                     } else {
  745:                         $numoldver = 1;
  746:                     } 
  747:                 }
  748:                 $$current = $numoldver;
  749: 		my %messages = ();
  750:                 my %subjects = ();
  751:                 my %attachtxt = ();
  752:                 my %allattachments = ();
  753:                 my ($screenname,$plainname);
  754:                 my $sender = &mt('Anonymous');
  755:                 my ($message,$subject,$vgrlink,$ctlink);
  756:                 &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver);
  757: 
  758: 
  759: # Set up for sorting by subject
  760:                 unless ($outputtarget eq 'export') {
  761:                     $message=$messages{$numoldver};
  762:                     $message.=$attachtxt{$numoldver};
  763:                     $subject=$subjects{$numoldver};
  764:                     if ($message) {
  765: 	  	        if ($hidden) {
  766: 			    $message='<font color="#888888">'.$message.'</font>';
  767:                             if ($studenthidden) {
  768:                                 $message .='<br /><br />Deleted by poster (student).';
  769:                             }
  770: 		        }
  771: 
  772:                         if ($subject eq '') {
  773:                            if (defined($$subjectsort{'__No subject'})) {
  774:                                push @{$$subjectsort{'__No subject'}}, $idx;
  775:                            } else {
  776:                                @{$$subjectsort{'__No subject'}} = ("$idx");
  777:                            }
  778:                         } else {
  779:                             if (defined($$subjectsort{$subject})) {
  780:                                push @{$$subjectsort{$subject}}, $idx;
  781:                             } else {
  782:                                @{$$subjectsort{$subject}} = ("$idx");
  783:                             }
  784:                         }
  785: 		        if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
  786: 			    $sender=&Apache::loncommon::aboutmewrapper(
  787: 					 $plainname,
  788: 					 $contrib{$idx.':sendername'},
  789: 					 $contrib{$idx.':senderdomain'}).' ('.
  790: 					 $contrib{$idx.':sendername'}.' at '.
  791: 					 $contrib{$idx.':senderdomain'}.')';
  792: 			    if ($contrib{$idx.':anonymous'}) {
  793: 			        $sender.=' ['.&mt('anonymous').'] '.
  794: 				    $screenname;
  795: 			    }
  796: 
  797: # Set up for sorting by domain, then username
  798:                             unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {
  799:                                 %{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
  800:                             }
  801:                             if (defined($$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
  802:                                 push @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx;
  803:                             } else {
  804:                                 @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
  805:                             }
  806: # Set up for sorting by last name, then first name
  807:                             my %names = &Apache::lonnet::get('environment',
  808:                                  ['firstname','lastname'],$contrib{$idx.':senderdomain'},
  809:                                   ,$contrib{$idx.':sendername'});
  810:                             my $lastname = $names{'lastname'};
  811:                             my $firstname = $names{'firstname'};
  812:                             if ($lastname eq '') {
  813:                                 $lastname = '_';
  814:                             }
  815:                             if ($firstname eq '') {
  816:                                 $firstname = '_';
  817:                             }
  818:                             unless (defined($$namesort{$lastname})) {
  819:                                 %{$$namesort{$lastname}} = ();
  820:                             }
  821:                             if (defined($$namesort{$lastname}{$firstname})) {
  822:                                 push @{$$namesort{$lastname}{$firstname}}, $idx;
  823:                             } else {
  824:                                 @{$$namesort{$lastname}{$firstname}} = ("$idx");
  825:                             }
  826:                             if ($ENV{'course.'.$ENV{'request.course.id'}.'.allow_discussion_post_editing'} =~ m/yes/i) {
  827:                                 if (($ENV{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($ENV{'user.name'} eq $contrib{$idx.':sendername'})) {
  828:                                     $sender.=' <a href="/adm/feedback?editdisc='.
  829:                                          $ressymb.':::'.$idx;
  830:                                     if ($newpostsflag) {
  831:                                         $sender .= '&previous='.$prevread;
  832:                                     }
  833:                                     $sender .= '" '.$target.'>'.&mt('Edit').'</a>';                                             
  834:                                     unless ($seeid) {
  835:                                         $sender.=" <a href=\"javascript:studentdelete('$ressymb','$idx','$newpostsflag','$prevread')";
  836:                                         $sender .= '">'.&mt('Delete').'</a>';
  837:                                     }
  838:                                 }
  839:                             } 
  840: 			    if ($seeid) {
  841: 			        if ($hidden) {
  842:                                     unless ($studenthidden) {
  843: 			                $sender.=' <a href="/adm/feedback?unhide='.
  844: 				                $ressymb.':::'.$idx;
  845:                                         if ($newpostsflag) {
  846:                                              $sender .= '&previous='.$prevread;
  847:                                         }
  848:                                         $sender .= '">'.&mt('Make Visible').'</a>';
  849:                                     }
  850: 			        } else {
  851: 				    $sender.=' <a href="/adm/feedback?hide='.
  852: 				        $ressymb.':::'.$idx;
  853:                                     if ($newpostsflag) {
  854:                                         $sender .= '&previous='.$prevread;
  855:                                     }
  856:                                     $sender .= '">'.&mt('Hide').'</a>';
  857: 			        }                     
  858: 			        $sender.=' <a href="/adm/feedback?deldisc='.
  859: 				        $ressymb.':::'.$idx;
  860:                                 if ($newpostsflag) {
  861:                                     $sender .= '&previous='.$prevread;
  862:                                 }
  863:                                 $sender .= '">'.&mt('Delete').'</a>';
  864:                             }
  865: 		        } else {
  866: 			    if ($screenname) {
  867: 			        $sender='<i>'.$screenname.'</i>';
  868: 			    }
  869: # Set up for sorting by domain, then username for anonymous
  870:                             unless (defined($$usernamesort{'__anon'})) {
  871:                                 %{$$usernamesort{'__anon'}} = ();
  872:                             }
  873:                             if (defined($$usernamesort{'__anon'}{'__anon'})) {
  874:                                 push @{$$usernamesort{'__anon'}{'__anon'}}, $idx;
  875:                             } else {
  876:                                 @{$$usernamesort{'__anon'}{'__anon'}} = ("$idx");
  877:                             }
  878: # Set up for sorting by last name, then first name for anonymous
  879:                             unless (defined($$namesort{'__anon'})) {
  880:                                 %{$$namesort{'__anon'}} = ();
  881:                             }
  882:                             if (defined($$namesort{'__anon'}{'__anon'})) {
  883:                                 push @{$$namesort{'__anon'}{'__anon'}}, $idx;
  884:                             } else {
  885:                                 @{$$namesort{'__anon'}{'__anon'}} = ("$idx");
  886:                             }
  887: 		        }
  888: 		        if (&discussion_open($status) &&
  889: 			        &Apache::lonnet::allowed('pch',
  890: 						 $ENV{'request.course.id'}.
  891: 						 ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
  892: 			    $sender.=' <a href="/adm/feedback?replydisc='.
  893: 			            $ressymb.':::'.$idx;
  894:                             if ($newpostsflag) {
  895:                                     $sender .= '&previous='.$prevread;
  896:                             }
  897:                             $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
  898:                         }
  899: 		        if ($viewgrades) {
  900: 			        $vgrlink=&Apache::loncommon::submlink('Submissions',
  901:                             $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
  902: 		        }
  903:                         if ($$dischash{$readkey}=~/\.$idx\./) { 
  904:                             $ctlink = '<b>'.&mt('Mark unread').'?</b>&nbsp;<input type="checkbox" name="postunread_'.$idx.'" />';
  905:                         } else {
  906:                             $ctlink = '<b>'.&mt('Mark read').'?</b>&nbsp;<input type="checkbox" name="postread_'.$idx.'" />';
  907:                         }
  908:                     }
  909: #figure out at what position this needs to print
  910:                 }
  911:                 if ($outputtarget eq 'export' || $message) {
  912: 		    my $thisindex=$idx;
  913: 		    if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
  914: 			$thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
  915: 		    }
  916: 		    $$alldiscussion{$thisindex}=$idx;
  917:                     $$shown{$idx} = 0;
  918:                     $index[$idx]=$thisindex;
  919:                 }
  920:                 if ($outputtarget eq 'export') {
  921:                     %{$$imsitems{$idx}} = ();
  922:                     $$imsitems{$idx}{'isvisible'}='true';
  923:                     if ($hidden) {
  924:                         $$imsitems{$idx}{'isvisible'}='false';
  925:                     }
  926:                     $$imsitems{$idx}{'title'}=$subjects{$numoldver};
  927:                     $$imsitems{$idx}{'message'}=$messages{$numoldver};
  928:                     $$imsitems{$idx}{'attach'}=$attachtxt{$numoldver};
  929:                     $$imsitems{$idx}{'timestamp'}=$contrib{$idx.':timestamp'};
  930:                     $$imsitems{$idx}{'sender'}=$plainname.' ('.
  931:                                          $contrib{$idx.':sendername'}.' at '.
  932:                                          $contrib{$idx.':senderdomain'}.')';
  933:                     $$imsitems{$idx}{'isanonymous'}='false';
  934:                     if ($contrib{$idx.':anonymous'}) {
  935:                         $$imsitems{$idx}{'isanonymous'}='true';
  936:                     }
  937:                     $$imsitems{$idx}{'currversion'}=$numoldver;
  938:                     %{$$imsitems{$idx}{'allattachments'}}=%allattachments;
  939:                     unless ($messages{$numoldver} eq '' && $attachtxt{$numoldver} eq '') {
  940:                         $$shown{$idx} = 1;
  941:                     }
  942:                 } else {
  943:                     if ($message) {
  944:                         my $spansize = 2;
  945:                         if ($showonlyunread && $prevread > $posttime) {
  946:                             $$notshown{$idx} = 1;
  947:                         } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
  948:                             $$notshown{$idx} = 1;
  949:                         } else {
  950: # apply filters
  951:                             my $uname = $contrib{$idx.':sendername'};
  952:                             my $udom = $contrib{$idx.':senderdomain'};
  953:                             my $poster = $uname.':'.$udom;
  954:                             my $rolematch = '';
  955:                             my $skiptest = 1;
  956:                             if ($totposters > 0) {
  957:                                 if (grep/^$poster$/,@{$posters}) {
  958:                                     $$shown{$idx} = 1;
  959:                                 }
  960:                             } else {
  961:                                 if ($rolefilter) {
  962:                                     if ($rolefilter eq 'all') {
  963:                                         $rolematch = '([^:]+)';
  964:                                     } else {
  965:                                         $rolematch = $rolefilter;
  966:                                         $skiptest = 0;
  967:                                     }
  968:                                 }
  969:                                 if ($sectionpick) {
  970:                                     if ($sectionpick eq 'all') {
  971:                                         $rolematch .= ':([^:]*)';
  972:                                     } else {
  973:                                         $rolematch .= ':'.$sectionpick;
  974:                                         $skiptest = 0;
  975:                                     }
  976:                                 }
  977:                                 if ($statusfilter) {
  978:                                     if ($statusfilter eq 'all') {
  979:                                         $rolematch .= ':([^:]+)';
  980:                                     } else {
  981:                                         $rolematch .= ':'.$statusfilter;
  982:                                         $skiptest = 0;
  983:                                     }
  984:                                 }
  985:                                 if ($skiptest) {
  986:                                     $$shown{$idx} = 1;
  987:                                 } else {
  988:                                     foreach my $role (@{$$roleinfo{$poster}}) {
  989:                                         if ($role =~ m/^$rolematch$/) {
  990:                                             $$shown{$idx} = 1;
  991:                                             last;
  992:                                         }
  993:                                     }
  994:                                 }
  995:                             }
  996:                         }
  997:                         unless ($$notshown{$idx} == 1) {
  998:                             if ($prevread > 0 && $prevread <= $posttime) {
  999:                                 $$newitem{$idx} = 1;
 1000:                                 $$discussionitems[$idx] .= '
 1001:                                  <p><table border="0" width="100%">
 1002:                                   <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
 1003:                             } else {
 1004:                                 $$newitem{$idx} = 0;
 1005:                                 $$discussionitems[$idx] .= '
 1006:                                  <p><table border="0" width="100%">
 1007:                                   <tr><td align="left">&nbsp;</td>';
 1008:                             }
 1009:                             $$discussionitems[$idx] .= '<td align ="left">&nbsp;&nbsp;'.
 1010:                                 '<b>'.$subject.'</b>&nbsp;&nbsp;'.
 1011:                                 $sender.'</b> '.$vgrlink.' ('.
 1012:                                 &Apache::lonlocal::locallocaltime($posttime).')</td>';
 1013:                             if ($$dischash{$toggkey}) {
 1014:                                 $$discussionitems[$idx].='<td align="right">&nbsp;&nbsp;'.
 1015:                                   $ctlink.'</td>';
 1016:                             }
 1017:                             $$discussionitems[$idx].= '</tr></table><blockquote>'.
 1018:                                     $message.'</blockquote></p>';
 1019:                             if ($contrib{$idx.':history'}) {
 1020:                                 my @postversions = ();
 1021:                                 $$discussionitems[$idx] .= &mt('This post has been edited by the author.');
 1022:                                 if ($seeid) {
 1023:                                     $$discussionitems[$idx] .= '&nbsp;&nbsp;<a href="/adm/feedback?allversions='.$ressymb.':::'.$idx.'">'.&mt('Display all versions').'</a>';
 1024:                                 }
 1025:                                 $$discussionitems[$idx].='<br/>'.&mt('Earlier version(s) were posted on: ');
 1026:                                 if ($contrib{$idx.':history'} =~ m/:/) {
 1027:                                     @postversions = split/:/,$contrib{$idx.':history'};
 1028:                                 } else {
 1029:                                     @postversions = ("$contrib{$idx.':history'}");
 1030:                                 }
 1031:                                 for (my $i=0; $i<@postversions; $i++) {
 1032:                                     my $version = $i+1;
 1033:                                     $$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).'  ';
 1034:                                 }
 1035:                             }
 1036:                         }
 1037:                     }
 1038:                 }
 1039:             }
 1040: 	}
 1041:     }
 1042: }
 1043: 
 1044: sub get_post_contents {
 1045:     my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_;
 1046:     my $discussion = '';
 1047:     my $start=$numver;
 1048:     my $end=$numver + 1;
 1049:     %{$$imsfiles{$idx}}=();
 1050:     if ($type eq 'allversions') {
 1051:        unless($seeid) {
 1052:            $discussion=&mt('You do not have privileges to view all versions of posts.').&mt('Please select a different role');
 1053:            return $discussion;
 1054:        } 
 1055:     }
 1056: #    $$screenname=&Apache::loncommon::screenname(
 1057: #                                        $$contrib{$idx.':sendername'},
 1058: #                                        $$contrib{$idx.':senderdomain'});
 1059: #    $$plainname=&Apache::loncommon::nickname(
 1060: #                                        $$contrib{$idx.':sendername'},
 1061: #                                        $$contrib{$idx.':senderdomain'});
 1062:     ($$screenname,$$plainname)=($$contrib{$idx.':screenname'},
 1063: 				$$contrib{$idx.':plainname'});
 1064:     my $sender=&Apache::loncommon::aboutmewrapper(
 1065:                                  $$plainname,
 1066:                                  $$contrib{$idx.':sendername'},
 1067:                                  $$contrib{$idx.':senderdomain'}).' ('.
 1068:                                  $$contrib{$idx.':sendername'}.' at '.
 1069:                                  $$contrib{$idx.':senderdomain'}.')';
 1070:     my $attachmenturls = $$contrib{$idx.':attachmenturl'};
 1071:     my @postversions = ();
 1072:     if ($type eq 'allversions' || $type eq 'export') {
 1073:         $start = 0;
 1074:         if ($$contrib{$idx.':history'}) {
 1075:             if ($$contrib{$idx.':history'} =~ m/:/) {
 1076:                 @postversions = split/:/,$$contrib{$idx.':history'};
 1077:             } else {
 1078:                 @postversions = ("$$contrib{$idx.':history'}");
 1079:             }
 1080:         }
 1081:         &get_post_versions($messages,$$contrib{$idx.':message'},1);
 1082:         &get_post_versions($subjects,$$contrib{$idx.':subject'},1);
 1083:         push @postversions,$$contrib{$idx.':timestamp'};
 1084:         $end = @postversions;
 1085:     } else {
 1086:         &get_post_versions($messages,$$contrib{$idx.':message'},1,$numver);
 1087:         &get_post_versions($subjects,$$contrib{$idx.':subject'},1,$numver);
 1088:     }
 1089: 
 1090:     if ($$contrib{$idx.':anonymous'}) {
 1091:         $sender.=' ['.&mt('anonymous').'] '.$$screenname;
 1092:     }
 1093:     if ($type eq 'allversions') {
 1094:         $discussion=('<b>'.$sender.'</b><br /><ul>');
 1095:     }
 1096:     for (my $i=$start; $i<$end; $i++) {
 1097:         my ($timesent,$attachmsg);
 1098:         my %currattach = ();
 1099:         $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
 1100:         $$messages{$i}=~s/\n/\<br \/\>/g;
 1101:         $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
 1102:         $$subjects{$i}=~s/\n/\<br \/\>/g;
 1103:         $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
 1104:         if ($attachmenturls) {
 1105:             &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,$allattachments,\%currattach);
 1106:         }
 1107:         if ($type eq 'export') {
 1108:             $$imsfiles{$idx}{$i} = '';
 1109:             if ($attachmsg) {
 1110:                 $$attachtxt{$i} = '<br />Attachments:<br />';
 1111:                 foreach (sort keys %currattach) {
 1112:                     if ($$allattachments{$_}{'filename'} =~ m-^/uploaded/([^/]+/[^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
 1113:                         my $fname = $1.$3.'/'.$4;
 1114:                         $$imsfiles{$idx}{$i} .= '<file href="'.$fname.'">'."\n";
 1115:                         $$attachtxt{$i}.= '<a href="'.$fname.'">'.$4.'</a><br />';
 1116:                     }
 1117:                 }
 1118:             }
 1119:         } else {
 1120:             if ($attachmsg) {
 1121:                 $$attachtxt{$i} = '<br />Attachments:'.$attachmsg.'<br />';
 1122:             } else {
 1123:                 $$attachtxt{$i} = '';
 1124:             }
 1125:         }
 1126:         if ($type eq 'allversions') {
 1127:             $discussion.= <<"END";
 1128: <li><b>$$subjects{$i}</b>, $timesent<br />
 1129: $$messages{$i}<br />
 1130: $$attachtxt{$i}</li>
 1131: END
 1132:         }
 1133:     }
 1134:     if ($type eq 'allversions') {
 1135:         $discussion.=('</ul></body></html>');
 1136:         return $discussion;
 1137:     } else {
 1138:         return;
 1139:     }
 1140: }
 1141: 
 1142: sub replicate_attachments {
 1143:     my ($attachrefs,$tempexport) = @_;
 1144:     my $response;
 1145:     foreach my $id (keys %{$attachrefs}) {
 1146:         if ($$attachrefs{$id}{'filename'} =~ m-^/uploaded/([^/]+)/([^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
 1147:             my $path = $tempexport;
 1148:             my $tail = $1.'/'.$2.$4;
 1149:             my @extras = split/\//,$tail;
 1150:             my $destination = $tempexport.'/'.$1.'/'.$2.$4.'/'.$5;
 1151:             if (!-e $destination) {
 1152:                 my $i= 0;
 1153:                 while ($i<@extras) {
 1154:                     $path .= '/'.$extras[$i];
 1155:                     if (!-e $path) {
 1156:                         mkdir($path,0700);
 1157:                     }
 1158:                     $i ++;
 1159:                 }
 1160:                 my ($content,$rtncode);
 1161:                 my $uploadreply = &Apache::lonnet::getuploaded('GET',$$attachrefs{$id}{'filename'},$1,$2,$content,$rtncode);
 1162:                 if ($uploadreply eq 'ok') {
 1163:                     my $attachcopy;
 1164:                     if ($attachcopy = Apache::File->new('>'.$destination)) {
 1165:                         print $attachcopy $content;
 1166:                         close($attachcopy);
 1167:                     } else {
 1168:                         $response .= 'Error copying file attachment - '.$5.' to IMS package: '.$!.'<br />'."\n";
 1169:                     }
 1170:                 } else {
 1171:                     &Apache::lonnet::logthis("Replication of attachment failed when building IMS export of discussion posts - domain: $1, course: $2, file: $$attachrefs{$id}{'filename'} -error: $rtncode");
 1172:                     $response .= 'Error copying file attachment - '.$5.' to IMS package: '.$rtncode.'<br />'."\n";
 1173:                 }
 1174:             }
 1175:         }
 1176:     }
 1177:     return $response;
 1178: }
 1179: 
 1180: sub mail_screen {
 1181:   my ($r,$feedurl,$options) = @_;
 1182:   if (exists($ENV{'form.origpage'})) {
 1183:       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']);
 1184:   }
 1185:   my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
 1186:                                           '','onLoad="window.focus();setposttype();"');
 1187:   my $title=&Apache::lonnet::gettitle($feedurl);
 1188:   if (!$title) { $title = $feedurl; }
 1189:   my $quote='';
 1190:   my $subject = '';
 1191:   my $comment = '';
 1192:   my $prevtag = '';
 1193:   my $parentmsg = '';
 1194:   my ($symb,$idx,$attachmenturls);
 1195:   my $numoldver = 0;
 1196:   my $attachmsg = '';
 1197:   my $newattachmsg = '';
 1198:   my @currnewattach = ();
 1199:   my @currdelold = ();
 1200:   my @keepold = ();
 1201:   my %attachments = ();
 1202:   my %currattach = ();
 1203:   my $attachnum = 0;
 1204:   my $anonchk = (<<END);
 1205:   function anonchk() {
 1206:      if (document.mailform.anondiscuss.checked == true) {
 1207:           document.attachment.anondiscuss.value = '1'
 1208:      }
 1209:      if (document.mailform.discuss.checked == true) {
 1210:           document.attachment.discuss.value = '1'
 1211:      }
 1212:      return
 1213:    }
 1214: END
 1215:   my $anonscript;
 1216:   if (exists($ENV{'form.origpage'})) {
 1217:       $anonscript = (<<END);
 1218:   function setposttype() {
 1219:       var anondisc = $ENV{'form.anondiscuss'};
 1220:       var disc = $ENV{'form.discuss'};
 1221:       if (anondisc == 1) {
 1222:           document.mailform.anondiscuss.checked = true
 1223:       }
 1224:       if (disc == 1) {
 1225:           document.mailform.discuss.checked = true
 1226:       }
 1227:       return
 1228:   }
 1229: END
 1230:   } else {
 1231:       $anonscript = (<<END);
 1232:   function setposttype() {
 1233:       return
 1234:   }
 1235: END
 1236:   }
 1237:   if (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
 1238:       if ($ENV{'form.replydisc'}) {
 1239:           ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
 1240:       } else {
 1241:           ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
 1242:       }
 1243:       my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
 1244: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1245: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1246:       unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
 1247:           if ($contrib{$idx.':history'}) {
 1248:               if ($contrib{$idx.':history'} =~ /:/) {
 1249:                   my @oldversions = split/:/,$contrib{$idx.':history'};
 1250:                   $numoldver = @oldversions;
 1251:               } else {
 1252:                   $numoldver = 1;
 1253:               }
 1254:           }
 1255:           if ($ENV{'form.replydisc'}) {
 1256:               if ($contrib{$idx.':history'}) {
 1257:                   if ($contrib{$idx.':history'} =~ /:/) {
 1258:                       my @oldversions = split/:/,$contrib{$idx.':history'};
 1259:                       $numoldver = @oldversions;
 1260:                   } else {
 1261:                       $numoldver = 1;
 1262:                   }
 1263:               }
 1264:               my $message;
 1265:               if ($idx > 0) {
 1266:                   my %msgversions = ();
 1267:                   &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
 1268:                   $message = $msgversions{$numoldver};
 1269:               }
 1270: 	      $message=~s/\n/\<br \/\>/g;
 1271: 	      $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
 1272:               if ($idx > 0) {
 1273:                   my %subversions = ();
 1274:                   &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
 1275:                   $subject = 'Re: '.$subversions{$numoldver};
 1276:               }
 1277:               $subject = &HTML::Entities::encode($subject,'<>&"');
 1278:           } else {
 1279:               $attachmenturls = $contrib{$idx.':attachmenturl'};
 1280:               if ($idx > 0) {
 1281:                   my %msgversions = ();
 1282:                   &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
 1283:                   $comment = $msgversions{$numoldver};
 1284:                   my %subversions = ();
 1285:                   &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
 1286:                   $subject = $subversions{$numoldver}; 
 1287:               }
 1288:               if (defined($contrib{$idx.':replyto'})) {
 1289:                   $parentmsg = $contrib{$idx.':replyto'};
 1290:               }
 1291:               unless (exists($ENV{'form.origpage'})) {
 1292:                   my $anonflag = 0;
 1293:                   if ($contrib{$idx.':anonymous'}) {
 1294:                       $anonflag = 1;
 1295:                   }
 1296:                   $anonscript = (<<END);
 1297:   function setposttype () {
 1298:       var currtype = $anonflag
 1299:       if (currtype == 1) {
 1300:           document.mailform.elements.discuss.checked = false
 1301:           document.mailform.elements.anondiscuss.checked = true
 1302:       }
 1303:       if (currtype == 0) {
 1304:           document.mailform.elements.anondiscuss.checked = false
 1305:           document.mailform.elements.discuss.checked = true
 1306:       }
 1307:       return
 1308:   }
 1309: END
 1310:               }
 1311:           }
 1312:       }
 1313:       if ($ENV{'form.previous'}) {
 1314:           $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
 1315:       }
 1316:   }
 1317: 
 1318:   if ($ENV{'form.origpage'}) {
 1319:       $subject = &Apache::lonnet::unescape($ENV{'form.subject'});
 1320:       $comment = &Apache::lonnet::unescape($ENV{'form.comment'});
 1321:       &process_attachments(\@currnewattach,\@currdelold,\@keepold);
 1322:   }
 1323:   my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
 1324:   my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
 1325:   my $send=&mt('Send');
 1326:   $r->print(<<END);
 1327: <html>
 1328: <head>
 1329: <title>The LearningOnline Network with CAPA</title>
 1330: <meta http-equiv="pragma" content="no-cache"></meta>
 1331: $htmlheader
 1332: <script type="text/javascript">
 1333: //<!--
 1334:     function gosubmit() {
 1335:         var rec=0;
 1336:         if (typeof(document.mailform.elements.author)!="undefined") {
 1337:           if (document.mailform.elements.author.checked) {
 1338:              rec=1;
 1339:           } 
 1340:         }
 1341:         if (typeof(document.mailform.elements.question)!="undefined") {
 1342:           if (document.mailform.elements.question.checked) {
 1343:              rec=1;
 1344:           } 
 1345:         }
 1346:         if (typeof(document.mailform.elements.course)!="undefined") {
 1347:           if (document.mailform.elements.course.checked) {
 1348:              rec=1;
 1349:           } 
 1350:         }
 1351:         if (typeof(document.mailform.elements.policy)!="undefined") {
 1352:           if (document.mailform.elements.policy.checked) {
 1353:              rec=1;
 1354:           } 
 1355:         }
 1356:         if (typeof(document.mailform.elements.discuss)!="undefined") {
 1357:           if (document.mailform.elements.discuss.checked) {
 1358:              rec=1;
 1359:           } 
 1360:         }
 1361:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
 1362:           if (document.mailform.elements.anondiscuss.checked) {
 1363:              rec=1;
 1364:           } 
 1365:         }
 1366: 
 1367:         if (rec) {
 1368:             if (typeof(document.mailform.onsubmit)=='function') {
 1369: 		document.mailform.onsubmit();
 1370: 	    }
 1371: 	    document.mailform.submit();
 1372:         } else {
 1373:             alert('Please check a feedback type.');
 1374: 	}
 1375:     }
 1376:     $anonchk
 1377:     $anonscript
 1378: //-->
 1379: </script>
 1380: </head>
 1381: $bodytag
 1382: <h2><tt>$title</tt></h2>
 1383: <form action="/adm/feedback" method="post" name="mailform"
 1384: enctype="multipart/form-data">
 1385: $prevtag
 1386: <input type="hidden" name="postdata" value="$feedurl" />
 1387: END
 1388:   if ($ENV{'form.replydisc'}) {
 1389:       $r->print(<<END);
 1390: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
 1391: END
 1392:   } elsif ($ENV{'form.editdisc'}) {
 1393:      $r->print(<<END);
 1394: <input type="hidden" name="editdisc" value ="$ENV{'form.editdisc'}" />
 1395: <input type="hidden" name="parentmsg" value ="$parentmsg" />
 1396: END
 1397:   }
 1398:   $r->print(<<END);
 1399: Please check at least one of the following feedback types:
 1400: $options<hr />
 1401: $quote
 1402: <p>My question/comment/feedback:</p>
 1403: <p>
 1404: $latexHelp
 1405: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
 1406: <p>
 1407: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$comment
 1408: </textarea></p>
 1409: <p>
 1410: END
 1411:     if ( ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'}) ) {
 1412:         if ($ENV{'form.origpage'}) {
 1413:             foreach (@currnewattach) {
 1414:                 $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
 1415:             }
 1416:             foreach (@currdelold) {
 1417:                 $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
 1418:             }
 1419:         }
 1420:         if ($ENV{'form.editdisc'}) {
 1421:             if ($attachmenturls) {
 1422:                 &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
 1423:                 $attachnum = scalar(keys %currattach);
 1424:                 foreach (keys %currattach) {
 1425:                     $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
 1426:                 }
 1427:             }
 1428:         }
 1429:     } else {
 1430:         $r->print(<<END);
 1431: Attachment (128 KB max size): <input type="file" name="attachment" />
 1432: </p>
 1433: END
 1434:     }
 1435:     $r->print(<<END);
 1436: <p>
 1437: <input type="hidden" name="sendit" value="1" />
 1438: <input type="button" value="$send" onClick='gosubmit();' />
 1439: </p>
 1440: </form>
 1441: END
 1442:     if ($ENV{'form.editdisc'} || $ENV{'form.replydisc'}) {
 1443:         my $now = time;
 1444:         my $ressymb = $symb;
 1445:         my $postidx = '';
 1446:         if ($ENV{'form.editdisc'}) {
 1447:             $postidx = $idx;
 1448:         }
 1449:         if (@currnewattach > 0) {
 1450:             $attachnum += @currnewattach;
 1451:         }
 1452:         $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver));
 1453:         if ($attachnum > 0) {
 1454:             if (@currnewattach > 0) {
 1455:                 $newattachmsg .= '<b>New attachments</b><br />';
 1456:                 if (@currnewattach > 1) {
 1457:                     $newattachmsg .= '<ol>';
 1458:                     foreach my $item (@currnewattach) {
 1459:                         $item =~ m#.*/([^/]+)$#;
 1460:                         $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
 1461:                     }
 1462:                     $newattachmsg .= '</ol>'."\n";
 1463:                 } else {
 1464:                     $currnewattach[0] =~ m#.*/([^/]+)$#;
 1465:                     $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
 1466:                 }
 1467:             }
 1468:             if ($attachmsg) {
 1469:                 $r->print("<b>Retained attachments</b>:$attachmsg<br />\n");
 1470:             }
 1471:             if ($newattachmsg) {
 1472:                 $r->print("$newattachmsg<br />");
 1473:             }
 1474:         }
 1475:     }
 1476:     $r->print(&generate_preview_button().
 1477:               &Apache::lonhtmlcommon::htmlareaselectactive('comment').
 1478:               '</body></html>');
 1479: }
 1480: 
 1481: sub print_display_options {
 1482:     my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
 1483:  # backward compatibility (bulletin boards used to be 'wrapped')
 1484:     if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 1485:         $feedurl=~s|^/adm/wrapper||;
 1486:     }
 1487: 
 1488:     my $function = &Apache::loncommon::get_users_function();
 1489:     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
 1490:                                                     $ENV{'user.domain'});
 1491:     my $bodytag=&Apache::loncommon::bodytag('Discussion options',
 1492:                                           '','');
 1493: 
 1494:     my %lt = &Apache::lonlocal::texthash(
 1495:         'dido' => 'Discussion display options',
 1496:         'pref' => 'Display Preference',
 1497:         'curr' => 'Current setting ',
 1498:         'actn' => 'Action',
 1499:         'deff' => 'Default for all discussions',
 1500:         'prca' => 'Preferences can be set for this discussion that determine ....',
 1501:         'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
 1502:         'unwh' => 'Under what circumstances posts are identified as "NEW", and',
 1503:         'wipa' => 'Whether individual posts can be marked as read/unread',
 1504:         'allposts' => 'All posts',
 1505:         'unread' => 'New posts only',
 1506:         'unmark' => 'Posts not marked read',
 1507:         'ondisp' => 'Once displayed',
 1508:         'onmark' => 'Once marked not NEW ',
 1509:         'toggon' => 'Shown',
 1510:         'toggoff' => 'Not shown',
 1511:         'disa' => 'Posts displayed?',
 1512:         'npmr' => 'New posts cease to be identified as "NEW"?',
 1513:         'dotm' => 'Option to mark each post as read/unread?',  
 1514:         'chgt' => 'Change to ',
 1515:         'mkdf' => 'Set to ',
 1516:         'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
 1517:         'ywbr' => 'You will be returned to the previous page if you click OK.'
 1518:     );
 1519: 
 1520:     my $dispchangeA = $lt{'unread'};
 1521:     my $dispchangeB = $lt{'unmark'};
 1522:     my $markchange = $lt{'ondisp'};
 1523:     my $toggchange = $lt{'toggon'};
 1524:     my $currdisp = $lt{'allposts'};
 1525:     my $currmark = $lt{'onmark'};
 1526:     my $discdisp = 'allposts';
 1527:     my $discmark = 'onmark';
 1528:     my $currtogg = $lt{'toggoff'};
 1529:     my $disctogg = 'toggoff';
 1530:                                                                                       
 1531:     if ($dispchgA eq 'allposts') {
 1532:         $dispchangeA = $lt{'allposts'};
 1533:         $currdisp = $lt{'unread'};
 1534:         $discdisp = 'unread';
 1535:     }
 1536: 
 1537:     if ($markchg eq 'markonread') {
 1538:         $markchange = $lt{'onmark'};
 1539:         $currmark = $lt{'ondisp'};
 1540:         $discmark = 'ondisp';
 1541:     }
 1542: 
 1543:     if ($dispchgB eq 'onlyunread') {
 1544:         $dispchangeB = $lt{'unread'};
 1545:         $currdisp = $lt{'unmark'};
 1546:         $discdisp = 'unmark';
 1547:     }
 1548:     if ($toggchg eq 'toggoff') {
 1549:         $toggchange = $lt{'toggoff'};
 1550:         $currtogg = $lt{'toggon'};
 1551:         $disctogg = 'toggon';
 1552:     }
 1553:     $r->print(<<END);
 1554: <html>
 1555: <head>
 1556: <title>$lt{'dido'}</title>
 1557: <meta http-equiv="pragma" content="no-cache" />
 1558: <script>
 1559: function discdispChk(caller) {
 1560:     var disctogg = '$toggchg'
 1561:     if (caller == 0) {
 1562:         if (document.modifydisp.discdisp[0].checked == true) {
 1563:             if (document.modifydisp.discdisp[1].checked == true) {
 1564:                 document.modifydisp.discdisp[1].checked = false
 1565:             }
 1566:         }
 1567:     }
 1568:     if (caller == 1) {
 1569:         if (document.modifydisp.discdisp[1].checked == true) {
 1570:             if (document.modifydisp.discdisp[0].checked == true) {
 1571:                 document.modifydisp.discdisp[0].checked = false
 1572:             }
 1573:             if (disctogg == 'toggon') {
 1574:                 document.modifydisp.disctogg.checked = true
 1575:             }
 1576:             if (disctogg == 'toggoff') {
 1577:                 document.modifydisp.disctogg.checked = false
 1578:             }
 1579:         }
 1580:     }
 1581:     if (caller == 2) {
 1582:         var dispchgB = '$dispchgB'
 1583:         if (disctogg == 'toggoff') {
 1584:             if (document.modifydisp.disctogg.checked == true) {
 1585:                 if (dispchgB == 'onlyunmark') {
 1586:                     document.modifydisp.discdisp[1].checked = false
 1587:                 }
 1588:             }
 1589:         }
 1590:     }  
 1591: }
 1592: 
 1593: function setDisp() {
 1594:     var prev = "$previous"
 1595:     var chktotal = 0
 1596:     if (document.modifydisp.discdisp[0].checked == true) {
 1597:         document.modifydisp.$dispchgA.value = "$symb"
 1598:         chktotal ++
 1599:     }
 1600:     if (document.modifydisp.discdisp[1].checked == true) {
 1601:         document.modifydisp.$dispchgB.value = "$symb"
 1602:         chktotal ++
 1603:     }
 1604:     if (document.modifydisp.discmark.checked == true) {
 1605:         document.modifydisp.$markchg.value = "$symb"
 1606:         chktotal ++
 1607:     }
 1608:     if (document.modifydisp.disctogg.checked == true) {
 1609:         document.modifydisp.$toggchg.value = "$symb"
 1610:         chktotal ++
 1611:     }
 1612:     if (chktotal > 0) { 
 1613:         document.modifydisp.submit()
 1614:     } else {
 1615:         if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}"))      {
 1616:             if (prev > 0) {
 1617:                 location.href = "$feedurl?previous=$previous"
 1618:             } else {
 1619:                 location.href = "$feedurl"
 1620:             }
 1621:         }
 1622:     }
 1623: }
 1624: </script>
 1625: </head>
 1626: $bodytag
 1627: <form name="modifydisp" method="post" action="/adm/feedback">
 1628: $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
 1629: <br />
 1630: <table border="0" cellpadding="0" cellspacing="0">
 1631:  <tr>
 1632:   <td width="100%" bgcolor="#000000">
 1633:    <table width="100%" border="0" cellpadding="1" cellspacing="0">
 1634:     <tr>
 1635:      <td width="100%" bgcolor="#000000">
 1636:       <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
 1637:        <tr bgcolor="$tabcolor">
 1638:         <td><b>$lt{'pref'}</b></td>
 1639:         <td><b>$lt{'curr'}</b></td>
 1640:         <td><b>$lt{'actn'}?</b></td>
 1641:        </tr>
 1642:        <tr bgcolor="#dddddd">
 1643:        <td>$lt{'disa'}</td>
 1644:        <td>$lt{$discdisp}</td>
 1645:        <td><input type="checkbox" name="discdisp" onClick="discdispChk('0')" />&nbsp;$lt{'chgt'} "$dispchangeA"
 1646:            <br />
 1647:            <input type="checkbox" name="discdisp" onClick="discdispChk('1')" />&nbsp;$lt{'chgt'} "$dispchangeB"
 1648:        </td>
 1649:       </tr><tr bgcolor="#eeeeee">
 1650:        <td>$lt{'npmr'}</td>
 1651:        <td>$lt{$discmark}</td>
 1652:        <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
 1653:       </tr><tr bgcolor="#dddddd">
 1654:        <td>$lt{'dotm'}</td>
 1655:        <td>$lt{$disctogg}</td>
 1656:        <td><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</td>
 1657:       </tr>
 1658:      </table>
 1659:     </td>
 1660:    </tr>
 1661:   </table>
 1662:  </td>
 1663: </tr>
 1664: </table>
 1665: <br />
 1666: <br />
 1667: <input type="hidden" name="previous" value="$previous" />
 1668: <input type="hidden" name="$dispchgA" value=""/>
 1669: <input type="hidden" name="$dispchgB" value=""/>
 1670: <input type="hidden" name="$markchg" value=""/>
 1671: <input type="hidden" name="$toggchg" value="" />
 1672: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
 1673: <br />
 1674: <br />
 1675: </form>
 1676: </body>
 1677: </html>
 1678: END
 1679:     return;
 1680: }
 1681: 
 1682: sub print_sortfilter_options {
 1683:     my ($r,$symb,$previous,$feedurl) = @_;
 1684:  # backward compatibility (bulletin boards used to be 'wrapped')
 1685:     if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 1686:         $feedurl=~s|^/adm/wrapper||;
 1687:     }
 1688:     my @sections = ();
 1689:     my $section_sel = '';
 1690:     my $numsections = 0;
 1691:     my $numvisible = 5;
 1692:     my ($classlist) = &Apache::loncoursedata::get_classlist(
 1693:                               $ENV{'request.course.id'},
 1694:                               $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1695:                               $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1696:                                                                                    
 1697:     my $sec_index = &Apache::loncoursedata::CL_SECTION();
 1698:     my $status_index = &Apache::loncoursedata::CL_STATUS();
 1699:     my %sectioncount = ();
 1700:     while (my ($student,$data) = each %$classlist) {
 1701:         my ($section,$status) = ($data->[$sec_index],
 1702:                                  $data->[$status_index]);
 1703:         unless ($section eq '' || $section =~ /^\s*$/) {
 1704:             if (!defined($sectioncount{$section})) {
 1705:                 $sectioncount{$section} = 1;
 1706:                 $numsections ++;
 1707:             } else {
 1708:                 $sectioncount{$section} ++;
 1709:             }
 1710:         }
 1711:     }
 1712:                                                                                    
 1713:     if ($ENV{'request.course.sec'} !~ /^\s*$/) {
 1714:         @sections = ($ENV{'request.course.sec'});
 1715:         $numvisible = 1;
 1716:     } else {
 1717:         @sections = sort {$a cmp $b} keys(%sectioncount);
 1718:         unshift(@sections,'all'); # Put 'all' at the front of the list
 1719:         if ($numsections < 4) {
 1720:             $numvisible = $numsections + 1;
 1721:         }
 1722:     }
 1723:     foreach (@sections) {
 1724:         $section_sel .= "  <option value=\"$_\" />$_\n";
 1725:     }
 1726:                                                                                    
 1727:     my $function = &Apache::loncommon::get_users_function();
 1728:     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
 1729:                                                     $ENV{'user.domain'});
 1730:     my $bodytag=&Apache::loncommon::bodytag('Discussion options',
 1731:                                           '','');
 1732:     my %lt = &Apache::lonlocal::texthash(
 1733:         'diso' => 'Discussion sorting and filtering options',
 1734:         'diop' => 'Display Options',
 1735:         'curr' => 'Current setting ',
 1736:         'actn' => 'Action',
 1737:         'prca' => 'Options can be set that control the sort order of the posts, in addition to which posts are displayed.',
 1738:         'soor' => 'Sort order',
 1739:         'disp' => 'Specific user roles',
 1740:         'actv' => 'Specific role status',
 1741:         'spse' => 'Specific sections',
 1742:         'psub' => 'Pick specific users (by name)',
 1743:         'shal' => 'Show a list of current posters'
 1744:     );
 1745:     $r->print(<<END);
 1746: <html>
 1747: <head>
 1748: <title>$lt{'diso'}</title>
 1749: <meta http-equiv="pragma" content="no-cache" />
 1750: </head>
 1751: $bodytag
 1752: <form name="modifyshown" method="post" action="/adm/feedback">
 1753: <b>$lt{'diso'}</b><br/> $lt{'prca'}
 1754: <br /><br />
 1755: <table border="0">
 1756:  <tr>
 1757:   <td><b>$lt{'soor'}</b></td>
 1758:   <td>&nbsp;</td>
 1759:   <td><b>$lt{'disp'}</b></td>
 1760:   <td>&nbsp;</td>
 1761:   <td><b>$lt{'actv'}</b></td>
 1762:   <td>&nbsp;</td>
 1763:   <td><b>$lt{'spse'}</b></td>
 1764:   <td>&nbsp;</td>
 1765:   <td><b>$lt{'psub'}</b></td>
 1766:  </tr>
 1767:  <tr>
 1768:   <td>
 1769:    <select name="sortposts">
 1770:     <option value="ascdate" />Date order - oldest first
 1771:     <option value="descdate" />Date order - newest first
 1772:     <option value="thread" />Threaded
 1773:     <option value="subject" />By subject
 1774:     <option value="username" />By domain and username
 1775:     <option value="lastfirst" />By last name, first name
 1776:    </select>
 1777:   </td>
 1778:   <td>&nbsp;</td>
 1779:   <td>
 1780:    <select name="rolefilter" multiple="true" size="5">
 1781:     <option value="all" />All users
 1782:     <option value="st" />Students
 1783:     <option value="cc" />Course Coordinators
 1784:     <option value="in" />Instructors
 1785:     <option value="ta" />TAs
 1786:     <option value="pr" />Exam proctors
 1787:     <option value="cr" />Custom roles
 1788:    </select>
 1789:   </td>
 1790:   <td>&nbsp;</td>
 1791:   <td>
 1792:    <select name="statusfilter">
 1793:     <option value="all" />Roles of any status
 1794:     <option value="Active" />Only active roles
 1795:     <option value="Expired" />Only inactive roles
 1796:    </select>
 1797:   </td>
 1798:   <td>&nbsp;</td>
 1799:   <td>
 1800:    <select name="sectionpick" multiple="true" size="$numvisible">
 1801:     $section_sel
 1802:    </select>
 1803:   </td>
 1804:   <td>&nbsp;</td>
 1805:   <td><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</td>
 1806:  </tr>
 1807: </table>
 1808: <br />
 1809: <br />
 1810: <input type="hidden" name="previous" value="$previous" />
 1811: <input type="hidden" name="applysort" value="$symb" />
 1812: <input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
 1813: <br />
 1814: <br />
 1815: </form>
 1816: </body>
 1817: </html>
 1818: END
 1819: }
 1820: 
 1821: sub print_showposters {
 1822:     my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
 1823:  # backward compatibility (bulletin boards used to be 'wrapped')
 1824:     if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 1825:         $feedurl=~s|^/adm/wrapper||;
 1826:     }
 1827: # backward compatibility (bulletin boards used to be 'wrapped')
 1828:     my $ressymb=$symb;
 1829:     if ($ressymb =~ /bulletin___\d+___/) {
 1830:         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 1831:             $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 1832:         }
 1833:     }
 1834:     my $crs='/'.$ENV{'request.course.id'};
 1835:     if ($ENV{'request.course.sec'}) {
 1836:         $crs.='_'.$ENV{'request.course.sec'};
 1837:     }
 1838:     $crs=~s/\_/\//g;
 1839:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
 1840:     my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
 1841:                           $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1842:                           $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1843:     my %namesort = ();
 1844:     my %postcounts = ();
 1845:     my %lt=&Apache::lonlocal::texthash(
 1846:                      'diso' => 'Discussion filtering options',
 1847:     );
 1848:     my $bodytag=&Apache::loncommon::bodytag('Discussion options',
 1849:                                           '','');
 1850:     if ($contrib{'version'}) {
 1851:         for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
 1852:             my $hidden=($contrib{'hidden'}=~/\.$idx\./);
 1853:             my $deleted=($contrib{'deleted'}=~/\.$idx\./);
 1854:             unless ((($hidden) && (!$seeid)) || ($deleted)) {
 1855:                 if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
 1856:                     my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
 1857:                     my $lastname = $names{'lastname'};
 1858:                     my $firstname = $names{'firstname'};
 1859:                     if ($lastname eq '') {
 1860:                         $lastname = '_';
 1861:                     }
 1862:                     if ($firstname eq '') {
 1863:                         $firstname = '_';
 1864:                     }
 1865:                     unless (defined($namesort{$lastname})) {
 1866:                         %{$namesort{$lastname}} = ();
 1867:                     }
 1868:                     my $poster =  $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
 1869:                     $postcounts{$poster} ++;
 1870:                     if (defined($namesort{$lastname}{$firstname})) {
 1871:                         if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
 1872:                             push @{$namesort{$lastname}{$firstname}}, $poster;
 1873:                         }
 1874:                     } else {
 1875:                         @{$namesort{$lastname}{$firstname}} = ("$poster");
 1876:                     }
 1877:                 }
 1878:             }
 1879:         }
 1880:     }
 1881:     $r->print(<<END);
 1882: <html>
 1883: <head>
 1884: <title>$lt{'diso'}</title>
 1885: <meta http-equiv="pragma" content="no-cache" />
 1886: </head>
 1887: $bodytag
 1888:  <form name="pickpostersform" method="post">
 1889:   <table border="0">
 1890:    <tr>
 1891:     <td bgcolor="#777777">
 1892:      <table border="0" cellpadding="3">
 1893:       <tr bgcolor="#e6ffff">
 1894:        <td><b>No.</b></td>
 1895:        <td><b>Select</b></td>
 1896:        <td><b>Fullname</b><font color="#999999">(Username/domain)</font></td>
 1897:        <td><b>Posts</td>
 1898:       </tr>
 1899: END
 1900:     my $count = 0;
 1901:     foreach my $last (sort keys %namesort) {
 1902:         foreach my $first (sort keys %{$namesort{$last}}) {
 1903:             foreach (sort @{$namesort{$last}{$first}}) {
 1904:                 my ($uname,$udom) = split/:/,$_;
 1905:                 if (!$uname || !$udom) { 
 1906:                     next;
 1907:                 } else {
 1908:                     $count ++;
 1909:                     $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>');
 1910:                 }
 1911:             }
 1912:         }
 1913:     }
 1914:     $r->print(<<END);
 1915:      </table>
 1916:     </td>
 1917:    </tr>
 1918:   </table>
 1919: <br />
 1920: <input type="hidden" name="sortposts" value="$sortposts" />
 1921: <input type="hidden" name="userpick" value="$symb" />
 1922: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
 1923: </form>
 1924: </body>
 1925: </html>
 1926: END
 1927: }
 1928: 
 1929: sub get_post_versions {
 1930:     my ($versions,$incoming,$htmldecode,$numver) = @_;
 1931:     if ($incoming =~ /^<version num="0">/) {
 1932:         my $p = HTML::LCParser->new(\$incoming);
 1933:         my $done = 0;                                                                       
 1934:         while ( (my $token = $p->get_tag("version")) && (!$done)) {
 1935:             my $num = $token->[1]{num};
 1936:             my $text = $p->get_text("/version");
 1937:             if (defined($numver)) {
 1938:                 if ($num == $numver) {
 1939:                     if ($htmldecode) {
 1940:                         $text = &HTML::Entities::decode($text);
 1941:                     }
 1942:                     $$versions{$numver}=$text;
 1943:                     $done = 1;
 1944:                 }
 1945:             } else {
 1946:                 if ($htmldecode) {
 1947:                     $text = &HTML::Entities::decode($text);
 1948:                 }
 1949:                 $$versions{$num}=$text;
 1950:             }
 1951:         }
 1952:     } else {
 1953:         if (!defined($numver)) {
 1954:             $numver = 0;
 1955:         }
 1956:         if ($htmldecode) {
 1957:             $$versions{$numver} = $incoming;
 1958:         } else {
 1959:             $$versions{$numver} = &HTML::Entities::encode($incoming,'<>&"');
 1960:         }
 1961:     }
 1962:     return;
 1963: }
 1964: 
 1965: sub get_post_attachments {
 1966:     my ($attachments,$attachmenturls) = @_;
 1967:     my $num;
 1968:     if ($attachmenturls =~ m/^<attachment id="0">/) {
 1969:         my $p = HTML::LCParser->new(\$attachmenturls);
 1970:         while (my $token = $p->get_tag("attachment","filename","post"))  {
 1971:             if ($token->[0] eq "attachment") {
 1972:                 $num = $token->[1]{id};
 1973:                 %{$$attachments{$num}} =();
 1974:             } elsif ($token->[0] eq "filename") {
 1975:                 $$attachments{$num}{'filename'} = $p->get_text("/filename");
 1976:             } elsif ($token->[0] eq "post") {
 1977:                 my $id = $token->[1]{id};
 1978:                 $$attachments{$num}{$id} = $p->get_text("/post");
 1979:             }
 1980:         }
 1981:     } else {
 1982:         %{$$attachments{'0'}} = ();
 1983:         $$attachments{'0'}{'filename'} = $attachmenturls;
 1984:         $$attachments{'0'}{'0'} = 'n';
 1985:     }
 1986: 
 1987:     return;
 1988: }
 1989: 
 1990: sub fail_redirect {;
 1991:   my ($r,$feedurl) = @_;
 1992:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
 1993:   $r->print (<<ENDFAILREDIR);
 1994: <html>
 1995: <head><title>Feedback not sent</title>
 1996: <meta http-equiv="pragma" content="no-cache" />
 1997: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
 1998: </head>
 1999: <body bgcolor="#FFFFFF">
 2000: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
 2001: <b>Sorry, no recipients  ...</b>
 2002: <br /><a href="$feedurl">Continue</a>
 2003: </body>
 2004: </html>
 2005: ENDFAILREDIR
 2006: }
 2007: 
 2008: sub redirect_back {
 2009:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$secpick,$numpicks) = @_;
 2010:   my $sorttag = '';
 2011:   my $roletag = '';
 2012:   my $statustag = '';
 2013:   my $sectag = '';
 2014:   my $userpicktag = '';
 2015:   my $qrystr = '';
 2016:   my $prevtag = '';
 2017:  # backward compatibility (bulletin boards used to be 'wrapped')
 2018:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 2019:       $feedurl=~s|^/adm/wrapper||;
 2020:   }
 2021:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
 2022:   if ($previous > 0) {
 2023:       $qrystr = 'previous='.$previous;
 2024:       if ($feedurl =~ /\?register=1/) {
 2025:           $feedurl .= '&'.$qrystr;
 2026:       } else {
 2027:           $feedurl .= '?'.$qrystr;
 2028:       }
 2029:       $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
 2030:   }
 2031:   if (defined($sort)) {
 2032:       my $sortqry = 'sortposts='.$sort;
 2033:       if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
 2034:           $feedurl .= '&'.$sortqry;
 2035:       } else {
 2036:           $feedurl .= '?'.$sortqry;
 2037:       }
 2038:       $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
 2039:       if ( (defined($numpicks)) && ($numpicks > 0) ) {
 2040:           my $userpickqry = 'totposters='.$numpicks;
 2041:           $feedurl .= '&'.$userpickqry;
 2042:           $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
 2043:       } else {
 2044:           my $roleqry = 'rolefilter='.$rolefilter;
 2045:           $feedurl .= '&'.$roleqry;
 2046:           $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
 2047:           $feedurl .= '&statusfilter='.$statusfilter;
 2048:           $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
 2049:           $feedurl .= '&sectionpick='.$secpick;
 2050:           $sectag = '<input type="hidden" name="sectionpick" value="'.$secpick.'" />';
 2051:       }
 2052:   }
 2053:   $feedurl=&Apache::lonenc::check_encrypt($feedurl);
 2054:   $r->print (<<ENDREDIR);
 2055: <html>
 2056: <head>
 2057: <title>Feedback sent</title>
 2058: <meta http-equiv="pragma" content="no-cache" />
 2059: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
 2060: </head>
 2061: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
 2062: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
 2063: $typestyle
 2064: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
 2065: <font color="red">$status</font>
 2066: <form name="reldt" action="$feedurl" target="loncapaclient">
 2067: $prevtag
 2068: $sorttag
 2069: $statustag
 2070: $roletag
 2071: $sectag
 2072: $userpicktag
 2073: </form>
 2074: <br /><a href="$feedurl">Continue</a>
 2075: </body>
 2076: </html>
 2077: ENDREDIR
 2078: }
 2079: 
 2080: sub no_redirect_back {
 2081:   my ($r,$feedurl) = @_;
 2082:   my $nofeed=&mt('Sorry, no feedback possible on this resource  ...');
 2083:   my $continue=&mt('Continue');
 2084:   $r->print (<<ENDNOREDIR);
 2085: <html>
 2086: <head><title>Feedback not sent</title>
 2087: <meta http-equiv="pragma" content="no-cache" />
 2088: ENDNOREDIR
 2089: 
 2090:   if ($feedurl!~/^\/adm\/feedback/) { 
 2091:       $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.
 2092: 		&Apache::lonenc::check_encrypt($feedurl).'">');
 2093:   }
 2094:   $feedurl=&Apache::lonenc::check_encrypt($feedurl);
 2095:   $r->print (<<ENDNOREDIRTWO);
 2096: </head>
 2097: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
 2098: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
 2099: <b>$nofeed</b>
 2100: <br /><a href="$feedurl">$continue</a>
 2101: </body>
 2102: </html>
 2103: ENDNOREDIRTWO
 2104: }
 2105: 
 2106: sub screen_header {
 2107:     my ($feedurl) = @_;
 2108:     my $msgoptions='';
 2109:     my $discussoptions='';
 2110:     unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
 2111: 	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
 2112: 	    $msgoptions= 
 2113: 		'<p><input type="checkbox" name="author" /> '.
 2114: 		&mt('Feedback to resource author').'</p>';
 2115: 	}
 2116: 	if (&feedback_available(1)) {
 2117: 	    $msgoptions.=
 2118: 		'<br /><input type="checkbox" name="question" /> '.
 2119: 		&mt('Question about resource content');
 2120: 	}
 2121: 	if (&feedback_available(0,1)) {
 2122: 	    $msgoptions.=
 2123: 		'<br /><input type="checkbox" name="course" /> '.
 2124: 		&mt('Question/Comment/Feedback about course content');
 2125: 	}
 2126: 	if (&feedback_available(0,0,1)) {
 2127: 	    $msgoptions.=
 2128: 		'<br /><input type="checkbox" name="policy" /> '.
 2129: 		&mt('Question/Comment/Feedback about course policy');
 2130: 	}
 2131:     }
 2132:     if ($ENV{'request.course.id'}) {
 2133: 	if (&discussion_open() &&
 2134: 	    &Apache::lonnet::allowed('pch',
 2135: 				     $ENV{'request.course.id'}.
 2136: 				     ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
 2137: 	    $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
 2138: 		($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
 2139: 		&mt('Contribution to course discussion of resource');
 2140: 	    $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
 2141: 		&mt('Anonymous contribution to course discussion of resource').
 2142: 		' <i>('.&mt('name only visible to course faculty').')</i>';
 2143:       }
 2144:     }
 2145:     if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
 2146:     if ($discussoptions) { 
 2147: 	$discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
 2148:     return $msgoptions.$discussoptions;
 2149: }
 2150: 
 2151: sub resource_output {
 2152:   my ($feedurl) = @_;
 2153:   my $usersaw=&Apache::lonnet::ssi_body($feedurl);
 2154:   $usersaw=~s/\<body[^\>]*\>//gi;
 2155:   $usersaw=~s/\<\/body\>//gi;
 2156:   $usersaw=~s/\<html\>//gi;
 2157:   $usersaw=~s/\<\/html\>//gi;
 2158:   $usersaw=~s/\<head\>//gi;
 2159:   $usersaw=~s/\<\/head\>//gi;
 2160:   $usersaw=~s/action\s*\=/would_be_action\=/gi;
 2161:   return $usersaw;
 2162: }
 2163: 
 2164: sub clear_out_html {
 2165:   my ($message,$override)=@_;
 2166:   unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
 2167: # Always allow the <m>-tag
 2168:   my %html=(M=>1);
 2169: # Check if more is allowed
 2170:   my $cid=$ENV{'request.course.id'};
 2171:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
 2172:       ($override)) {
 2173:       # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> 
 2174:       # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
 2175:       # <SUP>
 2176:       %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
 2177: 	     BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
 2178: 	     M=>1, SUB=>1, SUP=>1, SPAN=>1, 
 2179: 	     H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
 2180:   }
 2181: # Do the substitution of everything that is not explicitly allowed
 2182:   $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
 2183: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
 2184:   $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
 2185: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
 2186:   return $message;
 2187: }
 2188: 
 2189: sub assemble_email {
 2190:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
 2191:   my $email=<<"ENDEMAIL";
 2192: Refers to <a href="$feedurl">$feedurl</a>
 2193: 
 2194: $message
 2195: ENDEMAIL
 2196:     my $citations=<<"ENDCITE";
 2197: <h2>Previous attempts of student (if applicable)</h2>
 2198: $prevattempts
 2199: <br /><hr />
 2200: <h2>Original screen output (if applicable)</h2>
 2201: $usersaw
 2202: <h2>Correct Answer(s) (if applicable)</h2>
 2203: $useranswer
 2204: ENDCITE
 2205:   return ($email,$citations);
 2206: }
 2207: 
 2208: sub secapply {
 2209:     my $rec=shift;
 2210:     my $defaultflag=shift;
 2211:     $rec=~s/\s+//g;
 2212:     $rec=~s/\@/\:/g;
 2213:     my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
 2214:     if ($sections) {
 2215: 	foreach (split(/\;/,$sections)) {
 2216:             if (($_ eq $ENV{'request.course.sec'}) ||
 2217:                 ($defaultflag && ($_ eq '*'))) {
 2218:                 return $adr; 
 2219:             }
 2220:         }
 2221:     } else {
 2222:        return $rec;
 2223:     }
 2224:     return '';
 2225: }
 2226: 
 2227: sub decide_receiver {
 2228:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
 2229:   my $typestyle='';
 2230:   my %to=();
 2231:   if ($ENV{'form.author'}||$author) {
 2232:     $typestyle.='Submitting as Author Feedback<br>';
 2233:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
 2234:     $to{$2.':'.$1}=1;
 2235:   }
 2236:   if ($ENV{'form.question'}||$question) {
 2237:     $typestyle.='Submitting as Question<br>';
 2238:     foreach (split(/\,/,
 2239: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
 2240: 	     ) {
 2241: 	my $rec=&secapply($_,$defaultflag);
 2242:         if ($rec) { $to{$rec}=1; }
 2243:     } 
 2244:   }
 2245:   if ($ENV{'form.course'}||$course) {
 2246:     $typestyle.='Submitting as Comment<br />';
 2247:     foreach (split(/\,/,
 2248: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
 2249: 	     ) {
 2250: 	my $rec=&secapply($_,$defaultflag);
 2251:         if ($rec) { $to{$rec}=1; }
 2252:     } 
 2253:   }
 2254:   if ($ENV{'form.policy'}||$policy) {
 2255:     $typestyle.='Submitting as Policy Feedback<br />';
 2256:     foreach (split(/\,/,
 2257: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
 2258: 	     ) {
 2259: 	my $rec=&secapply($_,$defaultflag);
 2260:         if ($rec) { $to{$rec}=1; }
 2261:     } 
 2262:   }
 2263:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
 2264:      ($typestyle,%to)=
 2265: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
 2266:   }
 2267:   return ($typestyle,%to);
 2268: }
 2269: 
 2270: sub feedback_available {
 2271:     my ($question,$course,$policy)=@_;
 2272:     my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
 2273:     return scalar(%to);
 2274: }
 2275: 
 2276: sub send_msg {
 2277:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
 2278:   my $status='';
 2279:   my $sendsomething=0;
 2280:   foreach (keys %to) {
 2281:     if ($_) {
 2282:       my $declutter=&Apache::lonnet::declutter($feedurl);
 2283:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
 2284:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
 2285:                 $attachmenturl)=~/ok/) {
 2286: 	$status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
 2287:       } else {
 2288: 	$sendsomething++;
 2289:       }
 2290:     }
 2291:   }
 2292: 
 2293:     my %record=&Apache::lonnet::restore('_feedback');
 2294:     my ($temp)=keys %record;
 2295:     unless ($temp=~/^error\:/) {
 2296:        my %newrecord=();
 2297:        $newrecord{'resource'}=$feedurl;
 2298:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
 2299:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
 2300: 	   $status.='<br />'.&mt('Not registered').'<br />';
 2301:        }
 2302:     }
 2303:        
 2304:   return ($status,$sendsomething);
 2305: }
 2306: 
 2307: sub adddiscuss {
 2308:     my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
 2309:     my $status='';
 2310:     my $realsymb;
 2311:     if ($symb=~/^bulletin___/) {
 2312: 	my $filename=(&Apache::lonnet::decode_symb($symb))[2];
 2313: 	$filename=~s|^adm/wrapper/||;
 2314: 	$realsymb=&Apache::lonnet::symbread($filename);
 2315:     }
 2316:     if (&discussion_open(undef,$realsymb) &&
 2317: 	&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
 2318:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
 2319: 
 2320:     my %contrib=('message'      => $email,
 2321:                  'sendername'   => $ENV{'user.name'},
 2322:                  'senderdomain' => $ENV{'user.domain'},
 2323:                  'screenname'   => $ENV{'environment.screenname'},
 2324:                  'plainname'    => $ENV{'environment.firstname'}.' '.
 2325: 		                   $ENV{'environment.middlename'}.' '.
 2326:                                    $ENV{'environment.lastname'}.' '.
 2327:                                    $ENV{'enrironment.generation'},
 2328:                  'attachmenturl'=> $attachmenturl,
 2329:                  'subject'      => $subject);
 2330:     if ($ENV{'form.replydisc'}) {
 2331: 	$contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
 2332:     }
 2333:     if ($anon) {
 2334: 	$contrib{'anonymous'}='true';
 2335:     }
 2336:     if (($symb) && ($email)) {
 2337:         if ($ENV{'form.editdisc'}) {
 2338:             my %newcontrib = ();
 2339:             $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
 2340:             $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
 2341:             $contrib{'timestamp'} = time;
 2342:             $contrib{'history'} = '';
 2343:             my $numoldver = 0;
 2344:             my ($oldsymb,$oldidx)=split(/\:\:\:/,$ENV{'form.editdisc'});
 2345:             $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
 2346: # get timestamp for last post and history
 2347:             my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
 2348:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 2349:                      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 2350:             if (defined($oldcontrib{$oldidx.':replyto'})) {
 2351:                 $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
 2352:             }
 2353:             if (defined($oldcontrib{$oldidx.':history'})) {
 2354:                 if ($oldcontrib{$oldidx.':history'} =~ /:/) {
 2355:                     my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
 2356:                     $numoldver = @oldversions;
 2357:                 } else {
 2358:                     $numoldver = 1;
 2359:                 }
 2360:                 $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
 2361:             }
 2362:             my $numnewver = $numoldver + 1;
 2363:             if (defined($oldcontrib{$oldidx.':subject'})) {
 2364:                 if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
 2365:                     $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
 2366:                     $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
 2367:                 } else {
 2368:                     $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
 2369:                 }
 2370:             } 
 2371:             if (defined($oldcontrib{$oldidx.':message'})) {
 2372:                 if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
 2373:                     $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
 2374:                     $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
 2375:                 } else {
 2376:                     $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
 2377:                 }
 2378:             }
 2379:             $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
 2380:             foreach (keys %contrib) {
 2381:                 my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;                                                                               
 2382:                 $newcontrib{$key} = $contrib{$_};
 2383:             }
 2384:             my $put_reply = &Apache::lonnet::putstore($ENV{'request.course.id'},
 2385:                   \%newcontrib,
 2386:                   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 2387:                   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 2388:             $status='Editing class discussion'.($anon?' (anonymous)':'');
 2389:         } else {
 2390:            $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
 2391:            &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
 2392:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 2393: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 2394:         }
 2395:         my %storenewentry=($symb => time);
 2396:         $status.='<br />'.&mt('Updating discussion time').': '.
 2397:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
 2398:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 2399: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 2400:     }
 2401:     my %record=&Apache::lonnet::restore('_discussion');
 2402:     my ($temp)=keys %record;
 2403:     unless ($temp=~/^error\:/) {
 2404:        my %newrecord=();
 2405:        $newrecord{'resource'}=$symb;
 2406:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
 2407:        $status.='<br />'.&mt('Registering').': '.
 2408:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
 2409:     }
 2410:     } else {
 2411: 	$status.='Failed.';
 2412:     }
 2413:     return $status.'<br />';   
 2414: }
 2415: 
 2416: # ----------------------------------------------------------- Preview function
 2417: 
 2418: sub show_preview {
 2419:     my $r=shift;
 2420:     my $message=&clear_out_html($ENV{'form.comment'});
 2421:     $message=~s/\n/\<br \/\>/g;
 2422:     $message=&Apache::lonspeller::markeduptext($message);
 2423:     $message=&Apache::lontexconvert::msgtexconverted($message);
 2424:     my $subject=&clear_out_html($ENV{'form.subject'});
 2425:     $subject=~s/\n/\<br \/\>/g;
 2426:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
 2427:     $r->print('<table border="2"><tr><td>'.
 2428:        '<b>Subject:</b> '.$subject.'<br /><br />'.
 2429:        $message.'</td></tr></table>');
 2430: }
 2431: 
 2432: sub generate_preview_button {
 2433:     my $pre=&mt("Show Preview and Check Spelling");
 2434:     return(<<ENDPREVIEW);
 2435: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
 2436: <input type="hidden" name="subject">
 2437: <input type="hidden" name="comment" />
 2438: <input type="button" value="$pre"
 2439: onClick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
 2440: </form>
 2441: ENDPREVIEW
 2442: }
 2443: 
 2444: sub modify_attachments {
 2445:     my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
 2446:     my $orig_subject = &Apache::lonnet::unescape($ENV{'form.subject'});
 2447:     my $subject=&clear_out_html($orig_subject);
 2448:     $subject=~s/\n/\<br \/\>/g;
 2449:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
 2450:     my $timestamp=$ENV{'form.timestamp'};
 2451:     my $numoldver=$ENV{'form.numoldver'};
 2452:     my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
 2453:                                           '','');
 2454:     my $msg = '';
 2455:     my %attachments = ();
 2456:     my %currattach = ();
 2457:     if ($idx) {
 2458:         &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
 2459:     }
 2460:     $r->print(<<END);
 2461: <html>
 2462: <head>
 2463: <title>Managing Attachments</title>
 2464: <script>
 2465:  function setAction () {
 2466:    document.modattachments.action = document.modattachments.origpage.value;
 2467:    document.modattachments.submit();
 2468:  }
 2469: </script> 
 2470: </head>
 2471: $bodytag
 2472: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
 2473:  <table border="2">
 2474:   <tr>
 2475:    <td>
 2476:     <b>Subject:</b> $subject</b><br /><br />
 2477: END
 2478:     if ($idx) {
 2479:         if ($attachmenturls) {
 2480:             my @currold = keys %currattach;
 2481:             if (@currold > 0) {
 2482:                 $r->print("The following attachments were part of the most recent saved version of this posting.<br />Check the checkboxes for any you wish to remove<br />\n");  
 2483:                 foreach my $id (@currold) {
 2484:                     my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'}); 
 2485:                     $attachurl =~ m#/([^/]+)$#;
 2486:                     $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" />&nbsp;'.$1.'<br />'."\n");
 2487:                 }
 2488:                 $r->print("<br />");
 2489:             }
 2490:         }
 2491:     }
 2492:     if (@{$currnewattach} > 0) {
 2493:         $r->print("The following attachments have been uploaded for inclusion with this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
 2494:         foreach (@{$currnewattach}) {
 2495:             $_ =~ m#/([^/]+)$#;
 2496:             $r->print('<input type="checkbox" name="delnewattach" value="'.$_.'" />&nbsp;'.$1.'<br />'."\n");
 2497:         }
 2498:         $r->print("<br />"); 
 2499:     }
 2500:     $r->print(<<END);
 2501:    Add a new attachment to this post.&nbsp;<input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />    
 2502:    </td>
 2503:   </tr>
 2504:  </table>
 2505: <input type="hidden" name="subject" value="$ENV{'form.subject'}" />
 2506: <input type="hidden" name="comment" value="$ENV{'form.comment'}" />
 2507: <input type="hidden" name="timestamp" value="$ENV{'form.timestamp'}" />
 2508: <input type="hidden" name="idx" value="$ENV{'form.idx'}" />
 2509: <input type="hidden" name="numoldver" value="$ENV{'form.numoldver'}" />
 2510: <input type="hidden" name="origpage" value="$ENV{'form.origpage'}" />
 2511: <input type="hidden" name="anondiscuss" value="$ENV{'form.anondiscuss'}" />
 2512: <input type="hidden" name="discuss" value="$ENV{'form.discuss'}" />
 2513: END
 2514:     foreach (@{$currnewattach}) {
 2515:         $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
 2516:     }
 2517:     foreach (@{$currdelold}) {
 2518:         $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
 2519:     }
 2520:     $r->print(<<END);
 2521:  <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
 2522: </form>
 2523: </body>
 2524: </html>
 2525: END
 2526:     return;
 2527: }
 2528: 
 2529: sub process_attachments {
 2530:     my ($currnewattach,$currdelold,$keepold) = @_;
 2531:     if (exists($ENV{'form.currnewattach'})) {
 2532:         if (ref($ENV{'form.currnewattach'}) eq 'ARRAY') {
 2533:             @{$currnewattach} = @{$ENV{'form.currnewattach'}};
 2534:         } else {
 2535:             $$currnewattach[0] = $ENV{'form.currnewattach'};
 2536:         }
 2537:     }
 2538:     if (exists($ENV{'form.deloldattach'})) {
 2539:         if (ref($ENV{'form.deloldattach'}) eq 'ARRAY') {
 2540:             @{$currdelold} = @{$ENV{'form.deloldattach'}};
 2541:         } else {
 2542:             $$currdelold[0] = $ENV{'form.deloldattach'};
 2543:         }
 2544:     }
 2545:     if (exists($ENV{'form.delnewattach'})) {
 2546:         my @currdelnew = ();
 2547:         my @currnew = ();
 2548:         if (ref($ENV{'form.delnewattach'}) eq 'ARRAY') {
 2549:             @currdelnew = @{$ENV{'form.delnewattach'}};
 2550:         } else {
 2551:             $currdelnew[0] = $ENV{'form.delnewattach'};
 2552:         }
 2553:         foreach my $newone (@{$currnewattach}) {
 2554:             my $delflag = 0;
 2555:             foreach (@currdelnew) {
 2556:                 if ($newone eq $_) {
 2557:                     $delflag = 1;
 2558:                     last;
 2559:                 }
 2560:             }
 2561:             unless ($delflag) {
 2562:                 push @currnew, $newone;
 2563:             }
 2564:         }
 2565:         @{$currnewattach} = @currnew;
 2566:     }
 2567:     if (exists($ENV{'form.keepold'})) {
 2568:         if (ref($ENV{'form.keepold'}) eq 'ARRAY') {
 2569:             @{$keepold} = @{$ENV{'form.keepold'}};
 2570:         } else {
 2571:             $$keepold[0] = $ENV{'form.keepold'};
 2572:         }
 2573:     }
 2574: }
 2575: 
 2576: sub generate_attachments_button {
 2577:     my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
 2578:     my $origpage = $ENV{'REQUEST_URI'};
 2579:     my $att=$attachnum.' '.&mt("attachments");
 2580:     my $response = (<<END);
 2581: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
 2582: Click to add/remove attachments:&nbsp;<input type="button" value="$att"
 2583: onClick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=escape(document.mailform.comment.value);this.form.subject.value=escape(document.mailform.subject.value);
 2584: END
 2585:     unless ($mode eq 'board') {
 2586:         $response .= 'javascript:anonchk();';
 2587:     }
 2588:     $response .= (<<ENDATTACH);
 2589: this.form.submit();" />
 2590: <input type="hidden" name="origpage" value="$origpage" />
 2591: <input type="hidden" name="idx" value="$idx" />
 2592: <input type="hidden" name="timestamp" value="$now" />
 2593: <input type="hidden" name="subject" />
 2594: <input type="hidden" name="comment" />
 2595: <input type="hidden" name="anondiscuss" value = "0";
 2596: <input type="hidden" name="discuss" value = "0";
 2597: <input type="hidden" name="numoldver" value="$numoldver" />
 2598: ENDATTACH
 2599:     if (defined($deloldattach)) {
 2600:         if (@{$deloldattach} > 0) {
 2601:             foreach (@{$deloldattach}) {
 2602:                 $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
 2603:             }
 2604:         }
 2605:     }
 2606:     if (defined($currnewattach)) {
 2607:         if (@{$currnewattach} > 0) {
 2608:             foreach (@{$currnewattach}) {
 2609:                 $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
 2610:             }
 2611:         }
 2612:     }
 2613:     $response .= '</form>';
 2614:     return $response;
 2615: }
 2616: 
 2617: sub extract_attachments {
 2618:     my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
 2619:     %{$attachments}=();
 2620:     &get_post_attachments($attachments,$attachmenturls);
 2621:     foreach my $id (sort keys %{$attachments}) {
 2622:         if (exists($$attachments{$id}{$numoldver})) {
 2623:             if (defined($currdelold)) {
 2624:                 if (@{$currdelold} > 0) {
 2625:                     unless (grep/^$id$/,@{$currdelold}) {
 2626:                         $$currattach{$id} = $$attachments{$id}{$numoldver}; 
 2627:                     }
 2628:                 } else {
 2629:                     $$currattach{$id} = $$attachments{$id}{$numoldver};
 2630:                 }
 2631:             } else {
 2632:                 $$currattach{$id} = $$attachments{$id}{$numoldver};
 2633:             }
 2634:         }
 2635:     }
 2636:     my @attached = (sort { $a <=> $b } keys %{$currattach});
 2637:     if (@attached == 1) {
 2638:         my $id = $attached[0];
 2639:         my $attachurl;
 2640:         if ($attachmenturls =~ m/^<attachment id="0">/) {
 2641:             $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
 2642:         } else {
 2643:             $attachurl = $$attachments{$id}{'filename'};
 2644:         }
 2645:         $attachurl=~m|/([^/]+)$|;
 2646:         $$message.='<br /><a href="'.$attachurl.'"><tt>'.
 2647:         $1.'</tt></a><br />';
 2648:         &Apache::lonnet::allowuploaded('/adm/feedback',
 2649:                                $attachurl);
 2650:     } elsif (@attached > 1) {
 2651:         $$message.='<ol>';
 2652:         foreach (@attached) {
 2653:             my $id = $_;
 2654:             my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
 2655:             my ($fname)
 2656:               =($attachurl=~m|/([^/]+)$|);
 2657:             $$message .= '<li><a href="'.$attachurl.
 2658:               '"><tt>'.
 2659:               $fname.'</tt></a></li>';
 2660:             &Apache::lonnet::allowuploaded('/adm/feedback',
 2661:                              $attachurl);
 2662:         }
 2663:         $$message .= '</ol>';
 2664:     }
 2665: }
 2666: 
 2667: sub construct_attachmenturl {
 2668:     my ($currnewattach,$keepold,$symb,$idx)=@_;
 2669:     my $oldattachmenturl;
 2670:     my $newattachmenturl;
 2671:     my $startnum = 0;
 2672:     my $currver = 0;
 2673:     if (($ENV{'form.editdisc'}) && ($idx)) {
 2674:         my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
 2675:                        $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 2676:                        $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 2677:         $oldattachmenturl = $contrib{$idx.':attachmenturl'};
 2678:         if ($contrib{$idx.':history'}) {
 2679:             if ($contrib{$idx.':history'} =~ /:/) {
 2680:                 my @oldversions = split/:/,$contrib{$idx.':history'};
 2681:                 $currver = 1 + scalar(@oldversions);
 2682:             } else {
 2683:                 $currver = 2;
 2684:             }
 2685:         } else {
 2686:             $currver = 1;
 2687:         }
 2688:         if ($oldattachmenturl) {
 2689:             if ($oldattachmenturl =~ m/^<attachment id="0">/) {
 2690:                 my %attachments = ();
 2691:                 my $prevver = $currver-1;
 2692:                 &get_post_attachments(\%attachments,$oldattachmenturl);
 2693:                 my $numattach = scalar(keys %attachments);
 2694:                 $startnum += $numattach;
 2695:                 foreach my $num (sort {$a <=> $b} keys %attachments) {
 2696:                     $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
 2697:                     foreach $_ (sort {$a <=> $b} keys %{$attachments{$num}}) {
 2698:                         unless ($_ eq 'filename') {
 2699:                             $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
 2700:                         }
 2701:                     }
 2702:                     if (grep/^$num$/,@{$keepold}) {
 2703:                         $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
 2704:                     }
 2705:                     $newattachmenturl .= '</attachment>';
 2706:                 }
 2707:             } else {
 2708:                 $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
 2709:                 unless (grep/^0$/,@{$keepold}) {
 2710:                     $newattachmenturl .= '<post id="1">n</post>';
 2711:                 }
 2712:                 $newattachmenturl .= '</attachment>';
 2713:                 $startnum ++;
 2714:             }
 2715:         }
 2716:     }
 2717:     for (my $i=0; $i<@{$currnewattach}; $i++) {
 2718:         my $attachnum = $startnum + $i;
 2719:         $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
 2720:     }
 2721:     return $newattachmenturl; 
 2722: }
 2723: 
 2724: sub has_discussion {
 2725:     my $resourcesref = shift;
 2726:     my $navmap = Apache::lonnavmaps::navmap->new();
 2727:     my @allres=$navmap->retrieveResources();
 2728:     foreach my $resource (@allres) {
 2729:         if ($resource->hasDiscussion()) {
 2730:             my $ressymb;
 2731:             if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
 2732:                 $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
 2733:             } else {
 2734:                 $ressymb = $resource->symb();
 2735:             }
 2736:             push @{$resourcesref}, $ressymb;
 2737:         }
 2738:     }
 2739:     return;
 2740: } 
 2741:   
 2742: sub handler {
 2743:   my $r = shift;
 2744:   if ($r->header_only) {
 2745:      &Apache::loncommon::content_type($r,'text/html');
 2746:      $r->send_http_header;
 2747:      return OK;
 2748:   }
 2749: 
 2750: # --------------------------- Get query string for limited number of parameters
 2751: 
 2752:   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2753:          ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','threadedon','threadedoff','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export']);
 2754:   if ($ENV{'form.discsymb'}) {
 2755:       my $symb = $ENV{'form.discsymb'};
 2756:       my $readkey = $symb.'_read';
 2757:       my %readinghash = ();
 2758:       my $chgcount = 0;
 2759:       %readinghash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$readkey],$ENV{'user.domain'},$ENV{'user.name'});
 2760:       foreach my $key (keys %ENV) {
 2761:           if ($key =~ m/^form\.postunread_(\d+)/) {
 2762:               if ($readinghash{$readkey} =~ /\.$1\./) {
 2763:                   $readinghash{$readkey} =~ s/\.$1\.//;
 2764:                   $chgcount ++;
 2765:               }
 2766:           } elsif ($key =~ m/^form\.postread_(\d+)/) {
 2767:               unless ($readinghash{$readkey} =~ /\.$1\./) {
 2768:                   $readinghash{$readkey} .= '.'.$1.'.';
 2769:                   $chgcount ++;
 2770:               }
 2771:           }
 2772:       }
 2773:       if ($chgcount > 0) {
 2774:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'});
 2775:       }
 2776:       &Apache::loncommon::content_type($r,'text/html');
 2777:       $r->send_http_header;
 2778:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 2779:       my $previous=$ENV{'form.previous'};
 2780:       my $feedurl = &Apache::lonnet::clutter($url);
 2781:       &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />','0','0','',$previous,'','','',);
 2782:       return OK;
 2783:   }
 2784:   if ($ENV{'form.allversions'}) {
 2785:       &Apache::loncommon::content_type($r,'text/html');
 2786:       $r->send_http_header;
 2787:       my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions',
 2788:                                           '','');
 2789:       $r->print (<<END);
 2790: <html>
 2791: <head>
 2792: <title>Post Versions</title>
 2793: <meta http-equiv="pragma" content="no-cache" />
 2794: </head>
 2795: $bodytag
 2796: END
 2797:       my $crs='/'.$ENV{'request.course.id'};
 2798:       if ($ENV{'request.course.sec'}) {
 2799:           $crs.='_'.$ENV{'request.course.sec'};
 2800:       }
 2801:       $crs=~s/\_/\//g;
 2802:       my $seeid=&Apache::lonnet::allowed('rin',$crs);
 2803:       my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.allversions'});
 2804:       my $ressymb=$symb;
 2805:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 2806:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 2807:       }
 2808:       if ($idx > 0) {
 2809:           my %messages = ();
 2810:           my %subjects = ();
 2811:           my %attachmsgs = ();
 2812:           my %allattachments = ();
 2813:           my %imsfiles = ();
 2814:           my ($screenname,$plainname);
 2815:           my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
 2816:                $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 2817:                $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 2818:           my $discussion = &get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname);
 2819:           $r->print($discussion);
 2820:       }
 2821:       return OK;
 2822:   }
 2823:   if ($ENV{'form.posterlist'}) {
 2824:       &Apache::loncommon::content_type($r,'text/html');
 2825:       $r->send_http_header;
 2826:       my $symb=$ENV{'form.posterlist'};
 2827:       my $sortposts = $ENV{'form.sortposts'};
 2828:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 2829:       my $previous=$ENV{'form.previous'};
 2830:       my $feedurl = &Apache::lonnet::clutter($url);
 2831:  # backward compatibility (bulletin boards used to be 'wrapped')
 2832:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 2833:           $feedurl=~s|^/adm/wrapper||;
 2834:       }
 2835:       &print_showposters($r,$symb,$previous,$feedurl,$sortposts);
 2836:       return OK;
 2837:   }
 2838:   if ($ENV{'form.userpick'}) {
 2839:       &Apache::loncommon::content_type($r,'text/html');
 2840:       $r->send_http_header;
 2841:       my $symb=$ENV{'form.userpick'};
 2842:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 2843:       my $previous=$ENV{'form.previous'};
 2844: # backward compatibility (bulletin boards used to be 'wrapped')
 2845:       my $ressymb=$symb;
 2846:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 2847:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 2848:       }
 2849:       my $sort=$ENV{'form.sortposts'};
 2850:       my @posters = ();
 2851:       if (ref($ENV{'form.stuinfo'}) eq 'ARRAY') {
 2852:           @posters = $ENV{'form.stuinfo'};
 2853:       } else {
 2854:           $posters[0] = $ENV{'form.stuinfo'};
 2855:       }
 2856:       my $numpicks = @posters;
 2857:       if (defined($ENV{'form.userpick'})) {
 2858:           my %discinfo = ();
 2859:           $discinfo{$ressymb.'_userpick'} = join('&',@posters);
 2860:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 2861:       }
 2862:       my $feedurl = &Apache::lonnet::clutter($url);
 2863:  # backward compatibility (bulletin boards used to be 'wrapped')
 2864:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 2865:           $feedurl=~s|^/adm/wrapper||;
 2866:       }
 2867:       &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,'','','',$numpicks);
 2868:       return OK;
 2869:   }
 2870:   if ($ENV{'form.applysort'}) {
 2871:       &Apache::loncommon::content_type($r,'text/html');
 2872:       $r->send_http_header;
 2873:       my $symb=$ENV{'form.applysort'};
 2874:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 2875:       my $previous=$ENV{'form.previous'};
 2876:       my $sort = $ENV{'form.sortposts'};
 2877:       my $rolefilter = $ENV{'form.rolefilter'};
 2878:       my $statusfilter = $ENV{'form.statusfilter'};
 2879:       my $secpick = $ENV{'form.sectionpick'};
 2880:       my $feedurl = &Apache::lonnet::clutter($url);
 2881:  # backward compatibility (bulletin boards used to be 'wrapped')
 2882:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 2883:           $feedurl=~s|^/adm/wrapper||;
 2884:       }
 2885:       &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,$rolefilter,$statusfilter,$secpick);
 2886:       return OK;
 2887:   } elsif ($ENV{'form.sortfilter'}) {
 2888:       &Apache::loncommon::content_type($r,'text/html');
 2889:       $r->send_http_header;
 2890:       my $symb=$ENV{'form.sortfilter'};
 2891:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 2892:       my $previous=$ENV{'form.previous'};
 2893:       my $feedurl = &Apache::lonnet::clutter($url);
 2894:  # backward compatibility (bulletin boards used to be 'wrapped')
 2895:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 2896:           $feedurl=~s|^/adm/wrapper||;
 2897:       }
 2898:       &print_sortfilter_options($r,$symb,$previous,$feedurl);
 2899:       return OK;
 2900:   } elsif ($ENV{'form.navtime'}) {
 2901:       my %discinfo = ();
 2902:       my @resources = ();
 2903:       if (defined($ENV{'form.navmaps'})) {
 2904:           if ($ENV{'form.navmaps'} =~ /:/) {
 2905:               @resources = split/:/,$ENV{'form.navmaps'};
 2906:           } else {
 2907:               @resources = ("$ENV{'form.navmaps'}");
 2908:           }
 2909:       } else {
 2910:           &has_discussion(\@resources);
 2911:       }
 2912:       my $numitems = @resources;
 2913:       my $feedurl = '/adm/navmaps';
 2914:       if ($ENV{'form.navurl'}) {
 2915:           $feedurl .= '?'.$ENV{'form.navurl'};
 2916:       }
 2917:       my %lt = &Apache::lonlocal::texthash(
 2918:           'mnpa' => 'Marked "New" posts as read in a total of',
 2919:           'robb' => 'resources/bulletin boards.',
 2920:           'twnp' => 'There are currently no resources or bulletin boards with unread discussion postings.'
 2921:       );       
 2922:       foreach (@resources) {
 2923: # backward compatibility (bulletin boards used to be 'wrapped')
 2924:           my $ressymb=$_;
 2925:           if ($ressymb =~ m/bulletin___\d+___/) {
 2926:               unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 2927:                   $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
 2928:               }
 2929:           }
 2930:           my $lastkey = $ressymb.'_lastread';
 2931:           $discinfo{$lastkey} = $ENV{'form.navtime'};
 2932:       }
 2933:       my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
 2934:       if ($numitems > 0) {
 2935:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 2936:       } else {
 2937:           $textline = "<b>$lt{'twnp'}</b>";
 2938:       }
 2939:       &Apache::loncommon::content_type($r,'text/html');
 2940:       $r->send_http_header;
 2941:       $r->print (<<ENDREDIR);
 2942: <html>
 2943: <head>
 2944: <title>New posts marked as read</title>
 2945: <meta http-equiv="pragma" content="no-cache" />
 2946: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
 2947: </head>
 2948: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
 2949: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
 2950: $textline
 2951: <form name="reldt" action="$feedurl" target="loncapaclient">
 2952: </form>
 2953: <br /><a href="$feedurl">Continue</a>
 2954: </body>
 2955: </html>
 2956: ENDREDIR
 2957:       return OK;
 2958:   } elsif ($ENV{'form.modifydisp'}) {
 2959:       &Apache::loncommon::content_type($r,'text/html');
 2960:       $r->send_http_header;
 2961:       my $symb=$ENV{'form.modifydisp'};
 2962:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 2963:       my $previous=$ENV{'form.previous'};
 2964:       my ($dispchgA,$dispchgB,$markchg,$toggchg) = split/_/,$ENV{'form.changes'};
 2965:       my $feedurl = &Apache::lonnet::clutter($url);
 2966:  # backward compatibility (bulletin boards used to be 'wrapped')  
 2967:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 2968:           $feedurl=~s|^/adm/wrapper||;
 2969:       }
 2970:       &print_display_options($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl);
 2971:       return OK;
 2972:   } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || $ENV{'form.onlyunmark'} || $ENV{'form.toggoff'} || $ENV{'form.toggon'} ) {
 2973:       &Apache::loncommon::content_type($r,'text/html');
 2974:       $r->send_http_header;
 2975:       my $previous=$ENV{'form.previous'};
 2976:       my ($map,$ind,$url);
 2977:       if ( ($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
 2978: # ------------------------------ Modify setting for read/unread toggle for each post 
 2979:           my $symb=$ENV{'form.toggoff'}?$ENV{'form.toggoff'}:$ENV{'form.toggon'};
 2980:           my $ressymb = $symb;
 2981:           ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 2982:           unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 2983:               $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 2984:           }
 2985:           my %discinfo = ();
 2986:           my $toggkey = $ressymb.'_readtoggle';
 2987:           if ($ENV{'form.toggon'}) {
 2988:               $discinfo{$toggkey} = 1;
 2989:           } elsif ($ENV{'form.toggoff'}) {
 2990:               $discinfo{$toggkey} = 0;
 2991:           }
 2992:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 2993:       }
 2994:       if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
 2995: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
 2996:           my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
 2997:           my $ressymb = $symb;
 2998:           ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 2999:           unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 3000:               $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 3001:           }
 3002:           my %discinfo = ();
 3003:           my $lastkey = $ressymb.'_lastread';
 3004:           my $ondispkey = $ressymb.'_markondisp';
 3005:           if ($ENV{'form.markondisp'}) {
 3006:               $discinfo{$lastkey} = time;
 3007:               $discinfo{$ondispkey} = 1;
 3008:           } elsif ($ENV{'form.markonread'}) {
 3009:               if ( $previous > 0 ) {
 3010:                   $discinfo{$lastkey} = $previous;
 3011:               }
 3012:               $discinfo{$ondispkey} = 0;
 3013:           }
 3014:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 3015:       }
 3016:       if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ) {
 3017: # ----------------------------------------------------------------- Modify display setting for this discussion 
 3018:           my $symb;
 3019:           if ($ENV{'form.allposts'}) {
 3020:               $symb = $ENV{'form.allposts'};
 3021:           } elsif ($ENV{'form.onlyunread'}) {
 3022:               $symb = $ENV{'form.onlyunread'};
 3023:           } else {
 3024:               $symb = $ENV{'form.onlyunmark'};
 3025:           }
 3026:           my $ressymb = $symb;
 3027:           ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 3028:           unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 3029:               $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 3030:           }
 3031:           my %discinfo = ();
 3032:           if ($ENV{'form.allposts'}) {
 3033:               $discinfo{$ressymb.'_showonlyunread'} = 0;
 3034:               $discinfo{$ressymb.'_showonlyunmark'} = 0;
 3035:           } elsif ($ENV{'form.onlyunread'}) {
 3036:               $discinfo{$ressymb.'_showonlyunread'} = 1;
 3037:           } else {
 3038:               $discinfo{$ressymb.'_showonlyunmark'} = 1;
 3039:           }
 3040:           &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 3041:       }
 3042:       if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ||($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
 3043:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
 3044:       } else {
 3045:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
 3046:       }
 3047:       return OK;
 3048:   } elsif ($ENV{'form.markread'}) {
 3049: # ----------------------------------------------------------------- Mark new posts not NEW 
 3050:       &Apache::loncommon::content_type($r,'text/html');
 3051:       $r->send_http_header;
 3052:       my $symb=$ENV{'form.markread'};
 3053:       my $ressymb = $symb;
 3054:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 3055:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
 3056:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
 3057:       }
 3058:       my %discinfo = ();
 3059:       my $lastkey = $ressymb.'_lastread';
 3060:       $discinfo{$lastkey} = time;
 3061:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
 3062:       &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
 3063:       return OK;
 3064:   } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
 3065: # ----------------------------------------------------------------- Hide/unhide
 3066:     &Apache::loncommon::content_type($r,'text/html');
 3067:     $r->send_http_header;
 3068: 
 3069:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
 3070: 
 3071:     my ($symb,$idx)=split(/\:\:\:/,$entry);
 3072:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 3073: 
 3074:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
 3075:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 3076: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 3077: 
 3078:         
 3079:     my $currenthidden=$contrib{'hidden'};
 3080:     my $currentstudenthidden=$contrib{'studenthidden'};
 3081: 
 3082:     my $crs='/'.$ENV{'request.course.id'};
 3083:     if ($ENV{'request.course.sec'}) {
 3084:         $crs.='_'.$ENV{'request.course.sec'};
 3085:     }
 3086:     $crs=~s/\_/\//g;
 3087:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
 3088:     
 3089:     if ($ENV{'form.hide'}) {
 3090: 	$currenthidden.='.'.$idx.'.';
 3091:         unless ($seeid) {
 3092:             $currentstudenthidden.='.'.$idx.'.';
 3093:         }
 3094:     } else {
 3095:         $currenthidden=~s/\.$idx\.//g;
 3096:     }
 3097:     my %newhash=('hidden' => $currenthidden);
 3098:     if ( ($ENV{'form.hide'}) && (!$seeid) ) {
 3099:         $newhash{'studenthidden'} = $currentstudenthidden;
 3100:     }
 3101: 
 3102:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
 3103:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 3104: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 3105: 
 3106:     &redirect_back($r,&Apache::lonnet::clutter($url),
 3107:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
 3108:   } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
 3109:       &Apache::loncommon::content_type($r,'text/html');
 3110:       $r->send_http_header;
 3111:       if ($ENV{'form.threadedon'}) {
 3112: 	  &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
 3113: 	  &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
 3114:       } else {
 3115:  	  &Apache::lonnet::del('environment',['threadeddiscussion']);
 3116: 	  &Apache::lonnet::delenv('environment\.threadeddiscussion');
 3117:       }
 3118:       my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
 3119:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 3120:       &redirect_back($r,&Apache::lonnet::clutter($url),
 3121: 		     &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
 3122:   } elsif ($ENV{'form.deldisc'}) {
 3123: # --------------------------------------------------------------- Hide for good
 3124:     &Apache::loncommon::content_type($r,'text/html');
 3125:     $r->send_http_header;
 3126: 
 3127:     my $entry=$ENV{'form.deldisc'};
 3128: 
 3129:     my ($symb,$idx)=split(/\:\:\:/,$entry);
 3130:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 3131: 
 3132:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
 3133:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 3134: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 3135: 
 3136:         
 3137:     my $currentdeleted=$contrib{'deleted'};
 3138:     
 3139:     $currentdeleted.='.'.$idx.'.';
 3140: 
 3141:     my %newhash=('deleted' => $currentdeleted);
 3142: 
 3143:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
 3144:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 3145: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 3146: 
 3147:     &redirect_back($r,&Apache::lonnet::clutter($url),
 3148:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
 3149:   } elsif ($ENV{'form.preview'}) {
 3150: # -------------------------------------------------------- User wants a preview
 3151:       $r->content_type('text/html');
 3152:       $r->send_http_header;
 3153:       &show_preview($r);
 3154:   } elsif ($ENV{'form.attach'}) {
 3155: # -------------------------------------------------------- Work on attachments
 3156:       &Apache::loncommon::content_type($r,'text/html');
 3157:       $r->send_http_header;
 3158:       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
 3159:       my @currnewattach = ();
 3160:       my @currdelold = ();
 3161:       my @keepold = ();
 3162:       &process_attachments(\@currnewattach,\@currdelold,\@keepold);
 3163:       if (exists($ENV{'form.addnewattach.filename'})) {
 3164:           unless (length($ENV{'form.addnewattach'})>131072) {
 3165:               my $subdir = 'feedback/'.$ENV{'form.timestamp'};
 3166:               my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
 3167:               push @currnewattach, $newattachment;
 3168:           }
 3169:       }
 3170:       my $attachmenturls = '';
 3171:       my $idx = $ENV{'form.idx'};
 3172:       my $symb = $ENV{'form.attach'};
 3173:       if ($idx) {
 3174:           my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
 3175:                          $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 3176:                          $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 3177:           $attachmenturls = $contrib{$idx.':attachmenturl'};
 3178:       }
 3179:       &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,$attachmenturls);
 3180:   } elsif ($ENV{'form.chgreads'}) {
 3181:       &Apache::loncommon::content_type($r,'text/html');
 3182:       $r->send_http_header;
 3183:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ENV{'form.chgreads'});
 3184:       &redirect_back($r,&Apache::lonnet::clutter($url),
 3185:        &mt('Changed read status').'<br />','0','0');
 3186:   } elsif ($ENV{'form.export'}) {
 3187:       &Apache::loncommon::content_type($r,'text/html');
 3188:       $r->send_http_header;
 3189:       my $symb=$ENV{'form.export'};
 3190:       my $mode;
 3191:       my $status='OPEN';
 3192:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
 3193:       my $previous=$ENV{'form.previous'};
 3194:       my $feedurl = &Apache::lonnet::clutter($url);
 3195:  # backward compatibility (bulletin boards used to be 'wrapped')
 3196:       if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 3197:           $mode = 'board';
 3198:           $feedurl=~s|^/adm/wrapper||;
 3199:       }
 3200:       if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library)$/) {
 3201:           $mode='problem';
 3202:           $status=$Apache::inputtags::status[-1];
 3203:       }
 3204:       my $discussion = &list_discussion($mode,$status,$symb); 
 3205:       my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion');
 3206:       $r->print($bodytag.$discussion);                                     
 3207:       return OK;
 3208:   } else {
 3209: # ------------------------------------------------------------- Normal feedback
 3210:   my $feedurl=$ENV{'form.postdata'};
 3211:   $feedurl=~s/^http\:\/\///;
 3212:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
 3213:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
 3214:   $feedurl=~s/\?.+$//;
 3215: 
 3216:   my $symb;
 3217:   if ($ENV{'form.replydisc'}) {
 3218:       $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
 3219:       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
 3220:       $feedurl=&Apache::lonnet::clutter($url);
 3221:   } elsif ($ENV{'form.editdisc'}) {
 3222:       $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
 3223:       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
 3224:       $feedurl=&Apache::lonnet::clutter($url);
 3225:   } elsif ($ENV{'form.origpage'}) {
 3226:       $symb=""; 
 3227:   } else {
 3228:       $symb=&Apache::lonnet::symbread($feedurl);
 3229:   }
 3230:   unless ($symb) {
 3231:       $symb=$ENV{'form.symb'};
 3232:       if ($symb) {
 3233: 	  my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
 3234:           $feedurl=&Apache::lonnet::clutter($url);
 3235:       }
 3236:   }
 3237:   my $goahead=1;
 3238:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
 3239:       unless ($symb) { $goahead=0; }
 3240:   }
 3241:   # backward compatibility (bulletin boards used to be 'wrapped')
 3242:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
 3243:       $feedurl=~s|^/adm/wrapper||;
 3244:   }
 3245:   if ($goahead) {
 3246: # Go ahead with feedback, no ambiguous reference
 3247:     &Apache::loncommon::content_type($r,'text/html');
 3248:     $r->send_http_header;
 3249:   
 3250:     if (
 3251:       (
 3252:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
 3253:       ) 
 3254:       || 
 3255:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
 3256:       ||
 3257:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
 3258:      ) {
 3259: # --------------------------------------------------- Print login screen header
 3260:     unless ($ENV{'form.sendit'}) {
 3261:       my $options=&screen_header($feedurl);
 3262:       if ($options) {
 3263:         &mail_screen($r,$feedurl,$options);
 3264:       } else {
 3265: 	&fail_redirect($r,$feedurl);
 3266:       }
 3267:     } else {
 3268:       
 3269: # Get previous user input
 3270:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
 3271:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
 3272:             $ENV{'request.course.id'});
 3273: 
 3274: # Get output from resource
 3275:       my $usersaw=&resource_output($feedurl);
 3276: 
 3277: # Get resource answer (need to allow student to view grades for this to work)
 3278:       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
 3279:       my $useranswer=&Apache::loncommon::get_student_answers(
 3280:                        $symb,$ENV{'user.name'},$ENV{'user.domain'},
 3281: 		       $ENV{'request.course.id'});
 3282:       &Apache::lonnet::delenv('allowed.vgr');
 3283: # Get attachments, if any, and not too large
 3284:       my $attachmenturl='';
 3285:       if (($ENV{'form.origpage'}) || ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'})) {
 3286:           my ($symb,$idx);
 3287:           if ($ENV{'form.replydisc'}) {
 3288:               ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
 3289:           } elsif ($ENV{'form.editdisc'}) {
 3290:               ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
 3291:           } elsif ($ENV{'form.origpage'}) {
 3292:               $symb = $ENV{'form.symb'};
 3293:           }
 3294:           my @currnewattach = ();
 3295:           my @deloldattach = ();
 3296:           my @keepold = ();
 3297:           &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
 3298:           $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
 3299:           $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
 3300:       } elsif ($ENV{'form.attachment.filename'}) {
 3301: 	  unless (length($ENV{'form.attachment'})>131072) {
 3302: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
 3303: 	  }
 3304:       }
 3305: # Filter HTML out of message (could be nasty)
 3306:       my $message=&clear_out_html($ENV{'form.comment'});
 3307: 
 3308: # Assemble email
 3309:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
 3310:           $usersaw,$useranswer);
 3311:  
 3312: # Who gets this?
 3313:       my ($typestyle,%to) = &decide_receiver($feedurl);
 3314: 
 3315: # Actually send mail
 3316:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
 3317:           $attachmenturl,%to);
 3318: 
 3319: # Discussion? Store that.
 3320: 
 3321:       my $numpost=0;
 3322:       if ($ENV{'form.discuss'}) {
 3323:           my $subject = &clear_out_html($ENV{'form.subject'});
 3324: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
 3325: 	  $numpost++;
 3326:       }
 3327: 
 3328:       if ($ENV{'form.anondiscuss'}) {
 3329:           my $subject = &clear_out_html($ENV{'form.subject'});
 3330: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
 3331: 	  $numpost++;
 3332:       }
 3333: 
 3334: 
 3335: # Receipt screen and redirect back to where came from
 3336:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
 3337: 
 3338:     }
 3339:    } else {
 3340: # Unable to give feedback
 3341:     &no_redirect_back($r,$feedurl);
 3342:    }
 3343:   } else {
 3344: # Ambiguous Problem Resource
 3345:       if ( &Apache::lonnet::mod_perl_version() == 2 ) {
 3346: 	  &Apache::lonnet::cleanenv();
 3347:       }
 3348:       $r->internal_redirect('/adm/ambiguous');
 3349:   }
 3350: }
 3351:   return OK;
 3352: } 
 3353: 
 3354: 1;
 3355: __END__

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