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

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

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