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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.298   ! raeburn     4: # $Id: lonfeedback.pm,v 1.297 2010/08/07 19:23:50 raeburn Exp $
1.19      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.77      www        28: ###
1.7       albertel   29: 
1.1       www        30: package Apache::lonfeedback;
                     31: 
                     32: use strict;
                     33: use Apache::Constants qw(:common);
1.3       www        34: use Apache::lonmsg();
1.9       albertel   35: use Apache::loncommon();
1.33      www        36: use Apache::lontexconvert();
1.86      www        37: use Apache::lonlocal; # must not have ()
1.157     albertel   38: use Apache::lonnet;
1.86      www        39: use Apache::lonhtmlcommon();
1.128     raeburn    40: use Apache::lonnavmaps;
1.130     albertel   41: use Apache::lonenc();
1.175     www        42: use Apache::lonrss();
1.112     raeburn    43: use HTML::LCParser();
1.283     faziophi   44: #use HTML::Tidy::libXML;
1.106     www        45: use Apache::lonspeller();
1.208     raeburn    46: use Apache::longroup;
1.116     raeburn    47: use Cwd;
1.204     www        48: use LONCAPA;
1.54      www        49: 
1.92      albertel   50: sub discussion_open {
1.122     raeburn    51:     my ($status,$symb)=@_;
1.294     www        52: # Advanced roles can always discuss
1.249     albertel   53:     if ($env{'request.role.adv'}) { return 1; }
1.294     www        54: # Get discussion closing date
                     55:     my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb);
                     56: # If it is defined and in the future, the instructor wants this discussion to be open
                     57:     if (defined($close) && $close ne '' && $close > time) {
                     58:         return 1;
                     59:     }
                     60: # It was not explicitly open, check if the problem is available.
                     61: # If the problem is not available, close the discussion 
1.92      albertel   62:     if (defined($status) &&
                     63: 	!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
1.77      www        64: 	  || $status eq 'OPEN')) {
1.92      albertel   65: 	return 0;
1.75      albertel   66:     }
1.294     www        67: # The problem is available, but check if the instructor explictly closed discussion
1.89      albertel   68:     if (defined($close) && $close ne '' && $close < time) {
1.92      albertel   69: 	return 0;
1.89      albertel   70:     }
1.92      albertel   71:     return 1;
                     72: }
                     73: 
                     74: sub discussion_visible {
                     75:     my ($status)=@_;
                     76:     if (not &discussion_open($status)) {
                     77: 	my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
                     78: 	if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden))  {
1.157     albertel   79: 	    if (!$env{'request.role.adv'}) { return 0; }
1.92      albertel   80: 	}
                     81:     }
                     82:     return 1;
1.90      albertel   83: }
1.84      raeburn    84: 
1.90      albertel   85: sub list_discussion {
1.208     raeburn    86:     my ($mode,$status,$ressymb,$imsextras,$group)=@_;
1.232     raeburn    87:     unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }
                     88:     unless ($ressymb) { return ''; }
                     89:     $ressymb=&wrap_symb($ressymb);
1.157     albertel   90:     my $outputtarget=$env{'form.grade_target'};
                     91:     if (defined($env{'form.export'})) {
                     92: 	if($env{'form.export'}) {
1.116     raeburn    93:             $outputtarget = 'export';
                     94:         }
1.140     raeburn    95:     }
1.147     raeburn    96:     if (defined($imsextras)) {
                     97:         if ($$imsextras{'caller'} eq 'imsexport') {
                     98:             $outputtarget = 'export';
                     99:         }
                    100:     }
1.232     raeburn   101:     if (not &discussion_visible($status)) {
                    102:         if ($mode ne 'board') {
1.233     raeburn   103:             &Apache::lonenc::check_encrypt(\$ressymb); 
1.274     kalberla  104:             return '<br /><div class="LC_feedback_link">'.&send_message_link($ressymb)."</div>";
1.232     raeburn   105:         }
                    106:     }
1.208     raeburn   107:     if ($group ne '' && $mode eq 'board') {
                    108:         if (&check_group_priv($group,'vgb') ne 'ok') {
                    109:             return '';
                    110:         }
                    111:     }
1.219     raeburn   112: 
1.235     raeburn   113:     my ($blocked,$blocktext) = 
                    114:         &Apache::loncommon::blocking_status('boards');
1.223     raeburn   115:     if ($blocked) {
1.275     kalberla  116:         $blocktext = '<br /><div class="LC_feedback_link"><span class="LC_feedback_link">'.$blocktext."</span>";
1.234     raeburn   117:         &Apache::lonenc::check_encrypt(\$ressymb);
1.232     raeburn   118:         if ($mode ne 'board') {
1.275     kalberla  119:             $blocktext.=&send_message_link($ressymb).'</div>';
                    120:         }else{
                    121:             $blocktext.="</div>";
1.232     raeburn   122:         }
1.234     raeburn   123:         return $blocktext; 
1.223     raeburn   124:     }
                    125: 
1.270     www       126:     my @bgcols = ("LC_disc_old_item","LC_disc_new_item");
1.57      www       127:     my $discussiononly=0;
                    128:     if ($mode eq 'board') { $discussiononly=1; }
1.157     albertel  129:     unless ($env{'request.course.id'}) { return ''; }
                    130:     my $crs='/'.$env{'request.course.id'};
                    131:     my $cid=$env{'request.course.id'};
                    132:     if ($env{'request.course.sec'}) {
                    133: 	$crs.='_'.$env{'request.course.sec'};
1.143     raeburn   134:     }
1.55      www       135:     $crs=~s/\_/\//g;
1.133     albertel  136:     my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
                    137:     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
1.168     albertel  138: 		  && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form|task)$/));
1.133     albertel  139:     
1.100     raeburn   140:     my %usernamesort = ();
                    141:     my %namesort =();
                    142:     my %subjectsort = ();
1.133     albertel  143: 
1.80      raeburn   144: # Get discussion display settings for this discussion
                    145:     my $lastkey = $ressymb.'_lastread';
                    146:     my $showkey = $ressymb.'_showonlyunread';
1.111     raeburn   147:     my $markkey = $ressymb.'_showonlyunmark',
1.80      raeburn   148:     my $visitkey = $ressymb.'_visit';
1.84      raeburn   149:     my $ondispkey = $ressymb.'_markondisp';
1.101     raeburn   150:     my $userpickkey = $ressymb.'_userpick';
1.111     raeburn   151:     my $toggkey = $ressymb.'_readtoggle';
                    152:     my $readkey = $ressymb.'_read';
1.139     albertel  153:     $ressymb=$encsymb;
1.169     albertel  154:     my %dischash = &Apache::lonnet::get('nohist_'.$cid.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$env{'user.domain'},$env{'user.name'});
1.84      raeburn   155:     my %discinfo = ();
1.80      raeburn   156:     my $showonlyunread = 0;
1.111     raeburn   157:     my $showunmark = 0; 
1.84      raeburn   158:     my $markondisp = 0;
1.79      raeburn   159:     my $prevread = 0;
1.81      raeburn   160:     my $previous = 0;
1.80      raeburn   161:     my $visit = 0;
                    162:     my $newpostsflag = 0;
1.221     raeburn   163:     my @posters = split(/\&/,$dischash{$userpickkey});
1.80      raeburn   164: 
1.81      raeburn   165: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
1.208     raeburn   166:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts','rolefilter','statusfilter','sectionpick','grouppick','totposters']);
1.157     albertel  167:     my $sortposts = $env{'form.sortposts'};
                    168:     my $statusfilter = $env{'form.statusfilter'};
1.209     albertel  169:     my @sectionpick = split(/,/,$env{'form.sectionpick'});
                    170:     my @grouppick   = split(/,/,$env{'form.grouppick'});
                    171:     my @rolefilter  = split(/,/,$env{'form.rolefilter'});
1.208     raeburn   172: 
1.157     albertel  173:     my $totposters = $env{'form.totposters'};
                    174:     $previous = $env{'form.previous'};
1.80      raeburn   175:     if ($previous > 0) {
                    176:         $prevread = $previous;
                    177:     } elsif (defined($dischash{$lastkey})) {
1.84      raeburn   178:         unless ($dischash{$lastkey} eq '') {
                    179:             $prevread = $dischash{$lastkey};
                    180:         }
1.80      raeburn   181:     }
1.79      raeburn   182: 
1.208     raeburn   183:     my $cdom = $env{'course.'.$cid.'.domain'};
                    184:     my $cnum = $env{'course.'.$cid.'.num'};
1.278     raeburn   185:     my $crstype = &Apache::loncommon::course_type();
1.208     raeburn   186: 
1.108     raeburn   187: # Get information about students and non-students in course for filtering display of posts
1.101     raeburn   188:     my %roleshash = ();
                    189:     my %roleinfo = ();
1.208     raeburn   190:     my ($classgroups,$studentgroups);
1.157     albertel  191:     if ($env{'form.rolefilter'}) {
1.208     raeburn   192:         %roleshash = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
1.221     raeburn   193:         foreach my $rolekey (keys(%roleshash)) {
                    194:             my ($role,$uname,$udom,$sec) = split(/:/,$rolekey);
1.144     raeburn   195:             if ($role =~ /^cr/) {
                    196:                 $role = 'cr';
                    197:             }
1.221     raeburn   198:             my ($end,$start) = split(/:/,$roleshash{$rolekey});
1.101     raeburn   199:             my $now = time;
                    200:             my $status = 'Active';
                    201:             if (($now < $start) || ($end > 0 && $now > $end)) {
                    202:                 $status = 'Expired';
                    203:             }
1.144     raeburn   204:             if ($uname && $udom) { 
1.221     raeburn   205:                 push(@{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status);
1.144     raeburn   206:             }
1.101     raeburn   207:         }
1.208     raeburn   208:         my ($classlist,$keylist) =
                    209:                          &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.101     raeburn   210:         my $sec_index = &Apache::loncoursedata::CL_SECTION();
                    211:         my $status_index = &Apache::loncoursedata::CL_STATUS();
                    212:         while (my ($student,$data) = each %$classlist) {
                    213:             my ($section,$status) = ($data->[$sec_index],
                    214:                                  $data->[$status_index]);
1.221     raeburn   215:             push(@{$roleinfo{$student}}, 'st:'.$section.':'.$status);
1.101     raeburn   216:         }
1.208     raeburn   217: 	($classgroups,$studentgroups) = 
1.214     albertel  218: 	    &Apache::loncoursedata::get_group_memberships($classlist,$keylist,
                    219: 							  $cdom,$cnum);
1.101     raeburn   220:     }
                    221: 
1.84      raeburn   222: # Get discussion display default settings for user
1.157     albertel  223:     if ($env{'environment.discdisplay'} eq 'unread') {
1.83      raeburn   224:         $showonlyunread = 1;
                    225:     }
1.157     albertel  226:     if ($env{'environment.discmarkread'} eq 'ondisp') {
1.84      raeburn   227:         $markondisp = 1;
                    228:     }
                    229: 
                    230: # Override user's default if user specified display setting for this discussion
                    231:     if (defined($dischash{$ondispkey})) {
1.123     raeburn   232:         unless ($dischash{$ondispkey} eq '') {
                    233:             $markondisp = $dischash{$ondispkey};
                    234:         }
1.84      raeburn   235:     }
                    236:     if ($markondisp) {
                    237:         $discinfo{$lastkey} = time;
                    238:     }
1.83      raeburn   239: 
1.80      raeburn   240:     if (defined($dischash{$showkey})) {
1.123     raeburn   241:         unless ($dischash{$showkey} eq '') {
                    242:             $showonlyunread = $dischash{$showkey};
                    243:         }
1.80      raeburn   244:     }
                    245: 
1.111     raeburn   246:     if (defined($dischash{$markkey})) {
1.123     raeburn   247:         unless ($dischash{$markkey} eq '') {
                    248:             $showunmark = $dischash{$markkey};
                    249:         }
1.111     raeburn   250:     }
                    251: 
1.80      raeburn   252:     if (defined($dischash{$visitkey})) {
1.123     raeburn   253:         unless ($dischash{$visitkey} eq '') {
                    254:             $visit = $dischash{$visitkey};
                    255:         }
1.78      raeburn   256:     }
1.80      raeburn   257:     $visit ++;
1.78      raeburn   258: 
1.208     raeburn   259:     my $seeid;
                    260:     if (($group ne '') && ($mode eq 'board') && 
                    261:         ($ressymb =~ m|^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|)) {
                    262:         if (&check_group_priv($group,'dgp') eq 'ok') {
                    263:             $seeid = 1;
                    264:         }
                    265:     } else {
                    266:         $seeid=&Apache::lonnet::allowed('rin',$crs);
                    267:     }
1.68      www       268:     my @discussionitems=();
1.101     raeburn   269:     my %shown = ();
                    270:     my @posteridentity=();
1.116     raeburn   271: 
                    272:     my $current=0;
1.67      www       273:     my $visible=0;
1.68      www       274:     my @depth=();
1.116     raeburn   275:     my @replies = ();
1.68      www       276:     my %alldiscussion=();
1.116     raeburn   277:     my %imsitems=();
                    278:     my %imsfiles=();
1.80      raeburn   279:     my %notshown = ();
1.84      raeburn   280:     my %newitem = ();
1.68      www       281:     my $maxdepth=0;
1.173     www       282:     my %anonhash=();
                    283:     my $anoncnt=0;
1.69      www       284:     my $target='';
1.111     raeburn   285: 
1.79      raeburn   286:     my $now = time;
1.80      raeburn   287:     $discinfo{$visitkey} = $visit;
                    288: 
1.169     albertel  289:     &Apache::lonnet::put('nohist_'.$cid.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'});
1.208     raeburn   290:     &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,$encsymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group);
1.80      raeburn   291: 
1.67      www       292:     my $discussion='';
1.116     raeburn   293:     my $manifestfile;
                    294:     my $manifestok=0;
                    295:     my $tempexport;
                    296:     my $imsresources;
                    297:     my $copyresult;
1.84      raeburn   298: 
                    299:     my $function = &Apache::loncommon::get_users_function();
                    300:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.157     albertel  301:                                                     $env{'user.domain'});
1.84      raeburn   302:     my %lt = &Apache::lonlocal::texthash(
1.97      raeburn   303:         'cuse' => 'Current discussion settings',
1.84      raeburn   304:         'allposts' => 'All posts',
                    305:         'unread' => 'New posts only',
1.111     raeburn   306:         'unmark' => 'Unread only',
1.84      raeburn   307:         'ondisp' => 'Once displayed',
1.111     raeburn   308:         'onmark' => 'Once marked not NEW',
                    309:         'toggoff' => 'Off',
                    310:         'toggon' => 'On',
1.84      raeburn   311:         'disa' => 'Posts to be displayed',
                    312:         'npce' => 'Posts cease to be marked "NEW"',
1.111     raeburn   313:         'epcb' => 'Each post can be toggled read/unread', 
1.97      raeburn   314:         'chgt' => 'Change',
                    315:         'disp' => 'Display',
                    316:         'nolo' => 'Not new',
1.111     raeburn   317:         'togg' => 'Toggle read/unread',
1.220     raeburn   318:         'aner' => 'An error occurred opening the manifest file.',
                    319:         'difo' => 'Discussion for',
                    320:         'aerr' => 'An error occurred opening the export file for posting',
                    321:         'aysu' => 'Are you sure you want to delete this post?',
                    322:         'dpwn' => 'Deleted posts will no longer be visible to you and other students',
                    323:         'bwco' => 'but will continue to be visible to your instructor',
                    324:         'depo' => 'Deleted posts will no longer be visible to you or anyone else.',
1.295     www       325:         'discussions' => 'DISCUSSIONS'
1.84      raeburn   326:     );
                    327: 
                    328:     my $currdisp = $lt{'allposts'};
                    329:     my $currmark = $lt{'onmark'};
1.111     raeburn   330:     my $currtogg = $lt{'toggoff'};
1.84      raeburn   331:     my $dispchange = $lt{'unread'};
                    332:     my $markchange = $lt{'ondisp'};
1.111     raeburn   333:     my $toggchange = $lt{'toggon'};
1.97      raeburn   334:     my $chglink = '/adm/feedback?modifydisp='.$ressymb;
1.111     raeburn   335:     my $displinkA = 'onlyunread';
                    336:     my $displinkB = 'onlyunmark';
1.97      raeburn   337:     my $marklink = 'markondisp';
1.111     raeburn   338:     my $togglink = 'toggon';
1.84      raeburn   339: 
                    340:     if ($markondisp) {
                    341:         $currmark = $lt{'ondisp'};
                    342:         $markchange = $lt{'onmark'};
1.97      raeburn   343:         $marklink = 'markonread';
1.84      raeburn   344:     }
                    345: 
                    346:     if ($showonlyunread) {
                    347:         $currdisp = $lt{'unread'};
                    348:         $dispchange = $lt{'allposts'};
1.111     raeburn   349:         $displinkA = 'allposts';
1.84      raeburn   350:     }
1.111     raeburn   351: 
                    352:     if ($showunmark) {
                    353:         $currdisp = $lt{'unmark'};
                    354:         $dispchange = $lt{'unmark'};
                    355:         $displinkA='allposts';
                    356:         $displinkB='onlyunread';
                    357:         $showonlyunread = 0;
                    358:     }
                    359: 
                    360:     if ($dischash{$toggkey}) {
                    361:         $currtogg = $lt{'toggon'};
                    362:         $toggchange = $lt{'toggoff'};
                    363:         $togglink = 'toggoff';
                    364:     } 
1.97      raeburn   365:    
1.282     wenzelju  366:     $chglink .= '&amp;changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink;
1.84      raeburn   367: 
                    368:     if ($newpostsflag) {
1.282     wenzelju  369:         $chglink .= '&amp;previous='.$prevread;
1.84      raeburn   370:     }
1.211     albertel  371:     $chglink.=&group_args($group);
1.84      raeburn   372: 
1.67      www       373:     if ($visible) {
1.80      raeburn   374: # Print the discusssion
1.116     raeburn   375:         if ($outputtarget eq 'tex') {
1.156     albertel  376:             $discussion.='<tex>{\tiny \vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
1.295     www       377:                          '\textbf{'.$lt{'discussions'}.'}\makebox[2 cm][b]{\hrulefill}\vskip 0 mm'.
1.116     raeburn   378:                          '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
1.156     albertel  379:                          '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}}</tex>';
1.116     raeburn   380:         } elsif ($outputtarget eq 'export') {
                    381: # Create temporary directory if this is an export
                    382:             my $now = time;
1.147     raeburn   383:             if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
                    384:                 $tempexport = $$imsextras{'tempexport'};
                    385:                 if (!-e $tempexport) {
                    386:                     mkdir($tempexport,0700);
                    387:                 }
                    388:                 $tempexport .= '/'.$$imsextras{'count'};
                    389:                 if (!-e $tempexport) {
                    390:                     mkdir($tempexport,0700);
                    391:                 }
                    392:             } else {
                    393:                 $tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
                    394:                 if (!-e $tempexport) {
                    395:                     mkdir($tempexport,0700);
                    396:                 }
                    397:                 $tempexport .= '/'.$now;
                    398:                 if (!-e $tempexport) {
                    399:                     mkdir($tempexport,0700);
                    400:                 }
1.157     albertel  401:                 $tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
1.116     raeburn   402:             }
                    403:             if (!-e $tempexport) {
                    404:                 mkdir($tempexport,0700);
                    405:             }
                    406: # open manifest file
                    407:             my $manifest = '/imsmanifest.xml';
                    408:             my $manifestfilename = $tempexport.$manifest;
                    409:             if ($manifestfile = Apache::File->new('>'.$manifestfilename)) {
                    410:                 $manifestok=1;
1.284     raeburn   411:                 print $manifestfile qq|<?xml version="1.0" encoding="UTF-8"?>
1.116     raeburn   412: <manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2" 
                    413: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                    414: identifier="MANIFEST-$ressymb" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 
                    415: imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
                    416:   <organizations default="$ressymb">
                    417:     <organization identifier="$ressymb">
1.220     raeburn   418:       <title>$lt{'difo'} $ressymb</title>\n|;
1.116     raeburn   419:             } else {
1.220     raeburn   420:                 $discussion .= $lt{'aner'}.'<br />';
1.116     raeburn   421:             }
                    422: 	} else {
1.97      raeburn   423:             my $colspan=$maxdepth+1;
1.282     wenzelju  424:             $discussion.= &Apache::lonhtmlcommon::scripttag(qq|
1.219     raeburn   425:    function verifydelete (caller,symb,idx,newflag,previous,groupparm) {
1.102     raeburn   426:        var symbparm = symb+':::'+idx
                    427:        var prevparm = ""
                    428:        if (newflag == 1) {
1.282     wenzelju  429:            prevparm = "&amp;previous="+previous
1.102     raeburn   430:        }
1.219     raeburn   431:        if (caller == 'studentdelete') {
1.220     raeburn   432:            if (confirm("$lt{'aysu'}\\n$lt{'dpwn'},\\n$lt{'bwco'}")) {
1.219     raeburn   433:                document.location.href = "/adm/feedback?hide="+symbparm+prevparm+groupparm
                    434:            }
                    435:        } else {
                    436:            if (caller == 'seeiddelete') {
1.220     raeburn   437:                if (confirm("$lt{'aysu'}\\n$lt{'depo'}")) {
1.219     raeburn   438:                    document.location.href = "/adm/feedback?deldisc="+symbparm+prevparm+groupparm
                    439:                }
                    440:            }
                    441:        }
1.102     raeburn   442:    }
1.282     wenzelju  443:             |);
1.270     www       444: 	    $discussion.='<form name="readchoices" method="post" action="/adm/feedback?chgreads='.$ressymb.'" >'.
                    445:                          "\n".'<table class="LC_discussion">';
1.222     raeburn   446:             $discussion .= &action_links_bar($colspan,$ressymb,$visible,
                    447:                                              $newpostsflag,$group,
                    448:                                              $prevread,$markondisp);
                    449:             my $escsymb=&escape($ressymb);
1.220     raeburn   450:             my $numhidden = keys(%notshown);
1.116     raeburn   451:             if ($numhidden > 0) {
                    452:                 my $colspan = $maxdepth+1;
                    453:                 $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
1.173     www       454:                          '<a href="/adm/feedback?allposts=1&amp;symb='.$escsymb;
1.116     raeburn   455:                 if ($newpostsflag) {
1.282     wenzelju  456:                     $discussion .= '&amp;previous='.$prevread;
1.116     raeburn   457:                 }
1.211     albertel  458: 		$discussion .= &group_args($group);
1.116     raeburn   459:                 $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
1.111     raeburn   460:                          $numhidden.' ';
1.116     raeburn   461:                 if ($showunmark) {
                    462:                     $discussion .= &mt('posts previously marked read');
                    463:                 } else {
                    464:                     $discussion .= &mt('previously viewed posts');
                    465:                 }
                    466:                 $discussion .= '<br/></td></tr>';
1.111     raeburn   467:             }
1.80      raeburn   468:         }
1.100     raeburn   469: 
                    470: # Choose sort mechanism
                    471:         my @showposts = ();
                    472:         if ($sortposts eq 'descdate') {
1.221     raeburn   473:             @showposts = (sort { $b <=> $a } keys(%alldiscussion));
1.100     raeburn   474:         } elsif ($sortposts eq 'thread') {
1.221     raeburn   475:             @showposts = (sort { $a <=> $b } keys(%alldiscussion));
1.100     raeburn   476:         } elsif ($sortposts eq 'subject') {
1.221     raeburn   477:             foreach my $key (sort(keys(%subjectsort))) {
                    478:                 push(@showposts, @{$subjectsort{$key}});
1.100     raeburn   479:             }
                    480:         } elsif ($sortposts eq 'username') {
1.221     raeburn   481:             foreach my $domain (sort(keys(%usernamesort))) {
                    482:                 foreach my $key (sort(keys(%{$usernamesort{$domain}}))) {
                    483:                     push(@showposts, @{$usernamesort{$domain}{$key}});
1.100     raeburn   484:                 }
                    485:             }
                    486:         } elsif ($sortposts eq 'lastfirst') {
1.221     raeburn   487:             foreach my $last (sort(keys(%namesort))) {
                    488:                  foreach my $key (sort(keys(%{$namesort{$last}}))) {
                    489:                      push(@showposts, @{$namesort{$last}{$key}});
1.100     raeburn   490:                  }
                    491:             }
                    492:         } else {
1.221     raeburn   493:             @showposts =  (sort { $a <=> $b } keys(%alldiscussion));
1.100     raeburn   494:         }
1.116     raeburn   495:         my $currdepth = 0;
                    496:         my $firstidx = $alldiscussion{$showposts[0]};
1.221     raeburn   497:         foreach my $post (@showposts) {
1.157     albertel  498:             unless (($sortposts eq 'thread') || (($sortposts eq '') && ($env{'environment.threadeddiscussion'})) || ($outputtarget eq 'export')) {
1.221     raeburn   499:                 $alldiscussion{$post} = $post;
1.100     raeburn   500:             }
1.221     raeburn   501:             unless ( ($notshown{$alldiscussion{$post}} eq '1') || ($shown{$alldiscussion{$post}} == 0) ) {
1.117     albertel  502:                 if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
1.95      sakharuk  503: 		    $discussion.="\n<tr>";
                    504: 		}
1.221     raeburn   505: 	        my $thisdepth=$depth[$alldiscussion{$post}];
1.117     albertel  506:                 if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
1.95      sakharuk  507: 		    for (1..$thisdepth) {
                    508: 			$discussion.='<td>&nbsp;&nbsp;&nbsp;</td>';
                    509: 		    }
                    510: 		}
1.80      raeburn   511: 	        my $colspan=$maxdepth-$thisdepth+1;
1.116     raeburn   512:                 if ($outputtarget eq 'tex') {
1.95      sakharuk  513: 		    #cleanup block
1.221     raeburn   514: 		    $discussionitems[$alldiscussion{$post}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
                    515: 		    $discussionitems[$alldiscussion{$post}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
1.95      sakharuk  516:                     my $threadinsert='';
                    517:                     if ($thisdepth > 0) {
                    518: 			$threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
                    519: 		    }
1.221     raeburn   520: 		    $discussionitems[$alldiscussion{$post}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
                    521:                     $discussionitems[$alldiscussion{$post}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
1.114     sakharuk  522: 
1.221     raeburn   523: 		    $discussionitems[$alldiscussion{$post}]='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}</tex>'.$discussionitems[$alldiscussion{$post}];
                    524: 		    $discussion.=$discussionitems[$alldiscussion{$post}];
1.116     raeburn   525: 		} elsif ($outputtarget eq 'export') {
1.221     raeburn   526:                     my $postfilename = $alldiscussion{$post}.'-'.$imsitems{$alldiscussion{$post}}{'timestamp'}.'.html';
1.116     raeburn   527:                     if ($manifestok) {
1.221     raeburn   528:                         if (($depth[$alldiscussion{$post}] <= $currdepth) && ($alldiscussion{$post} != $firstidx)) {
1.116     raeburn   529:                             print $manifestfile '  </item>'."\n";
                    530:                         }
1.221     raeburn   531:                         $currdepth = $depth[$alldiscussion{$post}];
1.116     raeburn   532:                         print $manifestfile "\n". 
1.221     raeburn   533:       '<item identifier="ITEM-'.$ressymb.'-'.$alldiscussion{$post}.'" isvisible="'.
                    534:         $imsitems{$alldiscussion{$post}}{'isvisible'}.'" identifieref="RES-'.$ressymb.'-'.$alldiscussion{$post}.'">'.
1.284     raeburn   535:         '<title>'.$imsitems{$alldiscussion{$post}}{'title'}.'</title></item>';
1.116     raeburn   536:                         $imsresources .= "\n".
1.221     raeburn   537:     '<resource identifier="RES-'.$ressymb.'-'.$alldiscussion{$post}.'" type="webcontent" href="'.$postfilename.'">'."\n".
1.146     raeburn   538:       '<file href="'.$postfilename.'">'."\n".
1.284     raeburn   539:       $imsfiles{$alldiscussion{$post}}{$imsitems{$alldiscussion{$post}}{'currversion'}}.'</file>'."\n".
1.116     raeburn   540:     '</resource>';
                    541:                     }
                    542:                     my $postingfile;
                    543:                     my $postingfilename = $tempexport.'/'.$postfilename;
                    544:                     if ($postingfile = Apache::File->new('>'.$postingfilename)) {
                    545:                         print $postingfile '<html><head><title>Discussion Post</title></head><body>'.
1.221     raeburn   546:                                            $imsitems{$alldiscussion{$post}}{'title'}.' '.
                    547:                                            $imsitems{$alldiscussion{$post}}{'sender'}.
                    548:                                            $imsitems{$alldiscussion{$post}}{'timestamp'}.'<br /><br />'.
                    549:                                            $imsitems{$alldiscussion{$post}}{'message'}.'<br />'.
                    550:                                            $imsitems{$alldiscussion{$post}}{'attach'}.'</body></html>'."\n"; 
1.116     raeburn   551:                         close($postingfile);
                    552:                     } else {
1.221     raeburn   553:                         $discussion .= $lt{'aerr'}.' '.$alldiscussion{$post}.'<br />';
1.116     raeburn   554:                     }
1.221     raeburn   555:                     $copyresult.=&replicate_attachments($imsitems{$alldiscussion{$post}}{'allattachments'},$tempexport);
1.116     raeburn   556:                 } else {
1.270     www       557:                     $discussion.='<td class="'.$bgcols[$newitem{$alldiscussion{$post}}].
1.221     raeburn   558:                        '" colspan="'.$colspan.'">'. $discussionitems[$alldiscussion{$post}].
1.116     raeburn   559:                        '</td></tr>';
                    560:                 }
1.69      www       561: 	    }
1.80      raeburn   562:         }
1.116     raeburn   563: 	unless ($outputtarget eq 'tex' || $outputtarget eq 'export') {
1.97      raeburn   564:             my $colspan=$maxdepth+1;
1.111     raeburn   565:             $discussion .= <<END;
1.97      raeburn   566:             <tr bgcolor="#FFFFFF">
1.270     www       567:              <td colspan="$colspan" class="LC_disc_action_links_bar">
                    568:               <table class="LC_disc_action_table">
1.97      raeburn   569:                <tr>
                    570:                 <td align="left">
                    571:                  <table border="0" cellpadding="0" cellspacing="4">
                    572:                   <tr>
                    573:                    <td>
1.281     bisitz    574:                     <font size="-1"><b>$lt{'cuse'}</b>:</font></td>
1.97      raeburn   575:                    <td>&nbsp;</td>
1.111     raeburn   576:                    <td><font size="-1">
1.97      raeburn   577: END
                    578:             if ($newpostsflag) {
                    579:                 $discussion .= 
1.111     raeburn   580:                    '1.&nbsp;'.$lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i>&nbsp;&nbsp;2.&nbsp;'.$lt{'nolo'}.'&nbsp;-&nbsp;<i>'.$currmark.'</i>';
                    581:                 if ($dischash{$toggkey}) {
                    582:                    $discussion .= '&nbsp;&nbsp;3.&nbsp;'.$lt{'togg'}.'&nbsp;-&nbsp;<i>'.$currtogg.'</i>';
                    583:                 }
1.97      raeburn   584:             } else {
1.111     raeburn   585:                 if ($dischash{$toggkey}) {
                    586:                    $discussion .= '1.&nbsp;'.$lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i>&nbsp;2.&nbsp;'.$lt{'togg'}.'&nbsp;-&nbsp;<i>'.$currtogg.'</i>';
                    587:                 } else {
                    588:                     $discussion .=
                    589:                          $lt{'disp'}.'&nbsp;-&nbsp;<i>'.$currdisp.'</i>';
                    590:                 }
1.97      raeburn   591:             }
                    592:             $discussion .= <<END;
1.111     raeburn   593:                    </font></td>
1.97      raeburn   594:                    <td>&nbsp;</td>
1.144     raeburn   595:                    <td align="left">
1.281     bisitz    596:                     <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</b></font>
1.111     raeburn   597:                    </td>
1.97      raeburn   598:                   </tr>
                    599:                  </table>
                    600:                 </td>
1.111     raeburn   601: END
1.143     raeburn   602:             if ($sortposts) {
                    603:                 my %sort_types = ();
                    604:                 my %role_types = ();
                    605:                 my %status_types = ();
1.278     raeburn   606:                 &sort_filter_names(\%sort_types,\%role_types,\%status_types,$crstype);
1.143     raeburn   607: 
                    608:                 $discussion .= '<td><font size="-1"><b>'.&mt('Sorted by').'</b>: '.$sort_types{$sortposts}.'<br />';
1.157     albertel  609:                 if (defined($env{'form.totposters'})) {
1.144     raeburn   610:                     $discussion .= &mt('Posts by').':';
1.143     raeburn   611:                     if ($totposters > 0) {
                    612:                         foreach my $poster (@posters) {
1.144     raeburn   613:                             $discussion .= ' '.$poster.',';
1.143     raeburn   614:                         }
1.144     raeburn   615:                         $discussion =~ s/,$//;
1.143     raeburn   616:                     } else {
                    617:                         $discussion .= &mt('None selected');
                    618:                     }
                    619:                 } else {
                    620:                     my $filterchoice ='';
                    621:                     if (@sectionpick > 0) {
1.157     albertel  622:                         $filterchoice = '<i>'.&mt('sections').'</i>-&nbsp;'.$env{'form.sectionpick'};
1.143     raeburn   623:                         $filterchoice .= '&nbsp;&nbsp;&nbsp; ';
                    624:                     }
1.208     raeburn   625:                     if (@grouppick > 0) {
                    626:                         $filterchoice = '<i>'.&mt('groups').'</i>-&nbsp;'.$env{'form.grouppick'};
                    627:                         $filterchoice .= '&nbsp;&nbsp;&nbsp; ';
                    628:                     }
1.143     raeburn   629:                     if (@rolefilter > 0) {
1.144     raeburn   630:                         $filterchoice .= '<i>'.&mt('roles').'</i>-';
1.221     raeburn   631:                         foreach my $role (@rolefilter) {
                    632:                             $filterchoice .= '&nbsp;'.$role_types{$role}.',';
1.143     raeburn   633:                         }
1.144     raeburn   634:                         $filterchoice =~ s/,$//;
1.259     raeburn   635:                         $filterchoice .= '<br />'.('&nbsp;' x8);
1.143     raeburn   636:                     }
                    637:                     if ($statusfilter) {
                    638:                         $filterchoice .= '<i>'.&mt('status').'</i>-&nbsp;'.$status_types{$statusfilter};
                    639:                     }
                    640:                     if ($filterchoice) {
                    641:                         $discussion .= '<b>'.&mt('Filters').'</b>:&nbsp;'.$filterchoice;
                    642:                     }
                    643:                     $discussion .= '</font></td>';
                    644:                 }
                    645:             }
1.111     raeburn   646:             if ($dischash{$toggkey}) {
1.247     albertel  647:                 my $storebutton = &mt('Save read/unread changes');
1.111     raeburn   648:                 $discussion.='<td align="right">'.
1.269     bisitz    649:               '<input type="hidden" name="discsymb" value="'.$ressymb.'" />'."\n".
1.111     raeburn   650:               '<input type="button" name="readoptions" value="'.$storebutton.'"'.
1.282     wenzelju  651:               ' onclick="this.form.submit();" />'."\n".
1.111     raeburn   652:               '</td>';
                    653:             }
                    654:             $discussion .= (<<END);
1.97      raeburn   655:                </tr>
                    656:               </table>
                    657:              </td>
                    658:             </tr>
1.222     raeburn   659: END
                    660:             $discussion .= &action_links_bar($colspan,$ressymb,$visible,
                    661:                                              $newpostsflag,$group,
                    662:                                              $prevread,$markondisp);
                    663:             $discussion .= "
1.97      raeburn   664:            </table>
1.222     raeburn   665:            <br /><br /></form>\n";
1.114     sakharuk  666:         } 
1.116     raeburn   667:         if ($outputtarget eq 'export') {
                    668:             if ($manifestok) {
                    669:                 while ($currdepth > 0) {
                    670:                     print $manifestfile "    </item>\n";
                    671:                     $currdepth --;
                    672:                 }
                    673:                 print $manifestfile qq|
                    674:     </organization>
                    675:   </organizations>
                    676:   <resources>
                    677:     $imsresources
                    678:   </resources>
                    679: </manifest>
                    680:                 |;
                    681:                 close($manifestfile);
1.147     raeburn   682:                 if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
                    683:                     $discussion = $copyresult;
                    684:                 } else {
1.116     raeburn   685: 
                    686: #Create zip file in prtspool
                    687: 
1.147     raeburn   688:                     my $imszipfile = '/prtspool/'.
1.157     albertel  689:                     $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.147     raeburn   690:                          time.'_'.rand(1000000000).'.zip';
                    691:                     my $cwd = &getcwd(); 
                    692:                     my $imszip = '/home/httpd/'.$imszipfile;
                    693:                     chdir $tempexport;
                    694:                     open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
                    695:                     close(OUTPUT);
                    696:                     chdir $cwd;
1.220     raeburn   697:                     $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive','<a href="'.$imszipfile.'">').'</a><br />';
1.147     raeburn   698:                     if ($copyresult) {
1.220     raeburn   699:                         $discussion .= &mt('The following errors occurred during export').' - <br />'.$copyresult;
1.147     raeburn   700:                     }
1.116     raeburn   701:                 }
                    702:             } else {
1.220     raeburn   703:                 $discussion .= '<br />'.&mt('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 />';
1.116     raeburn   704:             }
                    705:             return $discussion;
                    706:         }
1.54      www       707:     }
                    708:     if ($discussiononly) {
1.108     raeburn   709:         my $now = time;
                    710:         my $attachnum = 0;
1.213     raeburn   711:         my $currnewattach = [];
                    712:         my $currdelold = [];
1.108     raeburn   713:         my $comment = '';
                    714:         my $subject = '';
1.157     albertel  715:         if ($env{'form.origpage'}) {
1.108     raeburn   716:             &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']);
1.204     www       717:             $subject = &unescape($env{'form.subject'});
                    718:             $comment = &unescape($env{'form.comment'});
1.108     raeburn   719:             my @keepold = ();
1.208     raeburn   720:             &process_attachments($currnewattach,$currdelold,\@keepold);
                    721:             if (@{$currnewattach} > 0) {
                    722:                 $attachnum += @{$currnewattach};
1.108     raeburn   723:             }
                    724:         }
1.122     raeburn   725: 	if (&discussion_open($status)) {
1.208     raeburn   726:             if (($group ne '') && ($mode eq 'board')) {  
                    727:                 if (&check_group_priv($group,'pgd') eq 'ok') {
                    728:                     $discussion .=
1.210     albertel  729: 			&postingform_display($mode,$ressymb,$now,$subject,
                    730: 					     $comment,$outputtarget,$attachnum,
                    731: 					     $currnewattach,$currdelold,
1.278     raeburn   732: 					     $group,$crstype);
1.108     raeburn   733:                 }
1.208     raeburn   734:             } else {
                    735: 	        $discussion.= 
1.210     albertel  736: 		    &postingform_display($mode,$ressymb,$now,$subject,
                    737: 					 $comment,$outputtarget,$attachnum,
1.278     raeburn   738: 					 $currnewattach,$currdelold,'',$crstype);
1.208     raeburn   739:             }
1.95      sakharuk  740: 	}
1.140     raeburn   741:     } else {
1.251     albertel  742:         $discussion.='<div class="LC_feedback_link">';
1.140     raeburn   743:         if (&discussion_open($status) &&
                    744:             &Apache::lonnet::allowed('pch',
1.157     albertel  745:     	        $env{'request.course.id'}.
                    746: 	        ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.95      sakharuk  747: 	    if ($outputtarget ne 'tex') {
1.298   ! raeburn   748:                 $discussion.= &send_feedback_link($ressymb,$target);
        !           749:                 if ($env{'request.role.adv'}) {
        !           750:                     my $close = &Apache::lonnet::EXT('resource.0.discussend',$ressymb);
        !           751:                     if (defined($close) && $close ne '' && $close < time) {
        !           752:                         $discussion .= '&nbsp;'.&mt('(Closed for [_1] roles)',
        !           753:                                                     &Apache::lonnet::plaintext('st',$crstype));
        !           754:                     }
        !           755:                 }
1.190     www       756:             }
1.294     www       757: 	} else {
                    758:             if ($outputtarget ne 'tex') {
1.298   ! raeburn   759:                 $discussion.= '<span class="LC_feedback_link">'.&mt('This discussion is closed.').'</span>';
1.294     www       760:             }
                    761:         }
1.232     raeburn   762:         if ($outputtarget ne 'tex') {
                    763: 	    $discussion.= &send_message_link($ressymb);
                    764:         }
1.252     bisitz    765:         $discussion.='</div>';
1.74      www       766:     }
1.114     sakharuk  767:     return $discussion;
1.54      www       768: }
1.1       www       769: 
1.232     raeburn   770: sub send_feedback_link {
                    771:     my ($ressymb,$target) = @_;
                    772:     my $output = '<span class="LC_feedback_link">'.
                    773:                  ' <a href="/adm/feedback?replydisc='.
                    774:                  &escape($ressymb).':::" '.$target.'>'.
1.274     kalberla  775:                  '<img alt="" class="LC_noBorder" src="'.
1.232     raeburn   776:                  &Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').
1.274     kalberla  777:                  '" border="0" /><span class="LC_menubuttons_inline_text">'.&mt('Post Discussion').'</span></a></span>';
1.232     raeburn   778:     return $output;
                    779: }
                    780: 
                    781: sub send_message_link {
                    782:     my ($ressymb) = @_;
1.251     albertel  783:     my $output = '<span class="LC_message_link">'.
1.232     raeburn   784:                  '  <a href="/adm/feedback?sendmessageonly=1&amp;symb='.
1.274     kalberla  785:                  &escape($ressymb).'"><img alt="" class="LC_noBorder" src="'.
1.292     wenzelju  786:                  &Apache::loncommon::lonhttpdurl('/res/adm/pages/feedback.png').
1.274     kalberla  787:                  '" border="0" /><span class="LC_menubuttons_inline_text">'.&mt('Send Feedback').'</span></a></span>';
1.232     raeburn   788:     return $output;
                    789: }
                    790: 
1.222     raeburn   791: sub action_links_bar {
                    792:     my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_;
1.270     www       793:     my $discussion = '<tr><td class="LC_disc_action_links_bar" colspan="'.$colspan.'">'.
1.277     raeburn   794:                      '<table width="100%" class="LC_disc_action_table"><tr>'.
                    795:                      '<td class="LC_disc_action_left">';
1.222     raeburn   796:     my $escsymb=&escape($ressymb);
                    797:     if ($visible>2) {
1.277     raeburn   798:         $discussion .= '<a href="/adm/feedback?cmd=threadedon&amp;symb='.$escsymb;
1.222     raeburn   799:         if ($newpostsflag) {
1.282     wenzelju  800:             $discussion .= '&amp;previous='.$prevread;
1.222     raeburn   801:         }
                    802:         $discussion .= &group_args($group);
                    803:         $discussion .='">'.&mt('Threaded View').'</a>&nbsp;&nbsp;'.
                    804:                       '<a href="/adm/feedback?cmd=threadedoff&amp;symb='.$escsymb;
                    805:         if ($newpostsflag) {
1.282     wenzelju  806:             $discussion .= '&amp;previous='.$prevread;
1.222     raeburn   807:         }
                    808:         $discussion .= &group_args($group);
                    809:         $discussion .='">'.&mt('Chronological View').'</a>&nbsp;&nbsp;
1.271     bisitz    810:                        <a href="/adm/feedback?cmd=sortfilter&amp;symb='.$escsymb;
1.222     raeburn   811:         if ($newpostsflag) {
1.282     wenzelju  812:             $discussion .= '&amp;previous='.$prevread;
1.222     raeburn   813:         }
                    814:         $discussion .= &group_args($group);
1.259     raeburn   815:         $discussion .='">'.&mt('Sorting/Filtering options').'</a>'.('&nbsp;' x2);
1.222     raeburn   816:     }
1.271     bisitz    817:     $discussion .='<a href="/adm/feedback?export='.$escsymb;
1.222     raeburn   818:     if ($newpostsflag) {
1.282     wenzelju  819:         $discussion .= '&amp;previous='.$prevread;
1.222     raeburn   820:     }
                    821:     $discussion .= &group_args($group);
                    822:     $discussion .= '">'.&mt('Export').'?</a>&nbsp;&nbsp;</td>';
                    823:     if ($newpostsflag) {
                    824:         if (!$markondisp) {
1.270     www       825:             $discussion .='<td class="LC_disc_action_right"><a href="/adm/preferences?action=changediscussions';
1.222     raeburn   826:             $discussion .= &group_args($group);
                    827:             $discussion .= '">'.
                    828:                            &mt('Preferences on what is marked as NEW').
                    829:                            '</a><br /><a href="/adm/feedback?markread=1&amp;symb='.$escsymb;
                    830:             $discussion .= &group_args($group);
1.281     bisitz    831:             $discussion .= '">'.&mt('Mark NEW posts no longer new').'</a></td>';
1.222     raeburn   832:         } else {
                    833:             $discussion .= '<td>&nbsp;</td>';
                    834:         }
                    835:     } else {
                    836:         $discussion .= '<td>&nbsp;</td>';
                    837:     }
                    838:     $discussion .= '</tr></table></td></tr>';
                    839:     return $discussion;
                    840: }
                    841: 
1.208     raeburn   842: sub postingform_display {
                    843:     my ($mode,$ressymb,$now,$subject,$comment,$outputtarget,$attachnum,
1.278     raeburn   844:         $currnewattach,$currdelold,$group,$crstype) = @_;
1.295     www       845:     if ($outputtarget eq 'tex') { return ''; }
1.208     raeburn   846:     my $newattachmsg;
1.220     raeburn   847:     my %lt = &Apache::lonlocal::texthash(
                    848:               'note' => 'Note: in anonymous discussion, your name is visible only to course faculty',
                    849:              'title' => 'Title',
                    850:              'podi' => 'Post Discussion',
                    851:              'poan' => 'Post Anonymous Discussion',
                    852:              'newa' => 'New attachments',
                    853:     );
1.278     raeburn   854:     if ($crstype eq 'Community') {
                    855:         $lt{'note'} = &mt('Note: in anonymous discussion, your name is visible only to community facilitators');
                    856:     }
1.297     raeburn   857:     my ($postingform,$textareaclass);
                    858:     if (&Apache::lonhtmlcommon::htmlareabrowser()) {
                    859:         $postingform = &Apache::lonhtmlcommon::htmlareaselectactive();
                    860:         $textareaclass = 'class="LC_richDefaultOff"';
                    861:     }
                    862:     $postingform .= (<<ENDDISCUSS);
1.220     raeburn   863: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data"> <input type="submit" name="discuss" value="$lt{'podi'}" />
                    864: <input type="submit" name="anondiscuss" value="$lt{'poan'}" /> <input type="hidden" name="symb" value="$ressymb" />
1.208     raeburn   865: <input type="hidden" name="sendit" value="true" />
                    866: <input type="hidden" name="timestamp" value="$now" />
                    867: <br /><a name="newpost"></a>
1.220     raeburn   868: <font size="1">$lt{'note'}</font><br />
                    869: <b>$lt{'title'}:</b>&nbsp;<input type="text" name="subject" value="$subject" size="30" /><br /><br />
1.297     raeburn   870: <textarea name="comment" cols="80" rows="14" id="comment" $textareaclass>$comment</textarea>
1.208     raeburn   871: ENDDISCUSS
                    872:     if ($env{'form.origpage'}) {
                    873:         $postingform .= '<input type="hidden" name="origpage" value="'.
                    874:                         $env{'form.origpage'}.'" />'."\n";
                    875:         foreach my $att (@{$currnewattach}) {
                    876:             $postingform .= '<input type="hidden" name="currnewattach" '.
                    877:                             'value="'.$att.'" />'."\n";
                    878:         }
                    879:     }
                    880:     if (exists($env{'form.ref'})) {
                    881:         $postingform .= '<input type="hidden" name="ref" value="'.
                    882:                         $env{'form.ref'}.'" />';
                    883:     }
                    884:     if ($group ne '') {
                    885:         $postingform .='<input type="hidden" name="group" value="'.$group.'" />';
                    886:     }
1.235     raeburn   887:     my $blockblog = &Apache::loncommon::blocking_status('blogs');
1.224     raeburn   888:     if (!$blockblog) {
1.278     raeburn   889:         $postingform .= &add_blog_checkbox($crstype);
1.224     raeburn   890:     }
1.208     raeburn   891:     $postingform .= "</form>\n";
1.295     www       892:     $postingform .= &generate_attachments_button('',$attachnum,$ressymb,
1.208     raeburn   893:                                                      $now,$currnewattach,
1.224     raeburn   894:                                                      $currdelold,'',$mode,
                    895:                                                      $blockblog);
1.295     www       896:     if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
                    897:         $newattachmsg = '<br /><b>'.$lt{'newa'}.'</b><br />';
                    898:         if (@{$currnewattach} > 1) {
                    899:              $newattachmsg .= '<ol>';
                    900:              foreach my $item (@{$currnewattach}) {
                    901:                 $item =~ m#.*/([^/]+)$#;
                    902:                 $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
                    903:              }
                    904:              $newattachmsg .= '</ol>'."\n";
                    905:          } else {
                    906:              $$currnewattach[0] =~ m#.*/([^/]+)$#;
                    907:              $newattachmsg .= '<a href="'.$$currnewattach[0].'">'.$1.'</a><br />'."\n";
                    908:          }
1.208     raeburn   909:     }
1.295     www       910:     $postingform .= $newattachmsg;
                    911:     $postingform .= &generate_preview_button();
1.208     raeburn   912:     return $postingform;
                    913: }
                    914: 
1.116     raeburn   915: sub build_posting_display {
1.208     raeburn   916:     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,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_;
1.116     raeburn   917:     my @original=();
                    918:     my @index=();
1.210     albertel  919:     my $skip_group_check = 0;
1.133     albertel  920:     my $symb=&Apache::lonenc::check_decrypt($ressymb);
1.204     www       921:     my $escsymb=&escape($ressymb);
1.157     albertel  922:     my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                    923: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                    924: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
1.116     raeburn   925: 
1.248     albertel  926:     my $see_anonymous = 
                    927: 	&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                    928: 
1.210     albertel  929:     if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) {
                    930:         $skip_group_check = 1;
1.208     raeburn   931:     }
1.116     raeburn   932:     if ($contrib{'version'}) {
                    933:         my $oldest = $contrib{'1:timestamp'};
                    934:         if ($prevread eq '0') {
                    935:             $prevread = $oldest-1;
                    936:         }
1.143     raeburn   937:         my ($skiptest,$rolematch,$roleregexp,$secregexp,$statusregexp);
                    938:         if ($sortposts) {
1.208     raeburn   939:             ($skiptest,$roleregexp,$secregexp,$statusregexp) = 
                    940:                      &filter_regexp($rolefilter,$sectionpick,$statusfilter);
1.143     raeburn   941:             $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;
                    942:         } 
1.116     raeburn   943: 	for (my $id=1;$id<=$contrib{'version'};$id++) {
                    944: 	    my $idx=$id;
                    945:             my $posttime = $contrib{$idx.':timestamp'};
                    946:             if ($prevread <= $posttime) {
                    947:                 $$newpostsflag = 1;
                    948:             }
                    949: 	    my $hidden=($contrib{'hidden'}=~/\.$idx\./);
                    950:             my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
                    951: 	    my $deleted=($contrib{'deleted'}=~/\.$idx\./);
                    952: 	    my $origindex='0.';
                    953:             my $numoldver=0;
                    954: 	    if ($contrib{$idx.':replyto'}) {
1.157     albertel  955:                 if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
1.116     raeburn   956: # this is a follow-up message
                    957: 		    $original[$idx]=$original[$contrib{$idx.':replyto'}];
                    958: 		    $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
                    959: 		    $origindex=$index[$contrib{$idx.':replyto'}];
                    960: 		    if ($$depth[$idx]>$$maxdepth) { $$maxdepth=$$depth[$idx]; }
                    961:                 } else {
                    962:                     $original[$idx]=0;
                    963:                     $$depth[$idx]=0;
                    964:                 }
                    965: 	    } else {
                    966: # this is an original message
                    967: 		$original[$idx]=0;
                    968: 		$$depth[$idx]=0;
                    969: 	    }
                    970: 	    if ($$replies[$$depth[$idx]]) {
                    971: 		$$replies[$$depth[$idx]]++;
                    972: 	    } else {
                    973: 		$$replies[$$depth[$idx]]=1;
                    974: 	    }
                    975: 	    unless ((($hidden) && (!$seeid)) || ($deleted)) {
                    976: 		$$visible++;
                    977:                 if ($contrib{$idx.':history'}) {
                    978:                     if ($contrib{$idx.':history'} =~ /:/) {
1.221     raeburn   979:                         my @oldversions = split(/:/,$contrib{$idx.':history'});
1.116     raeburn   980:                         $numoldver = @oldversions;
                    981:                     } else {
                    982:                         $numoldver = 1;
                    983:                     } 
                    984:                 }
                    985:                 $$current = $numoldver;
                    986: 		my %messages = ();
                    987:                 my %subjects = ();
                    988:                 my %attachtxt = ();
                    989:                 my %allattachments = ();
                    990:                 my ($screenname,$plainname);
                    991:                 my $sender = &mt('Anonymous');
1.173     www       992: # Anonymous users getting number within a discussion
                    993: # Since idx is in static order, this should give the same sequence every time. 
                    994: 		my $key=$contrib{$idx.':sendername'}.'@'.$contrib{$idx.':senderdomain'};
                    995: 		unless ($$anonhash{$key}) {
                    996:                     $anoncnt++;
                    997: 		    $$anonhash{$key}=&mt('Anonymous').' '.$anoncnt;
                    998: 		}
1.116     raeburn   999:                 my ($message,$subject,$vgrlink,$ctlink);
                   1000:                 &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver);
                   1001: 
                   1002: 
                   1003: # Set up for sorting by subject
                   1004:                 unless ($outputtarget eq 'export') {
                   1005:                     $message=$messages{$numoldver};
                   1006:                     $message.=$attachtxt{$numoldver};
                   1007:                     $subject=$subjects{$numoldver};
                   1008:                     if ($message) {
                   1009: 	  	        if ($hidden) {
                   1010: 			    $message='<font color="#888888">'.$message.'</font>';
                   1011:                             if ($studenthidden) {
                   1012:                                 $message .='<br /><br />Deleted by poster (student).';
                   1013:                             }
                   1014: 		        }
                   1015: 
                   1016:                         if ($subject eq '') {
                   1017:                            if (defined($$subjectsort{'__No subject'})) {
1.221     raeburn  1018:                                push(@{$$subjectsort{'__No subject'}}, $idx);
1.116     raeburn  1019:                            } else {
                   1020:                                @{$$subjectsort{'__No subject'}} = ("$idx");
                   1021:                            }
                   1022:                         } else {
                   1023:                             if (defined($$subjectsort{$subject})) {
1.221     raeburn  1024:                                push(@{$$subjectsort{$subject}}, $idx);
1.116     raeburn  1025:                             } else {
                   1026:                                @{$$subjectsort{$subject}} = ("$idx");
                   1027:                             }
                   1028:                         }
1.248     albertel 1029: 		        if (!$contrib{$idx.':anonymous'} || $see_anonymous) {
1.116     raeburn  1030: 			    $sender=&Apache::loncommon::aboutmewrapper(
                   1031: 					 $plainname,
                   1032: 					 $contrib{$idx.':sendername'},
                   1033: 					 $contrib{$idx.':senderdomain'}).' ('.
1.254     bisitz   1034: 					 $contrib{$idx.':sendername'}.':'.
1.116     raeburn  1035: 					 $contrib{$idx.':senderdomain'}.')';
1.287     raeburn  1036:                             $sender = '<b>'.$sender.'</b>';
1.116     raeburn  1037: 			    if ($contrib{$idx.':anonymous'}) {
1.173     www      1038: 			        $sender.=' <font color="red"><b>['.$$anonhash{$key}.']</b></font> '.
1.116     raeburn  1039: 				    $screenname;
                   1040: 			    }
1.248     albertel 1041: 			    if ($see_anonymous) {
                   1042: 				$sender.=&Apache::loncommon::student_image_tag($contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
                   1043: 			    }
1.116     raeburn  1044: # Set up for sorting by domain, then username
                   1045:                             unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {
                   1046:                                 %{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
                   1047:                             }
                   1048:                             if (defined($$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
1.221     raeburn  1049:                                 push(@{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx);
1.116     raeburn  1050:                             } else {
                   1051:                                 @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
                   1052:                             }
                   1053: # Set up for sorting by last name, then first name
                   1054:                             my %names = &Apache::lonnet::get('environment',
                   1055:                                  ['firstname','lastname'],$contrib{$idx.':senderdomain'},
                   1056:                                   ,$contrib{$idx.':sendername'});
                   1057:                             my $lastname = $names{'lastname'};
                   1058:                             my $firstname = $names{'firstname'};
                   1059:                             if ($lastname eq '') {
                   1060:                                 $lastname = '_';
                   1061:                             }
                   1062:                             if ($firstname eq '') {
                   1063:                                 $firstname = '_';
                   1064:                             }
                   1065:                             unless (defined($$namesort{$lastname})) {
                   1066:                                 %{$$namesort{$lastname}} = ();
                   1067:                             }
                   1068:                             if (defined($$namesort{$lastname}{$firstname})) {
1.221     raeburn  1069:                                 push(@{$$namesort{$lastname}{$firstname}}, $idx);
1.116     raeburn  1070:                             } else {
                   1071:                                 @{$$namesort{$lastname}{$firstname}} = ("$idx");
                   1072:                             }
1.296     www      1073:                             if ((&editing_allowed($escsymb.':::'.$idx,$group)) && ($outputtarget ne 'tex')) {
1.157     albertel 1074:                                 if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
1.116     raeburn  1075:                                     $sender.=' <a href="/adm/feedback?editdisc='.
1.173     www      1076:                                          $escsymb.':::'.$idx;
1.179     raeburn  1077:                                     if ($$newpostsflag) {
1.282     wenzelju 1078:                                         $sender .= '&amp;previous='.$prevread;
1.116     raeburn  1079:                                     }
1.211     albertel 1080: 				    $sender .= &group_args($group);
1.208     raeburn  1081:                                     $sender .= '" '.$target.'>'.&mt('Edit').'</a>';
                   1082:                                     
1.116     raeburn  1083:                                     unless ($seeid) {
1.219     raeburn  1084:                                         my $grpargs = &group_args($group);
                   1085:                                         $sender.=" <a href=\"javascript:verifydelete('studentdelete','$escsymb','$idx','$$newpostsflag','$prevread','$grpargs')";
1.116     raeburn  1086:                                         $sender .= '">'.&mt('Delete').'</a>';
                   1087:                                     }
                   1088:                                 }
                   1089:                             } 
1.296     www      1090: 			    if (($seeid) && ($outputtarget ne 'tex')) {
1.116     raeburn  1091: 			        if ($hidden) {
                   1092:                                     unless ($studenthidden) {
                   1093: 			                $sender.=' <a href="/adm/feedback?unhide='.
1.173     www      1094: 				                $escsymb.':::'.$idx;
1.179     raeburn  1095:                                         if ($$newpostsflag) {
1.282     wenzelju 1096:                                             $sender .= '&amp;previous='.$prevread;
1.116     raeburn  1097:                                         }
                   1098:                                         $sender .= '">'.&mt('Make Visible').'</a>';
                   1099:                                     }
                   1100: 			        } else {
                   1101: 				    $sender.=' <a href="/adm/feedback?hide='.
1.173     www      1102: 				        $escsymb.':::'.$idx;
1.179     raeburn  1103:                                     if ($$newpostsflag) {
1.282     wenzelju 1104:                                         $sender .= '&amp;previous='.$prevread;
1.116     raeburn  1105:                                     }
1.211     albertel 1106: 				    $sender .= &group_args($group);
1.116     raeburn  1107:                                     $sender .= '">'.&mt('Hide').'</a>';
1.219     raeburn  1108: 			        }
                   1109:                                 my $grpargs = &group_args($group);
                   1110: 			        $sender.= 
                   1111:                                     " <a href=\"javascript:verifydelete('seeiddelete','$escsymb','$idx','$$newpostsflag','$prevread','$grpargs')\">";
                   1112:                                 $sender .= &mt('Delete').'</a>';
1.116     raeburn  1113:                             }
                   1114: 		        } else {
                   1115: 			    if ($screenname) {
                   1116: 			        $sender='<i>'.$screenname.'</i>';
1.173     www      1117: 			    } else {
                   1118: 				$sender='<i>'.$$anonhash{$key}.'</i>';
1.116     raeburn  1119: 			    }
1.287     raeburn  1120:                             $sender = '<b>'.$sender.'</b>';
1.116     raeburn  1121: # Set up for sorting by domain, then username for anonymous
                   1122:                             unless (defined($$usernamesort{'__anon'})) {
                   1123:                                 %{$$usernamesort{'__anon'}} = ();
                   1124:                             }
                   1125:                             if (defined($$usernamesort{'__anon'}{'__anon'})) {
1.221     raeburn  1126:                                 push(@{$$usernamesort{'__anon'}{'__anon'}}, $idx);
1.116     raeburn  1127:                             } else {
                   1128:                                 @{$$usernamesort{'__anon'}{'__anon'}} = ("$idx");
                   1129:                             }
                   1130: # Set up for sorting by last name, then first name for anonymous
                   1131:                             unless (defined($$namesort{'__anon'})) {
                   1132:                                 %{$$namesort{'__anon'}} = ();
                   1133:                             }
                   1134:                             if (defined($$namesort{'__anon'}{'__anon'})) {
1.221     raeburn  1135:                                 push(@{$$namesort{'__anon'}{'__anon'}}, $idx);
1.116     raeburn  1136:                             } else {
                   1137:                                 @{$$namesort{'__anon'}{'__anon'}} = ("$idx");
                   1138:                             }
                   1139: 		        }
1.296     www      1140: 		        if ((&discussion_open($status)) && ($outputtarget ne 'tex')) {
1.208     raeburn  1141:                             if (($group ne '') && 
                   1142:                                 (&check_group_priv($group,'pgd') eq 'ok')) {
                   1143:                                  $sender.=' <a href="/adm/feedback?replydisc='.
                   1144:                                           $escsymb.':::'.$idx;
                   1145:                                 if ($$newpostsflag) {
1.282     wenzelju 1146:                                     $sender .= '&amp;previous='.$prevread;
1.208     raeburn  1147:                                 }
1.211     albertel 1148:                                 $sender .= &group_args($group);
1.208     raeburn  1149:                                 $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
                   1150:                             } elsif (&Apache::lonnet::allowed('pch', 
                   1151: 				 $env{'request.course.id'}.
                   1152: 				 ($env{'request.course.sec'}?'/'.
                   1153:                                   $env{'request.course.sec'}:''))) {
                   1154: 			         $sender.=' <a href="/adm/feedback?replydisc='.
                   1155: 			                  $escsymb.':::'.$idx;
                   1156:                                 if ($$newpostsflag) {
1.282     wenzelju 1157:                                     $sender .= '&amp;previous='.$prevread;
1.208     raeburn  1158:                                 }
                   1159:                                 $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
1.116     raeburn  1160:                             }
                   1161:                         }
1.296     www      1162: 		        if (($viewgrades) && ($outputtarget ne 'tex')) {
1.290     bisitz   1163: 			        $vgrlink=&Apache::loncommon::submlink(&mt('Submissions'),
1.116     raeburn  1164:                             $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
                   1165: 		        }
1.296     www      1166:                         if (($$dischash{$readkey}=~/\.$idx\./) && ($outputtarget ne 'tex')) { 
1.151     albertel 1167:                             $ctlink = '<label><b>'.&mt('Mark unread').'?</b>&nbsp;<input type="checkbox" name="postunread_'.$idx.'" /></label>';
1.116     raeburn  1168:                         } else {
1.151     albertel 1169:                             $ctlink = '<label><b>'.&mt('Mark read').'?</b>&nbsp;<input type="checkbox" name="postread_'.$idx.'" /></label>';
1.116     raeburn  1170:                         }
                   1171:                     }
                   1172: #figure out at what position this needs to print
                   1173:                 }
                   1174:                 if ($outputtarget eq 'export' || $message) {
                   1175: 		    my $thisindex=$idx;
1.157     albertel 1176: 		    if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
1.116     raeburn  1177: 			$thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
                   1178: 		    }
                   1179: 		    $$alldiscussion{$thisindex}=$idx;
                   1180:                     $$shown{$idx} = 0;
                   1181:                     $index[$idx]=$thisindex;
                   1182:                 }
                   1183:                 if ($outputtarget eq 'export') {
                   1184:                     %{$$imsitems{$idx}} = ();
                   1185:                     $$imsitems{$idx}{'isvisible'}='true';
                   1186:                     if ($hidden) {
                   1187:                         $$imsitems{$idx}{'isvisible'}='false';
                   1188:                     }
                   1189:                     $$imsitems{$idx}{'title'}=$subjects{$numoldver};
                   1190:                     $$imsitems{$idx}{'message'}=$messages{$numoldver};
                   1191:                     $$imsitems{$idx}{'attach'}=$attachtxt{$numoldver};
                   1192:                     $$imsitems{$idx}{'timestamp'}=$contrib{$idx.':timestamp'};
                   1193:                     $$imsitems{$idx}{'sender'}=$plainname.' ('.
1.276     bisitz   1194:                                          $contrib{$idx.':sendername'}.':'.
1.116     raeburn  1195:                                          $contrib{$idx.':senderdomain'}.')';
                   1196:                     $$imsitems{$idx}{'isanonymous'}='false';
                   1197:                     if ($contrib{$idx.':anonymous'}) {
                   1198:                         $$imsitems{$idx}{'isanonymous'}='true';
                   1199:                     }
                   1200:                     $$imsitems{$idx}{'currversion'}=$numoldver;
                   1201:                     %{$$imsitems{$idx}{'allattachments'}}=%allattachments;
                   1202:                     unless ($messages{$numoldver} eq '' && $attachtxt{$numoldver} eq '') {
                   1203:                         $$shown{$idx} = 1;
                   1204:                     }
                   1205:                 } else {
                   1206:                     if ($message) {
                   1207:                         my $spansize = 2;
                   1208:                         if ($showonlyunread && $prevread > $posttime) {
                   1209:                             $$notshown{$idx} = 1;
                   1210:                         } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
                   1211:                             $$notshown{$idx} = 1;
                   1212:                         } else {
                   1213: # apply filters
                   1214:                             my $uname = $contrib{$idx.':sendername'};
                   1215:                             my $udom = $contrib{$idx.':senderdomain'};
                   1216:                             my $poster = $uname.':'.$udom;
1.208     raeburn  1217:                             if ($env{'form.totposters'} ne '') {
1.143     raeburn  1218:                                 if ($totposters == 0) {
                   1219:                                     $$shown{$idx} = 0;
                   1220:                                 } elsif ($totposters > 0) {
                   1221:                                     if (grep/^$poster$/,@{$posters}) {
                   1222:                                         $$shown{$idx} = 1;
1.116     raeburn  1223:                                     }
                   1224:                                 }
1.143     raeburn  1225:                             } elsif ($sortposts) {
1.116     raeburn  1226:                                 if ($skiptest) {
                   1227:                                     $$shown{$idx} = 1;
                   1228:                                 } else {
                   1229:                                     foreach my $role (@{$$roleinfo{$poster}}) {
1.143     raeburn  1230:                                         if ($role =~ /^cc:/) {
                   1231:                                             my $cc_regexp = $roleregexp.':[^:]*:'.$statusregexp;
                   1232:                                             if ($role =~ /$cc_regexp/) {
                   1233:                                                 $$shown{$idx} = 1;
1.144     raeburn  1234:                                                 last;
1.143     raeburn  1235:                                             }
                   1236:                                         } elsif ($role =~ /^$rolematch$/) {
1.116     raeburn  1237:                                             $$shown{$idx} = 1;
                   1238:                                             last;
                   1239:                                         }
                   1240:                                     }
                   1241:                                 }
1.210     albertel 1242:                                 if ($$shown{$idx} && !$skip_group_check) {
1.208     raeburn  1243:                                     my $showflag = 0;
                   1244:                                     if (ref($$classgroups{$poster}{active}) eq 'HASH') {
                   1245:                                         foreach my $grp (@{$grouppick}) {
                   1246:                                             if (grep/^\Q$grp\E$/,
                   1247:                                  keys(%{$$classgroups{$poster}{active}})) {
                   1248:                                                 $showflag = 1;
                   1249:                                                 last;
                   1250:                                             }
                   1251:                                         }
                   1252:                                     }
                   1253:                                     if ($showflag) {
                   1254:                                         $$shown{$idx} = 1;
                   1255:                                     } else {
                   1256:                                         $$shown{$idx} = 0;
                   1257:                                     }
                   1258:                                 }
1.143     raeburn  1259:                             } else {
                   1260:                                 $$shown{$idx} = 1;
1.116     raeburn  1261:                             }
                   1262:                         }
                   1263:                         unless ($$notshown{$idx} == 1) {
                   1264:                             if ($prevread > 0 && $prevread <= $posttime) {
                   1265:                                 $$newitem{$idx} = 1;
                   1266:                                 $$discussionitems[$idx] .= '
1.282     wenzelju 1267:                                   <table border="0" width="100%">
1.295     www      1268:                                   <tr><td align="left"><font color="#FF0000"><b>'.&mt('NEW').'&nbsp;</b></font></td>';
1.116     raeburn  1269:                             } else {
                   1270:                                 $$newitem{$idx} = 0;
                   1271:                                 $$discussionitems[$idx] .= '
1.282     wenzelju 1272:                                   <table border="0" width="100%">
1.116     raeburn  1273:                                   <tr><td align="left">&nbsp;</td>';
                   1274:                             }
1.271     bisitz   1275:                             $$discussionitems[$idx] .= '<td align="left">&nbsp;&nbsp;'.
1.116     raeburn  1276:                                 '<b>'.$subject.'</b>&nbsp;&nbsp;'.
1.288     raeburn  1277:                                 $sender.' '.$vgrlink.' ('.
1.116     raeburn  1278:                                 &Apache::lonlocal::locallocaltime($posttime).')</td>';
                   1279:                             if ($$dischash{$toggkey}) {
                   1280:                                 $$discussionitems[$idx].='<td align="right">&nbsp;&nbsp;'.
                   1281:                                   $ctlink.'</td>';
                   1282:                             }
                   1283:                             $$discussionitems[$idx].= '</tr></table><blockquote>'.
1.282     wenzelju 1284:                                     $message.'</blockquote>';
1.116     raeburn  1285:                             if ($contrib{$idx.':history'}) {
                   1286:                                 my @postversions = ();
                   1287:                                 $$discussionitems[$idx] .= &mt('This post has been edited by the author.');
                   1288:                                 if ($seeid) {
1.208     raeburn  1289:                                     $$discussionitems[$idx] .= '&nbsp;&nbsp;<a href="/adm/feedback?allversions='.$escsymb.':::'.$idx;
1.211     albertel 1290: 				    $$discussionitems[$idx] .= &group_args($group);
1.208     raeburn  1291:                                     $$discussionitems[$idx] .= '">'.&mt('Display all versions').'</a>';
1.116     raeburn  1292:                                 }
                   1293:                                 $$discussionitems[$idx].='<br/>'.&mt('Earlier version(s) were posted on: ');
                   1294:                                 if ($contrib{$idx.':history'} =~ m/:/) {
1.221     raeburn  1295:                                     @postversions = split(/:/,$contrib{$idx.':history'});
1.116     raeburn  1296:                                 } else {
                   1297:                                     @postversions = ("$contrib{$idx.':history'}");
                   1298:                                 }
                   1299:                                 for (my $i=0; $i<@postversions; $i++) {
                   1300:                                     my $version = $i+1;
                   1301:                                     $$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).'  ';
                   1302:                                 }
                   1303:                             }
                   1304:                         }
                   1305:                     }
                   1306:                 }
                   1307:             }
                   1308: 	}
                   1309:     }
                   1310: }
                   1311: 
1.143     raeburn  1312: sub filter_regexp {
                   1313:     my ($rolefilter,$sectionpick,$statusfilter) = @_;
                   1314:     my ($roleregexp,$secregexp,$statusregexp);
                   1315:     my $skiptest = 1;
                   1316:     if (@{$rolefilter} > 0) {
                   1317:         my @okrolefilter = ();
1.221     raeburn  1318:         foreach my $role (@{$rolefilter}) {
                   1319:             unless ($role eq '') {
                   1320:                 push(@okrolefilter, $role);
1.143     raeburn  1321:             }
                   1322:         }
                   1323:         if (@okrolefilter > 0) {
                   1324:             if (grep/^all$/,@okrolefilter) {
                   1325:                 $roleregexp='[^:]+';
                   1326:             } else {
                   1327:                 if (@okrolefilter == 1) {
                   1328:                     $roleregexp=$okrolefilter[0];
                   1329:                 } else {
                   1330:                     $roleregexp='('.join('|',@okrolefilter).')';
                   1331:                 }
                   1332:                 $skiptest = 0;
                   1333:             }
                   1334:         }
                   1335:     }
                   1336:     if (@{$sectionpick} > 0) {
                   1337:         my @oksectionpick = ();
1.221     raeburn  1338:         foreach my $sec (@{$sectionpick}) {
                   1339:             unless ($sec eq '') {
                   1340:                  push(@oksectionpick, $sec);
1.143     raeburn  1341:             }
                   1342:         }
                   1343:         if ((@oksectionpick > 0) && (!grep/^all$/,@oksectionpick)) {
                   1344:             if (@oksectionpick == 1) {
                   1345:                 $secregexp = $oksectionpick[0];
                   1346:             } else {
                   1347:                 $secregexp .= '('.join('|',@oksectionpick).')';
                   1348:             }
                   1349:             $skiptest = 0;
                   1350:         } else {
                   1351:             $secregexp .= '[^:]*';
                   1352:         }
                   1353:     }
1.208     raeburn  1354: 
1.143     raeburn  1355:     if (defined($statusfilter) && $statusfilter ne '') {
                   1356:         if ($statusfilter eq 'all') {
                   1357:             $statusregexp = '[^:]+';
                   1358:         } else {
                   1359:             $statusregexp = $statusfilter;
                   1360:             $skiptest = 0;
                   1361:         }
                   1362:     }
                   1363:     return ($skiptest,$roleregexp,$secregexp,$statusregexp);
                   1364: }
                   1365: 
                   1366: 
1.116     raeburn  1367: sub get_post_contents {
                   1368:     my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_;
                   1369:     my $discussion = '';
                   1370:     my $start=$numver;
                   1371:     my $end=$numver + 1;
                   1372:     %{$$imsfiles{$idx}}=();
                   1373:     if ($type eq 'allversions') {
                   1374:        unless($seeid) {
1.208     raeburn  1375:            $discussion=&mt('You do not have privileges to view all versions of posts.').' '.&mt('Please select a different role.');
1.116     raeburn  1376:            return $discussion;
                   1377:        } 
                   1378:     }
1.126     albertel 1379: #    $$screenname=&Apache::loncommon::screenname(
                   1380: #                                        $$contrib{$idx.':sendername'},
                   1381: #                                        $$contrib{$idx.':senderdomain'});
1.172     www      1382:     $$plainname=&Apache::loncommon::nickname(
                   1383:                                         $$contrib{$idx.':sendername'},
                   1384:                                         $$contrib{$idx.':senderdomain'});
                   1385:     $$screenname=$$contrib{$idx.':screenname'};
                   1386: 
1.116     raeburn  1387:     my $sender=&Apache::loncommon::aboutmewrapper(
                   1388:                                  $$plainname,
                   1389:                                  $$contrib{$idx.':sendername'},
                   1390:                                  $$contrib{$idx.':senderdomain'}).' ('.
1.276     bisitz   1391:                                  $$contrib{$idx.':sendername'}.':'.
1.116     raeburn  1392:                                  $$contrib{$idx.':senderdomain'}.')';
                   1393:     my $attachmenturls = $$contrib{$idx.':attachmenturl'};
                   1394:     my @postversions = ();
                   1395:     if ($type eq 'allversions' || $type eq 'export') {
                   1396:         $start = 0;
                   1397:         if ($$contrib{$idx.':history'}) {
1.174     albertel 1398: 	    @postversions = split(/:/,$$contrib{$idx.':history'});
1.116     raeburn  1399:         }
                   1400:         &get_post_versions($messages,$$contrib{$idx.':message'},1);
                   1401:         &get_post_versions($subjects,$$contrib{$idx.':subject'},1);
1.221     raeburn  1402:         push(@postversions,$$contrib{$idx.':timestamp'});
1.116     raeburn  1403:         $end = @postversions;
                   1404:     } else {
                   1405:         &get_post_versions($messages,$$contrib{$idx.':message'},1,$numver);
                   1406:         &get_post_versions($subjects,$$contrib{$idx.':subject'},1,$numver);
                   1407:     }
                   1408: 
                   1409:     if ($$contrib{$idx.':anonymous'}) {
                   1410:         $sender.=' ['.&mt('anonymous').'] '.$$screenname;
                   1411:     }
                   1412:     if ($type eq 'allversions') {
                   1413:         $discussion=('<b>'.$sender.'</b><br /><ul>');
                   1414:     }
                   1415:     for (my $i=$start; $i<$end; $i++) {
                   1416:         my ($timesent,$attachmsg);
                   1417:         my %currattach = ();
                   1418:         $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
1.286     raeburn  1419:         unless (&contains_block_html($messages->{$i})) {
                   1420:             &newline_to_br(\$messages->{$i});
                   1421:         }
1.116     raeburn  1422:         $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
                   1423:         $$subjects{$i}=~s/\n/\<br \/\>/g;
                   1424:         $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
                   1425:         if ($attachmenturls) {
                   1426:             &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,$allattachments,\%currattach);
                   1427:         }
                   1428:         if ($type eq 'export') {
                   1429:             $$imsfiles{$idx}{$i} = '';
                   1430:             if ($attachmsg) {
1.220     raeburn  1431:                 $$attachtxt{$i} = '<br />'.&mt('Attachments').':<br />';
1.221     raeburn  1432:                 foreach my $key (sort(keys(%currattach))) {
                   1433:                     if ($$allattachments{$key}{'filename'} =~ m-^/uploaded/([^/]+/[^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1.116     raeburn  1434:                         my $fname = $1.$3.'/'.$4;
1.284     raeburn  1435:                         $$imsfiles{$idx}{$i} .= '<file href="'.$fname.'" />'."\n";
1.116     raeburn  1436:                         $$attachtxt{$i}.= '<a href="'.$fname.'">'.$4.'</a><br />';
                   1437:                     }
                   1438:                 }
                   1439:             }
                   1440:         } else {
                   1441:             if ($attachmsg) {
1.220     raeburn  1442:                 $$attachtxt{$i} = '<br />'.&mt('Attachments').':'.$attachmsg.'<br />';
1.116     raeburn  1443:             } else {
                   1444:                 $$attachtxt{$i} = '';
                   1445:             }
                   1446:         }
                   1447:         if ($type eq 'allversions') {
                   1448:             $discussion.= <<"END";
                   1449: <li><b>$$subjects{$i}</b>, $timesent<br />
                   1450: $$messages{$i}<br />
                   1451: $$attachtxt{$i}</li>
                   1452: END
                   1453:         }
                   1454:     }
                   1455:     if ($type eq 'allversions') {
1.187     albertel 1456:         $discussion.='</ul>';
1.116     raeburn  1457:         return $discussion;
                   1458:     } else {
                   1459:         return;
                   1460:     }
                   1461: }
                   1462: 
                   1463: sub replicate_attachments {
                   1464:     my ($attachrefs,$tempexport) = @_;
                   1465:     my $response;
1.221     raeburn  1466:     foreach my $id (keys(%{$attachrefs})) {
1.116     raeburn  1467:         if ($$attachrefs{$id}{'filename'} =~ m-^/uploaded/([^/]+)/([^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
                   1468:             my $path = $tempexport;
                   1469:             my $tail = $1.'/'.$2.$4;
1.221     raeburn  1470:             my @extras = split(/\//,$tail);
1.116     raeburn  1471:             my $destination = $tempexport.'/'.$1.'/'.$2.$4.'/'.$5;
                   1472:             if (!-e $destination) {
                   1473:                 my $i= 0;
                   1474:                 while ($i<@extras) {
                   1475:                     $path .= '/'.$extras[$i];
                   1476:                     if (!-e $path) {
                   1477:                         mkdir($path,0700);
                   1478:                     }
                   1479:                     $i ++;
                   1480:                 }
                   1481:                 my ($content,$rtncode);
                   1482:                 my $uploadreply = &Apache::lonnet::getuploaded('GET',$$attachrefs{$id}{'filename'},$1,$2,$content,$rtncode);
                   1483:                 if ($uploadreply eq 'ok') {
1.125     raeburn  1484:                     my $attachcopy;
                   1485:                     if ($attachcopy = Apache::File->new('>'.$destination)) {
                   1486:                         print $attachcopy $content;
                   1487:                         close($attachcopy);
                   1488:                     } else {
1.220     raeburn  1489:                         $response .= &mt('Error copying file attachment - [_1] to IMS package',$5).': '.$!.'<br />'."\n";
1.125     raeburn  1490:                     }
1.116     raeburn  1491:                 } else {
1.125     raeburn  1492:                     &Apache::lonnet::logthis("Replication of attachment failed when building IMS export of discussion posts - domain: $1, course: $2, file: $$attachrefs{$id}{'filename'} -error: $rtncode");
1.220     raeburn  1493:                     $response .= &mt('Error copying file attachment - [_1] to IMS package: ',$5).$rtncode.'<br />'."\n";
1.116     raeburn  1494:                 }
                   1495:             }
                   1496:         }
                   1497:     }
1.125     raeburn  1498:     return $response;
1.116     raeburn  1499: }
                   1500: 
1.6       albertel 1501: sub mail_screen {
1.255     raeburn  1502:   my ($r,$feedurl,$options,$caller_symb,$attachmaxtext) = @_;
1.157     albertel 1503:   if (exists($env{'form.origpage'})) {
1.208     raeburn  1504:       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss','blog','group','ref']);
1.108     raeburn  1505:   }
1.186     albertel 1506: 
1.220     raeburn  1507:   my %lt = &Apache::lonlocal::texthash(
                   1508:             'myqu' => 'My question/comment/feedback:',
                   1509:             'title' => 'Title',
                   1510:             'reta' => 'Retained attachments',
1.255     raeburn  1511:             'atta' => 'Attachment',
1.237     raeburn  1512:            );
1.239     albertel 1513:   my $restitle = &get_resource_title($caller_symb,$feedurl);
1.69      www      1514:   my $quote='';
1.78      raeburn  1515:   my $subject = '';
1.108     raeburn  1516:   my $comment = '';
1.80      raeburn  1517:   my $prevtag = '';
1.102     raeburn  1518:   my $parentmsg = '';
1.108     raeburn  1519:   my ($symb,$idx,$attachmenturls);
                   1520:   my $numoldver = 0;
                   1521:   my $attachmsg = '';
                   1522:   my $newattachmsg = '';
                   1523:   my @currnewattach = ();
                   1524:   my @currdelold = ();
                   1525:   my @keepold = ();
1.113     raeburn  1526:   my %attachments = ();
1.108     raeburn  1527:   my %currattach = ();
                   1528:   my $attachnum = 0;
                   1529:   my $anonchk = (<<END);
                   1530:   function anonchk() {
1.199     albertel 1531:       for (var i=0; i < document.mailform.discuss.length; i++) {
                   1532: 	  if (document.mailform.discuss[i].checked) {
                   1533: 	      document.attachment.discuss.value = 
                   1534: 		  document.mailform.discuss[i].value;
                   1535: 	  }
1.198     albertel 1536:       }
                   1537:       if (document.mailform.blog.checked) {
                   1538: 	  document.attachment.blog.value = 1;
                   1539:       }
1.108     raeburn  1540:      return
                   1541:    }
                   1542: END
                   1543:   my $anonscript;
1.157     albertel 1544:   if (exists($env{'form.origpage'})) {
1.108     raeburn  1545:       $anonscript = (<<END);
1.102     raeburn  1546:   function setposttype() {
1.198     albertel 1547:       var disc = "$env{'form.discuss'}";
1.199     albertel 1548:       for (var i=0; i < document.mailform.discuss.length; i++) {
                   1549: 	  if (disc == document.mailform.discuss[i].value) {
                   1550: 	      document.mailform.discuss[i].checked = 1;
                   1551: 	  }
1.198     albertel 1552:       }
                   1553:       var blog = "$env{'form.blog'}";
                   1554:       if (blog == 1) {
                   1555:           document.mailform.blog.checked=1;
1.108     raeburn  1556:       }
1.102     raeburn  1557:       return
                   1558:   }
                   1559: END
1.108     raeburn  1560:   } else {
                   1561:       $anonscript = (<<END);
                   1562:   function setposttype() {
                   1563:       return
                   1564:   }
                   1565: END
                   1566:   }
1.157     albertel 1567:   if (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
                   1568:       if ($env{'form.replydisc'}) {
                   1569:           ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
1.102     raeburn  1570:       } else {
1.157     albertel 1571:           ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
1.102     raeburn  1572:       }
1.157     albertel 1573:       my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                   1574: 					   $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1575: 					   $env{'course.'.$env{'request.course.id'}.'.num'});
1.80      raeburn  1576:       unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.112     raeburn  1577:           if ($contrib{$idx.':history'}) {
                   1578:               if ($contrib{$idx.':history'} =~ /:/) {
1.221     raeburn  1579:                   my @oldversions = split(/:/,$contrib{$idx.':history'});
1.112     raeburn  1580:                   $numoldver = @oldversions;
                   1581:               } else {
                   1582:                   $numoldver = 1;
                   1583:               }
                   1584:           }
1.157     albertel 1585:           if ($env{'form.replydisc'}) {
1.102     raeburn  1586:               if ($contrib{$idx.':history'}) {
                   1587:                   if ($contrib{$idx.':history'} =~ /:/) {
1.221     raeburn  1588:                       my @oldversions = split(/:/,$contrib{$idx.':history'});
1.102     raeburn  1589:                       $numoldver = @oldversions;
                   1590:                   } else {
                   1591:                       $numoldver = 1;
                   1592:                   }
                   1593:               }
1.108     raeburn  1594:               if ($idx > 0) {
1.116     raeburn  1595:                   my %msgversions = ();
                   1596:                   &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1.218     albertel 1597:                   $quote = $msgversions{$numoldver};
1.108     raeburn  1598:               }
1.102     raeburn  1599:               if ($idx > 0) {
1.116     raeburn  1600:                   my %subversions = ();
                   1601:                   &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
1.224     raeburn  1602:                   $subject = &mt('Re: ').$subversions{$numoldver};
1.102     raeburn  1603:               }
1.108     raeburn  1604:               $subject = &HTML::Entities::encode($subject,'<>&"');
1.102     raeburn  1605:           } else {
1.108     raeburn  1606:               $attachmenturls = $contrib{$idx.':attachmenturl'};
1.116     raeburn  1607:               if ($idx > 0) {
                   1608:                   my %msgversions = ();
                   1609:                   &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
                   1610:                   $comment = $msgversions{$numoldver};
                   1611:                   my %subversions = ();
                   1612:                   &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
                   1613:                   $subject = $subversions{$numoldver}; 
1.102     raeburn  1614:               }
                   1615:               if (defined($contrib{$idx.':replyto'})) {
                   1616:                   $parentmsg = $contrib{$idx.':replyto'};
                   1617:               }
1.157     albertel 1618:               unless (exists($env{'form.origpage'})) {
1.203     albertel 1619:                   my $anonflag = 'nonanon';
1.108     raeburn  1620:                   if ($contrib{$idx.':anonymous'}) {
1.203     albertel 1621:                       $anonflag = 'anon';
1.108     raeburn  1622:                   }
                   1623:                   $anonscript = (<<END);
1.102     raeburn  1624:   function setposttype () {
1.203     albertel 1625:       var currtype = "$anonflag";
                   1626:       for (var i=0; i<document.mailform.discuss.length; i++) {
                   1627: 	  if (document.mailform.elements.discuss[i].value == currtype ) {
                   1628: 	      document.mailform.elements.discuss[i].checked=1;
                   1629: 	  } 
1.102     raeburn  1630:       }
                   1631:       return
                   1632:   }
                   1633: END
1.108     raeburn  1634:               }
1.79      raeburn  1635:           }
1.69      www      1636:       }
1.157     albertel 1637:       if ($env{'form.previous'}) {
                   1638:           $prevtag = '<input type="hidden" name="previous" value="'.$env{'form.previous'}.'" />';
1.80      raeburn  1639:       }
1.69      www      1640:   }
1.108     raeburn  1641: 
1.157     albertel 1642:   if ($env{'form.origpage'}) {
1.204     www      1643:       $subject = &unescape($env{'form.subject'});
                   1644:       $comment = &unescape($env{'form.comment'});
1.108     raeburn  1645:       &process_attachments(\@currnewattach,\@currdelold,\@keepold);
                   1646:   }
1.261     raeburn  1647:   my $latexHelp=&Apache::loncommon::helpLatexCheatsheet(undef,undef,1);
1.74      www      1648:   my $send=&mt('Send');
1.220     raeburn  1649:   my $alert = &mt('Please select a feedback type.');
1.186     albertel 1650:   my $js= <<END;
1.63      albertel 1651: <script type="text/javascript">
                   1652: //<!--
1.5       www      1653:     function gosubmit() {
                   1654:         var rec=0;
1.12      albertel 1655:         if (typeof(document.mailform.elements.discuss)!="undefined") {
1.203     albertel 1656: 	    if (typeof(document.mailform.elements.discuss.length) == "undefined") {
                   1657: 		if (document.mailform.elements.discuss.checked ) {
1.202     albertel 1658: 		    rec=1;
                   1659: 		}
                   1660: 	    } else {
1.203     albertel 1661: 		for (var i=0; i<document.mailform.elements.discuss.length; i++) {
                   1662: 		    if (document.mailform.elements.discuss[i].checked ) {
1.202     albertel 1663: 			rec=1;
                   1664: 		    } 
                   1665: 		}
                   1666: 	    }
                   1667: 	}
1.175     www      1668:         if (typeof(document.mailform.elements.blog)!="undefined") {
1.203     albertel 1669:           if (document.mailform.elements.blog.checked) {
1.175     www      1670:              rec=1;
                   1671:           } 
                   1672:         }
1.5       www      1673: 
                   1674:         if (rec) {
1.118     albertel 1675:             if (typeof(document.mailform.onsubmit)=='function') {
1.105     www      1676: 		document.mailform.onsubmit();
                   1677: 	    }
1.5       www      1678: 	    document.mailform.submit();
                   1679:         } else {
1.220     raeburn  1680:             alert('$alert');
1.5       www      1681: 	}
                   1682:     }
1.108     raeburn  1683:     $anonchk
1.102     raeburn  1684:     $anonscript
1.63      albertel 1685: //-->
1.5       www      1686: </script>
1.186     albertel 1687: END
                   1688: 
1.297     raeburn  1689:   my ($textareaheader,$textareaclass);
                   1690:   if (&Apache::lonhtmlcommon::htmlareabrowser()) {
                   1691:       $textareaheader = &Apache::lonhtmlcommon::htmlareaselectactive();
                   1692:       $textareaclass = 'class="LC_richDefaultOff"';
                   1693:   }
                   1694: 
1.276     bisitz   1695:   # Breadcrumbs
                   1696:   my $brcrum = [{'href' => '',
                   1697:                  'text' => 'Resource Feedback and Discussion'}];
                   1698: 
1.189     albertel 1699:   my %onload = ('onload' => 'window.focus();setposttype();');
1.186     albertel 1700:   my $start_page=
                   1701:       &Apache::loncommon::start_page('Resource Feedback and Discussion',$js,
1.276     bisitz   1702:                                      {'add_entries' => \%onload,
                   1703:                                       'bread_crumbs' => $brcrum,});
1.186     albertel 1704: 
1.218     albertel 1705:   if ($quote ne '') {
1.286     raeburn  1706:       $quote = &HTML::Entities::decode($quote);
                   1707:       unless (&contains_block_html($quote)) {
                   1708:           &newline_to_br(\$quote);
                   1709:       }
1.218     albertel 1710:       $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($quote).'</blockquote>';
                   1711:   }
                   1712: 
1.186     albertel 1713:   $r->print(<<END);
                   1714: $start_page
1.237     raeburn  1715: <h2><tt>$restitle</tt></h2>
1.43      www      1716: <form action="/adm/feedback" method="post" name="mailform"
                   1717: enctype="multipart/form-data">
1.80      raeburn  1718: $prevtag
1.63      albertel 1719: <input type="hidden" name="postdata" value="$feedurl" />
1.102     raeburn  1720: END
1.157     albertel 1721:   if ($env{'form.replydisc'}) {
1.102     raeburn  1722:       $r->print(<<END);
1.157     albertel 1723: <input type="hidden" name="replydisc" value="$env{'form.replydisc'}" />
1.102     raeburn  1724: END
1.157     albertel 1725:   } elsif ($env{'form.editdisc'}) {
1.102     raeburn  1726:      $r->print(<<END);
1.271     bisitz   1727: <input type="hidden" name="editdisc" value="$env{'form.editdisc'}" />
                   1728: <input type="hidden" name="parentmsg" value="$parentmsg" />
1.102     raeburn  1729: END
                   1730:   }
1.108     raeburn  1731:   $r->print(<<END);
1.63      albertel 1732: $options<hr />
1.69      www      1733: $quote
1.297     raeburn  1734: <p>$lt{'myqu'}
                   1735: $textareaheader
                   1736: </p>
1.63      albertel 1737: <p>
1.47      bowersj2 1738: $latexHelp
1.267     bisitz   1739: </p>
                   1740: <p>
1.220     raeburn  1741: $lt{'title'}: <input type="text" name="subject" size="30" value="$subject" /></p>
1.78      raeburn  1742: <p>
1.297     raeburn  1743: <textarea name="comment" id="comment" cols="60" rows="10" $textareaclass>$comment
1.63      albertel 1744: </textarea></p>
1.108     raeburn  1745: END
1.157     albertel 1746:     if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
                   1747:         if ($env{'form.origpage'}) {
1.221     raeburn  1748:             foreach my $attach (@currnewattach) {
                   1749:                 $r->print('<input type="hidden" name="currnewattach" value="'.$attach.'" />'."\n");
1.108     raeburn  1750:             }
1.221     raeburn  1751:             foreach my $oldatt (@currdelold) {
                   1752:                 $r->print('<input type="hidden" name="deloldattach" value="'.$oldatt.'" />'."\n");
1.108     raeburn  1753:             }
                   1754:         }
1.157     albertel 1755:         if ($env{'form.editdisc'}) {
1.108     raeburn  1756:             if ($attachmenturls) {
1.113     raeburn  1757:                 &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
1.221     raeburn  1758:                 $attachnum = scalar(keys(%currattach));
                   1759:                 foreach my $key (keys(%currattach)) {
                   1760:                     $r->print('<input type="hidden" name="keepold" value="'.$key.'" />'."\n");
1.108     raeburn  1761:                 }
                   1762:             }
                   1763:         }
                   1764:     } else {
                   1765:         $r->print(<<END);
1.285     raeburn  1766: <p>
1.255     raeburn  1767: $lt{'atta'} $attachmaxtext: <input type="file" name="attachment" />
1.42      www      1768: </p>
1.108     raeburn  1769: END
                   1770:     }
1.208     raeburn  1771:     if (exists($env{'form.group'})) {
                   1772:         $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
                   1773:     }
                   1774:     if (exists($env{'form.ref'})) {
                   1775:         $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
                   1776:     }
1.108     raeburn  1777:     $r->print(<<END);
1.42      www      1778: <p>
                   1779: <input type="hidden" name="sendit" value="1" />
1.282     wenzelju 1780: <input type="button" value="$send" onclick='gosubmit();' />
1.42      www      1781: </p>
1.2       www      1782: </form>
1.108     raeburn  1783: END
1.157     albertel 1784:     if ($env{'form.editdisc'} || $env{'form.replydisc'}) {
1.108     raeburn  1785:         my $now = time;
                   1786:         my $ressymb = $symb;
1.233     raeburn  1787:         &Apache::lonenc::check_encrypt(\$ressymb);
1.108     raeburn  1788:         my $postidx = '';
1.157     albertel 1789:         if ($env{'form.editdisc'}) {
1.108     raeburn  1790:             $postidx = $idx;
                   1791:         }
                   1792:         if (@currnewattach > 0) {
                   1793:             $attachnum += @currnewattach;
                   1794:         }
1.235     raeburn  1795:         my $blockblog = &Apache::loncommon::blocking_status('blogs');
1.224     raeburn  1796:         $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver,'',$blockblog));
1.108     raeburn  1797:         if ($attachnum > 0) {
                   1798:             if (@currnewattach > 0) {
1.220     raeburn  1799:                 $newattachmsg .= '<br /><b>'.&mt('New attachments').'</b><br />';
1.108     raeburn  1800:                 if (@currnewattach > 1) {
                   1801:                     $newattachmsg .= '<ol>';
                   1802:                     foreach my $item (@currnewattach) {
                   1803:                         $item =~ m#.*/([^/]+)$#;
                   1804:                         $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
                   1805:                     }
                   1806:                     $newattachmsg .= '</ol>'."\n";
                   1807:                 } else {
                   1808:                     $currnewattach[0] =~ m#.*/([^/]+)$#;
                   1809:                     $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
                   1810:                 }
                   1811:             }
                   1812:             if ($attachmsg) {
1.220     raeburn  1813:                 $r->print("<br /><b>$lt{'reta'}</b>:$attachmsg<br />\n");
1.108     raeburn  1814:             }
                   1815:             if ($newattachmsg) {
                   1816:                 $r->print("$newattachmsg<br />");
                   1817:             }
                   1818:         }
                   1819:     }
                   1820:     $r->print(&generate_preview_button().
1.186     albertel 1821: 	      &Apache::loncommon::end_page());
                   1822: 
1.6       albertel 1823: }
                   1824: 
1.97      raeburn  1825: sub print_display_options {
1.111     raeburn  1826:     my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
1.135     albertel 1827:     &Apache::loncommon::content_type($r,'text/html');
                   1828:     $r->send_http_header;
1.98      raeburn  1829: 
1.97      raeburn  1830:     my $function = &Apache::loncommon::get_users_function();
                   1831:     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1.157     albertel 1832:                                                     $env{'user.domain'});
1.97      raeburn  1833: 
                   1834:     my %lt = &Apache::lonlocal::texthash(
                   1835:         'pref' => 'Display Preference',
                   1836:         'curr' => 'Current setting ',
                   1837:         'actn' => 'Action',
                   1838:         'deff' => 'Default for all discussions',
                   1839:         'prca' => 'Preferences can be set for this discussion that determine ....',
1.264     schafran 1840:         'whpo' => 'Which posts are displayed when you display this discussion board or resource, and',
1.111     raeburn  1841:         'unwh' => 'Under what circumstances posts are identified as "NEW", and',
                   1842:         'wipa' => 'Whether individual posts can be marked as read/unread',
1.97      raeburn  1843:         'allposts' => 'All posts',
                   1844:         'unread' => 'New posts only',
1.111     raeburn  1845:         'unmark' => 'Posts not marked read',
1.97      raeburn  1846:         'ondisp' => 'Once displayed',
1.254     bisitz   1847:         'onmark' => 'Once marked not NEW',
1.111     raeburn  1848:         'toggon' => 'Shown',
                   1849:         'toggoff' => 'Not shown',
1.97      raeburn  1850:         'disa' => 'Posts displayed?',
1.111     raeburn  1851:         'npmr' => 'New posts cease to be identified as "NEW"?',
                   1852:         'dotm' => 'Option to mark each post as read/unread?',  
1.97      raeburn  1853:         'chgt' => 'Change to ',
                   1854:         'mkdf' => 'Set to ',
1.111     raeburn  1855:         'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
1.97      raeburn  1856:         'ywbr' => 'You will be returned to the previous page if you click OK.'
                   1857:     );
                   1858: 
1.111     raeburn  1859:     my $dispchangeA = $lt{'unread'};
                   1860:     my $dispchangeB = $lt{'unmark'};
1.97      raeburn  1861:     my $markchange = $lt{'ondisp'};
1.111     raeburn  1862:     my $toggchange = $lt{'toggon'};
1.97      raeburn  1863:     my $currdisp = $lt{'allposts'};
                   1864:     my $currmark = $lt{'onmark'};
                   1865:     my $discdisp = 'allposts';
                   1866:     my $discmark = 'onmark';
1.111     raeburn  1867:     my $currtogg = $lt{'toggoff'};
                   1868:     my $disctogg = 'toggoff';
1.97      raeburn  1869:                                                                                       
1.111     raeburn  1870:     if ($dispchgA eq 'allposts') {
                   1871:         $dispchangeA = $lt{'allposts'};
1.97      raeburn  1872:         $currdisp = $lt{'unread'};
                   1873:         $discdisp = 'unread';
                   1874:     }
1.111     raeburn  1875: 
1.97      raeburn  1876:     if ($markchg eq 'markonread') {
                   1877:         $markchange = $lt{'onmark'};
                   1878:         $currmark = $lt{'ondisp'};
                   1879:         $discmark = 'ondisp';
                   1880:     }
1.111     raeburn  1881: 
                   1882:     if ($dispchgB eq 'onlyunread') {
                   1883:         $dispchangeB = $lt{'unread'};
                   1884:         $currdisp = $lt{'unmark'};
                   1885:         $discdisp = 'unmark';
                   1886:     }
                   1887:     if ($toggchg eq 'toggoff') {
                   1888:         $toggchange = $lt{'toggoff'};
                   1889:         $currtogg = $lt{'toggon'};
                   1890:         $disctogg = 'toggon';
                   1891:     }
1.187     albertel 1892: 
                   1893:     my $js = <<END;
                   1894: <script type="text/javascript">
1.111     raeburn  1895: function discdispChk(caller) {
                   1896:     var disctogg = '$toggchg'
                   1897:     if (caller == 0) {
                   1898:         if (document.modifydisp.discdisp[0].checked == true) {
                   1899:             if (document.modifydisp.discdisp[1].checked == true) {
                   1900:                 document.modifydisp.discdisp[1].checked = false
                   1901:             }
                   1902:         }
                   1903:     }
                   1904:     if (caller == 1) {
                   1905:         if (document.modifydisp.discdisp[1].checked == true) {
                   1906:             if (document.modifydisp.discdisp[0].checked == true) {
                   1907:                 document.modifydisp.discdisp[0].checked = false
                   1908:             }
                   1909:             if (disctogg == 'toggon') {
                   1910:                 document.modifydisp.disctogg.checked = true
                   1911:             }
                   1912:             if (disctogg == 'toggoff') {
                   1913:                 document.modifydisp.disctogg.checked = false
                   1914:             }
                   1915:         }
                   1916:     }
                   1917:     if (caller == 2) {
                   1918:         var dispchgB = '$dispchgB'
                   1919:         if (disctogg == 'toggoff') {
                   1920:             if (document.modifydisp.disctogg.checked == true) {
                   1921:                 if (dispchgB == 'onlyunmark') {
                   1922:                     document.modifydisp.discdisp[1].checked = false
                   1923:                 }
                   1924:             }
                   1925:         }
                   1926:     }  
                   1927: }
                   1928: 
1.97      raeburn  1929: function setDisp() {
                   1930:     var prev = "$previous"
                   1931:     var chktotal = 0
1.111     raeburn  1932:     if (document.modifydisp.discdisp[0].checked == true) {
                   1933:         document.modifydisp.$dispchgA.value = "$symb"
                   1934:         chktotal ++
                   1935:     }
                   1936:     if (document.modifydisp.discdisp[1].checked == true) {
                   1937:         document.modifydisp.$dispchgB.value = "$symb"
1.97      raeburn  1938:         chktotal ++
                   1939:     }
                   1940:     if (document.modifydisp.discmark.checked == true) {
                   1941:         document.modifydisp.$markchg.value = "$symb"
                   1942:         chktotal ++
                   1943:     }
1.111     raeburn  1944:     if (document.modifydisp.disctogg.checked == true) {
                   1945:         document.modifydisp.$toggchg.value = "$symb"
                   1946:         chktotal ++
                   1947:     }
1.97      raeburn  1948:     if (chktotal > 0) { 
                   1949:         document.modifydisp.submit()
                   1950:     } else {
                   1951:         if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}"))      {
                   1952:             if (prev > 0) {
                   1953:                 location.href = "$feedurl?previous=$previous"
                   1954:             } else {
                   1955:                 location.href = "$feedurl"
                   1956:             }
                   1957:         }
                   1958:     }
                   1959: }
                   1960: </script>
1.187     albertel 1961: END
                   1962: 
                   1963: 
                   1964:     my $start_page =
                   1965: 	&Apache::loncommon::start_page('Discussion display options',$js);
                   1966:     my $end_page =
                   1967: 	&Apache::loncommon::end_page();
                   1968:     $r->print(<<END);
1.192     albertel 1969: $start_page
1.273     bisitz   1970: <form name="modifydisp" method="post" action="/adm/feedback">
1.111     raeburn  1971: $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
1.97      raeburn  1972: <br />
1.195     albertel 1973: END
                   1974:     $r->print(&Apache::loncommon::start_data_table());
                   1975:     $r->print(<<END);
                   1976:        <tr>
                   1977:         <th>$lt{'pref'}</td>
                   1978:         <th>$lt{'curr'}</td>
                   1979:         <th>$lt{'actn'}?</td>
1.97      raeburn  1980:        </tr>
1.195     albertel 1981: END
                   1982:     $r->print(&Apache::loncommon::start_data_table_row());
                   1983:     $r->print(<<END);
1.97      raeburn  1984:        <td>$lt{'disa'}</td>
                   1985:        <td>$lt{$discdisp}</td>
1.282     wenzelju 1986:        <td><label><input type="checkbox" name="discdisp" onclick="discdispChk('0')" />&nbsp;$lt{'chgt'} "$dispchangeA"</label>
1.111     raeburn  1987:            <br />
1.282     wenzelju 1988:            <label><input type="checkbox" name="discdisp" onclick="discdispChk('1')" />&nbsp;$lt{'chgt'} "$dispchangeB"</label>
1.111     raeburn  1989:        </td>
1.195     albertel 1990: END
                   1991:     $r->print(&Apache::loncommon::end_data_table_row());
                   1992:     $r->print(&Apache::loncommon::start_data_table_row());
                   1993:     $r->print(<<END);
1.97      raeburn  1994:        <td>$lt{'npmr'}</td>
                   1995:        <td>$lt{$discmark}</td>
1.151     albertel 1996:        <td><label><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</label></td>
1.195     albertel 1997: END
                   1998:     $r->print(&Apache::loncommon::end_data_table_row());
                   1999:     $r->print(&Apache::loncommon::start_data_table_row());
                   2000:     $r->print(<<END);
1.111     raeburn  2001:        <td>$lt{'dotm'}</td>
                   2002:        <td>$lt{$disctogg}</td>
1.282     wenzelju 2003:        <td><label><input type="checkbox" name="disctogg" onclick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</label></td>
1.195     albertel 2004: END
1.264     schafran 2005:     my $save = &mt('Save');
1.195     albertel 2006:     $r->print(&Apache::loncommon::end_data_table_row());
                   2007:     $r->print(&Apache::loncommon::end_data_table());
                   2008:     $r->print(<<END);
1.97      raeburn  2009: <br />
                   2010: <br />
1.137     albertel 2011: <input type="hidden" name="symb" value="$symb" />
1.97      raeburn  2012: <input type="hidden" name="previous" value="$previous" />
1.269     bisitz   2013: <input type="hidden" name="$dispchgA" value="" />
                   2014: <input type="hidden" name="$dispchgB" value="" />
                   2015: <input type="hidden" name="$markchg" value="" />
1.111     raeburn  2016: <input type="hidden" name="$toggchg" value="" />
1.282     wenzelju 2017: <input type="button" name="sub" value="$save" onclick="javascript:setDisp()" />
1.208     raeburn  2018: END
                   2019:     if (exists($env{'form.group'})) {
                   2020:         $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
                   2021:     }
                   2022:     if (exists($env{'form.ref'})) {
                   2023:         $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
                   2024:     }
                   2025:     $r->print("
1.97      raeburn  2026: <br />
                   2027: <br />
                   2028: </form>
1.187     albertel 2029: $end_page
1.208     raeburn  2030:     ");
1.97      raeburn  2031:     return;
                   2032: }
                   2033: 
1.100     raeburn  2034: sub print_sortfilter_options {
                   2035:     my ($r,$symb,$previous,$feedurl) = @_;
1.133     albertel 2036: 
1.135     albertel 2037:     &Apache::loncommon::content_type($r,'text/html');
                   2038:     $r->send_http_header;
                   2039: 
1.139     albertel 2040:     &Apache::lonenc::check_encrypt(\$symb);
1.197     albertel 2041:     my @sections;
1.100     raeburn  2042:     my $section_sel = '';
                   2043:     my $numvisible = 5;
1.208     raeburn  2044:     my @groups;
                   2045:     my $group_sel = '';
                   2046:     my $numgroupvis = 5;
1.197     albertel 2047:     my %sectioncount = &Apache::loncommon::get_sections();
1.278     raeburn  2048:     my @courseroles = qw(st ad ep ta in);
                   2049:     my $crstype = &Apache::loncommon::course_type();
                   2050:     my $ccrole = 'cc';
                   2051:     if ($crstype eq 'Community') {
                   2052:         $ccrole = 'co';
                   2053:     }
                   2054:     push(@courseroles,$ccrole);
                   2055:     
1.157     albertel 2056:     if ($env{'request.course.sec'} !~ /^\s*$/) {  #Restrict section choice to current section 
                   2057:         @sections = ('all',$env{'request.course.sec'});
1.144     raeburn  2058:         $numvisible = 2;
1.100     raeburn  2059:     } else {
                   2060:         @sections = sort {$a cmp $b} keys(%sectioncount);
1.197     albertel 2061:         if (scalar(@sections) < 4) {
                   2062:             $numvisible = scalar(@sections) + 1;
                   2063:         }
1.100     raeburn  2064:         unshift(@sections,'all'); # Put 'all' at the front of the list
1.197     albertel 2065: 
1.100     raeburn  2066:     }
1.212     albertel 2067:     foreach my $sec (@sections) {
                   2068:         $section_sel .= "  <option value=\"$sec\">$sec</option>\n";
1.100     raeburn  2069:     }
1.208     raeburn  2070: 
                   2071:     if (&check_group_priv() eq 'ok') {
                   2072:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2073:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 
                   2074:         my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   2075:         @groups = sort {$a cmp $b} keys(%curr_groups);
                   2076:         if (scalar(@groups) < 4) {
                   2077:             $numgroupvis = scalar(@groups) + 1;
                   2078:         }
                   2079:         unshift(@groups,'all'); # Put 'all' at the front of the list
                   2080:     } else { 
                   2081:         my @coursegroups = split(/:/,$env{'request.course.groups'});
                   2082:         if (@coursegroups > 0) {
                   2083:             @coursegroups = sort {$a cmp $b} @coursegroups;
                   2084:             @groups = ('all',@coursegroups);
                   2085:             if (scalar(@groups) < 4) {
                   2086:                 $numgroupvis = scalar(@groups) + 1;
                   2087:             }
                   2088:         } else {
                   2089:             @groups = ('all');
                   2090:             $numgroupvis = 1;
                   2091:         }
                   2092:     }
1.212     albertel 2093:     foreach my $group (@groups) {
                   2094:         $group_sel .= "  <option value=\"$group\">$group</option>\n";
1.208     raeburn  2095:     }
                   2096: 
1.100     raeburn  2097:     my $function = &Apache::loncommon::get_users_function();
                   2098:     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1.157     albertel 2099:                                                     $env{'user.domain'});
1.100     raeburn  2100:     my %lt = &Apache::lonlocal::texthash(
                   2101:         'diop' => 'Display Options',
                   2102:         'curr' => 'Current setting ',
                   2103:         'actn' => 'Action',
1.143     raeburn  2104:         'prca' => 'Set options that control the sort order of posts, and/or which posts are displayed.',
1.100     raeburn  2105:         'soor' => 'Sort order',
1.143     raeburn  2106:         'spur' => 'Specific user roles',
                   2107:         'sprs' => 'Specific role status',
1.100     raeburn  2108:         'spse' => 'Specific sections',
1.208     raeburn  2109:         'spgr' => 'Specific groups',
1.100     raeburn  2110:         'psub' => 'Pick specific users (by name)',
1.220     raeburn  2111:         'shal' => 'Show a list of current posters',
1.247     albertel 2112:         'stor' => 'Save changes',
1.100     raeburn  2113:     );
1.143     raeburn  2114: 
                   2115:     my %sort_types = ();
                   2116:     my %role_types = ();
                   2117:     my %status_types = ();
1.278     raeburn  2118:     &sort_filter_names(\%sort_types,\%role_types,\%status_types,$crstype);
1.187     albertel 2119: 
                   2120:     my $js = <<END;
1.144     raeburn  2121: <script type="text/javascript">
                   2122: function verifyFilter() {
                   2123:     var rolenum = 0
                   2124:     for (var i=0; i<document.modifyshown.rolefilter.length; i++) {
                   2125:         if (document.modifyshown.rolefilter.options[i].selected == true) {
                   2126:             rolenum ++
                   2127:         }
                   2128:     }
                   2129:     if (rolenum == 0) {
                   2130:         document.modifyshown.rolefilter.options[0].selected = true
                   2131:     }
                   2132: 
                   2133:     var secnum = 0
                   2134:     for (var i=0; i<document.modifyshown.sectionpick.length; i++) {
                   2135:         if (document.modifyshown.sectionpick.options[i].selected == true) {
                   2136:             secnum ++
                   2137:         }
                   2138:     }
                   2139:     if (secnum == 0) {
                   2140:         document.modifyshown.sectionpick.options[0].selected = true
                   2141:     }
1.208     raeburn  2142: 
                   2143:     var grpnum = 0
                   2144:     for (var i=0; i<document.modifyshown.grouppick.length; i++) {
                   2145:         if (document.modifyshown.grouppick.options[i].selected == true) {
                   2146:             grpnum ++
                   2147:         }
                   2148:     }
                   2149:     if (grpnum == 0) {
                   2150:         document.modifyshown.grouppick.options[0].selected = true
                   2151:     }
                   2152: 
1.144     raeburn  2153:     document.modifyshown.submit();
                   2154: }
                   2155: </script>
1.187     albertel 2156: END
                   2157: 
                   2158:     my $start_page=
                   2159: 	&Apache::loncommon::start_page('Discussion options',$js);
                   2160:     my $end_page=
                   2161: 	&Apache::loncommon::end_page();
                   2162: 
                   2163:     $r->print(<<END);
                   2164: $start_page
1.273     bisitz   2165: <form name="modifyshown" method="post" action="/adm/feedback">
1.100     raeburn  2166: <b>$lt{'diso'}</b><br/> $lt{'prca'}
                   2167: <br /><br />
                   2168: <table border="0">
                   2169:  <tr>
1.281     bisitz   2170:   <th>$lt{'soor'}</th>
                   2171:   <th>&nbsp;</th>
                   2172:   <th>$lt{'sprs'}</th>
                   2173:   <th>&nbsp;</th>
                   2174:   <th>$lt{'spur'}</th>
                   2175:   <th>&nbsp;</th>
                   2176:   <th>$lt{'spse'}</th>
                   2177:   <th>&nbsp;</th>
                   2178:   <th>$lt{'spgr'}</th>
                   2179:   <th>&nbsp;</th>
                   2180:   <th>$lt{'psub'}</th>
1.100     raeburn  2181:  </tr>
                   2182:  <tr>
1.208     raeburn  2183:   <td align="center" valign="top">
1.100     raeburn  2184:    <select name="sortposts">
1.212     albertel 2185:     <option value="ascdate" selected="selected">$sort_types{'ascdate'}</option>
                   2186:     <option value="descdate">$sort_types{'descdate'}</option>
                   2187:     <option value="thread">$sort_types{'thread'}</option>
                   2188:     <option value="subject">$sort_types{'subject'}</option>
                   2189:     <option value="username">$sort_types{'username'}</option>
                   2190:     <option value="lastfirst">$sort_types{'lastfirst'}</option>
1.100     raeburn  2191:    </select>
                   2192:   </td>
                   2193:   <td>&nbsp;</td>
1.208     raeburn  2194:   <td align="center" valign="top">
1.143     raeburn  2195:    <select name="statusfilter">
1.215     albertel 2196:     <option value="all" selected="selected">$status_types{'all'}</option>
                   2197:     <option value="Active">$status_types{'Active'}</option>
                   2198:     <option value="Expired">$status_types{'Expired'}</option>
                   2199:     <option value="Future">$status_types{'Future'}</option>
1.100     raeburn  2200:    </select>
                   2201:   </td>
                   2202:   <td>&nbsp;</td>
1.208     raeburn  2203:   <td align="center" valign="top">
1.262     bisitz   2204:    <select name="rolefilter" multiple="multiple" size="5">
1.212     albertel 2205:     <option value="all">$role_types{'all'}</option>
                   2206:     <option value="st">$role_types{'st'}</option>
1.278     raeburn  2207:     <option value="$ccrole">$role_types{$ccrole}</option>
1.212     albertel 2208:     <option value="in">$role_types{'in'}</option>
                   2209:     <option value="ta">$role_types{'ta'}</option>
                   2210:     <option value="ep">$role_types{'ep'}</option>
1.278     raeburn  2211:     <option value="ad">$role_types{'ad'}</option>
1.212     albertel 2212:     <option value="cr">$role_types{'cr'}</option>
1.100     raeburn  2213:    </select>
                   2214:   </td>
                   2215:   <td>&nbsp;</td>
1.208     raeburn  2216:   <td align="center" valign="top">
1.262     bisitz   2217:    <select name="sectionpick" multiple="multiple" size="$numvisible">
1.100     raeburn  2218:     $section_sel
                   2219:    </select>
                   2220:   </td>
                   2221:   <td>&nbsp;</td>
1.208     raeburn  2222:   <td align="center" valign="top">
1.262     bisitz   2223:    <select name="grouppick" multiple="multiple" size="$numvisible">
1.208     raeburn  2224:     $group_sel
                   2225:    </select>
                   2226:   </td>
                   2227:   <td>&nbsp;</td>
                   2228:   <td valign="top"><label><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</label></td>
1.100     raeburn  2229:  </tr>
                   2230: </table>
                   2231: <br />
                   2232: <br />
                   2233: <input type="hidden" name="previous" value="$previous" />
                   2234: <input type="hidden" name="applysort" value="$symb" />
1.282     wenzelju 2235: <input type="button" name="sub" value="$lt{'stor'}" onclick="verifyFilter()" />
1.208     raeburn  2236: END
                   2237:     if (exists($env{'form.group'})) {
                   2238:         $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
                   2239:     }
                   2240:     if (exists($env{'form.ref'})) {
                   2241:         $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
                   2242:     }
                   2243:     $r->print("
1.100     raeburn  2244: <br />
                   2245: <br />
                   2246: </form>
1.187     albertel 2247: $end_page
1.208     raeburn  2248: ");
1.100     raeburn  2249: }
                   2250: 
1.101     raeburn  2251: sub print_showposters {
                   2252:     my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
1.133     albertel 2253: 
1.154     albertel 2254:     &Apache::loncommon::content_type($r,'text/html');
                   2255:     $r->send_http_header;
                   2256: 
1.139     albertel 2257:     &Apache::lonenc::check_encrypt(\$symb);
1.157     albertel 2258:     my $crs='/'.$env{'request.course.id'};
                   2259:     if ($env{'request.course.sec'}) {
                   2260:         $crs.='_'.$env{'request.course.sec'};
1.102     raeburn  2261:     }
1.101     raeburn  2262:     $crs=~s/\_/\//g;
1.208     raeburn  2263:     my $seeid;
                   2264:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2265:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2266:     my $group = $env{'form.group'};
                   2267:     my $ressymb = &wrap_symb($symb);
                   2268:     if (($group ne '') &&
                   2269:         ($ressymb =~ m|^bulletin___ \d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|)) {
                   2270:         if (&check_group_priv($group,'dgp') eq 'ok') {
                   2271:             $seeid = 1;
                   2272:         }
                   2273:     } else {
                   2274:         $seeid=&Apache::lonnet::allowed('rin',$crs);
                   2275:     }
1.157     albertel 2276:     my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
1.208     raeburn  2277:                                          $cdom,$cnum);
1.101     raeburn  2278:     my %namesort = ();
                   2279:     my %postcounts = ();
1.186     albertel 2280: 
1.208     raeburn  2281:     my %lt = &Apache::lonlocal::texthash(
                   2282:                                           sele => 'Select',
                   2283:                                           full => 'Fullname',
1.220     raeburn  2284:                                           usdo => 'Username:domain',
1.208     raeburn  2285:                                           post => 'Posts',
                   2286:                                         );
1.101     raeburn  2287:     if ($contrib{'version'}) {
                   2288:         for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
                   2289:             my $hidden=($contrib{'hidden'}=~/\.$idx\./);
                   2290:             my $deleted=($contrib{'deleted'}=~/\.$idx\./);
                   2291:             unless ((($hidden) && (!$seeid)) || ($deleted)) {
1.208     raeburn  2292:                 if ((!$contrib{$idx.':anonymous'}) || (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
1.101     raeburn  2293:                     my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
                   2294:                     my $lastname = $names{'lastname'};
                   2295:                     my $firstname = $names{'firstname'};
                   2296:                     if ($lastname eq '') {
                   2297:                         $lastname = '_';
                   2298:                     }
                   2299:                     if ($firstname eq '') {
                   2300:                         $firstname = '_';
                   2301:                     }
                   2302:                     unless (defined($namesort{$lastname})) {
                   2303:                         %{$namesort{$lastname}} = ();
                   2304:                     }
                   2305:                     my $poster =  $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
                   2306:                     $postcounts{$poster} ++;
                   2307:                     if (defined($namesort{$lastname}{$firstname})) {
                   2308:                         if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
1.221     raeburn  2309:                             push(@{$namesort{$lastname}{$firstname}}, $poster);
1.101     raeburn  2310:                         }
                   2311:                     } else {
                   2312:                         @{$namesort{$lastname}{$firstname}} = ("$poster");
                   2313:                     }
                   2314:                 }
                   2315:             }
                   2316:         }
                   2317:     }
1.186     albertel 2318: 
                   2319:     my $start_page = &Apache::loncommon::start_page('Discussion options');
1.196     albertel 2320:     my $table_start =&Apache::loncommon::start_data_table();
1.101     raeburn  2321:     $r->print(<<END);
1.186     albertel 2322: $start_page
1.101     raeburn  2323:  <form name="pickpostersform" method="post">
1.196     albertel 2324:  <br />
                   2325:     $table_start
                   2326:       <tr>
1.208     raeburn  2327:        <th>#</th>
                   2328:        <th>$lt{'sele'}</th>
                   2329:        <th>$lt{'full'} <font color="#999999">($lt{'usdo'})</font></th>
                   2330:        <th>$lt{'post'}</th>
1.101     raeburn  2331:       </tr>
                   2332: END
                   2333:     my $count = 0;
1.221     raeburn  2334:     foreach my $last (sort(keys(%namesort))) {
                   2335:         foreach my $first (sort(keys(%{$namesort{$last}}))) {
                   2336:             foreach my $user (sort(@{$namesort{$last}{$first}})) {
                   2337:                 my ($uname,$udom) = split(/:/,$user);
1.101     raeburn  2338:                 if (!$uname || !$udom) { 
                   2339:                     next;
                   2340:                 } else {
                   2341:                     $count ++;
1.196     albertel 2342:                     $r->print(&Apache::loncommon::start_data_table_row().
                   2343: 			      '<td align="right">'.$count.'</td>
1.221     raeburn  2344:                                <td align="center"><label><input name="stuinfo" type="checkbox" value="'.$user.'" /></td>
1.220     raeburn  2345:                                <td>'.$last.', '.$first.' ('.$uname.':'.$udom.')</label></td>
1.221     raeburn  2346:                                <td>'.$postcounts{$user}.'</td>'.
1.196     albertel 2347: 			      &Apache::loncommon::end_data_table_row());
1.101     raeburn  2348:                 }
                   2349:             }
                   2350:         }
                   2351:     }
1.196     albertel 2352:     $r->print(&Apache::loncommon::end_data_table());
1.186     albertel 2353:     my $end_page   = &Apache::loncommon::end_page();
1.101     raeburn  2354:     $r->print(<<END);
                   2355: <br />
                   2356: <input type="hidden" name="sortposts" value="$sortposts" />
                   2357: <input type="hidden" name="userpick" value="$symb" />
1.282     wenzelju 2358: <input type="button" name="store" value="Display posts" onclick="javascript:document.pickpostersform.submit()" />
1.101     raeburn  2359: </form>
1.186     albertel 2360: $end_page
1.101     raeburn  2361: END
                   2362: }
                   2363: 
1.112     raeburn  2364: sub get_post_versions {
1.116     raeburn  2365:     my ($versions,$incoming,$htmldecode,$numver) = @_;
                   2366:     if ($incoming =~ /^<version num="0">/) {
                   2367:         my $p = HTML::LCParser->new(\$incoming);
1.186     albertel 2368:         my $done = 0; 
                   2369: 
1.116     raeburn  2370:         while ( (my $token = $p->get_tag("version")) && (!$done)) {
                   2371:             my $num = $token->[1]{num};
                   2372:             my $text = $p->get_text("/version");
                   2373:             if (defined($numver)) {
                   2374:                 if ($num == $numver) {
                   2375:                     if ($htmldecode) {
                   2376:                         $text = &HTML::Entities::decode($text);
                   2377:                     }
                   2378:                     $$versions{$numver}=$text;
                   2379:                     $done = 1;
                   2380:                 }
                   2381:             } else {
                   2382:                 if ($htmldecode) {
                   2383:                     $text = &HTML::Entities::decode($text);
                   2384:                 }
                   2385:                 $$versions{$num}=$text;
1.112     raeburn  2386:             }
1.116     raeburn  2387:         }
                   2388:     } else {
                   2389:         if (!defined($numver)) {
                   2390:             $numver = 0;
                   2391:         }
                   2392:         if ($htmldecode) {
                   2393:             $$versions{$numver} = $incoming;
1.112     raeburn  2394:         } else {
1.116     raeburn  2395:             $$versions{$numver} = &HTML::Entities::encode($incoming,'<>&"');
1.112     raeburn  2396:         }
                   2397:     }
                   2398:     return;
                   2399: }
                   2400: 
1.113     raeburn  2401: sub get_post_attachments {
                   2402:     my ($attachments,$attachmenturls) = @_;
                   2403:     my $num;
1.116     raeburn  2404:     if ($attachmenturls =~ m/^<attachment id="0">/) {
                   2405:         my $p = HTML::LCParser->new(\$attachmenturls);
                   2406:         while (my $token = $p->get_tag("attachment","filename","post"))  {
                   2407:             if ($token->[0] eq "attachment") {
                   2408:                 $num = $token->[1]{id};
                   2409:                 %{$$attachments{$num}} =();
                   2410:             } elsif ($token->[0] eq "filename") {
                   2411:                 $$attachments{$num}{'filename'} = $p->get_text("/filename");
                   2412:             } elsif ($token->[0] eq "post") {
                   2413:                 my $id = $token->[1]{id};
                   2414:                 $$attachments{$num}{$id} = $p->get_text("/post");
                   2415:             }
1.113     raeburn  2416:         }
1.116     raeburn  2417:     } else {
                   2418:         %{$$attachments{'0'}} = ();
                   2419:         $$attachments{'0'}{'filename'} = $attachmenturls;
                   2420:         $$attachments{'0'}{'0'} = 'n';
1.113     raeburn  2421:     }
1.116     raeburn  2422: 
1.113     raeburn  2423:     return;
                   2424: }
                   2425: 
1.150     albertel 2426: sub fail_redirect {
1.6       albertel 2427:   my ($r,$feedurl) = @_;
1.70      www      2428:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.220     raeburn  2429:   my %lt = &Apache::lonlocal::texthash(
1.289     bisitz   2430:                  'sorr' => 'Sorry, no recipients ...',
1.220     raeburn  2431:   );
1.150     albertel 2432:   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.186     albertel 2433:   $r->print(&Apache::loncommon::start_page('Feedback not sent',undef,
                   2434: 					   {'redirect'  => [2,$feedurl],
                   2435: 					    'only_body' => 1,}));
                   2436:   $r->print(<<ENDFAILREDIR);
1.150     albertel 2437: <img align="right" src="$logo" />
1.220     raeburn  2438: <b>$lt{'sorr'}</b>
1.5       www      2439: ENDFAILREDIR
1.186     albertel 2440:   $r->print(&Apache::loncommon::end_page());
1.5       www      2441: }
1.4       www      2442: 
1.6       albertel 2443: sub redirect_back {
1.255     raeburn  2444:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_;
1.100     raeburn  2445:   my $sorttag = '';
1.101     raeburn  2446:   my $roletag = '';
                   2447:   my $statustag = '';
                   2448:   my $sectag = '';
1.208     raeburn  2449:   my $grptag = '';
1.101     raeburn  2450:   my $userpicktag = '';
                   2451:   my $qrystr = '';
1.80      raeburn  2452:   my $prevtag = '';
1.133     albertel 2453: 
1.135     albertel 2454:   &Apache::loncommon::content_type($r,'text/html');
                   2455:   $r->send_http_header;
1.133     albertel 2456:   &dewrapper(\$feedurl);
1.70      www      2457:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80      raeburn  2458:   if ($previous > 0) {
                   2459:       $qrystr = 'previous='.$previous;
                   2460:       if ($feedurl =~ /\?register=1/) {
1.282     wenzelju 2461:           $feedurl .= '&amp;'.$qrystr;
1.80      raeburn  2462:       } else {
                   2463:           $feedurl .= '?'.$qrystr;
                   2464:       }
                   2465:       $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
                   2466:   }
1.100     raeburn  2467:   if (defined($sort)) {
                   2468:       my $sortqry = 'sortposts='.$sort;
                   2469:       if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
1.282     wenzelju 2470:           $feedurl .= '&amp;'.$sortqry;
1.100     raeburn  2471:       } else {
                   2472:           $feedurl .= '?'.$sortqry;
                   2473:       }
                   2474:       $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.143     raeburn  2475:       if (defined($numpicks)) {
1.101     raeburn  2476:           my $userpickqry = 'totposters='.$numpicks;
1.282     wenzelju 2477:           $feedurl .= '&amp;'.$userpickqry;
1.101     raeburn  2478:           $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
                   2479:       } else {
1.143     raeburn  2480:           if (ref($sectionpick) eq 'ARRAY') {
1.282     wenzelju 2481:               $feedurl .= '&amp;sectionpick=';
1.143     raeburn  2482:               $sectag .=  '<input type="hidden" name="sectionpick" value="';
1.221     raeburn  2483:               foreach my $sec (@{$sectionpick}) {
                   2484:                   $feedurl .= $sec.',';
                   2485:                   $sectag .= $sec.',';
1.143     raeburn  2486:               }
                   2487:               $feedurl =~ s/,$//;
                   2488:               $sectag =~ s/,$//;
                   2489:               $sectag .= '" />';
                   2490:           } else {
1.282     wenzelju 2491:               $feedurl .= '&amp;sectionpick='.$sectionpick;
1.143     raeburn  2492:               $sectag = '<input type="hidden" name="sectionpick" value="'.$sectionpick.'" />';
                   2493:           }
1.208     raeburn  2494:           if (ref($grouppick) eq 'ARRAY') {
1.282     wenzelju 2495:               $feedurl .= '&amp;grouppick=';
1.208     raeburn  2496:               $sectag .=  '<input type="hidden" name="grouppick" value="';
                   2497:               foreach my $grp (@{$grouppick}) {
                   2498:                   $feedurl .= $grp.',';
                   2499:                   $grptag .= $grp.',';
                   2500:               }
                   2501:               $feedurl =~ s/,$//;
                   2502:               $grptag =~ s/,$//;
                   2503:               $grptag .= '" />';
                   2504:           } else {
1.282     wenzelju 2505:               $feedurl .= '&amp;grouppick='.$grouppick;
1.208     raeburn  2506:               $grptag = '<input type="hidden" name="grouppick" value="'.$grouppick.'" />';
                   2507:           }
1.143     raeburn  2508:           if (ref($rolefilter) eq 'ARRAY') {
1.282     wenzelju 2509:               $feedurl .= '&amp;rolefilter=';
1.143     raeburn  2510:               $roletag .=  '<input type="hidden" name="rolefilter" value="';
1.221     raeburn  2511:               foreach my $role (@{$rolefilter}) {
                   2512:                   $feedurl .= $role.',';
                   2513:                   $roletag .= $role.',';
1.143     raeburn  2514:               }
                   2515:               $feedurl =~ s/,$//;
                   2516:               $roletag =~ s/,$//;
                   2517:               $roletag .= '" />';
                   2518:           } else {
1.282     wenzelju 2519:               $feedurl .= '&amp;rolefilter='.$rolefilter;
1.143     raeburn  2520:               $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
                   2521:           }
1.282     wenzelju 2522:           $feedurl .= '&amp;statusfilter='.$statusfilter;
1.101     raeburn  2523:           $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
                   2524:       }
1.100     raeburn  2525:   }
1.208     raeburn  2526:   my $grouptag;
                   2527:   if ($group ne '') {
1.269     bisitz   2528:       $grouptag = '<input type="hidden" name="group" value="'.$group.'" />';
                   2529:       my $refarg;
1.208     raeburn  2530:       if (exists($env{'form.ref'})) {
                   2531:           $refarg = '&amp;ref='.$env{'form.ref'};
                   2532:           $grouptag .= '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />';
                   2533:       }
                   2534:       if ($feedurl =~ /\?/) {
                   2535:           $feedurl .= '&amp;group='.$group.$refarg;
                   2536:       } else {
                   2537:           $feedurl .= '?group='.$group.$refarg;
                   2538:       }
                   2539:   } 
1.233     raeburn  2540:   &Apache::lonenc::check_encrypt(\$feedurl);
1.150     albertel 2541:   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.200     albertel 2542:   my %onload;
1.186     albertel 2543:   my $start_page=
1.207     albertel 2544:       &Apache::loncommon::start_page('Feedback sent',undef,
1.208     raeburn  2545: 				     {'redirect'    => [0,$feedurl],
1.186     albertel 2546: 				      'only_body'   => 1,
1.189     albertel 2547: 				      'add_entries' => \%onload});
1.186     albertel 2548:   my $end_page = &Apache::loncommon::end_page();
                   2549:   $r->print(<<ENDREDIR);
                   2550: $start_page
1.150     albertel 2551: <img align="right" src="$logo" />
1.5       www      2552: $typestyle
1.32      albertel 2553: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.175     www      2554: $blog
1.255     raeburn  2555: $toolarge
1.63      albertel 2556: <font color="red">$status</font>
1.49      www      2557: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80      raeburn  2558: $prevtag
1.100     raeburn  2559: $sorttag
1.101     raeburn  2560: $statustag
                   2561: $roletag
                   2562: $sectag
1.208     raeburn  2563: $grptag
1.101     raeburn  2564: $userpicktag
1.208     raeburn  2565: $grouptag
1.49      www      2566: </form>
1.186     albertel 2567: $end_page
1.2       www      2568: ENDREDIR
                   2569: }
1.6       albertel 2570: 
                   2571: sub no_redirect_back {
                   2572:   my ($r,$feedurl) = @_;
1.289     bisitz   2573:   my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.187     albertel 2574:  
1.200     albertel 2575:   my %onload;
                   2576: 
1.187     albertel 2577:   my %body_options = ('only_body'   => 1,
1.191     albertel 2578: 		      'bgcolor'     => '#FFFFFF',
1.200     albertel 2579: 		      'add_entries' => \%onload,);
1.187     albertel 2580: 
                   2581:   if ($feedurl !~ m{^/adm/feedback}) { 
                   2582:       $body_options{'rediect'} = [2,$feedurl];
1.7       albertel 2583:   }
1.187     albertel 2584:   my $start_page=
                   2585:       &Apache::loncommon::start_page('Feedback not sent',undef,
                   2586: 				     \%body_options);
                   2587: 				      
                   2588:   my $end_page = &Apache::loncommon::end_page();
                   2589: 
1.233     raeburn  2590:   &Apache::lonenc::check_encrypt(\$feedurl);
1.150     albertel 2591:   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.8       www      2592:   $r->print (<<ENDNOREDIRTWO);
1.191     albertel 2593: $start_page
1.150     albertel 2594: <img align="right" src="$logo" />
1.107     www      2595: <b>$nofeed</b>
1.187     albertel 2596: <br />
                   2597: $end_page
1.8       www      2598: ENDNOREDIRTWO
1.2       www      2599: }
1.6       albertel 2600: 
                   2601: sub screen_header {
1.141     raeburn  2602:     my ($feedurl,$symb) = @_;
1.278     raeburn  2603:     my $crscontent = &mt('Question/Comment/Feedback about course content');
                   2604:     my $crspolicy = &mt('Question/Comment/Feedback about course policy');
                   2605:     my $contribdisc = &mt('Contribution to course discussion of resource');
                   2606:     my $anoncontrib = &mt('Anonymous contribution to course discussion of resource');
                   2607:     my $namevis = &mt('name only visible to course faculty');
                   2608:     my $crstype;
                   2609:     if ($env{'request.course.id'}) {
                   2610:         $crstype = &Apache::loncommon::course_type();
                   2611:         if ($crstype eq 'Community') {
                   2612:             $crscontent = &mt('Question/Comment/Feedback about community content');
                   2613:             $crspolicy = &mt('Question/Comment/Feedback about community policy');
                   2614:             $contribdisc = &mt('Contribution to community discussion of resource');
                   2615:             $anoncontrib = &mt('Anonymous contribution to community discussion of resource');
                   2616:             $namevis = &mt('name only visible to community facilitators');
                   2617:         }
                   2618:     }
1.65      www      2619:     my $msgoptions='';
                   2620:     my $discussoptions='';
1.157     albertel 2621:     unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
1.167     www      2622: 	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
1.65      www      2623: 	    $msgoptions= 
1.202     albertel 2624: 		'<p><label><input type="radio" name="discuss" value="author" /> '.
1.151     albertel 2625: 		&mt('Feedback to resource author').'</label></p>';
1.65      www      2626: 	}
1.243     www      2627:         my %optionhash=();
                   2628:         foreach my $type ('question','comment','policy') {
                   2629: 	    $optionhash{$type}=$env{'course.'.$env{'request.course.id'}.'.'.$type.'.email.text'};
                   2630: 	}
1.65      www      2631: 	if (&feedback_available(1)) {
                   2632: 	    $msgoptions.=
1.202     albertel 2633: 		'<p><label><input type="radio" name="discuss" value="question" /> '.
1.243     www      2634: 		($optionhash{'question'}?$optionhash{'question'}:&mt('Question about resource content')).'</label></p>';
1.65      www      2635: 	}
                   2636: 	if (&feedback_available(0,1)) {
                   2637: 	    $msgoptions.=
1.202     albertel 2638: 		'<p><label><input type="radio" name="discuss" value="course" /> '.
1.278     raeburn  2639: 		($optionhash{'comment'}?$optionhash{'comment'}:$crscontent).
1.151     albertel 2640: 		'</label></p>';
1.65      www      2641: 	}
                   2642: 	if (&feedback_available(0,0,1)) {
                   2643: 	    $msgoptions.=
1.202     albertel 2644: 		'<p><label><input type="radio" name="discuss" value="policy" /> '.
1.278     raeburn  2645: 		($optionhash{'policy'}?$optionhash{'policy'}:$crspolicy).
1.151     albertel 2646: 		'</label></p>';
1.65      www      2647: 	}
                   2648:     }
1.190     www      2649:     if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
1.241     raeburn  2650:         my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards');
                   2651:         if (!$blocked && &discussion_open(undef,$symb) && 
1.90      albertel 2652: 	    &Apache::lonnet::allowed('pch',
1.157     albertel 2653: 				     $env{'request.course.id'}.
                   2654: 				     ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.234     raeburn  2655: 	    $discussoptions='<label><input type="radio" name="discuss" value="nonanon" checked="checked" /> '.
1.278     raeburn  2656: 		$contribdisc.
                   2657: 	        '</label><br /><label><input type="radio" name="discuss" value="anon" /> '.
                   2658: 		$anoncontrib.
                   2659: 		' <i>('.$namevis.')</i></label> '.
1.234     raeburn  2660: 		'<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';
1.241     raeburn  2661:             my $blockblog = &Apache::loncommon::blocking_status('blogs');
                   2662:             if (!$blockblog) {
1.278     raeburn  2663:                 $discussoptions.= &add_blog_checkbox($crstype);
1.241     raeburn  2664:             }
1.141     raeburn  2665:         }
1.65      www      2666:     }
1.272     bisitz   2667:     if ($msgoptions) {
1.293     wenzelju 2668:         $msgoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/feedback.png').'" />'
1.279     www      2669:                    .' '.&mt('Send Feedback').'</h2><p>'.&Apache::lonhtmlcommon::coursepreflink(&mt('Feedback Settings'),'feedback').'</p>'
1.272     bisitz   2670:                    .$msgoptions;
                   2671:     }
1.65      www      2672:     if ($discussoptions) { 
1.285     raeburn  2673: 	$discussoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" alt="" />'
1.279     www      2674:                         .' '.&mt('Discussion Contributions').'</h2><p>'.&Apache::lonhtmlcommon::coursepreflink(&mt('Discussion Settings'),'discussion').'</p>'
1.272     bisitz   2675:                         .$discussoptions;
                   2676:     }
1.65      www      2677:     return $msgoptions.$discussoptions;
1.6       albertel 2678: }
                   2679: 
                   2680: sub resource_output {
                   2681:   my ($feedurl) = @_;
1.46      albertel 2682:   my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6       albertel 2683:   $usersaw=~s/\<body[^\>]*\>//gi;
                   2684:   $usersaw=~s/\<\/body\>//gi;
                   2685:   $usersaw=~s/\<html\>//gi;
                   2686:   $usersaw=~s/\<\/html\>//gi;
                   2687:   $usersaw=~s/\<head\>//gi;
                   2688:   $usersaw=~s/\<\/head\>//gi;
                   2689:   $usersaw=~s/action\s*\=/would_be_action\=/gi;
                   2690:   return $usersaw;
                   2691: }
                   2692: 
                   2693: sub clear_out_html {
1.297     raeburn  2694:   my ($message,$override)=@_;
1.107     www      2695: # Always allow the <m>-tag
                   2696:   my %html=(M=>1);
                   2697: # Check if more is allowed
1.157     albertel 2698:   my $cid=$env{'request.course.id'};
                   2699:   if (($env{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
1.39      www      2700:       ($override)) {
1.37      albertel 2701:       # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> 
1.88      www      2702:       # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
1.283     faziophi 2703:       # <SUP> <TABLE> <TR> <TD> <TH> <TBODY>
1.107     www      2704:       %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
1.297     raeburn  2705: 	     BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, PRE=>1, DIV=>1, IMG=>1,
                   2706: 	     M=>1, CHEM=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1,  
1.283     faziophi 2707: 	     H1=>1, H2=>1, H3=>1, H4=>1, H5=>1, H6=>1, 
                   2708: 	     TABLE=>1, TR=>1, TD=>1, TH=>1, TBODY=>1);
1.107     www      2709:   }
                   2710: # Do the substitution of everything that is not explicitly allowed
1.216     albertel 2711:   $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48      albertel 2712: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
1.216     albertel 2713:   $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48      albertel 2714: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
1.6       albertel 2715:   return $message;
                   2716: }
                   2717: 
                   2718: sub assemble_email {
1.237     raeburn  2719:   my ($message,$prevattempts,$usersaw,$useranswer)=@_;
1.220     raeburn  2720:   my %lt = &Apache::lonlocal::texthash(
                   2721:              'prev' => 'Previous attempts of student (if applicable)',
                   2722:              'orig' => 'Original screen output (if applicable)',
                   2723:              'corr' => 'Correct Answer(s) (if applicable)',
                   2724:   );
1.278     raeburn  2725:   if (&Apache::loncommon::course_type() eq 'Community') {
                   2726:       $lt{'prev'} = &mt('Previous attempts of member (if applicable)');
                   2727:   }
1.6       albertel 2728:   my $email=<<"ENDEMAIL";
                   2729: $message
                   2730: ENDEMAIL
                   2731:     my $citations=<<"ENDCITE";
1.220     raeburn  2732: <h2>$lt{'prev'}</h2>
1.6       albertel 2733: $prevattempts
1.63      albertel 2734: <br /><hr />
1.220     raeburn  2735: <h2>$lt{'orig'}</h2>
1.6       albertel 2736: $usersaw
1.220     raeburn  2737: <h2>$lt{'corr'}</h2>
1.40      albertel 2738: $useranswer
1.6       albertel 2739: ENDCITE
                   2740:   return ($email,$citations);
                   2741: }
                   2742: 
1.36      www      2743: 
                   2744: sub feedback_available {
                   2745:     my ($question,$course,$policy)=@_;
1.242     albertel 2746:     my ($typestyle,%to)=&Apache::lonmsg::decide_receiver('',0,$question,
                   2747: 							 $course,$policy);
1.36      www      2748:     return scalar(%to);
1.6       albertel 2749: }
                   2750: 
                   2751: sub send_msg {
1.246     albertel 2752:     my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,%to)=@_;
                   2753:     my $status='';
                   2754:     my $sendsomething=0;
                   2755:     my $restitle = &get_resource_title($symb,$feedurl);
                   2756:     if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }
                   2757:     unless ($title=~/\w/) { $title=&mt('Feedback'); }
                   2758:     foreach my $key (keys(%to)) {
                   2759: 	if ($key) {
                   2760: 	    my ($user,$domain) = split(/\:/,$key,2);
                   2761: 	    if (!defined($user)) {
                   2762: 		$status.='<br />'.&mt('Error sending message to [_1], no user specified.',$key);
                   2763: 	    } elsif (!defined($domain)) {
                   2764: 		$status.='<br />'.&mt('Error sending message to [_1], no domain specified.',$key);
                   2765: 	    } else {
                   2766: 		unless (&Apache::lonmsg::user_normal_msg($user,$domain,
                   2767: 							 $title.' ['.$restitle.']',$email,$citations,$feedurl,
                   2768: 							 $attachmenturl,undef,undef,$symb,$restitle)=~/ok/) {
                   2769: 		    $status.='<br />'.&mt('Error sending message to').' '.$key.'<br />';
                   2770: 		} else {
                   2771: 		    $sendsomething++;
                   2772: 		}
                   2773: 	    }
                   2774: 	}
1.6       albertel 2775:     }
1.246     albertel 2776: 
1.18      www      2777: 
                   2778:     my %record=&Apache::lonnet::restore('_feedback');
1.221     raeburn  2779:     my ($temp)=keys(%record);
1.18      www      2780:     unless ($temp=~/^error\:/) {
1.246     albertel 2781: 	my %newrecord=();
                   2782: 	$newrecord{'resource'}=$feedurl;
                   2783: 	$newrecord{'subnumber'}=$record{'subnumber'}+1;
                   2784: 	unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
                   2785: 	    $status.='<br />'.&mt('Not registered').'<br />';
                   2786: 	}
1.18      www      2787:     }
1.246     albertel 2788:     
                   2789:     return ($status,$sendsomething);
1.6       albertel 2790: }
                   2791: 
1.13      www      2792: sub adddiscuss {
1.78      raeburn  2793:     my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13      www      2794:     my $status='';
1.122     raeburn  2795:     my $realsymb;
                   2796:     if ($symb=~/^bulletin___/) {
                   2797: 	my $filename=(&Apache::lonnet::decode_symb($symb))[2];
                   2798: 	$filename=~s|^adm/wrapper/||;
                   2799: 	$realsymb=&Apache::lonnet::symbread($filename);
                   2800:     }
                   2801:     if (&discussion_open(undef,$realsymb) &&
1.157     albertel 2802: 	&Apache::lonnet::allowed('pch',$env{'request.course.id'}.
                   2803:         ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.20      www      2804: 
1.13      www      2805:     my %contrib=('message'      => $email,
1.157     albertel 2806:                  'sendername'   => $env{'user.name'},
                   2807:                  'senderdomain' => $env{'user.domain'},
                   2808:                  'screenname'   => $env{'environment.screenname'},
                   2809:                  'plainname'    => $env{'environment.firstname'}.' '.
                   2810: 		                   $env{'environment.middlename'}.' '.
                   2811:                                    $env{'environment.lastname'}.' '.
                   2812:                                    $env{'enrironment.generation'},
1.78      raeburn  2813:                  'attachmenturl'=> $attachmenturl,
                   2814:                  'subject'      => $subject);
1.157     albertel 2815:     if ($env{'form.replydisc'}) {
                   2816: 	$contrib{'replyto'}=(split(/\:\:\:/,$env{'form.replydisc'}))[1];
1.65      www      2817:     }
1.14      www      2818:     if ($anon) {
                   2819: 	$contrib{'anonymous'}='true';
                   2820:     }
1.13      www      2821:     if (($symb) && ($email)) {
1.231     raeburn  2822:         my $now = time;
1.157     albertel 2823:         if ($env{'form.editdisc'}) {
1.102     raeburn  2824:             $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
                   2825:             $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
1.231     raeburn  2826:             $contrib{'timestamp'} = $now;
1.102     raeburn  2827:             $contrib{'history'} = '';
                   2828:             my $numoldver = 0;
1.157     albertel 2829:             my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});
1.132     albertel 2830: 	    &Apache::lonenc::check_decrypt(\$oldsymb);
1.110     raeburn  2831:             $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102     raeburn  2832: # get timestamp for last post and history
1.157     albertel 2833:             my %oldcontrib=&Apache::lonnet::restore($oldsymb,$env{'request.course.id'},
                   2834:                      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2835:                      $env{'course.'.$env{'request.course.id'}.'.num'});
1.102     raeburn  2836:             if (defined($oldcontrib{$oldidx.':replyto'})) {
                   2837:                 $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
                   2838:             }
                   2839:             if (defined($oldcontrib{$oldidx.':history'})) {
                   2840:                 if ($oldcontrib{$oldidx.':history'} =~ /:/) {
1.221     raeburn  2841:                     my @oldversions = split(/:/,$oldcontrib{$oldidx.':history'});
1.102     raeburn  2842:                     $numoldver = @oldversions;
                   2843:                 } else {
                   2844:                     $numoldver = 1;
                   2845:                 }
                   2846:                 $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
                   2847:             }
1.108     raeburn  2848:             my $numnewver = $numoldver + 1;
1.102     raeburn  2849:             if (defined($oldcontrib{$oldidx.':subject'})) {
1.112     raeburn  2850:                 if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
                   2851:                     $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
                   2852:                     $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108     raeburn  2853:                 } else {
1.112     raeburn  2854:                     $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108     raeburn  2855:                 }
1.102     raeburn  2856:             } 
                   2857:             if (defined($oldcontrib{$oldidx.':message'})) {
1.112     raeburn  2858:                 if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
                   2859:                     $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
                   2860:                     $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108     raeburn  2861:                 } else {
1.112     raeburn  2862:                     $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108     raeburn  2863:                 }
1.102     raeburn  2864:             }
                   2865:             $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
1.157     albertel 2866:             my $put_reply = &Apache::lonnet::putstore($env{'request.course.id'},
1.182     albertel 2867:                   $oldsymb,$oldidx,\%contrib,
1.157     albertel 2868:                   $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2869:                   $env{'course.'.$env{'request.course.id'}.'.num'});
1.102     raeburn  2870:             $status='Editing class discussion'.($anon?' (anonymous)':'');
                   2871:         } else {
                   2872:            $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.157     albertel 2873:            &Apache::lonnet::store(\%contrib,$symb,$env{'request.course.id'},
                   2874:                      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2875: 		     $env{'course.'.$env{'request.course.id'}.'.num'});
1.102     raeburn  2876:         }
1.231     raeburn  2877:         my %storenewentry=($symb => $now);
1.63      albertel 2878:         $status.='<br />'.&mt('Updating discussion time').': '.
1.21      www      2879:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
1.157     albertel 2880:                      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2881: 		     $env{'course.'.$env{'request.course.id'}.'.num'});
1.13      www      2882:     }
1.17      www      2883:     my %record=&Apache::lonnet::restore('_discussion');
1.221     raeburn  2884:     my ($temp)=keys(%record);
1.17      www      2885:     unless ($temp=~/^error\:/) {
                   2886:        my %newrecord=();
                   2887:        $newrecord{'resource'}=$symb;
                   2888:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63      albertel 2889:        $status.='<br />'.&mt('Registering').': '.
1.21      www      2890:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20      www      2891:     }
                   2892:     } else {
                   2893: 	$status.='Failed.';
1.17      www      2894:     }
1.63      albertel 2895:     return $status.'<br />';   
1.13      www      2896: }
                   2897: 
1.231     raeburn  2898: sub get_discussion_info {
                   2899:     my ($idx,%contrib) = @_;
                   2900:     my $changelast = 0;
                   2901:     my $count = 0;
                   2902:     my $hiddenflag = 0;
                   2903:     my $deletedflag = 0;
                   2904:     my ($hidden,$deleted,%info,$newlastdisc);
                   2905:     my $version = $contrib{'version'};
                   2906:     if ($version) {
                   2907:         for (my $id=$version; $id>0; $id--) {
                   2908:             my $vkeys=$contrib{$id.':keys'};
                   2909:             my @keys=split(/:/,$vkeys);
                   2910:             if (grep(/^hidden$/,@keys)) {
                   2911:                 if (!$hiddenflag) {
                   2912:                     $hidden = $contrib{$id.':hidden'};
                   2913:                     $hiddenflag = 1;
                   2914:                 }
                   2915:             } elsif (grep(/^deleted$/,@keys)) {
                   2916:                 if (!$deletedflag) {
                   2917:                     $deleted = $contrib{$id.':deleted'};
                   2918:                     $deletedflag = 1;
                   2919:                 }
                   2920:             } else {
                   2921:                 if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) {
                   2922:                     $count++;
                   2923:                     $info{$count}{'id'} = $id;
                   2924:                     $info{$count}{'timestamp'}=$contrib{$id.':timestamp'}; 
                   2925:                 }
                   2926:             }
                   2927:         }
                   2928:         if ($info{'1'}{'id'} == $idx) {
                   2929:             $changelast = 1;
                   2930:             if ($count > 1) { 
                   2931:                 $newlastdisc =  $info{'2'}{'timestamp'};
                   2932:             } else {
                   2933:                 $newlastdisc = 0;
                   2934:             }
                   2935:         }
                   2936:     }
                   2937:     return ($changelast,$newlastdisc);
                   2938: }
                   2939: 
1.33      www      2940: # ----------------------------------------------------------- Preview function
                   2941: 
                   2942: sub show_preview {
1.187     albertel 2943:     my ($r) = @_;
1.135     albertel 2944:     &Apache::loncommon::content_type($r,'text/html');
                   2945:     $r->send_http_header;
1.218     albertel 2946:     my $start_page=
                   2947: 	&Apache::loncommon::start_page('Preview',undef,
                   2948: 				       {'only_body'   => 1,});
                   2949: 
1.157     albertel 2950:     my $message=&clear_out_html($env{'form.comment'});
1.165     albertel 2951:     &newline_to_br(\$message);
1.106     www      2952:     $message=&Apache::lonspeller::markeduptext($message);
1.33      www      2953:     $message=&Apache::lontexconvert::msgtexconverted($message);
1.297     raeburn  2954:     my $subject=&clear_out_html($env{'form.subject'});
1.78      raeburn  2955:     $subject=~s/\n/\<br \/\>/g;
                   2956:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.187     albertel 2957: 					
                   2958:     my $end_page = &Apache::loncommon::end_page();
                   2959: 
1.263     bisitz   2960:     $r->print($start_page
                   2961:              .'<h1>'.&mt('Preview').'</h1>'
                   2962:              .&Apache::lonhtmlcommon::start_pick_box()
                   2963:              .&Apache::lonhtmlcommon::row_title(&mt('Subject'))
                   2964:              .$subject
                   2965:              .&Apache::lonhtmlcommon::row_closure()
                   2966:              .&Apache::lonhtmlcommon::row_title(&mt('Message'))
                   2967:              .$message
                   2968:              .&Apache::lonhtmlcommon::row_closure(1)
                   2969:              .&Apache::lonhtmlcommon::end_pick_box()
                   2970:              .$end_page
                   2971:     );
1.33      www      2972: }
                   2973: 
1.280     faziophi 2974: sub contains_block_html {
1.286     raeburn  2975:     my ($message)=@_;
                   2976:     return ($message =~ m{
                   2977:         <(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div) 
                   2978: 	  \s*
                   2979: 	 (\w+\=['"]\w+['"])*
                   2980: 	  \s*
                   2981: 	(
                   2982: 	  \s*/>|
                   2983: 	  >.*</\1\s*>
                   2984: 	)}xs 
                   2985:     );
1.280     faziophi 2986: }
1.283     faziophi 2987: 
                   2988: sub tidy_html {
                   2989: 	my ($message)=@_;
                   2990: # 	my $tidy = HTML::Tidy::libXML->new();
                   2991: # 	my $xhtml = $tidy->clean($message, 'utf-8', 1);
                   2992: # 	$xhtml =~ m/<body>(.*)<\/body>/is;
                   2993: # 	my $clean = $1;
                   2994: # 	# remove any empty block-level tags
                   2995: # 	$clean =~ s/<(table|p|div|tbody|blockquote|m|pre|algebra|center|ol|ul|span|h1|h2|h3|h4|h5|h6)\s*\/>//i;
                   2996: # 	$message=$clean;
                   2997: 	return $message;
                   2998: }
                   2999: 
1.165     albertel 3000: sub newline_to_br {
                   3001:     my ($message)=@_;
                   3002:     my $newmessage;
                   3003:     my $parser=HTML::LCParser->new($message);
                   3004:     while (my $token=$parser->get_token()) {
                   3005: 	if ($token->[0] eq 'T') {
                   3006: 	    my $text=$token->[1];
                   3007: 	    $text=~s/\n/\<br \/\>/g;
                   3008: 	    $newmessage.=$text;
                   3009: 	} elsif ($token->[0] eq 'D' || $token->[0] eq 'C') {
                   3010: 	    $newmessage.=$token->[1];
                   3011: 	} elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') {
                   3012: 	    $newmessage.=$token->[2];
                   3013: 	} elsif ($token->[0] eq 'S') {
                   3014: 	    $newmessage.=$token->[4];
                   3015: 	}
                   3016: 	    
                   3017:     }
                   3018:     $$message=$newmessage;
                   3019: }
                   3020: 
1.33      www      3021: sub generate_preview_button {
1.171     www      3022:     my ($formname,$fieldname)=@_;
                   3023:     unless ($formname) { $formname='mailform'; }
                   3024:     unless ($fieldname) { $fieldname='comment'; }
1.107     www      3025:     my $pre=&mt("Show Preview and Check Spelling");
1.33      www      3026:     return(<<ENDPREVIEW);
1.205     raeburn  3027: <br />
1.33      www      3028: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.269     bisitz   3029: <input type="hidden" name="subject" />
1.33      www      3030: <input type="hidden" name="comment" />
1.65      www      3031: <input type="button" value="$pre"
1.282     wenzelju 3032: onclick="if (typeof(document.$formname.onsubmit)=='function') {document.$formname.onsubmit();};this.form.comment.value=document.$formname.$fieldname.value;this.form.subject.value=document.$formname.subject.value;this.form.submit();" />
1.33      www      3033: </form>
                   3034: ENDPREVIEW
                   3035: }
1.71      www      3036: 
1.108     raeburn  3037: sub modify_attachments {
1.255     raeburn  3038:     my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls,
                   3039:         $attachmaxtext,$toolarge)=@_;
1.218     albertel 3040: 
1.220     raeburn  3041:     my %lt = &Apache::lonlocal::texthash(
                   3042:                'subj' => 'Subject',
                   3043:                'thfo' => 'The following attachments were part of the most recent saved version of this posting.',
                   3044:                'chth' => 'Check the checkboxes for any you wish to remove.',
                   3045:                'thef' => 'The following attachments have been uploaded for inclusion with this posting.',
                   3046:                'adda' => 'Add a new attachment to this post.',
1.247     albertel 3047:                'stch' => 'Save Changes',
1.220     raeburn  3048:              );
1.218     albertel 3049:     my $js = <<END;
                   3050: <script type="text/javascript">
                   3051:  function setAction () {
                   3052:    document.modattachments.action = document.modattachments.origpage.value;
                   3053:    document.modattachments.submit();
                   3054:  }
                   3055: </script> 
                   3056: END
                   3057: 
1.276     bisitz   3058:     # Breadcrumbs
                   3059:     my $brcrum = [{'href' => '',
                   3060:                    'text' => 'Discussion Post Attachments'}];
1.218     albertel 3061:     my $start_page = 
1.276     bisitz   3062: 	&Apache::loncommon::start_page('Discussion Post Attachments',$js,
                   3063:                                    {'bread_crumbs' => $brcrum,});
1.218     albertel 3064: 
1.204     www      3065:     my $orig_subject = &unescape($env{'form.subject'});
1.297     raeburn  3066:     my $subject=&clear_out_html($orig_subject);
1.108     raeburn  3067:     $subject=~s/\n/\<br \/\>/g;
                   3068:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.157     albertel 3069:     my $timestamp=$env{'form.timestamp'};
                   3070:     my $numoldver=$env{'form.numoldver'};
1.187     albertel 3071: 
1.108     raeburn  3072:     my $msg = '';
1.113     raeburn  3073:     my %attachments = ();
1.108     raeburn  3074:     my %currattach = ();
                   3075:     if ($idx) {
1.113     raeburn  3076:         &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108     raeburn  3077:     }
1.139     albertel 3078:     &Apache::lonenc::check_encrypt(\$symb);
1.187     albertel 3079: 
                   3080:     my $end_page = 
                   3081: 	&Apache::loncommon::end_page();
                   3082: 				       
                   3083:     $r->print(<<END);
1.198     albertel 3084: $start_page
1.255     raeburn  3085: $toolarge
1.108     raeburn  3086: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
1.255     raeburn  3087:  <br />
                   3088:  <table class="LC_data_table">
1.108     raeburn  3089:   <tr>
1.255     raeburn  3090:    <td colspan="2">
1.281     bisitz   3091:     <b>Subject:</b> <b>$subject</b><br /><br />
1.108     raeburn  3092: END
                   3093:     if ($idx) {
                   3094:         if ($attachmenturls) {
1.221     raeburn  3095:             my @currold = keys(%currattach);
1.108     raeburn  3096:             if (@currold > 0) {
1.220     raeburn  3097:                 $r->print($lt{'thfo'}.'<br />'.$lt{'chth'}.'<br />'."\n");  
1.113     raeburn  3098:                 foreach my $id (@currold) {
                   3099:                     my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'}); 
                   3100:                     $attachurl =~ m#/([^/]+)$#;
1.151     albertel 3101:                     $r->print('<label><input type="checkbox" name="deloldattach" value="'.$id.'" />&nbsp;'.$1.'</label><br />'."\n");
1.108     raeburn  3102:                 }
                   3103:                 $r->print("<br />");
                   3104:             }
                   3105:         }
                   3106:     }
1.213     raeburn  3107:     if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
1.220     raeburn  3108:         $r->print($lt{'thef'}.'<br />'.$lt{'chth'}.'<br />'."\n");
1.221     raeburn  3109:         foreach my $attach (@{$currnewattach}) {
                   3110:             $attach =~ m#/([^/]+)$#;
                   3111:             $r->print('<label><input type="checkbox" name="delnewattach" value="'.$attach.'" />&nbsp;'.$1.'</label><br />'."\n");
1.108     raeburn  3112:         }
                   3113:         $r->print("<br />"); 
                   3114:     }
                   3115:     $r->print(<<END);
1.255     raeburn  3116:    </td></tr>
                   3117:    <tr>
                   3118:     <td>
1.282     wenzelju 3119:    $lt{'adda'}</td><td><input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onclick="this.form.submit()" />    
1.108     raeburn  3120:    </td>
                   3121:   </tr>
1.255     raeburn  3122:   <tr>
                   3123:    <td colspan="2">$attachmaxtext</td>
                   3124:   </tr>
1.108     raeburn  3125:  </table>
1.157     albertel 3126: <input type="hidden" name="subject" value="$env{'form.subject'}" />
                   3127: <input type="hidden" name="comment" value="$env{'form.comment'}" />
                   3128: <input type="hidden" name="timestamp" value="$env{'form.timestamp'}" />
                   3129: <input type="hidden" name="idx" value="$env{'form.idx'}" />
                   3130: <input type="hidden" name="numoldver" value="$env{'form.numoldver'}" />
                   3131: <input type="hidden" name="origpage" value="$env{'form.origpage'}" />
1.175     www      3132: <input type="hidden" name="blog" value="$env{'form.blog'}" />
1.157     albertel 3133: <input type="hidden" name="discuss" value="$env{'form.discuss'}" />
1.108     raeburn  3134: END
1.220     raeburn  3135:     foreach my $item (@{$currnewattach}) {
                   3136:         $r->print('<input type="hidden" name="currnewattach" value="'.$item.'" />'."\n");
1.108     raeburn  3137:     }
1.220     raeburn  3138:     foreach my $item (@{$currdelold}) {
                   3139:         $r->print('<input type="hidden" name="deloldattach" value="'.$item.'" />'."\n");
1.108     raeburn  3140:     }
                   3141:     $r->print(<<END);
1.282     wenzelju 3142:  <input type="button" name="rtntoedit" value="$lt{'stch'}" onclick="setAction()" />
1.108     raeburn  3143: </form>
1.187     albertel 3144: $end_page
1.108     raeburn  3145: END
                   3146:     return;
                   3147: }
                   3148: 
                   3149: sub process_attachments {
                   3150:     my ($currnewattach,$currdelold,$keepold) = @_;
1.158     albertel 3151: 
                   3152:     @{$currnewattach}=
                   3153: 	&Apache::loncommon::get_env_multiple('form.currnewattach');
                   3154:     @{$currdelold}=
                   3155: 	&Apache::loncommon::get_env_multiple('form.deloldattach');
1.157     albertel 3156:     if (exists($env{'form.delnewattach'})) {
1.158     albertel 3157:         my @currdelnew =
                   3158: 	    &Apache::loncommon::get_env_multiple('form.delnewattach');
1.108     raeburn  3159:         my @currnew = ();
                   3160:         foreach my $newone (@{$currnewattach}) {
                   3161:             my $delflag = 0;
1.221     raeburn  3162:             foreach my $item (@currdelnew) {
                   3163:                 if ($newone eq $item) {
1.108     raeburn  3164:                     $delflag = 1;
                   3165:                     last;
                   3166:                 }
                   3167:             }
                   3168:             unless ($delflag) {
1.221     raeburn  3169:                 push(@currnew, $newone);
1.108     raeburn  3170:             }
                   3171:         }
                   3172:         @{$currnewattach} = @currnew;
                   3173:     }
1.158     albertel 3174:     @{$keepold} = &Apache::loncommon::get_env_multiple('form.keepold');
1.108     raeburn  3175: }
                   3176: 
                   3177: sub generate_attachments_button {
1.224     raeburn  3178:     my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,
                   3179:         $numoldver,$mode,$blockblog) = @_;
1.108     raeburn  3180:     my $origpage = $ENV{'REQUEST_URI'};
                   3181:     my $att=$attachnum.' '.&mt("attachments");
1.220     raeburn  3182:     my %lt = &Apache::lonlocal::texthash(
                   3183:                 'clic' => 'Click to add/remove attachments',
                   3184:     ); 
1.108     raeburn  3185:     my $response = (<<END);
1.205     raeburn  3186: <br />
1.108     raeburn  3187: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
1.220     raeburn  3188: $lt{'clic'}:&nbsp;<input type="button" value="$att"
1.282     wenzelju 3189: onclick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=escape(document.mailform.comment.value);this.form.subject.value=escape(document.mailform.subject.value);
1.108     raeburn  3190: END
1.224     raeburn  3191:     if (!$blockblog) {
                   3192:         $response .= 'setblogvalue();';
                   3193:     }
1.108     raeburn  3194:     unless ($mode eq 'board') {
                   3195:         $response .= 'javascript:anonchk();';
                   3196:     }
                   3197:     $response .= (<<ENDATTACH);
                   3198: this.form.submit();" />
                   3199: <input type="hidden" name="origpage" value="$origpage" />
                   3200: <input type="hidden" name="idx" value="$idx" />
                   3201: <input type="hidden" name="timestamp" value="$now" />
                   3202: <input type="hidden" name="subject" />
                   3203: <input type="hidden" name="comment" />
1.271     bisitz   3204: <input type="hidden" name="blog" value="0" />
                   3205: <input type="hidden" name="discuss" value="0" />
1.108     raeburn  3206: <input type="hidden" name="numoldver" value="$numoldver" />
                   3207: ENDATTACH
                   3208:     if (defined($deloldattach)) {
                   3209:         if (@{$deloldattach} > 0) {
1.221     raeburn  3210:             foreach my $delatt (@{$deloldattach}) {
                   3211:                 $response .= '<input type="hidden" name="deloldattach" value="'.$delatt.'" />'."\n";
1.108     raeburn  3212:             }
                   3213:         }
                   3214:     }
                   3215:     if (defined($currnewattach)) {
                   3216:         if (@{$currnewattach} > 0) {
1.221     raeburn  3217:             foreach my $attach (@{$currnewattach}) {
                   3218:                 $response .= '<input type="hidden" name="currnewattach" value="'.$attach.'" />'."\n";
1.108     raeburn  3219:             }
                   3220:         }
                   3221:     }
                   3222:     $response .= '</form>';
                   3223:     return $response;
                   3224: }
                   3225: 
                   3226: sub extract_attachments {
                   3227:     my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.116     raeburn  3228:     %{$attachments}=();
                   3229:     &get_post_attachments($attachments,$attachmenturls);
1.221     raeburn  3230:     foreach my $id (sort(keys(%{$attachments}))) {
1.116     raeburn  3231:         if (exists($$attachments{$id}{$numoldver})) {
                   3232:             if (defined($currdelold)) {
                   3233:                 if (@{$currdelold} > 0) {
                   3234:                     unless (grep/^$id$/,@{$currdelold}) {
                   3235:                         $$currattach{$id} = $$attachments{$id}{$numoldver}; 
1.108     raeburn  3236:                     }
1.113     raeburn  3237:                 } else {
                   3238:                     $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108     raeburn  3239:                 }
1.116     raeburn  3240:             } else {
                   3241:                 $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108     raeburn  3242:             }
                   3243:         }
1.116     raeburn  3244:     }
1.221     raeburn  3245:     my @attached = (sort { $a <=> $b } keys(%{$currattach}));
1.116     raeburn  3246:     if (@attached == 1) {
                   3247:         my $id = $attached[0];
                   3248:         my $attachurl;
                   3249:         if ($attachmenturls =~ m/^<attachment id="0">/) {
                   3250:             $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
                   3251:         } else {
                   3252:             $attachurl = $$attachments{$id}{'filename'};
                   3253:         }
                   3254:         $attachurl=~m|/([^/]+)$|;
                   3255:         $$message.='<br /><a href="'.$attachurl.'"><tt>'.
                   3256:         $1.'</tt></a><br />';
                   3257:         &Apache::lonnet::allowuploaded('/adm/feedback',
                   3258:                                $attachurl);
                   3259:     } elsif (@attached > 1) {
                   3260:         $$message.='<ol>';
1.221     raeburn  3261:         foreach my $attach (@attached) {
                   3262:             my $id = $attach;
1.113     raeburn  3263:             my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.116     raeburn  3264:             my ($fname)
                   3265:               =($attachurl=~m|/([^/]+)$|);
                   3266:             $$message .= '<li><a href="'.$attachurl.
                   3267:               '"><tt>'.
                   3268:               $fname.'</tt></a></li>';
1.108     raeburn  3269:             &Apache::lonnet::allowuploaded('/adm/feedback',
1.116     raeburn  3270:                              $attachurl);
1.108     raeburn  3271:         }
1.116     raeburn  3272:         $$message .= '</ol>';
1.108     raeburn  3273:     }
                   3274: }
                   3275: 
                   3276: sub construct_attachmenturl {
                   3277:     my ($currnewattach,$keepold,$symb,$idx)=@_;
                   3278:     my $oldattachmenturl;
                   3279:     my $newattachmenturl;
1.113     raeburn  3280:     my $startnum = 0;
1.108     raeburn  3281:     my $currver = 0;
1.157     albertel 3282:     if (($env{'form.editdisc'}) && ($idx)) {
                   3283:         my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                   3284:                        $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3285:                        $env{'course.'.$env{'request.course.id'}.'.num'});
1.108     raeburn  3286:         $oldattachmenturl = $contrib{$idx.':attachmenturl'};
                   3287:         if ($contrib{$idx.':history'}) {
                   3288:             if ($contrib{$idx.':history'} =~ /:/) {
1.221     raeburn  3289:                 my @oldversions = split(/:/,$contrib{$idx.':history'});
1.108     raeburn  3290:                 $currver = 1 + scalar(@oldversions);
                   3291:             } else {
                   3292:                 $currver = 2;
                   3293:             }
                   3294:         } else {
                   3295:             $currver = 1;
                   3296:         }
                   3297:         if ($oldattachmenturl) {
1.113     raeburn  3298:             if ($oldattachmenturl =~ m/^<attachment id="0">/) {
                   3299:                 my %attachments = ();
                   3300:                 my $prevver = $currver-1;
                   3301:                 &get_post_attachments(\%attachments,$oldattachmenturl);
1.221     raeburn  3302:                 my $numattach = scalar(keys(%attachments));
1.113     raeburn  3303:                 $startnum += $numattach;
1.221     raeburn  3304:                 foreach my $num (sort {$a <=> $b} keys(%attachments)) {
1.113     raeburn  3305:                     $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
1.221     raeburn  3306:                     foreach my $item (sort {$a <=> $b} keys(%{$attachments{$num}})) {
                   3307:                         unless ($item eq 'filename') {
                   3308:                             $newattachmenturl .= '<post id="'.$item.'">'.$attachments{$num}{$item}.'</post>';
1.116     raeburn  3309:                         }
1.113     raeburn  3310:                     }
                   3311:                     if (grep/^$num$/,@{$keepold}) {
                   3312:                         $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108     raeburn  3313:                     }
1.113     raeburn  3314:                     $newattachmenturl .= '</attachment>';
1.108     raeburn  3315:                 }
                   3316:             } else {
1.116     raeburn  3317:                 $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
1.108     raeburn  3318:                 unless (grep/^0$/,@{$keepold}) {
1.113     raeburn  3319:                     $newattachmenturl .= '<post id="1">n</post>';
1.108     raeburn  3320:                 }
1.113     raeburn  3321:                 $newattachmenturl .= '</attachment>';
1.108     raeburn  3322:                 $startnum ++;
                   3323:             }
                   3324:         }
                   3325:     }
                   3326:     for (my $i=0; $i<@{$currnewattach}; $i++) {
                   3327:         my $attachnum = $startnum + $i;
1.113     raeburn  3328:         $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108     raeburn  3329:     }
                   3330:     return $newattachmenturl; 
                   3331: }
1.128     raeburn  3332: 
1.224     raeburn  3333: sub add_blog_checkbox {
1.278     raeburn  3334:     my ($crstype) = @_;
                   3335:     my $checkstatus;
1.224     raeburn  3336:     if ($env{'form.blog'}) {
                   3337:         $checkstatus = 'checked="checked"';
                   3338:     }
                   3339:     my $output = '
                   3340: <script type="text/javascript">
                   3341: function setblogvalue() {
                   3342:     if (document.mailform.blog.checked) {
                   3343:         document.attachment.blog.value = 1;
                   3344:     } else {
                   3345:         document.attachment.blog.value = 0;
                   3346:     }
                   3347: }
                   3348: </script><br />
1.278     raeburn  3349: <label><input type="checkbox" name="blog" '.$checkstatus.' /> ';
                   3350:     if ($crstype eq 'Community') {
                   3351:         $output .= &mt('Add to my public community blog');
                   3352:     } else {
                   3353:         $output .= &mt('Add to my public course blog');
                   3354:     } 
                   3355:     $output .= '</label><br />'."\n";
1.224     raeburn  3356:     return $output;
                   3357: }
                   3358: 
1.128     raeburn  3359: sub has_discussion {
                   3360:     my $resourcesref = shift;
                   3361:     my $navmap = Apache::lonnavmaps::navmap->new();
1.260     raeburn  3362:     if (defined($navmap)) {
                   3363:         my @allres=$navmap->retrieveResources();
                   3364:         foreach my $resource (@allres) {
                   3365:             if ($resource->hasDiscussion()) {
                   3366:                 my $ressymb = $resource->wrap_symb();
                   3367:                 if (ref($resourcesref) eq 'ARRAY') {
                   3368:                     push(@{$resourcesref}, $ressymb);
                   3369:                 }
                   3370:             }
1.128     raeburn  3371:         }
1.260     raeburn  3372:     } else {
                   3373:         &Apache::lonnet::logthis('Has discussion check failed - could not create navmap object.');
1.128     raeburn  3374:     }
                   3375:     return;
1.143     raeburn  3376: }
                   3377: 
                   3378: sub sort_filter_names {
1.278     raeburn  3379:     my ($sort_types,$role_types,$status_types,$crstype) = @_;
                   3380:     if (ref($sort_types) eq 'HASH') {
                   3381:         %{$sort_types} = (
1.143     raeburn  3382:                      ascdate => 'Date order - oldest first',
                   3383:                      descdate => 'Date order - newest first',
                   3384:                      thread => 'Threaded',
                   3385:                      subject => 'By subject',
                   3386:                      username => 'By domain and username',
                   3387:                      lastfirst => 'By last name, first name'
                   3388:                    );
1.278     raeburn  3389:     }
                   3390:     my @courseroles = qw(st in ta ep ad);
                   3391:     if ($crstype eq 'Community') {
                   3392:         push(@courseroles,'co');
                   3393:     } else {
                   3394:         push(@courseroles,'cc');
                   3395:     }
                   3396:     if (ref($role_types) eq 'HASH') {
                   3397:         foreach my $role (@courseroles) {
                   3398:             $role_types->{$role} = &Apache::lonnet::plaintext($role,$crstype);
                   3399:         }
                   3400:         $role_types->{'all'} = 'All roles';
                   3401:         $role_types->{'cr'} = 'Custom role';
                   3402:     }
                   3403:     if (ref($status_types) eq 'HASH') {
                   3404:         %{$status_types} = (
1.143     raeburn  3405:                      all     => 'Roles of any status',
1.214     albertel 3406:                      Active  => 'Only active roles',
                   3407:                      Expired => 'Only past roles',
                   3408:                      Future  => 'Only future roles',
1.143     raeburn  3409:                    );
1.278     raeburn  3410:     }
1.143     raeburn  3411: }
1.108     raeburn  3412:   
1.6       albertel 3413: sub handler {
                   3414:   my $r = shift;
1.8       www      3415:   if ($r->header_only) {
1.71      www      3416:      &Apache::loncommon::content_type($r,'text/html');
1.8       www      3417:      $r->send_http_header;
                   3418:      return OK;
                   3419:   }
1.15      www      3420: 
                   3421: # --------------------------- Get query string for limited number of parameters
                   3422: 
1.97      raeburn  3423:   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.208     raeburn  3424:          ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']);
                   3425:   my $group = $env{'form.group'};
1.255     raeburn  3426:   my %attachmax = (
1.268     bisitz   3427:                     text => &mt('(128 KB max size)'),
1.255     raeburn  3428:                     num  => 131072,
                   3429:                   );
1.180     raeburn  3430:   if ($env{'form.editdisc'}) {
1.208     raeburn  3431:       if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) {
1.180     raeburn  3432:           my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
                   3433:           my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
                   3434:           my $feedurl=&Apache::lonnet::clutter($url);
1.208     raeburn  3435:           &redirect_back($r,$feedurl,&mt('Editing not permitted').'<br />',                     '0','0','','',$env{'form.previous'},undef,undef,undef,
                   3436:                     undef,undef,undef,$group);
1.180     raeburn  3437:           return OK;
                   3438:       }
                   3439:   } 
1.157     albertel 3440:   if ($env{'form.discsymb'}) {
                   3441:       my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.discsymb'});
1.111     raeburn  3442:       my $readkey = $symb.'_read';
                   3443:       my $chgcount = 0;
1.157     albertel 3444:       my %readinghash = &Apache::lonnet::get('nohist_'.$env{'request.course.id'}.'_discuss',[$readkey],$env{'user.domain'},$env{'user.name'});
1.221     raeburn  3445:       foreach my $key (keys(%env)) {
1.111     raeburn  3446:           if ($key =~ m/^form\.postunread_(\d+)/) {
                   3447:               if ($readinghash{$readkey} =~ /\.$1\./) {
                   3448:                   $readinghash{$readkey} =~ s/\.$1\.//;
                   3449:                   $chgcount ++;
                   3450:               }
                   3451:           } elsif ($key =~ m/^form\.postread_(\d+)/) {
                   3452:               unless ($readinghash{$readkey} =~ /\.$1\./) {
                   3453:                   $readinghash{$readkey} .= '.'.$1.'.';
                   3454:                   $chgcount ++;
                   3455:               }
                   3456:           }
                   3457:       }
                   3458:       if ($chgcount > 0) {
1.157     albertel 3459:           &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
                   3460: 			  \%readinghash,$env{'user.domain'},$env{'user.name'});
1.111     raeburn  3461:       }
1.133     albertel 3462:       &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />',
1.208     raeburn  3463: 		     '0','0','','',$env{'form.previous'},'','','',
                   3464:                      undef,undef,undef,$group);
1.111     raeburn  3465:       return OK;
                   3466:   }
1.157     albertel 3467:   if ($env{'form.allversions'}) {
1.109     raeburn  3468:       &Apache::loncommon::content_type($r,'text/html');
1.187     albertel 3469:       &Apache::loncommon::no_cache($r);
1.109     raeburn  3470:       $r->send_http_header;
1.187     albertel 3471: 
1.276     bisitz   3472:       # Breadcrumbs
                   3473:       my $brcrum = [{'href' => '',
                   3474:                      'text' => 'Discussion Post Versions'}];
                   3475: 
                   3476:       $r->print(&Apache::loncommon::start_page('Discussion Post Versions',undef,
                   3477:                                                {'bread_crumbs' => $brcrum,})
                   3478:       );
1.187     albertel 3479: 
1.157     albertel 3480:       my $crs='/'.$env{'request.course.id'};
                   3481:       if ($env{'request.course.sec'}) {
                   3482:           $crs.='_'.$env{'request.course.sec'};
1.109     raeburn  3483:       }
1.133     albertel 3484:       $crs=~s|_|/|g;
1.208     raeburn  3485:       my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   3486:       my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.157     albertel 3487:       my ($symb,$idx)=split(/\:\:\:/,$env{'form.allversions'});
1.133     albertel 3488:       ($symb)=&get_feedurl_and_clean_symb($symb);
1.208     raeburn  3489:       my $ressymb = &wrap_symb($symb);
                   3490:       my $group = $env{'form.group'};
                   3491:       my $seeid;
                   3492:       if (($group ne '') && (($ressymb =~ m|^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|))) {
                   3493:           if (&check_group_priv($group,'dgp') eq 'ok') {
                   3494:               $seeid = 1;
                   3495:           }
                   3496:       } else {
                   3497:           $seeid = &Apache::lonnet::allowed('rin',$crs);
                   3498:       }
1.109     raeburn  3499:       if ($idx > 0) {
1.116     raeburn  3500:           my %messages = ();
                   3501:           my %subjects = ();
                   3502:           my %attachmsgs = ();
                   3503:           my %allattachments = ();
                   3504:           my %imsfiles = ();
                   3505:           my ($screenname,$plainname);
1.157     albertel 3506:           my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                   3507:                            $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3508:                            $env{'course.'.$env{'request.course.id'}.'.num'});
1.133     albertel 3509:           $r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname));
1.109     raeburn  3510:       }
1.187     albertel 3511:       $r->print(&Apache::loncommon::end_page());
1.109     raeburn  3512:       return OK;
                   3513:   }
1.157     albertel 3514:   if ($env{'form.posterlist'}) {
                   3515:       my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
                   3516:       &print_showposters($r,$symb,$env{'form.previous'},$feedurl,
                   3517: 			 $env{'form.sortposts'});
1.101     raeburn  3518:       return OK;
                   3519:   }
1.157     albertel 3520:   if ($env{'form.userpick'}) {
1.133     albertel 3521:       my @posters = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.157     albertel 3522:       my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.userpick'});
1.101     raeburn  3523:       my $numpicks = @posters;
1.133     albertel 3524:       my %discinfo;
                   3525:       $discinfo{$symb.'_userpick'} = join('&',@posters);
1.157     albertel 3526:       &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
                   3527: 			   \%discinfo,$env{'user.domain'},$env{'user.name'});
1.175     www      3528:       &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',
1.157     albertel 3529: 		     '',$env{'form.previous'},$env{'form.sortposts'},'','','',
1.208     raeburn  3530: 		     '',$numpicks,$group);
1.101     raeburn  3531:       return OK;
                   3532:   }
1.157     albertel 3533:   if ($env{'form.applysort'}) {
                   3534:       my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
1.175     www      3535:       &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',
1.157     albertel 3536: 		     '',$env{'form.previous'},$env{'form.sortposts'},
                   3537: 		     $env{'form.rolefilter'},$env{'form.statusfilter'},
1.208     raeburn  3538: 		     $env{'form.sectionpick'},$env{'form.grouppick'},
                   3539:                      undef,$group);
1.100     raeburn  3540:       return OK;
1.157     albertel 3541:   } elsif ($env{'form.cmd'} eq 'sortfilter') {
                   3542:       my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
                   3543:       &print_sortfilter_options($r,$symb,$env{'form.previous'},$feedurl);
1.100     raeburn  3544:       return OK;
1.157     albertel 3545:   } elsif ($env{'form.navtime'}) {
1.99      raeburn  3546:       my %discinfo = ();
                   3547:       my @resources = ();
1.157     albertel 3548:       if (defined($env{'form.navmaps'})) {
                   3549:           if ($env{'form.navmaps'} =~ /:/) {
1.221     raeburn  3550:               @resources = split(/:/,$env{'form.navmaps'});
1.128     raeburn  3551:           } else {
1.157     albertel 3552:               @resources = ("$env{'form.navmaps'}");
1.128     raeburn  3553:           }
1.99      raeburn  3554:       } else {
1.128     raeburn  3555:           &has_discussion(\@resources);
1.99      raeburn  3556:       }
                   3557:       my $numitems = @resources;
                   3558:       my $feedurl = '/adm/navmaps';
1.157     albertel 3559:       if ($env{'form.navurl'}) { $feedurl .= '?'.$env{'form.navurl'}; }
1.99      raeburn  3560:       my %lt = &Apache::lonlocal::texthash(
                   3561:           'mnpa' => 'Marked "New" posts as read in a total of',
1.128     raeburn  3562:           'robb' => 'resources/bulletin boards.',
1.264     schafran 3563:           'twnp' => 'There are currently no resources or discussion boards with unread discussion postings.'
1.99      raeburn  3564:       );       
1.221     raeburn  3565:       foreach my $res (@resources) {
                   3566:           my $ressymb=$res;
1.132     albertel 3567: 	  &Apache::lonenc::check_decrypt(\$ressymb);
1.99      raeburn  3568:           my $lastkey = $ressymb.'_lastread';
1.157     albertel 3569:           $discinfo{$lastkey} = $env{'form.navtime'};
1.99      raeburn  3570:       }
1.128     raeburn  3571:       my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
                   3572:       if ($numitems > 0) {
1.157     albertel 3573:           &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
                   3574: 			     \%discinfo,$env{'user.domain'},$env{'user.name'});
1.128     raeburn  3575:       } else {
                   3576:           $textline = "<b>$lt{'twnp'}</b>";
                   3577:       }
1.99      raeburn  3578:       &Apache::loncommon::content_type($r,'text/html');
                   3579:       $r->send_http_header;
1.150     albertel 3580:       my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.200     albertel 3581:       my %onload;
                   3582: 
1.186     albertel 3583:       my $start_page=
                   3584: 	  &Apache::loncommon::start_page('New posts marked as read',undef,
                   3585: 					 {'redirect'    => [2,$feedurl],
                   3586: 					  'only_body'   => 1,
1.189     albertel 3587: 					  'add_entries' => \%onload});
1.186     albertel 3588:       my $end_page = &Apache::loncommon::end_page();
1.99      raeburn  3589:       $r->print (<<ENDREDIR);
1.186     albertel 3590: $start_page
1.150     albertel 3591: <img align="right" src="$logo" />
1.128     raeburn  3592: $textline
1.99      raeburn  3593: <form name="reldt" action="$feedurl" target="loncapaclient">
                   3594: </form>
1.187     albertel 3595: <br />
1.186     albertel 3596: $end_page
1.99      raeburn  3597: ENDREDIR
                   3598:       return OK;
1.157     albertel 3599:   } elsif ($env{'form.modifydisp'}) {
                   3600:       my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.modifydisp'});
1.133     albertel 3601:       my ($dispchgA,$dispchgB,$markchg,$toggchg) = 
1.157     albertel 3602: 	  split(/_/,$env{'form.changes'});
                   3603:       &print_display_options($r,$symb,$env{'form.previous'},$dispchgA,
1.133     albertel 3604: 			     $dispchgB,$markchg,$toggchg,$feedurl);
1.97      raeburn  3605:       return OK;
1.157     albertel 3606:   } elsif ($env{'form.markondisp'} || $env{'form.markonread'} ||
                   3607: 	   $env{'form.allposts'}   || $env{'form.onlyunread'} ||
                   3608: 	   $env{'form.onlyunmark'} || $env{'form.toggoff'}    ||
                   3609: 	   $env{'form.toggon'}     || $env{'form.markread'}) {
                   3610:       my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
1.137     albertel 3611:       my %discinfo;
1.133     albertel 3612: # ------------------------ Modify setting for read/unread toggle for each post 
1.157     albertel 3613:       if ($env{'form.toggoff'}) { $discinfo{$symb.'_readtoggle'}=0; }
                   3614:       if ($env{'form.toggon'})  { $discinfo{$symb.'_readtoggle'}=1; }
1.133     albertel 3615: # --------- Modify setting for identification of 'NEW' posts in this discussion
1.157     albertel 3616:       if ($env{'form.markondisp'}) {
1.137     albertel 3617: 	  $discinfo{$symb.'_lastread'} = time;
                   3618: 	  $discinfo{$symb.'_markondisp'} = 1;
                   3619:       }
1.157     albertel 3620:       if ($env{'form.markonread'}) {
                   3621: 	  if ( $env{'form.previous'} > 0 ) {
                   3622: 	      $discinfo{$symb.'_lastread'} = $env{'form.previous'};
1.137     albertel 3623: 	  }
                   3624: 	  $discinfo{$symb.'_markondisp'} = 0;
1.84      raeburn  3625:       }
1.133     albertel 3626: # --------------------------------- Modify display setting for this discussion 
1.157     albertel 3627:       if ($env{'form.allposts'}) {
1.137     albertel 3628: 	  $discinfo{$symb.'_showonlyunread'} = 0;
                   3629: 	  $discinfo{$symb.'_showonlyunmark'} = 0;
1.84      raeburn  3630:       }
1.157     albertel 3631:       if ($env{'form.onlyunread'}) { $discinfo{$symb.'_showonlyunread'} = 1;  }
                   3632:       if ($env{'form.onlyunmark'}) { $discinfo{$symb.'_showonlyunmark'} = 1;  }
1.137     albertel 3633: # ----------------------------------------------------- Mark new posts not NEW 
1.157     albertel 3634:       if ($env{'form.markread'})   { $discinfo{$symb.'_lastread'} = time; }
                   3635:       &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
                   3636: 			   \%discinfo,$env{'user.domain'},$env{'user.name'});
                   3637:       my $previous=$env{'form.previous'};
                   3638:       if ($env{'form.markondisp'}) { $previous=undef; }
1.133     albertel 3639:       &redirect_back($r,$feedurl,&mt('Changed display status').'<br />',
1.208     raeburn  3640: 		     '0','0','','',$previous,'','','','','','',$group);
1.84      raeburn  3641:       return OK;
1.157     albertel 3642:   } elsif (($env{'form.hide'}) || ($env{'form.unhide'})) {
1.15      www      3643: # ----------------------------------------------------------------- Hide/unhide
1.157     albertel 3644:       my $entry=$env{'form.hide'}?$env{'form.hide'}:$env{'form.unhide'};
1.133     albertel 3645:       my ($symb,$idx)=split(/\:\:\:/,$entry);
                   3646:       ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.15      www      3647: 
1.180     raeburn  3648:       my $crs='/'.$env{'request.course.id'};
                   3649:       if ($env{'request.course.sec'}) {
                   3650:           $crs.='_'.$env{'request.course.sec'};
                   3651:       }
                   3652:       $crs=~s/\_/\//g;
                   3653:       my $seeid=&Apache::lonnet::allowed('rin',$crs);
                   3654: 
1.208     raeburn  3655:       if ($env{'form.hide'} && !$seeid && !(&editing_allowed($env{'form.hide'},$env{'form.group'}))) {
                   3656:           &redirect_back($r,$feedurl,&mt('Deletion not permitted').'<br />',                 '0','0','','',$env{'form.previous'},'','','','',
                   3657:                  undef,undef,$group,);
1.180     raeburn  3658:           return OK;
                   3659:       }
                   3660: 
1.157     albertel 3661:       my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                   3662:                           $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3663: 		          $env{'course.'.$env{'request.course.id'}.'.num'});
1.15      www      3664: 
1.133     albertel 3665:       my $currenthidden=$contrib{'hidden'};
                   3666:       my $currentstudenthidden=$contrib{'studenthidden'};
1.15      www      3667: 
1.157     albertel 3668:       if ($env{'form.hide'}) {
1.133     albertel 3669: 	  $currenthidden.='.'.$idx.'.';
                   3670: 	  unless ($seeid) {
                   3671: 	      $currentstudenthidden.='.'.$idx.'.';
                   3672: 	  }
                   3673:       } else {
                   3674: 	  $currenthidden=~s/\.$idx\.//g;
                   3675:       }
                   3676:       my %newhash=('hidden' => $currenthidden);
1.157     albertel 3677:       if ( ($env{'form.hide'}) && (!$seeid) ) {
1.133     albertel 3678: 	  $newhash{'studenthidden'} = $currentstudenthidden;
                   3679:       }
1.231     raeburn  3680:       if ($env{'form.hide'}) {
                   3681:           my $changelast = 0;
                   3682:           my $newlast;
                   3683:           ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
                   3684:           if ($changelast) {
                   3685:               &Apache::lonnet::put('discussiontimes',{$symb => $newlast},
                   3686:                      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3687:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   3688:           }
                   3689:       }
1.157     albertel 3690:       &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
                   3691:                            $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3692: 			   $env{'course.'.$env{'request.course.id'}.'.num'});
1.38      www      3693: 
1.133     albertel 3694:       &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
1.208     raeburn  3695: 		     '0','0','','',$env{'form.previous'},undef,undef,undef,
                   3696:                      undef,undef,undef,$group);
1.135     albertel 3697:       return OK;
1.157     albertel 3698:   } elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) {
                   3699:       my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
                   3700:       if ($env{'form.cmd'} eq 'threadedon') {
1.69      www      3701: 	  &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
1.253     raeburn  3702: 	  &Apache::lonnet::appenv({'environment.threadeddiscussion' => 'on'});
1.69      www      3703:       } else {
                   3704:  	  &Apache::lonnet::del('environment',['threadeddiscussion']);
1.265     raeburn  3705: 	  &Apache::lonnet::delenv('environment.threadeddiscussion');
1.72      albertel 3706:       }
1.133     albertel 3707:       &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'<br />',
1.208     raeburn  3708: 		     '0','0','','',$env{'form.previous'},undef,undef,undef,
                   3709:                      undef,undef,undef,$group);
1.135     albertel 3710:       return OK;
1.157     albertel 3711:   } elsif ($env{'form.deldisc'}) {
1.38      www      3712: # --------------------------------------------------------------- Hide for good
1.157     albertel 3713:       my ($symb,$idx)=split(/\:\:\:/,$env{'form.deldisc'});
1.133     albertel 3714:       ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.157     albertel 3715:       my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                   3716:                           $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3717: 		          $env{'course.'.$env{'request.course.id'}.'.num'});
1.231     raeburn  3718:       my ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
                   3719:       if ($changelast) {
                   3720:           &Apache::lonnet::put('discussiontimes',{$symb => $newlast},
                   3721:                    $env{'course.'.$env{'request.course.id'}.'.domain'},                   $env{'course.'.$env{'request.course.id'}.'.num'});
                   3722:       }
1.135     albertel 3723:       my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
1.157     albertel 3724:       &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
                   3725: 			   $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3726: 			   $env{'course.'.$env{'request.course.id'}.'.num'});
1.135     albertel 3727:       &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
1.208     raeburn  3728: 		     '0','0','','',$env{'form.previous'},undef,undef,undef,
                   3729:                      undef,undef,undef,$group);
1.135     albertel 3730:       return OK;
1.157     albertel 3731:   } elsif ($env{'form.preview'}) {
1.33      www      3732: # -------------------------------------------------------- User wants a preview
                   3733:       &show_preview($r);
1.135     albertel 3734:       return OK;
1.157     albertel 3735:   } elsif ($env{'form.attach'}) {
1.108     raeburn  3736: # -------------------------------------------------------- Work on attachments
                   3737:       &Apache::loncommon::content_type($r,'text/html');
                   3738:       $r->send_http_header;
1.198     albertel 3739:       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','discuss','blog']);
1.255     raeburn  3740:       my (@currnewattach,@currdelold,@keepold,$toolarge);
1.108     raeburn  3741:       &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1.157     albertel 3742:       if (exists($env{'form.addnewattach.filename'})) {
1.255     raeburn  3743:           if (length($env{'form.addnewattach'})<=$attachmax{'num'}) {
1.157     albertel 3744:               my $subdir = 'feedback/'.$env{'form.timestamp'};
1.108     raeburn  3745:               my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
1.221     raeburn  3746: 	      push(@currnewattach, $newattachment);
1.255     raeburn  3747:           } else {
                   3748:               $toolarge = '<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>';
1.108     raeburn  3749:           }
                   3750:       }
1.133     albertel 3751:       my $attachmenturls;
1.157     albertel 3752:       my ($symb) = &get_feedurl_and_clean_symb($env{'form.attach'});
                   3753:       my $idx = $env{'form.idx'};
1.108     raeburn  3754:       if ($idx) {
1.157     albertel 3755:           my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                   3756:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3757:                          $env{'course.'.$env{'request.course.id'}.'.num'});
1.108     raeburn  3758:           $attachmenturls = $contrib{$idx.':attachmenturl'};
                   3759:       }
1.133     albertel 3760:       &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
1.255     raeburn  3761: 			  $attachmenturls,$attachmax{'text'},$toolarge);
1.135     albertel 3762:       return OK;
1.157     albertel 3763:   } elsif ($env{'form.export'}) {
1.116     raeburn  3764:       &Apache::loncommon::content_type($r,'text/html');
                   3765:       $r->send_http_header;
1.157     albertel 3766:       my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.export'});
1.133     albertel 3767:       my $mode='board';
1.116     raeburn  3768:       my $status='OPEN';
1.157     albertel 3769:       my $previous=$env{'form.previous'};
1.168     albertel 3770:       if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library|task)$/) {
1.116     raeburn  3771:           $mode='problem';
                   3772:           $status=$Apache::inputtags::status[-1];
                   3773:       }
                   3774:       my $discussion = &list_discussion($mode,$status,$symb); 
1.188     albertel 3775:       my $start_page = 
                   3776: 	  &Apache::loncommon::start_page('Resource Feedback and Discussion');
                   3777:       my $end_page = 
                   3778: 	  &Apache::loncommon::end_page();
                   3779:       $r->print($start_page.$discussion.$end_page);
1.116     raeburn  3780:       return OK;
1.15      www      3781:   } else {
                   3782: # ------------------------------------------------------------- Normal feedback
1.157     albertel 3783:       my $feedurl=$env{'form.postdata'};
1.260     raeburn  3784:       $feedurl=~s/^https?\:\/\///;
1.133     albertel 3785:       $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                   3786:       $feedurl=~s/^$ENV{'HTTP_HOST'}//;
                   3787:       $feedurl=~s/\?.+$//;
1.8       www      3788: 
1.133     albertel 3789:       my $symb;
1.157     albertel 3790:       if ($env{'form.replydisc'}) {
                   3791: 	  $symb=(split(/\:\:\:/,$env{'form.replydisc'}))[0];
                   3792:       } elsif ($env{'form.editdisc'}) {
                   3793: 	  $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
                   3794:       } elsif ($env{'form.origpage'}) {
1.133     albertel 3795: 	  $symb=""; 
                   3796:       } else {
                   3797: 	  $symb=&Apache::lonnet::symbread($feedurl);
                   3798:       }
                   3799:       unless ($symb) {
1.157     albertel 3800: 	  $symb=$env{'form.symb'};
1.133     albertel 3801:       }
1.237     raeburn  3802:       if (defined($symb)) {
                   3803:           ($symb,$feedurl)=&get_feedurl_and_clean_symb($symb);
                   3804:       } else {
                   3805:           # backward compatibility (bulletin boards used to be 'wrapped')
                   3806:           &Apache::lonenc::check_decrypt(\$feedurl);
                   3807:           &dewrapper(\$feedurl);
                   3808:       }
1.133     albertel 3809:       my $goahead=1;
1.168     albertel 3810:       if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.133     albertel 3811: 	  unless ($symb) { $goahead=0; }
                   3812:       }
                   3813:       if (!$goahead) {
                   3814:           # Ambiguous Problem Resource
                   3815: 	  $r->internal_redirect('/adm/ambiguous');
                   3816: 	  return OK;
1.31      www      3817:       }
1.8       www      3818: # Go ahead with feedback, no ambiguous reference
1.133     albertel 3819:       unless (
                   3820: 	  (
                   3821: 	   ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
                   3822: 	   ) 
                   3823: 	  || 
1.157     albertel 3824: 	  ($env{'request.course.id'} && ($feedurl!~m:^/adm:))
1.133     albertel 3825: 	  ||
1.157     albertel 3826: 	  ($env{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.133     albertel 3827: 	  ) {
1.135     albertel 3828: 	  &Apache::loncommon::content_type($r,'text/html');
                   3829: 	  $r->send_http_header;
1.133     albertel 3830: # Unable to give feedback
1.233     raeburn  3831:           &Apache::lonenc::check_encrypt(\$feedurl);
1.133     albertel 3832: 	  &no_redirect_back($r,$feedurl);
1.178     albertel 3833: 	  return OK;
1.133     albertel 3834:       }
1.6       albertel 3835: # --------------------------------------------------- Print login screen header
1.157     albertel 3836:       unless ($env{'form.sendit'}) {
1.233     raeburn  3837:           &Apache::lonenc::check_encrypt(\$feedurl);
1.135     albertel 3838: 	  &Apache::loncommon::content_type($r,'text/html');
                   3839: 	  $r->send_http_header;
1.234     raeburn  3840:           if (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
1.235     raeburn  3841:               my ($blocked,$blocktext) = 
                   3842:                      &Apache::loncommon::blocking_status('boards');
1.234     raeburn  3843:               if ($blocked) {
                   3844:                   $r->print(&blocked_reply_or_edit($blocktext));
                   3845:                   return OK;
                   3846:               }
                   3847:           }
1.141     raeburn  3848: 	  my $options=&screen_header($feedurl,$symb);
1.133     albertel 3849: 	  if ($options) {
1.255     raeburn  3850: 	      &mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'});
1.133     albertel 3851: 	  } else {
                   3852: 	      &fail_redirect($r,$feedurl);
                   3853: 	  }
                   3854: 	  return OK;
1.6       albertel 3855:       }
                   3856:       
                   3857: # Get previous user input
1.9       albertel 3858:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.157     albertel 3859:                                    $symb,$env{'user.name'},$env{'user.domain'},
                   3860: 				   $env{'request.course.id'});
1.6       albertel 3861: 
                   3862: # Get output from resource
1.237     raeburn  3863:       &Apache::lonenc::check_encrypt(\$feedurl);
1.6       albertel 3864:       my $usersaw=&resource_output($feedurl);
                   3865: 
1.50      albertel 3866: # Get resource answer (need to allow student to view grades for this to work)
1.253     raeburn  3867:       &Apache::lonnet::appenv({'allowed.vgr'=>'F'});
1.238     raeburn  3868:       my $usersymb = &Apache::lonenc::check_encrypt($symb);
1.237     raeburn  3869:       my $useranswer=
                   3870:           &Apache::loncommon::get_student_answers(
1.238     raeburn  3871:               $usersymb,$env{'user.name'},$env{'user.domain'},
1.237     raeburn  3872:               $env{'request.course.id'});
1.50      albertel 3873:       &Apache::lonnet::delenv('allowed.vgr');
1.42      www      3874: # Get attachments, if any, and not too large
                   3875:       my $attachmenturl='';
1.255     raeburn  3876:       my $toolarge='';
1.157     albertel 3877:       if (($env{'form.origpage'}) || ($env{'form.editdisc'}) ||
                   3878: 	  ($env{'form.replydisc'})) {
1.133     albertel 3879: 	  my ($symb,$idx);
1.157     albertel 3880: 	  if ($env{'form.replydisc'}) {
                   3881: 	      ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
                   3882: 	  } elsif ($env{'form.editdisc'}) {
                   3883: 	      ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
                   3884: 	  } elsif ($env{'form.origpage'}) {
                   3885: 	      $symb = $env{'form.symb'};
1.133     albertel 3886: 	  }
1.132     albertel 3887: 	  &Apache::lonenc::check_decrypt(\$symb);
1.133     albertel 3888: 	  my @currnewattach = ();
                   3889: 	  my @deloldattach = ();
                   3890: 	  my @keepold = ();
                   3891: 	  &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
                   3892: 	  $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
                   3893: 	  $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
1.157     albertel 3894:       } elsif ($env{'form.attachment.filename'}) {
1.255     raeburn  3895: 	  if (length($env{'form.attachment'})<=$attachmax{'num'}) {
                   3896:               my $now = time;
                   3897:               my $subdir = 'feedback/'.$now;
                   3898: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,$subdir);
                   3899: 	  } else {
                   3900:               $toolarge = '<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>';
                   3901:           }
1.42      www      3902:       }
1.6       albertel 3903: # Filter HTML out of message (could be nasty)
1.157     albertel 3904:       my $message=&clear_out_html($env{'form.comment'});
1.6       albertel 3905: 
                   3906: # Assemble email
1.237     raeburn  3907:       my ($email,$citations)=&assemble_email($message,$prevattempts,
1.133     albertel 3908: 					     $usersaw,$useranswer);
1.40      albertel 3909:  
1.6       albertel 3910: # Who gets this?
1.242     albertel 3911:       my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl);
1.6       albertel 3912: 
                   3913: # Actually send mail
1.297     raeburn  3914:       my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}),
1.194     albertel 3915: 				      $feedurl,$email,$citations,
1.240     raeburn  3916: 				      $attachmenturl,$usersymb,%to);
1.13      www      3917: 
                   3918: # Discussion? Store that.
1.32      albertel 3919:       my $numpost=0;
1.207     albertel 3920:       if (  ($env{'form.discuss'} ne ''
                   3921: 	     && $env{'form.discuss'} !~ /^(?:author|question|course|policy)/)
                   3922: 	   || $env{'form.anondiscuss'} ne '') {
1.297     raeburn  3923: 	  my $subject = &clear_out_html($env{'form.subject'});
1.201     albertel 3924: 	  my $anonmode=($env{'form.discuss'} eq 'anon' || $env{'form.anondiscuss'} );
1.133     albertel 3925: 	  $typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl,
                   3926: 				  $subject);
1.32      albertel 3927: 	  $numpost++;
1.14      www      3928:       }
1.175     www      3929: 
                   3930: # Add to blog?
                   3931: 
                   3932:       my $blog='';
                   3933:       if ($env{'form.blog'}) {
1.297     raeburn  3934: 	  my $subject = &clear_out_html($env{'form.subject'});
1.175     www      3935: 	  $status.=&Apache::lonrss::addentry($env{'user.name'},
                   3936: 				    $env{'user.domain'},
                   3937: 				    'CourseBlog_'.$env{'request.course.id'},
                   3938: 				    $subject,$message,$feedurl,'public');
1.278     raeburn  3939:           if (&Apache::loncommon::course_type() eq 'Community') {
                   3940:               $blog='<br />'.&mt('Added to my community blog').'<br />';
                   3941:           } else {
                   3942: 	      $blog='<br />'.&mt('Added to my course blog').'<br />';
                   3943:           }
1.175     www      3944:       }
1.133     albertel 3945: 	  
1.6       albertel 3946: # Receipt screen and redirect back to where came from
1.255     raeburn  3947:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group,$toolarge);
1.133     albertel 3948:   }
                   3949:   return OK;
1.234     raeburn  3950: }
                   3951: 
                   3952: sub blocked_reply_or_edit {
                   3953:     my ($blocktext) = @_;
                   3954:     return 
                   3955:       &Apache::loncommon::start_page('Resource Feedback and Discussion').
                   3956:       $blocktext.'<br /><br /><a href="javascript:history.go(-1)">'.
                   3957:       &mt('Back to previous page').
                   3958:       &Apache::loncommon::end_page();
1.133     albertel 3959: } 
1.6       albertel 3960: 
1.133     albertel 3961: sub wrap_symb {
                   3962:     my ($ressymb)=@_;
                   3963:     if ($ressymb =~ /bulletin___\d+___/) {
                   3964:         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                   3965:             $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                   3966:         }
1.6       albertel 3967:     }
1.133     albertel 3968:     return $ressymb;
                   3969: }
                   3970: sub dewrapper {
                   3971:     my ($feedurl)=@_;
                   3972:     if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   3973:         $$feedurl=~s|^/adm/wrapper||;
                   3974:     }
                   3975: }
                   3976: 
                   3977: sub get_feedurl {
                   3978:     my ($symb)=@_;
                   3979:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   3980:     my $feedurl = &Apache::lonnet::clutter($url);
                   3981:     &dewrapper(\$feedurl);
                   3982:     return $feedurl;
1.15      www      3983: }
1.1       www      3984: 
1.133     albertel 3985: sub get_feedurl_and_clean_symb {
                   3986:     my ($symb)=@_;
                   3987:     &Apache::lonenc::check_decrypt(\$symb);
                   3988: # backward compatibility (bulletin boards used to be 'wrapped')
                   3989:     unless ($symb =~ m|bulletin___\d+___adm/wrapper|) {
                   3990: 	$symb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                   3991:     }
                   3992:     my $feedurl = &get_feedurl($symb);
                   3993:     return ($symb,$feedurl);
                   3994: }
1.180     raeburn  3995: 
                   3996: sub editing_allowed {
1.208     raeburn  3997:     my ($postid,$group) = @_;
                   3998:     $postid = &unescape($postid);
1.180     raeburn  3999:     my $can_edit = 0;
1.208     raeburn  4000:     if ($group ne '') {
                   4001:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   4002:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   4003:         if ($postid =~ m|^bulletin___\d+___adm/wrapper(/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard)|) {
                   4004:             if (&check_group_priv($group,'egp') eq 'ok') {
                   4005:                 $can_edit = 1;
                   4006:             }
                   4007:             return $can_edit;
                   4008:         }     
                   4009:     } 
1.180     raeburn  4010:     my $cid = $env{'request.course.id'};
                   4011:     my $role = (split(/\./,$env{'request.role'}))[0];
                   4012:     my $section = $env{'request.course.sec'};
1.184     albertel 4013:     my $allow_editing_config = 
                   4014: 	$env{'course.'.$cid.'.allow_discussion_post_editing'};
1.180     raeburn  4015:     if ($allow_editing_config =~ m/^\s*yes\s*$/i) {
                   4016:         $can_edit = 1;
                   4017:     } else {
1.184     albertel 4018: 	foreach my $editor (split(/,/,$allow_editing_config)) {
                   4019: 	    my ($editor_role,$editor_sec) = split(/:/,$editor);
                   4020: 	    if ($editor_role eq $role
                   4021: 		&& defined($editor_sec)
                   4022: 		&& defined($section)
                   4023: 		&& $editor_sec eq $section) {
                   4024: 		$can_edit = 1;
                   4025: 		last;
                   4026: 	    }
                   4027: 	    if ($editor_role eq $role
                   4028: 		&& !defined($editor_sec)) {
                   4029: 		$can_edit = 1;
                   4030: 	    }
                   4031: 	}
1.180     raeburn  4032:     }
                   4033:     return $can_edit;
                   4034: }
                   4035: 
1.208     raeburn  4036: sub check_group_priv {
                   4037:     my ($group,$grp_priv) = @_;
                   4038:     foreach my $priv ('mdg','vcg') {
                   4039:         my $checkcourse = $env{'request.course.id'}.
                   4040:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'');
                   4041:         if (&Apache::lonnet::allowed($priv,$checkcourse)) {
                   4042:             return 'ok';
                   4043:         }
                   4044:     }
                   4045:     if ($grp_priv && $group ne '') {
                   4046:         if (&Apache::lonnet::allowed($grp_priv,$env{'request.course.id'}.'/'.$group)) {
                   4047:             return 'ok';
                   4048:         }
                   4049:     }
                   4050:     return '';
                   4051: }
                   4052: 
1.211     albertel 4053: sub group_args { 
1.208     raeburn  4054:     my ($group) = @_;
1.211     albertel 4055:     if ($group eq '') { return ''; }
                   4056:     my $extra_args = '&amp;group='.$group;
1.208     raeburn  4057:     if (exists($env{'form.ref'})) {
1.211     albertel 4058:         $extra_args .= '&amp;ref='.$env{'form.ref'};
1.208     raeburn  4059:     }
                   4060:     return $extra_args;
                   4061: }
                   4062: 
1.237     raeburn  4063: sub get_resource_title {
                   4064:     my ($symb,$feedurl) = @_;
                   4065:     my ($restitle,$plainurl);
                   4066:     if (defined($symb)) {
                   4067:         my $plain_symb = &Apache::lonenc::check_decrypt($symb);
                   4068:         $restitle = &Apache::lonnet::gettitle($plain_symb);
                   4069:     }
                   4070:     if (defined($feedurl)) {
                   4071:         $plainurl = &Apache::lonenc::check_decrypt($feedurl);
                   4072:     }
                   4073:     if (!defined($restitle)) {
                   4074:         if (defined($feedurl)) {
                   4075:             $restitle = &Apache::lonnet::gettitle($plainurl);
                   4076:         }
                   4077:     }
                   4078:     if ($plainurl ne $feedurl) {
                   4079:         my ($plain_filename) = ($plainurl =~ m-/([^/]+)$-);
                   4080:         if ($plain_filename eq $restitle) {
                   4081:             $restitle = &mt('Untitled resource');
                   4082:         }
                   4083:     }
                   4084:     if ($restitle eq '') {
                   4085:         $restitle = &mt('Untitled resource');
                   4086:     }
                   4087:     return $restitle;
                   4088: }
                   4089: 
1.1       www      4090: 1;
                   4091: __END__
1.257     jms      4092: 
                   4093: 
                   4094: =pod
                   4095: 
                   4096: =head1 NAME
                   4097: 
                   4098: Apache::lonfeedback.pm
                   4099: 
                   4100: =head1 SYNOPSIS
                   4101: 
                   4102: Handles feedback from students to instructors and system administrators.
                   4103: 
                   4104: Provides a screenshot of the current resource, as well as previous attempts if the resource was a homework.
                   4105: 
                   4106: Used by lonmsg.pm.
                   4107: 
                   4108: This is part of the LearningOnline Network with CAPA project
                   4109: described at http://www.lon-capa.org.
                   4110: 
                   4111: =head1 OVERVIEW
                   4112: 
                   4113: None
                   4114: 
                   4115: =head1 SUBROUTINES
                   4116: 
                   4117: =over
                   4118: 
                   4119: =item discussion_open()
                   4120: 
                   4121: =item discussion_visible()
                   4122: 
                   4123: =item list_discussion()
                   4124: 
                   4125: =item send_feedback_link()
                   4126: 
                   4127: =item send_message_link()
                   4128: 
                   4129: =item action_links_bar()
                   4130: 
                   4131: =item postingform_display()
                   4132: 
                   4133: =item build_posting_display
                   4134: 
                   4135: =item filter_regexp()
                   4136: 
                   4137: =item get_post_contents()
                   4138: 
                   4139: =item replicate_attachments()
                   4140: 
                   4141: =item mail_screen()
                   4142: 
                   4143: =item print_display_options()
                   4144: 
                   4145: =item print_sortfilter_options()
                   4146: 
                   4147: =item print_showposters()
                   4148: 
                   4149: =item get_post_versions()
                   4150: 
                   4151: =item get_post_attachments()
                   4152: 
                   4153: =item fail_redirect()
                   4154: 
                   4155: =item redirect_back()
                   4156: 
                   4157: =item no_redirect_back()
                   4158: 
                   4159: =item screen_header()
                   4160: 
                   4161: =item resource_output()
                   4162: 
                   4163: =item clear_out_html()
                   4164: 
                   4165: =item assemble_email()
                   4166: 
                   4167: =item feedback_available()
                   4168: 
                   4169: =item send_msg()
                   4170: 
                   4171: =item adddiscuss()
                   4172: 
                   4173: =item get_discussion_info()
                   4174: 
                   4175: =item show_preview()
                   4176: 
                   4177: =item newline_to_br()
                   4178: 
1.283     faziophi 4179: =item tidy_html()
                   4180: 
1.257     jms      4181: =item generate_preview_button()
                   4182: 
                   4183: =item modify_attachments()
                   4184: 
                   4185: =item process_attachments()
                   4186: 
                   4187: =item generate_attachments_button()
                   4188: 
                   4189: =item extract_attachments()
                   4190: 
                   4191: =item construct_attachmenturl()
                   4192: 
                   4193: =item add_blog_checkbox()
                   4194: 
                   4195: =item has_discussion()
                   4196: 
                   4197: =item sort_filter_names()
                   4198: 
                   4199: =item handler()
                   4200: 
                   4201: =item blocked_reply_or_edit()
                   4202: 
                   4203: =item wrap_symb()
                   4204: 
                   4205: =item dewrapper()
                   4206: 
                   4207: =item get_feedurl()
                   4208: 
                   4209: =item get_feedurl_and_clean_symb()
                   4210: 
                   4211: =item editing_allowed()
                   4212: 
                   4213: =item check_group_priv()
                   4214: 
                   4215: =item group_args()
                   4216: 
                   4217: =item get_resource_title()
                   4218: 
                   4219: =back
                   4220: 
1.258     bisitz   4221: =cut

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