Annotation of loncom/interface/lonfeedback.pm, revision 1.115
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.115 ! sakharuk 4: # $Id: lonfeedback.pm,v 1.114 2004/08/10 18:01:25 sakharuk 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 {
1.115 ! sakharuk 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) {
1.113 raeburn 301: my %attachments = ();
1.108 raeburn 302: my %currattach = ();
1.113 raeburn 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 {
1.114 sakharuk 685: $discussion.='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
1.95 sakharuk 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'.
1.114 sakharuk 689: '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}</tex>';
1.95 sakharuk 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: }
1.80 raeburn 743: my $thisdepth=$depth[$alldiscussion{$_}];
1.95 sakharuk 744: if ($outputtarget ne 'tex') {
745: for (1..$thisdepth) {
746: $discussion.='<td> </td>';
747: }
748: }
1.80 raeburn 749: my $colspan=$maxdepth-$thisdepth+1;
1.95 sakharuk 750: if ($outputtarget ne 'tex') {
751: $discussion.='<td bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].'" colspan="'.$colspan.'">'.
1.80 raeburn 752: $discussionitems[$alldiscussion{$_}].
753: '</td></tr>';
1.95 sakharuk 754: } else {
755: #cleanup block
756: $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
757: $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
758: my $threadinsert='';
759: if ($thisdepth > 0) {
760: $threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
761: }
762: $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
1.102 raeburn 763: $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;
1.95 sakharuk 764: $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
1.114 sakharuk 765:
766: $discussionitems[$alldiscussion{$_}]='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}</tex>'.$discussionitems[$alldiscussion{$_}];
767: $discussion.=$discussionitems[$alldiscussion{$_}];
1.95 sakharuk 768: }
1.69 www 769: }
1.80 raeburn 770: }
1.95 sakharuk 771: if ($outputtarget ne 'tex') {
1.97 raeburn 772: my $colspan=$maxdepth+1;
1.111 raeburn 773: $discussion .= <<END;
1.97 raeburn 774: <tr bgcolor="#FFFFFF">
1.98 raeburn 775: <td colspan="$colspan" valign="top">
1.97 raeburn 776: <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
777: <tr>
778: <td align="left">
779: <table border="0" cellpadding="0" cellspacing="4">
780: <tr>
781: <td>
782: <font size="-1"><b>$lt{'cuse'}</b>:</td>
783: <td> </td>
1.111 raeburn 784: <td><font size="-1">
1.97 raeburn 785: END
786: if ($newpostsflag) {
787: $discussion .=
1.111 raeburn 788: '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'nolo'}.' - <i>'.$currmark.'</i>';
789: if ($dischash{$toggkey}) {
790: $discussion .= ' 3. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
791: }
1.97 raeburn 792: } else {
1.111 raeburn 793: if ($dischash{$toggkey}) {
794: $discussion .= '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
795: } else {
796: $discussion .=
797: $lt{'disp'}.' - <i>'.$currdisp.'</i>';
798: }
1.97 raeburn 799: }
800: $discussion .= <<END;
1.111 raeburn 801: </font></td>
1.97 raeburn 802: <td> </td>
803: <td>
1.111 raeburn 804: <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b>
805: </td>
1.97 raeburn 806: </tr>
807: </table>
808: </td>
1.111 raeburn 809: END
810: if ($dischash{$toggkey}) {
811: my $storebutton = &mt('Store read/unread changes');
812: $discussion.='<td align="right">'.
813: '<input type="hidden" name="discsymb" value="'.$ressymb.'">'."\n".
814: '<input type="button" name="readoptions" value="'.$storebutton.'"'.
815: ' onClick="this.form.submit();">'."\n".
816: '</td>';
817: }
818: $discussion .= (<<END);
1.97 raeburn 819: </tr>
820: </table>
821: </td>
822: </tr>
823: </table>
1.111 raeburn 824: <br /><br /></form>
1.97 raeburn 825: END
1.114 sakharuk 826: }
1.54 www 827: }
828: if ($discussiononly) {
1.108 raeburn 829: my $now = time;
830: my $attachnum = 0;
831: my $newattachmsg = '';
832: my @currnewattach = ();
833: my @currdelold = ();
834: my $comment = '';
835: my $subject = '';
836: if ($ENV{'form.origpage'}) {
837: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']);
838: $subject = &HTML::Entities::encode($ENV{'form.subject'},'<>&"');
839: $comment = &HTML::Entities::encode($ENV{'form.comment'},'<>&"');
840: my @keepold = ();
841: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
842: if (@currnewattach > 0) {
843: $attachnum += @currnewattach;
844: }
845: }
1.54 www 846: $discussion.=(<<ENDDISCUSS);
847: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
848: <input type="submit" name="discuss" value="Post Discussion" />
849: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
1.73 albertel 850: <input type="hidden" name="symb" value="$ressymb" />
1.54 www 851: <input type="hidden" name="sendit" value="true" />
1.108 raeburn 852: <input type="hidden" name="timestamp" value="$now" />
853: <br /><a name="newpost"></a>
854: <font size="1">Note: in anonymous discussion, your name is visible only
855: to course faculty</font><br />
856: <b>Title:</b> <input type="text" name="subject" value="$subject" size="30" /><br /><br />
857: <textarea name="comment" cols="80" rows="14" wrap="hard">$comment</textarea>
1.54 www 858: ENDDISCUSS
1.108 raeburn 859: if ($ENV{'form.origpage'}) {
860: $discussion.='<input type="hidden" name="origpage" value="'.$ENV{'form.origpage'}.'" />'."\n";
861: foreach (@currnewattach) {
862: $discussion.='<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
863: }
864: }
865: $discussion.="</form>\n";
1.95 sakharuk 866: if ($outputtarget ne 'tex') {
1.108 raeburn 867: $discussion.=&generate_attachments_button('',$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,'',$mode);
868: if (@currnewattach > 0) {
869: $newattachmsg .= '<b>New attachments</b><br />';
870: if (@currnewattach > 1) {
871: $newattachmsg .= '<ol>';
872: foreach my $item (@currnewattach) {
873: $item =~ m#.*/([^/]+)$#;
874: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
875: }
876: $newattachmsg .= '</ol>'."\n";
877: } else {
878: $currnewattach[0] =~ m#.*/([^/]+)$#;
879: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
880: }
881: }
882: $discussion.=$newattachmsg;
1.95 sakharuk 883: $discussion.=&generate_preview_button();
884: }
1.74 www 885: } else {
1.92 albertel 886: if (&discussion_open($status) &&
1.90 albertel 887: &Apache::lonnet::allowed('pch',
1.74 www 888: $ENV{'request.course.id'}.
889: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.95 sakharuk 890: if ($outputtarget ne 'tex') {
891: $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
892: $symb.':::" '.$target.'>'.
893: '<img src="/adm/lonMisc/chat.gif" border="0" />'.
894: &mt('Post Discussion').'</a></td></tr></table>';
895: }
1.100 raeburn 896: }
1.74 www 897: }
1.114 sakharuk 898: return $discussion;
1.54 www 899: }
1.1 www 900:
1.6 albertel 901: sub mail_screen {
902: my ($r,$feedurl,$options) = @_;
1.108 raeburn 903: if (exists($ENV{'form.origpage'})) {
904: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']);
905: }
1.45 www 906: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
1.102 raeburn 907: '','onLoad="window.focus();setposttype();"');
1.51 albertel 908: my $title=&Apache::lonnet::gettitle($feedurl);
909: if (!$title) { $title = $feedurl; }
1.69 www 910: my $quote='';
1.78 raeburn 911: my $subject = '';
1.108 raeburn 912: my $comment = '';
1.80 raeburn 913: my $prevtag = '';
1.102 raeburn 914: my $parentmsg = '';
1.108 raeburn 915: my ($symb,$idx,$attachmenturls);
916: my $numoldver = 0;
917: my $attachmsg = '';
918: my $newattachmsg = '';
919: my @currnewattach = ();
920: my @currdelold = ();
921: my @keepold = ();
1.113 raeburn 922: my %attachments = ();
1.108 raeburn 923: my %currattach = ();
924: my $attachnum = 0;
925: my $anonchk = (<<END);
926: function anonchk() {
927: if (document.mailform.anondiscuss.checked == true) {
928: document.attachment.anondiscuss.value = '1'
929: }
930: if (document.mailform.discuss.checked == true) {
931: document.attachment.discuss.value = '1'
932: }
933: return
934: }
935: END
936: my $anonscript;
937: if (exists($ENV{'form.origpage'})) {
938: $anonscript = (<<END);
1.102 raeburn 939: function setposttype() {
1.108 raeburn 940: var anondisc = $ENV{'form.anondiscuss'};
941: var disc = $ENV{'form.discuss'};
942: if (anondisc == 1) {
943: document.mailform.anondiscuss.checked = true
944: }
945: if (disc == 1) {
946: document.mailform.discuss.checked = true
947: }
1.102 raeburn 948: return
949: }
950: END
1.108 raeburn 951: } else {
952: $anonscript = (<<END);
953: function setposttype() {
954: return
955: }
956: END
957: }
1.102 raeburn 958: if (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
959: if ($ENV{'form.replydisc'}) {
960: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
961: } else {
962: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
963: }
1.69 www 964: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
965: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
966: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.80 raeburn 967: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.112 raeburn 968: if ($contrib{$idx.':history'}) {
969: if ($contrib{$idx.':history'} =~ /:/) {
970: my @oldversions = split/:/,$contrib{$idx.':history'};
971: $numoldver = @oldversions;
972: } else {
973: $numoldver = 1;
974: }
975: }
1.102 raeburn 976: if ($ENV{'form.replydisc'}) {
977: if ($contrib{$idx.':history'}) {
978: if ($contrib{$idx.':history'} =~ /:/) {
979: my @oldversions = split/:/,$contrib{$idx.':history'};
980: $numoldver = @oldversions;
981: } else {
982: $numoldver = 1;
983: }
984: }
1.108 raeburn 985: my $message;
986: if ($idx > 0) {
1.112 raeburn 987: if ($contrib{$idx.':message'} =~ /^<version num="0"/) {
988: my %versions = ();
989: &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
990: $message = &HTML::Entities::decode($versions{$numoldver});
1.108 raeburn 991: } else {
992: $message = $contrib{$idx.':message'};
993: }
994: } else {
995: $message=$contrib{$idx.':message'};
996: }
1.102 raeburn 997: $message=~s/\n/\<br \/\>/g;
1.108 raeburn 998: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.102 raeburn 999: if ($idx > 0) {
1.112 raeburn 1000: if ($contrib{$idx.':subject'} =~ /^<version num="0"/) {
1001: my %versions = ();
1002: &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
1003: $subject = &HTML::Entities::decode($versions{$numoldver});
1.102 raeburn 1004: } else {
1005: $subject = $contrib{$idx.':subject'};
1006: }
1007: $subject = 'Re: '.$subject;
1008: }
1.108 raeburn 1009: $subject = &HTML::Entities::encode($subject,'<>&"');
1.102 raeburn 1010: } else {
1.108 raeburn 1011: $attachmenturls = $contrib{$idx.':attachmenturl'};
1.112 raeburn 1012: if ($contrib{$idx.':message'} =~ /^<version num="0">/) {
1013: my %versions = ();
1014: &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
1015: $comment = $versions{$numoldver};
1.102 raeburn 1016: } else {
1.112 raeburn 1017: $comment = &HTML::Entities::encode($contrib{$idx.':message'},'<>&"');
1.102 raeburn 1018: }
1.112 raeburn 1019: if ($contrib{$idx.':subject'} =~ /<version num="0">/) {
1020: my %versions = ();
1021: &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
1022: $subject = $versions{$numoldver};
1.102 raeburn 1023: } else {
1.112 raeburn 1024: $subject = &HTML::Entities::encode($contrib{$idx.':subject'},'<>&"');
1.102 raeburn 1025: }
1026: if (defined($contrib{$idx.':replyto'})) {
1027: $parentmsg = $contrib{$idx.':replyto'};
1028: }
1.108 raeburn 1029: unless (exists($ENV{'form.origpage'})) {
1030: my $anonflag = 0;
1031: if ($contrib{$idx.':anonymous'}) {
1032: $anonflag = 1;
1033: }
1034: $anonscript = (<<END);
1.102 raeburn 1035: function setposttype () {
1036: var currtype = $anonflag
1037: if (currtype == 1) {
1038: document.mailform.elements.discuss.checked = false
1039: document.mailform.elements.anondiscuss.checked = true
1040: }
1041: if (currtype == 0) {
1042: document.mailform.elements.anondiscuss.checked = false
1043: document.mailform.elements.discuss.checked = true
1044: }
1045: return
1046: }
1047: END
1.108 raeburn 1048: }
1.79 raeburn 1049: }
1.69 www 1050: }
1.80 raeburn 1051: if ($ENV{'form.previous'}) {
1052: $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
1053: }
1.69 www 1054: }
1.108 raeburn 1055:
1056: if ($ENV{'form.origpage'}) {
1057: $subject = $ENV{'form.subject'};
1058: $comment = $ENV{'form.comment'};
1059: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1060: }
1.85 www 1061: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.86 www 1062: my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
1.74 www 1063: my $send=&mt('Send');
1.102 raeburn 1064: $r->print(<<END);
1.1 www 1065: <html>
1066: <head>
1067: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 1068: <meta http-equiv="pragma" content="no-cache"></meta>
1.85 www 1069: $htmlheader
1.63 albertel 1070: <script type="text/javascript">
1071: //<!--
1.5 www 1072: function gosubmit() {
1073: var rec=0;
1.12 albertel 1074: if (typeof(document.mailform.elements.author)!="undefined") {
1.5 www 1075: if (document.mailform.elements.author.checked) {
1076: rec=1;
1077: }
1078: }
1.12 albertel 1079: if (typeof(document.mailform.elements.question)!="undefined") {
1.5 www 1080: if (document.mailform.elements.question.checked) {
1081: rec=1;
1082: }
1083: }
1.12 albertel 1084: if (typeof(document.mailform.elements.course)!="undefined") {
1.5 www 1085: if (document.mailform.elements.course.checked) {
1086: rec=1;
1087: }
1088: }
1.12 albertel 1089: if (typeof(document.mailform.elements.policy)!="undefined") {
1.5 www 1090: if (document.mailform.elements.policy.checked) {
1091: rec=1;
1092: }
1093: }
1.12 albertel 1094: if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10 www 1095: if (document.mailform.elements.discuss.checked) {
1096: rec=1;
1097: }
1098: }
1.14 www 1099: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
1100: if (document.mailform.elements.anondiscuss.checked) {
1101: rec=1;
1102: }
1103: }
1.5 www 1104:
1105: if (rec) {
1.105 www 1106: if (typeof(document.mailform.onsubmit)!='undefined') {
1107: document.mailform.onsubmit();
1108: }
1.5 www 1109: document.mailform.submit();
1110: } else {
1111: alert('Please check a feedback type.');
1112: }
1113: }
1.108 raeburn 1114: $anonchk
1.102 raeburn 1115: $anonscript
1.63 albertel 1116: //-->
1.5 www 1117: </script>
1.1 www 1118: </head>
1.29 www 1119: $bodytag
1.51 albertel 1120: <h2><tt>$title</tt></h2>
1.43 www 1121: <form action="/adm/feedback" method="post" name="mailform"
1122: enctype="multipart/form-data">
1.80 raeburn 1123: $prevtag
1.63 albertel 1124: <input type="hidden" name="postdata" value="$feedurl" />
1.102 raeburn 1125: END
1126: if ($ENV{'form.replydisc'}) {
1127: $r->print(<<END);
1.68 www 1128: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
1.102 raeburn 1129: END
1130: } elsif ($ENV{'form.editdisc'}) {
1131: $r->print(<<END);
1132: <input type="hidden" name="editdisc" value ="$ENV{'form.editdisc'}" />
1133: <input type="hidden" name="parentmsg" value ="$parentmsg" />
1134: END
1135: }
1.108 raeburn 1136: $r->print(<<END);
1.5 www 1137: Please check at least one of the following feedback types:
1.63 albertel 1138: $options<hr />
1.69 www 1139: $quote
1.63 albertel 1140: <p>My question/comment/feedback:</p>
1141: <p>
1.47 bowersj2 1142: $latexHelp
1.78 raeburn 1143: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
1144: <p>
1.108 raeburn 1145: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$comment
1.63 albertel 1146: </textarea></p>
1147: <p>
1.108 raeburn 1148: END
1149: if ( ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'}) ) {
1150: if ($ENV{'form.origpage'}) {
1151: foreach (@currnewattach) {
1152: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
1153: }
1154: foreach (@currdelold) {
1155: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
1156: }
1157: }
1158: if ($ENV{'form.editdisc'}) {
1159: if ($attachmenturls) {
1.113 raeburn 1160: &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
1.108 raeburn 1161: $attachnum = scalar(keys %currattach);
1162: foreach (keys %currattach) {
1163: $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
1164: }
1165: }
1166: }
1167: } else {
1168: $r->print(<<END);
1.42 www 1169: Attachment (128 KB max size): <input type="file" name="attachment" />
1170: </p>
1.108 raeburn 1171: END
1172: }
1173: $r->print(<<END);
1.42 www 1174: <p>
1175: <input type="hidden" name="sendit" value="1" />
1.74 www 1176: <input type="button" value="$send" onClick='gosubmit();' />
1.42 www 1177: </p>
1.2 www 1178: </form>
1.108 raeburn 1179: END
1180: if ($ENV{'form.editdisc'} || $ENV{'form.replydisc'}) {
1181: my $now = time;
1182: my $ressymb = $symb;
1183: my $postidx = '';
1184: if ($ENV{'form.editdisc'}) {
1185: $postidx = $idx;
1186: }
1187: if (@currnewattach > 0) {
1188: $attachnum += @currnewattach;
1189: }
1190: $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver));
1191: if ($attachnum > 0) {
1192: if (@currnewattach > 0) {
1193: $newattachmsg .= '<b>New attachments</b><br />';
1194: if (@currnewattach > 1) {
1195: $newattachmsg .= '<ol>';
1196: foreach my $item (@currnewattach) {
1197: $item =~ m#.*/([^/]+)$#;
1198: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
1199: }
1200: $newattachmsg .= '</ol>'."\n";
1201: } else {
1202: $currnewattach[0] =~ m#.*/([^/]+)$#;
1203: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
1204: }
1205: }
1206: if ($attachmsg) {
1207: $r->print("<b>Retained attachments</b>:$attachmsg<br />\n");
1208: }
1209: if ($newattachmsg) {
1210: $r->print("$newattachmsg<br />");
1211: }
1212: }
1213: }
1214: $r->print(&generate_preview_button().
1215: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
1216: '</body></html>');
1.6 albertel 1217: }
1218:
1.97 raeburn 1219: sub print_display_options {
1.111 raeburn 1220: my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
1.98 raeburn 1221: # backward compatibility (bulletin boards used to be 'wrapped')
1222: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1223: $feedurl=~s|^/adm/wrapper||;
1224: }
1225:
1.97 raeburn 1226: my $function = &Apache::loncommon::get_users_function();
1227: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1228: $ENV{'user.domain'});
1229: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1230: '','');
1231:
1232: my %lt = &Apache::lonlocal::texthash(
1233: 'dido' => 'Discussion display options',
1234: 'pref' => 'Display Preference',
1235: 'curr' => 'Current setting ',
1236: 'actn' => 'Action',
1237: 'deff' => 'Default for all discussions',
1238: 'prca' => 'Preferences can be set for this discussion that determine ....',
1239: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
1.111 raeburn 1240: 'unwh' => 'Under what circumstances posts are identified as "NEW", and',
1241: 'wipa' => 'Whether individual posts can be marked as read/unread',
1.97 raeburn 1242: 'allposts' => 'All posts',
1243: 'unread' => 'New posts only',
1.111 raeburn 1244: 'unmark' => 'Posts not marked read',
1.97 raeburn 1245: 'ondisp' => 'Once displayed',
1.111 raeburn 1246: 'onmark' => 'Once marked not NEW ',
1247: 'toggon' => 'Shown',
1248: 'toggoff' => 'Not shown',
1.97 raeburn 1249: 'disa' => 'Posts displayed?',
1.111 raeburn 1250: 'npmr' => 'New posts cease to be identified as "NEW"?',
1251: 'dotm' => 'Option to mark each post as read/unread?',
1.97 raeburn 1252: 'chgt' => 'Change to ',
1253: 'mkdf' => 'Set to ',
1.111 raeburn 1254: 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
1.97 raeburn 1255: 'ywbr' => 'You will be returned to the previous page if you click OK.'
1256: );
1257:
1.111 raeburn 1258: my $dispchangeA = $lt{'unread'};
1259: my $dispchangeB = $lt{'unmark'};
1.97 raeburn 1260: my $markchange = $lt{'ondisp'};
1.111 raeburn 1261: my $toggchange = $lt{'toggon'};
1.97 raeburn 1262: my $currdisp = $lt{'allposts'};
1263: my $currmark = $lt{'onmark'};
1264: my $discdisp = 'allposts';
1265: my $discmark = 'onmark';
1.111 raeburn 1266: my $currtogg = $lt{'toggoff'};
1267: my $disctogg = 'toggoff';
1.97 raeburn 1268:
1.111 raeburn 1269: if ($dispchgA eq 'allposts') {
1270: $dispchangeA = $lt{'allposts'};
1.97 raeburn 1271: $currdisp = $lt{'unread'};
1272: $discdisp = 'unread';
1273: }
1.111 raeburn 1274:
1.97 raeburn 1275: if ($markchg eq 'markonread') {
1276: $markchange = $lt{'onmark'};
1277: $currmark = $lt{'ondisp'};
1278: $discmark = 'ondisp';
1279: }
1.111 raeburn 1280:
1281: if ($dispchgB eq 'onlyunread') {
1282: $dispchangeB = $lt{'unread'};
1283: $currdisp = $lt{'unmark'};
1284: $discdisp = 'unmark';
1285: }
1286: if ($toggchg eq 'toggoff') {
1287: $toggchange = $lt{'toggoff'};
1288: $currtogg = $lt{'toggon'};
1289: $disctogg = 'toggon';
1290: }
1.97 raeburn 1291: $r->print(<<END);
1292: <html>
1293: <head>
1294: <title>$lt{'dido'}</title>
1295: <meta http-equiv="pragma" content="no-cache" />
1296: <script>
1.111 raeburn 1297: function discdispChk(caller) {
1298: var disctogg = '$toggchg'
1299: if (caller == 0) {
1300: if (document.modifydisp.discdisp[0].checked == true) {
1301: if (document.modifydisp.discdisp[1].checked == true) {
1302: document.modifydisp.discdisp[1].checked = false
1303: }
1304: }
1305: }
1306: if (caller == 1) {
1307: if (document.modifydisp.discdisp[1].checked == true) {
1308: if (document.modifydisp.discdisp[0].checked == true) {
1309: document.modifydisp.discdisp[0].checked = false
1310: }
1311: if (disctogg == 'toggon') {
1312: document.modifydisp.disctogg.checked = true
1313: }
1314: if (disctogg == 'toggoff') {
1315: document.modifydisp.disctogg.checked = false
1316: }
1317: }
1318: }
1319: if (caller == 2) {
1320: var dispchgB = '$dispchgB'
1321: if (disctogg == 'toggoff') {
1322: if (document.modifydisp.disctogg.checked == true) {
1323: if (dispchgB == 'onlyunmark') {
1324: document.modifydisp.discdisp[1].checked = false
1325: }
1326: }
1327: }
1328: }
1329: }
1330:
1.97 raeburn 1331: function setDisp() {
1332: var prev = "$previous"
1333: var chktotal = 0
1.111 raeburn 1334: if (document.modifydisp.discdisp[0].checked == true) {
1335: document.modifydisp.$dispchgA.value = "$symb"
1336: chktotal ++
1337: }
1338: if (document.modifydisp.discdisp[1].checked == true) {
1339: document.modifydisp.$dispchgB.value = "$symb"
1.97 raeburn 1340: chktotal ++
1341: }
1342: if (document.modifydisp.discmark.checked == true) {
1343: document.modifydisp.$markchg.value = "$symb"
1344: chktotal ++
1345: }
1.111 raeburn 1346: if (document.modifydisp.disctogg.checked == true) {
1347: document.modifydisp.$toggchg.value = "$symb"
1348: chktotal ++
1349: }
1.97 raeburn 1350: if (chktotal > 0) {
1351: document.modifydisp.submit()
1352: } else {
1353: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
1354: if (prev > 0) {
1355: location.href = "$feedurl?previous=$previous"
1356: } else {
1357: location.href = "$feedurl"
1358: }
1359: }
1360: }
1361: }
1362: </script>
1363: </head>
1364: $bodytag
1365: <form name="modifydisp" method="post" action="/adm/feedback">
1.111 raeburn 1366: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
1.97 raeburn 1367: <br />
1368: <table border="0" cellpadding="0" cellspacing="0">
1369: <tr>
1370: <td width="100%" bgcolor="#000000">
1371: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1372: <tr>
1373: <td width="100%" bgcolor="#000000">
1374: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
1375: <tr bgcolor="$tabcolor">
1376: <td><b>$lt{'pref'}</b></td>
1377: <td><b>$lt{'curr'}</b></td>
1378: <td><b>$lt{'actn'}?</b></td>
1379: </tr>
1380: <tr bgcolor="#dddddd">
1381: <td>$lt{'disa'}</td>
1382: <td>$lt{$discdisp}</td>
1.111 raeburn 1383: <td><input type="checkbox" name="discdisp" onClick="discdispChk('0')" /> $lt{'chgt'} "$dispchangeA"
1384: <br />
1385: <input type="checkbox" name="discdisp" onClick="discdispChk('1')" /> $lt{'chgt'} "$dispchangeB"
1386: </td>
1.97 raeburn 1387: </tr><tr bgcolor="#eeeeee">
1388: <td>$lt{'npmr'}</td>
1389: <td>$lt{$discmark}</td>
1390: <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
1.111 raeburn 1391: </tr><tr bgcolor="#dddddd">
1392: <td>$lt{'dotm'}</td>
1393: <td>$lt{$disctogg}</td>
1394: <td><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</td>
1.97 raeburn 1395: </tr>
1396: </table>
1397: </td>
1398: </tr>
1399: </table>
1400: </td>
1401: </tr>
1402: </table>
1403: <br />
1404: <br />
1405: <input type="hidden" name="previous" value="$previous" />
1.111 raeburn 1406: <input type="hidden" name="$dispchgA" value=""/>
1407: <input type="hidden" name="$dispchgB" value=""/>
1.97 raeburn 1408: <input type="hidden" name="$markchg" value=""/>
1.111 raeburn 1409: <input type="hidden" name="$toggchg" value="" />
1.97 raeburn 1410: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
1411: <br />
1412: <br />
1413: </form>
1414: </body>
1415: </html>
1416: END
1417: return;
1418: }
1419:
1.100 raeburn 1420: sub print_sortfilter_options {
1421: my ($r,$symb,$previous,$feedurl) = @_;
1422: # backward compatibility (bulletin boards used to be 'wrapped')
1423: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1424: $feedurl=~s|^/adm/wrapper||;
1425: }
1426: my @sections = ();
1427: my $section_sel = '';
1428: my $numsections = 0;
1429: my $numvisible = 5;
1430: my ($classlist) = &Apache::loncoursedata::get_classlist(
1431: $ENV{'request.course.id'},
1432: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1433: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1434:
1435: my $sec_index = &Apache::loncoursedata::CL_SECTION();
1436: my $status_index = &Apache::loncoursedata::CL_STATUS();
1437: my %sectioncount = ();
1438: while (my ($student,$data) = each %$classlist) {
1439: my ($section,$status) = ($data->[$sec_index],
1440: $data->[$status_index]);
1441: unless ($section eq '' || $section =~ /^\s*$/) {
1442: if (!defined($sectioncount{$section})) {
1443: $sectioncount{$section} = 1;
1444: $numsections ++;
1445: } else {
1446: $sectioncount{$section} ++;
1447: }
1448: }
1449: }
1450:
1451: if ($ENV{'request.course.sec'} !~ /^\s*$/) {
1452: @sections = ($ENV{'request.course.sec'});
1453: $numvisible = 1;
1454: } else {
1455: @sections = sort {$a cmp $b} keys(%sectioncount);
1456: unshift(@sections,'all'); # Put 'all' at the front of the list
1457: if ($numsections < 4) {
1458: $numvisible = $numsections + 1;
1459: }
1460: }
1461: foreach (@sections) {
1462: $section_sel .= " <option value=\"$_\" />$_\n";
1463: }
1464:
1465: my $function = &Apache::loncommon::get_users_function();
1466: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1467: $ENV{'user.domain'});
1468: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1469: '','');
1470: my %lt = &Apache::lonlocal::texthash(
1471: 'diso' => 'Discussion sorting and filtering options',
1472: 'diop' => 'Display Options',
1473: 'curr' => 'Current setting ',
1474: 'actn' => 'Action',
1.101 raeburn 1475: 'prca' => 'Options can be set that control the sort order of the posts, in addition to which posts are displayed.',
1.100 raeburn 1476: 'soor' => 'Sort order',
1477: 'disp' => 'Specific user roles',
1478: 'actv' => 'Specific role status',
1479: 'spse' => 'Specific sections',
1480: 'psub' => 'Pick specific users (by name)',
1.101 raeburn 1481: 'shal' => 'Show a list of current posters'
1.100 raeburn 1482: );
1483: $r->print(<<END);
1484: <html>
1485: <head>
1486: <title>$lt{'diso'}</title>
1487: <meta http-equiv="pragma" content="no-cache" />
1488: </head>
1489: $bodytag
1490: <form name="modifyshown" method="post" action="/adm/feedback">
1491: <b>$lt{'diso'}</b><br/> $lt{'prca'}
1492: <br /><br />
1493: <table border="0">
1494: <tr>
1495: <td><b>$lt{'soor'}</b></td>
1496: <td> </td>
1497: <td><b>$lt{'disp'}</b></td>
1498: <td> </td>
1499: <td><b>$lt{'actv'}</b></td>
1500: <td> </td>
1501: <td><b>$lt{'spse'}</b></td>
1502: <td> </td>
1503: <td><b>$lt{'psub'}</b></td>
1504: </tr>
1505: <tr>
1506: <td>
1507: <select name="sortposts">
1508: <option value="ascdate" />Date order - oldest first
1509: <option value="descdate" />Date order - newest first
1510: <option value="thread" />Threaded
1511: <option value="subject" />By subject
1512: <option value="username" />By domain and username
1513: <option value="lastfirst" />By last name, first name
1514: </select>
1515: </td>
1516: <td> </td>
1517: <td>
1.101 raeburn 1518: <select name="rolefilter" multiple="true" size="5">
1.100 raeburn 1519: <option value="all" />All users
1520: <option value="st" />Students
1521: <option value="cc" />Course Coordinators
1522: <option value="in" />Instructors
1523: <option value="ta" />TAs
1524: <option value="pr" />Exam proctors
1525: <option value="cr" />Custom roles
1526: </select>
1527: </td>
1528: <td> </td>
1529: <td>
1530: <select name="statusfilter">
1531: <option value="all" />Roles of any status
1.101 raeburn 1532: <option value="Active" />Only active roles
1533: <option value="Expired" />Only inactive roles
1.100 raeburn 1534: </select>
1535: </td>
1536: <td> </td>
1537: <td>
1538: <select name="sectionpick" multiple="true" size="$numvisible">
1539: $section_sel
1540: </select>
1541: </td>
1542: <td> </td>
1543: <td><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</td>
1544: </tr>
1545: </table>
1546: <br />
1547: <br />
1548: <input type="hidden" name="previous" value="$previous" />
1549: <input type="hidden" name="applysort" value="$symb" />
1550: <input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
1551: <br />
1552: <br />
1553: </form>
1554: </body>
1555: </html>
1556: END
1557: }
1558:
1.101 raeburn 1559: sub print_showposters {
1560: my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
1561: # backward compatibility (bulletin boards used to be 'wrapped')
1562: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1563: $feedurl=~s|^/adm/wrapper||;
1564: }
1565: # backward compatibility (bulletin boards used to be 'wrapped')
1566: my $ressymb=$symb;
1567: if ($ressymb =~ /bulletin___\d+___/) {
1568: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1569: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1570: }
1571: }
1572: my $crs='/'.$ENV{'request.course.id'};
1.102 raeburn 1573: if ($ENV{'request.course.sec'}) {
1574: $crs.='_'.$ENV{'request.course.sec'};
1575: }
1.101 raeburn 1576: $crs=~s/\_/\//g;
1577: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1578: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1579: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1580: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1581: my %namesort = ();
1582: my %postcounts = ();
1583: my %lt=&Apache::lonlocal::texthash(
1584: 'diso' => 'Discussion filtering options',
1585: );
1586: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1587: '','');
1588: if ($contrib{'version'}) {
1589: for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
1590: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1591: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1592: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1593: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
1594: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
1595: my $lastname = $names{'lastname'};
1596: my $firstname = $names{'firstname'};
1597: if ($lastname eq '') {
1598: $lastname = '_';
1599: }
1600: if ($firstname eq '') {
1601: $firstname = '_';
1602: }
1603: unless (defined($namesort{$lastname})) {
1604: %{$namesort{$lastname}} = ();
1605: }
1606: my $poster = $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
1607: $postcounts{$poster} ++;
1608: if (defined($namesort{$lastname}{$firstname})) {
1609: if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
1610: push @{$namesort{$lastname}{$firstname}}, $poster;
1611: }
1612: } else {
1613: @{$namesort{$lastname}{$firstname}} = ("$poster");
1614: }
1615: }
1616: }
1617: }
1618: }
1619: $r->print(<<END);
1620: <html>
1621: <head>
1622: <title>$lt{'diso'}</title>
1623: <meta http-equiv="pragma" content="no-cache" />
1624: </head>
1625: $bodytag
1626: <form name="pickpostersform" method="post">
1627: <table border="0">
1628: <tr>
1629: <td bgcolor="#777777">
1630: <table border="0" cellpadding="3">
1631: <tr bgcolor="#e6ffff">
1632: <td><b>No.</b></td>
1633: <td><b>Select</b></td>
1634: <td><b>Fullname</b><font color="#999999">(Username/domain)</font></td>
1635: <td><b>Posts</td>
1636: </tr>
1637: END
1638: my $count = 0;
1639: foreach my $last (sort keys %namesort) {
1640: foreach my $first (sort keys %{$namesort{$last}}) {
1641: foreach (sort @{$namesort{$last}{$first}}) {
1642: my ($uname,$udom) = split/:/,$_;
1643: if (!$uname || !$udom) {
1644: next;
1645: } else {
1646: $count ++;
1647: $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>');
1648: }
1649: }
1650: }
1651: }
1652: $r->print(<<END);
1653: </table>
1654: </td>
1655: </tr>
1656: </table>
1657: <br />
1658: <input type="hidden" name="sortposts" value="$sortposts" />
1659: <input type="hidden" name="userpick" value="$symb" />
1660: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
1661: </form>
1662: </body>
1663: </html>
1664: END
1665: }
1666:
1.112 raeburn 1667: sub get_post_versions {
1668: my ($versions,$incoming,$numver) = @_;
1669: my $p = HTML::LCParser->new(\$incoming);
1670: my $done = 0;
1671: while ( (my $token = $p->get_tag("version")) && (!$done)) {
1672: my $num = $token->[1]{num};
1673: my $text = $p->get_text("/version");
1674: if (defined($numver)) {
1675: if ($num == $numver) {
1676: $$versions{$numver}=$text;
1677: $done = 1;
1678: }
1679: } else {
1680: $$versions{$num}=$text;
1681: }
1682: }
1683: return;
1684: }
1685:
1.113 raeburn 1686: sub get_post_attachments {
1687: my ($attachments,$attachmenturls) = @_;
1688: my $num;
1689: my $p = HTML::LCParser->new(\$attachmenturls);
1690: while (my $token = $p->get_tag("attachment","filename","post")) {
1691: if ($token->[0] eq "attachment") {
1692: $num = $token->[1]{id};
1693: %{$$attachments{$num}} =();
1694: } elsif ($token->[0] eq "filename") {
1695: $$attachments{$num}{'filename'} = $p->get_text("/filename");
1696: } elsif ($token->[0] eq "post") {
1697: my $id = $token->[1]{id};
1698: $$attachments{$num}{$id} = $p->get_text("/post");
1699: }
1700: }
1701: return;
1702: }
1703:
1704: sub fail_redirect {;
1.6 albertel 1705: my ($r,$feedurl) = @_;
1.70 www 1706: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.6 albertel 1707: $r->print (<<ENDFAILREDIR);
1.72 albertel 1708: <html>
1.5 www 1709: <head><title>Feedback not sent</title>
1.63 albertel 1710: <meta http-equiv="pragma" content="no-cache" />
1711: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5 www 1712: </head>
1713: <body bgcolor="#FFFFFF">
1.63 albertel 1714: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8 www 1715: <b>Sorry, no recipients ...</b>
1.5 www 1716: </body>
1717: </html>
1718: ENDFAILREDIR
1719: }
1.4 www 1720:
1.6 albertel 1721: sub redirect_back {
1.101 raeburn 1722: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$secpick,$numpicks) = @_;
1.100 raeburn 1723: my $sorttag = '';
1.101 raeburn 1724: my $roletag = '';
1725: my $statustag = '';
1726: my $sectag = '';
1727: my $userpicktag = '';
1728: my $qrystr = '';
1.80 raeburn 1729: my $prevtag = '';
1.98 raeburn 1730: # backward compatibility (bulletin boards used to be 'wrapped')
1731: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1732: $feedurl=~s|^/adm/wrapper||;
1733: }
1.70 www 1734: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 1735: if ($previous > 0) {
1736: $qrystr = 'previous='.$previous;
1737: if ($feedurl =~ /\?register=1/) {
1738: $feedurl .= '&'.$qrystr;
1739: } else {
1740: $feedurl .= '?'.$qrystr;
1741: }
1742: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
1743: }
1.100 raeburn 1744: if (defined($sort)) {
1745: my $sortqry = 'sortposts='.$sort;
1746: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
1747: $feedurl .= '&'.$sortqry;
1748: } else {
1749: $feedurl .= '?'.$sortqry;
1750: }
1751: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.101 raeburn 1752: if ( (defined($numpicks)) && ($numpicks > 0) ) {
1753: my $userpickqry = 'totposters='.$numpicks;
1754: $feedurl .= '&'.$userpickqry;
1755: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
1756: } else {
1757: my $roleqry = 'rolefilter='.$rolefilter;
1758: $feedurl .= '&'.$roleqry;
1759: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
1760: $feedurl .= '&statusfilter='.$statusfilter;
1761: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
1762: $feedurl .= '§ionpick='.$secpick;
1763: $sectag = '<input type="hidden" name="sectionpick" value="'.$secpick.'" />';
1764: }
1.100 raeburn 1765: }
1.6 albertel 1766: $r->print (<<ENDREDIR);
1.72 albertel 1767: <html>
1.3 www 1768: <head>
1769: <title>Feedback sent</title>
1.63 albertel 1770: <meta http-equiv="pragma" content="no-cache" />
1.80 raeburn 1771: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2 www 1772: </head>
1.49 www 1773: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63 albertel 1774: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5 www 1775: $typestyle
1.32 albertel 1776: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63 albertel 1777: <font color="red">$status</font>
1.49 www 1778: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 1779: $prevtag
1.100 raeburn 1780: $sorttag
1.101 raeburn 1781: $statustag
1782: $roletag
1783: $sectag
1784: $userpicktag
1.49 www 1785: </form>
1.2 www 1786: </body>
1787: </html>
1788: ENDREDIR
1789: }
1.6 albertel 1790:
1791: sub no_redirect_back {
1792: my ($r,$feedurl) = @_;
1.107 www 1793: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.6 albertel 1794: $r->print (<<ENDNOREDIR);
1.72 albertel 1795: <html>
1.2 www 1796: <head><title>Feedback not sent</title>
1.63 albertel 1797: <meta http-equiv="pragma" content="no-cache" />
1.7 albertel 1798: ENDNOREDIR
1799:
1.8 www 1800: if ($feedurl!~/^\/adm\/feedback/) {
1.7 albertel 1801: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
1802: }
1803:
1.8 www 1804: $r->print (<<ENDNOREDIRTWO);
1.2 www 1805: </head>
1.49 www 1806: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63 albertel 1807: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.107 www 1808: <b>$nofeed</b>
1.2 www 1809: </body>
1810: </html>
1.8 www 1811: ENDNOREDIRTWO
1.2 www 1812: }
1.6 albertel 1813:
1814: sub screen_header {
1.65 www 1815: my ($feedurl) = @_;
1816: my $msgoptions='';
1817: my $discussoptions='';
1.102 raeburn 1818: unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
1.65 www 1819: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
1820: $msgoptions=
1821: '<p><input type="checkbox" name="author" /> '.
1822: &mt('Feedback to resource author').'</p>';
1823: }
1824: if (&feedback_available(1)) {
1825: $msgoptions.=
1826: '<br /><input type="checkbox" name="question" /> '.
1827: &mt('Question about resource content');
1828: }
1829: if (&feedback_available(0,1)) {
1830: $msgoptions.=
1831: '<br /><input type="checkbox" name="course" /> '.
1832: &mt('Question/Comment/Feedback about course content');
1833: }
1834: if (&feedback_available(0,0,1)) {
1835: $msgoptions.=
1836: '<br /><input type="checkbox" name="policy" /> '.
1837: &mt('Question/Comment/Feedback about course policy');
1838: }
1839: }
1840: if ($ENV{'request.course.id'}) {
1.92 albertel 1841: if (&discussion_open() &&
1.90 albertel 1842: &Apache::lonnet::allowed('pch',
1.65 www 1843: $ENV{'request.course.id'}.
1844: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74 www 1845: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
1846: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65 www 1847: &mt('Contribution to course discussion of resource');
1848: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
1849: &mt('Anonymous contribution to course discussion of resource').
1850: ' <i>('.&mt('name only visible to course faculty').')</i>';
1.20 www 1851: }
1.65 www 1852: }
1.74 www 1853: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 1854: if ($discussoptions) {
1.74 www 1855: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 1856: return $msgoptions.$discussoptions;
1.6 albertel 1857: }
1858:
1859: sub resource_output {
1860: my ($feedurl) = @_;
1.46 albertel 1861: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 1862: $usersaw=~s/\<body[^\>]*\>//gi;
1863: $usersaw=~s/\<\/body\>//gi;
1864: $usersaw=~s/\<html\>//gi;
1865: $usersaw=~s/\<\/html\>//gi;
1866: $usersaw=~s/\<head\>//gi;
1867: $usersaw=~s/\<\/head\>//gi;
1868: $usersaw=~s/action\s*\=/would_be_action\=/gi;
1869: return $usersaw;
1870: }
1871:
1872: sub clear_out_html {
1.39 www 1873: my ($message,$override)=@_;
1.88 www 1874: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107 www 1875: # Always allow the <m>-tag
1876: my %html=(M=>1);
1877: # Check if more is allowed
1.37 albertel 1878: my $cid=$ENV{'request.course.id'};
1.39 www 1879: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
1880: ($override)) {
1.37 albertel 1881: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 1882: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
1883: # <SUP>
1.107 www 1884: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
1885: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
1886: M=>1, SUB=>1, SUP=>1, SPAN=>1,
1887: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
1888: }
1889: # Do the substitution of everything that is not explicitly allowed
1890: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48 albertel 1891: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.107 www 1892: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48 albertel 1893: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.6 albertel 1894: return $message;
1895: }
1896:
1897: sub assemble_email {
1.40 albertel 1898: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 1899: my $email=<<"ENDEMAIL";
1900: Refers to <a href="$feedurl">$feedurl</a>
1901:
1902: $message
1903: ENDEMAIL
1904: my $citations=<<"ENDCITE";
1905: <h2>Previous attempts of student (if applicable)</h2>
1906: $prevattempts
1.63 albertel 1907: <br /><hr />
1.6 albertel 1908: <h2>Original screen output (if applicable)</h2>
1909: $usersaw
1.40 albertel 1910: <h2>Correct Answer(s) (if applicable)</h2>
1911: $useranswer
1.6 albertel 1912: ENDCITE
1913: return ($email,$citations);
1914: }
1915:
1.35 www 1916: sub secapply {
1917: my $rec=shift;
1.36 www 1918: my $defaultflag=shift;
1919: $rec=~s/\s+//g;
1920: $rec=~s/\@/\:/g;
1921: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
1922: if ($sections) {
1923: foreach (split(/\;/,$sections)) {
1924: if (($_ eq $ENV{'request.course.sec'}) ||
1925: ($defaultflag && ($_ eq '*'))) {
1926: return $adr;
1927: }
1928: }
1929: } else {
1930: return $rec;
1931: }
1932: return '';
1.35 www 1933: }
1934:
1.6 albertel 1935: sub decide_receiver {
1.36 www 1936: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 1937: my $typestyle='';
1938: my %to=();
1.36 www 1939: if ($ENV{'form.author'}||$author) {
1.8 www 1940: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 1941: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
1942: $to{$2.':'.$1}=1;
1943: }
1.36 www 1944: if ($ENV{'form.question'}||$question) {
1.8 www 1945: $typestyle.='Submitting as Question<br>';
1.24 harris41 1946: foreach (split(/\,/,
1947: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
1948: ) {
1.36 www 1949: my $rec=&secapply($_,$defaultflag);
1950: if ($rec) { $to{$rec}=1; }
1.24 harris41 1951: }
1.6 albertel 1952: }
1.36 www 1953: if ($ENV{'form.course'}||$course) {
1.63 albertel 1954: $typestyle.='Submitting as Comment<br />';
1.24 harris41 1955: foreach (split(/\,/,
1956: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
1957: ) {
1.36 www 1958: my $rec=&secapply($_,$defaultflag);
1959: if ($rec) { $to{$rec}=1; }
1.24 harris41 1960: }
1.6 albertel 1961: }
1.36 www 1962: if ($ENV{'form.policy'}||$policy) {
1.63 albertel 1963: $typestyle.='Submitting as Policy Feedback<br />';
1.24 harris41 1964: foreach (split(/\,/,
1965: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
1966: ) {
1.36 www 1967: my $rec=&secapply($_,$defaultflag);
1968: if ($rec) { $to{$rec}=1; }
1.24 harris41 1969: }
1.6 albertel 1970: }
1.36 www 1971: if ((scalar(%to) eq '0') && (!$defaultflag)) {
1972: ($typestyle,%to)=
1973: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
1974: }
1.6 albertel 1975: return ($typestyle,%to);
1.36 www 1976: }
1977:
1978: sub feedback_available {
1979: my ($question,$course,$policy)=@_;
1980: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
1981: return scalar(%to);
1.6 albertel 1982: }
1983:
1984: sub send_msg {
1.43 www 1985: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 1986: my $status='';
1987: my $sendsomething=0;
1.24 harris41 1988: foreach (keys %to) {
1.6 albertel 1989: if ($_) {
1.22 www 1990: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 1991: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43 www 1992: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
1993: $attachmenturl)=~/ok/) {
1.63 albertel 1994: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 1995: } else {
1996: $sendsomething++;
1997: }
1998: }
1.24 harris41 1999: }
1.18 www 2000:
2001: my %record=&Apache::lonnet::restore('_feedback');
2002: my ($temp)=keys %record;
2003: unless ($temp=~/^error\:/) {
2004: my %newrecord=();
2005: $newrecord{'resource'}=$feedurl;
2006: $newrecord{'subnumber'}=$record{'subnumber'}+1;
2007: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63 albertel 2008: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 2009: }
2010: }
2011:
1.6 albertel 2012: return ($status,$sendsomething);
2013: }
2014:
1.13 www 2015: sub adddiscuss {
1.78 raeburn 2016: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 2017: my $status='';
1.92 albertel 2018: if (&discussion_open() &&
1.90 albertel 2019: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1.23 www 2020: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20 www 2021:
1.13 www 2022: my %contrib=('message' => $email,
2023: 'sendername' => $ENV{'user.name'},
1.26 www 2024: 'senderdomain' => $ENV{'user.domain'},
2025: 'screenname' => $ENV{'environment.screenname'},
2026: 'plainname' => $ENV{'environment.firstname'}.' '.
2027: $ENV{'environment.middlename'}.' '.
2028: $ENV{'environment.lastname'}.' '.
1.42 www 2029: $ENV{'enrironment.generation'},
1.78 raeburn 2030: 'attachmenturl'=> $attachmenturl,
2031: 'subject' => $subject);
1.65 www 2032: if ($ENV{'form.replydisc'}) {
1.66 www 2033: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65 www 2034: }
1.14 www 2035: if ($anon) {
2036: $contrib{'anonymous'}='true';
2037: }
1.13 www 2038: if (($symb) && ($email)) {
1.102 raeburn 2039: if ($ENV{'form.editdisc'}) {
2040: my %newcontrib = ();
2041: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
2042: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
2043: $contrib{'timestamp'} = time;
2044: $contrib{'history'} = '';
2045: my $numoldver = 0;
2046: my ($oldsymb,$oldidx)=split(/\:\:\:/,$ENV{'form.editdisc'});
1.110 raeburn 2047: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2048: # get timestamp for last post and history
2049: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
2050: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2051: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2052: if (defined($oldcontrib{$oldidx.':replyto'})) {
2053: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2054: }
2055: if (defined($oldcontrib{$oldidx.':history'})) {
2056: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2057: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2058: $numoldver = @oldversions;
2059: } else {
2060: $numoldver = 1;
2061: }
2062: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2063: }
1.108 raeburn 2064: my $numnewver = $numoldver + 1;
1.102 raeburn 2065: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 raeburn 2066: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
2067: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
2068: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2069: } else {
1.112 raeburn 2070: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2071: }
1.102 raeburn 2072: }
2073: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 raeburn 2074: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
2075: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
2076: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2077: } else {
1.112 raeburn 2078: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2079: }
1.102 raeburn 2080: }
2081: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
2082: foreach (keys %contrib) {
2083: my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;
2084: $newcontrib{$key} = $contrib{$_};
2085: }
2086: my $put_reply = &Apache::lonnet::putstore($ENV{'request.course.id'},
2087: \%newcontrib,
2088: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2089: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2090: $status='Editing class discussion'.($anon?' (anonymous)':'');
2091: } else {
2092: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
2093: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1.13 www 2094: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17 www 2095: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.102 raeburn 2096: }
1.21 www 2097: my %storenewentry=($symb => time);
1.63 albertel 2098: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2099: &Apache::lonnet::put('discussiontimes',\%storenewentry,
2100: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2101: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13 www 2102: }
1.17 www 2103: my %record=&Apache::lonnet::restore('_discussion');
2104: my ($temp)=keys %record;
2105: unless ($temp=~/^error\:/) {
2106: my %newrecord=();
2107: $newrecord{'resource'}=$symb;
2108: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2109: $status.='<br />'.&mt('Registering').': '.
1.21 www 2110: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2111: }
2112: } else {
2113: $status.='Failed.';
1.17 www 2114: }
1.63 albertel 2115: return $status.'<br />';
1.13 www 2116: }
2117:
1.33 www 2118: # ----------------------------------------------------------- Preview function
2119:
2120: sub show_preview {
2121: my $r=shift;
2122: my $message=&clear_out_html($ENV{'form.comment'});
2123: $message=~s/\n/\<br \/\>/g;
1.106 www 2124: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2125: $message=&Apache::lontexconvert::msgtexconverted($message);
1.78 raeburn 2126: my $subject=&clear_out_html($ENV{'form.subject'});
2127: $subject=~s/\n/\<br \/\>/g;
2128: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33 www 2129: $r->print('<table border="2"><tr><td>'.
1.78 raeburn 2130: '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33 www 2131: $message.'</td></tr></table>');
2132: }
2133:
2134: sub generate_preview_button {
1.107 www 2135: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2136: return(<<ENDPREVIEW);
2137: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2138: <input type="hidden" name="subject">
1.33 www 2139: <input type="hidden" name="comment" />
1.65 www 2140: <input type="button" value="$pre"
1.105 www 2141: 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 2142: </form>
2143: ENDPREVIEW
2144: }
1.71 www 2145:
1.108 raeburn 2146: sub modify_attachments {
2147: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
2148: my $subject=&clear_out_html($ENV{'form.subject'});
2149: $subject=~s/\n/\<br \/\>/g;
2150: $subject=&Apache::lontexconvert::msgtexconverted($subject);
2151: my $timestamp=$ENV{'form.timestamp'};
2152: my $numoldver=$ENV{'form.numoldver'};
2153: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
2154: '','');
2155: my $msg = '';
1.113 raeburn 2156: my %attachments = ();
1.108 raeburn 2157: my %currattach = ();
2158: if ($idx) {
1.113 raeburn 2159: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108 raeburn 2160: }
2161: $r->print(<<END);
2162: <html>
2163: <head>
2164: <title>Managing Attachments</title>
2165: <script>
2166: function setAction () {
2167: document.modattachments.action = document.modattachments.origpage.value;
2168: document.modattachments.submit();
2169: }
2170: </script>
2171: </head>
2172: $bodytag
2173: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2174: <table border="2">
2175: <tr>
2176: <td>
2177: <b>Subject:</b>$subject</b><br /><br />
2178: END
2179: if ($idx) {
2180: if ($attachmenturls) {
2181: my @currold = keys %currattach;
2182: if (@currold > 0) {
2183: $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");
1.113 raeburn 2184: foreach my $id (@currold) {
2185: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
2186: $attachurl =~ m#/([^/]+)$#;
2187: $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'<br />'."\n");
1.108 raeburn 2188: }
2189: $r->print("<br />");
2190: }
2191: }
2192: }
2193: if (@{$currnewattach} > 0) {
2194: $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");
2195: foreach (@{$currnewattach}) {
2196: $_ =~ m#/([^/]+)$#;
2197: $r->print('<input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'<br />'."\n");
2198: }
2199: $r->print("<br />");
2200: }
2201: $r->print(<<END);
2202: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2203: </td>
2204: </tr>
2205: </table>
2206: <input type="hidden" name="subject" value="$ENV{'form.subject'}" />
2207: <input type="hidden" name="comment" value="$ENV{'form.comment'}" />
2208: <input type="hidden" name="timestamp" value="$ENV{'form.timestamp'}" />
2209: <input type="hidden" name="idx" value="$ENV{'form.idx'}" />
2210: <input type="hidden" name="numoldver" value="$ENV{'form.numoldver'}" />
2211: <input type="hidden" name="origpage" value="$ENV{'form.origpage'}" />
2212: <input type="hidden" name="anondiscuss" value="$ENV{'form.anondiscuss'}" />
2213: <input type="hidden" name="discuss" value="$ENV{'form.discuss'}" />
2214: END
2215: foreach (@{$currnewattach}) {
2216: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2217: }
2218: foreach (@{$currdelold}) {
2219: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2220: }
2221: $r->print(<<END);
2222: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2223: </form>
2224: </body>
2225: </html>
2226: END
2227: return;
2228: }
2229:
2230: sub process_attachments {
2231: my ($currnewattach,$currdelold,$keepold) = @_;
2232: if (exists($ENV{'form.currnewattach'})) {
2233: if (ref($ENV{'form.currnewattach'}) eq 'ARRAY') {
2234: @{$currnewattach} = @{$ENV{'form.currnewattach'}};
2235: } else {
2236: $$currnewattach[0] = $ENV{'form.currnewattach'};
2237: }
2238: }
2239: if (exists($ENV{'form.deloldattach'})) {
2240: if (ref($ENV{'form.deloldattach'}) eq 'ARRAY') {
2241: @{$currdelold} = @{$ENV{'form.deloldattach'}};
2242: } else {
2243: $$currdelold[0] = $ENV{'form.deloldattach'};
2244: }
2245: }
2246: if (exists($ENV{'form.delnewattach'})) {
2247: my @currdelnew = ();
2248: my @currnew = ();
2249: if (ref($ENV{'form.delnewattach'}) eq 'ARRAY') {
2250: @currdelnew = @{$ENV{'form.delnewattach'}};
2251: } else {
2252: $currdelnew[0] = $ENV{'form.delnewattach'};
2253: }
2254: foreach my $newone (@{$currnewattach}) {
2255: my $delflag = 0;
2256: foreach (@currdelnew) {
2257: if ($newone eq $_) {
2258: $delflag = 1;
2259: last;
2260: }
2261: }
2262: unless ($delflag) {
2263: push @currnew, $newone;
2264: }
2265: }
2266: @{$currnewattach} = @currnew;
2267: }
2268: if (exists($ENV{'form.keepold'})) {
2269: if (ref($ENV{'form.keepold'}) eq 'ARRAY') {
2270: @{$keepold} = @{$ENV{'form.keepold'}};
2271: } else {
2272: $$keepold[0] = $ENV{'form.keepold'};
2273: }
2274: }
2275: }
2276:
2277: sub generate_attachments_button {
2278: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2279: my $origpage = $ENV{'REQUEST_URI'};
2280: my $att=$attachnum.' '.&mt("attachments");
2281: my $response = (<<END);
2282: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2283: Click to add/remove attachments: <input type="button" value="$att"
2284: onClick="this.form.subject.value=document.mailform.subject.value;this.form.comment.value=document.mailform.comment.value;
2285: END
2286: unless ($mode eq 'board') {
2287: $response .= 'javascript:anonchk();';
2288: }
2289: $response .= (<<ENDATTACH);
2290: this.form.submit();" />
2291: <input type="hidden" name="origpage" value="$origpage" />
2292: <input type="hidden" name="idx" value="$idx" />
2293: <input type="hidden" name="timestamp" value="$now" />
2294: <input type="hidden" name="subject" />
2295: <input type="hidden" name="comment" />
2296: <input type="hidden" name="anondiscuss" value = "0";
2297: <input type="hidden" name="discuss" value = "0";
2298: <input type="hidden" name="numoldver" value="$numoldver" />
2299: ENDATTACH
2300: if (defined($deloldattach)) {
2301: if (@{$deloldattach} > 0) {
2302: foreach (@{$deloldattach}) {
2303: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
2304: }
2305: }
2306: }
2307: if (defined($currnewattach)) {
2308: if (@{$currnewattach} > 0) {
2309: foreach (@{$currnewattach}) {
2310: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
2311: }
2312: }
2313: }
2314: $response .= '</form>';
2315: return $response;
2316: }
2317:
2318: sub extract_attachments {
2319: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.113 raeburn 2320: if ($attachmenturls =~ m/^<attachment id="0">/) {
2321: &get_post_attachments($attachments,$attachmenturls);
2322: foreach my $id (sort keys %{$attachments}) {
2323: if (exists($$attachments{$id}{$numoldver})) {
2324: if (defined($currdelold)) {
2325: if (@{$currdelold} > 0) {
2326: unless (grep/^$id$/,@{$currdelold}) {
2327: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2328: }
2329: } else {
1.113 raeburn 2330: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2331: }
1.113 raeburn 2332: } else {
2333: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2334: }
2335: }
2336: }
2337: my @attached = (sort { $a <=> $b } keys %{$currattach});
2338: if (@attached == 1) {
2339: my $id = $attached[0];
1.113 raeburn 2340: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
2341: $attachurl=~m|/([^/]+)$|;
2342: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
1.108 raeburn 2343: $1.'</tt></a><br />';
2344: &Apache::lonnet::allowuploaded('/adm/feedback',
1.113 raeburn 2345: $attachurl);
1.108 raeburn 2346: } elsif (@attached > 1) {
2347: $$message.='<ol>';
2348: foreach (@attached) {
2349: my $id = $_;
1.113 raeburn 2350: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.108 raeburn 2351: my ($fname)
1.113 raeburn 2352: =($attachurl=~m|/([^/]+)$|);
2353: $$message .= '<li><a href="'.$attachurl.
1.108 raeburn 2354: '"><tt>'.
2355: $fname.'</tt></a></li>';
2356: &Apache::lonnet::allowuploaded('/adm/feedback',
1.113 raeburn 2357: $attachurl);
1.108 raeburn 2358: }
2359: $$message .= '</ol><br />';
2360: }
2361: } else {
2362: my ($fname)
2363: =($attachmenturls=~m|/([^/]+)$|);
2364: $$message .='<p>'.&mt('Attachment').
2365: ': <a href="'.$attachmenturls.
2366: '"><tt>'.
2367: $fname.'</tt></a></p>';
1.113 raeburn 2368: $$attachments{0} = $attachmenturls;
1.108 raeburn 2369: $$currattach{'0'} = 'n';
2370: &Apache::lonnet::allowuploaded('/adm/feedback',
2371: $attachmenturls);
2372: }
2373: }
2374:
2375: sub construct_attachmenturl {
2376: my ($currnewattach,$keepold,$symb,$idx)=@_;
2377: my $oldattachmenturl;
2378: my $newattachmenturl;
1.113 raeburn 2379: my $startnum = 0;
1.108 raeburn 2380: my $currver = 0;
2381: if (($ENV{'form.editdisc'}) && ($idx)) {
2382: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2383: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2384: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2385: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
2386: if ($contrib{$idx.':history'}) {
2387: if ($contrib{$idx.':history'} =~ /:/) {
2388: my @oldversions = split/:/,$contrib{$idx.':history'};
2389: $currver = 1 + scalar(@oldversions);
2390: } else {
2391: $currver = 2;
2392: }
2393: } else {
2394: $currver = 1;
2395: }
2396: if ($oldattachmenturl) {
1.113 raeburn 2397: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
2398: my %attachments = ();
2399: my $prevver = $currver-1;
2400: &get_post_attachments(\%attachments,$oldattachmenturl);
2401: my $numattach = keys %attachments;
2402: $startnum += $numattach;
2403: foreach my $num (sort {$a <=> $b} keys %attachments) {
2404: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
2405: foreach (sort {$a <=> $b} keys %{$attachments{$num}}) {
2406: $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
2407: }
2408: if (grep/^$num$/,@{$keepold}) {
2409: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108 raeburn 2410: }
1.113 raeburn 2411: $newattachmenturl .= '</attachment>';
1.108 raeburn 2412: }
2413: } else {
1.113 raeburn 2414: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'<post id="0">n</post>';
1.108 raeburn 2415: unless (grep/^0$/,@{$keepold}) {
1.113 raeburn 2416: $newattachmenturl .= '<post id="1">n</post>';
1.108 raeburn 2417: }
1.113 raeburn 2418: $newattachmenturl .= '</attachment>';
1.108 raeburn 2419: $startnum ++;
2420: }
2421: }
2422: }
2423: for (my $i=0; $i<@{$currnewattach}; $i++) {
2424: my $attachnum = $startnum + $i;
1.113 raeburn 2425: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108 raeburn 2426: }
2427: return $newattachmenturl;
2428: }
2429:
1.6 albertel 2430: sub handler {
2431: my $r = shift;
1.8 www 2432: if ($r->header_only) {
1.71 www 2433: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2434: $r->send_http_header;
2435: return OK;
2436: }
1.15 www 2437:
2438: # --------------------------- Get query string for limited number of parameters
2439:
1.97 raeburn 2440: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.111 raeburn 2441: ['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']);
2442: if ($ENV{'form.discsymb'}) {
2443: my $symb = $ENV{'form.discsymb'};
2444: my $readkey = $symb.'_read';
2445: my %readinghash = ();
2446: my $chgcount = 0;
2447: %readinghash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$readkey],$ENV{'user.domain'},$ENV{'user.name'});
2448: foreach my $key (keys %ENV) {
2449: if ($key =~ m/^form\.postunread_(\d+)/) {
2450: if ($readinghash{$readkey} =~ /\.$1\./) {
2451: $readinghash{$readkey} =~ s/\.$1\.//;
2452: $chgcount ++;
2453: }
2454: } elsif ($key =~ m/^form\.postread_(\d+)/) {
2455: unless ($readinghash{$readkey} =~ /\.$1\./) {
2456: $readinghash{$readkey} .= '.'.$1.'.';
2457: $chgcount ++;
2458: }
2459: }
2460: }
2461: if ($chgcount > 0) {
2462: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'});
2463: }
2464: &Apache::loncommon::content_type($r,'text/html');
2465: $r->send_http_header;
2466: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2467: my $previous=$ENV{'form.previous'};
2468: my $feedurl = &Apache::lonnet::clutter($url);
2469: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />','0','0','',$previous,'','','',);
2470: return OK;
2471: }
1.109 raeburn 2472: if ($ENV{'form.allversions'}) {
2473: &Apache::loncommon::content_type($r,'text/html');
2474: $r->send_http_header;
2475: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions',
2476: '','');
2477: $r->print (<<END);
2478: <html>
2479: <head>
2480: <title>Post Versions</title>
2481: <meta http-equiv="pragma" content="no-cache" />
2482: </head>
2483: $bodytag
2484: END
2485: my $crs='/'.$ENV{'request.course.id'};
2486: if ($ENV{'request.course.sec'}) {
2487: $crs.='_'.$ENV{'request.course.sec'};
2488: }
2489: $crs=~s/\_/\//g;
2490: my $seeid=&Apache::lonnet::allowed('rin',$crs);
2491: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.allversions'});
2492: my $ressymb=$symb;
2493: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2494: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2495: }
2496: if ($idx > 0) {
2497: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
2498: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2499: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2500: if ($contrib{$idx.':history'}) {
2501: my $attachmenturls = $contrib{$idx.':attachmenturl'};
2502: my @postversions = ();
1.112 raeburn 2503: my %messages = ();
2504: my %subjects = ();
1.109 raeburn 2505: if ($contrib{$idx.':history'} =~ m/:/) {
2506: @postversions = split/:/,$contrib{$idx.':history'};
2507: } else {
2508: @postversions = ("$contrib{$idx.':history'}");
2509: }
2510: if (@postversions > 0) {
1.112 raeburn 2511: &get_post_versions(\%messages,$contrib{$idx.':message'});
2512: &get_post_versions(\%subjects,$contrib{$idx.':subject'});
1.109 raeburn 2513: push @postversions,$contrib{$idx.':timestamp'};
2514: my $screenname=&Apache::loncommon::screenname(
2515: $contrib{$idx.':sendername'},
2516: $contrib{$idx.':senderdomain'});
2517: my $plainname=&Apache::loncommon::nickname(
2518: $contrib{$idx.':sendername'},
2519: $contrib{$idx.':senderdomain'});
2520: my $sender=&Apache::loncommon::aboutmewrapper(
2521: $plainname,
2522: $contrib{$idx.':sendername'},
2523: $contrib{$idx.':senderdomain'}).' ('.
2524: $contrib{$idx.':sendername'}.' at '.
2525: $contrib{$idx.':senderdomain'}.')';
2526: if ($contrib{$idx.':anonymous'}) {
2527: $sender.=' ['.&mt('anonymous').'] '.$screenname;
2528: }
2529: $r->print('<b>'.$sender.'</b><br /><ul>');
2530: for (my $i=0; $i<@postversions; $i++) {
2531: my ($timesent,$message,$subject,$attachmsg);
2532: $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
1.112 raeburn 2533: $message=&HTML::Entities::decode($messages{$i});
2534: $subject=&HTML::Entities::decode($subjects{$i});
1.109 raeburn 2535: $message=~s/\n/\<br \/\>/g;
2536: $message=&Apache::lontexconvert::msgtexconverted($message);
2537: $subject=~s/\n/\<br \/\>/g;
2538: $subject=&Apache::lontexconvert::msgtexconverted($subject);
2539: if ($attachmenturls) {
1.113 raeburn 2540: my %attachments = ();
1.109 raeburn 2541: my %currattach = ();
1.113 raeburn 2542: &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,\%attachments,\%currattach);
1.109 raeburn 2543: }
2544: if ($attachmsg) {
2545: $attachmsg = '<br />Attachments:'.$attachmsg.'<br />';
2546: } else {
2547: $attachmsg = '<br />';
2548: }
2549: $r->print (<<END);
2550: <li><b>$subject</b>, $timesent<br />
2551: $message<br />
2552: $attachmsg</li>
2553: END
2554: }
2555: $r->print('</ul></body></html>');
2556: }
2557: }
2558: }
2559: return OK;
2560: }
1.101 raeburn 2561: if ($ENV{'form.posterlist'}) {
2562: &Apache::loncommon::content_type($r,'text/html');
2563: $r->send_http_header;
2564: my $symb=$ENV{'form.posterlist'};
2565: my $sortposts = $ENV{'form.sortposts'};
2566: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2567: my $previous=$ENV{'form.previous'};
2568: my $feedurl = &Apache::lonnet::clutter($url);
2569: # backward compatibility (bulletin boards used to be 'wrapped')
2570: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2571: $feedurl=~s|^/adm/wrapper||;
2572: }
2573: &print_showposters($r,$symb,$previous,$feedurl,$sortposts);
2574: return OK;
2575: }
2576: if ($ENV{'form.userpick'}) {
2577: &Apache::loncommon::content_type($r,'text/html');
2578: $r->send_http_header;
2579: my $symb=$ENV{'form.userpick'};
2580: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2581: my $previous=$ENV{'form.previous'};
2582: # backward compatibility (bulletin boards used to be 'wrapped')
2583: my $ressymb=$symb;
2584: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2585: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2586: }
2587: my $sort=$ENV{'form.sortposts'};
2588: my @posters = ();
2589: if (ref($ENV{'form.stuinfo'}) eq 'ARRAY') {
2590: @posters = $ENV{'form.stuinfo'};
2591: } else {
2592: $posters[0] = $ENV{'form.stuinfo'};
2593: }
2594: my $numpicks = @posters;
2595: if (defined($ENV{'form.userpick'})) {
2596: my %discinfo = ();
2597: $discinfo{$ressymb.'_userpick'} = join('&',@posters);
2598: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2599: }
2600: my $feedurl = &Apache::lonnet::clutter($url);
2601: # backward compatibility (bulletin boards used to be 'wrapped')
2602: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2603: $feedurl=~s|^/adm/wrapper||;
2604: }
2605: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,'','','',$numpicks);
2606: return OK;
2607: }
1.100 raeburn 2608: if ($ENV{'form.applysort'}) {
2609: &Apache::loncommon::content_type($r,'text/html');
2610: $r->send_http_header;
2611: my $symb=$ENV{'form.applysort'};
2612: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2613: my $previous=$ENV{'form.previous'};
2614: my $sort = $ENV{'form.sortposts'};
1.101 raeburn 2615: my $rolefilter = $ENV{'form.rolefilter'};
1.100 raeburn 2616: my $statusfilter = $ENV{'form.statusfilter'};
2617: my $secpick = $ENV{'form.sectionpick'};
2618: my $feedurl = &Apache::lonnet::clutter($url);
2619: # backward compatibility (bulletin boards used to be 'wrapped')
2620: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2621: $feedurl=~s|^/adm/wrapper||;
2622: }
1.101 raeburn 2623: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,$rolefilter,$statusfilter,$secpick);
1.100 raeburn 2624: return OK;
2625: } elsif ($ENV{'form.sortfilter'}) {
2626: &Apache::loncommon::content_type($r,'text/html');
2627: $r->send_http_header;
2628: my $symb=$ENV{'form.sortfilter'};
2629: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2630: my $previous=$ENV{'form.previous'};
2631: my $feedurl = &Apache::lonnet::clutter($url);
2632: # backward compatibility (bulletin boards used to be 'wrapped')
2633: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2634: $feedurl=~s|^/adm/wrapper||;
2635: }
2636: &print_sortfilter_options($r,$symb,$previous,$feedurl);
2637: return OK;
2638: } elsif ($ENV{'form.navmaps'}) {
1.99 raeburn 2639: my %discinfo = ();
2640: my @resources = ();
2641: if ($ENV{'form.navmaps'} =~ /:/) {
2642: @resources = split/:/,$ENV{'form.navmaps'};
2643: } else {
2644: @resources = ("$ENV{'form.navmaps'}");
2645: }
2646: my $numitems = @resources;
2647: my $feedurl = '/adm/navmaps';
2648: if ($ENV{'form.navurl'}) {
2649: $feedurl .= '?'.$ENV{'form.navurl'};
2650: }
2651: my %lt = &Apache::lonlocal::texthash(
2652: 'mnpa' => 'Marked "New" posts as read in a total of',
2653: 'robb' => 'resources/bulletin boards.'
2654: );
2655: foreach (@resources) {
2656: # backward compatibility (bulletin boards used to be 'wrapped')
2657: my $ressymb=$_;
2658: if ($ressymb =~ m/bulletin___\d+___/) {
2659: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2660: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
2661: }
2662: }
2663: my $lastkey = $ressymb.'_lastread';
2664: $discinfo{$lastkey} = time;
2665: }
2666: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2667: &Apache::loncommon::content_type($r,'text/html');
2668: $r->send_http_header;
2669: $r->print (<<ENDREDIR);
2670: <html>
2671: <head>
2672: <title>New posts marked as read</title>
2673: <meta http-equiv="pragma" content="no-cache" />
2674: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
2675: </head>
2676: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
2677: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
2678: <b>$lt{'mnpa'} $numitems $lt{'robb'}</b>
2679: <form name="reldt" action="$feedurl" target="loncapaclient">
2680: </form>
2681: </body>
2682: </html>
2683: ENDREDIR
2684: return OK;
2685: } elsif ($ENV{'form.modifydisp'}) {
1.84 raeburn 2686: &Apache::loncommon::content_type($r,'text/html');
2687: $r->send_http_header;
1.97 raeburn 2688: my $symb=$ENV{'form.modifydisp'};
1.84 raeburn 2689: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.97 raeburn 2690: my $previous=$ENV{'form.previous'};
1.111 raeburn 2691: my ($dispchgA,$dispchgB,$markchg,$toggchg) = split/_/,$ENV{'form.changes'};
1.97 raeburn 2692: my $feedurl = &Apache::lonnet::clutter($url);
1.98 raeburn 2693: # backward compatibility (bulletin boards used to be 'wrapped')
2694: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2695: $feedurl=~s|^/adm/wrapper||;
2696: }
1.111 raeburn 2697: &print_display_options($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 2698: return OK;
1.111 raeburn 2699: } 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 2700: &Apache::loncommon::content_type($r,'text/html');
2701: $r->send_http_header;
2702: my $previous=$ENV{'form.previous'};
2703: my ($map,$ind,$url);
1.111 raeburn 2704: if ( ($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
2705: # ------------------------------ Modify setting for read/unread toggle for each post
2706: my $symb=$ENV{'form.toggoff'}?$ENV{'form.toggoff'}:$ENV{'form.toggon'};
2707: my $ressymb = $symb;
2708: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2709: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2710: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2711: }
2712: my %discinfo = ();
2713: my $toggkey = $ressymb.'_readtoggle';
2714: if ($ENV{'form.toggon'}) {
2715: $discinfo{$toggkey} = 1;
2716: } elsif ($ENV{'form.toggoff'}) {
2717: $discinfo{$toggkey} = 0;
2718: }
2719: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2720: }
1.97 raeburn 2721: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
2722: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
2723: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
2724: my $ressymb = $symb;
2725: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2726: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2727: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2728: }
2729: my %discinfo = ();
2730: my $lastkey = $ressymb.'_lastread';
2731: my $ondispkey = $ressymb.'_markondisp';
2732: if ($ENV{'form.markondisp'}) {
2733: $discinfo{$lastkey} = time;
2734: $discinfo{$ondispkey} = 1;
2735: } elsif ($ENV{'form.markonread'}) {
2736: if ( $previous > 0 ) {
2737: $discinfo{$lastkey} = $previous;
2738: }
2739: $discinfo{$ondispkey} = 0;
2740: }
2741: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 2742: }
1.111 raeburn 2743: if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ) {
1.97 raeburn 2744: # ----------------------------------------------------------------- Modify display setting for this discussion
1.111 raeburn 2745: my $symb;
2746: if ($ENV{'form.allposts'}) {
2747: $symb = $ENV{'form.allposts'};
2748: } elsif ($ENV{'form.onlyunread'}) {
2749: $symb = $ENV{'form.onlyunread'};
2750: } else {
2751: $symb = $ENV{'form.onlyunmark'};
2752: }
1.97 raeburn 2753: my $ressymb = $symb;
2754: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2755: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2756: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2757: }
2758: my %discinfo = ();
2759: if ($ENV{'form.allposts'}) {
2760: $discinfo{$ressymb.'_showonlyunread'} = 0;
1.111 raeburn 2761: $discinfo{$ressymb.'_showonlyunmark'} = 0;
1.97 raeburn 2762: } elsif ($ENV{'form.onlyunread'}) {
2763: $discinfo{$ressymb.'_showonlyunread'} = 1;
1.111 raeburn 2764: } else {
2765: $discinfo{$ressymb.'_showonlyunmark'} = 1;
1.84 raeburn 2766: }
1.97 raeburn 2767: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 2768: }
1.111 raeburn 2769: if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ||($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
1.97 raeburn 2770: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
2771: } else {
1.84 raeburn 2772: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
2773: }
2774: return OK;
2775: } elsif ($ENV{'form.markread'}) {
1.111 raeburn 2776: # ----------------------------------------------------------------- Mark new posts not NEW
1.84 raeburn 2777: &Apache::loncommon::content_type($r,'text/html');
2778: $r->send_http_header;
2779: my $symb=$ENV{'form.markread'};
2780: my $ressymb = $symb;
2781: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2782: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2783: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1.78 raeburn 2784: }
1.84 raeburn 2785: my %discinfo = ();
2786: my $lastkey = $ressymb.'_lastread';
2787: $discinfo{$lastkey} = time;
2788: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2789: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1.78 raeburn 2790: return OK;
2791: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15 www 2792: # ----------------------------------------------------------------- Hide/unhide
1.71 www 2793: &Apache::loncommon::content_type($r,'text/html');
1.15 www 2794: $r->send_http_header;
2795:
2796: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
2797:
2798: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 2799: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15 www 2800:
2801: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2802: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2803: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2804:
2805:
2806: my $currenthidden=$contrib{'hidden'};
1.102 raeburn 2807: my $currentstudenthidden=$contrib{'studenthidden'};
2808:
2809: my $crs='/'.$ENV{'request.course.id'};
2810: if ($ENV{'request.course.sec'}) {
2811: $crs.='_'.$ENV{'request.course.sec'};
2812: }
2813: $crs=~s/\_/\//g;
2814: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.15 www 2815:
2816: if ($ENV{'form.hide'}) {
2817: $currenthidden.='.'.$idx.'.';
1.102 raeburn 2818: unless ($seeid) {
2819: $currentstudenthidden.='.'.$idx.'.';
2820: }
1.15 www 2821: } else {
2822: $currenthidden=~s/\.$idx\.//g;
2823: }
2824: my %newhash=('hidden' => $currenthidden);
1.102 raeburn 2825: if ( ($ENV{'form.hide'}) && (!$seeid) ) {
2826: $newhash{'studenthidden'} = $currentstudenthidden;
2827: }
1.38 www 2828:
2829: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
2830: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2831: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2832:
2833: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 2834: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69 www 2835: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72 albertel 2836: &Apache::loncommon::content_type($r,'text/html');
2837: $r->send_http_header;
1.69 www 2838: if ($ENV{'form.threadedon'}) {
2839: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
2840: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
2841: } else {
2842: &Apache::lonnet::del('environment',['threadeddiscussion']);
2843: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 2844: }
1.69 www 2845: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
2846: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2847: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 2848: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38 www 2849: } elsif ($ENV{'form.deldisc'}) {
2850: # --------------------------------------------------------------- Hide for good
1.71 www 2851: &Apache::loncommon::content_type($r,'text/html');
1.38 www 2852: $r->send_http_header;
2853:
2854: my $entry=$ENV{'form.deldisc'};
2855:
2856: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 2857: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38 www 2858:
2859: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2860: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2861: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2862:
2863:
2864: my $currentdeleted=$contrib{'deleted'};
2865:
2866: $currentdeleted.='.'.$idx.'.';
2867:
2868: my %newhash=('deleted' => $currentdeleted);
1.15 www 2869:
2870: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
2871: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2872: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2873:
1.30 www 2874: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 2875: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33 www 2876: } elsif ($ENV{'form.preview'}) {
2877: # -------------------------------------------------------- User wants a preview
1.76 albertel 2878: $r->content_type('text/html');
2879: $r->send_http_header;
1.33 www 2880: &show_preview($r);
1.108 raeburn 2881: } elsif ($ENV{'form.attach'}) {
2882: # -------------------------------------------------------- Work on attachments
2883: &Apache::loncommon::content_type($r,'text/html');
2884: $r->send_http_header;
2885: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
2886: my @currnewattach = ();
2887: my @currdelold = ();
2888: my @keepold = ();
2889: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
2890: if (exists($ENV{'form.addnewattach.filename'})) {
2891: unless (length($ENV{'form.addnewattach'})>131072) {
2892: my $subdir = 'feedback/'.$ENV{'form.timestamp'};
2893: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
2894: push @currnewattach, $newattachment;
2895: }
2896: }
2897: my $attachmenturls = '';
2898: my $idx = $ENV{'form.idx'};
2899: my $symb = $ENV{'form.attach'};
2900: if ($idx) {
2901: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2902: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2903: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2904: $attachmenturls = $contrib{$idx.':attachmenturl'};
2905: }
2906: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,$attachmenturls);
1.111 raeburn 2907: } elsif ($ENV{'form.chgreads'}) {
2908: &Apache::loncommon::content_type($r,'text/html');
2909: $r->send_http_header;
2910: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ENV{'form.chgreads'});
2911: &redirect_back($r,&Apache::lonnet::clutter($url),
2912: &mt('Changed read status').'<br />','0','0');
1.15 www 2913: } else {
2914: # ------------------------------------------------------------- Normal feedback
1.6 albertel 2915: my $feedurl=$ENV{'form.postdata'};
2916: $feedurl=~s/^http\:\/\///;
2917: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
2918: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62 www 2919: $feedurl=~s/\?.+$//;
1.8 www 2920:
1.66 www 2921: my $symb;
2922: if ($ENV{'form.replydisc'}) {
2923: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
2924: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
2925: $feedurl=&Apache::lonnet::clutter($url);
1.102 raeburn 2926: } elsif ($ENV{'form.editdisc'}) {
2927: $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
2928: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
2929: $feedurl=&Apache::lonnet::clutter($url);
1.108 raeburn 2930: } elsif ($ENV{'form.origpage'}) {
2931: $symb="";
1.66 www 2932: } else {
2933: $symb=&Apache::lonnet::symbread($feedurl);
2934: }
1.31 www 2935: unless ($symb) {
2936: $symb=$ENV{'form.symb'};
2937: if ($symb) {
1.52 www 2938: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31 www 2939: $feedurl=&Apache::lonnet::clutter($url);
2940: }
2941: }
1.8 www 2942: my $goahead=1;
2943: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
2944: unless ($symb) { $goahead=0; }
2945: }
1.98 raeburn 2946: # backward compatibility (bulletin boards used to be 'wrapped')
1.73 albertel 2947: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2948: $feedurl=~s|^/adm/wrapper||;
2949: }
1.8 www 2950: if ($goahead) {
2951: # Go ahead with feedback, no ambiguous reference
1.71 www 2952: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2953: $r->send_http_header;
1.6 albertel 2954:
1.8 www 2955: if (
1.7 albertel 2956: (
2957: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
2958: )
2959: ||
2960: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31 www 2961: ||
2962: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7 albertel 2963: ) {
1.6 albertel 2964: # --------------------------------------------------- Print login screen header
2965: unless ($ENV{'form.sendit'}) {
2966: my $options=&screen_header($feedurl);
2967: if ($options) {
1.108 raeburn 2968: &mail_screen($r,$feedurl,$options);
1.6 albertel 2969: } else {
2970: &fail_redirect($r,$feedurl);
2971: }
2972: } else {
2973:
2974: # Get previous user input
1.9 albertel 2975: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 2976: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 2977: $ENV{'request.course.id'});
1.6 albertel 2978:
2979: # Get output from resource
2980: my $usersaw=&resource_output($feedurl);
2981:
1.50 albertel 2982: # Get resource answer (need to allow student to view grades for this to work)
2983: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 2984: my $useranswer=&Apache::loncommon::get_student_answers(
2985: $symb,$ENV{'user.name'},$ENV{'user.domain'},
2986: $ENV{'request.course.id'});
1.50 albertel 2987: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 2988: # Get attachments, if any, and not too large
2989: my $attachmenturl='';
1.108 raeburn 2990: if (($ENV{'form.origpage'}) || ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'})) {
2991: my ($symb,$idx);
2992: if ($ENV{'form.replydisc'}) {
2993: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
2994: } elsif ($ENV{'form.editdisc'}) {
2995: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
2996: } elsif ($ENV{'form.origpage'}) {
2997: $symb = $ENV{'form.symb'};
2998: }
2999: my @currnewattach = ();
3000: my @deloldattach = ();
3001: my @keepold = ();
3002: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
1.110 raeburn 3003: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.108 raeburn 3004: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
3005: } elsif ($ENV{'form.attachment.filename'}) {
1.42 www 3006: unless (length($ENV{'form.attachment'})>131072) {
1.82 albertel 3007: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3008: }
3009: }
1.6 albertel 3010: # Filter HTML out of message (could be nasty)
1.39 www 3011: my $message=&clear_out_html($ENV{'form.comment'});
1.6 albertel 3012:
3013: # Assemble email
1.8 www 3014: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40 albertel 3015: $usersaw,$useranswer);
3016:
1.6 albertel 3017: # Who gets this?
3018: my ($typestyle,%to) = &decide_receiver($feedurl);
3019:
3020: # Actually send mail
1.43 www 3021: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
3022: $attachmenturl,%to);
1.13 www 3023:
3024: # Discussion? Store that.
3025:
1.32 albertel 3026: my $numpost=0;
1.13 www 3027: if ($ENV{'form.discuss'}) {
1.78 raeburn 3028: my $subject = &clear_out_html($ENV{'form.subject'});
3029: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32 albertel 3030: $numpost++;
1.13 www 3031: }
1.6 albertel 3032:
1.14 www 3033: if ($ENV{'form.anondiscuss'}) {
1.78 raeburn 3034: my $subject = &clear_out_html($ENV{'form.subject'});
3035: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32 albertel 3036: $numpost++;
1.14 www 3037: }
3038:
3039:
1.6 albertel 3040: # Receipt screen and redirect back to where came from
1.80 raeburn 3041: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6 albertel 3042:
3043: }
1.8 www 3044: } else {
1.7 albertel 3045: # Unable to give feedback
1.6 albertel 3046: &no_redirect_back($r,$feedurl);
1.8 www 3047: }
3048: } else {
3049: # Ambiguous Problem Resource
1.60 albertel 3050: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53 albertel 3051: &Apache::lonnet::cleanenv();
1.58 albertel 3052: }
1.53 albertel 3053: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 3054: }
1.15 www 3055: }
1.6 albertel 3056: return OK;
1.1 www 3057: }
3058:
3059: 1;
3060: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>