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