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