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