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