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