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