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