Annotation of loncom/interface/lonfeedback.pm, revision 1.134
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.134 ! albertel 4: # $Id: lonfeedback.pm,v 1.133 2004/11/15 21:35:37 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">'.
363: '<a href="/adm/feedback?threadedon='.$ressymb;
364: if ($newpostsflag) {
365: $discussion .= '&previous='.$prevread;
366: }
367: $discussion .='">'.&mt('Threaded View').'</a> '.
368: '<a href="/adm/feedback?threadedoff='.$ressymb;
369: if ($newpostsflag) {
370: $discussion .= '&previous='.$prevread;
371: }
1.100 raeburn 372: $discussion .='">'.&mt('Chronological View').'</a>
373: <a href= "/adm/feedback?sortfilter='.$ressymb;
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.111 raeburn 388: $discussion .='<td align="right"><a href="/adm/feedback?markread='.$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.133 albertel 1478: &dewrapper(\$feedurl);
1.98 raeburn 1479:
1.97 raeburn 1480: my $function = &Apache::loncommon::get_users_function();
1481: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1482: $ENV{'user.domain'});
1483: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1484: '','');
1485:
1486: my %lt = &Apache::lonlocal::texthash(
1487: 'dido' => 'Discussion display options',
1488: 'pref' => 'Display Preference',
1489: 'curr' => 'Current setting ',
1490: 'actn' => 'Action',
1491: 'deff' => 'Default for all discussions',
1492: 'prca' => 'Preferences can be set for this discussion that determine ....',
1493: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
1.111 raeburn 1494: 'unwh' => 'Under what circumstances posts are identified as "NEW", and',
1495: 'wipa' => 'Whether individual posts can be marked as read/unread',
1.97 raeburn 1496: 'allposts' => 'All posts',
1497: 'unread' => 'New posts only',
1.111 raeburn 1498: 'unmark' => 'Posts not marked read',
1.97 raeburn 1499: 'ondisp' => 'Once displayed',
1.111 raeburn 1500: 'onmark' => 'Once marked not NEW ',
1501: 'toggon' => 'Shown',
1502: 'toggoff' => 'Not shown',
1.97 raeburn 1503: 'disa' => 'Posts displayed?',
1.111 raeburn 1504: 'npmr' => 'New posts cease to be identified as "NEW"?',
1505: 'dotm' => 'Option to mark each post as read/unread?',
1.97 raeburn 1506: 'chgt' => 'Change to ',
1507: 'mkdf' => 'Set to ',
1.111 raeburn 1508: 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
1.97 raeburn 1509: 'ywbr' => 'You will be returned to the previous page if you click OK.'
1510: );
1511:
1.111 raeburn 1512: my $dispchangeA = $lt{'unread'};
1513: my $dispchangeB = $lt{'unmark'};
1.97 raeburn 1514: my $markchange = $lt{'ondisp'};
1.111 raeburn 1515: my $toggchange = $lt{'toggon'};
1.97 raeburn 1516: my $currdisp = $lt{'allposts'};
1517: my $currmark = $lt{'onmark'};
1518: my $discdisp = 'allposts';
1519: my $discmark = 'onmark';
1.111 raeburn 1520: my $currtogg = $lt{'toggoff'};
1521: my $disctogg = 'toggoff';
1.97 raeburn 1522:
1.111 raeburn 1523: if ($dispchgA eq 'allposts') {
1524: $dispchangeA = $lt{'allposts'};
1.97 raeburn 1525: $currdisp = $lt{'unread'};
1526: $discdisp = 'unread';
1527: }
1.111 raeburn 1528:
1.97 raeburn 1529: if ($markchg eq 'markonread') {
1530: $markchange = $lt{'onmark'};
1531: $currmark = $lt{'ondisp'};
1532: $discmark = 'ondisp';
1533: }
1.111 raeburn 1534:
1535: if ($dispchgB eq 'onlyunread') {
1536: $dispchangeB = $lt{'unread'};
1537: $currdisp = $lt{'unmark'};
1538: $discdisp = 'unmark';
1539: }
1540: if ($toggchg eq 'toggoff') {
1541: $toggchange = $lt{'toggoff'};
1542: $currtogg = $lt{'toggon'};
1543: $disctogg = 'toggon';
1544: }
1.97 raeburn 1545: $r->print(<<END);
1546: <html>
1547: <head>
1548: <title>$lt{'dido'}</title>
1549: <meta http-equiv="pragma" content="no-cache" />
1550: <script>
1.111 raeburn 1551: function discdispChk(caller) {
1552: var disctogg = '$toggchg'
1553: if (caller == 0) {
1554: if (document.modifydisp.discdisp[0].checked == true) {
1555: if (document.modifydisp.discdisp[1].checked == true) {
1556: document.modifydisp.discdisp[1].checked = false
1557: }
1558: }
1559: }
1560: if (caller == 1) {
1561: if (document.modifydisp.discdisp[1].checked == true) {
1562: if (document.modifydisp.discdisp[0].checked == true) {
1563: document.modifydisp.discdisp[0].checked = false
1564: }
1565: if (disctogg == 'toggon') {
1566: document.modifydisp.disctogg.checked = true
1567: }
1568: if (disctogg == 'toggoff') {
1569: document.modifydisp.disctogg.checked = false
1570: }
1571: }
1572: }
1573: if (caller == 2) {
1574: var dispchgB = '$dispchgB'
1575: if (disctogg == 'toggoff') {
1576: if (document.modifydisp.disctogg.checked == true) {
1577: if (dispchgB == 'onlyunmark') {
1578: document.modifydisp.discdisp[1].checked = false
1579: }
1580: }
1581: }
1582: }
1583: }
1584:
1.97 raeburn 1585: function setDisp() {
1586: var prev = "$previous"
1587: var chktotal = 0
1.111 raeburn 1588: if (document.modifydisp.discdisp[0].checked == true) {
1589: document.modifydisp.$dispchgA.value = "$symb"
1590: chktotal ++
1591: }
1592: if (document.modifydisp.discdisp[1].checked == true) {
1593: document.modifydisp.$dispchgB.value = "$symb"
1.97 raeburn 1594: chktotal ++
1595: }
1596: if (document.modifydisp.discmark.checked == true) {
1597: document.modifydisp.$markchg.value = "$symb"
1598: chktotal ++
1599: }
1.111 raeburn 1600: if (document.modifydisp.disctogg.checked == true) {
1601: document.modifydisp.$toggchg.value = "$symb"
1602: chktotal ++
1603: }
1.97 raeburn 1604: if (chktotal > 0) {
1605: document.modifydisp.submit()
1606: } else {
1607: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
1608: if (prev > 0) {
1609: location.href = "$feedurl?previous=$previous"
1610: } else {
1611: location.href = "$feedurl"
1612: }
1613: }
1614: }
1615: }
1616: </script>
1617: </head>
1618: $bodytag
1619: <form name="modifydisp" method="post" action="/adm/feedback">
1.111 raeburn 1620: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
1.97 raeburn 1621: <br />
1622: <table border="0" cellpadding="0" cellspacing="0">
1623: <tr>
1624: <td width="100%" bgcolor="#000000">
1625: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1626: <tr>
1627: <td width="100%" bgcolor="#000000">
1628: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
1629: <tr bgcolor="$tabcolor">
1630: <td><b>$lt{'pref'}</b></td>
1631: <td><b>$lt{'curr'}</b></td>
1632: <td><b>$lt{'actn'}?</b></td>
1633: </tr>
1634: <tr bgcolor="#dddddd">
1635: <td>$lt{'disa'}</td>
1636: <td>$lt{$discdisp}</td>
1.111 raeburn 1637: <td><input type="checkbox" name="discdisp" onClick="discdispChk('0')" /> $lt{'chgt'} "$dispchangeA"
1638: <br />
1639: <input type="checkbox" name="discdisp" onClick="discdispChk('1')" /> $lt{'chgt'} "$dispchangeB"
1640: </td>
1.97 raeburn 1641: </tr><tr bgcolor="#eeeeee">
1642: <td>$lt{'npmr'}</td>
1643: <td>$lt{$discmark}</td>
1644: <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
1.111 raeburn 1645: </tr><tr bgcolor="#dddddd">
1646: <td>$lt{'dotm'}</td>
1647: <td>$lt{$disctogg}</td>
1648: <td><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</td>
1.97 raeburn 1649: </tr>
1650: </table>
1651: </td>
1652: </tr>
1653: </table>
1654: </td>
1655: </tr>
1656: </table>
1657: <br />
1658: <br />
1659: <input type="hidden" name="previous" value="$previous" />
1.111 raeburn 1660: <input type="hidden" name="$dispchgA" value=""/>
1661: <input type="hidden" name="$dispchgB" value=""/>
1.97 raeburn 1662: <input type="hidden" name="$markchg" value=""/>
1.111 raeburn 1663: <input type="hidden" name="$toggchg" value="" />
1.97 raeburn 1664: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
1665: <br />
1666: <br />
1667: </form>
1668: </body>
1669: </html>
1670: END
1671: return;
1672: }
1673:
1.100 raeburn 1674: sub print_sortfilter_options {
1675: my ($r,$symb,$previous,$feedurl) = @_;
1.133 albertel 1676:
1677: &dewrapper(\$feedurl);
1.100 raeburn 1678: my @sections = ();
1679: my $section_sel = '';
1680: my $numsections = 0;
1681: my $numvisible = 5;
1682: my ($classlist) = &Apache::loncoursedata::get_classlist(
1683: $ENV{'request.course.id'},
1684: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1685: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1686:
1687: my $sec_index = &Apache::loncoursedata::CL_SECTION();
1688: my $status_index = &Apache::loncoursedata::CL_STATUS();
1689: my %sectioncount = ();
1690: while (my ($student,$data) = each %$classlist) {
1691: my ($section,$status) = ($data->[$sec_index],
1692: $data->[$status_index]);
1693: unless ($section eq '' || $section =~ /^\s*$/) {
1694: if (!defined($sectioncount{$section})) {
1695: $sectioncount{$section} = 1;
1696: $numsections ++;
1697: } else {
1698: $sectioncount{$section} ++;
1699: }
1700: }
1701: }
1702:
1703: if ($ENV{'request.course.sec'} !~ /^\s*$/) {
1704: @sections = ($ENV{'request.course.sec'});
1705: $numvisible = 1;
1706: } else {
1707: @sections = sort {$a cmp $b} keys(%sectioncount);
1708: unshift(@sections,'all'); # Put 'all' at the front of the list
1709: if ($numsections < 4) {
1710: $numvisible = $numsections + 1;
1711: }
1712: }
1713: foreach (@sections) {
1714: $section_sel .= " <option value=\"$_\" />$_\n";
1715: }
1716:
1717: my $function = &Apache::loncommon::get_users_function();
1718: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1719: $ENV{'user.domain'});
1720: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1721: '','');
1722: my %lt = &Apache::lonlocal::texthash(
1723: 'diso' => 'Discussion sorting and filtering options',
1724: 'diop' => 'Display Options',
1725: 'curr' => 'Current setting ',
1726: 'actn' => 'Action',
1.101 raeburn 1727: 'prca' => 'Options can be set that control the sort order of the posts, in addition to which posts are displayed.',
1.100 raeburn 1728: 'soor' => 'Sort order',
1729: 'disp' => 'Specific user roles',
1730: 'actv' => 'Specific role status',
1731: 'spse' => 'Specific sections',
1732: 'psub' => 'Pick specific users (by name)',
1.101 raeburn 1733: 'shal' => 'Show a list of current posters'
1.100 raeburn 1734: );
1735: $r->print(<<END);
1736: <html>
1737: <head>
1738: <title>$lt{'diso'}</title>
1739: <meta http-equiv="pragma" content="no-cache" />
1740: </head>
1741: $bodytag
1742: <form name="modifyshown" method="post" action="/adm/feedback">
1743: <b>$lt{'diso'}</b><br/> $lt{'prca'}
1744: <br /><br />
1745: <table border="0">
1746: <tr>
1747: <td><b>$lt{'soor'}</b></td>
1748: <td> </td>
1749: <td><b>$lt{'disp'}</b></td>
1750: <td> </td>
1751: <td><b>$lt{'actv'}</b></td>
1752: <td> </td>
1753: <td><b>$lt{'spse'}</b></td>
1754: <td> </td>
1755: <td><b>$lt{'psub'}</b></td>
1756: </tr>
1757: <tr>
1758: <td>
1759: <select name="sortposts">
1760: <option value="ascdate" />Date order - oldest first
1761: <option value="descdate" />Date order - newest first
1762: <option value="thread" />Threaded
1763: <option value="subject" />By subject
1764: <option value="username" />By domain and username
1765: <option value="lastfirst" />By last name, first name
1766: </select>
1767: </td>
1768: <td> </td>
1769: <td>
1.101 raeburn 1770: <select name="rolefilter" multiple="true" size="5">
1.100 raeburn 1771: <option value="all" />All users
1772: <option value="st" />Students
1773: <option value="cc" />Course Coordinators
1774: <option value="in" />Instructors
1775: <option value="ta" />TAs
1776: <option value="pr" />Exam proctors
1777: <option value="cr" />Custom roles
1778: </select>
1779: </td>
1780: <td> </td>
1781: <td>
1782: <select name="statusfilter">
1783: <option value="all" />Roles of any status
1.101 raeburn 1784: <option value="Active" />Only active roles
1785: <option value="Expired" />Only inactive roles
1.100 raeburn 1786: </select>
1787: </td>
1788: <td> </td>
1789: <td>
1790: <select name="sectionpick" multiple="true" size="$numvisible">
1791: $section_sel
1792: </select>
1793: </td>
1794: <td> </td>
1795: <td><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</td>
1796: </tr>
1797: </table>
1798: <br />
1799: <br />
1800: <input type="hidden" name="previous" value="$previous" />
1801: <input type="hidden" name="applysort" value="$symb" />
1802: <input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
1803: <br />
1804: <br />
1805: </form>
1806: </body>
1807: </html>
1808: END
1809: }
1810:
1.101 raeburn 1811: sub print_showposters {
1812: my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
1.133 albertel 1813:
1.101 raeburn 1814: # backward compatibility (bulletin boards used to be 'wrapped')
1.133 albertel 1815: my $ressymb=&wrap_symb($symb);
1.101 raeburn 1816: my $crs='/'.$ENV{'request.course.id'};
1.102 raeburn 1817: if ($ENV{'request.course.sec'}) {
1818: $crs.='_'.$ENV{'request.course.sec'};
1819: }
1.101 raeburn 1820: $crs=~s/\_/\//g;
1821: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1822: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1823: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1824: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1825: my %namesort = ();
1826: my %postcounts = ();
1827: my %lt=&Apache::lonlocal::texthash(
1828: 'diso' => 'Discussion filtering options',
1829: );
1830: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1831: '','');
1832: if ($contrib{'version'}) {
1833: for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
1834: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1835: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1836: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1837: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
1838: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
1839: my $lastname = $names{'lastname'};
1840: my $firstname = $names{'firstname'};
1841: if ($lastname eq '') {
1842: $lastname = '_';
1843: }
1844: if ($firstname eq '') {
1845: $firstname = '_';
1846: }
1847: unless (defined($namesort{$lastname})) {
1848: %{$namesort{$lastname}} = ();
1849: }
1850: my $poster = $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
1851: $postcounts{$poster} ++;
1852: if (defined($namesort{$lastname}{$firstname})) {
1853: if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
1854: push @{$namesort{$lastname}{$firstname}}, $poster;
1855: }
1856: } else {
1857: @{$namesort{$lastname}{$firstname}} = ("$poster");
1858: }
1859: }
1860: }
1861: }
1862: }
1863: $r->print(<<END);
1864: <html>
1865: <head>
1866: <title>$lt{'diso'}</title>
1867: <meta http-equiv="pragma" content="no-cache" />
1868: </head>
1869: $bodytag
1870: <form name="pickpostersform" method="post">
1871: <table border="0">
1872: <tr>
1873: <td bgcolor="#777777">
1874: <table border="0" cellpadding="3">
1875: <tr bgcolor="#e6ffff">
1876: <td><b>No.</b></td>
1877: <td><b>Select</b></td>
1878: <td><b>Fullname</b><font color="#999999">(Username/domain)</font></td>
1879: <td><b>Posts</td>
1880: </tr>
1881: END
1882: my $count = 0;
1883: foreach my $last (sort keys %namesort) {
1884: foreach my $first (sort keys %{$namesort{$last}}) {
1885: foreach (sort @{$namesort{$last}{$first}}) {
1886: my ($uname,$udom) = split/:/,$_;
1887: if (!$uname || !$udom) {
1888: next;
1889: } else {
1890: $count ++;
1891: $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>');
1892: }
1893: }
1894: }
1895: }
1896: $r->print(<<END);
1897: </table>
1898: </td>
1899: </tr>
1900: </table>
1901: <br />
1902: <input type="hidden" name="sortposts" value="$sortposts" />
1903: <input type="hidden" name="userpick" value="$symb" />
1904: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
1905: </form>
1906: </body>
1907: </html>
1908: END
1909: }
1910:
1.112 raeburn 1911: sub get_post_versions {
1.116 raeburn 1912: my ($versions,$incoming,$htmldecode,$numver) = @_;
1913: if ($incoming =~ /^<version num="0">/) {
1914: my $p = HTML::LCParser->new(\$incoming);
1915: my $done = 0;
1916: while ( (my $token = $p->get_tag("version")) && (!$done)) {
1917: my $num = $token->[1]{num};
1918: my $text = $p->get_text("/version");
1919: if (defined($numver)) {
1920: if ($num == $numver) {
1921: if ($htmldecode) {
1922: $text = &HTML::Entities::decode($text);
1923: }
1924: $$versions{$numver}=$text;
1925: $done = 1;
1926: }
1927: } else {
1928: if ($htmldecode) {
1929: $text = &HTML::Entities::decode($text);
1930: }
1931: $$versions{$num}=$text;
1.112 raeburn 1932: }
1.116 raeburn 1933: }
1934: } else {
1935: if (!defined($numver)) {
1936: $numver = 0;
1937: }
1938: if ($htmldecode) {
1939: $$versions{$numver} = $incoming;
1.112 raeburn 1940: } else {
1.116 raeburn 1941: $$versions{$numver} = &HTML::Entities::encode($incoming,'<>&"');
1.112 raeburn 1942: }
1943: }
1944: return;
1945: }
1946:
1.113 raeburn 1947: sub get_post_attachments {
1948: my ($attachments,$attachmenturls) = @_;
1949: my $num;
1.116 raeburn 1950: if ($attachmenturls =~ m/^<attachment id="0">/) {
1951: my $p = HTML::LCParser->new(\$attachmenturls);
1952: while (my $token = $p->get_tag("attachment","filename","post")) {
1953: if ($token->[0] eq "attachment") {
1954: $num = $token->[1]{id};
1955: %{$$attachments{$num}} =();
1956: } elsif ($token->[0] eq "filename") {
1957: $$attachments{$num}{'filename'} = $p->get_text("/filename");
1958: } elsif ($token->[0] eq "post") {
1959: my $id = $token->[1]{id};
1960: $$attachments{$num}{$id} = $p->get_text("/post");
1961: }
1.113 raeburn 1962: }
1.116 raeburn 1963: } else {
1964: %{$$attachments{'0'}} = ();
1965: $$attachments{'0'}{'filename'} = $attachmenturls;
1966: $$attachments{'0'}{'0'} = 'n';
1.113 raeburn 1967: }
1.116 raeburn 1968:
1.113 raeburn 1969: return;
1970: }
1971:
1972: sub fail_redirect {;
1.6 albertel 1973: my ($r,$feedurl) = @_;
1.70 www 1974: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.6 albertel 1975: $r->print (<<ENDFAILREDIR);
1.72 albertel 1976: <html>
1.5 www 1977: <head><title>Feedback not sent</title>
1.63 albertel 1978: <meta http-equiv="pragma" content="no-cache" />
1979: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5 www 1980: </head>
1981: <body bgcolor="#FFFFFF">
1.63 albertel 1982: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8 www 1983: <b>Sorry, no recipients ...</b>
1.121 albertel 1984: <br /><a href="$feedurl">Continue</a>
1.5 www 1985: </body>
1986: </html>
1987: ENDFAILREDIR
1988: }
1.4 www 1989:
1.6 albertel 1990: sub redirect_back {
1.101 raeburn 1991: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$secpick,$numpicks) = @_;
1.100 raeburn 1992: my $sorttag = '';
1.101 raeburn 1993: my $roletag = '';
1994: my $statustag = '';
1995: my $sectag = '';
1996: my $userpicktag = '';
1997: my $qrystr = '';
1.80 raeburn 1998: my $prevtag = '';
1.133 albertel 1999:
2000: &dewrapper(\$feedurl);
1.70 www 2001: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 2002: if ($previous > 0) {
2003: $qrystr = 'previous='.$previous;
2004: if ($feedurl =~ /\?register=1/) {
2005: $feedurl .= '&'.$qrystr;
2006: } else {
2007: $feedurl .= '?'.$qrystr;
2008: }
2009: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
2010: }
1.100 raeburn 2011: if (defined($sort)) {
2012: my $sortqry = 'sortposts='.$sort;
2013: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
2014: $feedurl .= '&'.$sortqry;
2015: } else {
2016: $feedurl .= '?'.$sortqry;
2017: }
2018: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.101 raeburn 2019: if ( (defined($numpicks)) && ($numpicks > 0) ) {
2020: my $userpickqry = 'totposters='.$numpicks;
2021: $feedurl .= '&'.$userpickqry;
2022: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
2023: } else {
2024: my $roleqry = 'rolefilter='.$rolefilter;
2025: $feedurl .= '&'.$roleqry;
2026: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
2027: $feedurl .= '&statusfilter='.$statusfilter;
2028: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
2029: $feedurl .= '§ionpick='.$secpick;
2030: $sectag = '<input type="hidden" name="sectionpick" value="'.$secpick.'" />';
2031: }
1.100 raeburn 2032: }
1.129 albertel 2033: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.6 albertel 2034: $r->print (<<ENDREDIR);
1.72 albertel 2035: <html>
1.3 www 2036: <head>
2037: <title>Feedback sent</title>
1.63 albertel 2038: <meta http-equiv="pragma" content="no-cache" />
1.80 raeburn 2039: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2 www 2040: </head>
1.49 www 2041: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63 albertel 2042: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5 www 2043: $typestyle
1.32 albertel 2044: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63 albertel 2045: <font color="red">$status</font>
1.49 www 2046: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 2047: $prevtag
1.100 raeburn 2048: $sorttag
1.101 raeburn 2049: $statustag
2050: $roletag
2051: $sectag
2052: $userpicktag
1.49 www 2053: </form>
1.121 albertel 2054: <br /><a href="$feedurl">Continue</a>
1.2 www 2055: </body>
2056: </html>
2057: ENDREDIR
2058: }
1.6 albertel 2059:
2060: sub no_redirect_back {
2061: my ($r,$feedurl) = @_;
1.107 www 2062: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.120 albertel 2063: my $continue=&mt('Continue');
1.6 albertel 2064: $r->print (<<ENDNOREDIR);
1.72 albertel 2065: <html>
1.2 www 2066: <head><title>Feedback not sent</title>
1.63 albertel 2067: <meta http-equiv="pragma" content="no-cache" />
1.7 albertel 2068: ENDNOREDIR
2069:
1.8 www 2070: if ($feedurl!~/^\/adm\/feedback/) {
1.129 albertel 2071: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.
2072: &Apache::lonenc::check_encrypt($feedurl).'">');
1.7 albertel 2073: }
1.129 albertel 2074: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.8 www 2075: $r->print (<<ENDNOREDIRTWO);
1.2 www 2076: </head>
1.49 www 2077: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63 albertel 2078: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.107 www 2079: <b>$nofeed</b>
1.121 albertel 2080: <br /><a href="$feedurl">$continue</a>
1.2 www 2081: </body>
2082: </html>
1.8 www 2083: ENDNOREDIRTWO
1.2 www 2084: }
1.6 albertel 2085:
2086: sub screen_header {
1.65 www 2087: my ($feedurl) = @_;
2088: my $msgoptions='';
2089: my $discussoptions='';
1.102 raeburn 2090: unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
1.65 www 2091: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
2092: $msgoptions=
2093: '<p><input type="checkbox" name="author" /> '.
2094: &mt('Feedback to resource author').'</p>';
2095: }
2096: if (&feedback_available(1)) {
2097: $msgoptions.=
2098: '<br /><input type="checkbox" name="question" /> '.
2099: &mt('Question about resource content');
2100: }
2101: if (&feedback_available(0,1)) {
2102: $msgoptions.=
2103: '<br /><input type="checkbox" name="course" /> '.
2104: &mt('Question/Comment/Feedback about course content');
2105: }
2106: if (&feedback_available(0,0,1)) {
2107: $msgoptions.=
2108: '<br /><input type="checkbox" name="policy" /> '.
2109: &mt('Question/Comment/Feedback about course policy');
2110: }
2111: }
2112: if ($ENV{'request.course.id'}) {
1.92 albertel 2113: if (&discussion_open() &&
1.90 albertel 2114: &Apache::lonnet::allowed('pch',
1.65 www 2115: $ENV{'request.course.id'}.
2116: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74 www 2117: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
2118: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65 www 2119: &mt('Contribution to course discussion of resource');
2120: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
2121: &mt('Anonymous contribution to course discussion of resource').
2122: ' <i>('.&mt('name only visible to course faculty').')</i>';
1.20 www 2123: }
1.65 www 2124: }
1.74 www 2125: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 2126: if ($discussoptions) {
1.74 www 2127: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 2128: return $msgoptions.$discussoptions;
1.6 albertel 2129: }
2130:
2131: sub resource_output {
2132: my ($feedurl) = @_;
1.46 albertel 2133: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 2134: $usersaw=~s/\<body[^\>]*\>//gi;
2135: $usersaw=~s/\<\/body\>//gi;
2136: $usersaw=~s/\<html\>//gi;
2137: $usersaw=~s/\<\/html\>//gi;
2138: $usersaw=~s/\<head\>//gi;
2139: $usersaw=~s/\<\/head\>//gi;
2140: $usersaw=~s/action\s*\=/would_be_action\=/gi;
2141: return $usersaw;
2142: }
2143:
2144: sub clear_out_html {
1.39 www 2145: my ($message,$override)=@_;
1.88 www 2146: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107 www 2147: # Always allow the <m>-tag
2148: my %html=(M=>1);
2149: # Check if more is allowed
1.37 albertel 2150: my $cid=$ENV{'request.course.id'};
1.39 www 2151: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
2152: ($override)) {
1.37 albertel 2153: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 2154: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
2155: # <SUP>
1.107 www 2156: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
2157: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
2158: M=>1, SUB=>1, SUP=>1, SPAN=>1,
2159: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
2160: }
2161: # Do the substitution of everything that is not explicitly allowed
2162: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48 albertel 2163: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.107 www 2164: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48 albertel 2165: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.6 albertel 2166: return $message;
2167: }
2168:
2169: sub assemble_email {
1.40 albertel 2170: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 2171: my $email=<<"ENDEMAIL";
2172: $message
2173: ENDEMAIL
2174: my $citations=<<"ENDCITE";
2175: <h2>Previous attempts of student (if applicable)</h2>
2176: $prevattempts
1.63 albertel 2177: <br /><hr />
1.6 albertel 2178: <h2>Original screen output (if applicable)</h2>
2179: $usersaw
1.40 albertel 2180: <h2>Correct Answer(s) (if applicable)</h2>
2181: $useranswer
1.6 albertel 2182: ENDCITE
2183: return ($email,$citations);
2184: }
2185:
1.35 www 2186: sub secapply {
2187: my $rec=shift;
1.36 www 2188: my $defaultflag=shift;
2189: $rec=~s/\s+//g;
2190: $rec=~s/\@/\:/g;
2191: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
2192: if ($sections) {
2193: foreach (split(/\;/,$sections)) {
2194: if (($_ eq $ENV{'request.course.sec'}) ||
2195: ($defaultflag && ($_ eq '*'))) {
2196: return $adr;
2197: }
2198: }
2199: } else {
2200: return $rec;
2201: }
2202: return '';
1.35 www 2203: }
2204:
1.6 albertel 2205: sub decide_receiver {
1.36 www 2206: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 2207: my $typestyle='';
2208: my %to=();
1.36 www 2209: if ($ENV{'form.author'}||$author) {
1.8 www 2210: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 2211: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
2212: $to{$2.':'.$1}=1;
2213: }
1.36 www 2214: if ($ENV{'form.question'}||$question) {
1.8 www 2215: $typestyle.='Submitting as Question<br>';
1.24 harris41 2216: foreach (split(/\,/,
2217: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
2218: ) {
1.36 www 2219: my $rec=&secapply($_,$defaultflag);
2220: if ($rec) { $to{$rec}=1; }
1.24 harris41 2221: }
1.6 albertel 2222: }
1.36 www 2223: if ($ENV{'form.course'}||$course) {
1.63 albertel 2224: $typestyle.='Submitting as Comment<br />';
1.24 harris41 2225: foreach (split(/\,/,
2226: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
2227: ) {
1.36 www 2228: my $rec=&secapply($_,$defaultflag);
2229: if ($rec) { $to{$rec}=1; }
1.24 harris41 2230: }
1.6 albertel 2231: }
1.36 www 2232: if ($ENV{'form.policy'}||$policy) {
1.63 albertel 2233: $typestyle.='Submitting as Policy Feedback<br />';
1.24 harris41 2234: foreach (split(/\,/,
2235: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
2236: ) {
1.36 www 2237: my $rec=&secapply($_,$defaultflag);
2238: if ($rec) { $to{$rec}=1; }
1.24 harris41 2239: }
1.6 albertel 2240: }
1.36 www 2241: if ((scalar(%to) eq '0') && (!$defaultflag)) {
2242: ($typestyle,%to)=
2243: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
2244: }
1.6 albertel 2245: return ($typestyle,%to);
1.36 www 2246: }
2247:
2248: sub feedback_available {
2249: my ($question,$course,$policy)=@_;
2250: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
2251: return scalar(%to);
1.6 albertel 2252: }
2253:
2254: sub send_msg {
1.43 www 2255: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 2256: my $status='';
2257: my $sendsomething=0;
1.24 harris41 2258: foreach (keys %to) {
1.6 albertel 2259: if ($_) {
1.22 www 2260: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 2261: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43 www 2262: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
2263: $attachmenturl)=~/ok/) {
1.63 albertel 2264: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 2265: } else {
2266: $sendsomething++;
2267: }
2268: }
1.24 harris41 2269: }
1.18 www 2270:
2271: my %record=&Apache::lonnet::restore('_feedback');
2272: my ($temp)=keys %record;
2273: unless ($temp=~/^error\:/) {
2274: my %newrecord=();
2275: $newrecord{'resource'}=$feedurl;
2276: $newrecord{'subnumber'}=$record{'subnumber'}+1;
2277: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63 albertel 2278: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 2279: }
2280: }
2281:
1.6 albertel 2282: return ($status,$sendsomething);
2283: }
2284:
1.13 www 2285: sub adddiscuss {
1.78 raeburn 2286: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 2287: my $status='';
1.122 raeburn 2288: my $realsymb;
2289: if ($symb=~/^bulletin___/) {
2290: my $filename=(&Apache::lonnet::decode_symb($symb))[2];
2291: $filename=~s|^adm/wrapper/||;
2292: $realsymb=&Apache::lonnet::symbread($filename);
2293: }
2294: if (&discussion_open(undef,$realsymb) &&
1.90 albertel 2295: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1.23 www 2296: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20 www 2297:
1.13 www 2298: my %contrib=('message' => $email,
2299: 'sendername' => $ENV{'user.name'},
1.26 www 2300: 'senderdomain' => $ENV{'user.domain'},
2301: 'screenname' => $ENV{'environment.screenname'},
2302: 'plainname' => $ENV{'environment.firstname'}.' '.
2303: $ENV{'environment.middlename'}.' '.
2304: $ENV{'environment.lastname'}.' '.
1.42 www 2305: $ENV{'enrironment.generation'},
1.78 raeburn 2306: 'attachmenturl'=> $attachmenturl,
2307: 'subject' => $subject);
1.65 www 2308: if ($ENV{'form.replydisc'}) {
1.66 www 2309: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65 www 2310: }
1.14 www 2311: if ($anon) {
2312: $contrib{'anonymous'}='true';
2313: }
1.13 www 2314: if (($symb) && ($email)) {
1.102 raeburn 2315: if ($ENV{'form.editdisc'}) {
2316: my %newcontrib = ();
2317: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
2318: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
2319: $contrib{'timestamp'} = time;
2320: $contrib{'history'} = '';
2321: my $numoldver = 0;
2322: my ($oldsymb,$oldidx)=split(/\:\:\:/,$ENV{'form.editdisc'});
1.132 albertel 2323: &Apache::lonenc::check_decrypt(\$oldsymb);
1.110 raeburn 2324: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2325: # get timestamp for last post and history
2326: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
2327: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2328: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2329: if (defined($oldcontrib{$oldidx.':replyto'})) {
2330: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2331: }
2332: if (defined($oldcontrib{$oldidx.':history'})) {
2333: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2334: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2335: $numoldver = @oldversions;
2336: } else {
2337: $numoldver = 1;
2338: }
2339: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2340: }
1.108 raeburn 2341: my $numnewver = $numoldver + 1;
1.102 raeburn 2342: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 raeburn 2343: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
2344: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
2345: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2346: } else {
1.112 raeburn 2347: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2348: }
1.102 raeburn 2349: }
2350: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 raeburn 2351: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
2352: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
2353: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2354: } else {
1.112 raeburn 2355: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2356: }
1.102 raeburn 2357: }
2358: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
2359: foreach (keys %contrib) {
2360: my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;
2361: $newcontrib{$key} = $contrib{$_};
2362: }
2363: my $put_reply = &Apache::lonnet::putstore($ENV{'request.course.id'},
2364: \%newcontrib,
2365: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2366: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2367: $status='Editing class discussion'.($anon?' (anonymous)':'');
2368: } else {
2369: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
2370: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1.13 www 2371: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17 www 2372: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.102 raeburn 2373: }
1.21 www 2374: my %storenewentry=($symb => time);
1.63 albertel 2375: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2376: &Apache::lonnet::put('discussiontimes',\%storenewentry,
2377: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2378: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13 www 2379: }
1.17 www 2380: my %record=&Apache::lonnet::restore('_discussion');
2381: my ($temp)=keys %record;
2382: unless ($temp=~/^error\:/) {
2383: my %newrecord=();
2384: $newrecord{'resource'}=$symb;
2385: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2386: $status.='<br />'.&mt('Registering').': '.
1.21 www 2387: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2388: }
2389: } else {
2390: $status.='Failed.';
1.17 www 2391: }
1.63 albertel 2392: return $status.'<br />';
1.13 www 2393: }
2394:
1.33 www 2395: # ----------------------------------------------------------- Preview function
2396:
2397: sub show_preview {
2398: my $r=shift;
2399: my $message=&clear_out_html($ENV{'form.comment'});
2400: $message=~s/\n/\<br \/\>/g;
1.106 www 2401: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2402: $message=&Apache::lontexconvert::msgtexconverted($message);
1.78 raeburn 2403: my $subject=&clear_out_html($ENV{'form.subject'});
2404: $subject=~s/\n/\<br \/\>/g;
2405: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33 www 2406: $r->print('<table border="2"><tr><td>'.
1.78 raeburn 2407: '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33 www 2408: $message.'</td></tr></table>');
2409: }
2410:
2411: sub generate_preview_button {
1.107 www 2412: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2413: return(<<ENDPREVIEW);
2414: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2415: <input type="hidden" name="subject">
1.33 www 2416: <input type="hidden" name="comment" />
1.65 www 2417: <input type="button" value="$pre"
1.119 albertel 2418: 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 2419: </form>
2420: ENDPREVIEW
2421: }
1.71 www 2422:
1.108 raeburn 2423: sub modify_attachments {
2424: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
1.124 raeburn 2425: my $orig_subject = &Apache::lonnet::unescape($ENV{'form.subject'});
2426: my $subject=&clear_out_html($orig_subject);
1.108 raeburn 2427: $subject=~s/\n/\<br \/\>/g;
2428: $subject=&Apache::lontexconvert::msgtexconverted($subject);
2429: my $timestamp=$ENV{'form.timestamp'};
2430: my $numoldver=$ENV{'form.numoldver'};
2431: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
2432: '','');
2433: my $msg = '';
1.113 raeburn 2434: my %attachments = ();
1.108 raeburn 2435: my %currattach = ();
2436: if ($idx) {
1.113 raeburn 2437: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108 raeburn 2438: }
2439: $r->print(<<END);
2440: <html>
2441: <head>
2442: <title>Managing Attachments</title>
2443: <script>
2444: function setAction () {
2445: document.modattachments.action = document.modattachments.origpage.value;
2446: document.modattachments.submit();
2447: }
2448: </script>
2449: </head>
2450: $bodytag
2451: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2452: <table border="2">
2453: <tr>
2454: <td>
1.124 raeburn 2455: <b>Subject:</b> $subject</b><br /><br />
1.108 raeburn 2456: END
2457: if ($idx) {
2458: if ($attachmenturls) {
2459: my @currold = keys %currattach;
2460: if (@currold > 0) {
2461: $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 2462: foreach my $id (@currold) {
2463: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
2464: $attachurl =~ m#/([^/]+)$#;
2465: $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'<br />'."\n");
1.108 raeburn 2466: }
2467: $r->print("<br />");
2468: }
2469: }
2470: }
2471: if (@{$currnewattach} > 0) {
2472: $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");
2473: foreach (@{$currnewattach}) {
2474: $_ =~ m#/([^/]+)$#;
2475: $r->print('<input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'<br />'."\n");
2476: }
2477: $r->print("<br />");
2478: }
2479: $r->print(<<END);
2480: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2481: </td>
2482: </tr>
2483: </table>
2484: <input type="hidden" name="subject" value="$ENV{'form.subject'}" />
2485: <input type="hidden" name="comment" value="$ENV{'form.comment'}" />
2486: <input type="hidden" name="timestamp" value="$ENV{'form.timestamp'}" />
2487: <input type="hidden" name="idx" value="$ENV{'form.idx'}" />
2488: <input type="hidden" name="numoldver" value="$ENV{'form.numoldver'}" />
2489: <input type="hidden" name="origpage" value="$ENV{'form.origpage'}" />
2490: <input type="hidden" name="anondiscuss" value="$ENV{'form.anondiscuss'}" />
2491: <input type="hidden" name="discuss" value="$ENV{'form.discuss'}" />
2492: END
2493: foreach (@{$currnewattach}) {
2494: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2495: }
2496: foreach (@{$currdelold}) {
2497: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2498: }
2499: $r->print(<<END);
2500: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2501: </form>
2502: </body>
2503: </html>
2504: END
2505: return;
2506: }
2507:
2508: sub process_attachments {
2509: my ($currnewattach,$currdelold,$keepold) = @_;
2510: if (exists($ENV{'form.currnewattach'})) {
2511: if (ref($ENV{'form.currnewattach'}) eq 'ARRAY') {
2512: @{$currnewattach} = @{$ENV{'form.currnewattach'}};
2513: } else {
2514: $$currnewattach[0] = $ENV{'form.currnewattach'};
2515: }
2516: }
2517: if (exists($ENV{'form.deloldattach'})) {
2518: if (ref($ENV{'form.deloldattach'}) eq 'ARRAY') {
2519: @{$currdelold} = @{$ENV{'form.deloldattach'}};
2520: } else {
2521: $$currdelold[0] = $ENV{'form.deloldattach'};
2522: }
2523: }
2524: if (exists($ENV{'form.delnewattach'})) {
2525: my @currdelnew = ();
2526: my @currnew = ();
2527: if (ref($ENV{'form.delnewattach'}) eq 'ARRAY') {
2528: @currdelnew = @{$ENV{'form.delnewattach'}};
2529: } else {
2530: $currdelnew[0] = $ENV{'form.delnewattach'};
2531: }
2532: foreach my $newone (@{$currnewattach}) {
2533: my $delflag = 0;
2534: foreach (@currdelnew) {
2535: if ($newone eq $_) {
2536: $delflag = 1;
2537: last;
2538: }
2539: }
2540: unless ($delflag) {
2541: push @currnew, $newone;
2542: }
2543: }
2544: @{$currnewattach} = @currnew;
2545: }
2546: if (exists($ENV{'form.keepold'})) {
2547: if (ref($ENV{'form.keepold'}) eq 'ARRAY') {
2548: @{$keepold} = @{$ENV{'form.keepold'}};
2549: } else {
2550: $$keepold[0] = $ENV{'form.keepold'};
2551: }
2552: }
2553: }
2554:
2555: sub generate_attachments_button {
2556: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2557: my $origpage = $ENV{'REQUEST_URI'};
2558: my $att=$attachnum.' '.&mt("attachments");
2559: my $response = (<<END);
2560: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2561: Click to add/remove attachments: <input type="button" value="$att"
1.124 raeburn 2562: 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 2563: END
2564: unless ($mode eq 'board') {
2565: $response .= 'javascript:anonchk();';
2566: }
2567: $response .= (<<ENDATTACH);
2568: this.form.submit();" />
2569: <input type="hidden" name="origpage" value="$origpage" />
2570: <input type="hidden" name="idx" value="$idx" />
2571: <input type="hidden" name="timestamp" value="$now" />
2572: <input type="hidden" name="subject" />
2573: <input type="hidden" name="comment" />
2574: <input type="hidden" name="anondiscuss" value = "0";
2575: <input type="hidden" name="discuss" value = "0";
2576: <input type="hidden" name="numoldver" value="$numoldver" />
2577: ENDATTACH
2578: if (defined($deloldattach)) {
2579: if (@{$deloldattach} > 0) {
2580: foreach (@{$deloldattach}) {
2581: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
2582: }
2583: }
2584: }
2585: if (defined($currnewattach)) {
2586: if (@{$currnewattach} > 0) {
2587: foreach (@{$currnewattach}) {
2588: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
2589: }
2590: }
2591: }
2592: $response .= '</form>';
2593: return $response;
2594: }
2595:
2596: sub extract_attachments {
2597: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.116 raeburn 2598: %{$attachments}=();
2599: &get_post_attachments($attachments,$attachmenturls);
2600: foreach my $id (sort keys %{$attachments}) {
2601: if (exists($$attachments{$id}{$numoldver})) {
2602: if (defined($currdelold)) {
2603: if (@{$currdelold} > 0) {
2604: unless (grep/^$id$/,@{$currdelold}) {
2605: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2606: }
1.113 raeburn 2607: } else {
2608: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2609: }
1.116 raeburn 2610: } else {
2611: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2612: }
2613: }
1.116 raeburn 2614: }
2615: my @attached = (sort { $a <=> $b } keys %{$currattach});
2616: if (@attached == 1) {
2617: my $id = $attached[0];
2618: my $attachurl;
2619: if ($attachmenturls =~ m/^<attachment id="0">/) {
2620: $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
2621: } else {
2622: $attachurl = $$attachments{$id}{'filename'};
2623: }
2624: $attachurl=~m|/([^/]+)$|;
2625: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
2626: $1.'</tt></a><br />';
2627: &Apache::lonnet::allowuploaded('/adm/feedback',
2628: $attachurl);
2629: } elsif (@attached > 1) {
2630: $$message.='<ol>';
2631: foreach (@attached) {
2632: my $id = $_;
1.113 raeburn 2633: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.116 raeburn 2634: my ($fname)
2635: =($attachurl=~m|/([^/]+)$|);
2636: $$message .= '<li><a href="'.$attachurl.
2637: '"><tt>'.
2638: $fname.'</tt></a></li>';
1.108 raeburn 2639: &Apache::lonnet::allowuploaded('/adm/feedback',
1.116 raeburn 2640: $attachurl);
1.108 raeburn 2641: }
1.116 raeburn 2642: $$message .= '</ol>';
1.108 raeburn 2643: }
2644: }
2645:
2646: sub construct_attachmenturl {
2647: my ($currnewattach,$keepold,$symb,$idx)=@_;
2648: my $oldattachmenturl;
2649: my $newattachmenturl;
1.113 raeburn 2650: my $startnum = 0;
1.108 raeburn 2651: my $currver = 0;
2652: if (($ENV{'form.editdisc'}) && ($idx)) {
2653: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2654: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2655: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2656: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
2657: if ($contrib{$idx.':history'}) {
2658: if ($contrib{$idx.':history'} =~ /:/) {
2659: my @oldversions = split/:/,$contrib{$idx.':history'};
2660: $currver = 1 + scalar(@oldversions);
2661: } else {
2662: $currver = 2;
2663: }
2664: } else {
2665: $currver = 1;
2666: }
2667: if ($oldattachmenturl) {
1.113 raeburn 2668: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
2669: my %attachments = ();
2670: my $prevver = $currver-1;
2671: &get_post_attachments(\%attachments,$oldattachmenturl);
1.116 raeburn 2672: my $numattach = scalar(keys %attachments);
1.113 raeburn 2673: $startnum += $numattach;
2674: foreach my $num (sort {$a <=> $b} keys %attachments) {
2675: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
1.116 raeburn 2676: foreach $_ (sort {$a <=> $b} keys %{$attachments{$num}}) {
2677: unless ($_ eq 'filename') {
2678: $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
2679: }
1.113 raeburn 2680: }
2681: if (grep/^$num$/,@{$keepold}) {
2682: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108 raeburn 2683: }
1.113 raeburn 2684: $newattachmenturl .= '</attachment>';
1.108 raeburn 2685: }
2686: } else {
1.116 raeburn 2687: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
1.108 raeburn 2688: unless (grep/^0$/,@{$keepold}) {
1.113 raeburn 2689: $newattachmenturl .= '<post id="1">n</post>';
1.108 raeburn 2690: }
1.113 raeburn 2691: $newattachmenturl .= '</attachment>';
1.108 raeburn 2692: $startnum ++;
2693: }
2694: }
2695: }
2696: for (my $i=0; $i<@{$currnewattach}; $i++) {
2697: my $attachnum = $startnum + $i;
1.113 raeburn 2698: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108 raeburn 2699: }
2700: return $newattachmenturl;
2701: }
1.128 raeburn 2702:
2703: sub has_discussion {
2704: my $resourcesref = shift;
2705: my $navmap = Apache::lonnavmaps::navmap->new();
2706: my @allres=$navmap->retrieveResources();
2707: foreach my $resource (@allres) {
2708: if ($resource->hasDiscussion()) {
2709: my $ressymb;
2710: if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
2711: $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
2712: } else {
2713: $ressymb = $resource->symb();
2714: }
2715: push @{$resourcesref}, $ressymb;
2716: }
2717: }
2718: return;
2719: }
1.108 raeburn 2720:
1.6 albertel 2721: sub handler {
2722: my $r = shift;
1.8 www 2723: if ($r->header_only) {
1.71 www 2724: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2725: $r->send_http_header;
2726: return OK;
2727: }
1.15 www 2728:
2729: # --------------------------- Get query string for limited number of parameters
2730:
1.97 raeburn 2731: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.128 raeburn 2732: ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','threadedon','threadedoff','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export']);
1.111 raeburn 2733: if ($ENV{'form.discsymb'}) {
1.133 albertel 2734: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($ENV{'form.discsymb'});
1.111 raeburn 2735: my $readkey = $symb.'_read';
2736: my $chgcount = 0;
1.133 albertel 2737: my %readinghash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$readkey],$ENV{'user.domain'},$ENV{'user.name'});
1.111 raeburn 2738: foreach my $key (keys %ENV) {
2739: if ($key =~ m/^form\.postunread_(\d+)/) {
2740: if ($readinghash{$readkey} =~ /\.$1\./) {
2741: $readinghash{$readkey} =~ s/\.$1\.//;
2742: $chgcount ++;
2743: }
2744: } elsif ($key =~ m/^form\.postread_(\d+)/) {
2745: unless ($readinghash{$readkey} =~ /\.$1\./) {
2746: $readinghash{$readkey} .= '.'.$1.'.';
2747: $chgcount ++;
2748: }
2749: }
2750: }
2751: if ($chgcount > 0) {
1.133 albertel 2752: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',
2753: \%readinghash,$ENV{'user.domain'},$ENV{'user.name'});
1.111 raeburn 2754: }
2755: &Apache::loncommon::content_type($r,'text/html');
2756: $r->send_http_header;
1.133 albertel 2757: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />',
2758: '0','0','',$ENV{'form.previous'},'','','',);
1.111 raeburn 2759: return OK;
2760: }
1.109 raeburn 2761: if ($ENV{'form.allversions'}) {
2762: &Apache::loncommon::content_type($r,'text/html');
2763: $r->send_http_header;
1.133 albertel 2764: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions');
1.109 raeburn 2765: $r->print (<<END);
2766: <html>
2767: <head>
2768: <title>Post Versions</title>
2769: <meta http-equiv="pragma" content="no-cache" />
2770: </head>
2771: $bodytag
2772: END
2773: my $crs='/'.$ENV{'request.course.id'};
2774: if ($ENV{'request.course.sec'}) {
2775: $crs.='_'.$ENV{'request.course.sec'};
2776: }
1.133 albertel 2777: $crs=~s|_|/|g;
1.109 raeburn 2778: my $seeid=&Apache::lonnet::allowed('rin',$crs);
2779: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.allversions'});
1.133 albertel 2780: ($symb)=&get_feedurl_and_clean_symb($symb);
1.109 raeburn 2781: if ($idx > 0) {
1.116 raeburn 2782: my %messages = ();
2783: my %subjects = ();
2784: my %attachmsgs = ();
2785: my %allattachments = ();
2786: my %imsfiles = ();
2787: my ($screenname,$plainname);
1.133 albertel 2788: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2789: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2790: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
2791: $r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname));
1.109 raeburn 2792: }
2793: return OK;
2794: }
1.101 raeburn 2795: if ($ENV{'form.posterlist'}) {
2796: &Apache::loncommon::content_type($r,'text/html');
2797: $r->send_http_header;
1.133 albertel 2798: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($ENV{'form.applysort'});
2799: &print_showposters($r,$symb,$ENV{'form.previous'},$feedurl,
2800: $ENV{'form.sortposts'});
1.101 raeburn 2801: return OK;
2802: }
2803: if ($ENV{'form.userpick'}) {
2804: &Apache::loncommon::content_type($r,'text/html');
2805: $r->send_http_header;
1.133 albertel 2806: my @posters = &Apache::loncommon::get_env_multiple('form.stuinfo');
2807: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($ENV{'form.userpick'});
1.101 raeburn 2808: my $numpicks = @posters;
1.133 albertel 2809: my %discinfo;
2810: $discinfo{$symb.'_userpick'} = join('&',@posters);
2811: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',
2812: \%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2813: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0',
2814: '',$ENV{'form.previous'},$ENV{'form.sortposts'},'','','',
2815: $numpicks);
1.101 raeburn 2816: return OK;
2817: }
1.100 raeburn 2818: if ($ENV{'form.applysort'}) {
2819: &Apache::loncommon::content_type($r,'text/html');
2820: $r->send_http_header;
1.133 albertel 2821: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($ENV{'form.applysort'});
2822: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0',
2823: '',$ENV{'form.previous'},$ENV{'form.sortposts'},
2824: $ENV{'form.rolefilter'},$ENV{'form.statusfilter'},
2825: $ENV{'form.secpick'});
1.100 raeburn 2826: return OK;
2827: } elsif ($ENV{'form.sortfilter'}) {
2828: &Apache::loncommon::content_type($r,'text/html');
2829: $r->send_http_header;
1.133 albertel 2830: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($ENV{'form.sortfilter'});
2831: &print_sortfilter_options($r,$symb,$ENV{'form.previous'},$feedurl);
1.100 raeburn 2832: return OK;
1.128 raeburn 2833: } elsif ($ENV{'form.navtime'}) {
1.99 raeburn 2834: my %discinfo = ();
2835: my @resources = ();
1.128 raeburn 2836: if (defined($ENV{'form.navmaps'})) {
2837: if ($ENV{'form.navmaps'} =~ /:/) {
2838: @resources = split/:/,$ENV{'form.navmaps'};
2839: } else {
2840: @resources = ("$ENV{'form.navmaps'}");
2841: }
1.99 raeburn 2842: } else {
1.128 raeburn 2843: &has_discussion(\@resources);
1.99 raeburn 2844: }
2845: my $numitems = @resources;
2846: my $feedurl = '/adm/navmaps';
1.133 albertel 2847: if ($ENV{'form.navurl'}) { $feedurl .= '?'.$ENV{'form.navurl'}; }
1.99 raeburn 2848: my %lt = &Apache::lonlocal::texthash(
2849: 'mnpa' => 'Marked "New" posts as read in a total of',
1.128 raeburn 2850: 'robb' => 'resources/bulletin boards.',
2851: 'twnp' => 'There are currently no resources or bulletin boards with unread discussion postings.'
1.99 raeburn 2852: );
2853: foreach (@resources) {
2854: # backward compatibility (bulletin boards used to be 'wrapped')
2855: my $ressymb=$_;
1.132 albertel 2856: &Apache::lonenc::check_decrypt(\$ressymb);
1.99 raeburn 2857: if ($ressymb =~ m/bulletin___\d+___/) {
2858: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
2859: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
2860: }
2861: }
2862: my $lastkey = $ressymb.'_lastread';
1.127 albertel 2863: $discinfo{$lastkey} = $ENV{'form.navtime'};
1.99 raeburn 2864: }
1.128 raeburn 2865: my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
2866: if ($numitems > 0) {
1.133 albertel 2867: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',
2868: \%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.128 raeburn 2869: } else {
2870: $textline = "<b>$lt{'twnp'}</b>";
2871: }
1.99 raeburn 2872: &Apache::loncommon::content_type($r,'text/html');
2873: $r->send_http_header;
2874: $r->print (<<ENDREDIR);
2875: <html>
2876: <head>
2877: <title>New posts marked as read</title>
2878: <meta http-equiv="pragma" content="no-cache" />
2879: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
2880: </head>
2881: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
2882: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.128 raeburn 2883: $textline
1.99 raeburn 2884: <form name="reldt" action="$feedurl" target="loncapaclient">
2885: </form>
1.121 albertel 2886: <br /><a href="$feedurl">Continue</a>
1.99 raeburn 2887: </body>
2888: </html>
2889: ENDREDIR
2890: return OK;
2891: } elsif ($ENV{'form.modifydisp'}) {
1.84 raeburn 2892: &Apache::loncommon::content_type($r,'text/html');
2893: $r->send_http_header;
1.133 albertel 2894: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($ENV{'form.modifydisp'});
2895: my ($dispchgA,$dispchgB,$markchg,$toggchg) =
2896: split(/_/,$ENV{'form.changes'});
2897: &print_display_options($r,$symb,$ENV{'form.previous'},$dispchgA,
2898: $dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 2899: return OK;
1.133 albertel 2900: } elsif ($ENV{'form.markondisp'} || $ENV{'form.markonread'} ||
2901: $ENV{'form.allposts'} || $ENV{'form.onlyunread'} ||
2902: $ENV{'form.onlyunmark'} || $ENV{'form.toggoff'} ||
2903: $ENV{'form.toggon'} ) {
1.97 raeburn 2904: &Apache::loncommon::content_type($r,'text/html');
2905: $r->send_http_header;
1.133 albertel 2906: my $feedurl;
1.111 raeburn 2907: if ( ($ENV{'form.toggoff'}) || ($ENV{'form.toggon'}) ) {
1.133 albertel 2908: # ------------------------ Modify setting for read/unread toggle for each post
1.111 raeburn 2909: my $symb=$ENV{'form.toggoff'}?$ENV{'form.toggoff'}:$ENV{'form.toggon'};
1.133 albertel 2910: ($symb,$feedurl)=&get_feedurl_and_clean_symb($symb);
2911: my %discinfo;
2912: $discinfo{$symb.'_readtoggle'}=1;
2913: if ($ENV{'form.toggoff'}) { $discinfo{$symb.'_readtoggle'}=0; }
2914: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',
2915: \%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.111 raeburn 2916: }
1.97 raeburn 2917: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
1.133 albertel 2918: # --------- Modify setting for identification of 'NEW' posts in this discussion
1.97 raeburn 2919: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
1.133 albertel 2920: ($symb,$feedurl)=&get_feedurl_and_clean_symb($symb);
2921: my %discinfo;
2922: my $lastkey = $symb.'_lastread';
2923: my $ondispkey = $symb.'_markondisp';
1.97 raeburn 2924: if ($ENV{'form.markondisp'}) {
2925: $discinfo{$lastkey} = time;
2926: $discinfo{$ondispkey} = 1;
2927: } elsif ($ENV{'form.markonread'}) {
1.133 albertel 2928: if ( $ENV{'form.previous'} > 0 ) {
2929: $discinfo{$lastkey} = $ENV{'form.previous'};
1.97 raeburn 2930: }
2931: $discinfo{$ondispkey} = 0;
2932: }
1.133 albertel 2933: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',
2934: \%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 2935: }
1.133 albertel 2936: if ($ENV{'form.allposts'} || $ENV{'form.onlyunread'} ||
2937: $ENV{'form.onlyunmark'}) {
2938: # --------------------------------- Modify display setting for this discussion
1.111 raeburn 2939: my $symb;
2940: if ($ENV{'form.allposts'}) {
2941: $symb = $ENV{'form.allposts'};
2942: } elsif ($ENV{'form.onlyunread'}) {
2943: $symb = $ENV{'form.onlyunread'};
2944: } else {
2945: $symb = $ENV{'form.onlyunmark'};
2946: }
1.133 albertel 2947: ($symb,$feedurl)=&get_feedurl_and_clean_symb($symb);
2948: my %discinfo;
1.97 raeburn 2949: if ($ENV{'form.allposts'}) {
1.133 albertel 2950: $discinfo{$symb.'_showonlyunread'} = 0;
2951: $discinfo{$symb.'_showonlyunmark'} = 0;
1.97 raeburn 2952: } elsif ($ENV{'form.onlyunread'}) {
1.133 albertel 2953: $discinfo{$symb.'_showonlyunread'} = 1;
1.111 raeburn 2954: } else {
1.133 albertel 2955: $discinfo{$symb.'_showonlyunmark'} = 1;
1.84 raeburn 2956: }
1.133 albertel 2957: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',
2958: \%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 2959: }
1.133 albertel 2960: my $previous=$ENV{'form.previous'};
2961: if ($ENV{'form.markondisp'}) { $previous=undef; }
2962: &redirect_back($r,$feedurl,&mt('Changed display status').'<br />',
2963: '0','0','',$previous);
1.84 raeburn 2964: return OK;
2965: } elsif ($ENV{'form.markread'}) {
1.133 albertel 2966: # ----------------------------------------------------- Mark new posts not NEW
1.84 raeburn 2967: &Apache::loncommon::content_type($r,'text/html');
2968: $r->send_http_header;
1.133 albertel 2969: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($ENV{'form.markread'});
2970: &Apache::lonnet::logthis("\n last read w symb ".$symb);
2971: my %discinfo;
2972: $discinfo{$symb.'_lastread'} = time;
2973: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',
2974: \%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
2975: &redirect_back($r,$feedurl,&mt('Changed reading status').'<br />',
2976: '0','0');
1.78 raeburn 2977: return OK;
2978: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15 www 2979: # ----------------------------------------------------------------- Hide/unhide
1.133 albertel 2980: &Apache::loncommon::content_type($r,'text/html');
2981: $r->send_http_header;
1.15 www 2982:
1.133 albertel 2983: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
2984: my ($symb,$idx)=split(/\:\:\:/,$entry);
2985: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.15 www 2986:
1.133 albertel 2987: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
2988: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
2989: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.15 www 2990:
1.133 albertel 2991: my $currenthidden=$contrib{'hidden'};
2992: my $currentstudenthidden=$contrib{'studenthidden'};
1.15 www 2993:
1.133 albertel 2994: my $crs='/'.$ENV{'request.course.id'};
2995: if ($ENV{'request.course.sec'}) {
2996: $crs.='_'.$ENV{'request.course.sec'};
2997: }
2998: $crs=~s/\_/\//g;
2999: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.102 raeburn 3000:
1.133 albertel 3001: if ($ENV{'form.hide'}) {
3002: $currenthidden.='.'.$idx.'.';
3003: unless ($seeid) {
3004: $currentstudenthidden.='.'.$idx.'.';
3005: }
3006: } else {
3007: $currenthidden=~s/\.$idx\.//g;
3008: }
3009: my %newhash=('hidden' => $currenthidden);
3010: if ( ($ENV{'form.hide'}) && (!$seeid) ) {
3011: $newhash{'studenthidden'} = $currentstudenthidden;
3012: }
1.38 www 3013:
1.133 albertel 3014: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
3015: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3016: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.38 www 3017:
1.133 albertel 3018: &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
3019: '0','0','',$ENV{'form.previous'});
1.69 www 3020: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72 albertel 3021: &Apache::loncommon::content_type($r,'text/html');
3022: $r->send_http_header;
1.133 albertel 3023: my $symb;
1.69 www 3024: if ($ENV{'form.threadedon'}) {
1.133 albertel 3025: $symb=$ENV{'form.threadedon'};
1.69 www 3026: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
3027: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
3028: } else {
1.133 albertel 3029: $symb=$ENV{'form.threadedoff'};
1.69 www 3030: &Apache::lonnet::del('environment',['threadeddiscussion']);
3031: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 3032: }
1.133 albertel 3033: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($symb);
3034: &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'<br />',
3035: '0','0','',$ENV{'form.previous'});
1.38 www 3036: } elsif ($ENV{'form.deldisc'}) {
3037: # --------------------------------------------------------------- Hide for good
1.133 albertel 3038: &Apache::loncommon::content_type($r,'text/html');
3039: $r->send_http_header;
1.15 www 3040:
1.133 albertel 3041: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.deldisc'});
3042: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
3043: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3044: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3045: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3046: my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
1.15 www 3047: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1.133 albertel 3048: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3049: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3050: &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
3051: '0','0','',$ENV{'form.previous'});
1.33 www 3052: } elsif ($ENV{'form.preview'}) {
3053: # -------------------------------------------------------- User wants a preview
1.133 albertel 3054: &Apache::loncommon::content_type($r,'text/html');
1.76 albertel 3055: $r->send_http_header;
1.33 www 3056: &show_preview($r);
1.108 raeburn 3057: } elsif ($ENV{'form.attach'}) {
3058: # -------------------------------------------------------- Work on attachments
3059: &Apache::loncommon::content_type($r,'text/html');
3060: $r->send_http_header;
3061: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
1.133 albertel 3062: my (@currnewattach,@currdelold,@keepold);
1.108 raeburn 3063: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
3064: if (exists($ENV{'form.addnewattach.filename'})) {
3065: unless (length($ENV{'form.addnewattach'})>131072) {
3066: my $subdir = 'feedback/'.$ENV{'form.timestamp'};
3067: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
3068: push @currnewattach, $newattachment;
3069: }
3070: }
1.133 albertel 3071: my $attachmenturls;
3072: my ($symb) = &get_feedurl_and_clean_symb($ENV{'form.attach'});
1.108 raeburn 3073: my $idx = $ENV{'form.idx'};
3074: if ($idx) {
3075: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
3076: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
3077: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
3078: $attachmenturls = $contrib{$idx.':attachmenturl'};
3079: }
1.133 albertel 3080: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
3081: $attachmenturls);
1.134 ! albertel 3082: } elsif ($ENV{'form.chgreads'}) {
! 3083: &Apache::loncommon::content_type($r,'text/html');
! 3084: $r->send_http_header;
! 3085: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ENV{'form.chgreads'});
! 3086: &redirect_back($r,&Apache::lonnet::clutter($url),
! 3087: &mt('Changed read status').'<br />','0','0');
1.116 raeburn 3088: } elsif ($ENV{'form.export'}) {
3089: &Apache::loncommon::content_type($r,'text/html');
3090: $r->send_http_header;
1.133 albertel 3091: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($ENV{'form.export'});
3092: my $mode='board';
1.116 raeburn 3093: my $status='OPEN';
3094: my $previous=$ENV{'form.previous'};
3095: if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library)$/) {
3096: $mode='problem';
3097: $status=$Apache::inputtags::status[-1];
3098: }
3099: my $discussion = &list_discussion($mode,$status,$symb);
3100: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion');
3101: $r->print($bodytag.$discussion);
3102: return OK;
1.15 www 3103: } else {
3104: # ------------------------------------------------------------- Normal feedback
1.133 albertel 3105: my $feedurl=$ENV{'form.postdata'};
3106: $feedurl=~s/^http\:\/\///;
3107: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
3108: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
3109: $feedurl=~s/\?.+$//;
1.8 www 3110:
1.133 albertel 3111: my $symb;
3112: if ($ENV{'form.replydisc'}) {
3113: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
3114: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3115: $feedurl=&Apache::lonnet::clutter($url);
3116: } elsif ($ENV{'form.editdisc'}) {
3117: $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
1.52 www 3118: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.133 albertel 3119: $feedurl=&Apache::lonnet::clutter($url);
3120: } elsif ($ENV{'form.origpage'}) {
3121: $symb="";
3122: } else {
3123: $symb=&Apache::lonnet::symbread($feedurl);
3124: }
3125: unless ($symb) {
3126: $symb=$ENV{'form.symb'};
3127: if ($symb) {
3128: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3129: $feedurl=&Apache::lonnet::clutter($url);
3130: }
3131: }
3132: &Apache::lonenc::check_decrypt(\$symb);
3133: my $goahead=1;
3134: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
3135: unless ($symb) { $goahead=0; }
3136: }
3137: # backward compatibility (bulletin boards used to be 'wrapped')
3138: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3139: $feedurl=~s|^/adm/wrapper||;
3140: }
3141: if (!$goahead) {
3142: # Ambiguous Problem Resource
3143: $r->internal_redirect('/adm/ambiguous');
3144: return OK;
1.31 www 3145: }
1.8 www 3146: # Go ahead with feedback, no ambiguous reference
1.133 albertel 3147: &Apache::loncommon::content_type($r,'text/html');
3148: $r->send_http_header;
1.6 albertel 3149:
1.133 albertel 3150: unless (
3151: (
3152: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
3153: )
3154: ||
3155: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
3156: ||
3157: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
3158: ) {
3159: # Unable to give feedback
3160: &no_redirect_back($r,$feedurl);
3161: }
1.6 albertel 3162: # --------------------------------------------------- Print login screen header
1.133 albertel 3163: unless ($ENV{'form.sendit'}) {
3164: my $options=&screen_header($feedurl);
3165: if ($options) {
3166: &mail_screen($r,$feedurl,$options);
3167: } else {
3168: &fail_redirect($r,$feedurl);
3169: }
3170: return OK;
1.6 albertel 3171: }
3172:
3173: # Get previous user input
1.9 albertel 3174: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.133 albertel 3175: $symb,$ENV{'user.name'},$ENV{'user.domain'},
3176: $ENV{'request.course.id'});
1.6 albertel 3177:
3178: # Get output from resource
3179: my $usersaw=&resource_output($feedurl);
3180:
1.50 albertel 3181: # Get resource answer (need to allow student to view grades for this to work)
3182: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 3183: my $useranswer=&Apache::loncommon::get_student_answers(
1.133 albertel 3184: $symb,$ENV{'user.name'},$ENV{'user.domain'},
3185: $ENV{'request.course.id'});
1.50 albertel 3186: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 3187: # Get attachments, if any, and not too large
3188: my $attachmenturl='';
1.133 albertel 3189: if (($ENV{'form.origpage'}) || ($ENV{'form.editdisc'}) ||
3190: ($ENV{'form.replydisc'})) {
3191: my ($symb,$idx);
3192: if ($ENV{'form.replydisc'}) {
3193: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
3194: } elsif ($ENV{'form.editdisc'}) {
3195: ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
3196: } elsif ($ENV{'form.origpage'}) {
3197: $symb = $ENV{'form.symb'};
3198: }
1.132 albertel 3199: &Apache::lonenc::check_decrypt(\$symb);
1.133 albertel 3200: my @currnewattach = ();
3201: my @deloldattach = ();
3202: my @keepold = ();
3203: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
3204: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
3205: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
1.108 raeburn 3206: } elsif ($ENV{'form.attachment.filename'}) {
1.42 www 3207: unless (length($ENV{'form.attachment'})>131072) {
1.82 albertel 3208: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3209: }
3210: }
1.6 albertel 3211: # Filter HTML out of message (could be nasty)
1.39 www 3212: my $message=&clear_out_html($ENV{'form.comment'});
1.6 albertel 3213:
3214: # Assemble email
1.8 www 3215: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.133 albertel 3216: $usersaw,$useranswer);
1.40 albertel 3217:
1.6 albertel 3218: # Who gets this?
3219: my ($typestyle,%to) = &decide_receiver($feedurl);
3220:
3221: # Actually send mail
1.43 www 3222: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
1.133 albertel 3223: $attachmenturl,%to);
1.13 www 3224:
3225: # Discussion? Store that.
3226:
1.32 albertel 3227: my $numpost=0;
1.133 albertel 3228: if ($ENV{'form.discuss'} || $ENV{'form.anondiscuss'}) {
3229: my $subject = &clear_out_html($ENV{'form.subject'});
3230: my $anonmode=(defined($ENV{'form.anondiscuss'}));
3231: $typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl,
3232: $subject);
1.32 albertel 3233: $numpost++;
1.14 www 3234: }
1.133 albertel 3235:
1.6 albertel 3236: # Receipt screen and redirect back to where came from
1.80 raeburn 3237: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.133 albertel 3238: }
3239: return OK;
3240: }
1.6 albertel 3241:
1.133 albertel 3242: sub wrap_symb {
3243: my ($ressymb)=@_;
3244: if ($ressymb =~ /bulletin___\d+___/) {
3245: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3246: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3247: }
1.6 albertel 3248: }
1.133 albertel 3249: return $ressymb;
3250: }
3251: sub dewrapper {
3252: my ($feedurl)=@_;
3253: if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3254: $$feedurl=~s|^/adm/wrapper||;
3255: }
3256: }
3257:
3258: sub get_feedurl {
3259: my ($symb)=@_;
3260: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3261: my $feedurl = &Apache::lonnet::clutter($url);
3262: &dewrapper(\$feedurl);
3263: return $feedurl;
1.15 www 3264: }
1.1 www 3265:
1.133 albertel 3266: sub get_feedurl_and_clean_symb {
3267: my ($symb)=@_;
3268: &Apache::lonenc::check_decrypt(\$symb);
3269: # backward compatibility (bulletin boards used to be 'wrapped')
3270: unless ($symb =~ m|bulletin___\d+___adm/wrapper|) {
3271: $symb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3272: }
3273: my $feedurl = &get_feedurl($symb);
3274: return ($symb,$feedurl);
3275: }
1.1 www 3276: 1;
3277: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>