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