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