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