File:  [LON-CAPA] / loncom / interface / lonfeedback.pm
Revision 1.118: download - view: text, annotated - select for diffs
Fri Aug 27 22:12:39 2004 UTC (19 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- bug#3385, non-htmlarea feedback fails on IE

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

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