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