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