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