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