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