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