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