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