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