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