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