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

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

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