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