Annotation of loncom/interface/lonfeedback.pm, revision 1.131
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.131 ! www 4: # $Id: lonfeedback.pm,v 1.130 2004/11/11 22:47:55 albertel Exp $
1.19 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.77 www 28: ###
1.7 albertel 29:
1.1 www 30: package Apache::lonfeedback;
31:
32: use strict;
33: use Apache::Constants qw(:common);
1.3 www 34: use Apache::lonmsg();
1.9 albertel 35: use Apache::loncommon();
1.33 www 36: use Apache::lontexconvert();
1.86 www 37: use Apache::lonlocal; # must not have ()
38: use Apache::lonhtmlcommon();
1.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.110 raeburn 2343: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2344: # get timestamp for last post and history
2345: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
2346: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2347: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2348: if (defined($oldcontrib{$oldidx.':replyto'})) {
2349: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2350: }
2351: if (defined($oldcontrib{$oldidx.':history'})) {
2352: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2353: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2354: $numoldver = @oldversions;
2355: } else {
2356: $numoldver = 1;
2357: }
2358: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2359: }
1.108 raeburn 2360: my $numnewver = $numoldver + 1;
1.102 raeburn 2361: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 raeburn 2362: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
2363: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
2364: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2365: } else {
1.112 raeburn 2366: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2367: }
1.102 raeburn 2368: }
2369: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 raeburn 2370: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
2371: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
2372: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2373: } else {
1.112 raeburn 2374: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2375: }
1.102 raeburn 2376: }
2377: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
2378: foreach (keys %contrib) {
2379: my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;
2380: $newcontrib{$key} = $contrib{$_};
2381: }
2382: my $put_reply = &Apache::lonnet::putstore($ENV{'request.course.id'},
2383: \%newcontrib,
2384: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2385: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2386: $status='Editing class discussion'.($anon?' (anonymous)':'');
2387: } else {
2388: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
2389: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1.13 www 2390: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17 www 2391: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.102 raeburn 2392: }
1.21 www 2393: my %storenewentry=($symb => time);
1.63 albertel 2394: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2395: &Apache::lonnet::put('discussiontimes',\%storenewentry,
2396: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2397: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13 www 2398: }
1.17 www 2399: my %record=&Apache::lonnet::restore('_discussion');
2400: my ($temp)=keys %record;
2401: unless ($temp=~/^error\:/) {
2402: my %newrecord=();
2403: $newrecord{'resource'}=$symb;
2404: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2405: $status.='<br />'.&mt('Registering').': '.
1.21 www 2406: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2407: }
2408: } else {
2409: $status.='Failed.';
1.17 www 2410: }
1.63 albertel 2411: return $status.'<br />';
1.13 www 2412: }
2413:
1.33 www 2414: # ----------------------------------------------------------- Preview function
2415:
2416: sub show_preview {
2417: my $r=shift;
2418: my $message=&clear_out_html($ENV{'form.comment'});
2419: $message=~s/\n/\<br \/\>/g;
1.106 www 2420: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2421: $message=&Apache::lontexconvert::msgtexconverted($message);
1.78 raeburn 2422: my $subject=&clear_out_html($ENV{'form.subject'});
2423: $subject=~s/\n/\<br \/\>/g;
2424: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33 www 2425: $r->print('<table border="2"><tr><td>'.
1.78 raeburn 2426: '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33 www 2427: $message.'</td></tr></table>');
2428: }
2429:
2430: sub generate_preview_button {
1.107 www 2431: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2432: return(<<ENDPREVIEW);
2433: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2434: <input type="hidden" name="subject">
1.33 www 2435: <input type="hidden" name="comment" />
1.65 www 2436: <input type="button" value="$pre"
1.119 albertel 2437: 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 2438: </form>
2439: ENDPREVIEW
2440: }
1.71 www 2441:
1.108 raeburn 2442: sub modify_attachments {
2443: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
1.124 raeburn 2444: my $orig_subject = &Apache::lonnet::unescape($ENV{'form.subject'});
2445: my $subject=&clear_out_html($orig_subject);
1.108 raeburn 2446: $subject=~s/\n/\<br \/\>/g;
2447: $subject=&Apache::lontexconvert::msgtexconverted($subject);
2448: my $timestamp=$ENV{'form.timestamp'};
2449: my $numoldver=$ENV{'form.numoldver'};
2450: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
2451: '','');
2452: my $msg = '';
1.113 raeburn 2453: my %attachments = ();
1.108 raeburn 2454: my %currattach = ();
2455: if ($idx) {
1.113 raeburn 2456: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108 raeburn 2457: }
2458: $r->print(<<END);
2459: <html>
2460: <head>
2461: <title>Managing Attachments</title>
2462: <script>
2463: function setAction () {
2464: document.modattachments.action = document.modattachments.origpage.value;
2465: document.modattachments.submit();
2466: }
2467: </script>
2468: </head>
2469: $bodytag
2470: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2471: <table border="2">
2472: <tr>
2473: <td>
1.124 raeburn 2474: <b>Subject:</b> $subject</b><br /><br />
1.108 raeburn 2475: END
2476: if ($idx) {
2477: if ($attachmenturls) {
2478: my @currold = keys %currattach;
2479: if (@currold > 0) {
2480: $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 2481: foreach my $id (@currold) {
2482: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
2483: $attachurl =~ m#/([^/]+)$#;
2484: $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'<br />'."\n");
1.108 raeburn 2485: }
2486: $r->print("<br />");
2487: }
2488: }
2489: }
2490: if (@{$currnewattach} > 0) {
2491: $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");
2492: foreach (@{$currnewattach}) {
2493: $_ =~ m#/([^/]+)$#;
2494: $r->print('<input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'<br />'."\n");
2495: }
2496: $r->print("<br />");
2497: }
2498: $r->print(<<END);
2499: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2500: </td>
2501: </tr>
2502: </table>
2503: <input type="hidden" name="subject" value="$ENV{'form.subject'}" />
2504: <input type="hidden" name="comment" value="$ENV{'form.comment'}" />
2505: <input type="hidden" name="timestamp" value="$ENV{'form.timestamp'}" />
2506: <input type="hidden" name="idx" value="$ENV{'form.idx'}" />
2507: <input type="hidden" name="numoldver" value="$ENV{'form.numoldver'}" />
2508: <input type="hidden" name="origpage" value="$ENV{'form.origpage'}" />
2509: <input type="hidden" name="anondiscuss" value="$ENV{'form.anondiscuss'}" />
2510: <input type="hidden" name="discuss" value="$ENV{'form.discuss'}" />
2511: END
2512: foreach (@{$currnewattach}) {
2513: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2514: }
2515: foreach (@{$currdelold}) {
2516: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2517: }
2518: $r->print(<<END);
2519: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2520: </form>
2521: </body>
2522: </html>
2523: END
2524: return;
2525: }
2526:
2527: sub process_attachments {
2528: my ($currnewattach,$currdelold,$keepold) = @_;
2529: if (exists($ENV{'form.currnewattach'})) {
2530: if (ref($ENV{'form.currnewattach'}) eq 'ARRAY') {
2531: @{$currnewattach} = @{$ENV{'form.currnewattach'}};
2532: } else {
2533: $$currnewattach[0] = $ENV{'form.currnewattach'};
2534: }
2535: }
2536: if (exists($ENV{'form.deloldattach'})) {
2537: if (ref($ENV{'form.deloldattach'}) eq 'ARRAY') {
2538: @{$currdelold} = @{$ENV{'form.deloldattach'}};
2539: } else {
2540: $$currdelold[0] = $ENV{'form.deloldattach'};
2541: }
2542: }
2543: if (exists($ENV{'form.delnewattach'})) {
2544: my @currdelnew = ();
2545: my @currnew = ();
2546: if (ref($ENV{'form.delnewattach'}) eq 'ARRAY') {
2547: @currdelnew = @{$ENV{'form.delnewattach'}};
2548: } else {
2549: $currdelnew[0] = $ENV{'form.delnewattach'};
2550: }
2551: foreach my $newone (@{$currnewattach}) {
2552: my $delflag = 0;
2553: foreach (@currdelnew) {
2554: if ($newone eq $_) {
2555: $delflag = 1;
2556: last;
2557: }
2558: }
2559: unless ($delflag) {
2560: push @currnew, $newone;
2561: }
2562: }
2563: @{$currnewattach} = @currnew;
2564: }
2565: if (exists($ENV{'form.keepold'})) {
2566: if (ref($ENV{'form.keepold'}) eq 'ARRAY') {
2567: @{$keepold} = @{$ENV{'form.keepold'}};
2568: } else {
2569: $$keepold[0] = $ENV{'form.keepold'};
2570: }
2571: }
2572: }
2573:
2574: sub generate_attachments_button {
2575: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2576: my $origpage = $ENV{'REQUEST_URI'};
2577: my $att=$attachnum.' '.&mt("attachments");
2578: my $response = (<<END);
2579: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2580: Click to add/remove attachments: <input type="button" value="$att"
1.124 raeburn 2581: 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 2582: END
2583: unless ($mode eq 'board') {
2584: $response .= 'javascript:anonchk();';
2585: }
2586: $response .= (<<ENDATTACH);
2587: this.form.submit();" />
2588: <input type="hidden" name="origpage" value="$origpage" />
2589: <input type="hidden" name="idx" value="$idx" />
2590: <input type="hidden" name="timestamp" value="$now" />
2591: <input type="hidden" name="subject" />
2592: <input type="hidden" name="comment" />
2593: <input type="hidden" name="anondiscuss" value = "0";
2594: <input type="hidden" name="discuss" value = "0";
2595: <input type="hidden" name="numoldver" value="$numoldver" />
2596: ENDATTACH
2597: if (defined($deloldattach)) {
2598: if (@{$deloldattach} > 0) {
2599: foreach (@{$deloldattach}) {
2600: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
2601: }
2602: }
2603: }
2604: if (defined($currnewattach)) {
2605: if (@{$currnewattach} > 0) {
2606: foreach (@{$currnewattach}) {
2607: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
2608: }
2609: }
2610: }
2611: $response .= '</form>';
2612: return $response;
2613: }
2614:
2615: sub extract_attachments {
2616: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.116 raeburn 2617: %{$attachments}=();
2618: &get_post_attachments($attachments,$attachmenturls);
2619: foreach my $id (sort keys %{$attachments}) {
2620: if (exists($$attachments{$id}{$numoldver})) {
2621: if (defined($currdelold)) {
2622: if (@{$currdelold} > 0) {
2623: unless (grep/^$id$/,@{$currdelold}) {
2624: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2625: }
1.113 raeburn 2626: } else {
2627: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2628: }
1.116 raeburn 2629: } else {
2630: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2631: }
2632: }
1.116 raeburn 2633: }
2634: my @attached = (sort { $a <=> $b } keys %{$currattach});
2635: if (@attached == 1) {
2636: my $id = $attached[0];
2637: my $attachurl;
2638: if ($attachmenturls =~ m/^<attachment id="0">/) {
2639: $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
2640: } else {
2641: $attachurl = $$attachments{$id}{'filename'};
2642: }
2643: $attachurl=~m|/([^/]+)$|;
2644: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
2645: $1.'</tt></a><br />';
2646: &Apache::lonnet::allowuploaded('/adm/feedback',
2647: $attachurl);
2648: } elsif (@attached > 1) {
2649: $$message.='<ol>';
2650: foreach (@attached) {
2651: my $id = $_;
1.113 raeburn 2652: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.116 raeburn 2653: my ($fname)
2654: =($attachurl=~m|/([^/]+)$|);
2655: $$message .= '<li><a href="'.$attachurl.
2656: '"><tt>'.
2657: $fname.'</tt></a></li>';
1.108 raeburn 2658: &Apache::lonnet::allowuploaded('/adm/feedback',
1.116 raeburn 2659: $attachurl);
1.108 raeburn 2660: }
1.116 raeburn 2661: $$message .= '</ol>';
1.108 raeburn 2662: }
2663: }
2664:
2665: sub construct_attachmenturl {
2666: my ($currnewattach,$keepold,$symb,$idx)=@_;
2667: my $oldattachmenturl;
2668: my $newattachmenturl;
1.113 raeburn 2669: my $startnum = 0;
1.108 raeburn 2670: my $currver = 0;
2671: if (($ENV{'form.editdisc'}) && ($idx)) {
2672: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2673: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2674: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2675: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
2676: if ($contrib{$idx.':history'}) {
2677: if ($contrib{$idx.':history'} =~ /:/) {
2678: my @oldversions = split/:/,$contrib{$idx.':history'};
2679: $currver = 1 + scalar(@oldversions);
2680: } else {
2681: $currver = 2;
2682: }
2683: } else {
2684: $currver = 1;
2685: }
2686: if ($oldattachmenturl) {
1.113 raeburn 2687: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
2688: my %attachments = ();
2689: my $prevver = $currver-1;
2690: &get_post_attachments(\%attachments,$oldattachmenturl);
1.116 raeburn 2691: my $numattach = scalar(keys %attachments);
1.113 raeburn 2692: $startnum += $numattach;
2693: foreach my $num (sort {$a <=> $b} keys %attachments) {
2694: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
1.116 raeburn 2695: foreach $_ (sort {$a <=> $b} keys %{$attachments{$num}}) {
2696: unless ($_ eq 'filename') {
2697: $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
2698: }
1.113 raeburn 2699: }
2700: if (grep/^$num$/,@{$keepold}) {
2701: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108 raeburn 2702: }
1.113 raeburn 2703: $newattachmenturl .= '</attachment>';
1.108 raeburn 2704: }
2705: } else {
1.116 raeburn 2706: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
1.108 raeburn 2707: unless (grep/^0$/,@{$keepold}) {
1.113 raeburn 2708: $newattachmenturl .= '<post id="1">n</post>';
1.108 raeburn 2709: }
1.113 raeburn 2710: $newattachmenturl .= '</attachment>';
1.108 raeburn 2711: $startnum ++;
2712: }
2713: }
2714: }
2715: for (my $i=0; $i<@{$currnewattach}; $i++) {
2716: my $attachnum = $startnum + $i;
1.113 raeburn 2717: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108 raeburn 2718: }
2719: return $newattachmenturl;
2720: }
1.128 raeburn 2721:
2722: sub has_discussion {
2723: my $resourcesref = shift;
2724: my $navmap = Apache::lonnavmaps::navmap->new();
2725: my @allres=$navmap->retrieveResources();
2726: foreach my $resource (@allres) {
2727: if ($resource->hasDiscussion()) {
2728: my $ressymb;
2729: if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
2730: $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
2731: } else {
2732: $ressymb = $resource->symb();
2733: }
2734: push @{$resourcesref}, $ressymb;
2735: }
2736: }
2737: return;
2738: }
1.108 raeburn 2739:
1.6 albertel 2740: sub handler {
2741: my $r = shift;
1.8 www 2742: if ($r->header_only) {
1.71 www 2743: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2744: $r->send_http_header;
2745: return OK;
2746: }
1.15 www 2747:
2748: # --------------------------- Get query string for limited number of parameters
2749:
1.97 raeburn 2750: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.128 raeburn 2751: ['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 2752: if ($ENV{'form.discsymb'}) {
2753: my $symb = $ENV{'form.discsymb'};
2754: my $readkey = $symb.'_read';
2755: my %readinghash = ();
2756: my $chgcount = 0;
2757: %readinghash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$readkey],$ENV{'user.domain'},$ENV{'user.name'});
2758: foreach my $key (keys %ENV) {
2759: if ($key =~ m/^form\.postunread_(\d+)/) {
2760: if ($readinghash{$readkey} =~ /\.$1\./) {
2761: $readinghash{$readkey} =~ s/\.$1\.//;
2762: $chgcount ++;
2763: }
2764: } elsif ($key =~ m/^form\.postread_(\d+)/) {
2765: unless ($readinghash{$readkey} =~ /\.$1\./) {
2766: $readinghash{$readkey} .= '.'.$1.'.';
2767: $chgcount ++;
2768: }
2769: }
2770: }
2771: if ($chgcount > 0) {
2772: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%readinghash,$ENV{'user.domain'},$ENV{'user.name'});
2773: }
2774: &Apache::loncommon::content_type($r,'text/html');
2775: $r->send_http_header;
2776: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2777: my $previous=$ENV{'form.previous'};
2778: my $feedurl = &Apache::lonnet::clutter($url);
2779: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />','0','0','',$previous,'','','',);
2780: return OK;
2781: }
1.109 raeburn 2782: if ($ENV{'form.allversions'}) {
2783: &Apache::loncommon::content_type($r,'text/html');
2784: $r->send_http_header;
2785: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions',
2786: '','');
2787: $r->print (<<END);
2788: <html>
2789: <head>
2790: <title>Post Versions</title>
2791: <meta http-equiv="pragma" content="no-cache" />
2792: </head>
2793: $bodytag
2794: END
2795: my $crs='/'.$ENV{'request.course.id'};
2796: if ($ENV{'request.course.sec'}) {
2797: $crs.='_'.$ENV{'request.course.sec'};
2798: }
2799: $crs=~s/\_/\//g;
2800: my $seeid=&Apache::lonnet::allowed('rin',$crs);
2801: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.allversions'});
2802: my $ressymb=$symb;
2803: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2804: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2805: }
2806: if ($idx > 0) {
1.116 raeburn 2807: my %messages = ();
2808: my %subjects = ();
2809: my %attachmsgs = ();
2810: my %allattachments = ();
2811: my %imsfiles = ();
2812: my ($screenname,$plainname);
1.109 raeburn 2813: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
2814: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2815: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.116 raeburn 2816: my $discussion = &get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname);
2817: $r->print($discussion);
1.109 raeburn 2818: }
2819: return OK;
2820: }
1.101 raeburn 2821: if ($ENV{'form.posterlist'}) {
2822: &Apache::loncommon::content_type($r,'text/html');
2823: $r->send_http_header;
2824: my $symb=$ENV{'form.posterlist'};
2825: my $sortposts = $ENV{'form.sortposts'};
2826: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2827: my $previous=$ENV{'form.previous'};
2828: my $feedurl = &Apache::lonnet::clutter($url);
2829: # backward compatibility (bulletin boards used to be 'wrapped')
2830: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2831: $feedurl=~s|^/adm/wrapper||;
2832: }
2833: &print_showposters($r,$symb,$previous,$feedurl,$sortposts);
2834: return OK;
2835: }
2836: if ($ENV{'form.userpick'}) {
2837: &Apache::loncommon::content_type($r,'text/html');
2838: $r->send_http_header;
2839: my $symb=$ENV{'form.userpick'};
2840: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2841: my $previous=$ENV{'form.previous'};
2842: # backward compatibility (bulletin boards used to be 'wrapped')
2843: my $ressymb=$symb;
2844: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2845: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2846: }
2847: my $sort=$ENV{'form.sortposts'};
2848: my @posters = ();
2849: if (ref($ENV{'form.stuinfo'}) eq 'ARRAY') {
2850: @posters = $ENV{'form.stuinfo'};
2851: } else {
2852: $posters[0] = $ENV{'form.stuinfo'};
2853: }
2854: my $numpicks = @posters;
2855: if (defined($ENV{'form.userpick'})) {
2856: my %discinfo = ();
2857: $discinfo{$ressymb.'_userpick'} = join('&',@posters);
2858: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2859: }
2860: my $feedurl = &Apache::lonnet::clutter($url);
2861: # backward compatibility (bulletin boards used to be 'wrapped')
2862: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2863: $feedurl=~s|^/adm/wrapper||;
2864: }
2865: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,'','','',$numpicks);
2866: return OK;
2867: }
1.100 raeburn 2868: if ($ENV{'form.applysort'}) {
2869: &Apache::loncommon::content_type($r,'text/html');
2870: $r->send_http_header;
2871: my $symb=$ENV{'form.applysort'};
2872: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2873: my $previous=$ENV{'form.previous'};
2874: my $sort = $ENV{'form.sortposts'};
1.101 raeburn 2875: my $rolefilter = $ENV{'form.rolefilter'};
1.100 raeburn 2876: my $statusfilter = $ENV{'form.statusfilter'};
2877: my $secpick = $ENV{'form.sectionpick'};
2878: my $feedurl = &Apache::lonnet::clutter($url);
2879: # backward compatibility (bulletin boards used to be 'wrapped')
2880: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2881: $feedurl=~s|^/adm/wrapper||;
2882: }
1.101 raeburn 2883: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,$rolefilter,$statusfilter,$secpick);
1.100 raeburn 2884: return OK;
2885: } elsif ($ENV{'form.sortfilter'}) {
2886: &Apache::loncommon::content_type($r,'text/html');
2887: $r->send_http_header;
2888: my $symb=$ENV{'form.sortfilter'};
2889: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2890: my $previous=$ENV{'form.previous'};
2891: my $feedurl = &Apache::lonnet::clutter($url);
2892: # backward compatibility (bulletin boards used to be 'wrapped')
2893: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2894: $feedurl=~s|^/adm/wrapper||;
2895: }
2896: &print_sortfilter_options($r,$symb,$previous,$feedurl);
2897: return OK;
1.128 raeburn 2898: } elsif ($ENV{'form.navtime'}) {
1.99 raeburn 2899: my %discinfo = ();
2900: my @resources = ();
1.128 raeburn 2901: if (defined($ENV{'form.navmaps'})) {
2902: if ($ENV{'form.navmaps'} =~ /:/) {
2903: @resources = split/:/,$ENV{'form.navmaps'};
2904: } else {
2905: @resources = ("$ENV{'form.navmaps'}");
2906: }
1.99 raeburn 2907: } else {
1.128 raeburn 2908: &has_discussion(\@resources);
1.99 raeburn 2909: }
2910: my $numitems = @resources;
2911: my $feedurl = '/adm/navmaps';
2912: if ($ENV{'form.navurl'}) {
2913: $feedurl .= '?'.$ENV{'form.navurl'};
2914: }
2915: my %lt = &Apache::lonlocal::texthash(
2916: 'mnpa' => 'Marked "New" posts as read in a total of',
1.128 raeburn 2917: 'robb' => 'resources/bulletin boards.',
2918: 'twnp' => 'There are currently no resources or bulletin boards with unread discussion postings.'
1.99 raeburn 2919: );
2920: foreach (@resources) {
2921: # backward compatibility (bulletin boards used to be 'wrapped')
2922: my $ressymb=$_;
2923: if ($ressymb =~ m/bulletin___\d+___/) {
2924: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2925: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
2926: }
2927: }
2928: my $lastkey = $ressymb.'_lastread';
1.127 albertel 2929: $discinfo{$lastkey} = $ENV{'form.navtime'};
1.99 raeburn 2930: }
1.128 raeburn 2931: my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
2932: if ($numitems > 0) {
2933: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2934: } else {
2935: $textline = "<b>$lt{'twnp'}</b>";
2936: }
1.99 raeburn 2937: &Apache::loncommon::content_type($r,'text/html');
2938: $r->send_http_header;
2939: $r->print (<<ENDREDIR);
2940: <html>
2941: <head>
2942: <title>New posts marked as read</title>
2943: <meta http-equiv="pragma" content="no-cache" />
2944: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
2945: </head>
2946: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
2947: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.128 raeburn 2948: $textline
1.99 raeburn 2949: <form name="reldt" action="$feedurl" target="loncapaclient">
2950: </form>
1.121 albertel 2951: <br /><a href="$feedurl">Continue</a>
1.99 raeburn 2952: </body>
2953: </html>
2954: ENDREDIR
2955: return OK;
2956: } elsif ($ENV{'form.modifydisp'}) {
1.84 raeburn 2957: &Apache::loncommon::content_type($r,'text/html');
2958: $r->send_http_header;
1.97 raeburn 2959: my $symb=$ENV{'form.modifydisp'};
1.84 raeburn 2960: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.97 raeburn 2961: my $previous=$ENV{'form.previous'};
1.111 raeburn 2962: my ($dispchgA,$dispchgB,$markchg,$toggchg) = split/_/,$ENV{'form.changes'};
1.97 raeburn 2963: my $feedurl = &Apache::lonnet::clutter($url);
1.98 raeburn 2964: # backward compatibility (bulletin boards used to be 'wrapped')
2965: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
2966: $feedurl=~s|^/adm/wrapper||;
2967: }
1.111 raeburn 2968: &print_display_options($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 2969: return OK;
1.111 raeburn 2970: } 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 2971: &Apache::loncommon::content_type($r,'text/html');
2972: $r->send_http_header;
2973: my $previous=$ENV{'form.previous'};
2974: my ($map,$ind,$url);
1.111 raeburn 2975: if ( ($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
2976: # ------------------------------ Modify setting for read/unread toggle for each post
2977: my $symb=$ENV{'form.toggoff'}?$ENV{'form.toggoff'}:$ENV{'form.toggon'};
2978: my $ressymb = $symb;
2979: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2980: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2981: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2982: }
2983: my %discinfo = ();
2984: my $toggkey = $ressymb.'_readtoggle';
2985: if ($ENV{'form.toggon'}) {
2986: $discinfo{$toggkey} = 1;
2987: } elsif ($ENV{'form.toggoff'}) {
2988: $discinfo{$toggkey} = 0;
2989: }
2990: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2991: }
1.97 raeburn 2992: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
2993: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
2994: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
2995: my $ressymb = $symb;
2996: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
2997: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2998: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
2999: }
3000: my %discinfo = ();
3001: my $lastkey = $ressymb.'_lastread';
3002: my $ondispkey = $ressymb.'_markondisp';
3003: if ($ENV{'form.markondisp'}) {
3004: $discinfo{$lastkey} = time;
3005: $discinfo{$ondispkey} = 1;
3006: } elsif ($ENV{'form.markonread'}) {
3007: if ( $previous > 0 ) {
3008: $discinfo{$lastkey} = $previous;
3009: }
3010: $discinfo{$ondispkey} = 0;
3011: }
3012: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 3013: }
1.111 raeburn 3014: if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ) {
1.97 raeburn 3015: # ----------------------------------------------------------------- Modify display setting for this discussion
1.111 raeburn 3016: my $symb;
3017: if ($ENV{'form.allposts'}) {
3018: $symb = $ENV{'form.allposts'};
3019: } elsif ($ENV{'form.onlyunread'}) {
3020: $symb = $ENV{'form.onlyunread'};
3021: } else {
3022: $symb = $ENV{'form.onlyunmark'};
3023: }
1.97 raeburn 3024: my $ressymb = $symb;
3025: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3026: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3027: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3028: }
3029: my %discinfo = ();
3030: if ($ENV{'form.allposts'}) {
3031: $discinfo{$ressymb.'_showonlyunread'} = 0;
1.111 raeburn 3032: $discinfo{$ressymb.'_showonlyunmark'} = 0;
1.97 raeburn 3033: } elsif ($ENV{'form.onlyunread'}) {
3034: $discinfo{$ressymb.'_showonlyunread'} = 1;
1.111 raeburn 3035: } else {
3036: $discinfo{$ressymb.'_showonlyunmark'} = 1;
1.84 raeburn 3037: }
1.97 raeburn 3038: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 3039: }
1.111 raeburn 3040: if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) || ($ENV{'form.onlyunmark'}) ||($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
1.97 raeburn 3041: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
3042: } else {
1.84 raeburn 3043: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
3044: }
3045: return OK;
3046: } elsif ($ENV{'form.markread'}) {
1.111 raeburn 3047: # ----------------------------------------------------------------- Mark new posts not NEW
1.84 raeburn 3048: &Apache::loncommon::content_type($r,'text/html');
3049: $r->send_http_header;
3050: my $symb=$ENV{'form.markread'};
3051: my $ressymb = $symb;
3052: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3053: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3054: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1.78 raeburn 3055: }
1.84 raeburn 3056: my %discinfo = ();
3057: my $lastkey = $ressymb.'_lastread';
3058: $discinfo{$lastkey} = time;
3059: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
3060: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1.78 raeburn 3061: return OK;
3062: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15 www 3063: # ----------------------------------------------------------------- Hide/unhide
1.71 www 3064: &Apache::loncommon::content_type($r,'text/html');
1.15 www 3065: $r->send_http_header;
3066:
3067: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
3068:
3069: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 3070: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15 www 3071:
3072: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3073: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3074: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3075:
3076:
3077: my $currenthidden=$contrib{'hidden'};
1.102 raeburn 3078: my $currentstudenthidden=$contrib{'studenthidden'};
3079:
3080: my $crs='/'.$ENV{'request.course.id'};
3081: if ($ENV{'request.course.sec'}) {
3082: $crs.='_'.$ENV{'request.course.sec'};
3083: }
3084: $crs=~s/\_/\//g;
3085: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.15 www 3086:
3087: if ($ENV{'form.hide'}) {
3088: $currenthidden.='.'.$idx.'.';
1.102 raeburn 3089: unless ($seeid) {
3090: $currentstudenthidden.='.'.$idx.'.';
3091: }
1.15 www 3092: } else {
3093: $currenthidden=~s/\.$idx\.//g;
3094: }
3095: my %newhash=('hidden' => $currenthidden);
1.102 raeburn 3096: if ( ($ENV{'form.hide'}) && (!$seeid) ) {
3097: $newhash{'studenthidden'} = $currentstudenthidden;
3098: }
1.38 www 3099:
3100: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
3101: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3102: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3103:
3104: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3105: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69 www 3106: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72 albertel 3107: &Apache::loncommon::content_type($r,'text/html');
3108: $r->send_http_header;
1.69 www 3109: if ($ENV{'form.threadedon'}) {
3110: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
3111: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
3112: } else {
3113: &Apache::lonnet::del('environment',['threadeddiscussion']);
3114: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 3115: }
1.69 www 3116: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
3117: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3118: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3119: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38 www 3120: } elsif ($ENV{'form.deldisc'}) {
3121: # --------------------------------------------------------------- Hide for good
1.71 www 3122: &Apache::loncommon::content_type($r,'text/html');
1.38 www 3123: $r->send_http_header;
3124:
3125: my $entry=$ENV{'form.deldisc'};
3126:
3127: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 3128: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38 www 3129:
3130: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3131: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3132: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3133:
3134:
3135: my $currentdeleted=$contrib{'deleted'};
3136:
3137: $currentdeleted.='.'.$idx.'.';
3138:
3139: my %newhash=('deleted' => $currentdeleted);
1.15 www 3140:
3141: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
3142: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3143: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3144:
1.30 www 3145: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 3146: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33 www 3147: } elsif ($ENV{'form.preview'}) {
3148: # -------------------------------------------------------- User wants a preview
1.76 albertel 3149: $r->content_type('text/html');
3150: $r->send_http_header;
1.33 www 3151: &show_preview($r);
1.108 raeburn 3152: } elsif ($ENV{'form.attach'}) {
3153: # -------------------------------------------------------- Work on attachments
3154: &Apache::loncommon::content_type($r,'text/html');
3155: $r->send_http_header;
3156: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
3157: my @currnewattach = ();
3158: my @currdelold = ();
3159: my @keepold = ();
3160: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
3161: if (exists($ENV{'form.addnewattach.filename'})) {
3162: unless (length($ENV{'form.addnewattach'})>131072) {
3163: my $subdir = 'feedback/'.$ENV{'form.timestamp'};
3164: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
3165: push @currnewattach, $newattachment;
3166: }
3167: }
3168: my $attachmenturls = '';
3169: my $idx = $ENV{'form.idx'};
3170: my $symb = $ENV{'form.attach'};
3171: if ($idx) {
3172: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3173: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3174: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3175: $attachmenturls = $contrib{$idx.':attachmenturl'};
3176: }
3177: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,$attachmenturls);
1.111 raeburn 3178: } elsif ($ENV{'form.chgreads'}) {
3179: &Apache::loncommon::content_type($r,'text/html');
3180: $r->send_http_header;
3181: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ENV{'form.chgreads'});
3182: &redirect_back($r,&Apache::lonnet::clutter($url),
3183: &mt('Changed read status').'<br />','0','0');
1.116 raeburn 3184: } elsif ($ENV{'form.export'}) {
3185: &Apache::loncommon::content_type($r,'text/html');
3186: $r->send_http_header;
3187: my $symb=$ENV{'form.export'};
3188: my $mode;
3189: my $status='OPEN';
3190: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3191: my $previous=$ENV{'form.previous'};
3192: my $feedurl = &Apache::lonnet::clutter($url);
3193: # backward compatibility (bulletin boards used to be 'wrapped')
3194: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3195: $mode = 'board';
3196: $feedurl=~s|^/adm/wrapper||;
3197: }
3198: if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library)$/) {
3199: $mode='problem';
3200: $status=$Apache::inputtags::status[-1];
3201: }
3202: my $discussion = &list_discussion($mode,$status,$symb);
3203: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion');
3204: $r->print($bodytag.$discussion);
3205: return OK;
1.15 www 3206: } else {
3207: # ------------------------------------------------------------- Normal feedback
1.6 albertel 3208: my $feedurl=$ENV{'form.postdata'};
3209: $feedurl=~s/^http\:\/\///;
3210: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
3211: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62 www 3212: $feedurl=~s/\?.+$//;
1.8 www 3213:
1.66 www 3214: my $symb;
3215: if ($ENV{'form.replydisc'}) {
3216: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
3217: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3218: $feedurl=&Apache::lonnet::clutter($url);
1.102 raeburn 3219: } elsif ($ENV{'form.editdisc'}) {
3220: $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
3221: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3222: $feedurl=&Apache::lonnet::clutter($url);
1.108 raeburn 3223: } elsif ($ENV{'form.origpage'}) {
3224: $symb="";
1.66 www 3225: } else {
3226: $symb=&Apache::lonnet::symbread($feedurl);
3227: }
1.31 www 3228: unless ($symb) {
3229: $symb=$ENV{'form.symb'};
3230: if ($symb) {
1.52 www 3231: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31 www 3232: $feedurl=&Apache::lonnet::clutter($url);
3233: }
3234: }
1.8 www 3235: my $goahead=1;
3236: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
3237: unless ($symb) { $goahead=0; }
3238: }
1.98 raeburn 3239: # backward compatibility (bulletin boards used to be 'wrapped')
1.73 albertel 3240: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3241: $feedurl=~s|^/adm/wrapper||;
3242: }
1.8 www 3243: if ($goahead) {
3244: # Go ahead with feedback, no ambiguous reference
1.71 www 3245: &Apache::loncommon::content_type($r,'text/html');
1.8 www 3246: $r->send_http_header;
1.6 albertel 3247:
1.8 www 3248: if (
1.7 albertel 3249: (
3250: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
3251: )
3252: ||
3253: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31 www 3254: ||
3255: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7 albertel 3256: ) {
1.6 albertel 3257: # --------------------------------------------------- Print login screen header
3258: unless ($ENV{'form.sendit'}) {
3259: my $options=&screen_header($feedurl);
3260: if ($options) {
1.108 raeburn 3261: &mail_screen($r,$feedurl,$options);
1.6 albertel 3262: } else {
3263: &fail_redirect($r,$feedurl);
3264: }
3265: } else {
3266:
3267: # Get previous user input
1.9 albertel 3268: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 3269: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 3270: $ENV{'request.course.id'});
1.6 albertel 3271:
3272: # Get output from resource
3273: my $usersaw=&resource_output($feedurl);
3274:
1.50 albertel 3275: # Get resource answer (need to allow student to view grades for this to work)
3276: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 3277: my $useranswer=&Apache::loncommon::get_student_answers(
3278: $symb,$ENV{'user.name'},$ENV{'user.domain'},
3279: $ENV{'request.course.id'});
1.50 albertel 3280: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 3281: # Get attachments, if any, and not too large
3282: my $attachmenturl='';
1.108 raeburn 3283: if (($ENV{'form.origpage'}) || ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'})) {
3284: my ($symb,$idx);
3285: if ($ENV{'form.replydisc'}) {
3286: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
3287: } elsif ($ENV{'form.editdisc'}) {
3288: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
3289: } elsif ($ENV{'form.origpage'}) {
3290: $symb = $ENV{'form.symb'};
3291: }
3292: my @currnewattach = ();
3293: my @deloldattach = ();
3294: my @keepold = ();
3295: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
1.110 raeburn 3296: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.108 raeburn 3297: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
3298: } elsif ($ENV{'form.attachment.filename'}) {
1.42 www 3299: unless (length($ENV{'form.attachment'})>131072) {
1.82 albertel 3300: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3301: }
3302: }
1.6 albertel 3303: # Filter HTML out of message (could be nasty)
1.39 www 3304: my $message=&clear_out_html($ENV{'form.comment'});
1.6 albertel 3305:
3306: # Assemble email
1.8 www 3307: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40 albertel 3308: $usersaw,$useranswer);
3309:
1.6 albertel 3310: # Who gets this?
3311: my ($typestyle,%to) = &decide_receiver($feedurl);
3312:
3313: # Actually send mail
1.43 www 3314: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
3315: $attachmenturl,%to);
1.13 www 3316:
3317: # Discussion? Store that.
3318:
1.32 albertel 3319: my $numpost=0;
1.13 www 3320: if ($ENV{'form.discuss'}) {
1.78 raeburn 3321: my $subject = &clear_out_html($ENV{'form.subject'});
3322: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32 albertel 3323: $numpost++;
1.13 www 3324: }
1.6 albertel 3325:
1.14 www 3326: if ($ENV{'form.anondiscuss'}) {
1.78 raeburn 3327: my $subject = &clear_out_html($ENV{'form.subject'});
3328: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32 albertel 3329: $numpost++;
1.14 www 3330: }
3331:
3332:
1.6 albertel 3333: # Receipt screen and redirect back to where came from
1.80 raeburn 3334: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6 albertel 3335:
3336: }
1.8 www 3337: } else {
1.7 albertel 3338: # Unable to give feedback
1.6 albertel 3339: &no_redirect_back($r,$feedurl);
1.8 www 3340: }
3341: } else {
3342: # Ambiguous Problem Resource
1.60 albertel 3343: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53 albertel 3344: &Apache::lonnet::cleanenv();
1.58 albertel 3345: }
1.53 albertel 3346: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 3347: }
1.15 www 3348: }
1.6 albertel 3349: return OK;
1.1 www 3350: }
3351:
3352: 1;
3353: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>