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