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