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