Annotation of loncom/interface/lonfeedback.pm, revision 1.117
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.117 ! albertel 4: # $Id: lonfeedback.pm,v 1.116 2004/08/17 14:27:19 raeburn 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.105 www 1358: if (typeof(document.mailform.onsubmit)!='undefined') {
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.5 www 2031: </body>
2032: </html>
2033: ENDFAILREDIR
2034: }
1.4 www 2035:
1.6 albertel 2036: sub redirect_back {
1.101 raeburn 2037: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$secpick,$numpicks) = @_;
1.100 raeburn 2038: my $sorttag = '';
1.101 raeburn 2039: my $roletag = '';
2040: my $statustag = '';
2041: my $sectag = '';
2042: my $userpicktag = '';
2043: my $qrystr = '';
1.80 raeburn 2044: my $prevtag = '';
1.98 raeburn 2045: # backward compatibility (bulletin boards used to be 'wrapped')
2046: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2047: $feedurl=~s|^/adm/wrapper||;
2048: }
1.70 www 2049: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 2050: if ($previous > 0) {
2051: $qrystr = 'previous='.$previous;
2052: if ($feedurl =~ /\?register=1/) {
2053: $feedurl .= '&'.$qrystr;
2054: } else {
2055: $feedurl .= '?'.$qrystr;
2056: }
2057: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
2058: }
1.100 raeburn 2059: if (defined($sort)) {
2060: my $sortqry = 'sortposts='.$sort;
2061: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
2062: $feedurl .= '&'.$sortqry;
2063: } else {
2064: $feedurl .= '?'.$sortqry;
2065: }
2066: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.101 raeburn 2067: if ( (defined($numpicks)) && ($numpicks > 0) ) {
2068: my $userpickqry = 'totposters='.$numpicks;
2069: $feedurl .= '&'.$userpickqry;
2070: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
2071: } else {
2072: my $roleqry = 'rolefilter='.$rolefilter;
2073: $feedurl .= '&'.$roleqry;
2074: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
2075: $feedurl .= '&statusfilter='.$statusfilter;
2076: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
2077: $feedurl .= '§ionpick='.$secpick;
2078: $sectag = '<input type="hidden" name="sectionpick" value="'.$secpick.'" />';
2079: }
1.100 raeburn 2080: }
1.6 albertel 2081: $r->print (<<ENDREDIR);
1.72 albertel 2082: <html>
1.3 www 2083: <head>
2084: <title>Feedback sent</title>
1.63 albertel 2085: <meta http-equiv="pragma" content="no-cache" />
1.80 raeburn 2086: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2 www 2087: </head>
1.49 www 2088: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63 albertel 2089: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5 www 2090: $typestyle
1.32 albertel 2091: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63 albertel 2092: <font color="red">$status</font>
1.49 www 2093: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 2094: $prevtag
1.100 raeburn 2095: $sorttag
1.101 raeburn 2096: $statustag
2097: $roletag
2098: $sectag
2099: $userpicktag
1.49 www 2100: </form>
1.2 www 2101: </body>
2102: </html>
2103: ENDREDIR
2104: }
1.6 albertel 2105:
2106: sub no_redirect_back {
2107: my ($r,$feedurl) = @_;
1.107 www 2108: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.6 albertel 2109: $r->print (<<ENDNOREDIR);
1.72 albertel 2110: <html>
1.2 www 2111: <head><title>Feedback not sent</title>
1.63 albertel 2112: <meta http-equiv="pragma" content="no-cache" />
1.7 albertel 2113: ENDNOREDIR
2114:
1.8 www 2115: if ($feedurl!~/^\/adm\/feedback/) {
1.7 albertel 2116: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
2117: }
2118:
1.8 www 2119: $r->print (<<ENDNOREDIRTWO);
1.2 www 2120: </head>
1.49 www 2121: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63 albertel 2122: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.107 www 2123: <b>$nofeed</b>
1.2 www 2124: </body>
2125: </html>
1.8 www 2126: ENDNOREDIRTWO
1.2 www 2127: }
1.6 albertel 2128:
2129: sub screen_header {
1.65 www 2130: my ($feedurl) = @_;
2131: my $msgoptions='';
2132: my $discussoptions='';
1.102 raeburn 2133: unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
1.65 www 2134: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
2135: $msgoptions=
2136: '<p><input type="checkbox" name="author" /> '.
2137: &mt('Feedback to resource author').'</p>';
2138: }
2139: if (&feedback_available(1)) {
2140: $msgoptions.=
2141: '<br /><input type="checkbox" name="question" /> '.
2142: &mt('Question about resource content');
2143: }
2144: if (&feedback_available(0,1)) {
2145: $msgoptions.=
2146: '<br /><input type="checkbox" name="course" /> '.
2147: &mt('Question/Comment/Feedback about course content');
2148: }
2149: if (&feedback_available(0,0,1)) {
2150: $msgoptions.=
2151: '<br /><input type="checkbox" name="policy" /> '.
2152: &mt('Question/Comment/Feedback about course policy');
2153: }
2154: }
2155: if ($ENV{'request.course.id'}) {
1.92 albertel 2156: if (&discussion_open() &&
1.90 albertel 2157: &Apache::lonnet::allowed('pch',
1.65 www 2158: $ENV{'request.course.id'}.
2159: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74 www 2160: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
2161: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65 www 2162: &mt('Contribution to course discussion of resource');
2163: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
2164: &mt('Anonymous contribution to course discussion of resource').
2165: ' <i>('.&mt('name only visible to course faculty').')</i>';
1.20 www 2166: }
1.65 www 2167: }
1.74 www 2168: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 2169: if ($discussoptions) {
1.74 www 2170: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 2171: return $msgoptions.$discussoptions;
1.6 albertel 2172: }
2173:
2174: sub resource_output {
2175: my ($feedurl) = @_;
1.46 albertel 2176: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 2177: $usersaw=~s/\<body[^\>]*\>//gi;
2178: $usersaw=~s/\<\/body\>//gi;
2179: $usersaw=~s/\<html\>//gi;
2180: $usersaw=~s/\<\/html\>//gi;
2181: $usersaw=~s/\<head\>//gi;
2182: $usersaw=~s/\<\/head\>//gi;
2183: $usersaw=~s/action\s*\=/would_be_action\=/gi;
2184: return $usersaw;
2185: }
2186:
2187: sub clear_out_html {
1.39 www 2188: my ($message,$override)=@_;
1.88 www 2189: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107 www 2190: # Always allow the <m>-tag
2191: my %html=(M=>1);
2192: # Check if more is allowed
1.37 albertel 2193: my $cid=$ENV{'request.course.id'};
1.39 www 2194: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
2195: ($override)) {
1.37 albertel 2196: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 2197: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
2198: # <SUP>
1.107 www 2199: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
2200: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
2201: M=>1, SUB=>1, SUP=>1, SPAN=>1,
2202: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
2203: }
2204: # Do the substitution of everything that is not explicitly allowed
2205: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48 albertel 2206: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.107 www 2207: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48 albertel 2208: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.6 albertel 2209: return $message;
2210: }
2211:
2212: sub assemble_email {
1.40 albertel 2213: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 2214: my $email=<<"ENDEMAIL";
2215: Refers to <a href="$feedurl">$feedurl</a>
2216:
2217: $message
2218: ENDEMAIL
2219: my $citations=<<"ENDCITE";
2220: <h2>Previous attempts of student (if applicable)</h2>
2221: $prevattempts
1.63 albertel 2222: <br /><hr />
1.6 albertel 2223: <h2>Original screen output (if applicable)</h2>
2224: $usersaw
1.40 albertel 2225: <h2>Correct Answer(s) (if applicable)</h2>
2226: $useranswer
1.6 albertel 2227: ENDCITE
2228: return ($email,$citations);
2229: }
2230:
1.35 www 2231: sub secapply {
2232: my $rec=shift;
1.36 www 2233: my $defaultflag=shift;
2234: $rec=~s/\s+//g;
2235: $rec=~s/\@/\:/g;
2236: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
2237: if ($sections) {
2238: foreach (split(/\;/,$sections)) {
2239: if (($_ eq $ENV{'request.course.sec'}) ||
2240: ($defaultflag && ($_ eq '*'))) {
2241: return $adr;
2242: }
2243: }
2244: } else {
2245: return $rec;
2246: }
2247: return '';
1.35 www 2248: }
2249:
1.6 albertel 2250: sub decide_receiver {
1.36 www 2251: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 2252: my $typestyle='';
2253: my %to=();
1.36 www 2254: if ($ENV{'form.author'}||$author) {
1.8 www 2255: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 2256: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
2257: $to{$2.':'.$1}=1;
2258: }
1.36 www 2259: if ($ENV{'form.question'}||$question) {
1.8 www 2260: $typestyle.='Submitting as Question<br>';
1.24 harris41 2261: foreach (split(/\,/,
2262: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
2263: ) {
1.36 www 2264: my $rec=&secapply($_,$defaultflag);
2265: if ($rec) { $to{$rec}=1; }
1.24 harris41 2266: }
1.6 albertel 2267: }
1.36 www 2268: if ($ENV{'form.course'}||$course) {
1.63 albertel 2269: $typestyle.='Submitting as Comment<br />';
1.24 harris41 2270: foreach (split(/\,/,
2271: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
2272: ) {
1.36 www 2273: my $rec=&secapply($_,$defaultflag);
2274: if ($rec) { $to{$rec}=1; }
1.24 harris41 2275: }
1.6 albertel 2276: }
1.36 www 2277: if ($ENV{'form.policy'}||$policy) {
1.63 albertel 2278: $typestyle.='Submitting as Policy Feedback<br />';
1.24 harris41 2279: foreach (split(/\,/,
2280: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
2281: ) {
1.36 www 2282: my $rec=&secapply($_,$defaultflag);
2283: if ($rec) { $to{$rec}=1; }
1.24 harris41 2284: }
1.6 albertel 2285: }
1.36 www 2286: if ((scalar(%to) eq '0') && (!$defaultflag)) {
2287: ($typestyle,%to)=
2288: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
2289: }
1.6 albertel 2290: return ($typestyle,%to);
1.36 www 2291: }
2292:
2293: sub feedback_available {
2294: my ($question,$course,$policy)=@_;
2295: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
2296: return scalar(%to);
1.6 albertel 2297: }
2298:
2299: sub send_msg {
1.43 www 2300: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 2301: my $status='';
2302: my $sendsomething=0;
1.24 harris41 2303: foreach (keys %to) {
1.6 albertel 2304: if ($_) {
1.22 www 2305: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 2306: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43 www 2307: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
2308: $attachmenturl)=~/ok/) {
1.63 albertel 2309: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 2310: } else {
2311: $sendsomething++;
2312: }
2313: }
1.24 harris41 2314: }
1.18 www 2315:
2316: my %record=&Apache::lonnet::restore('_feedback');
2317: my ($temp)=keys %record;
2318: unless ($temp=~/^error\:/) {
2319: my %newrecord=();
2320: $newrecord{'resource'}=$feedurl;
2321: $newrecord{'subnumber'}=$record{'subnumber'}+1;
2322: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63 albertel 2323: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 2324: }
2325: }
2326:
1.6 albertel 2327: return ($status,$sendsomething);
2328: }
2329:
1.13 www 2330: sub adddiscuss {
1.78 raeburn 2331: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 2332: my $status='';
1.92 albertel 2333: if (&discussion_open() &&
1.90 albertel 2334: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1.23 www 2335: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20 www 2336:
1.13 www 2337: my %contrib=('message' => $email,
2338: 'sendername' => $ENV{'user.name'},
1.26 www 2339: 'senderdomain' => $ENV{'user.domain'},
2340: 'screenname' => $ENV{'environment.screenname'},
2341: 'plainname' => $ENV{'environment.firstname'}.' '.
2342: $ENV{'environment.middlename'}.' '.
2343: $ENV{'environment.lastname'}.' '.
1.42 www 2344: $ENV{'enrironment.generation'},
1.78 raeburn 2345: 'attachmenturl'=> $attachmenturl,
2346: 'subject' => $subject);
1.65 www 2347: if ($ENV{'form.replydisc'}) {
1.66 www 2348: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65 www 2349: }
1.14 www 2350: if ($anon) {
2351: $contrib{'anonymous'}='true';
2352: }
1.13 www 2353: if (($symb) && ($email)) {
1.102 raeburn 2354: if ($ENV{'form.editdisc'}) {
2355: my %newcontrib = ();
2356: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
2357: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
2358: $contrib{'timestamp'} = time;
2359: $contrib{'history'} = '';
2360: my $numoldver = 0;
2361: my ($oldsymb,$oldidx)=split(/\:\:\:/,$ENV{'form.editdisc'});
1.110 raeburn 2362: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2363: # get timestamp for last post and history
2364: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
2365: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2366: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2367: if (defined($oldcontrib{$oldidx.':replyto'})) {
2368: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2369: }
2370: if (defined($oldcontrib{$oldidx.':history'})) {
2371: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2372: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2373: $numoldver = @oldversions;
2374: } else {
2375: $numoldver = 1;
2376: }
2377: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2378: }
1.108 raeburn 2379: my $numnewver = $numoldver + 1;
1.102 raeburn 2380: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 raeburn 2381: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
2382: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
2383: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2384: } else {
1.112 raeburn 2385: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2386: }
1.102 raeburn 2387: }
2388: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 raeburn 2389: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
2390: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
2391: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2392: } else {
1.112 raeburn 2393: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2394: }
1.102 raeburn 2395: }
2396: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
2397: foreach (keys %contrib) {
2398: my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;
2399: $newcontrib{$key} = $contrib{$_};
2400: }
2401: my $put_reply = &Apache::lonnet::putstore($ENV{'request.course.id'},
2402: \%newcontrib,
2403: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2404: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2405: $status='Editing class discussion'.($anon?' (anonymous)':'');
2406: } else {
2407: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
2408: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1.13 www 2409: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17 www 2410: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.102 raeburn 2411: }
1.21 www 2412: my %storenewentry=($symb => time);
1.63 albertel 2413: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2414: &Apache::lonnet::put('discussiontimes',\%storenewentry,
2415: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2416: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13 www 2417: }
1.17 www 2418: my %record=&Apache::lonnet::restore('_discussion');
2419: my ($temp)=keys %record;
2420: unless ($temp=~/^error\:/) {
2421: my %newrecord=();
2422: $newrecord{'resource'}=$symb;
2423: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2424: $status.='<br />'.&mt('Registering').': '.
1.21 www 2425: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2426: }
2427: } else {
2428: $status.='Failed.';
1.17 www 2429: }
1.63 albertel 2430: return $status.'<br />';
1.13 www 2431: }
2432:
1.33 www 2433: # ----------------------------------------------------------- Preview function
2434:
2435: sub show_preview {
2436: my $r=shift;
2437: my $message=&clear_out_html($ENV{'form.comment'});
2438: $message=~s/\n/\<br \/\>/g;
1.106 www 2439: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2440: $message=&Apache::lontexconvert::msgtexconverted($message);
1.78 raeburn 2441: my $subject=&clear_out_html($ENV{'form.subject'});
2442: $subject=~s/\n/\<br \/\>/g;
2443: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33 www 2444: $r->print('<table border="2"><tr><td>'.
1.78 raeburn 2445: '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33 www 2446: $message.'</td></tr></table>');
2447: }
2448:
2449: sub generate_preview_button {
1.107 www 2450: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2451: return(<<ENDPREVIEW);
2452: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2453: <input type="hidden" name="subject">
1.33 www 2454: <input type="hidden" name="comment" />
1.65 www 2455: <input type="button" value="$pre"
1.105 www 2456: onClick="if (typeof(document.mailform.onsubmit)!='undefined') {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 2457: </form>
2458: ENDPREVIEW
2459: }
1.71 www 2460:
1.108 raeburn 2461: sub modify_attachments {
2462: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
2463: my $subject=&clear_out_html($ENV{'form.subject'});
2464: $subject=~s/\n/\<br \/\>/g;
2465: $subject=&Apache::lontexconvert::msgtexconverted($subject);
2466: my $timestamp=$ENV{'form.timestamp'};
2467: my $numoldver=$ENV{'form.numoldver'};
2468: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
2469: '','');
2470: my $msg = '';
1.113 raeburn 2471: my %attachments = ();
1.108 raeburn 2472: my %currattach = ();
2473: if ($idx) {
1.113 raeburn 2474: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108 raeburn 2475: }
2476: $r->print(<<END);
2477: <html>
2478: <head>
2479: <title>Managing Attachments</title>
2480: <script>
2481: function setAction () {
2482: document.modattachments.action = document.modattachments.origpage.value;
2483: document.modattachments.submit();
2484: }
2485: </script>
2486: </head>
2487: $bodytag
2488: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2489: <table border="2">
2490: <tr>
2491: <td>
2492: <b>Subject:</b>$subject</b><br /><br />
2493: END
2494: if ($idx) {
2495: if ($attachmenturls) {
2496: my @currold = keys %currattach;
2497: if (@currold > 0) {
2498: $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 2499: foreach my $id (@currold) {
2500: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
2501: $attachurl =~ m#/([^/]+)$#;
2502: $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'<br />'."\n");
1.108 raeburn 2503: }
2504: $r->print("<br />");
2505: }
2506: }
2507: }
2508: if (@{$currnewattach} > 0) {
2509: $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");
2510: foreach (@{$currnewattach}) {
2511: $_ =~ m#/([^/]+)$#;
2512: $r->print('<input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'<br />'."\n");
2513: }
2514: $r->print("<br />");
2515: }
2516: $r->print(<<END);
2517: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2518: </td>
2519: </tr>
2520: </table>
2521: <input type="hidden" name="subject" value="$ENV{'form.subject'}" />
2522: <input type="hidden" name="comment" value="$ENV{'form.comment'}" />
2523: <input type="hidden" name="timestamp" value="$ENV{'form.timestamp'}" />
2524: <input type="hidden" name="idx" value="$ENV{'form.idx'}" />
2525: <input type="hidden" name="numoldver" value="$ENV{'form.numoldver'}" />
2526: <input type="hidden" name="origpage" value="$ENV{'form.origpage'}" />
2527: <input type="hidden" name="anondiscuss" value="$ENV{'form.anondiscuss'}" />
2528: <input type="hidden" name="discuss" value="$ENV{'form.discuss'}" />
2529: END
2530: foreach (@{$currnewattach}) {
2531: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2532: }
2533: foreach (@{$currdelold}) {
2534: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2535: }
2536: $r->print(<<END);
2537: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2538: </form>
2539: </body>
2540: </html>
2541: END
2542: return;
2543: }
2544:
2545: sub process_attachments {
2546: my ($currnewattach,$currdelold,$keepold) = @_;
2547: if (exists($ENV{'form.currnewattach'})) {
2548: if (ref($ENV{'form.currnewattach'}) eq 'ARRAY') {
2549: @{$currnewattach} = @{$ENV{'form.currnewattach'}};
2550: } else {
2551: $$currnewattach[0] = $ENV{'form.currnewattach'};
2552: }
2553: }
2554: if (exists($ENV{'form.deloldattach'})) {
2555: if (ref($ENV{'form.deloldattach'}) eq 'ARRAY') {
2556: @{$currdelold} = @{$ENV{'form.deloldattach'}};
2557: } else {
2558: $$currdelold[0] = $ENV{'form.deloldattach'};
2559: }
2560: }
2561: if (exists($ENV{'form.delnewattach'})) {
2562: my @currdelnew = ();
2563: my @currnew = ();
2564: if (ref($ENV{'form.delnewattach'}) eq 'ARRAY') {
2565: @currdelnew = @{$ENV{'form.delnewattach'}};
2566: } else {
2567: $currdelnew[0] = $ENV{'form.delnewattach'};
2568: }
2569: foreach my $newone (@{$currnewattach}) {
2570: my $delflag = 0;
2571: foreach (@currdelnew) {
2572: if ($newone eq $_) {
2573: $delflag = 1;
2574: last;
2575: }
2576: }
2577: unless ($delflag) {
2578: push @currnew, $newone;
2579: }
2580: }
2581: @{$currnewattach} = @currnew;
2582: }
2583: if (exists($ENV{'form.keepold'})) {
2584: if (ref($ENV{'form.keepold'}) eq 'ARRAY') {
2585: @{$keepold} = @{$ENV{'form.keepold'}};
2586: } else {
2587: $$keepold[0] = $ENV{'form.keepold'};
2588: }
2589: }
2590: }
2591:
2592: sub generate_attachments_button {
2593: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2594: my $origpage = $ENV{'REQUEST_URI'};
2595: my $att=$attachnum.' '.&mt("attachments");
2596: my $response = (<<END);
2597: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2598: Click to add/remove attachments: <input type="button" value="$att"
2599: onClick="this.form.subject.value=document.mailform.subject.value;this.form.comment.value=document.mailform.comment.value;
2600: END
2601: unless ($mode eq 'board') {
2602: $response .= 'javascript:anonchk();';
2603: }
2604: $response .= (<<ENDATTACH);
2605: this.form.submit();" />
2606: <input type="hidden" name="origpage" value="$origpage" />
2607: <input type="hidden" name="idx" value="$idx" />
2608: <input type="hidden" name="timestamp" value="$now" />
2609: <input type="hidden" name="subject" />
2610: <input type="hidden" name="comment" />
2611: <input type="hidden" name="anondiscuss" value = "0";
2612: <input type="hidden" name="discuss" value = "0";
2613: <input type="hidden" name="numoldver" value="$numoldver" />
2614: ENDATTACH
2615: if (defined($deloldattach)) {
2616: if (@{$deloldattach} > 0) {
2617: foreach (@{$deloldattach}) {
2618: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
2619: }
2620: }
2621: }
2622: if (defined($currnewattach)) {
2623: if (@{$currnewattach} > 0) {
2624: foreach (@{$currnewattach}) {
2625: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
2626: }
2627: }
2628: }
2629: $response .= '</form>';
2630: return $response;
2631: }
2632:
2633: sub extract_attachments {
2634: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.116 raeburn 2635: %{$attachments}=();
2636: &get_post_attachments($attachments,$attachmenturls);
2637: foreach my $id (sort keys %{$attachments}) {
2638: if (exists($$attachments{$id}{$numoldver})) {
2639: if (defined($currdelold)) {
2640: if (@{$currdelold} > 0) {
2641: unless (grep/^$id$/,@{$currdelold}) {
2642: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2643: }
1.113 raeburn 2644: } else {
2645: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2646: }
1.116 raeburn 2647: } else {
2648: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2649: }
2650: }
1.116 raeburn 2651: }
2652: my @attached = (sort { $a <=> $b } keys %{$currattach});
2653: if (@attached == 1) {
2654: my $id = $attached[0];
2655: my $attachurl;
2656: if ($attachmenturls =~ m/^<attachment id="0">/) {
2657: $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
2658: } else {
2659: $attachurl = $$attachments{$id}{'filename'};
2660: }
2661: $attachurl=~m|/([^/]+)$|;
2662: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
2663: $1.'</tt></a><br />';
2664: &Apache::lonnet::allowuploaded('/adm/feedback',
2665: $attachurl);
2666: } elsif (@attached > 1) {
2667: $$message.='<ol>';
2668: foreach (@attached) {
2669: my $id = $_;
1.113 raeburn 2670: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.116 raeburn 2671: my ($fname)
2672: =($attachurl=~m|/([^/]+)$|);
2673: $$message .= '<li><a href="'.$attachurl.
2674: '"><tt>'.
2675: $fname.'</tt></a></li>';
1.108 raeburn 2676: &Apache::lonnet::allowuploaded('/adm/feedback',
1.116 raeburn 2677: $attachurl);
1.108 raeburn 2678: }
1.116 raeburn 2679: $$message .= '</ol>';
1.108 raeburn 2680: }
2681: }
2682:
2683: sub construct_attachmenturl {
2684: my ($currnewattach,$keepold,$symb,$idx)=@_;
2685: my $oldattachmenturl;
2686: my $newattachmenturl;
1.113 raeburn 2687: my $startnum = 0;
1.108 raeburn 2688: my $currver = 0;
2689: if (($ENV{'form.editdisc'}) && ($idx)) {
2690: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2691: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2692: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2693: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
2694: if ($contrib{$idx.':history'}) {
2695: if ($contrib{$idx.':history'} =~ /:/) {
2696: my @oldversions = split/:/,$contrib{$idx.':history'};
2697: $currver = 1 + scalar(@oldversions);
2698: } else {
2699: $currver = 2;
2700: }
2701: } else {
2702: $currver = 1;
2703: }
2704: if ($oldattachmenturl) {
1.113 raeburn 2705: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
2706: my %attachments = ();
2707: my $prevver = $currver-1;
2708: &get_post_attachments(\%attachments,$oldattachmenturl);
1.116 raeburn 2709: my $numattach = scalar(keys %attachments);
1.113 raeburn 2710: $startnum += $numattach;
2711: foreach my $num (sort {$a <=> $b} keys %attachments) {
2712: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
1.116 raeburn 2713: foreach $_ (sort {$a <=> $b} keys %{$attachments{$num}}) {
2714: unless ($_ eq 'filename') {
2715: $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
2716: }
1.113 raeburn 2717: }
2718: if (grep/^$num$/,@{$keepold}) {
2719: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108 raeburn 2720: }
1.113 raeburn 2721: $newattachmenturl .= '</attachment>';
1.108 raeburn 2722: }
2723: } else {
1.116 raeburn 2724: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
1.108 raeburn 2725: unless (grep/^0$/,@{$keepold}) {
1.113 raeburn 2726: $newattachmenturl .= '<post id="1">n</post>';
1.108 raeburn 2727: }
1.113 raeburn 2728: $newattachmenturl .= '</attachment>';
1.108 raeburn 2729: $startnum ++;
2730: }
2731: }
2732: }
2733: for (my $i=0; $i<@{$currnewattach}; $i++) {
2734: my $attachnum = $startnum + $i;
1.113 raeburn 2735: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108 raeburn 2736: }
2737: return $newattachmenturl;
2738: }
2739:
1.6 albertel 2740: sub handler {
2741: my $r = shift;
1.8 www 2742: if ($r->header_only) {
1.71 www 2743: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2744: $r->send_http_header;
2745: return OK;
2746: }
1.15 www 2747:
2748: # --------------------------- Get query string for limited number of parameters
2749:
1.97 raeburn 2750: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.116 raeburn 2751: ['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 2752: if ($ENV{'form.discsymb'}) {
2753: my $symb = $ENV{'form.discsymb'};
2754: my $readkey = $symb.'_read';
2755: my %readinghash = ();
2756: my $chgcount = 0;
2757: %readinghash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$readkey],$ENV{'user.domain'},$ENV{'user.name'});
2758: foreach my $key (keys %ENV) {
2759: if ($key =~ m/^form\.postunread_(\d+)/) {
2760: if ($readinghash{$readkey} =~ /\.$1\./) {
2761: $readinghash{$readkey} =~ s/\.$1\.//;
2762: $chgcount ++;
2763: }
2764: } elsif ($key =~ m/^form\.postread_(\d+)/) {
2765: unless ($readinghash{$readkey} =~ /\.$1\./) {
2766: $readinghash{$readkey} .= '.'.$1.'.';
2767: $chgcount ++;
2768: }
2769: }
2770: }
2771: if ($chgcount > 0) {
2772: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'});
2773: }
2774: &Apache::loncommon::content_type($r,'text/html');
2775: $r->send_http_header;
2776: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2777: my $previous=$ENV{'form.previous'};
2778: my $feedurl = &Apache::lonnet::clutter($url);
2779: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />','0','0','',$previous,'','','',);
2780: return OK;
2781: }
1.109 raeburn 2782: if ($ENV{'form.allversions'}) {
2783: &Apache::loncommon::content_type($r,'text/html');
2784: $r->send_http_header;
2785: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions',
2786: '','');
2787: $r->print (<<END);
2788: <html>
2789: <head>
2790: <title>Post Versions</title>
2791: <meta http-equiv="pragma" content="no-cache" />
2792: </head>
2793: $bodytag
2794: END
2795: my $crs='/'.$ENV{'request.course.id'};
2796: if ($ENV{'request.course.sec'}) {
2797: $crs.='_'.$ENV{'request.course.sec'};
2798: }
2799: $crs=~s/\_/\//g;
2800: my $seeid=&Apache::lonnet::allowed('rin',$crs);
2801: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.allversions'});
2802: my $ressymb=$symb;
2803: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2804: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2805: }
2806: if ($idx > 0) {
1.116 raeburn 2807: my %messages = ();
2808: my %subjects = ();
2809: my %attachmsgs = ();
2810: my %allattachments = ();
2811: my %imsfiles = ();
2812: my ($screenname,$plainname);
1.109 raeburn 2813: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
2814: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2815: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.116 raeburn 2816: my $discussion = &get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname);
2817: $r->print($discussion);
1.109 raeburn 2818: }
2819: return OK;
2820: }
1.101 raeburn 2821: if ($ENV{'form.posterlist'}) {
2822: &Apache::loncommon::content_type($r,'text/html');
2823: $r->send_http_header;
2824: my $symb=$ENV{'form.posterlist'};
2825: my $sortposts = $ENV{'form.sortposts'};
2826: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2827: my $previous=$ENV{'form.previous'};
2828: my $feedurl = &Apache::lonnet::clutter($url);
2829: # backward compatibility (bulletin boards used to be 'wrapped')
2830: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2831: $feedurl=~s|^/adm/wrapper||;
2832: }
2833: &print_showposters($r,$symb,$previous,$feedurl,$sortposts);
2834: return OK;
2835: }
2836: if ($ENV{'form.userpick'}) {
2837: &Apache::loncommon::content_type($r,'text/html');
2838: $r->send_http_header;
2839: my $symb=$ENV{'form.userpick'};
2840: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2841: my $previous=$ENV{'form.previous'};
2842: # backward compatibility (bulletin boards used to be 'wrapped')
2843: my $ressymb=$symb;
2844: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2845: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2846: }
2847: my $sort=$ENV{'form.sortposts'};
2848: my @posters = ();
2849: if (ref($ENV{'form.stuinfo'}) eq 'ARRAY') {
2850: @posters = $ENV{'form.stuinfo'};
2851: } else {
2852: $posters[0] = $ENV{'form.stuinfo'};
2853: }
2854: my $numpicks = @posters;
2855: if (defined($ENV{'form.userpick'})) {
2856: my %discinfo = ();
2857: $discinfo{$ressymb.'_userpick'} = join('&',@posters);
2858: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2859: }
2860: my $feedurl = &Apache::lonnet::clutter($url);
2861: # backward compatibility (bulletin boards used to be 'wrapped')
2862: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2863: $feedurl=~s|^/adm/wrapper||;
2864: }
2865: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,'','','',$numpicks);
2866: return OK;
2867: }
1.100 raeburn 2868: if ($ENV{'form.applysort'}) {
2869: &Apache::loncommon::content_type($r,'text/html');
2870: $r->send_http_header;
2871: my $symb=$ENV{'form.applysort'};
2872: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2873: my $previous=$ENV{'form.previous'};
2874: my $sort = $ENV{'form.sortposts'};
1.101 raeburn 2875: my $rolefilter = $ENV{'form.rolefilter'};
1.100 raeburn 2876: my $statusfilter = $ENV{'form.statusfilter'};
2877: my $secpick = $ENV{'form.sectionpick'};
2878: my $feedurl = &Apache::lonnet::clutter($url);
2879: # backward compatibility (bulletin boards used to be 'wrapped')
2880: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2881: $feedurl=~s|^/adm/wrapper||;
2882: }
1.101 raeburn 2883: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,$rolefilter,$statusfilter,$secpick);
1.100 raeburn 2884: return OK;
2885: } elsif ($ENV{'form.sortfilter'}) {
2886: &Apache::loncommon::content_type($r,'text/html');
2887: $r->send_http_header;
2888: my $symb=$ENV{'form.sortfilter'};
2889: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2890: my $previous=$ENV{'form.previous'};
2891: my $feedurl = &Apache::lonnet::clutter($url);
2892: # backward compatibility (bulletin boards used to be 'wrapped')
2893: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2894: $feedurl=~s|^/adm/wrapper||;
2895: }
2896: &print_sortfilter_options($r,$symb,$previous,$feedurl);
2897: return OK;
2898: } elsif ($ENV{'form.navmaps'}) {
1.99 raeburn 2899: my %discinfo = ();
2900: my @resources = ();
2901: if ($ENV{'form.navmaps'} =~ /:/) {
2902: @resources = split/:/,$ENV{'form.navmaps'};
2903: } else {
2904: @resources = ("$ENV{'form.navmaps'}");
2905: }
2906: my $numitems = @resources;
2907: my $feedurl = '/adm/navmaps';
2908: if ($ENV{'form.navurl'}) {
2909: $feedurl .= '?'.$ENV{'form.navurl'};
2910: }
2911: my %lt = &Apache::lonlocal::texthash(
2912: 'mnpa' => 'Marked "New" posts as read in a total of',
2913: 'robb' => 'resources/bulletin boards.'
2914: );
2915: foreach (@resources) {
2916: # backward compatibility (bulletin boards used to be 'wrapped')
2917: my $ressymb=$_;
2918: if ($ressymb =~ m/bulletin___\d+___/) {
2919: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2920: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
2921: }
2922: }
2923: my $lastkey = $ressymb.'_lastread';
2924: $discinfo{$lastkey} = time;
2925: }
2926: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2927: &Apache::loncommon::content_type($r,'text/html');
2928: $r->send_http_header;
2929: $r->print (<<ENDREDIR);
2930: <html>
2931: <head>
2932: <title>New posts marked as read</title>
2933: <meta http-equiv="pragma" content="no-cache" />
2934: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
2935: </head>
2936: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
2937: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
2938: <b>$lt{'mnpa'} $numitems $lt{'robb'}</b>
2939: <form name="reldt" action="$feedurl" target="loncapaclient">
2940: </form>
2941: </body>
2942: </html>
2943: ENDREDIR
2944: return OK;
2945: } elsif ($ENV{'form.modifydisp'}) {
1.84 raeburn 2946: &Apache::loncommon::content_type($r,'text/html');
2947: $r->send_http_header;
1.97 raeburn 2948: my $symb=$ENV{'form.modifydisp'};
1.84 raeburn 2949: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.97 raeburn 2950: my $previous=$ENV{'form.previous'};
1.111 raeburn 2951: my ($dispchgA,$dispchgB,$markchg,$toggchg) = split/_/,$ENV{'form.changes'};
1.97 raeburn 2952: my $feedurl = &Apache::lonnet::clutter($url);
1.98 raeburn 2953: # backward compatibility (bulletin boards used to be 'wrapped')
2954: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2955: $feedurl=~s|^/adm/wrapper||;
2956: }
1.111 raeburn 2957: &print_display_options($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 2958: return OK;
1.111 raeburn 2959: } 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 2960: &Apache::loncommon::content_type($r,'text/html');
2961: $r->send_http_header;
2962: my $previous=$ENV{'form.previous'};
2963: my ($map,$ind,$url);
1.111 raeburn 2964: if ( ($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
2965: # ------------------------------ Modify setting for read/unread toggle for each post
2966: my $symb=$ENV{'form.toggoff'}?$ENV{'form.toggoff'}:$ENV{'form.toggon'};
2967: my $ressymb = $symb;
2968: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2969: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2970: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2971: }
2972: my %discinfo = ();
2973: my $toggkey = $ressymb.'_readtoggle';
2974: if ($ENV{'form.toggon'}) {
2975: $discinfo{$toggkey} = 1;
2976: } elsif ($ENV{'form.toggoff'}) {
2977: $discinfo{$toggkey} = 0;
2978: }
2979: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2980: }
1.97 raeburn 2981: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
2982: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
2983: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
2984: my $ressymb = $symb;
2985: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2986: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2987: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2988: }
2989: my %discinfo = ();
2990: my $lastkey = $ressymb.'_lastread';
2991: my $ondispkey = $ressymb.'_markondisp';
2992: if ($ENV{'form.markondisp'}) {
2993: $discinfo{$lastkey} = time;
2994: $discinfo{$ondispkey} = 1;
2995: } elsif ($ENV{'form.markonread'}) {
2996: if ( $previous > 0 ) {
2997: $discinfo{$lastkey} = $previous;
2998: }
2999: $discinfo{$ondispkey} = 0;
3000: }
3001: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 3002: }
1.111 raeburn 3003: if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ) {
1.97 raeburn 3004: # ----------------------------------------------------------------- Modify display setting for this discussion
1.111 raeburn 3005: my $symb;
3006: if ($ENV{'form.allposts'}) {
3007: $symb = $ENV{'form.allposts'};
3008: } elsif ($ENV{'form.onlyunread'}) {
3009: $symb = $ENV{'form.onlyunread'};
3010: } else {
3011: $symb = $ENV{'form.onlyunmark'};
3012: }
1.97 raeburn 3013: my $ressymb = $symb;
3014: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3015: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3016: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3017: }
3018: my %discinfo = ();
3019: if ($ENV{'form.allposts'}) {
3020: $discinfo{$ressymb.'_showonlyunread'} = 0;
1.111 raeburn 3021: $discinfo{$ressymb.'_showonlyunmark'} = 0;
1.97 raeburn 3022: } elsif ($ENV{'form.onlyunread'}) {
3023: $discinfo{$ressymb.'_showonlyunread'} = 1;
1.111 raeburn 3024: } else {
3025: $discinfo{$ressymb.'_showonlyunmark'} = 1;
1.84 raeburn 3026: }
1.97 raeburn 3027: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 3028: }
1.111 raeburn 3029: if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ||($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
1.97 raeburn 3030: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
3031: } else {
1.84 raeburn 3032: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
3033: }
3034: return OK;
3035: } elsif ($ENV{'form.markread'}) {
1.111 raeburn 3036: # ----------------------------------------------------------------- Mark new posts not NEW
1.84 raeburn 3037: &Apache::loncommon::content_type($r,'text/html');
3038: $r->send_http_header;
3039: my $symb=$ENV{'form.markread'};
3040: my $ressymb = $symb;
3041: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3042: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3043: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1.78 raeburn 3044: }
1.84 raeburn 3045: my %discinfo = ();
3046: my $lastkey = $ressymb.'_lastread';
3047: $discinfo{$lastkey} = time;
3048: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
3049: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1.78 raeburn 3050: return OK;
3051: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15 www 3052: # ----------------------------------------------------------------- Hide/unhide
1.71 www 3053: &Apache::loncommon::content_type($r,'text/html');
1.15 www 3054: $r->send_http_header;
3055:
3056: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
3057:
3058: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 3059: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15 www 3060:
3061: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3062: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3063: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3064:
3065:
3066: my $currenthidden=$contrib{'hidden'};
1.102 raeburn 3067: my $currentstudenthidden=$contrib{'studenthidden'};
3068:
3069: my $crs='/'.$ENV{'request.course.id'};
3070: if ($ENV{'request.course.sec'}) {
3071: $crs.='_'.$ENV{'request.course.sec'};
3072: }
3073: $crs=~s/\_/\//g;
3074: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.15 www 3075:
3076: if ($ENV{'form.hide'}) {
3077: $currenthidden.='.'.$idx.'.';
1.102 raeburn 3078: unless ($seeid) {
3079: $currentstudenthidden.='.'.$idx.'.';
3080: }
1.15 www 3081: } else {
3082: $currenthidden=~s/\.$idx\.//g;
3083: }
3084: my %newhash=('hidden' => $currenthidden);
1.102 raeburn 3085: if ( ($ENV{'form.hide'}) && (!$seeid) ) {
3086: $newhash{'studenthidden'} = $currentstudenthidden;
3087: }
1.38 www 3088:
3089: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
3090: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3091: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3092:
3093: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3094: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69 www 3095: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72 albertel 3096: &Apache::loncommon::content_type($r,'text/html');
3097: $r->send_http_header;
1.69 www 3098: if ($ENV{'form.threadedon'}) {
3099: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
3100: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
3101: } else {
3102: &Apache::lonnet::del('environment',['threadeddiscussion']);
3103: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 3104: }
1.69 www 3105: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
3106: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3107: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3108: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38 www 3109: } elsif ($ENV{'form.deldisc'}) {
3110: # --------------------------------------------------------------- Hide for good
1.71 www 3111: &Apache::loncommon::content_type($r,'text/html');
1.38 www 3112: $r->send_http_header;
3113:
3114: my $entry=$ENV{'form.deldisc'};
3115:
3116: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 3117: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38 www 3118:
3119: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3120: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3121: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3122:
3123:
3124: my $currentdeleted=$contrib{'deleted'};
3125:
3126: $currentdeleted.='.'.$idx.'.';
3127:
3128: my %newhash=('deleted' => $currentdeleted);
1.15 www 3129:
3130: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
3131: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3132: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3133:
1.30 www 3134: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3135: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33 www 3136: } elsif ($ENV{'form.preview'}) {
3137: # -------------------------------------------------------- User wants a preview
1.76 albertel 3138: $r->content_type('text/html');
3139: $r->send_http_header;
1.33 www 3140: &show_preview($r);
1.108 raeburn 3141: } elsif ($ENV{'form.attach'}) {
3142: # -------------------------------------------------------- Work on attachments
3143: &Apache::loncommon::content_type($r,'text/html');
3144: $r->send_http_header;
3145: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
3146: my @currnewattach = ();
3147: my @currdelold = ();
3148: my @keepold = ();
3149: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
3150: if (exists($ENV{'form.addnewattach.filename'})) {
3151: unless (length($ENV{'form.addnewattach'})>131072) {
3152: my $subdir = 'feedback/'.$ENV{'form.timestamp'};
3153: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
3154: push @currnewattach, $newattachment;
3155: }
3156: }
3157: my $attachmenturls = '';
3158: my $idx = $ENV{'form.idx'};
3159: my $symb = $ENV{'form.attach'};
3160: if ($idx) {
3161: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3162: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3163: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3164: $attachmenturls = $contrib{$idx.':attachmenturl'};
3165: }
3166: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,$attachmenturls);
1.111 raeburn 3167: } elsif ($ENV{'form.chgreads'}) {
3168: &Apache::loncommon::content_type($r,'text/html');
3169: $r->send_http_header;
3170: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ENV{'form.chgreads'});
3171: &redirect_back($r,&Apache::lonnet::clutter($url),
3172: &mt('Changed read status').'<br />','0','0');
1.116 raeburn 3173: } elsif ($ENV{'form.export'}) {
3174: &Apache::loncommon::content_type($r,'text/html');
3175: $r->send_http_header;
3176: my $symb=$ENV{'form.export'};
3177: my $mode;
3178: my $status='OPEN';
3179: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3180: my $previous=$ENV{'form.previous'};
3181: my $feedurl = &Apache::lonnet::clutter($url);
3182: # backward compatibility (bulletin boards used to be 'wrapped')
3183: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3184: $mode = 'board';
3185: $feedurl=~s|^/adm/wrapper||;
3186: }
3187: if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library)$/) {
3188: $mode='problem';
3189: $status=$Apache::inputtags::status[-1];
3190: }
3191: my $discussion = &list_discussion($mode,$status,$symb);
3192: # &build_ims_export($r,$symb,$previous,$feedurl);
3193: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion');
3194: $r->print($bodytag.$discussion);
3195: return OK;
1.15 www 3196: } else {
3197: # ------------------------------------------------------------- Normal feedback
1.6 albertel 3198: my $feedurl=$ENV{'form.postdata'};
3199: $feedurl=~s/^http\:\/\///;
3200: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
3201: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62 www 3202: $feedurl=~s/\?.+$//;
1.8 www 3203:
1.66 www 3204: my $symb;
3205: if ($ENV{'form.replydisc'}) {
3206: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
3207: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3208: $feedurl=&Apache::lonnet::clutter($url);
1.102 raeburn 3209: } elsif ($ENV{'form.editdisc'}) {
3210: $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
3211: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3212: $feedurl=&Apache::lonnet::clutter($url);
1.108 raeburn 3213: } elsif ($ENV{'form.origpage'}) {
3214: $symb="";
1.66 www 3215: } else {
3216: $symb=&Apache::lonnet::symbread($feedurl);
3217: }
1.31 www 3218: unless ($symb) {
3219: $symb=$ENV{'form.symb'};
3220: if ($symb) {
1.52 www 3221: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31 www 3222: $feedurl=&Apache::lonnet::clutter($url);
3223: }
3224: }
1.8 www 3225: my $goahead=1;
3226: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
3227: unless ($symb) { $goahead=0; }
3228: }
1.98 raeburn 3229: # backward compatibility (bulletin boards used to be 'wrapped')
1.73 albertel 3230: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3231: $feedurl=~s|^/adm/wrapper||;
3232: }
1.8 www 3233: if ($goahead) {
3234: # Go ahead with feedback, no ambiguous reference
1.71 www 3235: &Apache::loncommon::content_type($r,'text/html');
1.8 www 3236: $r->send_http_header;
1.6 albertel 3237:
1.8 www 3238: if (
1.7 albertel 3239: (
3240: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
3241: )
3242: ||
3243: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31 www 3244: ||
3245: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7 albertel 3246: ) {
1.6 albertel 3247: # --------------------------------------------------- Print login screen header
3248: unless ($ENV{'form.sendit'}) {
3249: my $options=&screen_header($feedurl);
3250: if ($options) {
1.108 raeburn 3251: &mail_screen($r,$feedurl,$options);
1.6 albertel 3252: } else {
3253: &fail_redirect($r,$feedurl);
3254: }
3255: } else {
3256:
3257: # Get previous user input
1.9 albertel 3258: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 3259: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 3260: $ENV{'request.course.id'});
1.6 albertel 3261:
3262: # Get output from resource
3263: my $usersaw=&resource_output($feedurl);
3264:
1.50 albertel 3265: # Get resource answer (need to allow student to view grades for this to work)
3266: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 3267: my $useranswer=&Apache::loncommon::get_student_answers(
3268: $symb,$ENV{'user.name'},$ENV{'user.domain'},
3269: $ENV{'request.course.id'});
1.50 albertel 3270: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 3271: # Get attachments, if any, and not too large
3272: my $attachmenturl='';
1.108 raeburn 3273: if (($ENV{'form.origpage'}) || ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'})) {
3274: my ($symb,$idx);
3275: if ($ENV{'form.replydisc'}) {
3276: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
3277: } elsif ($ENV{'form.editdisc'}) {
3278: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
3279: } elsif ($ENV{'form.origpage'}) {
3280: $symb = $ENV{'form.symb'};
3281: }
3282: my @currnewattach = ();
3283: my @deloldattach = ();
3284: my @keepold = ();
3285: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
1.110 raeburn 3286: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.108 raeburn 3287: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
3288: } elsif ($ENV{'form.attachment.filename'}) {
1.42 www 3289: unless (length($ENV{'form.attachment'})>131072) {
1.82 albertel 3290: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3291: }
3292: }
1.6 albertel 3293: # Filter HTML out of message (could be nasty)
1.39 www 3294: my $message=&clear_out_html($ENV{'form.comment'});
1.6 albertel 3295:
3296: # Assemble email
1.8 www 3297: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40 albertel 3298: $usersaw,$useranswer);
3299:
1.6 albertel 3300: # Who gets this?
3301: my ($typestyle,%to) = &decide_receiver($feedurl);
3302:
3303: # Actually send mail
1.43 www 3304: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
3305: $attachmenturl,%to);
1.13 www 3306:
3307: # Discussion? Store that.
3308:
1.32 albertel 3309: my $numpost=0;
1.13 www 3310: if ($ENV{'form.discuss'}) {
1.78 raeburn 3311: my $subject = &clear_out_html($ENV{'form.subject'});
3312: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32 albertel 3313: $numpost++;
1.13 www 3314: }
1.6 albertel 3315:
1.14 www 3316: if ($ENV{'form.anondiscuss'}) {
1.78 raeburn 3317: my $subject = &clear_out_html($ENV{'form.subject'});
3318: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32 albertel 3319: $numpost++;
1.14 www 3320: }
3321:
3322:
1.6 albertel 3323: # Receipt screen and redirect back to where came from
1.80 raeburn 3324: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6 albertel 3325:
3326: }
1.8 www 3327: } else {
1.7 albertel 3328: # Unable to give feedback
1.6 albertel 3329: &no_redirect_back($r,$feedurl);
1.8 www 3330: }
3331: } else {
3332: # Ambiguous Problem Resource
1.60 albertel 3333: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53 albertel 3334: &Apache::lonnet::cleanenv();
1.58 albertel 3335: }
1.53 albertel 3336: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 3337: }
1.15 www 3338: }
1.6 albertel 3339: return OK;
1.1 www 3340: }
3341:
3342: 1;
3343: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>