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