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