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