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