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