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