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