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