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

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

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