Annotation of loncom/interface/lonfeedback.pm, revision 1.112
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.112 ! raeburn 4: # $Id: lonfeedback.pm,v 1.111 2004/08/01 16:05:14 raeburn Exp $
1.19 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.77 www 28: ###
1.7 albertel 29:
1.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 ()
38: use Apache::lonhtmlcommon();
1.112 ! raeburn 39: use HTML::LCParser();
1.106 www 40: use Apache::lonspeller();
1.54 www 41:
1.92 albertel 42: sub discussion_open {
1.90 albertel 43: my ($status)=@_;
1.92 albertel 44: if (defined($status) &&
45: !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
1.77 www 46: || $status eq 'OPEN')) {
1.92 albertel 47: return 0;
1.75 albertel 48: }
1.89 albertel 49: my $close=&Apache::lonnet::EXT('resource.0.discussend');
50: if (defined($close) && $close ne '' && $close < time) {
1.92 albertel 51: return 0;
1.89 albertel 52: }
1.92 albertel 53: return 1;
54: }
55:
56: sub discussion_visible {
57: my ($status)=@_;
58: if (not &discussion_open($status)) {
59: my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
60: if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden)) {
61: return 0;
62: }
63: }
64: return 1;
1.90 albertel 65: }
1.84 raeburn 66:
1.90 albertel 67: sub list_discussion {
68: my ($mode,$status,$symb)=@_;
1.95 sakharuk 69: my $outputtarget=$ENV{'form.grade_target'};
1.92 albertel 70: if (not &discussion_visible($status)) { return ''; }
1.84 raeburn 71: my @bgcols = ("#cccccc","#eeeeee");
1.57 www 72: my $discussiononly=0;
73: if ($mode eq 'board') { $discussiononly=1; }
1.55 www 74: unless ($ENV{'request.course.id'}) { return ''; }
75: my $crs='/'.$ENV{'request.course.id'};
1.101 raeburn 76: my $cid=$ENV{'request.course.id'};
1.55 www 77: if ($ENV{'request.course.sec'}) {
78: $crs.='_'.$ENV{'request.course.sec'};
79: }
80: $crs=~s/\_/\//g;
1.54 www 81: unless ($symb) {
82: $symb=&Apache::lonnet::symbread();
83: }
84: unless ($symb) { return ''; }
1.100 raeburn 85: my %usernamesort = ();
86: my %namesort =();
87: my %subjectsort = ();
1.80 raeburn 88: # backward compatibility (bulletin boards used to be 'wrapped')
89: my $ressymb=$symb;
90: if ($mode eq 'board') {
91: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
92: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
93: }
94: }
95:
96: # Get discussion display settings for this discussion
97: my $lastkey = $ressymb.'_lastread';
98: my $showkey = $ressymb.'_showonlyunread';
1.111 raeburn 99: my $markkey = $ressymb.'_showonlyunmark',
1.80 raeburn 100: my $visitkey = $ressymb.'_visit';
1.84 raeburn 101: my $ondispkey = $ressymb.'_markondisp';
1.101 raeburn 102: my $userpickkey = $ressymb.'_userpick';
1.111 raeburn 103: my $toggkey = $ressymb.'_readtoggle';
104: my $readkey = $ressymb.'_read';
105:
106: my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 107: my %discinfo = ();
1.80 raeburn 108: my $showonlyunread = 0;
1.111 raeburn 109: my $showunmark = 0;
1.84 raeburn 110: my $markondisp = 0;
1.79 raeburn 111: my $prevread = 0;
1.81 raeburn 112: my $previous = 0;
1.80 raeburn 113: my $visit = 0;
114: my $newpostsflag = 0;
1.101 raeburn 115: my @posters = split/\&/,$dischash{$userpickkey};
1.80 raeburn 116:
1.81 raeburn 117: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
1.101 raeburn 118: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts','rolefilter','statusfilter','sectionpick','totposters']);
1.100 raeburn 119: my $sortposts = $ENV{'form.sortposts'};
1.101 raeburn 120: my $rolefilter = $ENV{'form.rolefilter'};
121: my $statusfilter = $ENV{'form.statusfilter'};
122: my $sectionpick = $ENV{'form.sectionpick'};
123: my $totposters = $ENV{'form.totposters'};
1.81 raeburn 124: $previous = $ENV{'form.previous'};
1.80 raeburn 125: if ($previous > 0) {
126: $prevread = $previous;
127: } elsif (defined($dischash{$lastkey})) {
1.84 raeburn 128: unless ($dischash{$lastkey} eq '') {
129: $prevread = $dischash{$lastkey};
130: }
1.80 raeburn 131: }
1.79 raeburn 132:
1.108 raeburn 133: # Get information about students and non-students in course for filtering display of posts
1.101 raeburn 134: my %roleshash = ();
135: my %roleinfo = ();
136: if ($rolefilter) {
137: %roleshash = &Apache::lonnet::dump('nohist_userroles',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
138: foreach (keys %roleshash) {
139: my ($role,$uname,$udom,$sec) = split/:/,$_;
140: my ($end,$start) = split/:/,$roleshash{$_};
141: my $now = time;
142: my $status = 'Active';
143: if (($now < $start) || ($end > 0 && $now > $end)) {
144: $status = 'Expired';
145: }
146: push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
147: }
148: my ($classlist) = &Apache::loncoursedata::get_classlist(
149: $ENV{'request.course.id'},
150: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
151: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
152: my $sec_index = &Apache::loncoursedata::CL_SECTION();
153: my $status_index = &Apache::loncoursedata::CL_STATUS();
154: while (my ($student,$data) = each %$classlist) {
155: my ($section,$status) = ($data->[$sec_index],
156: $data->[$status_index]);
157: push @{$roleinfo{$student}}, 'st:'.$section.':'.$status;
158: }
159: }
160:
1.84 raeburn 161: # Get discussion display default settings for user
162: my %userenv = &Apache::lonnet::get('environment',['discdisplay','discmarkread'],$ENV{'user.domain'},$ENV{'user.name'});
1.83 raeburn 163: my $discdisplay=$userenv{'discdisplay'};
164: if ($discdisplay eq 'unread') {
165: $showonlyunread = 1;
166: }
1.84 raeburn 167: my $discmarkread=$userenv{'discmarkread'};
168: if ($discmarkread eq 'ondisp') {
169: $markondisp = 1;
170: }
171:
172: # Override user's default if user specified display setting for this discussion
173: if (defined($dischash{$ondispkey})) {
174: $markondisp = $dischash{$ondispkey};
175: }
176: if ($markondisp) {
177: $discinfo{$lastkey} = time;
178: }
1.83 raeburn 179:
1.80 raeburn 180: if (defined($dischash{$showkey})) {
181: $showonlyunread = $dischash{$showkey};
182: }
183:
1.111 raeburn 184: if (defined($dischash{$markkey})) {
185: $showunmark = $dischash{$markkey};
186: }
187:
1.80 raeburn 188: if (defined($dischash{$visitkey})) {
189: $visit = $dischash{$visitkey};
1.78 raeburn 190: }
1.80 raeburn 191: $visit ++;
1.78 raeburn 192:
1.54 www 193: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.77 www 194: my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
195: && ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
1.68 www 196: my @discussionitems=();
1.101 raeburn 197: my %shown = ();
198: my @posteridentity=();
1.73 albertel 199: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1.54 www 200: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
201: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.67 www 202: my $visible=0;
1.68 www 203: my @depth=();
204: my @original=();
205: my @index=();
206: my @replies=();
207: my %alldiscussion=();
1.80 raeburn 208: my %notshown = ();
1.84 raeburn 209: my %newitem = ();
1.68 www 210: my $maxdepth=0;
211:
1.69 www 212: my $target='';
213: unless ($ENV{'browser.interface'} eq 'textual' ||
214: $ENV{'environment.remote'} eq 'off' ) {
215: $target='target="LONcom"';
216: }
1.111 raeburn 217:
1.79 raeburn 218: my $now = time;
1.80 raeburn 219: $discinfo{$visitkey} = $visit;
220:
221: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.79 raeburn 222:
1.54 www 223: if ($contrib{'version'}) {
1.84 raeburn 224: my $oldest = $contrib{'1:timestamp'};
225: if ($prevread eq '0') {
226: $prevread = $oldest-1;
227: }
1.64 www 228: for (my $id=1;$id<=$contrib{'version'};$id++) {
229: my $idx=$id;
1.80 raeburn 230: my $posttime = $contrib{$idx.':timestamp'};
1.84 raeburn 231: if ($prevread <= $posttime) {
1.80 raeburn 232: $newpostsflag = 1;
233: }
1.54 www 234: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1.102 raeburn 235: my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
1.54 www 236: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1.68 www 237: my $origindex='0.';
1.102 raeburn 238: my $numoldver=0;
1.100 raeburn 239: if ($contrib{$idx.':replyto'}) {
240: if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) {
1.68 www 241: # this is a follow-up message
1.100 raeburn 242: $original[$idx]=$original[$contrib{$idx.':replyto'}];
243: $depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
244: $origindex=$index[$contrib{$idx.':replyto'}];
245: if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
246: } else {
247: $original[$idx]=0;
248: $depth[$idx]=0;
249: }
1.68 www 250: } else {
251: # this is an original message
252: $original[$idx]=0;
253: $depth[$idx]=0;
254: }
255: if ($replies[$depth[$idx]]) {
256: $replies[$depth[$idx]]++;
257: } else {
258: $replies[$depth[$idx]]=1;
259: }
1.54 www 260: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1.67 www 261: $visible++;
1.102 raeburn 262: if ($contrib{$idx.':history'}) {
263: if ($contrib{$idx.':history'} =~ /:/) {
264: my @oldversions = split/:/,$contrib{$idx.':history'};
265: $numoldver = @oldversions;
266: } else {
267: $numoldver = 1;
268: }
269: }
1.108 raeburn 270: my ($message,$subject);
271: if ($idx > 0) {
1.112 ! raeburn 272: if ($contrib{$idx.':message'} =~ /^<version num="0">/) {
! 273: my %versions = ();
! 274: &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
! 275: $message = &HTML::Entities::decode($versions{$numoldver});
1.108 raeburn 276: } else {
277: $message = $contrib{$idx.':message'};
278: }
279: } else {
280: $message=$contrib{$idx.':message'};
281: }
282: my $attachmenturls = $contrib{$idx.':attachmenturl'};
1.54 www 283: $message=~s/\n/\<br \/\>/g;
1.108 raeburn 284: $message=&Apache::lontexconvert::msgtexconverted($message);
285: if ($idx > 0) {
1.112 ! raeburn 286: if ($contrib{$idx.':subject'} =~ /^<version num="0"/) {
! 287: my %versions = ();
! 288: &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
! 289: $subject = &HTML::Entities::decode($versions{$numoldver});
1.108 raeburn 290: } else {
291: $subject = $contrib{$idx.':subject'};
292: }
293: } else {
294: $subject=$contrib{$idx.':subject'};
295: }
1.78 raeburn 296: if (defined($subject)) {
297: $subject=~s/\n/\<br \/\>/g;
1.108 raeburn 298: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.78 raeburn 299: }
1.108 raeburn 300: if ($attachmenturls) {
301: my @attachments = ();
302: my %currattach = ();
303: &extract_attachments($attachmenturls,$idx,$numoldver,\$message,\@attachments,\%currattach);
1.54 www 304: }
305: if ($message) {
306: if ($hidden) {
307: $message='<font color="#888888">'.$message.'</font>';
1.102 raeburn 308: if ($studenthidden) {
309: $message .='<br /><br />Deleted by poster (student).';
310: }
1.54 www 311: }
312: my $screenname=&Apache::loncommon::screenname(
313: $contrib{$idx.':sendername'},
314: $contrib{$idx.':senderdomain'});
315: my $plainname=&Apache::loncommon::nickname(
316: $contrib{$idx.':sendername'},
317: $contrib{$idx.':senderdomain'});
318:
1.62 www 319: my $sender=&mt('Anonymous');
1.100 raeburn 320: # Set up for sorting by subject
321: if ($contrib{$idx.':subject'} eq '') {
322: if (defined($subjectsort{'__No subject'})) {
323: push @{$subjectsort{'__No subject'}}, $idx;
324: } else {
325: @{$subjectsort{'__No subject'}} = ("$idx");
326: }
327: } else {
328: if (defined($subjectsort{$contrib{$idx.':subject'}})) {
329: push @{$subjectsort{$contrib{$idx.':subject'}}}, $idx;
330: } else {
331: @{$subjectsort{$contrib{$idx.':subject'}}} = ("$idx");
332: }
333: }
1.54 www 334: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
335: $sender=&Apache::loncommon::aboutmewrapper(
336: $plainname,
337: $contrib{$idx.':sendername'},
338: $contrib{$idx.':senderdomain'}).' ('.
339: $contrib{$idx.':sendername'}.' at '.
340: $contrib{$idx.':senderdomain'}.')';
341: if ($contrib{$idx.':anonymous'}) {
1.62 www 342: $sender.=' ['.&mt('anonymous').'] '.
1.54 www 343: $screenname;
344: }
1.100 raeburn 345: # Set up for sorting by domain, then username
346: unless (defined($usernamesort{$contrib{$idx.':senderdomain'}})) {
347: %{$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
348: }
349: if (defined($usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
350: push @{$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx;
351: } else {
352: @{$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
353: }
354: # Set up for sorting by last name, then first name
355: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],
356: $contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
357: my $lastname = $names{'lastname'};
358: my $firstname = $names{'firstname'};
359: if ($lastname eq '') {
360: $lastname = '_';
361: }
362: if ($firstname eq '') {
363: $firstname = '_';
364: }
365: unless (defined($namesort{$lastname})) {
366: %{$namesort{$lastname}} = ();
367: }
368: if (defined($namesort{$lastname}{$firstname})) {
369: push @{$namesort{$lastname}{$firstname}}, $idx;
370: } else {
371: @{$namesort{$lastname}{$firstname}} = ("$idx");
372: }
1.102 raeburn 373: if ($ENV{"course.$cid.allow_discussion_post_editing"} =~ m/yes/i) {
374: if (($ENV{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($ENV{'user.name'} eq $contrib{$idx.':sendername'})) {
375: $sender.=' <a href="/adm/feedback?editdisc='.
376: $ressymb.':::'.$idx;
377: if ($newpostsflag) {
378: $sender .= '&previous='.$prevread;
379: }
380: $sender .= '" '.$target.'>'.&mt('Edit').'</a>'; unless ($seeid) {
381: $sender.=" <a href=\"javascript:studentdelete('$ressymb','$idx','$newpostsflag','$prevread')";
382: $sender .= '">'.&mt('Delete').'</a>';
383: }
384: }
385: }
1.54 www 386: if ($seeid) {
387: if ($hidden) {
1.102 raeburn 388: unless ($studenthidden) {
389: $sender.=' <a href="/adm/feedback?unhide='.
390: $ressymb.':::'.$idx;
391: if ($newpostsflag) {
392: $sender .= '&previous='.$prevread;
393: }
394: $sender .= '">'.&mt('Make Visible').'</a>';
1.80 raeburn 395: }
1.54 www 396: } else {
397: $sender.=' <a href="/adm/feedback?hide='.
1.80 raeburn 398: $ressymb.':::'.$idx;
399: if ($newpostsflag) {
400: $sender .= '&previous='.$prevread;
401: }
402: $sender .= '">'.&mt('Hide').'</a>';
1.54 www 403: }
404: $sender.=' <a href="/adm/feedback?deldisc='.
1.102 raeburn 405: $ressymb.':::'.$idx;
1.100 raeburn 406: if ($newpostsflag) {
407: $sender .= '&previous='.$prevread;
408: }
409: $sender .= '">'.&mt('Delete').'</a>';
1.64 www 410: }
1.54 www 411: } else {
412: if ($screenname) {
413: $sender='<i>'.$screenname.'</i>';
414: }
1.100 raeburn 415: # Set up for sorting by domain, then username for anonymous
416: unless (defined($usernamesort{'__anon'})) {
417: %{$usernamesort{'__anon'}} = ();
418: }
419: if (defined($usernamesort{'__anon'}{'__anon'})) {
420: push @{$usernamesort{'__anon'}{'__anon'}}, $idx;
421: } else {
422: @{$usernamesort{'__anon'}{'__anon'}} = ("$idx");
423: }
424: # Set up for sorting by last name, then first name for anonymous
425: unless (defined($namesort{'__anon'})) {
426: %{$namesort{'__anon'}} = ();
427: }
428: if (defined($namesort{'__anon'}{'__anon'})) {
429: push @{$namesort{'__anon'}{'__anon'}}, $idx;
430: } else {
431: @{$namesort{'__anon'}{'__anon'}} = ("$idx");
432: }
1.77 www 433: }
1.92 albertel 434: if (&discussion_open($status) &&
1.90 albertel 435: &Apache::lonnet::allowed('pch',
1.77 www 436: $ENV{'request.course.id'}.
437: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
438: $sender.=' <a href="/adm/feedback?replydisc='.
1.80 raeburn 439: $ressymb.':::'.$idx;
440: if ($newpostsflag) {
441: $sender .= '&previous='.$prevread;
442: }
443: $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
1.54 www 444: }
445: my $vgrlink;
446: if ($viewgrades) {
447: $vgrlink=&Apache::loncommon::submlink('Submissions',
448: $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
449: }
1.111 raeburn 450: my $ctlink;
451: if ($dischash{$readkey}=~/\.$idx\./) {
452: $ctlink = '<b>'.&mt('Mark unread').'?</b> <input type="checkbox" name="postunread_'.$idx.'" />';
453: } else {
454: $ctlink = '<b>'.&mt('Mark read').'?</b> <input type="checkbox" name="postread_'.$idx.'" />';
455: }
1.68 www 456: #figure out at what position this needs to print
457: my $thisindex=$idx;
1.100 raeburn 458: if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) {
1.101 raeburn 459: $thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);
1.68 www 460: }
461: $alldiscussion{$thisindex}=$idx;
1.101 raeburn 462: $shown{$idx} = 0;
463: $index[$idx]=$thisindex;
1.79 raeburn 464: my $spansize = 2;
1.80 raeburn 465: if ($showonlyunread && $prevread > $posttime) {
466: $notshown{$idx} = 1;
1.111 raeburn 467: } elsif ($showunmark && $dischash{$readkey}=~/\.$idx\./) {
468: $notshown{$idx} = 1;
1.78 raeburn 469: } else {
1.108 raeburn 470: # apply filters
1.101 raeburn 471: my $uname = $contrib{$idx.':sendername'};
472: my $udom = $contrib{$idx.':senderdomain'};
473: my $poster = $uname.':'.$udom;
474: my $rolematch = '';
475: my $skiptest = 1;
476: if ($totposters > 0) {
477: if (grep/^$poster$/,@posters) {
478: $shown{$idx} = 1;
479: }
480: } else {
481: if ($rolefilter) {
482: if ($rolefilter eq 'all') {
483: $rolematch = '([^:]+)';
484: } else {
485: $rolematch = $rolefilter;
486: $skiptest = 0;
487: }
488: }
489: if ($sectionpick) {
490: if ($sectionpick eq 'all') {
491: $rolematch .= ':([^:]*)';
492: } else {
493: $rolematch .= ':'.$sectionpick;
494: $skiptest = 0;
495: }
496: }
497: if ($statusfilter) {
498: if ($statusfilter eq 'all') {
499: $rolematch .= ':([^:]+)';
500: } else {
501: $rolematch .= ':'.$statusfilter;
502: $skiptest = 0;
503: }
504: }
505: if ($skiptest) {
506: $shown{$idx} = 1;
507: } else {
508: foreach my $role (@{$roleinfo{$poster}}) {
509: if ($role =~ m/^$rolematch$/) {
510: $shown{$idx} = 1;
511: last;
512: }
513: }
514: }
515: }
516: }
517: unless ($notshown{$idx} == 1) {
1.80 raeburn 518: if ($prevread > 0 && $prevread <= $posttime) {
1.84 raeburn 519: $newitem{$idx} = 1;
520: $discussionitems[$idx] .= '
521: <p><table border="0" width="100%">
522: <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
523: } else {
524: $newitem{$idx} = 0;
525: $discussionitems[$idx] .= '
526: <p><table border="0" width="100%">
527: <tr><td align="left"> </td>';
1.80 raeburn 528: }
529: $discussionitems[$idx] .= '<td align ="left"> '.
530: '<b>'.$subject.'</b> '.
531: $sender.'</b> '.$vgrlink.' ('.
1.111 raeburn 532: &Apache::lonlocal::locallocaltime($posttime).')</td>';
533: if ($dischash{$toggkey}) {
534: $discussionitems[$idx].='<td align="right"> '.
535: $ctlink.'</td>';
536: }
537: $discussionitems[$idx].= '</tr></table><blockquote>'.$message.'</blockquote></p>';
1.102 raeburn 538: if ($contrib{$idx.':history'}) {
539: my @postversions = ();
1.109 raeburn 540: $discussionitems[$idx] .= '<br />'.&mt('This post has been edited by the author.');
541: if ($seeid) {
542: $discussionitems[$idx] .= ' <a href="/adm/feedback?allversions='.$ressymb.':::'.$idx.'">'.&mt('Display all versions').'</a>';
543: }
544: $discussionitems[$idx].='<br/>'.&mt('Earlier version(s) were posted on: ');
1.102 raeburn 545: if ($contrib{$idx.':history'} =~ m/:/) {
546: @postversions = split/:/,$contrib{$idx.':history'};
547: } else {
548: @postversions = ("$contrib{$idx.':history'}");
549: }
550: for (my $i=0; $i<@postversions; $i++) {
551: my $version = $i+1;
552: $discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' ';
553: }
554: }
1.78 raeburn 555: }
556: }
557: }
1.54 www 558: }
1.64 www 559: }
1.80 raeburn 560:
1.67 www 561: my $discussion='';
1.84 raeburn 562:
563: my $function = &Apache::loncommon::get_users_function();
564: my $color = &Apache::loncommon::designparm($function.'.tabbg',
565: $ENV{'user.domain'});
566: my %lt = &Apache::lonlocal::texthash(
1.97 raeburn 567: 'cuse' => 'Current discussion settings',
1.84 raeburn 568: 'allposts' => 'All posts',
569: 'unread' => 'New posts only',
1.111 raeburn 570: 'unmark' => 'Unread only',
1.84 raeburn 571: 'ondisp' => 'Once displayed',
1.111 raeburn 572: 'onmark' => 'Once marked not NEW',
573: 'toggoff' => 'Off',
574: 'toggon' => 'On',
1.84 raeburn 575: 'disa' => 'Posts to be displayed',
576: 'npce' => 'Posts cease to be marked "NEW"',
1.111 raeburn 577: 'epcb' => 'Each post can be toggled read/unread',
1.97 raeburn 578: 'chgt' => 'Change',
579: 'disp' => 'Display',
580: 'nolo' => 'Not new',
1.111 raeburn 581: 'togg' => 'Toggle read/unread',
1.84 raeburn 582: );
583:
584: my $currdisp = $lt{'allposts'};
585: my $currmark = $lt{'onmark'};
1.111 raeburn 586: my $currtogg = $lt{'toggoff'};
1.84 raeburn 587: my $dispchange = $lt{'unread'};
588: my $markchange = $lt{'ondisp'};
1.111 raeburn 589: my $toggchange = $lt{'toggon'};
1.97 raeburn 590: my $chglink = '/adm/feedback?modifydisp='.$ressymb;
1.111 raeburn 591: my $displinkA = 'onlyunread';
592: my $displinkB = 'onlyunmark';
1.97 raeburn 593: my $marklink = 'markondisp';
1.111 raeburn 594: my $togglink = 'toggon';
1.84 raeburn 595:
596: if ($markondisp) {
597: $currmark = $lt{'ondisp'};
598: $markchange = $lt{'onmark'};
1.97 raeburn 599: $marklink = 'markonread';
1.84 raeburn 600: }
601:
602: if ($showonlyunread) {
603: $currdisp = $lt{'unread'};
604: $dispchange = $lt{'allposts'};
1.111 raeburn 605: $displinkA = 'allposts';
1.84 raeburn 606: }
1.111 raeburn 607:
608: if ($showunmark) {
609: $currdisp = $lt{'unmark'};
610: $dispchange = $lt{'unmark'};
611: $displinkA='allposts';
612: $displinkB='onlyunread';
613: $showonlyunread = 0;
614: }
615:
616: if ($dischash{$toggkey}) {
617: $currtogg = $lt{'toggon'};
618: $toggchange = $lt{'toggoff'};
619: $togglink = 'toggoff';
620: }
1.97 raeburn 621:
1.111 raeburn 622: $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink;
1.84 raeburn 623:
624: if ($newpostsflag) {
1.97 raeburn 625: $chglink .= '&previous='.$prevread;
1.84 raeburn 626: }
627:
1.67 www 628: if ($visible) {
1.80 raeburn 629: # Print the discusssion
1.95 sakharuk 630: if ($outputtarget ne 'tex') {
1.97 raeburn 631: my $colspan=$maxdepth+1;
1.102 raeburn 632: $discussion.= qq|
633: <script>
634: function studentdelete (symb,idx,newflag,previous) {
635: var symbparm = symb+':::'+idx
636: var prevparm = ""
637: if (newflag == 1) {
638: prevparm = "&previous="+previous
639: }
640: if (confirm("Are you sure you want to delete this post?\\nDeleted posts will no longer be visible to you and other students,\\nbut will continue to be visible to your instructor")) {
641: document.location.href = "/adm/feedback?hide="+symbparm+prevparm
642: }
643: }
644: </script>
645: |;
1.111 raeburn 646: $discussion.='<form name="readchoices" method="post" action="/adm/feedback?chgreads='.$symb.'"><table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
1.97 raeburn 647: $discussion .='<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
1.95 sakharuk 648: '<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
649: if ($visible>2) {
650: $discussion.='<td align="left">'.
651: '<a href="/adm/feedback?threadedon='.$ressymb;
652: if ($newpostsflag) {
653: $discussion .= '&previous='.$prevread;
654: }
655: $discussion .='">'.&mt('Threaded View').'</a> '.
656: '<a href="/adm/feedback?threadedoff='.$ressymb;
657: if ($newpostsflag) {
658: $discussion .= '&previous='.$prevread;
659: }
1.100 raeburn 660: $discussion .='">'.&mt('Chronological View').'</a>
661: <a href= "/adm/feedback?sortfilter='.$ressymb;
662: if ($newpostsflag) {
663: $discussion .= '&previous='.$prevread;
664: }
665: $discussion .='">'.&mt('Sorting/Filtering options').'</a>  ';
666: } else {
667: $discussion .= '<td align="left">';
668: }
669: $discussion .='<a href= "/adm/feedback?export='.$ressymb;
670: if ($newpostsflag) {
671: $discussion .= '&previous='.$prevread;
672: }
673: $discussion .= '">'.&mt('Export').'?</a> </td>';
1.95 sakharuk 674: if ($newpostsflag) {
675: if (!$markondisp) {
1.111 raeburn 676: $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark NEW posts no longer new').'</a> ';
1.95 sakharuk 677: } else {
678: $discussion .= '<td> </td>';
679: }
680: } else {
681: $discussion .= '<td> </td>';
682: }
683: $discussion .= '</tr></table></td></tr>';
684: } else {
685: $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
686: '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
687: '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
688: '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
689: '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}';
690: }
1.80 raeburn 691: my $numhidden = keys %notshown;
692: if ($numhidden > 0) {
693: my $colspan = $maxdepth+1;
694: $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
695: '<a href="/adm/feedback?allposts='.$ressymb;
696: if ($newpostsflag) {
697: $discussion .= '&previous='.$prevread;
698: }
699: $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
1.111 raeburn 700: $numhidden.' ';
701: if ($showunmark) {
702: $discussion .= &mt('posts previously marked read');
703: } else {
704: $discussion .= &mt('previously viewed posts');
705: }
706: $discussion .= '<br/></td></tr>';
1.80 raeburn 707: }
1.100 raeburn 708:
709: # Choose sort mechanism
710: my @showposts = ();
711: if ($sortposts eq 'descdate') {
712: @showposts = (sort { $b <=> $a } keys %alldiscussion);
713: } elsif ($sortposts eq 'thread') {
714: @showposts = (sort { $a <=> $b } keys %alldiscussion);
715: } elsif ($sortposts eq 'subject') {
716: foreach (sort keys %subjectsort) {
717: push @showposts, @{$subjectsort{$_}};
718: }
719: } elsif ($sortposts eq 'username') {
720: foreach my $domain (sort keys %usernamesort) {
721: foreach (sort keys %{$usernamesort{$domain}}) {
722: push @showposts, @{$usernamesort{$domain}{$_}};
723: }
724: }
725: } elsif ($sortposts eq 'lastfirst') {
726: foreach my $last (sort keys %namesort) {
727: foreach (sort keys %{$namesort{$last}}) {
728: push @showposts, @{$namesort{$last}{$_}};
729: }
730: }
731: } else {
732: $sortposts = 'ascdate';
733: @showposts = (sort { $a <=> $b } keys %alldiscussion);
734: }
735: foreach (@showposts) {
736: unless (($sortposts eq 'thread') || ($sortposts eq 'ascdate' && $ENV{'environment.threadeddiscussion'})) {
737: $alldiscussion{$_} = $_;
738: }
1.101 raeburn 739: unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {
1.95 sakharuk 740: if ($outputtarget ne 'tex') {
741: $discussion.="\n<tr>";
742: } else {
743: $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}';
744: }
1.80 raeburn 745: my $thisdepth=$depth[$alldiscussion{$_}];
1.95 sakharuk 746: if ($outputtarget ne 'tex') {
747: for (1..$thisdepth) {
748: $discussion.='<td> </td>';
749: }
750: }
1.80 raeburn 751: my $colspan=$maxdepth-$thisdepth+1;
1.95 sakharuk 752: if ($outputtarget ne 'tex') {
753: $discussion.='<td bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].'" colspan="'.$colspan.'">'.
1.80 raeburn 754: $discussionitems[$alldiscussion{$_}].
755: '</td></tr>';
1.95 sakharuk 756: } else {
757: #cleanup block
758: $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
759: $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
760: my $threadinsert='';
761: if ($thisdepth > 0) {
762: $threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
763: }
764: $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
1.102 raeburn 765: $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;
1.95 sakharuk 766: $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
1.96 albertel 767:
768: #FIXME xmlparse can't be safely called from inside xmlparse
769: # due to the global variables that are use, the safe
770: # space etc. I expect this has unforseen issues that
771: # need resolving.
772:
773: $discussion.=&Apache::lonxml::xmlparse('','tex',$discussionitems[$alldiscussion{$_}]);
1.95 sakharuk 774: }
1.69 www 775: }
1.80 raeburn 776: }
1.95 sakharuk 777: if ($outputtarget ne 'tex') {
1.97 raeburn 778: my $colspan=$maxdepth+1;
1.111 raeburn 779: $discussion .= <<END;
1.97 raeburn 780: <tr bgcolor="#FFFFFF">
1.98 raeburn 781: <td colspan="$colspan" valign="top">
1.97 raeburn 782: <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
783: <tr>
784: <td align="left">
785: <table border="0" cellpadding="0" cellspacing="4">
786: <tr>
787: <td>
788: <font size="-1"><b>$lt{'cuse'}</b>:</td>
789: <td> </td>
1.111 raeburn 790: <td><font size="-1">
1.97 raeburn 791: END
792: if ($newpostsflag) {
793: $discussion .=
1.111 raeburn 794: '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'nolo'}.' - <i>'.$currmark.'</i>';
795: if ($dischash{$toggkey}) {
796: $discussion .= ' 3. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
797: }
1.97 raeburn 798: } else {
1.111 raeburn 799: if ($dischash{$toggkey}) {
800: $discussion .= '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
801: } else {
802: $discussion .=
803: $lt{'disp'}.' - <i>'.$currdisp.'</i>';
804: }
1.97 raeburn 805: }
806: $discussion .= <<END;
1.111 raeburn 807: </font></td>
1.97 raeburn 808: <td> </td>
809: <td>
1.111 raeburn 810: <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b>
811: </td>
1.97 raeburn 812: </tr>
813: </table>
814: </td>
1.111 raeburn 815: END
816: if ($dischash{$toggkey}) {
817: my $storebutton = &mt('Store read/unread changes');
818: $discussion.='<td align="right">'.
819: '<input type="hidden" name="discsymb" value="'.$ressymb.'">'."\n".
820: '<input type="button" name="readoptions" value="'.$storebutton.'"'.
821: ' onClick="this.form.submit();">'."\n".
822: '</td>';
823: }
824: $discussion .= (<<END);
1.97 raeburn 825: </tr>
826: </table>
827: </td>
828: </tr>
829: </table>
1.111 raeburn 830: <br /><br /></form>
1.97 raeburn 831: END
1.95 sakharuk 832: }
1.54 www 833: }
834: if ($discussiononly) {
1.108 raeburn 835: my $now = time;
836: my $attachnum = 0;
837: my $newattachmsg = '';
838: my @currnewattach = ();
839: my @currdelold = ();
840: my $comment = '';
841: my $subject = '';
842: if ($ENV{'form.origpage'}) {
843: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']);
844: $subject = &HTML::Entities::encode($ENV{'form.subject'},'<>&"');
845: $comment = &HTML::Entities::encode($ENV{'form.comment'},'<>&"');
846: my @keepold = ();
847: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
848: if (@currnewattach > 0) {
849: $attachnum += @currnewattach;
850: }
851: }
1.54 www 852: $discussion.=(<<ENDDISCUSS);
853: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
854: <input type="submit" name="discuss" value="Post Discussion" />
855: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
1.73 albertel 856: <input type="hidden" name="symb" value="$ressymb" />
1.54 www 857: <input type="hidden" name="sendit" value="true" />
1.108 raeburn 858: <input type="hidden" name="timestamp" value="$now" />
859: <br /><a name="newpost"></a>
860: <font size="1">Note: in anonymous discussion, your name is visible only
861: to course faculty</font><br />
862: <b>Title:</b> <input type="text" name="subject" value="$subject" size="30" /><br /><br />
863: <textarea name="comment" cols="80" rows="14" wrap="hard">$comment</textarea>
1.54 www 864: ENDDISCUSS
1.108 raeburn 865: if ($ENV{'form.origpage'}) {
866: $discussion.='<input type="hidden" name="origpage" value="'.$ENV{'form.origpage'}.'" />'."\n";
867: foreach (@currnewattach) {
868: $discussion.='<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
869: }
870: }
871: $discussion.="</form>\n";
1.95 sakharuk 872: if ($outputtarget ne 'tex') {
1.108 raeburn 873: $discussion.=&generate_attachments_button('',$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,'',$mode);
874: if (@currnewattach > 0) {
875: $newattachmsg .= '<b>New attachments</b><br />';
876: if (@currnewattach > 1) {
877: $newattachmsg .= '<ol>';
878: foreach my $item (@currnewattach) {
879: $item =~ m#.*/([^/]+)$#;
880: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
881: }
882: $newattachmsg .= '</ol>'."\n";
883: } else {
884: $currnewattach[0] =~ m#.*/([^/]+)$#;
885: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
886: }
887: }
888: $discussion.=$newattachmsg;
1.95 sakharuk 889: $discussion.=&generate_preview_button();
890: }
1.74 www 891: } else {
1.92 albertel 892: if (&discussion_open($status) &&
1.90 albertel 893: &Apache::lonnet::allowed('pch',
1.74 www 894: $ENV{'request.course.id'}.
895: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.95 sakharuk 896: if ($outputtarget ne 'tex') {
897: $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
898: $symb.':::" '.$target.'>'.
899: '<img src="/adm/lonMisc/chat.gif" border="0" />'.
900: &mt('Post Discussion').'</a></td></tr></table>';
901: }
1.100 raeburn 902: }
1.74 www 903: }
1.54 www 904: return $discussion;
905: }
1.1 www 906:
1.6 albertel 907: sub mail_screen {
908: my ($r,$feedurl,$options) = @_;
1.108 raeburn 909: if (exists($ENV{'form.origpage'})) {
910: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']);
911: }
1.45 www 912: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
1.102 raeburn 913: '','onLoad="window.focus();setposttype();"');
1.51 albertel 914: my $title=&Apache::lonnet::gettitle($feedurl);
915: if (!$title) { $title = $feedurl; }
1.69 www 916: my $quote='';
1.78 raeburn 917: my $subject = '';
1.108 raeburn 918: my $comment = '';
1.80 raeburn 919: my $prevtag = '';
1.102 raeburn 920: my $parentmsg = '';
1.108 raeburn 921: my ($symb,$idx,$attachmenturls);
922: my $numoldver = 0;
923: my $attachmsg = '';
924: my $newattachmsg = '';
925: my @currnewattach = ();
926: my @currdelold = ();
927: my @keepold = ();
928: my @attachments = ();
929: my %currattach = ();
930: my $attachnum = 0;
931: my $anonchk = (<<END);
932: function anonchk() {
933: if (document.mailform.anondiscuss.checked == true) {
934: document.attachment.anondiscuss.value = '1'
935: }
936: if (document.mailform.discuss.checked == true) {
937: document.attachment.discuss.value = '1'
938: }
939: return
940: }
941: END
942: my $anonscript;
943: if (exists($ENV{'form.origpage'})) {
944: $anonscript = (<<END);
1.102 raeburn 945: function setposttype() {
1.108 raeburn 946: var anondisc = $ENV{'form.anondiscuss'};
947: var disc = $ENV{'form.discuss'};
948: if (anondisc == 1) {
949: document.mailform.anondiscuss.checked = true
950: }
951: if (disc == 1) {
952: document.mailform.discuss.checked = true
953: }
1.102 raeburn 954: return
955: }
956: END
1.108 raeburn 957: } else {
958: $anonscript = (<<END);
959: function setposttype() {
960: return
961: }
962: END
963: }
1.102 raeburn 964: if (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
965: if ($ENV{'form.replydisc'}) {
966: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
967: } else {
968: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
969: }
1.69 www 970: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
971: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
972: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.80 raeburn 973: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.112 ! raeburn 974: if ($contrib{$idx.':history'}) {
! 975: if ($contrib{$idx.':history'} =~ /:/) {
! 976: my @oldversions = split/:/,$contrib{$idx.':history'};
! 977: $numoldver = @oldversions;
! 978: } else {
! 979: $numoldver = 1;
! 980: }
! 981: }
1.102 raeburn 982: if ($ENV{'form.replydisc'}) {
983: if ($contrib{$idx.':history'}) {
984: if ($contrib{$idx.':history'} =~ /:/) {
985: my @oldversions = split/:/,$contrib{$idx.':history'};
986: $numoldver = @oldversions;
987: } else {
988: $numoldver = 1;
989: }
990: }
1.108 raeburn 991: my $message;
992: if ($idx > 0) {
1.112 ! raeburn 993: if ($contrib{$idx.':message'} =~ /^<version num="0"/) {
! 994: my %versions = ();
! 995: &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
! 996: $message = &HTML::Entities::decode($versions{$numoldver});
1.108 raeburn 997: } else {
998: $message = $contrib{$idx.':message'};
999: }
1000: } else {
1001: $message=$contrib{$idx.':message'};
1002: }
1.102 raeburn 1003: $message=~s/\n/\<br \/\>/g;
1.108 raeburn 1004: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.102 raeburn 1005: if ($idx > 0) {
1.112 ! raeburn 1006: if ($contrib{$idx.':subject'} =~ /^<version num="0"/) {
! 1007: my %versions = ();
! 1008: &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
! 1009: $subject = &HTML::Entities::decode($versions{$numoldver});
1.102 raeburn 1010: } else {
1011: $subject = $contrib{$idx.':subject'};
1012: }
1013: $subject = 'Re: '.$subject;
1014: }
1.108 raeburn 1015: $subject = &HTML::Entities::encode($subject,'<>&"');
1.102 raeburn 1016: } else {
1.108 raeburn 1017: $attachmenturls = $contrib{$idx.':attachmenturl'};
1.112 ! raeburn 1018: if ($contrib{$idx.':message'} =~ /^<version num="0">/) {
! 1019: my %versions = ();
! 1020: &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
! 1021: $comment = $versions{$numoldver};
1.102 raeburn 1022: } else {
1.112 ! raeburn 1023: $comment = &HTML::Entities::encode($contrib{$idx.':message'},'<>&"');
1.102 raeburn 1024: }
1.112 ! raeburn 1025: if ($contrib{$idx.':subject'} =~ /<version num="0">/) {
! 1026: my %versions = ();
! 1027: &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
! 1028: $subject = $versions{$numoldver};
1.102 raeburn 1029: } else {
1.112 ! raeburn 1030: $subject = &HTML::Entities::encode($contrib{$idx.':subject'},'<>&"');
1.102 raeburn 1031: }
1032: if (defined($contrib{$idx.':replyto'})) {
1033: $parentmsg = $contrib{$idx.':replyto'};
1034: }
1.108 raeburn 1035: unless (exists($ENV{'form.origpage'})) {
1036: my $anonflag = 0;
1037: if ($contrib{$idx.':anonymous'}) {
1038: $anonflag = 1;
1039: }
1040: $anonscript = (<<END);
1.102 raeburn 1041: function setposttype () {
1042: var currtype = $anonflag
1043: if (currtype == 1) {
1044: document.mailform.elements.discuss.checked = false
1045: document.mailform.elements.anondiscuss.checked = true
1046: }
1047: if (currtype == 0) {
1048: document.mailform.elements.anondiscuss.checked = false
1049: document.mailform.elements.discuss.checked = true
1050: }
1051: return
1052: }
1053: END
1.108 raeburn 1054: }
1.79 raeburn 1055: }
1.69 www 1056: }
1.80 raeburn 1057: if ($ENV{'form.previous'}) {
1058: $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
1059: }
1.69 www 1060: }
1.108 raeburn 1061:
1062: if ($ENV{'form.origpage'}) {
1063: $subject = $ENV{'form.subject'};
1064: $comment = $ENV{'form.comment'};
1065: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1066: }
1.85 www 1067: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.86 www 1068: my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
1.74 www 1069: my $send=&mt('Send');
1.102 raeburn 1070: $r->print(<<END);
1.1 www 1071: <html>
1072: <head>
1073: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 1074: <meta http-equiv="pragma" content="no-cache"></meta>
1.85 www 1075: $htmlheader
1.63 albertel 1076: <script type="text/javascript">
1077: //<!--
1.5 www 1078: function gosubmit() {
1079: var rec=0;
1.12 albertel 1080: if (typeof(document.mailform.elements.author)!="undefined") {
1.5 www 1081: if (document.mailform.elements.author.checked) {
1082: rec=1;
1083: }
1084: }
1.12 albertel 1085: if (typeof(document.mailform.elements.question)!="undefined") {
1.5 www 1086: if (document.mailform.elements.question.checked) {
1087: rec=1;
1088: }
1089: }
1.12 albertel 1090: if (typeof(document.mailform.elements.course)!="undefined") {
1.5 www 1091: if (document.mailform.elements.course.checked) {
1092: rec=1;
1093: }
1094: }
1.12 albertel 1095: if (typeof(document.mailform.elements.policy)!="undefined") {
1.5 www 1096: if (document.mailform.elements.policy.checked) {
1097: rec=1;
1098: }
1099: }
1.12 albertel 1100: if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10 www 1101: if (document.mailform.elements.discuss.checked) {
1102: rec=1;
1103: }
1104: }
1.14 www 1105: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
1106: if (document.mailform.elements.anondiscuss.checked) {
1107: rec=1;
1108: }
1109: }
1.5 www 1110:
1111: if (rec) {
1.105 www 1112: if (typeof(document.mailform.onsubmit)!='undefined') {
1113: document.mailform.onsubmit();
1114: }
1.5 www 1115: document.mailform.submit();
1116: } else {
1117: alert('Please check a feedback type.');
1118: }
1119: }
1.108 raeburn 1120: $anonchk
1.102 raeburn 1121: $anonscript
1.63 albertel 1122: //-->
1.5 www 1123: </script>
1.1 www 1124: </head>
1.29 www 1125: $bodytag
1.51 albertel 1126: <h2><tt>$title</tt></h2>
1.43 www 1127: <form action="/adm/feedback" method="post" name="mailform"
1128: enctype="multipart/form-data">
1.80 raeburn 1129: $prevtag
1.63 albertel 1130: <input type="hidden" name="postdata" value="$feedurl" />
1.102 raeburn 1131: END
1132: if ($ENV{'form.replydisc'}) {
1133: $r->print(<<END);
1.68 www 1134: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
1.102 raeburn 1135: END
1136: } elsif ($ENV{'form.editdisc'}) {
1137: $r->print(<<END);
1138: <input type="hidden" name="editdisc" value ="$ENV{'form.editdisc'}" />
1139: <input type="hidden" name="parentmsg" value ="$parentmsg" />
1140: END
1141: }
1.108 raeburn 1142: $r->print(<<END);
1.5 www 1143: Please check at least one of the following feedback types:
1.63 albertel 1144: $options<hr />
1.69 www 1145: $quote
1.63 albertel 1146: <p>My question/comment/feedback:</p>
1147: <p>
1.47 bowersj2 1148: $latexHelp
1.78 raeburn 1149: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
1150: <p>
1.108 raeburn 1151: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$comment
1.63 albertel 1152: </textarea></p>
1153: <p>
1.108 raeburn 1154: END
1155: if ( ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'}) ) {
1156: if ($ENV{'form.origpage'}) {
1157: foreach (@currnewattach) {
1158: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
1159: }
1160: foreach (@currdelold) {
1161: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
1162: }
1163: }
1164: if ($ENV{'form.editdisc'}) {
1165: if ($attachmenturls) {
1166: &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\@attachments,\%currattach,\@currdelold);
1167: $attachnum = scalar(keys %currattach);
1168: foreach (keys %currattach) {
1169: $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
1170: }
1171: }
1172: }
1173: } else {
1174: $r->print(<<END);
1.42 www 1175: Attachment (128 KB max size): <input type="file" name="attachment" />
1176: </p>
1.108 raeburn 1177: END
1178: }
1179: $r->print(<<END);
1.42 www 1180: <p>
1181: <input type="hidden" name="sendit" value="1" />
1.74 www 1182: <input type="button" value="$send" onClick='gosubmit();' />
1.42 www 1183: </p>
1.2 www 1184: </form>
1.108 raeburn 1185: END
1186: if ($ENV{'form.editdisc'} || $ENV{'form.replydisc'}) {
1187: my $now = time;
1188: my $ressymb = $symb;
1189: my $postidx = '';
1190: if ($ENV{'form.editdisc'}) {
1191: $postidx = $idx;
1192: }
1193: if (@currnewattach > 0) {
1194: $attachnum += @currnewattach;
1195: }
1196: $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver));
1197: if ($attachnum > 0) {
1198: if (@currnewattach > 0) {
1199: $newattachmsg .= '<b>New attachments</b><br />';
1200: if (@currnewattach > 1) {
1201: $newattachmsg .= '<ol>';
1202: foreach my $item (@currnewattach) {
1203: $item =~ m#.*/([^/]+)$#;
1204: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
1205: }
1206: $newattachmsg .= '</ol>'."\n";
1207: } else {
1208: $currnewattach[0] =~ m#.*/([^/]+)$#;
1209: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
1210: }
1211: }
1212: if ($attachmsg) {
1213: $r->print("<b>Retained attachments</b>:$attachmsg<br />\n");
1214: }
1215: if ($newattachmsg) {
1216: $r->print("$newattachmsg<br />");
1217: }
1218: }
1219: }
1220: $r->print(&generate_preview_button().
1221: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
1222: '</body></html>');
1.6 albertel 1223: }
1224:
1.97 raeburn 1225: sub print_display_options {
1.111 raeburn 1226: my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
1.98 raeburn 1227: # backward compatibility (bulletin boards used to be 'wrapped')
1228: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1229: $feedurl=~s|^/adm/wrapper||;
1230: }
1231:
1.97 raeburn 1232: my $function = &Apache::loncommon::get_users_function();
1233: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1234: $ENV{'user.domain'});
1235: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1236: '','');
1237:
1238: my %lt = &Apache::lonlocal::texthash(
1239: 'dido' => 'Discussion display options',
1240: 'pref' => 'Display Preference',
1241: 'curr' => 'Current setting ',
1242: 'actn' => 'Action',
1243: 'deff' => 'Default for all discussions',
1244: 'prca' => 'Preferences can be set for this discussion that determine ....',
1245: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
1.111 raeburn 1246: 'unwh' => 'Under what circumstances posts are identified as "NEW", and',
1247: 'wipa' => 'Whether individual posts can be marked as read/unread',
1.97 raeburn 1248: 'allposts' => 'All posts',
1249: 'unread' => 'New posts only',
1.111 raeburn 1250: 'unmark' => 'Posts not marked read',
1.97 raeburn 1251: 'ondisp' => 'Once displayed',
1.111 raeburn 1252: 'onmark' => 'Once marked not NEW ',
1253: 'toggon' => 'Shown',
1254: 'toggoff' => 'Not shown',
1.97 raeburn 1255: 'disa' => 'Posts displayed?',
1.111 raeburn 1256: 'npmr' => 'New posts cease to be identified as "NEW"?',
1257: 'dotm' => 'Option to mark each post as read/unread?',
1.97 raeburn 1258: 'chgt' => 'Change to ',
1259: 'mkdf' => 'Set to ',
1.111 raeburn 1260: 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
1.97 raeburn 1261: 'ywbr' => 'You will be returned to the previous page if you click OK.'
1262: );
1263:
1.111 raeburn 1264: my $dispchangeA = $lt{'unread'};
1265: my $dispchangeB = $lt{'unmark'};
1.97 raeburn 1266: my $markchange = $lt{'ondisp'};
1.111 raeburn 1267: my $toggchange = $lt{'toggon'};
1.97 raeburn 1268: my $currdisp = $lt{'allposts'};
1269: my $currmark = $lt{'onmark'};
1270: my $discdisp = 'allposts';
1271: my $discmark = 'onmark';
1.111 raeburn 1272: my $currtogg = $lt{'toggoff'};
1273: my $disctogg = 'toggoff';
1.97 raeburn 1274:
1.111 raeburn 1275: if ($dispchgA eq 'allposts') {
1276: $dispchangeA = $lt{'allposts'};
1.97 raeburn 1277: $currdisp = $lt{'unread'};
1278: $discdisp = 'unread';
1279: }
1.111 raeburn 1280:
1.97 raeburn 1281: if ($markchg eq 'markonread') {
1282: $markchange = $lt{'onmark'};
1283: $currmark = $lt{'ondisp'};
1284: $discmark = 'ondisp';
1285: }
1.111 raeburn 1286:
1287: if ($dispchgB eq 'onlyunread') {
1288: $dispchangeB = $lt{'unread'};
1289: $currdisp = $lt{'unmark'};
1290: $discdisp = 'unmark';
1291: }
1292: if ($toggchg eq 'toggoff') {
1293: $toggchange = $lt{'toggoff'};
1294: $currtogg = $lt{'toggon'};
1295: $disctogg = 'toggon';
1296: }
1.97 raeburn 1297: $r->print(<<END);
1298: <html>
1299: <head>
1300: <title>$lt{'dido'}</title>
1301: <meta http-equiv="pragma" content="no-cache" />
1302: <script>
1.111 raeburn 1303: function discdispChk(caller) {
1304: var disctogg = '$toggchg'
1305: if (caller == 0) {
1306: if (document.modifydisp.discdisp[0].checked == true) {
1307: if (document.modifydisp.discdisp[1].checked == true) {
1308: document.modifydisp.discdisp[1].checked = false
1309: }
1310: }
1311: }
1312: if (caller == 1) {
1313: if (document.modifydisp.discdisp[1].checked == true) {
1314: if (document.modifydisp.discdisp[0].checked == true) {
1315: document.modifydisp.discdisp[0].checked = false
1316: }
1317: if (disctogg == 'toggon') {
1318: document.modifydisp.disctogg.checked = true
1319: }
1320: if (disctogg == 'toggoff') {
1321: document.modifydisp.disctogg.checked = false
1322: }
1323: }
1324: }
1325: if (caller == 2) {
1326: var dispchgB = '$dispchgB'
1327: if (disctogg == 'toggoff') {
1328: if (document.modifydisp.disctogg.checked == true) {
1329: if (dispchgB == 'onlyunmark') {
1330: document.modifydisp.discdisp[1].checked = false
1331: }
1332: }
1333: }
1334: }
1335: }
1336:
1.97 raeburn 1337: function setDisp() {
1338: var prev = "$previous"
1339: var chktotal = 0
1.111 raeburn 1340: if (document.modifydisp.discdisp[0].checked == true) {
1341: document.modifydisp.$dispchgA.value = "$symb"
1342: chktotal ++
1343: }
1344: if (document.modifydisp.discdisp[1].checked == true) {
1345: document.modifydisp.$dispchgB.value = "$symb"
1.97 raeburn 1346: chktotal ++
1347: }
1348: if (document.modifydisp.discmark.checked == true) {
1349: document.modifydisp.$markchg.value = "$symb"
1350: chktotal ++
1351: }
1.111 raeburn 1352: if (document.modifydisp.disctogg.checked == true) {
1353: document.modifydisp.$toggchg.value = "$symb"
1354: chktotal ++
1355: }
1.97 raeburn 1356: if (chktotal > 0) {
1357: document.modifydisp.submit()
1358: } else {
1359: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
1360: if (prev > 0) {
1361: location.href = "$feedurl?previous=$previous"
1362: } else {
1363: location.href = "$feedurl"
1364: }
1365: }
1366: }
1367: }
1368: </script>
1369: </head>
1370: $bodytag
1371: <form name="modifydisp" method="post" action="/adm/feedback">
1.111 raeburn 1372: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
1.97 raeburn 1373: <br />
1374: <table border="0" cellpadding="0" cellspacing="0">
1375: <tr>
1376: <td width="100%" bgcolor="#000000">
1377: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1378: <tr>
1379: <td width="100%" bgcolor="#000000">
1380: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
1381: <tr bgcolor="$tabcolor">
1382: <td><b>$lt{'pref'}</b></td>
1383: <td><b>$lt{'curr'}</b></td>
1384: <td><b>$lt{'actn'}?</b></td>
1385: </tr>
1386: <tr bgcolor="#dddddd">
1387: <td>$lt{'disa'}</td>
1388: <td>$lt{$discdisp}</td>
1.111 raeburn 1389: <td><input type="checkbox" name="discdisp" onClick="discdispChk('0')" /> $lt{'chgt'} "$dispchangeA"
1390: <br />
1391: <input type="checkbox" name="discdisp" onClick="discdispChk('1')" /> $lt{'chgt'} "$dispchangeB"
1392: </td>
1.97 raeburn 1393: </tr><tr bgcolor="#eeeeee">
1394: <td>$lt{'npmr'}</td>
1395: <td>$lt{$discmark}</td>
1396: <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
1.111 raeburn 1397: </tr><tr bgcolor="#dddddd">
1398: <td>$lt{'dotm'}</td>
1399: <td>$lt{$disctogg}</td>
1400: <td><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</td>
1.97 raeburn 1401: </tr>
1402: </table>
1403: </td>
1404: </tr>
1405: </table>
1406: </td>
1407: </tr>
1408: </table>
1409: <br />
1410: <br />
1411: <input type="hidden" name="previous" value="$previous" />
1.111 raeburn 1412: <input type="hidden" name="$dispchgA" value=""/>
1413: <input type="hidden" name="$dispchgB" value=""/>
1.97 raeburn 1414: <input type="hidden" name="$markchg" value=""/>
1.111 raeburn 1415: <input type="hidden" name="$toggchg" value="" />
1.97 raeburn 1416: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
1417: <br />
1418: <br />
1419: </form>
1420: </body>
1421: </html>
1422: END
1423: return;
1424: }
1425:
1.100 raeburn 1426: sub print_sortfilter_options {
1427: my ($r,$symb,$previous,$feedurl) = @_;
1428: # backward compatibility (bulletin boards used to be 'wrapped')
1429: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1430: $feedurl=~s|^/adm/wrapper||;
1431: }
1432: my @sections = ();
1433: my $section_sel = '';
1434: my $numsections = 0;
1435: my $numvisible = 5;
1436: my ($classlist) = &Apache::loncoursedata::get_classlist(
1437: $ENV{'request.course.id'},
1438: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1439: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1440:
1441: my $sec_index = &Apache::loncoursedata::CL_SECTION();
1442: my $status_index = &Apache::loncoursedata::CL_STATUS();
1443: my %sectioncount = ();
1444: while (my ($student,$data) = each %$classlist) {
1445: my ($section,$status) = ($data->[$sec_index],
1446: $data->[$status_index]);
1447: unless ($section eq '' || $section =~ /^\s*$/) {
1448: if (!defined($sectioncount{$section})) {
1449: $sectioncount{$section} = 1;
1450: $numsections ++;
1451: } else {
1452: $sectioncount{$section} ++;
1453: }
1454: }
1455: }
1456:
1457: if ($ENV{'request.course.sec'} !~ /^\s*$/) {
1458: @sections = ($ENV{'request.course.sec'});
1459: $numvisible = 1;
1460: } else {
1461: @sections = sort {$a cmp $b} keys(%sectioncount);
1462: unshift(@sections,'all'); # Put 'all' at the front of the list
1463: if ($numsections < 4) {
1464: $numvisible = $numsections + 1;
1465: }
1466: }
1467: foreach (@sections) {
1468: $section_sel .= " <option value=\"$_\" />$_\n";
1469: }
1470:
1471: my $function = &Apache::loncommon::get_users_function();
1472: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1473: $ENV{'user.domain'});
1474: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1475: '','');
1476: my %lt = &Apache::lonlocal::texthash(
1477: 'diso' => 'Discussion sorting and filtering options',
1478: 'diop' => 'Display Options',
1479: 'curr' => 'Current setting ',
1480: 'actn' => 'Action',
1.101 raeburn 1481: 'prca' => 'Options can be set that control the sort order of the posts, in addition to which posts are displayed.',
1.100 raeburn 1482: 'soor' => 'Sort order',
1483: 'disp' => 'Specific user roles',
1484: 'actv' => 'Specific role status',
1485: 'spse' => 'Specific sections',
1486: 'psub' => 'Pick specific users (by name)',
1.101 raeburn 1487: 'shal' => 'Show a list of current posters'
1.100 raeburn 1488: );
1489: $r->print(<<END);
1490: <html>
1491: <head>
1492: <title>$lt{'diso'}</title>
1493: <meta http-equiv="pragma" content="no-cache" />
1494: </head>
1495: $bodytag
1496: <form name="modifyshown" method="post" action="/adm/feedback">
1497: <b>$lt{'diso'}</b><br/> $lt{'prca'}
1498: <br /><br />
1499: <table border="0">
1500: <tr>
1501: <td><b>$lt{'soor'}</b></td>
1502: <td> </td>
1503: <td><b>$lt{'disp'}</b></td>
1504: <td> </td>
1505: <td><b>$lt{'actv'}</b></td>
1506: <td> </td>
1507: <td><b>$lt{'spse'}</b></td>
1508: <td> </td>
1509: <td><b>$lt{'psub'}</b></td>
1510: </tr>
1511: <tr>
1512: <td>
1513: <select name="sortposts">
1514: <option value="ascdate" />Date order - oldest first
1515: <option value="descdate" />Date order - newest first
1516: <option value="thread" />Threaded
1517: <option value="subject" />By subject
1518: <option value="username" />By domain and username
1519: <option value="lastfirst" />By last name, first name
1520: </select>
1521: </td>
1522: <td> </td>
1523: <td>
1.101 raeburn 1524: <select name="rolefilter" multiple="true" size="5">
1.100 raeburn 1525: <option value="all" />All users
1526: <option value="st" />Students
1527: <option value="cc" />Course Coordinators
1528: <option value="in" />Instructors
1529: <option value="ta" />TAs
1530: <option value="pr" />Exam proctors
1531: <option value="cr" />Custom roles
1532: </select>
1533: </td>
1534: <td> </td>
1535: <td>
1536: <select name="statusfilter">
1537: <option value="all" />Roles of any status
1.101 raeburn 1538: <option value="Active" />Only active roles
1539: <option value="Expired" />Only inactive roles
1.100 raeburn 1540: </select>
1541: </td>
1542: <td> </td>
1543: <td>
1544: <select name="sectionpick" multiple="true" size="$numvisible">
1545: $section_sel
1546: </select>
1547: </td>
1548: <td> </td>
1549: <td><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</td>
1550: </tr>
1551: </table>
1552: <br />
1553: <br />
1554: <input type="hidden" name="previous" value="$previous" />
1555: <input type="hidden" name="applysort" value="$symb" />
1556: <input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
1557: <br />
1558: <br />
1559: </form>
1560: </body>
1561: </html>
1562: END
1563: }
1564:
1.101 raeburn 1565: sub print_showposters {
1566: my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
1567: # backward compatibility (bulletin boards used to be 'wrapped')
1568: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1569: $feedurl=~s|^/adm/wrapper||;
1570: }
1571: # backward compatibility (bulletin boards used to be 'wrapped')
1572: my $ressymb=$symb;
1573: if ($ressymb =~ /bulletin___\d+___/) {
1574: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1575: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1576: }
1577: }
1578: my $crs='/'.$ENV{'request.course.id'};
1.102 raeburn 1579: if ($ENV{'request.course.sec'}) {
1580: $crs.='_'.$ENV{'request.course.sec'};
1581: }
1.101 raeburn 1582: $crs=~s/\_/\//g;
1583: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1584: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1585: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1586: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1587: my %namesort = ();
1588: my %postcounts = ();
1589: my %lt=&Apache::lonlocal::texthash(
1590: 'diso' => 'Discussion filtering options',
1591: );
1592: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1593: '','');
1594: if ($contrib{'version'}) {
1595: for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
1596: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1597: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1598: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1599: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
1600: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
1601: my $lastname = $names{'lastname'};
1602: my $firstname = $names{'firstname'};
1603: if ($lastname eq '') {
1604: $lastname = '_';
1605: }
1606: if ($firstname eq '') {
1607: $firstname = '_';
1608: }
1609: unless (defined($namesort{$lastname})) {
1610: %{$namesort{$lastname}} = ();
1611: }
1612: my $poster = $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
1613: $postcounts{$poster} ++;
1614: if (defined($namesort{$lastname}{$firstname})) {
1615: if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
1616: push @{$namesort{$lastname}{$firstname}}, $poster;
1617: }
1618: } else {
1619: @{$namesort{$lastname}{$firstname}} = ("$poster");
1620: }
1621: }
1622: }
1623: }
1624: }
1625: $r->print(<<END);
1626: <html>
1627: <head>
1628: <title>$lt{'diso'}</title>
1629: <meta http-equiv="pragma" content="no-cache" />
1630: </head>
1631: $bodytag
1632: <form name="pickpostersform" method="post">
1633: <table border="0">
1634: <tr>
1635: <td bgcolor="#777777">
1636: <table border="0" cellpadding="3">
1637: <tr bgcolor="#e6ffff">
1638: <td><b>No.</b></td>
1639: <td><b>Select</b></td>
1640: <td><b>Fullname</b><font color="#999999">(Username/domain)</font></td>
1641: <td><b>Posts</td>
1642: </tr>
1643: END
1644: my $count = 0;
1645: foreach my $last (sort keys %namesort) {
1646: foreach my $first (sort keys %{$namesort{$last}}) {
1647: foreach (sort @{$namesort{$last}{$first}}) {
1648: my ($uname,$udom) = split/:/,$_;
1649: if (!$uname || !$udom) {
1650: next;
1651: } else {
1652: $count ++;
1653: $r->print('<tr bgcolor="#ffffe6"><td align="right">'.$count.'</td><td align="center"><input name="stuinfo" type="checkbox" value="'.$_.'" /></td><td>'.$last.', '.$first.' ('.$uname.','.$udom.')</td><td>'.$postcounts{$_}.'</td></tr>');
1654: }
1655: }
1656: }
1657: }
1658: $r->print(<<END);
1659: </table>
1660: </td>
1661: </tr>
1662: </table>
1663: <br />
1664: <input type="hidden" name="sortposts" value="$sortposts" />
1665: <input type="hidden" name="userpick" value="$symb" />
1666: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
1667: </form>
1668: </body>
1669: </html>
1670: END
1671: }
1672:
1.112 ! raeburn 1673: sub get_post_versions {
! 1674: my ($versions,$incoming,$numver) = @_;
! 1675: my $p = HTML::LCParser->new(\$incoming);
! 1676: my $done = 0;
! 1677: while ( (my $token = $p->get_tag("version")) && (!$done)) {
! 1678: my $num = $token->[1]{num};
! 1679: my $text = $p->get_text("/version");
! 1680: if (defined($numver)) {
! 1681: if ($num == $numver) {
! 1682: $$versions{$numver}=$text;
! 1683: $done = 1;
! 1684: }
! 1685: } else {
! 1686: $$versions{$num}=$text;
! 1687: }
! 1688: }
! 1689: return;
! 1690: }
! 1691:
1.6 albertel 1692: sub fail_redirect {
1693: my ($r,$feedurl) = @_;
1.70 www 1694: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.6 albertel 1695: $r->print (<<ENDFAILREDIR);
1.72 albertel 1696: <html>
1.5 www 1697: <head><title>Feedback not sent</title>
1.63 albertel 1698: <meta http-equiv="pragma" content="no-cache" />
1699: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5 www 1700: </head>
1701: <body bgcolor="#FFFFFF">
1.63 albertel 1702: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8 www 1703: <b>Sorry, no recipients ...</b>
1.5 www 1704: </body>
1705: </html>
1706: ENDFAILREDIR
1707: }
1.4 www 1708:
1.6 albertel 1709: sub redirect_back {
1.101 raeburn 1710: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$secpick,$numpicks) = @_;
1.100 raeburn 1711: my $sorttag = '';
1.101 raeburn 1712: my $roletag = '';
1713: my $statustag = '';
1714: my $sectag = '';
1715: my $userpicktag = '';
1716: my $qrystr = '';
1.80 raeburn 1717: my $prevtag = '';
1.98 raeburn 1718: # backward compatibility (bulletin boards used to be 'wrapped')
1719: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1720: $feedurl=~s|^/adm/wrapper||;
1721: }
1.70 www 1722: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 1723: if ($previous > 0) {
1724: $qrystr = 'previous='.$previous;
1725: if ($feedurl =~ /\?register=1/) {
1726: $feedurl .= '&'.$qrystr;
1727: } else {
1728: $feedurl .= '?'.$qrystr;
1729: }
1730: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
1731: }
1.100 raeburn 1732: if (defined($sort)) {
1733: my $sortqry = 'sortposts='.$sort;
1734: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
1735: $feedurl .= '&'.$sortqry;
1736: } else {
1737: $feedurl .= '?'.$sortqry;
1738: }
1739: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.101 raeburn 1740: if ( (defined($numpicks)) && ($numpicks > 0) ) {
1741: my $userpickqry = 'totposters='.$numpicks;
1742: $feedurl .= '&'.$userpickqry;
1743: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
1744: } else {
1745: my $roleqry = 'rolefilter='.$rolefilter;
1746: $feedurl .= '&'.$roleqry;
1747: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
1748: $feedurl .= '&statusfilter='.$statusfilter;
1749: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
1750: $feedurl .= '§ionpick='.$secpick;
1751: $sectag = '<input type="hidden" name="sectionpick" value="'.$secpick.'" />';
1752: }
1.100 raeburn 1753: }
1.6 albertel 1754: $r->print (<<ENDREDIR);
1.72 albertel 1755: <html>
1.3 www 1756: <head>
1757: <title>Feedback sent</title>
1.63 albertel 1758: <meta http-equiv="pragma" content="no-cache" />
1.80 raeburn 1759: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2 www 1760: </head>
1.49 www 1761: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63 albertel 1762: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5 www 1763: $typestyle
1.32 albertel 1764: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63 albertel 1765: <font color="red">$status</font>
1.49 www 1766: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 1767: $prevtag
1.100 raeburn 1768: $sorttag
1.101 raeburn 1769: $statustag
1770: $roletag
1771: $sectag
1772: $userpicktag
1.49 www 1773: </form>
1.2 www 1774: </body>
1775: </html>
1776: ENDREDIR
1777: }
1.6 albertel 1778:
1779: sub no_redirect_back {
1780: my ($r,$feedurl) = @_;
1.107 www 1781: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.6 albertel 1782: $r->print (<<ENDNOREDIR);
1.72 albertel 1783: <html>
1.2 www 1784: <head><title>Feedback not sent</title>
1.63 albertel 1785: <meta http-equiv="pragma" content="no-cache" />
1.7 albertel 1786: ENDNOREDIR
1787:
1.8 www 1788: if ($feedurl!~/^\/adm\/feedback/) {
1.7 albertel 1789: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
1790: }
1791:
1.8 www 1792: $r->print (<<ENDNOREDIRTWO);
1.2 www 1793: </head>
1.49 www 1794: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63 albertel 1795: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.107 www 1796: <b>$nofeed</b>
1.2 www 1797: </body>
1798: </html>
1.8 www 1799: ENDNOREDIRTWO
1.2 www 1800: }
1.6 albertel 1801:
1802: sub screen_header {
1.65 www 1803: my ($feedurl) = @_;
1804: my $msgoptions='';
1805: my $discussoptions='';
1.102 raeburn 1806: unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
1.65 www 1807: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
1808: $msgoptions=
1809: '<p><input type="checkbox" name="author" /> '.
1810: &mt('Feedback to resource author').'</p>';
1811: }
1812: if (&feedback_available(1)) {
1813: $msgoptions.=
1814: '<br /><input type="checkbox" name="question" /> '.
1815: &mt('Question about resource content');
1816: }
1817: if (&feedback_available(0,1)) {
1818: $msgoptions.=
1819: '<br /><input type="checkbox" name="course" /> '.
1820: &mt('Question/Comment/Feedback about course content');
1821: }
1822: if (&feedback_available(0,0,1)) {
1823: $msgoptions.=
1824: '<br /><input type="checkbox" name="policy" /> '.
1825: &mt('Question/Comment/Feedback about course policy');
1826: }
1827: }
1828: if ($ENV{'request.course.id'}) {
1.92 albertel 1829: if (&discussion_open() &&
1.90 albertel 1830: &Apache::lonnet::allowed('pch',
1.65 www 1831: $ENV{'request.course.id'}.
1832: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74 www 1833: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
1834: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65 www 1835: &mt('Contribution to course discussion of resource');
1836: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
1837: &mt('Anonymous contribution to course discussion of resource').
1838: ' <i>('.&mt('name only visible to course faculty').')</i>';
1.20 www 1839: }
1.65 www 1840: }
1.74 www 1841: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 1842: if ($discussoptions) {
1.74 www 1843: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 1844: return $msgoptions.$discussoptions;
1.6 albertel 1845: }
1846:
1847: sub resource_output {
1848: my ($feedurl) = @_;
1.46 albertel 1849: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 1850: $usersaw=~s/\<body[^\>]*\>//gi;
1851: $usersaw=~s/\<\/body\>//gi;
1852: $usersaw=~s/\<html\>//gi;
1853: $usersaw=~s/\<\/html\>//gi;
1854: $usersaw=~s/\<head\>//gi;
1855: $usersaw=~s/\<\/head\>//gi;
1856: $usersaw=~s/action\s*\=/would_be_action\=/gi;
1857: return $usersaw;
1858: }
1859:
1860: sub clear_out_html {
1.39 www 1861: my ($message,$override)=@_;
1.88 www 1862: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107 www 1863: # Always allow the <m>-tag
1864: my %html=(M=>1);
1865: # Check if more is allowed
1.37 albertel 1866: my $cid=$ENV{'request.course.id'};
1.39 www 1867: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
1868: ($override)) {
1.37 albertel 1869: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 1870: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
1871: # <SUP>
1.107 www 1872: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
1873: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
1874: M=>1, SUB=>1, SUP=>1, SPAN=>1,
1875: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
1876: }
1877: # Do the substitution of everything that is not explicitly allowed
1878: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48 albertel 1879: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.107 www 1880: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48 albertel 1881: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.6 albertel 1882: return $message;
1883: }
1884:
1885: sub assemble_email {
1.40 albertel 1886: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 1887: my $email=<<"ENDEMAIL";
1888: Refers to <a href="$feedurl">$feedurl</a>
1889:
1890: $message
1891: ENDEMAIL
1892: my $citations=<<"ENDCITE";
1893: <h2>Previous attempts of student (if applicable)</h2>
1894: $prevattempts
1.63 albertel 1895: <br /><hr />
1.6 albertel 1896: <h2>Original screen output (if applicable)</h2>
1897: $usersaw
1.40 albertel 1898: <h2>Correct Answer(s) (if applicable)</h2>
1899: $useranswer
1.6 albertel 1900: ENDCITE
1901: return ($email,$citations);
1902: }
1903:
1.35 www 1904: sub secapply {
1905: my $rec=shift;
1.36 www 1906: my $defaultflag=shift;
1907: $rec=~s/\s+//g;
1908: $rec=~s/\@/\:/g;
1909: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
1910: if ($sections) {
1911: foreach (split(/\;/,$sections)) {
1912: if (($_ eq $ENV{'request.course.sec'}) ||
1913: ($defaultflag && ($_ eq '*'))) {
1914: return $adr;
1915: }
1916: }
1917: } else {
1918: return $rec;
1919: }
1920: return '';
1.35 www 1921: }
1922:
1.6 albertel 1923: sub decide_receiver {
1.36 www 1924: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 1925: my $typestyle='';
1926: my %to=();
1.36 www 1927: if ($ENV{'form.author'}||$author) {
1.8 www 1928: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 1929: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
1930: $to{$2.':'.$1}=1;
1931: }
1.36 www 1932: if ($ENV{'form.question'}||$question) {
1.8 www 1933: $typestyle.='Submitting as Question<br>';
1.24 harris41 1934: foreach (split(/\,/,
1935: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
1936: ) {
1.36 www 1937: my $rec=&secapply($_,$defaultflag);
1938: if ($rec) { $to{$rec}=1; }
1.24 harris41 1939: }
1.6 albertel 1940: }
1.36 www 1941: if ($ENV{'form.course'}||$course) {
1.63 albertel 1942: $typestyle.='Submitting as Comment<br />';
1.24 harris41 1943: foreach (split(/\,/,
1944: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
1945: ) {
1.36 www 1946: my $rec=&secapply($_,$defaultflag);
1947: if ($rec) { $to{$rec}=1; }
1.24 harris41 1948: }
1.6 albertel 1949: }
1.36 www 1950: if ($ENV{'form.policy'}||$policy) {
1.63 albertel 1951: $typestyle.='Submitting as Policy Feedback<br />';
1.24 harris41 1952: foreach (split(/\,/,
1953: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
1954: ) {
1.36 www 1955: my $rec=&secapply($_,$defaultflag);
1956: if ($rec) { $to{$rec}=1; }
1.24 harris41 1957: }
1.6 albertel 1958: }
1.36 www 1959: if ((scalar(%to) eq '0') && (!$defaultflag)) {
1960: ($typestyle,%to)=
1961: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
1962: }
1.6 albertel 1963: return ($typestyle,%to);
1.36 www 1964: }
1965:
1966: sub feedback_available {
1967: my ($question,$course,$policy)=@_;
1968: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
1969: return scalar(%to);
1.6 albertel 1970: }
1971:
1972: sub send_msg {
1.43 www 1973: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 1974: my $status='';
1975: my $sendsomething=0;
1.24 harris41 1976: foreach (keys %to) {
1.6 albertel 1977: if ($_) {
1.22 www 1978: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 1979: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43 www 1980: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
1981: $attachmenturl)=~/ok/) {
1.63 albertel 1982: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 1983: } else {
1984: $sendsomething++;
1985: }
1986: }
1.24 harris41 1987: }
1.18 www 1988:
1989: my %record=&Apache::lonnet::restore('_feedback');
1990: my ($temp)=keys %record;
1991: unless ($temp=~/^error\:/) {
1992: my %newrecord=();
1993: $newrecord{'resource'}=$feedurl;
1994: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1995: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63 albertel 1996: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 1997: }
1998: }
1999:
1.6 albertel 2000: return ($status,$sendsomething);
2001: }
2002:
1.13 www 2003: sub adddiscuss {
1.78 raeburn 2004: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 2005: my $status='';
1.92 albertel 2006: if (&discussion_open() &&
1.90 albertel 2007: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1.23 www 2008: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20 www 2009:
1.13 www 2010: my %contrib=('message' => $email,
2011: 'sendername' => $ENV{'user.name'},
1.26 www 2012: 'senderdomain' => $ENV{'user.domain'},
2013: 'screenname' => $ENV{'environment.screenname'},
2014: 'plainname' => $ENV{'environment.firstname'}.' '.
2015: $ENV{'environment.middlename'}.' '.
2016: $ENV{'environment.lastname'}.' '.
1.42 www 2017: $ENV{'enrironment.generation'},
1.78 raeburn 2018: 'attachmenturl'=> $attachmenturl,
2019: 'subject' => $subject);
1.65 www 2020: if ($ENV{'form.replydisc'}) {
1.66 www 2021: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65 www 2022: }
1.14 www 2023: if ($anon) {
2024: $contrib{'anonymous'}='true';
2025: }
1.13 www 2026: if (($symb) && ($email)) {
1.102 raeburn 2027: if ($ENV{'form.editdisc'}) {
2028: my %newcontrib = ();
2029: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
2030: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
2031: $contrib{'timestamp'} = time;
2032: $contrib{'history'} = '';
2033: my $numoldver = 0;
2034: my ($oldsymb,$oldidx)=split(/\:\:\:/,$ENV{'form.editdisc'});
1.110 raeburn 2035: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2036: # get timestamp for last post and history
2037: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
2038: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2039: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2040: if (defined($oldcontrib{$oldidx.':replyto'})) {
2041: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2042: }
2043: if (defined($oldcontrib{$oldidx.':history'})) {
2044: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2045: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2046: $numoldver = @oldversions;
2047: } else {
2048: $numoldver = 1;
2049: }
2050: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2051: }
1.108 raeburn 2052: my $numnewver = $numoldver + 1;
1.102 raeburn 2053: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 ! raeburn 2054: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
! 2055: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
! 2056: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2057: } else {
1.112 ! raeburn 2058: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2059: }
1.102 raeburn 2060: }
2061: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 ! raeburn 2062: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
! 2063: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
! 2064: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2065: } else {
1.112 ! raeburn 2066: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2067: }
1.102 raeburn 2068: }
2069: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
2070: foreach (keys %contrib) {
2071: my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;
2072: $newcontrib{$key} = $contrib{$_};
2073: }
2074: my $put_reply = &Apache::lonnet::putstore($ENV{'request.course.id'},
2075: \%newcontrib,
2076: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2077: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2078: $status='Editing class discussion'.($anon?' (anonymous)':'');
2079: } else {
2080: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
2081: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1.13 www 2082: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17 www 2083: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.102 raeburn 2084: }
1.21 www 2085: my %storenewentry=($symb => time);
1.63 albertel 2086: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2087: &Apache::lonnet::put('discussiontimes',\%storenewentry,
2088: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2089: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13 www 2090: }
1.17 www 2091: my %record=&Apache::lonnet::restore('_discussion');
2092: my ($temp)=keys %record;
2093: unless ($temp=~/^error\:/) {
2094: my %newrecord=();
2095: $newrecord{'resource'}=$symb;
2096: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2097: $status.='<br />'.&mt('Registering').': '.
1.21 www 2098: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2099: }
2100: } else {
2101: $status.='Failed.';
1.17 www 2102: }
1.63 albertel 2103: return $status.'<br />';
1.13 www 2104: }
2105:
1.33 www 2106: # ----------------------------------------------------------- Preview function
2107:
2108: sub show_preview {
2109: my $r=shift;
2110: my $message=&clear_out_html($ENV{'form.comment'});
2111: $message=~s/\n/\<br \/\>/g;
1.106 www 2112: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2113: $message=&Apache::lontexconvert::msgtexconverted($message);
1.78 raeburn 2114: my $subject=&clear_out_html($ENV{'form.subject'});
2115: $subject=~s/\n/\<br \/\>/g;
2116: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33 www 2117: $r->print('<table border="2"><tr><td>'.
1.78 raeburn 2118: '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33 www 2119: $message.'</td></tr></table>');
2120: }
2121:
2122: sub generate_preview_button {
1.107 www 2123: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2124: return(<<ENDPREVIEW);
2125: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2126: <input type="hidden" name="subject">
1.33 www 2127: <input type="hidden" name="comment" />
1.65 www 2128: <input type="button" value="$pre"
1.105 www 2129: onClick="if (typeof(document.mailform.onsubmit)!='undefined') {document.mailform.onsubmit();};this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
1.33 www 2130: </form>
2131: ENDPREVIEW
2132: }
1.71 www 2133:
1.108 raeburn 2134: sub modify_attachments {
2135: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
2136: my $subject=&clear_out_html($ENV{'form.subject'});
2137: $subject=~s/\n/\<br \/\>/g;
2138: $subject=&Apache::lontexconvert::msgtexconverted($subject);
2139: my $timestamp=$ENV{'form.timestamp'};
2140: my $numoldver=$ENV{'form.numoldver'};
2141: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
2142: '','');
2143: my $msg = '';
2144: my @attachments = ();
2145: my %currattach = ();
2146: if ($idx) {
2147: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\@attachments,\%currattach,$currdelold);
2148: }
2149: $r->print(<<END);
2150: <html>
2151: <head>
2152: <title>Managing Attachments</title>
2153: <script>
2154: function setAction () {
2155: document.modattachments.action = document.modattachments.origpage.value;
2156: document.modattachments.submit();
2157: }
2158: </script>
2159: </head>
2160: $bodytag
2161: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2162: <table border="2">
2163: <tr>
2164: <td>
2165: <b>Subject:</b>$subject</b><br /><br />
2166: END
2167: if ($idx) {
2168: if ($attachmenturls) {
2169: my @currold = keys %currattach;
2170: if (@currold > 0) {
2171: $r->print("The following attachments were part of the most recent saved version of this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
2172: foreach (@currold) {
2173: my $id = $_;
2174: $attachments[$id] =~ m#/([^/]+)$#;
2175: $r->print('<input type="checkbox" name="deloldattach" value="'.$_.'" /> '.$1.'<br />'."\n");
2176: }
2177: $r->print("<br />");
2178: }
2179: }
2180: }
2181: if (@{$currnewattach} > 0) {
2182: $r->print("The following attachments have been uploaded for inclusion with this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
2183: foreach (@{$currnewattach}) {
2184: $_ =~ m#/([^/]+)$#;
2185: $r->print('<input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'<br />'."\n");
2186: }
2187: $r->print("<br />");
2188: }
2189: $r->print(<<END);
2190: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2191: </td>
2192: </tr>
2193: </table>
2194: <input type="hidden" name="subject" value="$ENV{'form.subject'}" />
2195: <input type="hidden" name="comment" value="$ENV{'form.comment'}" />
2196: <input type="hidden" name="timestamp" value="$ENV{'form.timestamp'}" />
2197: <input type="hidden" name="idx" value="$ENV{'form.idx'}" />
2198: <input type="hidden" name="numoldver" value="$ENV{'form.numoldver'}" />
2199: <input type="hidden" name="origpage" value="$ENV{'form.origpage'}" />
2200: <input type="hidden" name="anondiscuss" value="$ENV{'form.anondiscuss'}" />
2201: <input type="hidden" name="discuss" value="$ENV{'form.discuss'}" />
2202: END
2203: foreach (@{$currnewattach}) {
2204: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2205: }
2206: foreach (@{$currdelold}) {
2207: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2208: }
2209: $r->print(<<END);
2210: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2211: </form>
2212: </body>
2213: </html>
2214: END
2215: return;
2216: }
2217:
2218: sub process_attachments {
2219: my ($currnewattach,$currdelold,$keepold) = @_;
2220: if (exists($ENV{'form.currnewattach'})) {
2221: if (ref($ENV{'form.currnewattach'}) eq 'ARRAY') {
2222: @{$currnewattach} = @{$ENV{'form.currnewattach'}};
2223: } else {
2224: $$currnewattach[0] = $ENV{'form.currnewattach'};
2225: }
2226: }
2227: if (exists($ENV{'form.deloldattach'})) {
2228: if (ref($ENV{'form.deloldattach'}) eq 'ARRAY') {
2229: @{$currdelold} = @{$ENV{'form.deloldattach'}};
2230: } else {
2231: $$currdelold[0] = $ENV{'form.deloldattach'};
2232: }
2233: }
2234: if (exists($ENV{'form.delnewattach'})) {
2235: my @currdelnew = ();
2236: my @currnew = ();
2237: if (ref($ENV{'form.delnewattach'}) eq 'ARRAY') {
2238: @currdelnew = @{$ENV{'form.delnewattach'}};
2239: } else {
2240: $currdelnew[0] = $ENV{'form.delnewattach'};
2241: }
2242: foreach my $newone (@{$currnewattach}) {
2243: my $delflag = 0;
2244: foreach (@currdelnew) {
2245: if ($newone eq $_) {
2246: $delflag = 1;
2247: last;
2248: }
2249: }
2250: unless ($delflag) {
2251: push @currnew, $newone;
2252: }
2253: }
2254: @{$currnewattach} = @currnew;
2255: }
2256: if (exists($ENV{'form.keepold'})) {
2257: if (ref($ENV{'form.keepold'}) eq 'ARRAY') {
2258: @{$keepold} = @{$ENV{'form.keepold'}};
2259: } else {
2260: $$keepold[0] = $ENV{'form.keepold'};
2261: }
2262: }
2263: }
2264:
2265: sub generate_attachments_button {
2266: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2267: my $origpage = $ENV{'REQUEST_URI'};
2268: my $att=$attachnum.' '.&mt("attachments");
2269: my $response = (<<END);
2270: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2271: Click to add/remove attachments: <input type="button" value="$att"
2272: onClick="this.form.subject.value=document.mailform.subject.value;this.form.comment.value=document.mailform.comment.value;
2273: END
2274: unless ($mode eq 'board') {
2275: $response .= 'javascript:anonchk();';
2276: }
2277: $response .= (<<ENDATTACH);
2278: this.form.submit();" />
2279: <input type="hidden" name="origpage" value="$origpage" />
2280: <input type="hidden" name="idx" value="$idx" />
2281: <input type="hidden" name="timestamp" value="$now" />
2282: <input type="hidden" name="subject" />
2283: <input type="hidden" name="comment" />
2284: <input type="hidden" name="anondiscuss" value = "0";
2285: <input type="hidden" name="discuss" value = "0";
2286: <input type="hidden" name="numoldver" value="$numoldver" />
2287: ENDATTACH
2288: if (defined($deloldattach)) {
2289: if (@{$deloldattach} > 0) {
2290: foreach (@{$deloldattach}) {
2291: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
2292: }
2293: }
2294: }
2295: if (defined($currnewattach)) {
2296: if (@{$currnewattach} > 0) {
2297: foreach (@{$currnewattach}) {
2298: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
2299: }
2300: }
2301: }
2302: $response .= '</form>';
2303: return $response;
2304: }
2305:
2306: sub extract_attachments {
2307: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
2308: if ($attachmenturls =~ m/::::\d+:[\.yn\d]+::::/) {
2309: @{$attachments} = split/::::\d+:[\.yn\d]+::::/,$attachmenturls;
2310: shift @{$attachments};
2311: my $searchstr = '::::';
2312: for (my $i=0; $i<@{$attachments}; $i++) {
2313: if ($attachmenturls =~ m#^\Q$searchstr\E(\d+)(:[\.yn\d]+)::::#) {
2314: my $info = $1.$2;
2315: my $attachid = $1-1;
2316: $searchstr .= $info.'::::'.$$attachments[$i].'::::';
2317: if ($info =~ /\.$numoldver([yn])\./) {
2318: if (defined($currdelold)) {
2319: if (@{$currdelold} > 0) {
2320: unless (grep/^$attachid$/,@{$currdelold}) {
2321: my $id = $i;
2322: $$currattach{$id} = $1;
2323: }
2324: } else {
2325: my $id = $i;
2326: $$currattach{$id} = $1;
2327: }
2328: } else {
2329: my $id = $i;
2330: $$currattach{$id} = $1;
2331: }
2332: }
2333: }
2334: }
2335: my @attached = (sort { $a <=> $b } keys %{$currattach});
2336: if (@attached == 1) {
2337: my $id = $attached[0];
2338: $$attachments[$attached[0]]=~m|/([^/]+)$|;
2339: $$message.='<br /><a href="'.$$attachments[$id].'"><tt>'.
2340: $1.'</tt></a><br />';
2341: &Apache::lonnet::allowuploaded('/adm/feedback',
2342: $$attachments[$id]);
2343: } elsif (@attached > 1) {
2344: $$message.='<ol>';
2345: foreach (@attached) {
2346: my $id = $_;
2347: my ($fname)
2348: =($$attachments[$id]=~m|/([^/]+)$|);
2349: $$message .= '<li><a href="'.$$attachments[$id].
2350: '"><tt>'.
2351: $fname.'</tt></a></li>';
2352: &Apache::lonnet::allowuploaded('/adm/feedback',
2353: $$attachments[$id]);
2354: }
2355: $$message .= '</ol><br />';
2356: }
2357: } else {
2358: my ($fname)
2359: =($attachmenturls=~m|/([^/]+)$|);
2360: $$message .='<p>'.&mt('Attachment').
2361: ': <a href="'.$attachmenturls.
2362: '"><tt>'.
2363: $fname.'</tt></a></p>';
2364: $$attachments[0] = $attachmenturls;
2365: $$currattach{'0'} = 'n';
2366: &Apache::lonnet::allowuploaded('/adm/feedback',
2367: $attachmenturls);
2368: }
2369: }
2370:
2371: sub construct_attachmenturl {
2372: my ($currnewattach,$keepold,$symb,$idx)=@_;
2373: my $oldattachmenturl;
2374: my $newattachmenturl;
2375: my $startnum = 1;
2376: my $currver = 0;
2377: if (($ENV{'form.editdisc'}) && ($idx)) {
2378: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2379: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2380: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2381: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
2382: if ($contrib{$idx.':history'}) {
2383: if ($contrib{$idx.':history'} =~ /:/) {
2384: my @oldversions = split/:/,$contrib{$idx.':history'};
2385: $currver = 1 + scalar(@oldversions);
2386: } else {
2387: $currver = 2;
2388: }
2389: } else {
2390: $currver = 1;
2391: }
2392: if ($oldattachmenturl) {
2393: if ($oldattachmenturl =~ m/::::\d+:[\.yn\d]+::::/) {
2394: my @attachments = split/::::\d+:[\.yn\d]+::::/,$oldattachmenturl;
2395: shift @attachments;
2396: $startnum += @attachments;
2397: my $searchstr = '::::';
2398: $newattachmenturl = '::::';
2399: for (my $i=0; $i<@attachments; $i++) {
2400: if ($oldattachmenturl =~ m#^\Q$searchstr\E(\d+)(:[\.yn\d]+)::::#) {
2401: my $attachid = $1 - 1;
2402: $searchstr .= $1.$2.'::::'.$attachments[$i].'::::';
2403: $newattachmenturl .= $1.$2;
2404: if (grep/^$attachid$/,@{$keepold}) {
2405: $newattachmenturl .= '.'.$currver.'n.';
2406: }
2407: $newattachmenturl .= '::::'.$attachments[$i].'::::';
2408: }
2409: }
2410: $newattachmenturl =~ s/::::$//;
2411: } else {
2412: $newattachmenturl = '::::1:.0n.';
2413: unless (grep/^0$/,@{$keepold}) {
2414: $newattachmenturl .= '.1n.';
2415: }
2416: $newattachmenturl .= '::::'.$oldattachmenturl;
2417: $startnum ++;
2418: }
2419: }
2420: }
2421: for (my $i=0; $i<@{$currnewattach}; $i++) {
2422: my $attachnum = $startnum + $i;
2423: $newattachmenturl .= '::::'.$attachnum.':.'.$currver.'n.::::'.$$currnewattach[$i];
2424: }
2425: return $newattachmenturl;
2426: }
2427:
1.6 albertel 2428: sub handler {
2429: my $r = shift;
1.8 www 2430: if ($r->header_only) {
1.71 www 2431: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2432: $r->send_http_header;
2433: return OK;
2434: }
1.15 www 2435:
2436: # --------------------------- Get query string for limited number of parameters
2437:
1.97 raeburn 2438: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.111 raeburn 2439: ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','threadedon','threadedoff','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions']);
2440: if ($ENV{'form.discsymb'}) {
2441: my $symb = $ENV{'form.discsymb'};
2442: my $readkey = $symb.'_read';
2443: my %readinghash = ();
2444: my $chgcount = 0;
2445: %readinghash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$readkey],$ENV{'user.domain'},$ENV{'user.name'});
2446: foreach my $key (keys %ENV) {
2447: if ($key =~ m/^form\.postunread_(\d+)/) {
2448: if ($readinghash{$readkey} =~ /\.$1\./) {
2449: $readinghash{$readkey} =~ s/\.$1\.//;
2450: $chgcount ++;
2451: }
2452: } elsif ($key =~ m/^form\.postread_(\d+)/) {
2453: unless ($readinghash{$readkey} =~ /\.$1\./) {
2454: $readinghash{$readkey} .= '.'.$1.'.';
2455: $chgcount ++;
2456: }
2457: }
2458: }
2459: if ($chgcount > 0) {
2460: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'});
2461: }
2462: &Apache::loncommon::content_type($r,'text/html');
2463: $r->send_http_header;
2464: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2465: my $previous=$ENV{'form.previous'};
2466: my $feedurl = &Apache::lonnet::clutter($url);
2467: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />','0','0','',$previous,'','','',);
2468: return OK;
2469: }
1.109 raeburn 2470: if ($ENV{'form.allversions'}) {
2471: &Apache::loncommon::content_type($r,'text/html');
2472: $r->send_http_header;
2473: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions',
2474: '','');
2475: $r->print (<<END);
2476: <html>
2477: <head>
2478: <title>Post Versions</title>
2479: <meta http-equiv="pragma" content="no-cache" />
2480: </head>
2481: $bodytag
2482: END
2483: my $crs='/'.$ENV{'request.course.id'};
2484: if ($ENV{'request.course.sec'}) {
2485: $crs.='_'.$ENV{'request.course.sec'};
2486: }
2487: $crs=~s/\_/\//g;
2488: my $seeid=&Apache::lonnet::allowed('rin',$crs);
2489: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.allversions'});
2490: my $ressymb=$symb;
2491: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2492: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2493: }
2494: if ($idx > 0) {
2495: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
2496: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2497: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2498: if ($contrib{$idx.':history'}) {
2499: my $attachmenturls = $contrib{$idx.':attachmenturl'};
2500: my @postversions = ();
1.112 ! raeburn 2501: my %messages = ();
! 2502: my %subjects = ();
1.109 raeburn 2503: if ($contrib{$idx.':history'} =~ m/:/) {
2504: @postversions = split/:/,$contrib{$idx.':history'};
2505: } else {
2506: @postversions = ("$contrib{$idx.':history'}");
2507: }
2508: if (@postversions > 0) {
1.112 ! raeburn 2509: &get_post_versions(\%messages,$contrib{$idx.':message'});
! 2510: &get_post_versions(\%subjects,$contrib{$idx.':subject'});
1.109 raeburn 2511: push @postversions,$contrib{$idx.':timestamp'};
2512: my $screenname=&Apache::loncommon::screenname(
2513: $contrib{$idx.':sendername'},
2514: $contrib{$idx.':senderdomain'});
2515: my $plainname=&Apache::loncommon::nickname(
2516: $contrib{$idx.':sendername'},
2517: $contrib{$idx.':senderdomain'});
2518: my $sender=&Apache::loncommon::aboutmewrapper(
2519: $plainname,
2520: $contrib{$idx.':sendername'},
2521: $contrib{$idx.':senderdomain'}).' ('.
2522: $contrib{$idx.':sendername'}.' at '.
2523: $contrib{$idx.':senderdomain'}.')';
2524: if ($contrib{$idx.':anonymous'}) {
2525: $sender.=' ['.&mt('anonymous').'] '.$screenname;
2526: }
2527: $r->print('<b>'.$sender.'</b><br /><ul>');
2528: for (my $i=0; $i<@postversions; $i++) {
2529: my ($timesent,$message,$subject,$attachmsg);
2530: $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
1.112 ! raeburn 2531: $message=&HTML::Entities::decode($messages{$i});
! 2532: $subject=&HTML::Entities::decode($subjects{$i});
1.109 raeburn 2533: $message=~s/\n/\<br \/\>/g;
2534: $message=&Apache::lontexconvert::msgtexconverted($message);
2535: $subject=~s/\n/\<br \/\>/g;
2536: $subject=&Apache::lontexconvert::msgtexconverted($subject);
2537: if ($attachmenturls) {
2538: my @attachments = ();
2539: my %currattach = ();
2540: &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,\@attachments,\%currattach);
2541: }
2542: if ($attachmsg) {
2543: $attachmsg = '<br />Attachments:'.$attachmsg.'<br />';
2544: } else {
2545: $attachmsg = '<br />';
2546: }
2547: $r->print (<<END);
2548: <li><b>$subject</b>, $timesent<br />
2549: $message<br />
2550: $attachmsg</li>
2551: END
2552: }
2553: $r->print('</ul></body></html>');
2554: }
2555: }
2556: }
2557: return OK;
2558: }
1.101 raeburn 2559: if ($ENV{'form.posterlist'}) {
2560: &Apache::loncommon::content_type($r,'text/html');
2561: $r->send_http_header;
2562: my $symb=$ENV{'form.posterlist'};
2563: my $sortposts = $ENV{'form.sortposts'};
2564: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2565: my $previous=$ENV{'form.previous'};
2566: my $feedurl = &Apache::lonnet::clutter($url);
2567: # backward compatibility (bulletin boards used to be 'wrapped')
2568: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2569: $feedurl=~s|^/adm/wrapper||;
2570: }
2571: &print_showposters($r,$symb,$previous,$feedurl,$sortposts);
2572: return OK;
2573: }
2574: if ($ENV{'form.userpick'}) {
2575: &Apache::loncommon::content_type($r,'text/html');
2576: $r->send_http_header;
2577: my $symb=$ENV{'form.userpick'};
2578: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2579: my $previous=$ENV{'form.previous'};
2580: # backward compatibility (bulletin boards used to be 'wrapped')
2581: my $ressymb=$symb;
2582: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2583: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2584: }
2585: my $sort=$ENV{'form.sortposts'};
2586: my @posters = ();
2587: if (ref($ENV{'form.stuinfo'}) eq 'ARRAY') {
2588: @posters = $ENV{'form.stuinfo'};
2589: } else {
2590: $posters[0] = $ENV{'form.stuinfo'};
2591: }
2592: my $numpicks = @posters;
2593: if (defined($ENV{'form.userpick'})) {
2594: my %discinfo = ();
2595: $discinfo{$ressymb.'_userpick'} = join('&',@posters);
2596: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2597: }
2598: my $feedurl = &Apache::lonnet::clutter($url);
2599: # backward compatibility (bulletin boards used to be 'wrapped')
2600: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2601: $feedurl=~s|^/adm/wrapper||;
2602: }
2603: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,'','','',$numpicks);
2604: return OK;
2605: }
1.100 raeburn 2606: if ($ENV{'form.applysort'}) {
2607: &Apache::loncommon::content_type($r,'text/html');
2608: $r->send_http_header;
2609: my $symb=$ENV{'form.applysort'};
2610: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2611: my $previous=$ENV{'form.previous'};
2612: my $sort = $ENV{'form.sortposts'};
1.101 raeburn 2613: my $rolefilter = $ENV{'form.rolefilter'};
1.100 raeburn 2614: my $statusfilter = $ENV{'form.statusfilter'};
2615: my $secpick = $ENV{'form.sectionpick'};
2616: my $feedurl = &Apache::lonnet::clutter($url);
2617: # backward compatibility (bulletin boards used to be 'wrapped')
2618: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2619: $feedurl=~s|^/adm/wrapper||;
2620: }
1.101 raeburn 2621: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,$rolefilter,$statusfilter,$secpick);
1.100 raeburn 2622: return OK;
2623: } elsif ($ENV{'form.sortfilter'}) {
2624: &Apache::loncommon::content_type($r,'text/html');
2625: $r->send_http_header;
2626: my $symb=$ENV{'form.sortfilter'};
2627: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2628: my $previous=$ENV{'form.previous'};
2629: my $feedurl = &Apache::lonnet::clutter($url);
2630: # backward compatibility (bulletin boards used to be 'wrapped')
2631: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2632: $feedurl=~s|^/adm/wrapper||;
2633: }
2634: &print_sortfilter_options($r,$symb,$previous,$feedurl);
2635: return OK;
2636: } elsif ($ENV{'form.navmaps'}) {
1.99 raeburn 2637: my %discinfo = ();
2638: my @resources = ();
2639: if ($ENV{'form.navmaps'} =~ /:/) {
2640: @resources = split/:/,$ENV{'form.navmaps'};
2641: } else {
2642: @resources = ("$ENV{'form.navmaps'}");
2643: }
2644: my $numitems = @resources;
2645: my $feedurl = '/adm/navmaps';
2646: if ($ENV{'form.navurl'}) {
2647: $feedurl .= '?'.$ENV{'form.navurl'};
2648: }
2649: my %lt = &Apache::lonlocal::texthash(
2650: 'mnpa' => 'Marked "New" posts as read in a total of',
2651: 'robb' => 'resources/bulletin boards.'
2652: );
2653: foreach (@resources) {
2654: # backward compatibility (bulletin boards used to be 'wrapped')
2655: my $ressymb=$_;
2656: if ($ressymb =~ m/bulletin___\d+___/) {
2657: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2658: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
2659: }
2660: }
2661: my $lastkey = $ressymb.'_lastread';
2662: $discinfo{$lastkey} = time;
2663: }
2664: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2665: &Apache::loncommon::content_type($r,'text/html');
2666: $r->send_http_header;
2667: $r->print (<<ENDREDIR);
2668: <html>
2669: <head>
2670: <title>New posts marked as read</title>
2671: <meta http-equiv="pragma" content="no-cache" />
2672: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
2673: </head>
2674: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
2675: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
2676: <b>$lt{'mnpa'} $numitems $lt{'robb'}</b>
2677: <form name="reldt" action="$feedurl" target="loncapaclient">
2678: </form>
2679: </body>
2680: </html>
2681: ENDREDIR
2682: return OK;
2683: } elsif ($ENV{'form.modifydisp'}) {
1.84 raeburn 2684: &Apache::loncommon::content_type($r,'text/html');
2685: $r->send_http_header;
1.97 raeburn 2686: my $symb=$ENV{'form.modifydisp'};
1.84 raeburn 2687: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.97 raeburn 2688: my $previous=$ENV{'form.previous'};
1.111 raeburn 2689: my ($dispchgA,$dispchgB,$markchg,$toggchg) = split/_/,$ENV{'form.changes'};
1.97 raeburn 2690: my $feedurl = &Apache::lonnet::clutter($url);
1.98 raeburn 2691: # backward compatibility (bulletin boards used to be 'wrapped')
2692: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2693: $feedurl=~s|^/adm/wrapper||;
2694: }
1.111 raeburn 2695: &print_display_options($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 2696: return OK;
1.111 raeburn 2697: } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || $ENV{'form.onlyunmark'} || $ENV{'form.toggoff'} || $ENV{'form.toggon'} ) {
1.97 raeburn 2698: &Apache::loncommon::content_type($r,'text/html');
2699: $r->send_http_header;
2700: my $previous=$ENV{'form.previous'};
2701: my ($map,$ind,$url);
1.111 raeburn 2702: if ( ($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
2703: # ------------------------------ Modify setting for read/unread toggle for each post
2704: my $symb=$ENV{'form.toggoff'}?$ENV{'form.toggoff'}:$ENV{'form.toggon'};
2705: my $ressymb = $symb;
2706: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2707: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2708: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2709: }
2710: my %discinfo = ();
2711: my $toggkey = $ressymb.'_readtoggle';
2712: if ($ENV{'form.toggon'}) {
2713: $discinfo{$toggkey} = 1;
2714: } elsif ($ENV{'form.toggoff'}) {
2715: $discinfo{$toggkey} = 0;
2716: }
2717: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2718: }
1.97 raeburn 2719: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
2720: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
2721: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
2722: my $ressymb = $symb;
2723: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2724: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2725: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2726: }
2727: my %discinfo = ();
2728: my $lastkey = $ressymb.'_lastread';
2729: my $ondispkey = $ressymb.'_markondisp';
2730: if ($ENV{'form.markondisp'}) {
2731: $discinfo{$lastkey} = time;
2732: $discinfo{$ondispkey} = 1;
2733: } elsif ($ENV{'form.markonread'}) {
2734: if ( $previous > 0 ) {
2735: $discinfo{$lastkey} = $previous;
2736: }
2737: $discinfo{$ondispkey} = 0;
2738: }
2739: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 2740: }
1.111 raeburn 2741: if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ) {
1.97 raeburn 2742: # ----------------------------------------------------------------- Modify display setting for this discussion
1.111 raeburn 2743: my $symb;
2744: if ($ENV{'form.allposts'}) {
2745: $symb = $ENV{'form.allposts'};
2746: } elsif ($ENV{'form.onlyunread'}) {
2747: $symb = $ENV{'form.onlyunread'};
2748: } else {
2749: $symb = $ENV{'form.onlyunmark'};
2750: }
1.97 raeburn 2751: my $ressymb = $symb;
2752: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2753: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2754: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2755: }
2756: my %discinfo = ();
2757: if ($ENV{'form.allposts'}) {
2758: $discinfo{$ressymb.'_showonlyunread'} = 0;
1.111 raeburn 2759: $discinfo{$ressymb.'_showonlyunmark'} = 0;
1.97 raeburn 2760: } elsif ($ENV{'form.onlyunread'}) {
2761: $discinfo{$ressymb.'_showonlyunread'} = 1;
1.111 raeburn 2762: } else {
2763: $discinfo{$ressymb.'_showonlyunmark'} = 1;
1.84 raeburn 2764: }
1.97 raeburn 2765: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 2766: }
1.111 raeburn 2767: if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ||($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
1.97 raeburn 2768: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
2769: } else {
1.84 raeburn 2770: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
2771: }
2772: return OK;
2773: } elsif ($ENV{'form.markread'}) {
1.111 raeburn 2774: # ----------------------------------------------------------------- Mark new posts not NEW
1.84 raeburn 2775: &Apache::loncommon::content_type($r,'text/html');
2776: $r->send_http_header;
2777: my $symb=$ENV{'form.markread'};
2778: my $ressymb = $symb;
2779: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2780: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2781: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1.78 raeburn 2782: }
1.84 raeburn 2783: my %discinfo = ();
2784: my $lastkey = $ressymb.'_lastread';
2785: $discinfo{$lastkey} = time;
2786: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2787: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1.78 raeburn 2788: return OK;
2789: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15 www 2790: # ----------------------------------------------------------------- Hide/unhide
1.71 www 2791: &Apache::loncommon::content_type($r,'text/html');
1.15 www 2792: $r->send_http_header;
2793:
2794: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
2795:
2796: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 2797: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15 www 2798:
2799: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2800: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2801: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2802:
2803:
2804: my $currenthidden=$contrib{'hidden'};
1.102 raeburn 2805: my $currentstudenthidden=$contrib{'studenthidden'};
2806:
2807: my $crs='/'.$ENV{'request.course.id'};
2808: if ($ENV{'request.course.sec'}) {
2809: $crs.='_'.$ENV{'request.course.sec'};
2810: }
2811: $crs=~s/\_/\//g;
2812: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.15 www 2813:
2814: if ($ENV{'form.hide'}) {
2815: $currenthidden.='.'.$idx.'.';
1.102 raeburn 2816: unless ($seeid) {
2817: $currentstudenthidden.='.'.$idx.'.';
2818: }
1.15 www 2819: } else {
2820: $currenthidden=~s/\.$idx\.//g;
2821: }
2822: my %newhash=('hidden' => $currenthidden);
1.102 raeburn 2823: if ( ($ENV{'form.hide'}) && (!$seeid) ) {
2824: $newhash{'studenthidden'} = $currentstudenthidden;
2825: }
1.38 www 2826:
2827: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
2828: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2829: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2830:
2831: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 2832: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69 www 2833: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72 albertel 2834: &Apache::loncommon::content_type($r,'text/html');
2835: $r->send_http_header;
1.69 www 2836: if ($ENV{'form.threadedon'}) {
2837: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
2838: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
2839: } else {
2840: &Apache::lonnet::del('environment',['threadeddiscussion']);
2841: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 2842: }
1.69 www 2843: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
2844: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2845: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 2846: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38 www 2847: } elsif ($ENV{'form.deldisc'}) {
2848: # --------------------------------------------------------------- Hide for good
1.71 www 2849: &Apache::loncommon::content_type($r,'text/html');
1.38 www 2850: $r->send_http_header;
2851:
2852: my $entry=$ENV{'form.deldisc'};
2853:
2854: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 2855: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38 www 2856:
2857: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2858: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2859: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2860:
2861:
2862: my $currentdeleted=$contrib{'deleted'};
2863:
2864: $currentdeleted.='.'.$idx.'.';
2865:
2866: my %newhash=('deleted' => $currentdeleted);
1.15 www 2867:
2868: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
2869: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2870: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2871:
1.30 www 2872: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 2873: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33 www 2874: } elsif ($ENV{'form.preview'}) {
2875: # -------------------------------------------------------- User wants a preview
1.76 albertel 2876: $r->content_type('text/html');
2877: $r->send_http_header;
1.33 www 2878: &show_preview($r);
1.108 raeburn 2879: } elsif ($ENV{'form.attach'}) {
2880: # -------------------------------------------------------- Work on attachments
2881: &Apache::loncommon::content_type($r,'text/html');
2882: $r->send_http_header;
2883: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
2884: my @currnewattach = ();
2885: my @currdelold = ();
2886: my @keepold = ();
2887: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
2888: if (exists($ENV{'form.addnewattach.filename'})) {
2889: unless (length($ENV{'form.addnewattach'})>131072) {
2890: my $subdir = 'feedback/'.$ENV{'form.timestamp'};
2891: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
2892: push @currnewattach, $newattachment;
2893: }
2894: }
2895: my $attachmenturls = '';
2896: my $idx = $ENV{'form.idx'};
2897: my $symb = $ENV{'form.attach'};
2898: if ($idx) {
2899: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2900: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2901: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2902: $attachmenturls = $contrib{$idx.':attachmenturl'};
2903: }
2904: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,$attachmenturls);
1.111 raeburn 2905: } elsif ($ENV{'form.chgreads'}) {
2906: &Apache::loncommon::content_type($r,'text/html');
2907: $r->send_http_header;
2908: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ENV{'form.chgreads'});
2909: &redirect_back($r,&Apache::lonnet::clutter($url),
2910: &mt('Changed read status').'<br />','0','0');
1.15 www 2911: } else {
2912: # ------------------------------------------------------------- Normal feedback
1.6 albertel 2913: my $feedurl=$ENV{'form.postdata'};
2914: $feedurl=~s/^http\:\/\///;
2915: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
2916: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62 www 2917: $feedurl=~s/\?.+$//;
1.8 www 2918:
1.66 www 2919: my $symb;
2920: if ($ENV{'form.replydisc'}) {
2921: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
2922: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
2923: $feedurl=&Apache::lonnet::clutter($url);
1.102 raeburn 2924: } elsif ($ENV{'form.editdisc'}) {
2925: $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
2926: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
2927: $feedurl=&Apache::lonnet::clutter($url);
1.108 raeburn 2928: } elsif ($ENV{'form.origpage'}) {
2929: $symb="";
1.66 www 2930: } else {
2931: $symb=&Apache::lonnet::symbread($feedurl);
2932: }
1.31 www 2933: unless ($symb) {
2934: $symb=$ENV{'form.symb'};
2935: if ($symb) {
1.52 www 2936: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31 www 2937: $feedurl=&Apache::lonnet::clutter($url);
2938: }
2939: }
1.8 www 2940: my $goahead=1;
2941: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
2942: unless ($symb) { $goahead=0; }
2943: }
1.98 raeburn 2944: # backward compatibility (bulletin boards used to be 'wrapped')
1.73 albertel 2945: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2946: $feedurl=~s|^/adm/wrapper||;
2947: }
1.8 www 2948: if ($goahead) {
2949: # Go ahead with feedback, no ambiguous reference
1.71 www 2950: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2951: $r->send_http_header;
1.6 albertel 2952:
1.8 www 2953: if (
1.7 albertel 2954: (
2955: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
2956: )
2957: ||
2958: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31 www 2959: ||
2960: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7 albertel 2961: ) {
1.6 albertel 2962: # --------------------------------------------------- Print login screen header
2963: unless ($ENV{'form.sendit'}) {
2964: my $options=&screen_header($feedurl);
2965: if ($options) {
1.108 raeburn 2966: &mail_screen($r,$feedurl,$options);
1.6 albertel 2967: } else {
2968: &fail_redirect($r,$feedurl);
2969: }
2970: } else {
2971:
2972: # Get previous user input
1.9 albertel 2973: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 2974: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 2975: $ENV{'request.course.id'});
1.6 albertel 2976:
2977: # Get output from resource
2978: my $usersaw=&resource_output($feedurl);
2979:
1.50 albertel 2980: # Get resource answer (need to allow student to view grades for this to work)
2981: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 2982: my $useranswer=&Apache::loncommon::get_student_answers(
2983: $symb,$ENV{'user.name'},$ENV{'user.domain'},
2984: $ENV{'request.course.id'});
1.50 albertel 2985: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 2986: # Get attachments, if any, and not too large
2987: my $attachmenturl='';
1.108 raeburn 2988: if (($ENV{'form.origpage'}) || ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'})) {
2989: my ($symb,$idx);
2990: if ($ENV{'form.replydisc'}) {
2991: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
2992: } elsif ($ENV{'form.editdisc'}) {
2993: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
2994: } elsif ($ENV{'form.origpage'}) {
2995: $symb = $ENV{'form.symb'};
2996: }
2997: my @currnewattach = ();
2998: my @deloldattach = ();
2999: my @keepold = ();
3000: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
1.110 raeburn 3001: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.108 raeburn 3002: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
3003: } elsif ($ENV{'form.attachment.filename'}) {
1.42 www 3004: unless (length($ENV{'form.attachment'})>131072) {
1.82 albertel 3005: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3006: }
3007: }
1.6 albertel 3008: # Filter HTML out of message (could be nasty)
1.39 www 3009: my $message=&clear_out_html($ENV{'form.comment'});
1.6 albertel 3010:
3011: # Assemble email
1.8 www 3012: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40 albertel 3013: $usersaw,$useranswer);
3014:
1.6 albertel 3015: # Who gets this?
3016: my ($typestyle,%to) = &decide_receiver($feedurl);
3017:
3018: # Actually send mail
1.43 www 3019: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
3020: $attachmenturl,%to);
1.13 www 3021:
3022: # Discussion? Store that.
3023:
1.32 albertel 3024: my $numpost=0;
1.13 www 3025: if ($ENV{'form.discuss'}) {
1.78 raeburn 3026: my $subject = &clear_out_html($ENV{'form.subject'});
3027: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32 albertel 3028: $numpost++;
1.13 www 3029: }
1.6 albertel 3030:
1.14 www 3031: if ($ENV{'form.anondiscuss'}) {
1.78 raeburn 3032: my $subject = &clear_out_html($ENV{'form.subject'});
3033: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32 albertel 3034: $numpost++;
1.14 www 3035: }
3036:
3037:
1.6 albertel 3038: # Receipt screen and redirect back to where came from
1.80 raeburn 3039: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6 albertel 3040:
3041: }
1.8 www 3042: } else {
1.7 albertel 3043: # Unable to give feedback
1.6 albertel 3044: &no_redirect_back($r,$feedurl);
1.8 www 3045: }
3046: } else {
3047: # Ambiguous Problem Resource
1.60 albertel 3048: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53 albertel 3049: &Apache::lonnet::cleanenv();
1.58 albertel 3050: }
1.53 albertel 3051: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 3052: }
1.15 www 3053: }
1.6 albertel 3054: return OK;
1.1 www 3055: }
3056:
3057: 1;
3058: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>