Annotation of loncom/interface/lonfeedback.pm, revision 1.130
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.130 ! albertel 4: # $Id: lonfeedback.pm,v 1.129 2004/11/11 22:19:53 albertel Exp $
1.19 albertel 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: #
1.77 www 28: ###
1.7 albertel 29:
1.1 www 30: package Apache::lonfeedback;
31:
32: use strict;
33: use Apache::Constants qw(:common);
1.3 www 34: use Apache::lonmsg();
1.9 albertel 35: use Apache::loncommon();
1.33 www 36: use Apache::lontexconvert();
1.86 www 37: use Apache::lonlocal; # must not have ()
38: use Apache::lonhtmlcommon();
1.128 raeburn 39: use Apache::lonnavmaps;
1.130 ! albertel 40: use Apache::lonenc();
1.112 raeburn 41: use HTML::LCParser();
1.106 www 42: use Apache::lonspeller();
1.116 raeburn 43: use Cwd;
1.54 www 44:
1.92 albertel 45: sub discussion_open {
1.122 raeburn 46: my ($status,$symb)=@_;
1.92 albertel 47: if (defined($status) &&
48: !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
1.77 www 49: || $status eq 'OPEN')) {
1.92 albertel 50: return 0;
1.75 albertel 51: }
1.122 raeburn 52: my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb);
1.89 albertel 53: if (defined($close) && $close ne '' && $close < time) {
1.92 albertel 54: return 0;
1.89 albertel 55: }
1.92 albertel 56: return 1;
57: }
58:
59: sub discussion_visible {
60: my ($status)=@_;
61: if (not &discussion_open($status)) {
62: my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
63: if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden)) {
1.122 raeburn 64: if (!$ENV{'request.role.adv'}) { return 0; }
1.92 albertel 65: }
66: }
67: return 1;
1.90 albertel 68: }
1.84 raeburn 69:
1.90 albertel 70: sub list_discussion {
1.115 sakharuk 71: my ($mode,$status,$symb)=@_;
1.95 sakharuk 72: my $outputtarget=$ENV{'form.grade_target'};
1.116 raeburn 73: if (defined($ENV{'form.export'})) {
74: if($ENV{'form.export'}) {
75: $outputtarget = 'export';
76: }
77: }
1.92 albertel 78: if (not &discussion_visible($status)) { return ''; }
1.84 raeburn 79: my @bgcols = ("#cccccc","#eeeeee");
1.57 www 80: my $discussiononly=0;
81: if ($mode eq 'board') { $discussiononly=1; }
1.55 www 82: unless ($ENV{'request.course.id'}) { return ''; }
83: my $crs='/'.$ENV{'request.course.id'};
1.101 raeburn 84: my $cid=$ENV{'request.course.id'};
1.55 www 85: if ($ENV{'request.course.sec'}) {
86: $crs.='_'.$ENV{'request.course.sec'};
87: }
88: $crs=~s/\_/\//g;
1.54 www 89: unless ($symb) {
90: $symb=&Apache::lonnet::symbread();
91: }
92: unless ($symb) { return ''; }
1.100 raeburn 93: my %usernamesort = ();
94: my %namesort =();
95: my %subjectsort = ();
1.80 raeburn 96: # backward compatibility (bulletin boards used to be 'wrapped')
97: my $ressymb=$symb;
98: if ($mode eq 'board') {
99: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
100: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
101: }
102: }
1.129 albertel 103: $ressymb=&Apache::lonenc::check_encrypt($ressymb);
1.80 raeburn 104: # Get discussion display settings for this discussion
105: my $lastkey = $ressymb.'_lastread';
106: my $showkey = $ressymb.'_showonlyunread';
1.111 raeburn 107: my $markkey = $ressymb.'_showonlyunmark',
1.80 raeburn 108: my $visitkey = $ressymb.'_visit';
1.84 raeburn 109: my $ondispkey = $ressymb.'_markondisp';
1.101 raeburn 110: my $userpickkey = $ressymb.'_userpick';
1.111 raeburn 111: my $toggkey = $ressymb.'_readtoggle';
112: my $readkey = $ressymb.'_read';
113:
114: my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 115: my %discinfo = ();
1.80 raeburn 116: my $showonlyunread = 0;
1.111 raeburn 117: my $showunmark = 0;
1.84 raeburn 118: my $markondisp = 0;
1.79 raeburn 119: my $prevread = 0;
1.81 raeburn 120: my $previous = 0;
1.80 raeburn 121: my $visit = 0;
122: my $newpostsflag = 0;
1.101 raeburn 123: my @posters = split/\&/,$dischash{$userpickkey};
1.80 raeburn 124:
1.81 raeburn 125: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
1.101 raeburn 126: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts','rolefilter','statusfilter','sectionpick','totposters']);
1.100 raeburn 127: my $sortposts = $ENV{'form.sortposts'};
1.101 raeburn 128: my $rolefilter = $ENV{'form.rolefilter'};
129: my $statusfilter = $ENV{'form.statusfilter'};
130: my $sectionpick = $ENV{'form.sectionpick'};
131: my $totposters = $ENV{'form.totposters'};
1.81 raeburn 132: $previous = $ENV{'form.previous'};
1.80 raeburn 133: if ($previous > 0) {
134: $prevread = $previous;
135: } elsif (defined($dischash{$lastkey})) {
1.84 raeburn 136: unless ($dischash{$lastkey} eq '') {
137: $prevread = $dischash{$lastkey};
138: }
1.80 raeburn 139: }
1.79 raeburn 140:
1.108 raeburn 141: # Get information about students and non-students in course for filtering display of posts
1.101 raeburn 142: my %roleshash = ();
143: my %roleinfo = ();
144: if ($rolefilter) {
145: %roleshash = &Apache::lonnet::dump('nohist_userroles',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
146: foreach (keys %roleshash) {
147: my ($role,$uname,$udom,$sec) = split/:/,$_;
148: my ($end,$start) = split/:/,$roleshash{$_};
149: my $now = time;
150: my $status = 'Active';
151: if (($now < $start) || ($end > 0 && $now > $end)) {
152: $status = 'Expired';
153: }
154: push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
155: }
156: my ($classlist) = &Apache::loncoursedata::get_classlist(
157: $ENV{'request.course.id'},
158: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
159: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
160: my $sec_index = &Apache::loncoursedata::CL_SECTION();
161: my $status_index = &Apache::loncoursedata::CL_STATUS();
162: while (my ($student,$data) = each %$classlist) {
163: my ($section,$status) = ($data->[$sec_index],
164: $data->[$status_index]);
165: push @{$roleinfo{$student}}, 'st:'.$section.':'.$status;
166: }
167: }
168:
1.84 raeburn 169: # Get discussion display default settings for user
1.126 albertel 170: if ($ENV{'environment.discdisplay'} eq 'unread') {
1.83 raeburn 171: $showonlyunread = 1;
172: }
1.126 albertel 173: if ($ENV{'environment.discmarkread'} eq 'ondisp') {
1.84 raeburn 174: $markondisp = 1;
175: }
176:
177: # Override user's default if user specified display setting for this discussion
178: if (defined($dischash{$ondispkey})) {
1.123 raeburn 179: unless ($dischash{$ondispkey} eq '') {
180: $markondisp = $dischash{$ondispkey};
181: }
1.84 raeburn 182: }
183: if ($markondisp) {
184: $discinfo{$lastkey} = time;
185: }
1.83 raeburn 186:
1.80 raeburn 187: if (defined($dischash{$showkey})) {
1.123 raeburn 188: unless ($dischash{$showkey} eq '') {
189: $showonlyunread = $dischash{$showkey};
190: }
1.80 raeburn 191: }
192:
1.111 raeburn 193: if (defined($dischash{$markkey})) {
1.123 raeburn 194: unless ($dischash{$markkey} eq '') {
195: $showunmark = $dischash{$markkey};
196: }
1.111 raeburn 197: }
198:
1.80 raeburn 199: if (defined($dischash{$visitkey})) {
1.123 raeburn 200: unless ($dischash{$visitkey} eq '') {
201: $visit = $dischash{$visitkey};
202: }
1.78 raeburn 203: }
1.80 raeburn 204: $visit ++;
1.78 raeburn 205:
1.54 www 206: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.77 www 207: my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
208: && ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
1.68 www 209: my @discussionitems=();
1.101 raeburn 210: my %shown = ();
211: my @posteridentity=();
1.116 raeburn 212:
213: my $current=0;
1.67 www 214: my $visible=0;
1.68 www 215: my @depth=();
1.116 raeburn 216: my @replies = ();
1.68 www 217: my %alldiscussion=();
1.116 raeburn 218: my %imsitems=();
219: my %imsfiles=();
1.80 raeburn 220: my %notshown = ();
1.84 raeburn 221: my %newitem = ();
1.68 www 222: my $maxdepth=0;
223:
1.69 www 224: my $target='';
225: unless ($ENV{'browser.interface'} eq 'textual' ||
226: $ENV{'environment.remote'} eq 'off' ) {
227: $target='target="LONcom"';
228: }
1.111 raeburn 229:
1.79 raeburn 230: my $now = time;
1.80 raeburn 231: $discinfo{$visitkey} = $visit;
232:
233: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.116 raeburn 234: &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,$ressymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$statusfilter,$toggkey,$outputtarget);
1.80 raeburn 235:
1.67 www 236: my $discussion='';
1.116 raeburn 237: my $manifestfile;
238: my $manifestok=0;
239: my $tempexport;
240: my $imsresources;
241: my $copyresult;
1.84 raeburn 242:
243: my $function = &Apache::loncommon::get_users_function();
244: my $color = &Apache::loncommon::designparm($function.'.tabbg',
245: $ENV{'user.domain'});
246: my %lt = &Apache::lonlocal::texthash(
1.97 raeburn 247: 'cuse' => 'Current discussion settings',
1.84 raeburn 248: 'allposts' => 'All posts',
249: 'unread' => 'New posts only',
1.111 raeburn 250: 'unmark' => 'Unread only',
1.84 raeburn 251: 'ondisp' => 'Once displayed',
1.111 raeburn 252: 'onmark' => 'Once marked not NEW',
253: 'toggoff' => 'Off',
254: 'toggon' => 'On',
1.84 raeburn 255: 'disa' => 'Posts to be displayed',
256: 'npce' => 'Posts cease to be marked "NEW"',
1.111 raeburn 257: 'epcb' => 'Each post can be toggled read/unread',
1.97 raeburn 258: 'chgt' => 'Change',
259: 'disp' => 'Display',
260: 'nolo' => 'Not new',
1.111 raeburn 261: 'togg' => 'Toggle read/unread',
1.84 raeburn 262: );
263:
264: my $currdisp = $lt{'allposts'};
265: my $currmark = $lt{'onmark'};
1.111 raeburn 266: my $currtogg = $lt{'toggoff'};
1.84 raeburn 267: my $dispchange = $lt{'unread'};
268: my $markchange = $lt{'ondisp'};
1.111 raeburn 269: my $toggchange = $lt{'toggon'};
1.97 raeburn 270: my $chglink = '/adm/feedback?modifydisp='.$ressymb;
1.111 raeburn 271: my $displinkA = 'onlyunread';
272: my $displinkB = 'onlyunmark';
1.97 raeburn 273: my $marklink = 'markondisp';
1.111 raeburn 274: my $togglink = 'toggon';
1.84 raeburn 275:
276: if ($markondisp) {
277: $currmark = $lt{'ondisp'};
278: $markchange = $lt{'onmark'};
1.97 raeburn 279: $marklink = 'markonread';
1.84 raeburn 280: }
281:
282: if ($showonlyunread) {
283: $currdisp = $lt{'unread'};
284: $dispchange = $lt{'allposts'};
1.111 raeburn 285: $displinkA = 'allposts';
1.84 raeburn 286: }
1.111 raeburn 287:
288: if ($showunmark) {
289: $currdisp = $lt{'unmark'};
290: $dispchange = $lt{'unmark'};
291: $displinkA='allposts';
292: $displinkB='onlyunread';
293: $showonlyunread = 0;
294: }
295:
296: if ($dischash{$toggkey}) {
297: $currtogg = $lt{'toggon'};
298: $toggchange = $lt{'toggoff'};
299: $togglink = 'toggoff';
300: }
1.97 raeburn 301:
1.111 raeburn 302: $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink;
1.84 raeburn 303:
304: if ($newpostsflag) {
1.97 raeburn 305: $chglink .= '&previous='.$prevread;
1.84 raeburn 306: }
307:
1.67 www 308: if ($visible) {
1.80 raeburn 309: # Print the discusssion
1.116 raeburn 310: if ($outputtarget eq 'tex') {
311: $discussion.='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
312: '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
313: '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
314: '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
315: '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}</tex>';
316: } elsif ($outputtarget eq 'export') {
317: # Create temporary directory if this is an export
318: my $now = time;
319: $tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
320: if (!-e $tempexport) {
321: mkdir($tempexport,0700);
322: }
323: $tempexport .= '/'.$now;
324: if (!-e $tempexport) {
325: mkdir($tempexport,0700);
326: }
327: $tempexport .= '/'.$ENV{'user.domain'}.'_'.$ENV{'user.name'};
328: if (!-e $tempexport) {
329: mkdir($tempexport,0700);
330: }
331: # open manifest file
332: my $manifest = '/imsmanifest.xml';
333: my $manifestfilename = $tempexport.$manifest;
334: if ($manifestfile = Apache::File->new('>'.$manifestfilename)) {
335: $manifestok=1;
336: print $manifestfile qq|
337: <?xml version="1.0" encoding="UTF-8"?>
338: <manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
339: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
340: identifier="MANIFEST-$ressymb" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1
341: imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
342: <organizations default="$ressymb">
343: <organization identifier="$ressymb">
344: <title>Discussion for $ressymb</title>\n|;
345: } else {
346: $discussion .= 'An error occurred opening the manifest file.<br />';
347: }
348: } else {
1.97 raeburn 349: my $colspan=$maxdepth+1;
1.102 raeburn 350: $discussion.= qq|
351: <script>
352: function studentdelete (symb,idx,newflag,previous) {
353: var symbparm = symb+':::'+idx
354: var prevparm = ""
355: if (newflag == 1) {
356: prevparm = "&previous="+previous
357: }
358: if (confirm("Are you sure you want to delete this post?\\nDeleted posts will no longer be visible to you and other students,\\nbut will continue to be visible to your instructor")) {
359: document.location.href = "/adm/feedback?hide="+symbparm+prevparm
360: }
361: }
362: </script>
363: |;
1.129 albertel 364: $discussion.='<form name="readchoices" method="post" action="/adm/feedback?chgreads='.$ressymb.'"><table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
1.97 raeburn 365: $discussion .='<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
1.95 sakharuk 366: '<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
367: if ($visible>2) {
368: $discussion.='<td align="left">'.
369: '<a href="/adm/feedback?threadedon='.$ressymb;
370: if ($newpostsflag) {
371: $discussion .= '&previous='.$prevread;
372: }
373: $discussion .='">'.&mt('Threaded View').'</a> '.
374: '<a href="/adm/feedback?threadedoff='.$ressymb;
375: if ($newpostsflag) {
376: $discussion .= '&previous='.$prevread;
377: }
1.100 raeburn 378: $discussion .='">'.&mt('Chronological View').'</a>
379: <a href= "/adm/feedback?sortfilter='.$ressymb;
380: if ($newpostsflag) {
381: $discussion .= '&previous='.$prevread;
382: }
383: $discussion .='">'.&mt('Sorting/Filtering options').'</a>  ';
384: } else {
385: $discussion .= '<td align="left">';
386: }
387: $discussion .='<a href= "/adm/feedback?export='.$ressymb;
388: if ($newpostsflag) {
389: $discussion .= '&previous='.$prevread;
390: }
391: $discussion .= '">'.&mt('Export').'?</a> </td>';
1.95 sakharuk 392: if ($newpostsflag) {
393: if (!$markondisp) {
1.111 raeburn 394: $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark NEW posts no longer new').'</a> ';
1.95 sakharuk 395: } else {
396: $discussion .= '<td> </td>';
397: }
398: } else {
399: $discussion .= '<td> </td>';
400: }
401: $discussion .= '</tr></table></td></tr>';
1.116 raeburn 402:
403: my $numhidden = keys %notshown;
404: if ($numhidden > 0) {
405: my $colspan = $maxdepth+1;
406: $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
1.80 raeburn 407: '<a href="/adm/feedback?allposts='.$ressymb;
1.116 raeburn 408: if ($newpostsflag) {
409: $discussion .= '&previous='.$prevread;
410: }
411: $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
1.111 raeburn 412: $numhidden.' ';
1.116 raeburn 413: if ($showunmark) {
414: $discussion .= &mt('posts previously marked read');
415: } else {
416: $discussion .= &mt('previously viewed posts');
417: }
418: $discussion .= '<br/></td></tr>';
1.111 raeburn 419: }
1.80 raeburn 420: }
1.100 raeburn 421:
422: # Choose sort mechanism
423: my @showposts = ();
424: if ($sortposts eq 'descdate') {
425: @showposts = (sort { $b <=> $a } keys %alldiscussion);
426: } elsif ($sortposts eq 'thread') {
427: @showposts = (sort { $a <=> $b } keys %alldiscussion);
428: } elsif ($sortposts eq 'subject') {
429: foreach (sort keys %subjectsort) {
430: push @showposts, @{$subjectsort{$_}};
431: }
432: } elsif ($sortposts eq 'username') {
433: foreach my $domain (sort keys %usernamesort) {
434: foreach (sort keys %{$usernamesort{$domain}}) {
435: push @showposts, @{$usernamesort{$domain}{$_}};
436: }
437: }
438: } elsif ($sortposts eq 'lastfirst') {
439: foreach my $last (sort keys %namesort) {
440: foreach (sort keys %{$namesort{$last}}) {
441: push @showposts, @{$namesort{$last}{$_}};
442: }
443: }
444: } else {
445: $sortposts = 'ascdate';
446: @showposts = (sort { $a <=> $b } keys %alldiscussion);
447: }
1.116 raeburn 448: my $currdepth = 0;
449: my $firstidx = $alldiscussion{$showposts[0]};
1.100 raeburn 450: foreach (@showposts) {
1.116 raeburn 451: unless (($sortposts eq 'thread') || ($sortposts eq 'ascdate' && $ENV{'environment.threadeddiscussion'}) || ($outputtarget eq 'export')) {
1.100 raeburn 452: $alldiscussion{$_} = $_;
453: }
1.101 raeburn 454: unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {
1.117 albertel 455: if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
1.95 sakharuk 456: $discussion.="\n<tr>";
457: }
1.80 raeburn 458: my $thisdepth=$depth[$alldiscussion{$_}];
1.117 albertel 459: if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
1.95 sakharuk 460: for (1..$thisdepth) {
461: $discussion.='<td> </td>';
462: }
463: }
1.80 raeburn 464: my $colspan=$maxdepth-$thisdepth+1;
1.116 raeburn 465: if ($outputtarget eq 'tex') {
1.95 sakharuk 466: #cleanup block
467: $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
468: $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
469: my $threadinsert='';
470: if ($thisdepth > 0) {
471: $threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
472: }
473: $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
1.102 raeburn 474: $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;
1.95 sakharuk 475: $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
1.114 sakharuk 476:
477: $discussionitems[$alldiscussion{$_}]='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}</tex>'.$discussionitems[$alldiscussion{$_}];
478: $discussion.=$discussionitems[$alldiscussion{$_}];
1.116 raeburn 479: } elsif ($outputtarget eq 'export') {
480: my $postfilename = $alldiscussion{$_}.'-'.$imsitems{$alldiscussion{$_}}{'timestamp'}.'.html';
481: if ($manifestok) {
482: if (($depth[$alldiscussion{$_}] <= $currdepth) && ($alldiscussion{$_} != $firstidx)) {
483: print $manifestfile ' </item>'."\n";
484: }
485: $currdepth = $depth[$alldiscussion{$_}];
486: print $manifestfile "\n".
487: '<item identifier="ITEM-'.$ressymb.'-'.$alldiscussion{$_}.'" isvisible="'.
488: $imsitems{$alldiscussion{$_}}{'isvisible'}.'" identifieref="RES-'.$ressymb.'-'.$alldiscussion{$_}.'">'.
489: '<title>'.$imsitems{$alldiscussion{$_}}{'title'}.'</title>';
490: $imsresources .= "\n".
491: '<resource identifier="RES-'.$ressymb.'-'.$alldiscussion{$_}.'" type="webcontent" href="'.$postfilename.'">'.
492: '<file href="'.$alldiscussion{$_}.'.html">'."\n".
493: $imsfiles{$alldiscussion{$_}}{$imsitems{$alldiscussion{$_}}{'currversion'}}."\n".
494: '</resource>';
495: }
496: my $postingfile;
497: my $postingfilename = $tempexport.'/'.$postfilename;
498: if ($postingfile = Apache::File->new('>'.$postingfilename)) {
499: print $postingfile '<html><head><title>Discussion Post</title></head><body>'.
500: $imsitems{$alldiscussion{$_}}{'title'}.' '.
501: $imsitems{$alldiscussion{$_}}{'sender'}.
502: $imsitems{$alldiscussion{$_}}{'timestamp'}.'<br /><br />'.
503: $imsitems{$alldiscussion{$_}}{'message'}.'<br />'.
504: $imsitems{$alldiscussion{$_}}{'attach'}.'</body></html>'."\n";
505: close($postingfile);
506: } else {
507: $discussion .= 'An error occurred opening the export file for posting '.$alldiscussion{$_}.'<br />';
508: }
509: $copyresult.=&replicate_attachments($imsitems{$alldiscussion{$_}}{'allattachments'},$tempexport);
510: } else {
511: $discussion.='<td bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].
512: '" colspan="'.$colspan.'">'. $discussionitems[$alldiscussion{$_}].
513: '</td></tr>';
514: }
1.69 www 515: }
1.80 raeburn 516: }
1.116 raeburn 517: unless ($outputtarget eq 'tex' || $outputtarget eq 'export') {
1.97 raeburn 518: my $colspan=$maxdepth+1;
1.111 raeburn 519: $discussion .= <<END;
1.97 raeburn 520: <tr bgcolor="#FFFFFF">
1.98 raeburn 521: <td colspan="$colspan" valign="top">
1.97 raeburn 522: <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
523: <tr>
524: <td align="left">
525: <table border="0" cellpadding="0" cellspacing="4">
526: <tr>
527: <td>
528: <font size="-1"><b>$lt{'cuse'}</b>:</td>
529: <td> </td>
1.111 raeburn 530: <td><font size="-1">
1.97 raeburn 531: END
532: if ($newpostsflag) {
533: $discussion .=
1.111 raeburn 534: '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'nolo'}.' - <i>'.$currmark.'</i>';
535: if ($dischash{$toggkey}) {
536: $discussion .= ' 3. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
537: }
1.97 raeburn 538: } else {
1.111 raeburn 539: if ($dischash{$toggkey}) {
540: $discussion .= '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
541: } else {
542: $discussion .=
543: $lt{'disp'}.' - <i>'.$currdisp.'</i>';
544: }
1.97 raeburn 545: }
546: $discussion .= <<END;
1.111 raeburn 547: </font></td>
1.97 raeburn 548: <td> </td>
549: <td>
1.111 raeburn 550: <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b>
551: </td>
1.97 raeburn 552: </tr>
553: </table>
554: </td>
1.111 raeburn 555: END
556: if ($dischash{$toggkey}) {
557: my $storebutton = &mt('Store read/unread changes');
558: $discussion.='<td align="right">'.
559: '<input type="hidden" name="discsymb" value="'.$ressymb.'">'."\n".
560: '<input type="button" name="readoptions" value="'.$storebutton.'"'.
561: ' onClick="this.form.submit();">'."\n".
562: '</td>';
563: }
564: $discussion .= (<<END);
1.97 raeburn 565: </tr>
566: </table>
567: </td>
568: </tr>
569: </table>
1.111 raeburn 570: <br /><br /></form>
1.97 raeburn 571: END
1.114 sakharuk 572: }
1.116 raeburn 573: if ($outputtarget eq 'export') {
574: if ($manifestok) {
575: while ($currdepth > 0) {
576: print $manifestfile " </item>\n";
577: $currdepth --;
578: }
579: print $manifestfile qq|
580: </organization>
581: </organizations>
582: <resources>
583: $imsresources
584: </resources>
585: </manifest>
586: |;
587: close($manifestfile);
588:
589: #Create zip file in prtspool
590:
591: my $imszipfile = '/prtspool/'.
592: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
593: time.'_'.rand(1000000000).'.zip';
594: # zip can cause an sh launch which can pass along all of %ENV
595: # which can be too large for /bin/sh to handle
596: my %oldENV=%ENV;
597: undef(%ENV);
598: my $cwd = &getcwd();
599: my $imszip = '/home/httpd/'.$imszipfile;
600: chdir $tempexport;
601: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
602: close(OUTPUT);
603: chdir $cwd;
604: %ENV=%oldENV;
605: undef(%oldENV);
606: $discussion .= 'Download the zip file from <a href="'.$imszipfile.'">Discussion Posting Archive</a><br />';
607: if ($copyresult) {
1.125 raeburn 608: $discussion .= 'The following errors occurred during export - <br />'.$copyresult;
1.116 raeburn 609: }
610: } else {
611: $discussion .= '<br />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 />';
612: }
613: return $discussion;
614: }
1.54 www 615: }
616: if ($discussiononly) {
1.108 raeburn 617: my $now = time;
618: my $attachnum = 0;
619: my $newattachmsg = '';
620: my @currnewattach = ();
621: my @currdelold = ();
622: my $comment = '';
623: my $subject = '';
624: if ($ENV{'form.origpage'}) {
625: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']);
1.124 raeburn 626: $subject = &Apache::lonnet::unescape($ENV{'form.subject'});
627: $comment = &Apache::lonnet::unescape($ENV{'form.comment'});
1.108 raeburn 628: my @keepold = ();
629: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
630: if (@currnewattach > 0) {
631: $attachnum += @currnewattach;
632: }
633: }
1.122 raeburn 634: if (&discussion_open($status)) {
635: $discussion.=(<<ENDDISCUSS);
1.54 www 636: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
637: <input type="submit" name="discuss" value="Post Discussion" />
638: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
1.73 albertel 639: <input type="hidden" name="symb" value="$ressymb" />
1.54 www 640: <input type="hidden" name="sendit" value="true" />
1.108 raeburn 641: <input type="hidden" name="timestamp" value="$now" />
642: <br /><a name="newpost"></a>
643: <font size="1">Note: in anonymous discussion, your name is visible only
644: to course faculty</font><br />
645: <b>Title:</b> <input type="text" name="subject" value="$subject" size="30" /><br /><br />
646: <textarea name="comment" cols="80" rows="14" wrap="hard">$comment</textarea>
1.54 www 647: ENDDISCUSS
1.108 raeburn 648: if ($ENV{'form.origpage'}) {
649: $discussion.='<input type="hidden" name="origpage" value="'.$ENV{'form.origpage'}.'" />'."\n";
650: foreach (@currnewattach) {
651: $discussion.='<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
652: }
653: }
654: $discussion.="</form>\n";
1.95 sakharuk 655: if ($outputtarget ne 'tex') {
1.108 raeburn 656: $discussion.=&generate_attachments_button('',$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,'',$mode);
657: if (@currnewattach > 0) {
658: $newattachmsg .= '<b>New attachments</b><br />';
659: if (@currnewattach > 1) {
660: $newattachmsg .= '<ol>';
661: foreach my $item (@currnewattach) {
662: $item =~ m#.*/([^/]+)$#;
663: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
664: }
665: $newattachmsg .= '</ol>'."\n";
666: } else {
667: $currnewattach[0] =~ m#.*/([^/]+)$#;
668: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
669: }
670: }
671: $discussion.=$newattachmsg;
1.95 sakharuk 672: $discussion.=&generate_preview_button();
673: }
1.122 raeburn 674: }
1.116 raeburn 675: } else {
1.92 albertel 676: if (&discussion_open($status) &&
1.90 albertel 677: &Apache::lonnet::allowed('pch',
1.74 www 678: $ENV{'request.course.id'}.
679: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.95 sakharuk 680: if ($outputtarget ne 'tex') {
681: $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
1.129 albertel 682: $ressymb.':::" '.$target.'>'.
1.95 sakharuk 683: '<img src="/adm/lonMisc/chat.gif" border="0" />'.
684: &mt('Post Discussion').'</a></td></tr></table>';
685: }
1.100 raeburn 686: }
1.74 www 687: }
1.114 sakharuk 688: return $discussion;
1.54 www 689: }
1.1 www 690:
1.116 raeburn 691: sub build_posting_display {
692: my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$statusfilter,$toggkey,$outputtarget) = @_;
693:
694: my @original=();
695: my @index=();
696:
697: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
698: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
699: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
700:
701: if ($contrib{'version'}) {
702: my $oldest = $contrib{'1:timestamp'};
703: if ($prevread eq '0') {
704: $prevread = $oldest-1;
705: }
706: for (my $id=1;$id<=$contrib{'version'};$id++) {
707: my $idx=$id;
708: my $posttime = $contrib{$idx.':timestamp'};
709: if ($prevread <= $posttime) {
710: $$newpostsflag = 1;
711: }
712: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
713: my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
714: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
715: my $origindex='0.';
716: my $numoldver=0;
717: if ($contrib{$idx.':replyto'}) {
718: if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
719: # this is a follow-up message
720: $original[$idx]=$original[$contrib{$idx.':replyto'}];
721: $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
722: $origindex=$index[$contrib{$idx.':replyto'}];
723: if ($$depth[$idx]>$$maxdepth) { $$maxdepth=$$depth[$idx]; }
724: } else {
725: $original[$idx]=0;
726: $$depth[$idx]=0;
727: }
728: } else {
729: # this is an original message
730: $original[$idx]=0;
731: $$depth[$idx]=0;
732: }
733: if ($$replies[$$depth[$idx]]) {
734: $$replies[$$depth[$idx]]++;
735: } else {
736: $$replies[$$depth[$idx]]=1;
737: }
738: unless ((($hidden) && (!$seeid)) || ($deleted)) {
739: $$visible++;
740: if ($contrib{$idx.':history'}) {
741: if ($contrib{$idx.':history'} =~ /:/) {
742: my @oldversions = split/:/,$contrib{$idx.':history'};
743: $numoldver = @oldversions;
744: } else {
745: $numoldver = 1;
746: }
747: }
748: $$current = $numoldver;
749: my %messages = ();
750: my %subjects = ();
751: my %attachtxt = ();
752: my %allattachments = ();
753: my ($screenname,$plainname);
754: my $sender = &mt('Anonymous');
755: my ($message,$subject,$vgrlink,$ctlink);
756: &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver);
757:
758:
759: # Set up for sorting by subject
760: unless ($outputtarget eq 'export') {
761: $message=$messages{$numoldver};
762: $message.=$attachtxt{$numoldver};
763: $subject=$subjects{$numoldver};
764: if ($message) {
765: if ($hidden) {
766: $message='<font color="#888888">'.$message.'</font>';
767: if ($studenthidden) {
768: $message .='<br /><br />Deleted by poster (student).';
769: }
770: }
771:
772: if ($subject eq '') {
773: if (defined($$subjectsort{'__No subject'})) {
774: push @{$$subjectsort{'__No subject'}}, $idx;
775: } else {
776: @{$$subjectsort{'__No subject'}} = ("$idx");
777: }
778: } else {
779: if (defined($$subjectsort{$subject})) {
780: push @{$$subjectsort{$subject}}, $idx;
781: } else {
782: @{$$subjectsort{$subject}} = ("$idx");
783: }
784: }
785: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
786: $sender=&Apache::loncommon::aboutmewrapper(
787: $plainname,
788: $contrib{$idx.':sendername'},
789: $contrib{$idx.':senderdomain'}).' ('.
790: $contrib{$idx.':sendername'}.' at '.
791: $contrib{$idx.':senderdomain'}.')';
792: if ($contrib{$idx.':anonymous'}) {
793: $sender.=' ['.&mt('anonymous').'] '.
794: $screenname;
795: }
796:
797: # Set up for sorting by domain, then username
798: unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {
799: %{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
800: }
801: if (defined($$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
802: push @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx;
803: } else {
804: @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
805: }
806: # Set up for sorting by last name, then first name
807: my %names = &Apache::lonnet::get('environment',
808: ['firstname','lastname'],$contrib{$idx.':senderdomain'},
809: ,$contrib{$idx.':sendername'});
810: my $lastname = $names{'lastname'};
811: my $firstname = $names{'firstname'};
812: if ($lastname eq '') {
813: $lastname = '_';
814: }
815: if ($firstname eq '') {
816: $firstname = '_';
817: }
818: unless (defined($$namesort{$lastname})) {
819: %{$$namesort{$lastname}} = ();
820: }
821: if (defined($$namesort{$lastname}{$firstname})) {
822: push @{$$namesort{$lastname}{$firstname}}, $idx;
823: } else {
824: @{$$namesort{$lastname}{$firstname}} = ("$idx");
825: }
826: if ($ENV{'course.'.$ENV{'request.course.id'}.'.allow_discussion_post_editing'} =~ m/yes/i) {
827: if (($ENV{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($ENV{'user.name'} eq $contrib{$idx.':sendername'})) {
828: $sender.=' <a href="/adm/feedback?editdisc='.
829: $ressymb.':::'.$idx;
830: if ($newpostsflag) {
831: $sender .= '&previous='.$prevread;
832: }
833: $sender .= '" '.$target.'>'.&mt('Edit').'</a>';
834: unless ($seeid) {
835: $sender.=" <a href=\"javascript:studentdelete('$ressymb','$idx','$newpostsflag','$prevread')";
836: $sender .= '">'.&mt('Delete').'</a>';
837: }
838: }
839: }
840: if ($seeid) {
841: if ($hidden) {
842: unless ($studenthidden) {
843: $sender.=' <a href="/adm/feedback?unhide='.
844: $ressymb.':::'.$idx;
845: if ($newpostsflag) {
846: $sender .= '&previous='.$prevread;
847: }
848: $sender .= '">'.&mt('Make Visible').'</a>';
849: }
850: } else {
851: $sender.=' <a href="/adm/feedback?hide='.
852: $ressymb.':::'.$idx;
853: if ($newpostsflag) {
854: $sender .= '&previous='.$prevread;
855: }
856: $sender .= '">'.&mt('Hide').'</a>';
857: }
858: $sender.=' <a href="/adm/feedback?deldisc='.
859: $ressymb.':::'.$idx;
860: if ($newpostsflag) {
861: $sender .= '&previous='.$prevread;
862: }
863: $sender .= '">'.&mt('Delete').'</a>';
864: }
865: } else {
866: if ($screenname) {
867: $sender='<i>'.$screenname.'</i>';
868: }
869: # Set up for sorting by domain, then username for anonymous
870: unless (defined($$usernamesort{'__anon'})) {
871: %{$$usernamesort{'__anon'}} = ();
872: }
873: if (defined($$usernamesort{'__anon'}{'__anon'})) {
874: push @{$$usernamesort{'__anon'}{'__anon'}}, $idx;
875: } else {
876: @{$$usernamesort{'__anon'}{'__anon'}} = ("$idx");
877: }
878: # Set up for sorting by last name, then first name for anonymous
879: unless (defined($$namesort{'__anon'})) {
880: %{$$namesort{'__anon'}} = ();
881: }
882: if (defined($$namesort{'__anon'}{'__anon'})) {
883: push @{$$namesort{'__anon'}{'__anon'}}, $idx;
884: } else {
885: @{$$namesort{'__anon'}{'__anon'}} = ("$idx");
886: }
887: }
888: if (&discussion_open($status) &&
889: &Apache::lonnet::allowed('pch',
890: $ENV{'request.course.id'}.
891: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
892: $sender.=' <a href="/adm/feedback?replydisc='.
893: $ressymb.':::'.$idx;
894: if ($newpostsflag) {
895: $sender .= '&previous='.$prevread;
896: }
897: $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
898: }
899: if ($viewgrades) {
900: $vgrlink=&Apache::loncommon::submlink('Submissions',
901: $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
902: }
903: if ($$dischash{$readkey}=~/\.$idx\./) {
904: $ctlink = '<b>'.&mt('Mark unread').'?</b> <input type="checkbox" name="postunread_'.$idx.'" />';
905: } else {
906: $ctlink = '<b>'.&mt('Mark read').'?</b> <input type="checkbox" name="postread_'.$idx.'" />';
907: }
908: }
909: #figure out at what position this needs to print
910: }
911: if ($outputtarget eq 'export' || $message) {
912: my $thisindex=$idx;
913: if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
914: $thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
915: }
916: $$alldiscussion{$thisindex}=$idx;
917: $$shown{$idx} = 0;
918: $index[$idx]=$thisindex;
919: }
920: if ($outputtarget eq 'export') {
921: %{$$imsitems{$idx}} = ();
922: $$imsitems{$idx}{'isvisible'}='true';
923: if ($hidden) {
924: $$imsitems{$idx}{'isvisible'}='false';
925: }
926: $$imsitems{$idx}{'title'}=$subjects{$numoldver};
927: $$imsitems{$idx}{'message'}=$messages{$numoldver};
928: $$imsitems{$idx}{'attach'}=$attachtxt{$numoldver};
929: $$imsitems{$idx}{'timestamp'}=$contrib{$idx.':timestamp'};
930: $$imsitems{$idx}{'sender'}=$plainname.' ('.
931: $contrib{$idx.':sendername'}.' at '.
932: $contrib{$idx.':senderdomain'}.')';
933: $$imsitems{$idx}{'isanonymous'}='false';
934: if ($contrib{$idx.':anonymous'}) {
935: $$imsitems{$idx}{'isanonymous'}='true';
936: }
937: $$imsitems{$idx}{'currversion'}=$numoldver;
938: %{$$imsitems{$idx}{'allattachments'}}=%allattachments;
939: unless ($messages{$numoldver} eq '' && $attachtxt{$numoldver} eq '') {
940: $$shown{$idx} = 1;
941: }
942: } else {
943: if ($message) {
944: my $spansize = 2;
945: if ($showonlyunread && $prevread > $posttime) {
946: $$notshown{$idx} = 1;
947: } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
948: $$notshown{$idx} = 1;
949: } else {
950: # apply filters
951: my $uname = $contrib{$idx.':sendername'};
952: my $udom = $contrib{$idx.':senderdomain'};
953: my $poster = $uname.':'.$udom;
954: my $rolematch = '';
955: my $skiptest = 1;
956: if ($totposters > 0) {
957: if (grep/^$poster$/,@{$posters}) {
958: $$shown{$idx} = 1;
959: }
960: } else {
961: if ($rolefilter) {
962: if ($rolefilter eq 'all') {
963: $rolematch = '([^:]+)';
964: } else {
965: $rolematch = $rolefilter;
966: $skiptest = 0;
967: }
968: }
969: if ($sectionpick) {
970: if ($sectionpick eq 'all') {
971: $rolematch .= ':([^:]*)';
972: } else {
973: $rolematch .= ':'.$sectionpick;
974: $skiptest = 0;
975: }
976: }
977: if ($statusfilter) {
978: if ($statusfilter eq 'all') {
979: $rolematch .= ':([^:]+)';
980: } else {
981: $rolematch .= ':'.$statusfilter;
982: $skiptest = 0;
983: }
984: }
985: if ($skiptest) {
986: $$shown{$idx} = 1;
987: } else {
988: foreach my $role (@{$$roleinfo{$poster}}) {
989: if ($role =~ m/^$rolematch$/) {
990: $$shown{$idx} = 1;
991: last;
992: }
993: }
994: }
995: }
996: }
997: unless ($$notshown{$idx} == 1) {
998: if ($prevread > 0 && $prevread <= $posttime) {
999: $$newitem{$idx} = 1;
1000: $$discussionitems[$idx] .= '
1001: <p><table border="0" width="100%">
1002: <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
1003: } else {
1004: $$newitem{$idx} = 0;
1005: $$discussionitems[$idx] .= '
1006: <p><table border="0" width="100%">
1007: <tr><td align="left"> </td>';
1008: }
1009: $$discussionitems[$idx] .= '<td align ="left"> '.
1010: '<b>'.$subject.'</b> '.
1011: $sender.'</b> '.$vgrlink.' ('.
1012: &Apache::lonlocal::locallocaltime($posttime).')</td>';
1013: if ($$dischash{$toggkey}) {
1014: $$discussionitems[$idx].='<td align="right"> '.
1015: $ctlink.'</td>';
1016: }
1017: $$discussionitems[$idx].= '</tr></table><blockquote>'.
1018: $message.'</blockquote></p>';
1019: if ($contrib{$idx.':history'}) {
1020: my @postversions = ();
1021: $$discussionitems[$idx] .= &mt('This post has been edited by the author.');
1022: if ($seeid) {
1023: $$discussionitems[$idx] .= ' <a href="/adm/feedback?allversions='.$ressymb.':::'.$idx.'">'.&mt('Display all versions').'</a>';
1024: }
1025: $$discussionitems[$idx].='<br/>'.&mt('Earlier version(s) were posted on: ');
1026: if ($contrib{$idx.':history'} =~ m/:/) {
1027: @postversions = split/:/,$contrib{$idx.':history'};
1028: } else {
1029: @postversions = ("$contrib{$idx.':history'}");
1030: }
1031: for (my $i=0; $i<@postversions; $i++) {
1032: my $version = $i+1;
1033: $$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' ';
1034: }
1035: }
1036: }
1037: }
1038: }
1039: }
1040: }
1041: }
1042: }
1043:
1044: sub get_post_contents {
1045: my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_;
1046: my $discussion = '';
1047: my $start=$numver;
1048: my $end=$numver + 1;
1049: %{$$imsfiles{$idx}}=();
1050: if ($type eq 'allversions') {
1051: unless($seeid) {
1052: $discussion=&mt('You do not have privileges to view all versions of posts.').&mt('Please select a different role');
1053: return $discussion;
1054: }
1055: }
1.126 albertel 1056: # $$screenname=&Apache::loncommon::screenname(
1057: # $$contrib{$idx.':sendername'},
1058: # $$contrib{$idx.':senderdomain'});
1059: # $$plainname=&Apache::loncommon::nickname(
1060: # $$contrib{$idx.':sendername'},
1061: # $$contrib{$idx.':senderdomain'});
1062: ($$screenname,$$plainname)=($$contrib{$idx.':screenname'},
1063: $$contrib{$idx.':plainname'});
1.116 raeburn 1064: my $sender=&Apache::loncommon::aboutmewrapper(
1065: $$plainname,
1066: $$contrib{$idx.':sendername'},
1067: $$contrib{$idx.':senderdomain'}).' ('.
1068: $$contrib{$idx.':sendername'}.' at '.
1069: $$contrib{$idx.':senderdomain'}.')';
1070: my $attachmenturls = $$contrib{$idx.':attachmenturl'};
1071: my @postversions = ();
1072: if ($type eq 'allversions' || $type eq 'export') {
1073: $start = 0;
1074: if ($$contrib{$idx.':history'}) {
1075: if ($$contrib{$idx.':history'} =~ m/:/) {
1076: @postversions = split/:/,$$contrib{$idx.':history'};
1077: } else {
1078: @postversions = ("$$contrib{$idx.':history'}");
1079: }
1080: }
1081: &get_post_versions($messages,$$contrib{$idx.':message'},1);
1082: &get_post_versions($subjects,$$contrib{$idx.':subject'},1);
1083: push @postversions,$$contrib{$idx.':timestamp'};
1084: $end = @postversions;
1085: } else {
1086: &get_post_versions($messages,$$contrib{$idx.':message'},1,$numver);
1087: &get_post_versions($subjects,$$contrib{$idx.':subject'},1,$numver);
1088: }
1089:
1090: if ($$contrib{$idx.':anonymous'}) {
1091: $sender.=' ['.&mt('anonymous').'] '.$$screenname;
1092: }
1093: if ($type eq 'allversions') {
1094: $discussion=('<b>'.$sender.'</b><br /><ul>');
1095: }
1096: for (my $i=$start; $i<$end; $i++) {
1097: my ($timesent,$attachmsg);
1098: my %currattach = ();
1099: $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
1100: $$messages{$i}=~s/\n/\<br \/\>/g;
1101: $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
1102: $$subjects{$i}=~s/\n/\<br \/\>/g;
1103: $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
1104: if ($attachmenturls) {
1105: &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,$allattachments,\%currattach);
1106: }
1107: if ($type eq 'export') {
1108: $$imsfiles{$idx}{$i} = '';
1109: if ($attachmsg) {
1110: $$attachtxt{$i} = '<br />Attachments:<br />';
1111: foreach (sort keys %currattach) {
1112: if ($$allattachments{$_}{'filename'} =~ m-^/uploaded/([^/]+/[^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1113: my $fname = $1.$3.'/'.$4;
1114: $$imsfiles{$idx}{$i} .= '<file href="'.$fname.'">'."\n";
1115: $$attachtxt{$i}.= '<a href="'.$fname.'">'.$4.'</a><br />';
1116: }
1117: }
1118: }
1119: } else {
1120: if ($attachmsg) {
1121: $$attachtxt{$i} = '<br />Attachments:'.$attachmsg.'<br />';
1122: } else {
1123: $$attachtxt{$i} = '';
1124: }
1125: }
1126: if ($type eq 'allversions') {
1127: $discussion.= <<"END";
1128: <li><b>$$subjects{$i}</b>, $timesent<br />
1129: $$messages{$i}<br />
1130: $$attachtxt{$i}</li>
1131: END
1132: }
1133: }
1134: if ($type eq 'allversions') {
1135: $discussion.=('</ul></body></html>');
1136: return $discussion;
1137: } else {
1138: return;
1139: }
1140: }
1141:
1142: sub replicate_attachments {
1143: my ($attachrefs,$tempexport) = @_;
1144: my $response;
1145: foreach my $id (keys %{$attachrefs}) {
1146: if ($$attachrefs{$id}{'filename'} =~ m-^/uploaded/([^/]+)/([^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1147: my $path = $tempexport;
1148: my $tail = $1.'/'.$2.$4;
1149: my @extras = split/\//,$tail;
1150: my $destination = $tempexport.'/'.$1.'/'.$2.$4.'/'.$5;
1151: if (!-e $destination) {
1152: my $i= 0;
1153: while ($i<@extras) {
1154: $path .= '/'.$extras[$i];
1155: if (!-e $path) {
1156: mkdir($path,0700);
1157: }
1158: $i ++;
1159: }
1160: my ($content,$rtncode);
1161: my $uploadreply = &Apache::lonnet::getuploaded('GET',$$attachrefs{$id}{'filename'},$1,$2,$content,$rtncode);
1162: if ($uploadreply eq 'ok') {
1.125 raeburn 1163: my $attachcopy;
1164: if ($attachcopy = Apache::File->new('>'.$destination)) {
1165: print $attachcopy $content;
1166: close($attachcopy);
1167: } else {
1168: $response .= 'Error copying file attachment - '.$5.' to IMS package: '.$!.'<br />'."\n";
1169: }
1.116 raeburn 1170: } else {
1.125 raeburn 1171: &Apache::lonnet::logthis("Replication of attachment failed when building IMS export of discussion posts - domain: $1, course: $2, file: $$attachrefs{$id}{'filename'} -error: $rtncode");
1172: $response .= 'Error copying file attachment - '.$5.' to IMS package: '.$rtncode.'<br />'."\n";
1.116 raeburn 1173: }
1174: }
1175: }
1176: }
1.125 raeburn 1177: return $response;
1.116 raeburn 1178: }
1179:
1.6 albertel 1180: sub mail_screen {
1181: my ($r,$feedurl,$options) = @_;
1.108 raeburn 1182: if (exists($ENV{'form.origpage'})) {
1183: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']);
1184: }
1.45 www 1185: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
1.102 raeburn 1186: '','onLoad="window.focus();setposttype();"');
1.51 albertel 1187: my $title=&Apache::lonnet::gettitle($feedurl);
1188: if (!$title) { $title = $feedurl; }
1.69 www 1189: my $quote='';
1.78 raeburn 1190: my $subject = '';
1.108 raeburn 1191: my $comment = '';
1.80 raeburn 1192: my $prevtag = '';
1.102 raeburn 1193: my $parentmsg = '';
1.108 raeburn 1194: my ($symb,$idx,$attachmenturls);
1195: my $numoldver = 0;
1196: my $attachmsg = '';
1197: my $newattachmsg = '';
1198: my @currnewattach = ();
1199: my @currdelold = ();
1200: my @keepold = ();
1.113 raeburn 1201: my %attachments = ();
1.108 raeburn 1202: my %currattach = ();
1203: my $attachnum = 0;
1204: my $anonchk = (<<END);
1205: function anonchk() {
1206: if (document.mailform.anondiscuss.checked == true) {
1207: document.attachment.anondiscuss.value = '1'
1208: }
1209: if (document.mailform.discuss.checked == true) {
1210: document.attachment.discuss.value = '1'
1211: }
1212: return
1213: }
1214: END
1215: my $anonscript;
1216: if (exists($ENV{'form.origpage'})) {
1217: $anonscript = (<<END);
1.102 raeburn 1218: function setposttype() {
1.108 raeburn 1219: var anondisc = $ENV{'form.anondiscuss'};
1220: var disc = $ENV{'form.discuss'};
1221: if (anondisc == 1) {
1222: document.mailform.anondiscuss.checked = true
1223: }
1224: if (disc == 1) {
1225: document.mailform.discuss.checked = true
1226: }
1.102 raeburn 1227: return
1228: }
1229: END
1.108 raeburn 1230: } else {
1231: $anonscript = (<<END);
1232: function setposttype() {
1233: return
1234: }
1235: END
1236: }
1.102 raeburn 1237: if (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
1238: if ($ENV{'form.replydisc'}) {
1239: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
1240: } else {
1241: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
1242: }
1.69 www 1243: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1244: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1245: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.80 raeburn 1246: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.112 raeburn 1247: if ($contrib{$idx.':history'}) {
1248: if ($contrib{$idx.':history'} =~ /:/) {
1249: my @oldversions = split/:/,$contrib{$idx.':history'};
1250: $numoldver = @oldversions;
1251: } else {
1252: $numoldver = 1;
1253: }
1254: }
1.102 raeburn 1255: if ($ENV{'form.replydisc'}) {
1256: if ($contrib{$idx.':history'}) {
1257: if ($contrib{$idx.':history'} =~ /:/) {
1258: my @oldversions = split/:/,$contrib{$idx.':history'};
1259: $numoldver = @oldversions;
1260: } else {
1261: $numoldver = 1;
1262: }
1263: }
1.108 raeburn 1264: my $message;
1265: if ($idx > 0) {
1.116 raeburn 1266: my %msgversions = ();
1267: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1268: $message = $msgversions{$numoldver};
1.108 raeburn 1269: }
1.102 raeburn 1270: $message=~s/\n/\<br \/\>/g;
1.108 raeburn 1271: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.102 raeburn 1272: if ($idx > 0) {
1.116 raeburn 1273: my %subversions = ();
1274: &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
1275: $subject = 'Re: '.$subversions{$numoldver};
1.102 raeburn 1276: }
1.108 raeburn 1277: $subject = &HTML::Entities::encode($subject,'<>&"');
1.102 raeburn 1278: } else {
1.108 raeburn 1279: $attachmenturls = $contrib{$idx.':attachmenturl'};
1.116 raeburn 1280: if ($idx > 0) {
1281: my %msgversions = ();
1282: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1283: $comment = $msgversions{$numoldver};
1284: my %subversions = ();
1285: &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
1286: $subject = $subversions{$numoldver};
1.102 raeburn 1287: }
1288: if (defined($contrib{$idx.':replyto'})) {
1289: $parentmsg = $contrib{$idx.':replyto'};
1290: }
1.108 raeburn 1291: unless (exists($ENV{'form.origpage'})) {
1292: my $anonflag = 0;
1293: if ($contrib{$idx.':anonymous'}) {
1294: $anonflag = 1;
1295: }
1296: $anonscript = (<<END);
1.102 raeburn 1297: function setposttype () {
1298: var currtype = $anonflag
1299: if (currtype == 1) {
1300: document.mailform.elements.discuss.checked = false
1301: document.mailform.elements.anondiscuss.checked = true
1302: }
1303: if (currtype == 0) {
1304: document.mailform.elements.anondiscuss.checked = false
1305: document.mailform.elements.discuss.checked = true
1306: }
1307: return
1308: }
1309: END
1.108 raeburn 1310: }
1.79 raeburn 1311: }
1.69 www 1312: }
1.80 raeburn 1313: if ($ENV{'form.previous'}) {
1314: $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
1315: }
1.69 www 1316: }
1.108 raeburn 1317:
1318: if ($ENV{'form.origpage'}) {
1.124 raeburn 1319: $subject = &Apache::lonnet::unescape($ENV{'form.subject'});
1320: $comment = &Apache::lonnet::unescape($ENV{'form.comment'});
1.108 raeburn 1321: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1322: }
1.85 www 1323: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.86 www 1324: my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
1.74 www 1325: my $send=&mt('Send');
1.102 raeburn 1326: $r->print(<<END);
1.1 www 1327: <html>
1328: <head>
1329: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 1330: <meta http-equiv="pragma" content="no-cache"></meta>
1.85 www 1331: $htmlheader
1.63 albertel 1332: <script type="text/javascript">
1333: //<!--
1.5 www 1334: function gosubmit() {
1335: var rec=0;
1.12 albertel 1336: if (typeof(document.mailform.elements.author)!="undefined") {
1.5 www 1337: if (document.mailform.elements.author.checked) {
1338: rec=1;
1339: }
1340: }
1.12 albertel 1341: if (typeof(document.mailform.elements.question)!="undefined") {
1.5 www 1342: if (document.mailform.elements.question.checked) {
1343: rec=1;
1344: }
1345: }
1.12 albertel 1346: if (typeof(document.mailform.elements.course)!="undefined") {
1.5 www 1347: if (document.mailform.elements.course.checked) {
1348: rec=1;
1349: }
1350: }
1.12 albertel 1351: if (typeof(document.mailform.elements.policy)!="undefined") {
1.5 www 1352: if (document.mailform.elements.policy.checked) {
1353: rec=1;
1354: }
1355: }
1.12 albertel 1356: if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10 www 1357: if (document.mailform.elements.discuss.checked) {
1358: rec=1;
1359: }
1360: }
1.14 www 1361: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
1362: if (document.mailform.elements.anondiscuss.checked) {
1363: rec=1;
1364: }
1365: }
1.5 www 1366:
1367: if (rec) {
1.118 albertel 1368: if (typeof(document.mailform.onsubmit)=='function') {
1.105 www 1369: document.mailform.onsubmit();
1370: }
1.5 www 1371: document.mailform.submit();
1372: } else {
1373: alert('Please check a feedback type.');
1374: }
1375: }
1.108 raeburn 1376: $anonchk
1.102 raeburn 1377: $anonscript
1.63 albertel 1378: //-->
1.5 www 1379: </script>
1.1 www 1380: </head>
1.29 www 1381: $bodytag
1.51 albertel 1382: <h2><tt>$title</tt></h2>
1.43 www 1383: <form action="/adm/feedback" method="post" name="mailform"
1384: enctype="multipart/form-data">
1.80 raeburn 1385: $prevtag
1.63 albertel 1386: <input type="hidden" name="postdata" value="$feedurl" />
1.102 raeburn 1387: END
1388: if ($ENV{'form.replydisc'}) {
1389: $r->print(<<END);
1.68 www 1390: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
1.102 raeburn 1391: END
1392: } elsif ($ENV{'form.editdisc'}) {
1393: $r->print(<<END);
1394: <input type="hidden" name="editdisc" value ="$ENV{'form.editdisc'}" />
1395: <input type="hidden" name="parentmsg" value ="$parentmsg" />
1396: END
1397: }
1.108 raeburn 1398: $r->print(<<END);
1.5 www 1399: Please check at least one of the following feedback types:
1.63 albertel 1400: $options<hr />
1.69 www 1401: $quote
1.63 albertel 1402: <p>My question/comment/feedback:</p>
1403: <p>
1.47 bowersj2 1404: $latexHelp
1.78 raeburn 1405: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
1406: <p>
1.108 raeburn 1407: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$comment
1.63 albertel 1408: </textarea></p>
1409: <p>
1.108 raeburn 1410: END
1411: if ( ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'}) ) {
1412: if ($ENV{'form.origpage'}) {
1413: foreach (@currnewattach) {
1414: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
1415: }
1416: foreach (@currdelold) {
1417: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
1418: }
1419: }
1420: if ($ENV{'form.editdisc'}) {
1421: if ($attachmenturls) {
1.113 raeburn 1422: &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
1.108 raeburn 1423: $attachnum = scalar(keys %currattach);
1424: foreach (keys %currattach) {
1425: $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
1426: }
1427: }
1428: }
1429: } else {
1430: $r->print(<<END);
1.42 www 1431: Attachment (128 KB max size): <input type="file" name="attachment" />
1432: </p>
1.108 raeburn 1433: END
1434: }
1435: $r->print(<<END);
1.42 www 1436: <p>
1437: <input type="hidden" name="sendit" value="1" />
1.74 www 1438: <input type="button" value="$send" onClick='gosubmit();' />
1.42 www 1439: </p>
1.2 www 1440: </form>
1.108 raeburn 1441: END
1442: if ($ENV{'form.editdisc'} || $ENV{'form.replydisc'}) {
1443: my $now = time;
1444: my $ressymb = $symb;
1445: my $postidx = '';
1446: if ($ENV{'form.editdisc'}) {
1447: $postidx = $idx;
1448: }
1449: if (@currnewattach > 0) {
1450: $attachnum += @currnewattach;
1451: }
1452: $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver));
1453: if ($attachnum > 0) {
1454: if (@currnewattach > 0) {
1455: $newattachmsg .= '<b>New attachments</b><br />';
1456: if (@currnewattach > 1) {
1457: $newattachmsg .= '<ol>';
1458: foreach my $item (@currnewattach) {
1459: $item =~ m#.*/([^/]+)$#;
1460: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
1461: }
1462: $newattachmsg .= '</ol>'."\n";
1463: } else {
1464: $currnewattach[0] =~ m#.*/([^/]+)$#;
1465: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
1466: }
1467: }
1468: if ($attachmsg) {
1469: $r->print("<b>Retained attachments</b>:$attachmsg<br />\n");
1470: }
1471: if ($newattachmsg) {
1472: $r->print("$newattachmsg<br />");
1473: }
1474: }
1475: }
1476: $r->print(&generate_preview_button().
1477: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
1478: '</body></html>');
1.6 albertel 1479: }
1480:
1.97 raeburn 1481: sub print_display_options {
1.111 raeburn 1482: my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
1.98 raeburn 1483: # backward compatibility (bulletin boards used to be 'wrapped')
1484: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1485: $feedurl=~s|^/adm/wrapper||;
1486: }
1487:
1.97 raeburn 1488: my $function = &Apache::loncommon::get_users_function();
1489: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1490: $ENV{'user.domain'});
1491: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1492: '','');
1493:
1494: my %lt = &Apache::lonlocal::texthash(
1495: 'dido' => 'Discussion display options',
1496: 'pref' => 'Display Preference',
1497: 'curr' => 'Current setting ',
1498: 'actn' => 'Action',
1499: 'deff' => 'Default for all discussions',
1500: 'prca' => 'Preferences can be set for this discussion that determine ....',
1501: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
1.111 raeburn 1502: 'unwh' => 'Under what circumstances posts are identified as "NEW", and',
1503: 'wipa' => 'Whether individual posts can be marked as read/unread',
1.97 raeburn 1504: 'allposts' => 'All posts',
1505: 'unread' => 'New posts only',
1.111 raeburn 1506: 'unmark' => 'Posts not marked read',
1.97 raeburn 1507: 'ondisp' => 'Once displayed',
1.111 raeburn 1508: 'onmark' => 'Once marked not NEW ',
1509: 'toggon' => 'Shown',
1510: 'toggoff' => 'Not shown',
1.97 raeburn 1511: 'disa' => 'Posts displayed?',
1.111 raeburn 1512: 'npmr' => 'New posts cease to be identified as "NEW"?',
1513: 'dotm' => 'Option to mark each post as read/unread?',
1.97 raeburn 1514: 'chgt' => 'Change to ',
1515: 'mkdf' => 'Set to ',
1.111 raeburn 1516: 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
1.97 raeburn 1517: 'ywbr' => 'You will be returned to the previous page if you click OK.'
1518: );
1519:
1.111 raeburn 1520: my $dispchangeA = $lt{'unread'};
1521: my $dispchangeB = $lt{'unmark'};
1.97 raeburn 1522: my $markchange = $lt{'ondisp'};
1.111 raeburn 1523: my $toggchange = $lt{'toggon'};
1.97 raeburn 1524: my $currdisp = $lt{'allposts'};
1525: my $currmark = $lt{'onmark'};
1526: my $discdisp = 'allposts';
1527: my $discmark = 'onmark';
1.111 raeburn 1528: my $currtogg = $lt{'toggoff'};
1529: my $disctogg = 'toggoff';
1.97 raeburn 1530:
1.111 raeburn 1531: if ($dispchgA eq 'allposts') {
1532: $dispchangeA = $lt{'allposts'};
1.97 raeburn 1533: $currdisp = $lt{'unread'};
1534: $discdisp = 'unread';
1535: }
1.111 raeburn 1536:
1.97 raeburn 1537: if ($markchg eq 'markonread') {
1538: $markchange = $lt{'onmark'};
1539: $currmark = $lt{'ondisp'};
1540: $discmark = 'ondisp';
1541: }
1.111 raeburn 1542:
1543: if ($dispchgB eq 'onlyunread') {
1544: $dispchangeB = $lt{'unread'};
1545: $currdisp = $lt{'unmark'};
1546: $discdisp = 'unmark';
1547: }
1548: if ($toggchg eq 'toggoff') {
1549: $toggchange = $lt{'toggoff'};
1550: $currtogg = $lt{'toggon'};
1551: $disctogg = 'toggon';
1552: }
1.97 raeburn 1553: $r->print(<<END);
1554: <html>
1555: <head>
1556: <title>$lt{'dido'}</title>
1557: <meta http-equiv="pragma" content="no-cache" />
1558: <script>
1.111 raeburn 1559: function discdispChk(caller) {
1560: var disctogg = '$toggchg'
1561: if (caller == 0) {
1562: if (document.modifydisp.discdisp[0].checked == true) {
1563: if (document.modifydisp.discdisp[1].checked == true) {
1564: document.modifydisp.discdisp[1].checked = false
1565: }
1566: }
1567: }
1568: if (caller == 1) {
1569: if (document.modifydisp.discdisp[1].checked == true) {
1570: if (document.modifydisp.discdisp[0].checked == true) {
1571: document.modifydisp.discdisp[0].checked = false
1572: }
1573: if (disctogg == 'toggon') {
1574: document.modifydisp.disctogg.checked = true
1575: }
1576: if (disctogg == 'toggoff') {
1577: document.modifydisp.disctogg.checked = false
1578: }
1579: }
1580: }
1581: if (caller == 2) {
1582: var dispchgB = '$dispchgB'
1583: if (disctogg == 'toggoff') {
1584: if (document.modifydisp.disctogg.checked == true) {
1585: if (dispchgB == 'onlyunmark') {
1586: document.modifydisp.discdisp[1].checked = false
1587: }
1588: }
1589: }
1590: }
1591: }
1592:
1.97 raeburn 1593: function setDisp() {
1594: var prev = "$previous"
1595: var chktotal = 0
1.111 raeburn 1596: if (document.modifydisp.discdisp[0].checked == true) {
1597: document.modifydisp.$dispchgA.value = "$symb"
1598: chktotal ++
1599: }
1600: if (document.modifydisp.discdisp[1].checked == true) {
1601: document.modifydisp.$dispchgB.value = "$symb"
1.97 raeburn 1602: chktotal ++
1603: }
1604: if (document.modifydisp.discmark.checked == true) {
1605: document.modifydisp.$markchg.value = "$symb"
1606: chktotal ++
1607: }
1.111 raeburn 1608: if (document.modifydisp.disctogg.checked == true) {
1609: document.modifydisp.$toggchg.value = "$symb"
1610: chktotal ++
1611: }
1.97 raeburn 1612: if (chktotal > 0) {
1613: document.modifydisp.submit()
1614: } else {
1615: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
1616: if (prev > 0) {
1617: location.href = "$feedurl?previous=$previous"
1618: } else {
1619: location.href = "$feedurl"
1620: }
1621: }
1622: }
1623: }
1624: </script>
1625: </head>
1626: $bodytag
1627: <form name="modifydisp" method="post" action="/adm/feedback">
1.111 raeburn 1628: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
1.97 raeburn 1629: <br />
1630: <table border="0" cellpadding="0" cellspacing="0">
1631: <tr>
1632: <td width="100%" bgcolor="#000000">
1633: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1634: <tr>
1635: <td width="100%" bgcolor="#000000">
1636: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
1637: <tr bgcolor="$tabcolor">
1638: <td><b>$lt{'pref'}</b></td>
1639: <td><b>$lt{'curr'}</b></td>
1640: <td><b>$lt{'actn'}?</b></td>
1641: </tr>
1642: <tr bgcolor="#dddddd">
1643: <td>$lt{'disa'}</td>
1644: <td>$lt{$discdisp}</td>
1.111 raeburn 1645: <td><input type="checkbox" name="discdisp" onClick="discdispChk('0')" /> $lt{'chgt'} "$dispchangeA"
1646: <br />
1647: <input type="checkbox" name="discdisp" onClick="discdispChk('1')" /> $lt{'chgt'} "$dispchangeB"
1648: </td>
1.97 raeburn 1649: </tr><tr bgcolor="#eeeeee">
1650: <td>$lt{'npmr'}</td>
1651: <td>$lt{$discmark}</td>
1652: <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
1.111 raeburn 1653: </tr><tr bgcolor="#dddddd">
1654: <td>$lt{'dotm'}</td>
1655: <td>$lt{$disctogg}</td>
1656: <td><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</td>
1.97 raeburn 1657: </tr>
1658: </table>
1659: </td>
1660: </tr>
1661: </table>
1662: </td>
1663: </tr>
1664: </table>
1665: <br />
1666: <br />
1667: <input type="hidden" name="previous" value="$previous" />
1.111 raeburn 1668: <input type="hidden" name="$dispchgA" value=""/>
1669: <input type="hidden" name="$dispchgB" value=""/>
1.97 raeburn 1670: <input type="hidden" name="$markchg" value=""/>
1.111 raeburn 1671: <input type="hidden" name="$toggchg" value="" />
1.97 raeburn 1672: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
1673: <br />
1674: <br />
1675: </form>
1676: </body>
1677: </html>
1678: END
1679: return;
1680: }
1681:
1.100 raeburn 1682: sub print_sortfilter_options {
1683: my ($r,$symb,$previous,$feedurl) = @_;
1684: # backward compatibility (bulletin boards used to be 'wrapped')
1685: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1686: $feedurl=~s|^/adm/wrapper||;
1687: }
1688: my @sections = ();
1689: my $section_sel = '';
1690: my $numsections = 0;
1691: my $numvisible = 5;
1692: my ($classlist) = &Apache::loncoursedata::get_classlist(
1693: $ENV{'request.course.id'},
1694: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1695: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1696:
1697: my $sec_index = &Apache::loncoursedata::CL_SECTION();
1698: my $status_index = &Apache::loncoursedata::CL_STATUS();
1699: my %sectioncount = ();
1700: while (my ($student,$data) = each %$classlist) {
1701: my ($section,$status) = ($data->[$sec_index],
1702: $data->[$status_index]);
1703: unless ($section eq '' || $section =~ /^\s*$/) {
1704: if (!defined($sectioncount{$section})) {
1705: $sectioncount{$section} = 1;
1706: $numsections ++;
1707: } else {
1708: $sectioncount{$section} ++;
1709: }
1710: }
1711: }
1712:
1713: if ($ENV{'request.course.sec'} !~ /^\s*$/) {
1714: @sections = ($ENV{'request.course.sec'});
1715: $numvisible = 1;
1716: } else {
1717: @sections = sort {$a cmp $b} keys(%sectioncount);
1718: unshift(@sections,'all'); # Put 'all' at the front of the list
1719: if ($numsections < 4) {
1720: $numvisible = $numsections + 1;
1721: }
1722: }
1723: foreach (@sections) {
1724: $section_sel .= " <option value=\"$_\" />$_\n";
1725: }
1726:
1727: my $function = &Apache::loncommon::get_users_function();
1728: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1729: $ENV{'user.domain'});
1730: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1731: '','');
1732: my %lt = &Apache::lonlocal::texthash(
1733: 'diso' => 'Discussion sorting and filtering options',
1734: 'diop' => 'Display Options',
1735: 'curr' => 'Current setting ',
1736: 'actn' => 'Action',
1.101 raeburn 1737: 'prca' => 'Options can be set that control the sort order of the posts, in addition to which posts are displayed.',
1.100 raeburn 1738: 'soor' => 'Sort order',
1739: 'disp' => 'Specific user roles',
1740: 'actv' => 'Specific role status',
1741: 'spse' => 'Specific sections',
1742: 'psub' => 'Pick specific users (by name)',
1.101 raeburn 1743: 'shal' => 'Show a list of current posters'
1.100 raeburn 1744: );
1745: $r->print(<<END);
1746: <html>
1747: <head>
1748: <title>$lt{'diso'}</title>
1749: <meta http-equiv="pragma" content="no-cache" />
1750: </head>
1751: $bodytag
1752: <form name="modifyshown" method="post" action="/adm/feedback">
1753: <b>$lt{'diso'}</b><br/> $lt{'prca'}
1754: <br /><br />
1755: <table border="0">
1756: <tr>
1757: <td><b>$lt{'soor'}</b></td>
1758: <td> </td>
1759: <td><b>$lt{'disp'}</b></td>
1760: <td> </td>
1761: <td><b>$lt{'actv'}</b></td>
1762: <td> </td>
1763: <td><b>$lt{'spse'}</b></td>
1764: <td> </td>
1765: <td><b>$lt{'psub'}</b></td>
1766: </tr>
1767: <tr>
1768: <td>
1769: <select name="sortposts">
1770: <option value="ascdate" />Date order - oldest first
1771: <option value="descdate" />Date order - newest first
1772: <option value="thread" />Threaded
1773: <option value="subject" />By subject
1774: <option value="username" />By domain and username
1775: <option value="lastfirst" />By last name, first name
1776: </select>
1777: </td>
1778: <td> </td>
1779: <td>
1.101 raeburn 1780: <select name="rolefilter" multiple="true" size="5">
1.100 raeburn 1781: <option value="all" />All users
1782: <option value="st" />Students
1783: <option value="cc" />Course Coordinators
1784: <option value="in" />Instructors
1785: <option value="ta" />TAs
1786: <option value="pr" />Exam proctors
1787: <option value="cr" />Custom roles
1788: </select>
1789: </td>
1790: <td> </td>
1791: <td>
1792: <select name="statusfilter">
1793: <option value="all" />Roles of any status
1.101 raeburn 1794: <option value="Active" />Only active roles
1795: <option value="Expired" />Only inactive roles
1.100 raeburn 1796: </select>
1797: </td>
1798: <td> </td>
1799: <td>
1800: <select name="sectionpick" multiple="true" size="$numvisible">
1801: $section_sel
1802: </select>
1803: </td>
1804: <td> </td>
1805: <td><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</td>
1806: </tr>
1807: </table>
1808: <br />
1809: <br />
1810: <input type="hidden" name="previous" value="$previous" />
1811: <input type="hidden" name="applysort" value="$symb" />
1812: <input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
1813: <br />
1814: <br />
1815: </form>
1816: </body>
1817: </html>
1818: END
1819: }
1820:
1.101 raeburn 1821: sub print_showposters {
1822: my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
1823: # backward compatibility (bulletin boards used to be 'wrapped')
1824: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1825: $feedurl=~s|^/adm/wrapper||;
1826: }
1827: # backward compatibility (bulletin boards used to be 'wrapped')
1828: my $ressymb=$symb;
1829: if ($ressymb =~ /bulletin___\d+___/) {
1830: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1831: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1832: }
1833: }
1834: my $crs='/'.$ENV{'request.course.id'};
1.102 raeburn 1835: if ($ENV{'request.course.sec'}) {
1836: $crs.='_'.$ENV{'request.course.sec'};
1837: }
1.101 raeburn 1838: $crs=~s/\_/\//g;
1839: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1840: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1841: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1842: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1843: my %namesort = ();
1844: my %postcounts = ();
1845: my %lt=&Apache::lonlocal::texthash(
1846: 'diso' => 'Discussion filtering options',
1847: );
1848: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1849: '','');
1850: if ($contrib{'version'}) {
1851: for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
1852: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1853: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1854: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1855: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
1856: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
1857: my $lastname = $names{'lastname'};
1858: my $firstname = $names{'firstname'};
1859: if ($lastname eq '') {
1860: $lastname = '_';
1861: }
1862: if ($firstname eq '') {
1863: $firstname = '_';
1864: }
1865: unless (defined($namesort{$lastname})) {
1866: %{$namesort{$lastname}} = ();
1867: }
1868: my $poster = $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
1869: $postcounts{$poster} ++;
1870: if (defined($namesort{$lastname}{$firstname})) {
1871: if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
1872: push @{$namesort{$lastname}{$firstname}}, $poster;
1873: }
1874: } else {
1875: @{$namesort{$lastname}{$firstname}} = ("$poster");
1876: }
1877: }
1878: }
1879: }
1880: }
1881: $r->print(<<END);
1882: <html>
1883: <head>
1884: <title>$lt{'diso'}</title>
1885: <meta http-equiv="pragma" content="no-cache" />
1886: </head>
1887: $bodytag
1888: <form name="pickpostersform" method="post">
1889: <table border="0">
1890: <tr>
1891: <td bgcolor="#777777">
1892: <table border="0" cellpadding="3">
1893: <tr bgcolor="#e6ffff">
1894: <td><b>No.</b></td>
1895: <td><b>Select</b></td>
1896: <td><b>Fullname</b><font color="#999999">(Username/domain)</font></td>
1897: <td><b>Posts</td>
1898: </tr>
1899: END
1900: my $count = 0;
1901: foreach my $last (sort keys %namesort) {
1902: foreach my $first (sort keys %{$namesort{$last}}) {
1903: foreach (sort @{$namesort{$last}{$first}}) {
1904: my ($uname,$udom) = split/:/,$_;
1905: if (!$uname || !$udom) {
1906: next;
1907: } else {
1908: $count ++;
1909: $r->print('<tr bgcolor="#ffffe6"><td align="right">'.$count.'</td><td align="center"><input name="stuinfo" type="checkbox" value="'.$_.'" /></td><td>'.$last.', '.$first.' ('.$uname.','.$udom.')</td><td>'.$postcounts{$_}.'</td></tr>');
1910: }
1911: }
1912: }
1913: }
1914: $r->print(<<END);
1915: </table>
1916: </td>
1917: </tr>
1918: </table>
1919: <br />
1920: <input type="hidden" name="sortposts" value="$sortposts" />
1921: <input type="hidden" name="userpick" value="$symb" />
1922: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
1923: </form>
1924: </body>
1925: </html>
1926: END
1927: }
1928:
1.112 raeburn 1929: sub get_post_versions {
1.116 raeburn 1930: my ($versions,$incoming,$htmldecode,$numver) = @_;
1931: if ($incoming =~ /^<version num="0">/) {
1932: my $p = HTML::LCParser->new(\$incoming);
1933: my $done = 0;
1934: while ( (my $token = $p->get_tag("version")) && (!$done)) {
1935: my $num = $token->[1]{num};
1936: my $text = $p->get_text("/version");
1937: if (defined($numver)) {
1938: if ($num == $numver) {
1939: if ($htmldecode) {
1940: $text = &HTML::Entities::decode($text);
1941: }
1942: $$versions{$numver}=$text;
1943: $done = 1;
1944: }
1945: } else {
1946: if ($htmldecode) {
1947: $text = &HTML::Entities::decode($text);
1948: }
1949: $$versions{$num}=$text;
1.112 raeburn 1950: }
1.116 raeburn 1951: }
1952: } else {
1953: if (!defined($numver)) {
1954: $numver = 0;
1955: }
1956: if ($htmldecode) {
1957: $$versions{$numver} = $incoming;
1.112 raeburn 1958: } else {
1.116 raeburn 1959: $$versions{$numver} = &HTML::Entities::encode($incoming,'<>&"');
1.112 raeburn 1960: }
1961: }
1962: return;
1963: }
1964:
1.113 raeburn 1965: sub get_post_attachments {
1966: my ($attachments,$attachmenturls) = @_;
1967: my $num;
1.116 raeburn 1968: if ($attachmenturls =~ m/^<attachment id="0">/) {
1969: my $p = HTML::LCParser->new(\$attachmenturls);
1970: while (my $token = $p->get_tag("attachment","filename","post")) {
1971: if ($token->[0] eq "attachment") {
1972: $num = $token->[1]{id};
1973: %{$$attachments{$num}} =();
1974: } elsif ($token->[0] eq "filename") {
1975: $$attachments{$num}{'filename'} = $p->get_text("/filename");
1976: } elsif ($token->[0] eq "post") {
1977: my $id = $token->[1]{id};
1978: $$attachments{$num}{$id} = $p->get_text("/post");
1979: }
1.113 raeburn 1980: }
1.116 raeburn 1981: } else {
1982: %{$$attachments{'0'}} = ();
1983: $$attachments{'0'}{'filename'} = $attachmenturls;
1984: $$attachments{'0'}{'0'} = 'n';
1.113 raeburn 1985: }
1.116 raeburn 1986:
1.113 raeburn 1987: return;
1988: }
1989:
1990: sub fail_redirect {;
1.6 albertel 1991: my ($r,$feedurl) = @_;
1.70 www 1992: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.6 albertel 1993: $r->print (<<ENDFAILREDIR);
1.72 albertel 1994: <html>
1.5 www 1995: <head><title>Feedback not sent</title>
1.63 albertel 1996: <meta http-equiv="pragma" content="no-cache" />
1997: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5 www 1998: </head>
1999: <body bgcolor="#FFFFFF">
1.63 albertel 2000: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8 www 2001: <b>Sorry, no recipients ...</b>
1.121 albertel 2002: <br /><a href="$feedurl">Continue</a>
1.5 www 2003: </body>
2004: </html>
2005: ENDFAILREDIR
2006: }
1.4 www 2007:
1.6 albertel 2008: sub redirect_back {
1.101 raeburn 2009: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$secpick,$numpicks) = @_;
1.100 raeburn 2010: my $sorttag = '';
1.101 raeburn 2011: my $roletag = '';
2012: my $statustag = '';
2013: my $sectag = '';
2014: my $userpicktag = '';
2015: my $qrystr = '';
1.80 raeburn 2016: my $prevtag = '';
1.98 raeburn 2017: # backward compatibility (bulletin boards used to be 'wrapped')
2018: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2019: $feedurl=~s|^/adm/wrapper||;
2020: }
1.70 www 2021: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 2022: if ($previous > 0) {
2023: $qrystr = 'previous='.$previous;
2024: if ($feedurl =~ /\?register=1/) {
2025: $feedurl .= '&'.$qrystr;
2026: } else {
2027: $feedurl .= '?'.$qrystr;
2028: }
2029: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
2030: }
1.100 raeburn 2031: if (defined($sort)) {
2032: my $sortqry = 'sortposts='.$sort;
2033: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
2034: $feedurl .= '&'.$sortqry;
2035: } else {
2036: $feedurl .= '?'.$sortqry;
2037: }
2038: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.101 raeburn 2039: if ( (defined($numpicks)) && ($numpicks > 0) ) {
2040: my $userpickqry = 'totposters='.$numpicks;
2041: $feedurl .= '&'.$userpickqry;
2042: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
2043: } else {
2044: my $roleqry = 'rolefilter='.$rolefilter;
2045: $feedurl .= '&'.$roleqry;
2046: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
2047: $feedurl .= '&statusfilter='.$statusfilter;
2048: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
2049: $feedurl .= '§ionpick='.$secpick;
2050: $sectag = '<input type="hidden" name="sectionpick" value="'.$secpick.'" />';
2051: }
1.100 raeburn 2052: }
1.129 albertel 2053: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.6 albertel 2054: $r->print (<<ENDREDIR);
1.72 albertel 2055: <html>
1.3 www 2056: <head>
2057: <title>Feedback sent</title>
1.63 albertel 2058: <meta http-equiv="pragma" content="no-cache" />
1.80 raeburn 2059: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2 www 2060: </head>
1.49 www 2061: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63 albertel 2062: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5 www 2063: $typestyle
1.32 albertel 2064: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63 albertel 2065: <font color="red">$status</font>
1.49 www 2066: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 2067: $prevtag
1.100 raeburn 2068: $sorttag
1.101 raeburn 2069: $statustag
2070: $roletag
2071: $sectag
2072: $userpicktag
1.49 www 2073: </form>
1.121 albertel 2074: <br /><a href="$feedurl">Continue</a>
1.2 www 2075: </body>
2076: </html>
2077: ENDREDIR
2078: }
1.6 albertel 2079:
2080: sub no_redirect_back {
2081: my ($r,$feedurl) = @_;
1.107 www 2082: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.120 albertel 2083: my $continue=&mt('Continue');
1.6 albertel 2084: $r->print (<<ENDNOREDIR);
1.72 albertel 2085: <html>
1.2 www 2086: <head><title>Feedback not sent</title>
1.63 albertel 2087: <meta http-equiv="pragma" content="no-cache" />
1.7 albertel 2088: ENDNOREDIR
2089:
1.8 www 2090: if ($feedurl!~/^\/adm\/feedback/) {
1.129 albertel 2091: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.
2092: &Apache::lonenc::check_encrypt($feedurl).'">');
1.7 albertel 2093: }
1.129 albertel 2094: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.8 www 2095: $r->print (<<ENDNOREDIRTWO);
1.2 www 2096: </head>
1.49 www 2097: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63 albertel 2098: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.107 www 2099: <b>$nofeed</b>
1.121 albertel 2100: <br /><a href="$feedurl">$continue</a>
1.2 www 2101: </body>
2102: </html>
1.8 www 2103: ENDNOREDIRTWO
1.2 www 2104: }
1.6 albertel 2105:
2106: sub screen_header {
1.65 www 2107: my ($feedurl) = @_;
2108: my $msgoptions='';
2109: my $discussoptions='';
1.102 raeburn 2110: unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
1.65 www 2111: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
2112: $msgoptions=
2113: '<p><input type="checkbox" name="author" /> '.
2114: &mt('Feedback to resource author').'</p>';
2115: }
2116: if (&feedback_available(1)) {
2117: $msgoptions.=
2118: '<br /><input type="checkbox" name="question" /> '.
2119: &mt('Question about resource content');
2120: }
2121: if (&feedback_available(0,1)) {
2122: $msgoptions.=
2123: '<br /><input type="checkbox" name="course" /> '.
2124: &mt('Question/Comment/Feedback about course content');
2125: }
2126: if (&feedback_available(0,0,1)) {
2127: $msgoptions.=
2128: '<br /><input type="checkbox" name="policy" /> '.
2129: &mt('Question/Comment/Feedback about course policy');
2130: }
2131: }
2132: if ($ENV{'request.course.id'}) {
1.92 albertel 2133: if (&discussion_open() &&
1.90 albertel 2134: &Apache::lonnet::allowed('pch',
1.65 www 2135: $ENV{'request.course.id'}.
2136: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74 www 2137: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
2138: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65 www 2139: &mt('Contribution to course discussion of resource');
2140: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
2141: &mt('Anonymous contribution to course discussion of resource').
2142: ' <i>('.&mt('name only visible to course faculty').')</i>';
1.20 www 2143: }
1.65 www 2144: }
1.74 www 2145: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 2146: if ($discussoptions) {
1.74 www 2147: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 2148: return $msgoptions.$discussoptions;
1.6 albertel 2149: }
2150:
2151: sub resource_output {
2152: my ($feedurl) = @_;
1.46 albertel 2153: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 2154: $usersaw=~s/\<body[^\>]*\>//gi;
2155: $usersaw=~s/\<\/body\>//gi;
2156: $usersaw=~s/\<html\>//gi;
2157: $usersaw=~s/\<\/html\>//gi;
2158: $usersaw=~s/\<head\>//gi;
2159: $usersaw=~s/\<\/head\>//gi;
2160: $usersaw=~s/action\s*\=/would_be_action\=/gi;
2161: return $usersaw;
2162: }
2163:
2164: sub clear_out_html {
1.39 www 2165: my ($message,$override)=@_;
1.88 www 2166: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107 www 2167: # Always allow the <m>-tag
2168: my %html=(M=>1);
2169: # Check if more is allowed
1.37 albertel 2170: my $cid=$ENV{'request.course.id'};
1.39 www 2171: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
2172: ($override)) {
1.37 albertel 2173: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 2174: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
2175: # <SUP>
1.107 www 2176: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
2177: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
2178: M=>1, SUB=>1, SUP=>1, SPAN=>1,
2179: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
2180: }
2181: # Do the substitution of everything that is not explicitly allowed
2182: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48 albertel 2183: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.107 www 2184: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48 albertel 2185: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.6 albertel 2186: return $message;
2187: }
2188:
2189: sub assemble_email {
1.40 albertel 2190: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 2191: my $email=<<"ENDEMAIL";
2192: Refers to <a href="$feedurl">$feedurl</a>
2193:
2194: $message
2195: ENDEMAIL
2196: my $citations=<<"ENDCITE";
2197: <h2>Previous attempts of student (if applicable)</h2>
2198: $prevattempts
1.63 albertel 2199: <br /><hr />
1.6 albertel 2200: <h2>Original screen output (if applicable)</h2>
2201: $usersaw
1.40 albertel 2202: <h2>Correct Answer(s) (if applicable)</h2>
2203: $useranswer
1.6 albertel 2204: ENDCITE
2205: return ($email,$citations);
2206: }
2207:
1.35 www 2208: sub secapply {
2209: my $rec=shift;
1.36 www 2210: my $defaultflag=shift;
2211: $rec=~s/\s+//g;
2212: $rec=~s/\@/\:/g;
2213: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
2214: if ($sections) {
2215: foreach (split(/\;/,$sections)) {
2216: if (($_ eq $ENV{'request.course.sec'}) ||
2217: ($defaultflag && ($_ eq '*'))) {
2218: return $adr;
2219: }
2220: }
2221: } else {
2222: return $rec;
2223: }
2224: return '';
1.35 www 2225: }
2226:
1.6 albertel 2227: sub decide_receiver {
1.36 www 2228: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 2229: my $typestyle='';
2230: my %to=();
1.36 www 2231: if ($ENV{'form.author'}||$author) {
1.8 www 2232: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 2233: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
2234: $to{$2.':'.$1}=1;
2235: }
1.36 www 2236: if ($ENV{'form.question'}||$question) {
1.8 www 2237: $typestyle.='Submitting as Question<br>';
1.24 harris41 2238: foreach (split(/\,/,
2239: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
2240: ) {
1.36 www 2241: my $rec=&secapply($_,$defaultflag);
2242: if ($rec) { $to{$rec}=1; }
1.24 harris41 2243: }
1.6 albertel 2244: }
1.36 www 2245: if ($ENV{'form.course'}||$course) {
1.63 albertel 2246: $typestyle.='Submitting as Comment<br />';
1.24 harris41 2247: foreach (split(/\,/,
2248: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
2249: ) {
1.36 www 2250: my $rec=&secapply($_,$defaultflag);
2251: if ($rec) { $to{$rec}=1; }
1.24 harris41 2252: }
1.6 albertel 2253: }
1.36 www 2254: if ($ENV{'form.policy'}||$policy) {
1.63 albertel 2255: $typestyle.='Submitting as Policy Feedback<br />';
1.24 harris41 2256: foreach (split(/\,/,
2257: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
2258: ) {
1.36 www 2259: my $rec=&secapply($_,$defaultflag);
2260: if ($rec) { $to{$rec}=1; }
1.24 harris41 2261: }
1.6 albertel 2262: }
1.36 www 2263: if ((scalar(%to) eq '0') && (!$defaultflag)) {
2264: ($typestyle,%to)=
2265: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
2266: }
1.6 albertel 2267: return ($typestyle,%to);
1.36 www 2268: }
2269:
2270: sub feedback_available {
2271: my ($question,$course,$policy)=@_;
2272: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
2273: return scalar(%to);
1.6 albertel 2274: }
2275:
2276: sub send_msg {
1.43 www 2277: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 2278: my $status='';
2279: my $sendsomething=0;
1.24 harris41 2280: foreach (keys %to) {
1.6 albertel 2281: if ($_) {
1.22 www 2282: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 2283: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43 www 2284: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
2285: $attachmenturl)=~/ok/) {
1.63 albertel 2286: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 2287: } else {
2288: $sendsomething++;
2289: }
2290: }
1.24 harris41 2291: }
1.18 www 2292:
2293: my %record=&Apache::lonnet::restore('_feedback');
2294: my ($temp)=keys %record;
2295: unless ($temp=~/^error\:/) {
2296: my %newrecord=();
2297: $newrecord{'resource'}=$feedurl;
2298: $newrecord{'subnumber'}=$record{'subnumber'}+1;
2299: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63 albertel 2300: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 2301: }
2302: }
2303:
1.6 albertel 2304: return ($status,$sendsomething);
2305: }
2306:
1.13 www 2307: sub adddiscuss {
1.78 raeburn 2308: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 2309: my $status='';
1.122 raeburn 2310: my $realsymb;
2311: if ($symb=~/^bulletin___/) {
2312: my $filename=(&Apache::lonnet::decode_symb($symb))[2];
2313: $filename=~s|^adm/wrapper/||;
2314: $realsymb=&Apache::lonnet::symbread($filename);
2315: }
2316: if (&discussion_open(undef,$realsymb) &&
1.90 albertel 2317: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1.23 www 2318: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20 www 2319:
1.13 www 2320: my %contrib=('message' => $email,
2321: 'sendername' => $ENV{'user.name'},
1.26 www 2322: 'senderdomain' => $ENV{'user.domain'},
2323: 'screenname' => $ENV{'environment.screenname'},
2324: 'plainname' => $ENV{'environment.firstname'}.' '.
2325: $ENV{'environment.middlename'}.' '.
2326: $ENV{'environment.lastname'}.' '.
1.42 www 2327: $ENV{'enrironment.generation'},
1.78 raeburn 2328: 'attachmenturl'=> $attachmenturl,
2329: 'subject' => $subject);
1.65 www 2330: if ($ENV{'form.replydisc'}) {
1.66 www 2331: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65 www 2332: }
1.14 www 2333: if ($anon) {
2334: $contrib{'anonymous'}='true';
2335: }
1.13 www 2336: if (($symb) && ($email)) {
1.102 raeburn 2337: if ($ENV{'form.editdisc'}) {
2338: my %newcontrib = ();
2339: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
2340: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
2341: $contrib{'timestamp'} = time;
2342: $contrib{'history'} = '';
2343: my $numoldver = 0;
2344: my ($oldsymb,$oldidx)=split(/\:\:\:/,$ENV{'form.editdisc'});
1.110 raeburn 2345: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2346: # get timestamp for last post and history
2347: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
2348: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2349: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2350: if (defined($oldcontrib{$oldidx.':replyto'})) {
2351: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2352: }
2353: if (defined($oldcontrib{$oldidx.':history'})) {
2354: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2355: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2356: $numoldver = @oldversions;
2357: } else {
2358: $numoldver = 1;
2359: }
2360: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2361: }
1.108 raeburn 2362: my $numnewver = $numoldver + 1;
1.102 raeburn 2363: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 raeburn 2364: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
2365: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
2366: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2367: } else {
1.112 raeburn 2368: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2369: }
1.102 raeburn 2370: }
2371: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 raeburn 2372: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
2373: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
2374: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2375: } else {
1.112 raeburn 2376: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2377: }
1.102 raeburn 2378: }
2379: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
2380: foreach (keys %contrib) {
2381: my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;
2382: $newcontrib{$key} = $contrib{$_};
2383: }
2384: my $put_reply = &Apache::lonnet::putstore($ENV{'request.course.id'},
2385: \%newcontrib,
2386: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2387: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2388: $status='Editing class discussion'.($anon?' (anonymous)':'');
2389: } else {
2390: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
2391: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1.13 www 2392: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17 www 2393: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.102 raeburn 2394: }
1.21 www 2395: my %storenewentry=($symb => time);
1.63 albertel 2396: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2397: &Apache::lonnet::put('discussiontimes',\%storenewentry,
2398: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2399: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13 www 2400: }
1.17 www 2401: my %record=&Apache::lonnet::restore('_discussion');
2402: my ($temp)=keys %record;
2403: unless ($temp=~/^error\:/) {
2404: my %newrecord=();
2405: $newrecord{'resource'}=$symb;
2406: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2407: $status.='<br />'.&mt('Registering').': '.
1.21 www 2408: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2409: }
2410: } else {
2411: $status.='Failed.';
1.17 www 2412: }
1.63 albertel 2413: return $status.'<br />';
1.13 www 2414: }
2415:
1.33 www 2416: # ----------------------------------------------------------- Preview function
2417:
2418: sub show_preview {
2419: my $r=shift;
2420: my $message=&clear_out_html($ENV{'form.comment'});
2421: $message=~s/\n/\<br \/\>/g;
1.106 www 2422: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2423: $message=&Apache::lontexconvert::msgtexconverted($message);
1.78 raeburn 2424: my $subject=&clear_out_html($ENV{'form.subject'});
2425: $subject=~s/\n/\<br \/\>/g;
2426: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33 www 2427: $r->print('<table border="2"><tr><td>'.
1.78 raeburn 2428: '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33 www 2429: $message.'</td></tr></table>');
2430: }
2431:
2432: sub generate_preview_button {
1.107 www 2433: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2434: return(<<ENDPREVIEW);
2435: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2436: <input type="hidden" name="subject">
1.33 www 2437: <input type="hidden" name="comment" />
1.65 www 2438: <input type="button" value="$pre"
1.119 albertel 2439: onClick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
1.33 www 2440: </form>
2441: ENDPREVIEW
2442: }
1.71 www 2443:
1.108 raeburn 2444: sub modify_attachments {
2445: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
1.124 raeburn 2446: my $orig_subject = &Apache::lonnet::unescape($ENV{'form.subject'});
2447: my $subject=&clear_out_html($orig_subject);
1.108 raeburn 2448: $subject=~s/\n/\<br \/\>/g;
2449: $subject=&Apache::lontexconvert::msgtexconverted($subject);
2450: my $timestamp=$ENV{'form.timestamp'};
2451: my $numoldver=$ENV{'form.numoldver'};
2452: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
2453: '','');
2454: my $msg = '';
1.113 raeburn 2455: my %attachments = ();
1.108 raeburn 2456: my %currattach = ();
2457: if ($idx) {
1.113 raeburn 2458: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108 raeburn 2459: }
2460: $r->print(<<END);
2461: <html>
2462: <head>
2463: <title>Managing Attachments</title>
2464: <script>
2465: function setAction () {
2466: document.modattachments.action = document.modattachments.origpage.value;
2467: document.modattachments.submit();
2468: }
2469: </script>
2470: </head>
2471: $bodytag
2472: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2473: <table border="2">
2474: <tr>
2475: <td>
1.124 raeburn 2476: <b>Subject:</b> $subject</b><br /><br />
1.108 raeburn 2477: END
2478: if ($idx) {
2479: if ($attachmenturls) {
2480: my @currold = keys %currattach;
2481: if (@currold > 0) {
2482: $r->print("The following attachments were part of the most recent saved version of this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
1.113 raeburn 2483: foreach my $id (@currold) {
2484: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
2485: $attachurl =~ m#/([^/]+)$#;
2486: $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'<br />'."\n");
1.108 raeburn 2487: }
2488: $r->print("<br />");
2489: }
2490: }
2491: }
2492: if (@{$currnewattach} > 0) {
2493: $r->print("The following attachments have been uploaded for inclusion with this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
2494: foreach (@{$currnewattach}) {
2495: $_ =~ m#/([^/]+)$#;
2496: $r->print('<input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'<br />'."\n");
2497: }
2498: $r->print("<br />");
2499: }
2500: $r->print(<<END);
2501: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2502: </td>
2503: </tr>
2504: </table>
2505: <input type="hidden" name="subject" value="$ENV{'form.subject'}" />
2506: <input type="hidden" name="comment" value="$ENV{'form.comment'}" />
2507: <input type="hidden" name="timestamp" value="$ENV{'form.timestamp'}" />
2508: <input type="hidden" name="idx" value="$ENV{'form.idx'}" />
2509: <input type="hidden" name="numoldver" value="$ENV{'form.numoldver'}" />
2510: <input type="hidden" name="origpage" value="$ENV{'form.origpage'}" />
2511: <input type="hidden" name="anondiscuss" value="$ENV{'form.anondiscuss'}" />
2512: <input type="hidden" name="discuss" value="$ENV{'form.discuss'}" />
2513: END
2514: foreach (@{$currnewattach}) {
2515: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2516: }
2517: foreach (@{$currdelold}) {
2518: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2519: }
2520: $r->print(<<END);
2521: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2522: </form>
2523: </body>
2524: </html>
2525: END
2526: return;
2527: }
2528:
2529: sub process_attachments {
2530: my ($currnewattach,$currdelold,$keepold) = @_;
2531: if (exists($ENV{'form.currnewattach'})) {
2532: if (ref($ENV{'form.currnewattach'}) eq 'ARRAY') {
2533: @{$currnewattach} = @{$ENV{'form.currnewattach'}};
2534: } else {
2535: $$currnewattach[0] = $ENV{'form.currnewattach'};
2536: }
2537: }
2538: if (exists($ENV{'form.deloldattach'})) {
2539: if (ref($ENV{'form.deloldattach'}) eq 'ARRAY') {
2540: @{$currdelold} = @{$ENV{'form.deloldattach'}};
2541: } else {
2542: $$currdelold[0] = $ENV{'form.deloldattach'};
2543: }
2544: }
2545: if (exists($ENV{'form.delnewattach'})) {
2546: my @currdelnew = ();
2547: my @currnew = ();
2548: if (ref($ENV{'form.delnewattach'}) eq 'ARRAY') {
2549: @currdelnew = @{$ENV{'form.delnewattach'}};
2550: } else {
2551: $currdelnew[0] = $ENV{'form.delnewattach'};
2552: }
2553: foreach my $newone (@{$currnewattach}) {
2554: my $delflag = 0;
2555: foreach (@currdelnew) {
2556: if ($newone eq $_) {
2557: $delflag = 1;
2558: last;
2559: }
2560: }
2561: unless ($delflag) {
2562: push @currnew, $newone;
2563: }
2564: }
2565: @{$currnewattach} = @currnew;
2566: }
2567: if (exists($ENV{'form.keepold'})) {
2568: if (ref($ENV{'form.keepold'}) eq 'ARRAY') {
2569: @{$keepold} = @{$ENV{'form.keepold'}};
2570: } else {
2571: $$keepold[0] = $ENV{'form.keepold'};
2572: }
2573: }
2574: }
2575:
2576: sub generate_attachments_button {
2577: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2578: my $origpage = $ENV{'REQUEST_URI'};
2579: my $att=$attachnum.' '.&mt("attachments");
2580: my $response = (<<END);
2581: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2582: Click to add/remove attachments: <input type="button" value="$att"
1.124 raeburn 2583: 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);
1.108 raeburn 2584: END
2585: unless ($mode eq 'board') {
2586: $response .= 'javascript:anonchk();';
2587: }
2588: $response .= (<<ENDATTACH);
2589: this.form.submit();" />
2590: <input type="hidden" name="origpage" value="$origpage" />
2591: <input type="hidden" name="idx" value="$idx" />
2592: <input type="hidden" name="timestamp" value="$now" />
2593: <input type="hidden" name="subject" />
2594: <input type="hidden" name="comment" />
2595: <input type="hidden" name="anondiscuss" value = "0";
2596: <input type="hidden" name="discuss" value = "0";
2597: <input type="hidden" name="numoldver" value="$numoldver" />
2598: ENDATTACH
2599: if (defined($deloldattach)) {
2600: if (@{$deloldattach} > 0) {
2601: foreach (@{$deloldattach}) {
2602: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
2603: }
2604: }
2605: }
2606: if (defined($currnewattach)) {
2607: if (@{$currnewattach} > 0) {
2608: foreach (@{$currnewattach}) {
2609: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
2610: }
2611: }
2612: }
2613: $response .= '</form>';
2614: return $response;
2615: }
2616:
2617: sub extract_attachments {
2618: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.116 raeburn 2619: %{$attachments}=();
2620: &get_post_attachments($attachments,$attachmenturls);
2621: foreach my $id (sort keys %{$attachments}) {
2622: if (exists($$attachments{$id}{$numoldver})) {
2623: if (defined($currdelold)) {
2624: if (@{$currdelold} > 0) {
2625: unless (grep/^$id$/,@{$currdelold}) {
2626: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2627: }
1.113 raeburn 2628: } else {
2629: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2630: }
1.116 raeburn 2631: } else {
2632: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2633: }
2634: }
1.116 raeburn 2635: }
2636: my @attached = (sort { $a <=> $b } keys %{$currattach});
2637: if (@attached == 1) {
2638: my $id = $attached[0];
2639: my $attachurl;
2640: if ($attachmenturls =~ m/^<attachment id="0">/) {
2641: $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
2642: } else {
2643: $attachurl = $$attachments{$id}{'filename'};
2644: }
2645: $attachurl=~m|/([^/]+)$|;
2646: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
2647: $1.'</tt></a><br />';
2648: &Apache::lonnet::allowuploaded('/adm/feedback',
2649: $attachurl);
2650: } elsif (@attached > 1) {
2651: $$message.='<ol>';
2652: foreach (@attached) {
2653: my $id = $_;
1.113 raeburn 2654: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.116 raeburn 2655: my ($fname)
2656: =($attachurl=~m|/([^/]+)$|);
2657: $$message .= '<li><a href="'.$attachurl.
2658: '"><tt>'.
2659: $fname.'</tt></a></li>';
1.108 raeburn 2660: &Apache::lonnet::allowuploaded('/adm/feedback',
1.116 raeburn 2661: $attachurl);
1.108 raeburn 2662: }
1.116 raeburn 2663: $$message .= '</ol>';
1.108 raeburn 2664: }
2665: }
2666:
2667: sub construct_attachmenturl {
2668: my ($currnewattach,$keepold,$symb,$idx)=@_;
2669: my $oldattachmenturl;
2670: my $newattachmenturl;
1.113 raeburn 2671: my $startnum = 0;
1.108 raeburn 2672: my $currver = 0;
2673: if (($ENV{'form.editdisc'}) && ($idx)) {
2674: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2675: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2676: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2677: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
2678: if ($contrib{$idx.':history'}) {
2679: if ($contrib{$idx.':history'} =~ /:/) {
2680: my @oldversions = split/:/,$contrib{$idx.':history'};
2681: $currver = 1 + scalar(@oldversions);
2682: } else {
2683: $currver = 2;
2684: }
2685: } else {
2686: $currver = 1;
2687: }
2688: if ($oldattachmenturl) {
1.113 raeburn 2689: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
2690: my %attachments = ();
2691: my $prevver = $currver-1;
2692: &get_post_attachments(\%attachments,$oldattachmenturl);
1.116 raeburn 2693: my $numattach = scalar(keys %attachments);
1.113 raeburn 2694: $startnum += $numattach;
2695: foreach my $num (sort {$a <=> $b} keys %attachments) {
2696: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
1.116 raeburn 2697: foreach $_ (sort {$a <=> $b} keys %{$attachments{$num}}) {
2698: unless ($_ eq 'filename') {
2699: $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
2700: }
1.113 raeburn 2701: }
2702: if (grep/^$num$/,@{$keepold}) {
2703: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108 raeburn 2704: }
1.113 raeburn 2705: $newattachmenturl .= '</attachment>';
1.108 raeburn 2706: }
2707: } else {
1.116 raeburn 2708: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
1.108 raeburn 2709: unless (grep/^0$/,@{$keepold}) {
1.113 raeburn 2710: $newattachmenturl .= '<post id="1">n</post>';
1.108 raeburn 2711: }
1.113 raeburn 2712: $newattachmenturl .= '</attachment>';
1.108 raeburn 2713: $startnum ++;
2714: }
2715: }
2716: }
2717: for (my $i=0; $i<@{$currnewattach}; $i++) {
2718: my $attachnum = $startnum + $i;
1.113 raeburn 2719: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108 raeburn 2720: }
2721: return $newattachmenturl;
2722: }
1.128 raeburn 2723:
2724: sub has_discussion {
2725: my $resourcesref = shift;
2726: my $navmap = Apache::lonnavmaps::navmap->new();
2727: my @allres=$navmap->retrieveResources();
2728: foreach my $resource (@allres) {
2729: if ($resource->hasDiscussion()) {
2730: my $ressymb;
2731: if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
2732: $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
2733: } else {
2734: $ressymb = $resource->symb();
2735: }
2736: push @{$resourcesref}, $ressymb;
2737: }
2738: }
2739: return;
2740: }
1.108 raeburn 2741:
1.6 albertel 2742: sub handler {
2743: my $r = shift;
1.8 www 2744: if ($r->header_only) {
1.71 www 2745: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2746: $r->send_http_header;
2747: return OK;
2748: }
1.15 www 2749:
2750: # --------------------------- Get query string for limited number of parameters
2751:
1.97 raeburn 2752: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.128 raeburn 2753: ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','threadedon','threadedoff','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export']);
1.111 raeburn 2754: if ($ENV{'form.discsymb'}) {
2755: my $symb = $ENV{'form.discsymb'};
2756: my $readkey = $symb.'_read';
2757: my %readinghash = ();
2758: my $chgcount = 0;
2759: %readinghash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$readkey],$ENV{'user.domain'},$ENV{'user.name'});
2760: foreach my $key (keys %ENV) {
2761: if ($key =~ m/^form\.postunread_(\d+)/) {
2762: if ($readinghash{$readkey} =~ /\.$1\./) {
2763: $readinghash{$readkey} =~ s/\.$1\.//;
2764: $chgcount ++;
2765: }
2766: } elsif ($key =~ m/^form\.postread_(\d+)/) {
2767: unless ($readinghash{$readkey} =~ /\.$1\./) {
2768: $readinghash{$readkey} .= '.'.$1.'.';
2769: $chgcount ++;
2770: }
2771: }
2772: }
2773: if ($chgcount > 0) {
2774: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'});
2775: }
2776: &Apache::loncommon::content_type($r,'text/html');
2777: $r->send_http_header;
2778: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2779: my $previous=$ENV{'form.previous'};
2780: my $feedurl = &Apache::lonnet::clutter($url);
2781: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />','0','0','',$previous,'','','',);
2782: return OK;
2783: }
1.109 raeburn 2784: if ($ENV{'form.allversions'}) {
2785: &Apache::loncommon::content_type($r,'text/html');
2786: $r->send_http_header;
2787: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions',
2788: '','');
2789: $r->print (<<END);
2790: <html>
2791: <head>
2792: <title>Post Versions</title>
2793: <meta http-equiv="pragma" content="no-cache" />
2794: </head>
2795: $bodytag
2796: END
2797: my $crs='/'.$ENV{'request.course.id'};
2798: if ($ENV{'request.course.sec'}) {
2799: $crs.='_'.$ENV{'request.course.sec'};
2800: }
2801: $crs=~s/\_/\//g;
2802: my $seeid=&Apache::lonnet::allowed('rin',$crs);
2803: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.allversions'});
2804: my $ressymb=$symb;
2805: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2806: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2807: }
2808: if ($idx > 0) {
1.116 raeburn 2809: my %messages = ();
2810: my %subjects = ();
2811: my %attachmsgs = ();
2812: my %allattachments = ();
2813: my %imsfiles = ();
2814: my ($screenname,$plainname);
1.109 raeburn 2815: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
2816: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2817: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.116 raeburn 2818: my $discussion = &get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname);
2819: $r->print($discussion);
1.109 raeburn 2820: }
2821: return OK;
2822: }
1.101 raeburn 2823: if ($ENV{'form.posterlist'}) {
2824: &Apache::loncommon::content_type($r,'text/html');
2825: $r->send_http_header;
2826: my $symb=$ENV{'form.posterlist'};
2827: my $sortposts = $ENV{'form.sortposts'};
2828: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2829: my $previous=$ENV{'form.previous'};
2830: my $feedurl = &Apache::lonnet::clutter($url);
2831: # backward compatibility (bulletin boards used to be 'wrapped')
2832: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2833: $feedurl=~s|^/adm/wrapper||;
2834: }
2835: &print_showposters($r,$symb,$previous,$feedurl,$sortposts);
2836: return OK;
2837: }
2838: if ($ENV{'form.userpick'}) {
2839: &Apache::loncommon::content_type($r,'text/html');
2840: $r->send_http_header;
2841: my $symb=$ENV{'form.userpick'};
2842: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2843: my $previous=$ENV{'form.previous'};
2844: # backward compatibility (bulletin boards used to be 'wrapped')
2845: my $ressymb=$symb;
2846: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2847: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2848: }
2849: my $sort=$ENV{'form.sortposts'};
2850: my @posters = ();
2851: if (ref($ENV{'form.stuinfo'}) eq 'ARRAY') {
2852: @posters = $ENV{'form.stuinfo'};
2853: } else {
2854: $posters[0] = $ENV{'form.stuinfo'};
2855: }
2856: my $numpicks = @posters;
2857: if (defined($ENV{'form.userpick'})) {
2858: my %discinfo = ();
2859: $discinfo{$ressymb.'_userpick'} = join('&',@posters);
2860: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2861: }
2862: my $feedurl = &Apache::lonnet::clutter($url);
2863: # backward compatibility (bulletin boards used to be 'wrapped')
2864: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2865: $feedurl=~s|^/adm/wrapper||;
2866: }
2867: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,'','','',$numpicks);
2868: return OK;
2869: }
1.100 raeburn 2870: if ($ENV{'form.applysort'}) {
2871: &Apache::loncommon::content_type($r,'text/html');
2872: $r->send_http_header;
2873: my $symb=$ENV{'form.applysort'};
2874: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2875: my $previous=$ENV{'form.previous'};
2876: my $sort = $ENV{'form.sortposts'};
1.101 raeburn 2877: my $rolefilter = $ENV{'form.rolefilter'};
1.100 raeburn 2878: my $statusfilter = $ENV{'form.statusfilter'};
2879: my $secpick = $ENV{'form.sectionpick'};
2880: my $feedurl = &Apache::lonnet::clutter($url);
2881: # backward compatibility (bulletin boards used to be 'wrapped')
2882: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2883: $feedurl=~s|^/adm/wrapper||;
2884: }
1.101 raeburn 2885: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,$rolefilter,$statusfilter,$secpick);
1.100 raeburn 2886: return OK;
2887: } elsif ($ENV{'form.sortfilter'}) {
2888: &Apache::loncommon::content_type($r,'text/html');
2889: $r->send_http_header;
2890: my $symb=$ENV{'form.sortfilter'};
2891: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2892: my $previous=$ENV{'form.previous'};
2893: my $feedurl = &Apache::lonnet::clutter($url);
2894: # backward compatibility (bulletin boards used to be 'wrapped')
2895: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2896: $feedurl=~s|^/adm/wrapper||;
2897: }
2898: &print_sortfilter_options($r,$symb,$previous,$feedurl);
2899: return OK;
1.128 raeburn 2900: } elsif ($ENV{'form.navtime'}) {
1.99 raeburn 2901: my %discinfo = ();
2902: my @resources = ();
1.128 raeburn 2903: if (defined($ENV{'form.navmaps'})) {
2904: if ($ENV{'form.navmaps'} =~ /:/) {
2905: @resources = split/:/,$ENV{'form.navmaps'};
2906: } else {
2907: @resources = ("$ENV{'form.navmaps'}");
2908: }
1.99 raeburn 2909: } else {
1.128 raeburn 2910: &has_discussion(\@resources);
1.99 raeburn 2911: }
2912: my $numitems = @resources;
2913: my $feedurl = '/adm/navmaps';
2914: if ($ENV{'form.navurl'}) {
2915: $feedurl .= '?'.$ENV{'form.navurl'};
2916: }
2917: my %lt = &Apache::lonlocal::texthash(
2918: 'mnpa' => 'Marked "New" posts as read in a total of',
1.128 raeburn 2919: 'robb' => 'resources/bulletin boards.',
2920: 'twnp' => 'There are currently no resources or bulletin boards with unread discussion postings.'
1.99 raeburn 2921: );
2922: foreach (@resources) {
2923: # backward compatibility (bulletin boards used to be 'wrapped')
2924: my $ressymb=$_;
2925: if ($ressymb =~ m/bulletin___\d+___/) {
2926: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2927: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
2928: }
2929: }
2930: my $lastkey = $ressymb.'_lastread';
1.127 albertel 2931: $discinfo{$lastkey} = $ENV{'form.navtime'};
1.99 raeburn 2932: }
1.128 raeburn 2933: my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
2934: if ($numitems > 0) {
2935: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2936: } else {
2937: $textline = "<b>$lt{'twnp'}</b>";
2938: }
1.99 raeburn 2939: &Apache::loncommon::content_type($r,'text/html');
2940: $r->send_http_header;
2941: $r->print (<<ENDREDIR);
2942: <html>
2943: <head>
2944: <title>New posts marked as read</title>
2945: <meta http-equiv="pragma" content="no-cache" />
2946: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
2947: </head>
2948: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
2949: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.128 raeburn 2950: $textline
1.99 raeburn 2951: <form name="reldt" action="$feedurl" target="loncapaclient">
2952: </form>
1.121 albertel 2953: <br /><a href="$feedurl">Continue</a>
1.99 raeburn 2954: </body>
2955: </html>
2956: ENDREDIR
2957: return OK;
2958: } elsif ($ENV{'form.modifydisp'}) {
1.84 raeburn 2959: &Apache::loncommon::content_type($r,'text/html');
2960: $r->send_http_header;
1.97 raeburn 2961: my $symb=$ENV{'form.modifydisp'};
1.84 raeburn 2962: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.97 raeburn 2963: my $previous=$ENV{'form.previous'};
1.111 raeburn 2964: my ($dispchgA,$dispchgB,$markchg,$toggchg) = split/_/,$ENV{'form.changes'};
1.97 raeburn 2965: my $feedurl = &Apache::lonnet::clutter($url);
1.98 raeburn 2966: # backward compatibility (bulletin boards used to be 'wrapped')
2967: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2968: $feedurl=~s|^/adm/wrapper||;
2969: }
1.111 raeburn 2970: &print_display_options($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 2971: return OK;
1.111 raeburn 2972: } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || $ENV{'form.onlyunmark'} || $ENV{'form.toggoff'} || $ENV{'form.toggon'} ) {
1.97 raeburn 2973: &Apache::loncommon::content_type($r,'text/html');
2974: $r->send_http_header;
2975: my $previous=$ENV{'form.previous'};
2976: my ($map,$ind,$url);
1.111 raeburn 2977: if ( ($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
2978: # ------------------------------ Modify setting for read/unread toggle for each post
2979: my $symb=$ENV{'form.toggoff'}?$ENV{'form.toggoff'}:$ENV{'form.toggon'};
2980: my $ressymb = $symb;
2981: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2982: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2983: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2984: }
2985: my %discinfo = ();
2986: my $toggkey = $ressymb.'_readtoggle';
2987: if ($ENV{'form.toggon'}) {
2988: $discinfo{$toggkey} = 1;
2989: } elsif ($ENV{'form.toggoff'}) {
2990: $discinfo{$toggkey} = 0;
2991: }
2992: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2993: }
1.97 raeburn 2994: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
2995: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
2996: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
2997: my $ressymb = $symb;
2998: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2999: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3000: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3001: }
3002: my %discinfo = ();
3003: my $lastkey = $ressymb.'_lastread';
3004: my $ondispkey = $ressymb.'_markondisp';
3005: if ($ENV{'form.markondisp'}) {
3006: $discinfo{$lastkey} = time;
3007: $discinfo{$ondispkey} = 1;
3008: } elsif ($ENV{'form.markonread'}) {
3009: if ( $previous > 0 ) {
3010: $discinfo{$lastkey} = $previous;
3011: }
3012: $discinfo{$ondispkey} = 0;
3013: }
3014: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 3015: }
1.111 raeburn 3016: if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ) {
1.97 raeburn 3017: # ----------------------------------------------------------------- Modify display setting for this discussion
1.111 raeburn 3018: my $symb;
3019: if ($ENV{'form.allposts'}) {
3020: $symb = $ENV{'form.allposts'};
3021: } elsif ($ENV{'form.onlyunread'}) {
3022: $symb = $ENV{'form.onlyunread'};
3023: } else {
3024: $symb = $ENV{'form.onlyunmark'};
3025: }
1.97 raeburn 3026: my $ressymb = $symb;
3027: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3028: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3029: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3030: }
3031: my %discinfo = ();
3032: if ($ENV{'form.allposts'}) {
3033: $discinfo{$ressymb.'_showonlyunread'} = 0;
1.111 raeburn 3034: $discinfo{$ressymb.'_showonlyunmark'} = 0;
1.97 raeburn 3035: } elsif ($ENV{'form.onlyunread'}) {
3036: $discinfo{$ressymb.'_showonlyunread'} = 1;
1.111 raeburn 3037: } else {
3038: $discinfo{$ressymb.'_showonlyunmark'} = 1;
1.84 raeburn 3039: }
1.97 raeburn 3040: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 3041: }
1.111 raeburn 3042: if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ||($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
1.97 raeburn 3043: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
3044: } else {
1.84 raeburn 3045: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
3046: }
3047: return OK;
3048: } elsif ($ENV{'form.markread'}) {
1.111 raeburn 3049: # ----------------------------------------------------------------- Mark new posts not NEW
1.84 raeburn 3050: &Apache::loncommon::content_type($r,'text/html');
3051: $r->send_http_header;
3052: my $symb=$ENV{'form.markread'};
3053: my $ressymb = $symb;
3054: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3055: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3056: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1.78 raeburn 3057: }
1.84 raeburn 3058: my %discinfo = ();
3059: my $lastkey = $ressymb.'_lastread';
3060: $discinfo{$lastkey} = time;
3061: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
3062: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1.78 raeburn 3063: return OK;
3064: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15 www 3065: # ----------------------------------------------------------------- Hide/unhide
1.71 www 3066: &Apache::loncommon::content_type($r,'text/html');
1.15 www 3067: $r->send_http_header;
3068:
3069: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
3070:
3071: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 3072: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15 www 3073:
3074: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3075: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3076: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3077:
3078:
3079: my $currenthidden=$contrib{'hidden'};
1.102 raeburn 3080: my $currentstudenthidden=$contrib{'studenthidden'};
3081:
3082: my $crs='/'.$ENV{'request.course.id'};
3083: if ($ENV{'request.course.sec'}) {
3084: $crs.='_'.$ENV{'request.course.sec'};
3085: }
3086: $crs=~s/\_/\//g;
3087: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.15 www 3088:
3089: if ($ENV{'form.hide'}) {
3090: $currenthidden.='.'.$idx.'.';
1.102 raeburn 3091: unless ($seeid) {
3092: $currentstudenthidden.='.'.$idx.'.';
3093: }
1.15 www 3094: } else {
3095: $currenthidden=~s/\.$idx\.//g;
3096: }
3097: my %newhash=('hidden' => $currenthidden);
1.102 raeburn 3098: if ( ($ENV{'form.hide'}) && (!$seeid) ) {
3099: $newhash{'studenthidden'} = $currentstudenthidden;
3100: }
1.38 www 3101:
3102: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
3103: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3104: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3105:
3106: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3107: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69 www 3108: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72 albertel 3109: &Apache::loncommon::content_type($r,'text/html');
3110: $r->send_http_header;
1.69 www 3111: if ($ENV{'form.threadedon'}) {
3112: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
3113: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
3114: } else {
3115: &Apache::lonnet::del('environment',['threadeddiscussion']);
3116: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 3117: }
1.69 www 3118: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
3119: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3120: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3121: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38 www 3122: } elsif ($ENV{'form.deldisc'}) {
3123: # --------------------------------------------------------------- Hide for good
1.71 www 3124: &Apache::loncommon::content_type($r,'text/html');
1.38 www 3125: $r->send_http_header;
3126:
3127: my $entry=$ENV{'form.deldisc'};
3128:
3129: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 3130: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38 www 3131:
3132: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3133: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3134: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3135:
3136:
3137: my $currentdeleted=$contrib{'deleted'};
3138:
3139: $currentdeleted.='.'.$idx.'.';
3140:
3141: my %newhash=('deleted' => $currentdeleted);
1.15 www 3142:
3143: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
3144: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3145: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3146:
1.30 www 3147: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3148: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33 www 3149: } elsif ($ENV{'form.preview'}) {
3150: # -------------------------------------------------------- User wants a preview
1.76 albertel 3151: $r->content_type('text/html');
3152: $r->send_http_header;
1.33 www 3153: &show_preview($r);
1.108 raeburn 3154: } elsif ($ENV{'form.attach'}) {
3155: # -------------------------------------------------------- Work on attachments
3156: &Apache::loncommon::content_type($r,'text/html');
3157: $r->send_http_header;
3158: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
3159: my @currnewattach = ();
3160: my @currdelold = ();
3161: my @keepold = ();
3162: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
3163: if (exists($ENV{'form.addnewattach.filename'})) {
3164: unless (length($ENV{'form.addnewattach'})>131072) {
3165: my $subdir = 'feedback/'.$ENV{'form.timestamp'};
3166: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
3167: push @currnewattach, $newattachment;
3168: }
3169: }
3170: my $attachmenturls = '';
3171: my $idx = $ENV{'form.idx'};
3172: my $symb = $ENV{'form.attach'};
3173: if ($idx) {
3174: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3175: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3176: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3177: $attachmenturls = $contrib{$idx.':attachmenturl'};
3178: }
3179: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,$attachmenturls);
1.111 raeburn 3180: } elsif ($ENV{'form.chgreads'}) {
3181: &Apache::loncommon::content_type($r,'text/html');
3182: $r->send_http_header;
3183: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ENV{'form.chgreads'});
3184: &redirect_back($r,&Apache::lonnet::clutter($url),
3185: &mt('Changed read status').'<br />','0','0');
1.116 raeburn 3186: } elsif ($ENV{'form.export'}) {
3187: &Apache::loncommon::content_type($r,'text/html');
3188: $r->send_http_header;
3189: my $symb=$ENV{'form.export'};
3190: my $mode;
3191: my $status='OPEN';
3192: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3193: my $previous=$ENV{'form.previous'};
3194: my $feedurl = &Apache::lonnet::clutter($url);
3195: # backward compatibility (bulletin boards used to be 'wrapped')
3196: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3197: $mode = 'board';
3198: $feedurl=~s|^/adm/wrapper||;
3199: }
3200: if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library)$/) {
3201: $mode='problem';
3202: $status=$Apache::inputtags::status[-1];
3203: }
3204: my $discussion = &list_discussion($mode,$status,$symb);
3205: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion');
3206: $r->print($bodytag.$discussion);
3207: return OK;
1.15 www 3208: } else {
3209: # ------------------------------------------------------------- Normal feedback
1.6 albertel 3210: my $feedurl=$ENV{'form.postdata'};
3211: $feedurl=~s/^http\:\/\///;
3212: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
3213: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62 www 3214: $feedurl=~s/\?.+$//;
1.8 www 3215:
1.66 www 3216: my $symb;
3217: if ($ENV{'form.replydisc'}) {
3218: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
3219: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3220: $feedurl=&Apache::lonnet::clutter($url);
1.102 raeburn 3221: } elsif ($ENV{'form.editdisc'}) {
3222: $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
3223: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3224: $feedurl=&Apache::lonnet::clutter($url);
1.108 raeburn 3225: } elsif ($ENV{'form.origpage'}) {
3226: $symb="";
1.66 www 3227: } else {
3228: $symb=&Apache::lonnet::symbread($feedurl);
3229: }
1.31 www 3230: unless ($symb) {
3231: $symb=$ENV{'form.symb'};
3232: if ($symb) {
1.52 www 3233: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31 www 3234: $feedurl=&Apache::lonnet::clutter($url);
3235: }
3236: }
1.8 www 3237: my $goahead=1;
3238: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
3239: unless ($symb) { $goahead=0; }
3240: }
1.98 raeburn 3241: # backward compatibility (bulletin boards used to be 'wrapped')
1.73 albertel 3242: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3243: $feedurl=~s|^/adm/wrapper||;
3244: }
1.8 www 3245: if ($goahead) {
3246: # Go ahead with feedback, no ambiguous reference
1.71 www 3247: &Apache::loncommon::content_type($r,'text/html');
1.8 www 3248: $r->send_http_header;
1.6 albertel 3249:
1.8 www 3250: if (
1.7 albertel 3251: (
3252: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
3253: )
3254: ||
3255: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31 www 3256: ||
3257: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7 albertel 3258: ) {
1.6 albertel 3259: # --------------------------------------------------- Print login screen header
3260: unless ($ENV{'form.sendit'}) {
3261: my $options=&screen_header($feedurl);
3262: if ($options) {
1.108 raeburn 3263: &mail_screen($r,$feedurl,$options);
1.6 albertel 3264: } else {
3265: &fail_redirect($r,$feedurl);
3266: }
3267: } else {
3268:
3269: # Get previous user input
1.9 albertel 3270: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 3271: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 3272: $ENV{'request.course.id'});
1.6 albertel 3273:
3274: # Get output from resource
3275: my $usersaw=&resource_output($feedurl);
3276:
1.50 albertel 3277: # Get resource answer (need to allow student to view grades for this to work)
3278: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 3279: my $useranswer=&Apache::loncommon::get_student_answers(
3280: $symb,$ENV{'user.name'},$ENV{'user.domain'},
3281: $ENV{'request.course.id'});
1.50 albertel 3282: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 3283: # Get attachments, if any, and not too large
3284: my $attachmenturl='';
1.108 raeburn 3285: if (($ENV{'form.origpage'}) || ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'})) {
3286: my ($symb,$idx);
3287: if ($ENV{'form.replydisc'}) {
3288: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
3289: } elsif ($ENV{'form.editdisc'}) {
3290: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
3291: } elsif ($ENV{'form.origpage'}) {
3292: $symb = $ENV{'form.symb'};
3293: }
3294: my @currnewattach = ();
3295: my @deloldattach = ();
3296: my @keepold = ();
3297: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
1.110 raeburn 3298: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.108 raeburn 3299: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
3300: } elsif ($ENV{'form.attachment.filename'}) {
1.42 www 3301: unless (length($ENV{'form.attachment'})>131072) {
1.82 albertel 3302: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3303: }
3304: }
1.6 albertel 3305: # Filter HTML out of message (could be nasty)
1.39 www 3306: my $message=&clear_out_html($ENV{'form.comment'});
1.6 albertel 3307:
3308: # Assemble email
1.8 www 3309: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40 albertel 3310: $usersaw,$useranswer);
3311:
1.6 albertel 3312: # Who gets this?
3313: my ($typestyle,%to) = &decide_receiver($feedurl);
3314:
3315: # Actually send mail
1.43 www 3316: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
3317: $attachmenturl,%to);
1.13 www 3318:
3319: # Discussion? Store that.
3320:
1.32 albertel 3321: my $numpost=0;
1.13 www 3322: if ($ENV{'form.discuss'}) {
1.78 raeburn 3323: my $subject = &clear_out_html($ENV{'form.subject'});
3324: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32 albertel 3325: $numpost++;
1.13 www 3326: }
1.6 albertel 3327:
1.14 www 3328: if ($ENV{'form.anondiscuss'}) {
1.78 raeburn 3329: my $subject = &clear_out_html($ENV{'form.subject'});
3330: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32 albertel 3331: $numpost++;
1.14 www 3332: }
3333:
3334:
1.6 albertel 3335: # Receipt screen and redirect back to where came from
1.80 raeburn 3336: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6 albertel 3337:
3338: }
1.8 www 3339: } else {
1.7 albertel 3340: # Unable to give feedback
1.6 albertel 3341: &no_redirect_back($r,$feedurl);
1.8 www 3342: }
3343: } else {
3344: # Ambiguous Problem Resource
1.60 albertel 3345: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53 albertel 3346: &Apache::lonnet::cleanenv();
1.58 albertel 3347: }
1.53 albertel 3348: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 3349: }
1.15 www 3350: }
1.6 albertel 3351: return OK;
1.1 www 3352: }
3353:
3354: 1;
3355: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>