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