Annotation of loncom/interface/lonfeedback.pm, revision 1.214
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.214 ! albertel 4: # $Id: lonfeedback.pm,v 1.213 2006/07/27 15:48:56 raeburn Exp $
1.19 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.77 www 28: ###
1.7 albertel 29:
1.1 www 30: package Apache::lonfeedback;
31:
32: use strict;
33: use Apache::Constants qw(:common);
1.3 www 34: use Apache::lonmsg();
1.9 albertel 35: use Apache::loncommon();
1.33 www 36: use Apache::lontexconvert();
1.86 www 37: use Apache::lonlocal; # must not have ()
1.157 albertel 38: use Apache::lonnet;
1.86 www 39: use Apache::lonhtmlcommon();
1.128 raeburn 40: use Apache::lonnavmaps;
1.130 albertel 41: use Apache::lonenc();
1.175 www 42: use Apache::lonrss();
1.112 raeburn 43: use HTML::LCParser();
1.106 www 44: use Apache::lonspeller();
1.208 raeburn 45: use Apache::longroup;
1.116 raeburn 46: use Cwd;
1.204 www 47: use 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.148 albertel 755: '<img 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.190 www 759: $discussion.='<a href="/adm/feedback?sendmessageonly=1&symb='.
1.204 www 760: &escape($ressymb).
1.190 www 761: '"><img 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: my $message;
1490: if ($idx > 0) {
1.116 raeburn 1491: my %msgversions = ();
1492: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1493: $message = $msgversions{$numoldver};
1.108 raeburn 1494: }
1.165 albertel 1495: &newline_to_br(\$message);
1.108 raeburn 1496: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.102 raeburn 1497: if ($idx > 0) {
1.116 raeburn 1498: my %subversions = ();
1499: &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
1500: $subject = 'Re: '.$subversions{$numoldver};
1.102 raeburn 1501: }
1.108 raeburn 1502: $subject = &HTML::Entities::encode($subject,'<>&"');
1.102 raeburn 1503: } else {
1.108 raeburn 1504: $attachmenturls = $contrib{$idx.':attachmenturl'};
1.116 raeburn 1505: if ($idx > 0) {
1506: my %msgversions = ();
1507: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1508: $comment = $msgversions{$numoldver};
1509: my %subversions = ();
1510: &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
1511: $subject = $subversions{$numoldver};
1.102 raeburn 1512: }
1513: if (defined($contrib{$idx.':replyto'})) {
1514: $parentmsg = $contrib{$idx.':replyto'};
1515: }
1.157 albertel 1516: unless (exists($env{'form.origpage'})) {
1.203 albertel 1517: my $anonflag = 'nonanon';
1.108 raeburn 1518: if ($contrib{$idx.':anonymous'}) {
1.203 albertel 1519: $anonflag = 'anon';
1.108 raeburn 1520: }
1521: $anonscript = (<<END);
1.102 raeburn 1522: function setposttype () {
1.203 albertel 1523: var currtype = "$anonflag";
1524: for (var i=0; i<document.mailform.discuss.length; i++) {
1525: if (document.mailform.elements.discuss[i].value == currtype ) {
1526: document.mailform.elements.discuss[i].checked=1;
1527: }
1.102 raeburn 1528: }
1529: return
1530: }
1531: END
1.108 raeburn 1532: }
1.79 raeburn 1533: }
1.69 www 1534: }
1.157 albertel 1535: if ($env{'form.previous'}) {
1536: $prevtag = '<input type="hidden" name="previous" value="'.$env{'form.previous'}.'" />';
1.80 raeburn 1537: }
1.69 www 1538: }
1.108 raeburn 1539:
1.157 albertel 1540: if ($env{'form.origpage'}) {
1.204 www 1541: $subject = &unescape($env{'form.subject'});
1542: $comment = &unescape($env{'form.comment'});
1.108 raeburn 1543: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1544: }
1.85 www 1545: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.74 www 1546: my $send=&mt('Send');
1.186 albertel 1547: my $js= <<END;
1.63 albertel 1548: <script type="text/javascript">
1549: //<!--
1.5 www 1550: function gosubmit() {
1551: var rec=0;
1.12 albertel 1552: if (typeof(document.mailform.elements.discuss)!="undefined") {
1.203 albertel 1553: if (typeof(document.mailform.elements.discuss.length) == "undefined") {
1554: if (document.mailform.elements.discuss.checked ) {
1.202 albertel 1555: rec=1;
1556: }
1557: } else {
1.203 albertel 1558: for (var i=0; i<document.mailform.elements.discuss.length; i++) {
1559: if (document.mailform.elements.discuss[i].checked ) {
1.202 albertel 1560: rec=1;
1561: }
1562: }
1563: }
1564: }
1.175 www 1565: if (typeof(document.mailform.elements.blog)!="undefined") {
1.203 albertel 1566: if (document.mailform.elements.blog.checked) {
1.175 www 1567: rec=1;
1568: }
1569: }
1.5 www 1570:
1571: if (rec) {
1.118 albertel 1572: if (typeof(document.mailform.onsubmit)=='function') {
1.105 www 1573: document.mailform.onsubmit();
1574: }
1.5 www 1575: document.mailform.submit();
1576: } else {
1.198 albertel 1577: alert('Please select a feedback type.');
1.5 www 1578: }
1579: }
1.108 raeburn 1580: $anonchk
1.102 raeburn 1581: $anonscript
1.63 albertel 1582: //-->
1.5 www 1583: </script>
1.186 albertel 1584: END
1585:
1.189 albertel 1586: my %onload = ('onload' => 'window.focus();setposttype();');
1.186 albertel 1587: my $start_page=
1588: &Apache::loncommon::start_page('Resource Feedback and Discussion',$js,
1.189 albertel 1589: {'add_entries' => \%onload});
1.186 albertel 1590:
1591: $r->print(<<END);
1592: $start_page
1.51 albertel 1593: <h2><tt>$title</tt></h2>
1.43 www 1594: <form action="/adm/feedback" method="post" name="mailform"
1595: enctype="multipart/form-data">
1.80 raeburn 1596: $prevtag
1.63 albertel 1597: <input type="hidden" name="postdata" value="$feedurl" />
1.102 raeburn 1598: END
1.157 albertel 1599: if ($env{'form.replydisc'}) {
1.102 raeburn 1600: $r->print(<<END);
1.157 albertel 1601: <input type="hidden" name="replydisc" value="$env{'form.replydisc'}" />
1.102 raeburn 1602: END
1.157 albertel 1603: } elsif ($env{'form.editdisc'}) {
1.102 raeburn 1604: $r->print(<<END);
1.157 albertel 1605: <input type="hidden" name="editdisc" value ="$env{'form.editdisc'}" />
1.102 raeburn 1606: <input type="hidden" name="parentmsg" value ="$parentmsg" />
1607: END
1608: }
1.108 raeburn 1609: $r->print(<<END);
1.5 www 1610: Please check at least one of the following feedback types:
1.63 albertel 1611: $options<hr />
1.69 www 1612: $quote
1.63 albertel 1613: <p>My question/comment/feedback:</p>
1614: <p>
1.47 bowersj2 1615: $latexHelp
1.78 raeburn 1616: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
1617: <p>
1.108 raeburn 1618: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$comment
1.63 albertel 1619: </textarea></p>
1620: <p>
1.108 raeburn 1621: END
1.157 albertel 1622: if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
1623: if ($env{'form.origpage'}) {
1.108 raeburn 1624: foreach (@currnewattach) {
1625: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
1626: }
1627: foreach (@currdelold) {
1628: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
1629: }
1630: }
1.157 albertel 1631: if ($env{'form.editdisc'}) {
1.108 raeburn 1632: if ($attachmenturls) {
1.113 raeburn 1633: &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
1.108 raeburn 1634: $attachnum = scalar(keys %currattach);
1635: foreach (keys %currattach) {
1636: $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
1637: }
1638: }
1639: }
1640: } else {
1641: $r->print(<<END);
1.42 www 1642: Attachment (128 KB max size): <input type="file" name="attachment" />
1643: </p>
1.108 raeburn 1644: END
1645: }
1.208 raeburn 1646: if (exists($env{'form.group'})) {
1647: $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
1648: }
1649: if (exists($env{'form.ref'})) {
1650: $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
1651: }
1.108 raeburn 1652: $r->print(<<END);
1.42 www 1653: <p>
1654: <input type="hidden" name="sendit" value="1" />
1.74 www 1655: <input type="button" value="$send" onClick='gosubmit();' />
1.42 www 1656: </p>
1.2 www 1657: </form>
1.108 raeburn 1658: END
1.157 albertel 1659: if ($env{'form.editdisc'} || $env{'form.replydisc'}) {
1.108 raeburn 1660: my $now = time;
1661: my $ressymb = $symb;
1662: my $postidx = '';
1.157 albertel 1663: if ($env{'form.editdisc'}) {
1.108 raeburn 1664: $postidx = $idx;
1665: }
1666: if (@currnewattach > 0) {
1667: $attachnum += @currnewattach;
1668: }
1669: $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver));
1670: if ($attachnum > 0) {
1671: if (@currnewattach > 0) {
1.198 albertel 1672: $newattachmsg .= '<br /><b>New attachments</b><br />';
1.108 raeburn 1673: if (@currnewattach > 1) {
1674: $newattachmsg .= '<ol>';
1675: foreach my $item (@currnewattach) {
1676: $item =~ m#.*/([^/]+)$#;
1677: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
1678: }
1679: $newattachmsg .= '</ol>'."\n";
1680: } else {
1681: $currnewattach[0] =~ m#.*/([^/]+)$#;
1682: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
1683: }
1684: }
1685: if ($attachmsg) {
1.213 raeburn 1686: $r->print("<br /><b>Retained attachments</b>:$attachmsg<br />\n");
1.108 raeburn 1687: }
1688: if ($newattachmsg) {
1689: $r->print("$newattachmsg<br />");
1690: }
1691: }
1692: }
1693: $r->print(&generate_preview_button().
1694: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
1.186 albertel 1695: &Apache::loncommon::end_page());
1696:
1.6 albertel 1697: }
1698:
1.97 raeburn 1699: sub print_display_options {
1.111 raeburn 1700: my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
1.135 albertel 1701: &Apache::loncommon::content_type($r,'text/html');
1702: $r->send_http_header;
1.98 raeburn 1703:
1.97 raeburn 1704: my $function = &Apache::loncommon::get_users_function();
1705: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1.157 albertel 1706: $env{'user.domain'});
1.97 raeburn 1707:
1708: my %lt = &Apache::lonlocal::texthash(
1709: 'pref' => 'Display Preference',
1710: 'curr' => 'Current setting ',
1711: 'actn' => 'Action',
1712: 'deff' => 'Default for all discussions',
1713: 'prca' => 'Preferences can be set for this discussion that determine ....',
1714: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
1.111 raeburn 1715: 'unwh' => 'Under what circumstances posts are identified as "NEW", and',
1716: 'wipa' => 'Whether individual posts can be marked as read/unread',
1.97 raeburn 1717: 'allposts' => 'All posts',
1718: 'unread' => 'New posts only',
1.111 raeburn 1719: 'unmark' => 'Posts not marked read',
1.97 raeburn 1720: 'ondisp' => 'Once displayed',
1.111 raeburn 1721: 'onmark' => 'Once marked not NEW ',
1722: 'toggon' => 'Shown',
1723: 'toggoff' => 'Not shown',
1.97 raeburn 1724: 'disa' => 'Posts displayed?',
1.111 raeburn 1725: 'npmr' => 'New posts cease to be identified as "NEW"?',
1726: 'dotm' => 'Option to mark each post as read/unread?',
1.97 raeburn 1727: 'chgt' => 'Change to ',
1728: 'mkdf' => 'Set to ',
1.111 raeburn 1729: 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
1.97 raeburn 1730: 'ywbr' => 'You will be returned to the previous page if you click OK.'
1731: );
1732:
1.111 raeburn 1733: my $dispchangeA = $lt{'unread'};
1734: my $dispchangeB = $lt{'unmark'};
1.97 raeburn 1735: my $markchange = $lt{'ondisp'};
1.111 raeburn 1736: my $toggchange = $lt{'toggon'};
1.97 raeburn 1737: my $currdisp = $lt{'allposts'};
1738: my $currmark = $lt{'onmark'};
1739: my $discdisp = 'allposts';
1740: my $discmark = 'onmark';
1.111 raeburn 1741: my $currtogg = $lt{'toggoff'};
1742: my $disctogg = 'toggoff';
1.97 raeburn 1743:
1.111 raeburn 1744: if ($dispchgA eq 'allposts') {
1745: $dispchangeA = $lt{'allposts'};
1.97 raeburn 1746: $currdisp = $lt{'unread'};
1747: $discdisp = 'unread';
1748: }
1.111 raeburn 1749:
1.97 raeburn 1750: if ($markchg eq 'markonread') {
1751: $markchange = $lt{'onmark'};
1752: $currmark = $lt{'ondisp'};
1753: $discmark = 'ondisp';
1754: }
1.111 raeburn 1755:
1756: if ($dispchgB eq 'onlyunread') {
1757: $dispchangeB = $lt{'unread'};
1758: $currdisp = $lt{'unmark'};
1759: $discdisp = 'unmark';
1760: }
1761: if ($toggchg eq 'toggoff') {
1762: $toggchange = $lt{'toggoff'};
1763: $currtogg = $lt{'toggon'};
1764: $disctogg = 'toggon';
1765: }
1.187 albertel 1766:
1767: my $js = <<END;
1768: <script type="text/javascript">
1.111 raeburn 1769: function discdispChk(caller) {
1770: var disctogg = '$toggchg'
1771: if (caller == 0) {
1772: if (document.modifydisp.discdisp[0].checked == true) {
1773: if (document.modifydisp.discdisp[1].checked == true) {
1774: document.modifydisp.discdisp[1].checked = false
1775: }
1776: }
1777: }
1778: if (caller == 1) {
1779: if (document.modifydisp.discdisp[1].checked == true) {
1780: if (document.modifydisp.discdisp[0].checked == true) {
1781: document.modifydisp.discdisp[0].checked = false
1782: }
1783: if (disctogg == 'toggon') {
1784: document.modifydisp.disctogg.checked = true
1785: }
1786: if (disctogg == 'toggoff') {
1787: document.modifydisp.disctogg.checked = false
1788: }
1789: }
1790: }
1791: if (caller == 2) {
1792: var dispchgB = '$dispchgB'
1793: if (disctogg == 'toggoff') {
1794: if (document.modifydisp.disctogg.checked == true) {
1795: if (dispchgB == 'onlyunmark') {
1796: document.modifydisp.discdisp[1].checked = false
1797: }
1798: }
1799: }
1800: }
1801: }
1802:
1.97 raeburn 1803: function setDisp() {
1804: var prev = "$previous"
1805: var chktotal = 0
1.111 raeburn 1806: if (document.modifydisp.discdisp[0].checked == true) {
1807: document.modifydisp.$dispchgA.value = "$symb"
1808: chktotal ++
1809: }
1810: if (document.modifydisp.discdisp[1].checked == true) {
1811: document.modifydisp.$dispchgB.value = "$symb"
1.97 raeburn 1812: chktotal ++
1813: }
1814: if (document.modifydisp.discmark.checked == true) {
1815: document.modifydisp.$markchg.value = "$symb"
1816: chktotal ++
1817: }
1.111 raeburn 1818: if (document.modifydisp.disctogg.checked == true) {
1819: document.modifydisp.$toggchg.value = "$symb"
1820: chktotal ++
1821: }
1.97 raeburn 1822: if (chktotal > 0) {
1823: document.modifydisp.submit()
1824: } else {
1825: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
1826: if (prev > 0) {
1827: location.href = "$feedurl?previous=$previous"
1828: } else {
1829: location.href = "$feedurl"
1830: }
1831: }
1832: }
1833: }
1834: </script>
1.187 albertel 1835: END
1836:
1837:
1838: my $start_page =
1839: &Apache::loncommon::start_page('Discussion display options',$js);
1840: my $end_page =
1841: &Apache::loncommon::end_page();
1842: $r->print(<<END);
1.192 albertel 1843: $start_page
1.193 albertel 1844: <form name="modifydisp" method="POST" action="/adm/feedback">
1.111 raeburn 1845: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
1.97 raeburn 1846: <br />
1.195 albertel 1847: END
1848: $r->print(&Apache::loncommon::start_data_table());
1849: $r->print(<<END);
1850: <tr>
1851: <th>$lt{'pref'}</td>
1852: <th>$lt{'curr'}</td>
1853: <th>$lt{'actn'}?</td>
1.97 raeburn 1854: </tr>
1.195 albertel 1855: END
1856: $r->print(&Apache::loncommon::start_data_table_row());
1857: $r->print(<<END);
1.97 raeburn 1858: <td>$lt{'disa'}</td>
1859: <td>$lt{$discdisp}</td>
1.151 albertel 1860: <td><label><input type="checkbox" name="discdisp" onClick="discdispChk('0')" /> $lt{'chgt'} "$dispchangeA"</label>
1.111 raeburn 1861: <br />
1.151 albertel 1862: <label><input type="checkbox" name="discdisp" onClick="discdispChk('1')" /> $lt{'chgt'} "$dispchangeB"</label>
1.111 raeburn 1863: </td>
1.195 albertel 1864: END
1865: $r->print(&Apache::loncommon::end_data_table_row());
1866: $r->print(&Apache::loncommon::start_data_table_row());
1867: $r->print(<<END);
1.97 raeburn 1868: <td>$lt{'npmr'}</td>
1869: <td>$lt{$discmark}</td>
1.151 albertel 1870: <td><label><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</label></td>
1.195 albertel 1871: END
1872: $r->print(&Apache::loncommon::end_data_table_row());
1873: $r->print(&Apache::loncommon::start_data_table_row());
1874: $r->print(<<END);
1.111 raeburn 1875: <td>$lt{'dotm'}</td>
1876: <td>$lt{$disctogg}</td>
1.151 albertel 1877: <td><label><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</label></td>
1.195 albertel 1878: END
1879: $r->print(&Apache::loncommon::end_data_table_row());
1880: $r->print(&Apache::loncommon::end_data_table());
1881: $r->print(<<END);
1.97 raeburn 1882: <br />
1883: <br />
1.137 albertel 1884: <input type="hidden" name="symb" value="$symb" />
1.97 raeburn 1885: <input type="hidden" name="previous" value="$previous" />
1.111 raeburn 1886: <input type="hidden" name="$dispchgA" value=""/>
1887: <input type="hidden" name="$dispchgB" value=""/>
1.97 raeburn 1888: <input type="hidden" name="$markchg" value=""/>
1.111 raeburn 1889: <input type="hidden" name="$toggchg" value="" />
1.97 raeburn 1890: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
1.208 raeburn 1891: END
1892: if (exists($env{'form.group'})) {
1893: $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
1894: }
1895: if (exists($env{'form.ref'})) {
1896: $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
1897: }
1898: $r->print("
1.97 raeburn 1899: <br />
1900: <br />
1901: </form>
1.187 albertel 1902: $end_page
1.208 raeburn 1903: ");
1.97 raeburn 1904: return;
1905: }
1906:
1.100 raeburn 1907: sub print_sortfilter_options {
1908: my ($r,$symb,$previous,$feedurl) = @_;
1.133 albertel 1909:
1.135 albertel 1910: &Apache::loncommon::content_type($r,'text/html');
1911: $r->send_http_header;
1912:
1.139 albertel 1913: &Apache::lonenc::check_encrypt(\$symb);
1.197 albertel 1914: my @sections;
1.100 raeburn 1915: my $section_sel = '';
1916: my $numvisible = 5;
1.208 raeburn 1917: my @groups;
1918: my $group_sel = '';
1919: my $numgroupvis = 5;
1.197 albertel 1920: my %sectioncount = &Apache::loncommon::get_sections();
1.144 raeburn 1921:
1.157 albertel 1922: if ($env{'request.course.sec'} !~ /^\s*$/) { #Restrict section choice to current section
1923: @sections = ('all',$env{'request.course.sec'});
1.144 raeburn 1924: $numvisible = 2;
1.100 raeburn 1925: } else {
1926: @sections = sort {$a cmp $b} keys(%sectioncount);
1.197 albertel 1927: if (scalar(@sections) < 4) {
1928: $numvisible = scalar(@sections) + 1;
1929: }
1.100 raeburn 1930: unshift(@sections,'all'); # Put 'all' at the front of the list
1.197 albertel 1931:
1.100 raeburn 1932: }
1.212 albertel 1933: foreach my $sec (@sections) {
1934: $section_sel .= " <option value=\"$sec\">$sec</option>\n";
1.100 raeburn 1935: }
1.208 raeburn 1936:
1937: if (&check_group_priv() eq 'ok') {
1938: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1939: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1940: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1941: @groups = sort {$a cmp $b} keys(%curr_groups);
1942: if (scalar(@groups) < 4) {
1943: $numgroupvis = scalar(@groups) + 1;
1944: }
1945: unshift(@groups,'all'); # Put 'all' at the front of the list
1946: } else {
1947: my @coursegroups = split(/:/,$env{'request.course.groups'});
1948: if (@coursegroups > 0) {
1949: @coursegroups = sort {$a cmp $b} @coursegroups;
1950: @groups = ('all',@coursegroups);
1951: if (scalar(@groups) < 4) {
1952: $numgroupvis = scalar(@groups) + 1;
1953: }
1954: } else {
1955: @groups = ('all');
1956: $numgroupvis = 1;
1957: }
1958: }
1.212 albertel 1959: foreach my $group (@groups) {
1960: $group_sel .= " <option value=\"$group\">$group</option>\n";
1.208 raeburn 1961: }
1962:
1.100 raeburn 1963: my $function = &Apache::loncommon::get_users_function();
1964: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1.157 albertel 1965: $env{'user.domain'});
1.100 raeburn 1966: my %lt = &Apache::lonlocal::texthash(
1967: 'diop' => 'Display Options',
1968: 'curr' => 'Current setting ',
1969: 'actn' => 'Action',
1.143 raeburn 1970: 'prca' => 'Set options that control the sort order of posts, and/or which posts are displayed.',
1.100 raeburn 1971: 'soor' => 'Sort order',
1.143 raeburn 1972: 'spur' => 'Specific user roles',
1973: 'sprs' => 'Specific role status',
1.100 raeburn 1974: 'spse' => 'Specific sections',
1.208 raeburn 1975: 'spgr' => 'Specific groups',
1.100 raeburn 1976: 'psub' => 'Pick specific users (by name)',
1.101 raeburn 1977: 'shal' => 'Show a list of current posters'
1.100 raeburn 1978: );
1.143 raeburn 1979:
1980: my %sort_types = ();
1981: my %role_types = ();
1982: my %status_types = ();
1983: &sort_filter_names(\%sort_types,\%role_types,\%status_types);
1.187 albertel 1984:
1985: my $js = <<END;
1.144 raeburn 1986: <script type="text/javascript">
1987: function verifyFilter() {
1988: var rolenum = 0
1989: for (var i=0; i<document.modifyshown.rolefilter.length; i++) {
1990: if (document.modifyshown.rolefilter.options[i].selected == true) {
1991: rolenum ++
1992: }
1993: }
1994: if (rolenum == 0) {
1995: document.modifyshown.rolefilter.options[0].selected = true
1996: }
1997:
1998: var secnum = 0
1999: for (var i=0; i<document.modifyshown.sectionpick.length; i++) {
2000: if (document.modifyshown.sectionpick.options[i].selected == true) {
2001: secnum ++
2002: }
2003: }
2004: if (secnum == 0) {
2005: document.modifyshown.sectionpick.options[0].selected = true
2006: }
1.208 raeburn 2007:
2008: var grpnum = 0
2009: for (var i=0; i<document.modifyshown.grouppick.length; i++) {
2010: if (document.modifyshown.grouppick.options[i].selected == true) {
2011: grpnum ++
2012: }
2013: }
2014: if (grpnum == 0) {
2015: document.modifyshown.grouppick.options[0].selected = true
2016: }
2017:
1.144 raeburn 2018: document.modifyshown.submit();
2019: }
2020: </script>
1.187 albertel 2021: END
2022:
2023: my $start_page=
2024: &Apache::loncommon::start_page('Discussion options',$js);
2025: my $end_page=
2026: &Apache::loncommon::end_page();
2027:
2028: $r->print(<<END);
2029: $start_page
2030: <form name="modifyshown" method="POST" action="/adm/feedback">
1.100 raeburn 2031: <b>$lt{'diso'}</b><br/> $lt{'prca'}
2032: <br /><br />
2033: <table border="0">
2034: <tr>
2035: <td><b>$lt{'soor'}</b></td>
2036: <td> </td>
1.143 raeburn 2037: <td><b>$lt{'sprs'}</b></td>
1.100 raeburn 2038: <td> </td>
1.143 raeburn 2039: <td><b>$lt{'spur'}</b></td>
1.100 raeburn 2040: <td> </td>
2041: <td><b>$lt{'spse'}</b></td>
2042: <td> </td>
1.208 raeburn 2043: <td><b>$lt{'spgr'}</b></td>
2044: <td> </td>
1.100 raeburn 2045: <td><b>$lt{'psub'}</b></td>
2046: </tr>
2047: <tr>
1.208 raeburn 2048: <td align="center" valign="top">
1.100 raeburn 2049: <select name="sortposts">
1.212 albertel 2050: <option value="ascdate" selected="selected">$sort_types{'ascdate'}</option>
2051: <option value="descdate">$sort_types{'descdate'}</option>
2052: <option value="thread">$sort_types{'thread'}</option>
2053: <option value="subject">$sort_types{'subject'}</option>
2054: <option value="username">$sort_types{'username'}</option>
2055: <option value="lastfirst">$sort_types{'lastfirst'}</option>
1.100 raeburn 2056: </select>
2057: </td>
2058: <td> </td>
1.208 raeburn 2059: <td align="center" valign="top">
1.143 raeburn 2060: <select name="statusfilter">
1.212 albertel 2061: <option value="all" selected="selected" />$status_types{'all'}</option>
2062: <option value="Active" />$status_types{'Active'}</option>
2063: <option value="Expired" />$status_types{'Expired'}</option>
1.214 ! albertel 2064: <option value="Future" />$status_types{'Future'}</option>
1.100 raeburn 2065: </select>
2066: </td>
2067: <td> </td>
1.208 raeburn 2068: <td align="center" valign="top">
1.143 raeburn 2069: <select name="rolefilter" multiple="true" size="5">
1.212 albertel 2070: <option value="all">$role_types{'all'}</option>
2071: <option value="st">$role_types{'st'}</option>
2072: <option value="cc">$role_types{'cc'}</option>
2073: <option value="in">$role_types{'in'}</option>
2074: <option value="ta">$role_types{'ta'}</option>
2075: <option value="ep">$role_types{'ep'}</option>
2076: <option value="cr">$role_types{'cr'}</option>
1.100 raeburn 2077: </select>
2078: </td>
2079: <td> </td>
1.208 raeburn 2080: <td align="center" valign="top">
1.100 raeburn 2081: <select name="sectionpick" multiple="true" size="$numvisible">
2082: $section_sel
2083: </select>
2084: </td>
2085: <td> </td>
1.208 raeburn 2086: <td align="center" valign="top">
2087: <select name="grouppick" multiple="true" size="$numvisible">
2088: $group_sel
2089: </select>
2090: </td>
2091: <td> </td>
2092: <td valign="top"><label><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</label></td>
1.100 raeburn 2093: </tr>
2094: </table>
2095: <br />
2096: <br />
2097: <input type="hidden" name="previous" value="$previous" />
2098: <input type="hidden" name="applysort" value="$symb" />
1.144 raeburn 2099: <input type="button" name="sub" value="Store Changes" onClick="verifyFilter()" />
1.208 raeburn 2100: END
2101: if (exists($env{'form.group'})) {
2102: $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
2103: }
2104: if (exists($env{'form.ref'})) {
2105: $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
2106: }
2107: $r->print("
1.100 raeburn 2108: <br />
2109: <br />
2110: </form>
1.187 albertel 2111: $end_page
1.208 raeburn 2112: ");
1.100 raeburn 2113: }
2114:
1.101 raeburn 2115: sub print_showposters {
2116: my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
1.133 albertel 2117:
1.154 albertel 2118: &Apache::loncommon::content_type($r,'text/html');
2119: $r->send_http_header;
2120:
1.139 albertel 2121: &Apache::lonenc::check_encrypt(\$symb);
1.157 albertel 2122: my $crs='/'.$env{'request.course.id'};
2123: if ($env{'request.course.sec'}) {
2124: $crs.='_'.$env{'request.course.sec'};
1.102 raeburn 2125: }
1.101 raeburn 2126: $crs=~s/\_/\//g;
1.208 raeburn 2127: my $seeid;
2128: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2129: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2130: my $group = $env{'form.group'};
2131: my $ressymb = &wrap_symb($symb);
2132: if (($group ne '') &&
2133: ($ressymb =~ m|^bulletin___ \d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|)) {
2134: if (&check_group_priv($group,'dgp') eq 'ok') {
2135: $seeid = 1;
2136: }
2137: } else {
2138: $seeid=&Apache::lonnet::allowed('rin',$crs);
2139: }
1.157 albertel 2140: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
1.208 raeburn 2141: $cdom,$cnum);
1.101 raeburn 2142: my %namesort = ();
2143: my %postcounts = ();
1.186 albertel 2144:
1.208 raeburn 2145: my %lt = &Apache::lonlocal::texthash(
2146: sele => 'Select',
2147: full => 'Fullname',
2148: usdo => 'Username/domain',
2149: post => 'Posts',
2150: );
1.101 raeburn 2151: if ($contrib{'version'}) {
2152: for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
2153: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
2154: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
2155: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1.208 raeburn 2156: if ((!$contrib{$idx.':anonymous'}) || (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
1.101 raeburn 2157: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
2158: my $lastname = $names{'lastname'};
2159: my $firstname = $names{'firstname'};
2160: if ($lastname eq '') {
2161: $lastname = '_';
2162: }
2163: if ($firstname eq '') {
2164: $firstname = '_';
2165: }
2166: unless (defined($namesort{$lastname})) {
2167: %{$namesort{$lastname}} = ();
2168: }
2169: my $poster = $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
2170: $postcounts{$poster} ++;
2171: if (defined($namesort{$lastname}{$firstname})) {
2172: if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
2173: push @{$namesort{$lastname}{$firstname}}, $poster;
2174: }
2175: } else {
2176: @{$namesort{$lastname}{$firstname}} = ("$poster");
2177: }
2178: }
2179: }
2180: }
2181: }
1.186 albertel 2182:
2183: my $start_page = &Apache::loncommon::start_page('Discussion options');
1.196 albertel 2184: my $table_start =&Apache::loncommon::start_data_table();
1.101 raeburn 2185: $r->print(<<END);
1.186 albertel 2186: $start_page
1.101 raeburn 2187: <form name="pickpostersform" method="post">
1.196 albertel 2188: <br />
2189: $table_start
2190: <tr>
1.208 raeburn 2191: <th>#</th>
2192: <th>$lt{'sele'}</th>
2193: <th>$lt{'full'} <font color="#999999">($lt{'usdo'})</font></th>
2194: <th>$lt{'post'}</th>
1.101 raeburn 2195: </tr>
2196: END
2197: my $count = 0;
2198: foreach my $last (sort keys %namesort) {
2199: foreach my $first (sort keys %{$namesort{$last}}) {
2200: foreach (sort @{$namesort{$last}{$first}}) {
2201: my ($uname,$udom) = split/:/,$_;
2202: if (!$uname || !$udom) {
2203: next;
2204: } else {
2205: $count ++;
1.196 albertel 2206: $r->print(&Apache::loncommon::start_data_table_row().
2207: '<td align="right">'.$count.'</td>
2208: <td align="center"><label><input name="stuinfo" type="checkbox" value="'.$_.'" /></td>
2209: <td>'.$last.', '.$first.' ('.$uname.','.$udom.')</label></td>
2210: <td>'.$postcounts{$_}.'</td>'.
2211: &Apache::loncommon::end_data_table_row());
1.101 raeburn 2212: }
2213: }
2214: }
2215: }
1.196 albertel 2216: $r->print(&Apache::loncommon::end_data_table());
1.186 albertel 2217: my $end_page = &Apache::loncommon::end_page();
1.101 raeburn 2218: $r->print(<<END);
2219: <br />
2220: <input type="hidden" name="sortposts" value="$sortposts" />
2221: <input type="hidden" name="userpick" value="$symb" />
2222: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
2223: </form>
1.186 albertel 2224: $end_page
1.101 raeburn 2225: END
2226: }
2227:
1.112 raeburn 2228: sub get_post_versions {
1.116 raeburn 2229: my ($versions,$incoming,$htmldecode,$numver) = @_;
2230: if ($incoming =~ /^<version num="0">/) {
2231: my $p = HTML::LCParser->new(\$incoming);
1.186 albertel 2232: my $done = 0;
2233:
1.116 raeburn 2234: while ( (my $token = $p->get_tag("version")) && (!$done)) {
2235: my $num = $token->[1]{num};
2236: my $text = $p->get_text("/version");
2237: if (defined($numver)) {
2238: if ($num == $numver) {
2239: if ($htmldecode) {
2240: $text = &HTML::Entities::decode($text);
2241: }
2242: $$versions{$numver}=$text;
2243: $done = 1;
2244: }
2245: } else {
2246: if ($htmldecode) {
2247: $text = &HTML::Entities::decode($text);
2248: }
2249: $$versions{$num}=$text;
1.112 raeburn 2250: }
1.116 raeburn 2251: }
2252: } else {
2253: if (!defined($numver)) {
2254: $numver = 0;
2255: }
2256: if ($htmldecode) {
2257: $$versions{$numver} = $incoming;
1.112 raeburn 2258: } else {
1.116 raeburn 2259: $$versions{$numver} = &HTML::Entities::encode($incoming,'<>&"');
1.112 raeburn 2260: }
2261: }
2262: return;
2263: }
2264:
1.113 raeburn 2265: sub get_post_attachments {
2266: my ($attachments,$attachmenturls) = @_;
2267: my $num;
1.116 raeburn 2268: if ($attachmenturls =~ m/^<attachment id="0">/) {
2269: my $p = HTML::LCParser->new(\$attachmenturls);
2270: while (my $token = $p->get_tag("attachment","filename","post")) {
2271: if ($token->[0] eq "attachment") {
2272: $num = $token->[1]{id};
2273: %{$$attachments{$num}} =();
2274: } elsif ($token->[0] eq "filename") {
2275: $$attachments{$num}{'filename'} = $p->get_text("/filename");
2276: } elsif ($token->[0] eq "post") {
2277: my $id = $token->[1]{id};
2278: $$attachments{$num}{$id} = $p->get_text("/post");
2279: }
1.113 raeburn 2280: }
1.116 raeburn 2281: } else {
2282: %{$$attachments{'0'}} = ();
2283: $$attachments{'0'}{'filename'} = $attachmenturls;
2284: $$attachments{'0'}{'0'} = 'n';
1.113 raeburn 2285: }
1.116 raeburn 2286:
1.113 raeburn 2287: return;
2288: }
2289:
1.150 albertel 2290: sub fail_redirect {
1.6 albertel 2291: my ($r,$feedurl) = @_;
1.70 www 2292: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.150 albertel 2293: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.186 albertel 2294: $r->print(&Apache::loncommon::start_page('Feedback not sent',undef,
2295: {'redirect' => [2,$feedurl],
2296: 'only_body' => 1,}));
2297: $r->print(<<ENDFAILREDIR);
1.150 albertel 2298: <img align="right" src="$logo" />
1.8 www 2299: <b>Sorry, no recipients ...</b>
1.5 www 2300: ENDFAILREDIR
1.186 albertel 2301: $r->print(&Apache::loncommon::end_page());
1.5 www 2302: }
1.4 www 2303:
1.6 albertel 2304: sub redirect_back {
1.208 raeburn 2305: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group) = @_;
1.100 raeburn 2306: my $sorttag = '';
1.101 raeburn 2307: my $roletag = '';
2308: my $statustag = '';
2309: my $sectag = '';
1.208 raeburn 2310: my $grptag = '';
1.101 raeburn 2311: my $userpicktag = '';
2312: my $qrystr = '';
1.80 raeburn 2313: my $prevtag = '';
1.133 albertel 2314:
1.135 albertel 2315: &Apache::loncommon::content_type($r,'text/html');
2316: $r->send_http_header;
1.133 albertel 2317: &dewrapper(\$feedurl);
1.70 www 2318: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 2319: if ($previous > 0) {
2320: $qrystr = 'previous='.$previous;
2321: if ($feedurl =~ /\?register=1/) {
2322: $feedurl .= '&'.$qrystr;
2323: } else {
2324: $feedurl .= '?'.$qrystr;
2325: }
2326: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
2327: }
1.100 raeburn 2328: if (defined($sort)) {
2329: my $sortqry = 'sortposts='.$sort;
2330: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
2331: $feedurl .= '&'.$sortqry;
2332: } else {
2333: $feedurl .= '?'.$sortqry;
2334: }
2335: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.143 raeburn 2336: if (defined($numpicks)) {
1.101 raeburn 2337: my $userpickqry = 'totposters='.$numpicks;
2338: $feedurl .= '&'.$userpickqry;
2339: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
2340: } else {
1.143 raeburn 2341: if (ref($sectionpick) eq 'ARRAY') {
2342: $feedurl .= '§ionpick=';
2343: $sectag .= '<input type="hidden" name="sectionpick" value="';
2344: foreach (@{$sectionpick}) {
2345: $feedurl .= $_.',';
2346: $sectag .= $_.',';
2347: }
2348: $feedurl =~ s/,$//;
2349: $sectag =~ s/,$//;
2350: $sectag .= '" />';
2351: } else {
2352: $feedurl .= '§ionpick='.$sectionpick;
2353: $sectag = '<input type="hidden" name="sectionpick" value="'.$sectionpick.'" />';
2354: }
1.208 raeburn 2355: if (ref($grouppick) eq 'ARRAY') {
2356: $feedurl .= '&grouppick=';
2357: $sectag .= '<input type="hidden" name="grouppick" value="';
2358: foreach my $grp (@{$grouppick}) {
2359: $feedurl .= $grp.',';
2360: $grptag .= $grp.',';
2361: }
2362: $feedurl =~ s/,$//;
2363: $grptag =~ s/,$//;
2364: $grptag .= '" />';
2365: } else {
2366: $feedurl .= '&grouppick='.$grouppick;
2367: $grptag = '<input type="hidden" name="grouppick" value="'.$grouppick.'" />';
2368: }
1.143 raeburn 2369: if (ref($rolefilter) eq 'ARRAY') {
2370: $feedurl .= '&rolefilter=';
2371: $roletag .= '<input type="hidden" name="rolefilter" value="';
2372: foreach (@{$rolefilter}) {
2373: $feedurl .= $_.',';
2374: $roletag .= $_.',';
2375: }
2376: $feedurl =~ s/,$//;
2377: $roletag =~ s/,$//;
2378: $roletag .= '" />';
2379: } else {
2380: $feedurl .= '&rolefilter='.$rolefilter;
2381: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
2382: }
1.101 raeburn 2383: $feedurl .= '&statusfilter='.$statusfilter;
2384: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
2385: }
1.100 raeburn 2386: }
1.208 raeburn 2387: my $grouptag;
2388: if ($group ne '') {
2389: $grouptag = '<input type="hidden" name="group" value="'.$group.'" />'; my $refarg;
2390: if (exists($env{'form.ref'})) {
2391: $refarg = '&ref='.$env{'form.ref'};
2392: $grouptag .= '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />';
2393: }
2394: if ($feedurl =~ /\?/) {
2395: $feedurl .= '&group='.$group.$refarg;
2396: } else {
2397: $feedurl .= '?group='.$group.$refarg;
2398: }
2399: }
1.129 albertel 2400: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.150 albertel 2401: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.200 albertel 2402: my %onload;
2403: if ($env{'environment.remote'} ne 'off') {
2404: $onload{'onload'} =
2405: "if (window.name!='loncapaclient') { this.document.reldt.submit(); self.window.close(); }";
2406: }
1.186 albertel 2407: my $start_page=
1.207 albertel 2408: &Apache::loncommon::start_page('Feedback sent',undef,
1.208 raeburn 2409: {'redirect' => [0,$feedurl],
1.186 albertel 2410: 'only_body' => 1,
1.189 albertel 2411: 'add_entries' => \%onload});
1.186 albertel 2412: my $end_page = &Apache::loncommon::end_page();
2413: $r->print(<<ENDREDIR);
2414: $start_page
1.150 albertel 2415: <img align="right" src="$logo" />
1.5 www 2416: $typestyle
1.32 albertel 2417: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.175 www 2418: $blog
1.63 albertel 2419: <font color="red">$status</font>
1.49 www 2420: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 2421: $prevtag
1.100 raeburn 2422: $sorttag
1.101 raeburn 2423: $statustag
2424: $roletag
2425: $sectag
1.208 raeburn 2426: $grptag
1.101 raeburn 2427: $userpicktag
1.208 raeburn 2428: $grouptag
1.49 www 2429: </form>
1.186 albertel 2430: $end_page
1.2 www 2431: ENDREDIR
2432: }
1.6 albertel 2433:
2434: sub no_redirect_back {
2435: my ($r,$feedurl) = @_;
1.107 www 2436: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.187 albertel 2437:
1.200 albertel 2438: my %onload;
2439: if ($env{'environment.remote'} ne 'off') {
2440: $onload{'onload'} =
2441: "if (window.name!='loncapaclient') { self.window.close(); }";
2442: }
2443:
1.187 albertel 2444: my %body_options = ('only_body' => 1,
1.191 albertel 2445: 'bgcolor' => '#FFFFFF',
1.200 albertel 2446: 'add_entries' => \%onload,);
1.187 albertel 2447:
2448: if ($feedurl !~ m{^/adm/feedback}) {
2449: $body_options{'rediect'} = [2,$feedurl];
1.7 albertel 2450: }
1.187 albertel 2451: my $start_page=
2452: &Apache::loncommon::start_page('Feedback not sent',undef,
2453: \%body_options);
2454:
2455: my $end_page = &Apache::loncommon::end_page();
2456:
1.129 albertel 2457: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.150 albertel 2458: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.8 www 2459: $r->print (<<ENDNOREDIRTWO);
1.191 albertel 2460: $start_page
1.150 albertel 2461: <img align="right" src="$logo" />
1.107 www 2462: <b>$nofeed</b>
1.187 albertel 2463: <br />
2464: $end_page
1.8 www 2465: ENDNOREDIRTWO
1.2 www 2466: }
1.6 albertel 2467:
2468: sub screen_header {
1.141 raeburn 2469: my ($feedurl,$symb) = @_;
1.65 www 2470: my $msgoptions='';
2471: my $discussoptions='';
1.157 albertel 2472: unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
1.167 www 2473: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
1.65 www 2474: $msgoptions=
1.202 albertel 2475: '<p><label><input type="radio" name="discuss" value="author" /> '.
1.151 albertel 2476: &mt('Feedback to resource author').'</label></p>';
1.65 www 2477: }
2478: if (&feedback_available(1)) {
2479: $msgoptions.=
1.202 albertel 2480: '<p><label><input type="radio" name="discuss" value="question" /> '.
1.151 albertel 2481: &mt('Question about resource content').'</label></p>';
1.65 www 2482: }
2483: if (&feedback_available(0,1)) {
2484: $msgoptions.=
1.202 albertel 2485: '<p><label><input type="radio" name="discuss" value="course" /> '.
1.151 albertel 2486: &mt('Question/Comment/Feedback about course content').
2487: '</label></p>';
1.65 www 2488: }
2489: if (&feedback_available(0,0,1)) {
2490: $msgoptions.=
1.202 albertel 2491: '<p><label><input type="radio" name="discuss" value="policy" /> '.
1.151 albertel 2492: &mt('Question/Comment/Feedback about course policy').
2493: '</label></p>';
1.65 www 2494: }
2495: }
1.190 www 2496: if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
1.141 raeburn 2497: if (&discussion_open(undef,$symb) &&
1.90 albertel 2498: &Apache::lonnet::allowed('pch',
1.157 albertel 2499: $env{'request.course.id'}.
2500: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.198 albertel 2501: $discussoptions='<label><input type="radio" name="discuss" value="nonanon" checked="checked" /> '.
1.65 www 2502: &mt('Contribution to course discussion of resource');
1.198 albertel 2503: $discussoptions.='</label><br /><label><input type="radio" name="discuss" value="anon" /> '.
1.65 www 2504: &mt('Anonymous contribution to course discussion of resource').
1.173 www 2505: ' <i>('.&mt('name only visible to course faculty').')</i></label> '.
2506: '<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';
1.141 raeburn 2507: }
1.185 www 2508: $discussoptions.='<br /><label><input type="checkbox" name="blog" /> '.
2509: &mt('Add to my public course blog').'</label>';
1.65 www 2510: }
1.149 albertel 2511: if ($msgoptions) { $msgoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 2512: if ($discussoptions) {
1.149 albertel 2513: $discussoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 2514: return $msgoptions.$discussoptions;
1.6 albertel 2515: }
2516:
2517: sub resource_output {
2518: my ($feedurl) = @_;
1.46 albertel 2519: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 2520: $usersaw=~s/\<body[^\>]*\>//gi;
2521: $usersaw=~s/\<\/body\>//gi;
2522: $usersaw=~s/\<html\>//gi;
2523: $usersaw=~s/\<\/html\>//gi;
2524: $usersaw=~s/\<head\>//gi;
2525: $usersaw=~s/\<\/head\>//gi;
2526: $usersaw=~s/action\s*\=/would_be_action\=/gi;
2527: return $usersaw;
2528: }
2529:
2530: sub clear_out_html {
1.194 albertel 2531: my ($message,$override,$ignore_htmlarea)=@_;
2532: if (!$ignore_htmlarea
2533: && !&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107 www 2534: # Always allow the <m>-tag
2535: my %html=(M=>1);
2536: # Check if more is allowed
1.157 albertel 2537: my $cid=$env{'request.course.id'};
2538: if (($env{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
1.39 www 2539: ($override)) {
1.37 albertel 2540: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 2541: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
2542: # <SUP>
1.107 www 2543: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
2544: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
1.155 albertel 2545: M=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1,
1.107 www 2546: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
2547: }
2548: # Do the substitution of everything that is not explicitly allowed
1.194 albertel 2549: $message =~ s/\<(\/?\s*(\w*)[^\>\<]*)/
1.48 albertel 2550: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.194 albertel 2551: $message =~ s/(\<?\s*(\w*)[^\<\>]*)\>/
1.48 albertel 2552: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.6 albertel 2553: return $message;
2554: }
2555:
2556: sub assemble_email {
1.40 albertel 2557: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 2558: my $email=<<"ENDEMAIL";
2559: $message
2560: ENDEMAIL
2561: my $citations=<<"ENDCITE";
2562: <h2>Previous attempts of student (if applicable)</h2>
2563: $prevattempts
1.63 albertel 2564: <br /><hr />
1.6 albertel 2565: <h2>Original screen output (if applicable)</h2>
2566: $usersaw
1.40 albertel 2567: <h2>Correct Answer(s) (if applicable)</h2>
2568: $useranswer
1.6 albertel 2569: ENDCITE
2570: return ($email,$citations);
2571: }
2572:
1.35 www 2573: sub secapply {
2574: my $rec=shift;
1.36 www 2575: my $defaultflag=shift;
2576: $rec=~s/\s+//g;
2577: $rec=~s/\@/\:/g;
2578: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
2579: if ($sections) {
2580: foreach (split(/\;/,$sections)) {
1.157 albertel 2581: if (($_ eq $env{'request.course.sec'}) ||
1.36 www 2582: ($defaultflag && ($_ eq '*'))) {
2583: return $adr;
2584: }
2585: }
2586: } else {
2587: return $rec;
2588: }
2589: return '';
1.35 www 2590: }
2591:
1.163 albertel 2592: =pod
2593:
2594: =over 4
2595:
2596: =item *
2597:
2598: decide_receiver($feedurl,$author,$question,$course,$policy,$defaultflag);
2599:
2600: Arguments
2601: $feedurl - /res/ url of resource (only need if $author is true)
2602: $author,$question,$course,$policy - all true/false parameters
2603: if true will attempt to find the addresses of user that should receive
2604: this type of feedback (author - feedback to author of resource $feedurl,
2605: $question 'Resource Content Questions', $course 'Course Content Question',
2606: $policy 'Course Policy')
2607: (Additionally it also checks $env for whether the corresponding form.<name>
2608: element exists, for ease of use in a html response context)
2609:
2610: $defaultflag - (internal should be left blank) if true gather addresses
2611: that aren't for a section even if I have a section
2612: (used for reccursion internally, first we look for
2613: addresses for our specific section then we recurse
2614: and look for non section addresses)
2615:
2616: Returns
2617: $typestyle - string of html text, describing what addresses were found
2618: %to - a hash, which keys are addresses of users to send messages to
2619: the keys will look like name:domain
2620:
2621: =cut
2622:
1.6 albertel 2623: sub decide_receiver {
1.36 www 2624: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 2625: my $typestyle='';
2626: my %to=();
1.202 albertel 2627: if ($env{'form.discuss'} eq 'author' ||$author) {
1.163 albertel 2628: $typestyle.='Submitting as Author Feedback<br />';
1.6 albertel 2629: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
2630: $to{$2.':'.$1}=1;
2631: }
1.202 albertel 2632: if ($env{'form.discuss'} eq 'question' ||$question) {
2633: $typestyle.=&mt('Submitting as Question').'<br />';
1.24 harris41 2634: foreach (split(/\,/,
1.157 albertel 2635: $env{'course.'.$env{'request.course.id'}.'.question.email'})
1.24 harris41 2636: ) {
1.36 www 2637: my $rec=&secapply($_,$defaultflag);
2638: if ($rec) { $to{$rec}=1; }
1.24 harris41 2639: }
1.6 albertel 2640: }
1.202 albertel 2641: if ($env{'form.discuss'} eq 'course' ||$course) {
2642: $typestyle.=&mt('Submitting as Comment').'<br />';
1.24 harris41 2643: foreach (split(/\,/,
1.157 albertel 2644: $env{'course.'.$env{'request.course.id'}.'.comment.email'})
1.24 harris41 2645: ) {
1.36 www 2646: my $rec=&secapply($_,$defaultflag);
2647: if ($rec) { $to{$rec}=1; }
1.24 harris41 2648: }
1.6 albertel 2649: }
1.202 albertel 2650: if ($env{'form.discuss'} eq 'policy' ||$policy) {
2651: $typestyle.=&mt('Submitting as Policy Feedback').'<br />';
1.24 harris41 2652: foreach (split(/\,/,
1.157 albertel 2653: $env{'course.'.$env{'request.course.id'}.'.policy.email'})
1.24 harris41 2654: ) {
1.36 www 2655: my $rec=&secapply($_,$defaultflag);
2656: if ($rec) { $to{$rec}=1; }
1.24 harris41 2657: }
1.6 albertel 2658: }
1.36 www 2659: if ((scalar(%to) eq '0') && (!$defaultflag)) {
2660: ($typestyle,%to)=
2661: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
2662: }
1.6 albertel 2663: return ($typestyle,%to);
1.36 www 2664: }
2665:
2666: sub feedback_available {
2667: my ($question,$course,$policy)=@_;
2668: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
2669: return scalar(%to);
1.6 albertel 2670: }
2671:
2672: sub send_msg {
1.181 www 2673: my ($title,$feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 2674: my $status='';
2675: my $sendsomething=0;
1.181 www 2676: if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }
2677: unless ($title=~/\w/) { $title=&mt('Feedback'); }
1.24 harris41 2678: foreach (keys %to) {
1.6 albertel 2679: if ($_) {
1.22 www 2680: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 2681: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.181 www 2682: $title.' ['.$declutter.']',$email,$citations,$feedurl,
1.43 www 2683: $attachmenturl)=~/ok/) {
1.63 albertel 2684: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 2685: } else {
2686: $sendsomething++;
2687: }
2688: }
1.24 harris41 2689: }
1.18 www 2690:
2691: my %record=&Apache::lonnet::restore('_feedback');
2692: my ($temp)=keys %record;
2693: unless ($temp=~/^error\:/) {
2694: my %newrecord=();
2695: $newrecord{'resource'}=$feedurl;
2696: $newrecord{'subnumber'}=$record{'subnumber'}+1;
2697: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63 albertel 2698: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 2699: }
2700: }
2701:
1.6 albertel 2702: return ($status,$sendsomething);
2703: }
2704:
1.13 www 2705: sub adddiscuss {
1.78 raeburn 2706: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 2707: my $status='';
1.122 raeburn 2708: my $realsymb;
2709: if ($symb=~/^bulletin___/) {
2710: my $filename=(&Apache::lonnet::decode_symb($symb))[2];
2711: $filename=~s|^adm/wrapper/||;
2712: $realsymb=&Apache::lonnet::symbread($filename);
2713: }
2714: if (&discussion_open(undef,$realsymb) &&
1.157 albertel 2715: &Apache::lonnet::allowed('pch',$env{'request.course.id'}.
2716: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.20 www 2717:
1.13 www 2718: my %contrib=('message' => $email,
1.157 albertel 2719: 'sendername' => $env{'user.name'},
2720: 'senderdomain' => $env{'user.domain'},
2721: 'screenname' => $env{'environment.screenname'},
2722: 'plainname' => $env{'environment.firstname'}.' '.
2723: $env{'environment.middlename'}.' '.
2724: $env{'environment.lastname'}.' '.
2725: $env{'enrironment.generation'},
1.78 raeburn 2726: 'attachmenturl'=> $attachmenturl,
2727: 'subject' => $subject);
1.157 albertel 2728: if ($env{'form.replydisc'}) {
2729: $contrib{'replyto'}=(split(/\:\:\:/,$env{'form.replydisc'}))[1];
1.65 www 2730: }
1.14 www 2731: if ($anon) {
2732: $contrib{'anonymous'}='true';
2733: }
1.13 www 2734: if (($symb) && ($email)) {
1.157 albertel 2735: if ($env{'form.editdisc'}) {
1.102 raeburn 2736: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
2737: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
2738: $contrib{'timestamp'} = time;
2739: $contrib{'history'} = '';
2740: my $numoldver = 0;
1.157 albertel 2741: my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});
1.132 albertel 2742: &Apache::lonenc::check_decrypt(\$oldsymb);
1.110 raeburn 2743: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2744: # get timestamp for last post and history
1.157 albertel 2745: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$env{'request.course.id'},
2746: $env{'course.'.$env{'request.course.id'}.'.domain'},
2747: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2748: if (defined($oldcontrib{$oldidx.':replyto'})) {
2749: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2750: }
2751: if (defined($oldcontrib{$oldidx.':history'})) {
2752: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2753: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2754: $numoldver = @oldversions;
2755: } else {
2756: $numoldver = 1;
2757: }
2758: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2759: }
1.108 raeburn 2760: my $numnewver = $numoldver + 1;
1.102 raeburn 2761: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 raeburn 2762: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
2763: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
2764: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2765: } else {
1.112 raeburn 2766: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2767: }
1.102 raeburn 2768: }
2769: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 raeburn 2770: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
2771: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
2772: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2773: } else {
1.112 raeburn 2774: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2775: }
1.102 raeburn 2776: }
2777: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
1.157 albertel 2778: my $put_reply = &Apache::lonnet::putstore($env{'request.course.id'},
1.182 albertel 2779: $oldsymb,$oldidx,\%contrib,
1.157 albertel 2780: $env{'course.'.$env{'request.course.id'}.'.domain'},
2781: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2782: $status='Editing class discussion'.($anon?' (anonymous)':'');
2783: } else {
2784: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.157 albertel 2785: &Apache::lonnet::store(\%contrib,$symb,$env{'request.course.id'},
2786: $env{'course.'.$env{'request.course.id'}.'.domain'},
2787: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2788: }
1.21 www 2789: my %storenewentry=($symb => time);
1.63 albertel 2790: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2791: &Apache::lonnet::put('discussiontimes',\%storenewentry,
1.157 albertel 2792: $env{'course.'.$env{'request.course.id'}.'.domain'},
2793: $env{'course.'.$env{'request.course.id'}.'.num'});
1.13 www 2794: }
1.17 www 2795: my %record=&Apache::lonnet::restore('_discussion');
2796: my ($temp)=keys %record;
2797: unless ($temp=~/^error\:/) {
2798: my %newrecord=();
2799: $newrecord{'resource'}=$symb;
2800: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2801: $status.='<br />'.&mt('Registering').': '.
1.21 www 2802: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2803: }
2804: } else {
2805: $status.='Failed.';
1.17 www 2806: }
1.63 albertel 2807: return $status.'<br />';
1.13 www 2808: }
2809:
1.33 www 2810: # ----------------------------------------------------------- Preview function
2811:
2812: sub show_preview {
1.187 albertel 2813: my ($r) = @_;
1.135 albertel 2814: &Apache::loncommon::content_type($r,'text/html');
2815: $r->send_http_header;
1.157 albertel 2816: my $message=&clear_out_html($env{'form.comment'});
1.165 albertel 2817: &newline_to_br(\$message);
1.106 www 2818: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2819: $message=&Apache::lontexconvert::msgtexconverted($message);
1.194 albertel 2820: my $subject=&clear_out_html($env{'form.subject'},undef,1);
1.78 raeburn 2821: $subject=~s/\n/\<br \/\>/g;
2822: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.187 albertel 2823: my $start_page=
2824: &Apache::loncommon::start_page('Preview',undef,
2825: {'only_body' => 1,});
2826:
2827: my $end_page = &Apache::loncommon::end_page();
2828:
2829: $r->print($start_page.'<table border="2"><tr><td>'.
1.153 albertel 2830: '<b>Subject:</b> '.$subject.'<br /><br />'.
1.187 albertel 2831: $message.'</td></tr></table>'.$end_page);
1.33 www 2832: }
2833:
1.165 albertel 2834:
2835: sub newline_to_br {
2836: my ($message)=@_;
2837: my $newmessage;
2838: my $parser=HTML::LCParser->new($message);
2839: while (my $token=$parser->get_token()) {
2840: if ($token->[0] eq 'T') {
2841: my $text=$token->[1];
2842: $text=~s/\n/\<br \/\>/g;
2843: $newmessage.=$text;
2844: } elsif ($token->[0] eq 'D' || $token->[0] eq 'C') {
2845: $newmessage.=$token->[1];
2846: } elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') {
2847: $newmessage.=$token->[2];
2848: } elsif ($token->[0] eq 'S') {
2849: $newmessage.=$token->[4];
2850: }
2851:
2852: }
2853: $$message=$newmessage;
2854: }
2855:
1.33 www 2856: sub generate_preview_button {
1.171 www 2857: my ($formname,$fieldname)=@_;
2858: unless ($formname) { $formname='mailform'; }
2859: unless ($fieldname) { $fieldname='comment'; }
1.107 www 2860: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2861: return(<<ENDPREVIEW);
1.205 raeburn 2862: <br />
1.33 www 2863: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2864: <input type="hidden" name="subject">
1.33 www 2865: <input type="hidden" name="comment" />
1.65 www 2866: <input type="button" value="$pre"
1.171 www 2867: 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 2868: </form>
2869: ENDPREVIEW
2870: }
1.71 www 2871:
1.108 raeburn 2872: sub modify_attachments {
2873: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
1.204 www 2874: my $orig_subject = &unescape($env{'form.subject'});
1.194 albertel 2875: my $subject=&clear_out_html($orig_subject,undef,1);
1.108 raeburn 2876: $subject=~s/\n/\<br \/\>/g;
2877: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.157 albertel 2878: my $timestamp=$env{'form.timestamp'};
2879: my $numoldver=$env{'form.numoldver'};
1.187 albertel 2880:
1.108 raeburn 2881: my $msg = '';
1.113 raeburn 2882: my %attachments = ();
1.108 raeburn 2883: my %currattach = ();
2884: if ($idx) {
1.113 raeburn 2885: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108 raeburn 2886: }
1.139 albertel 2887: &Apache::lonenc::check_encrypt(\$symb);
1.187 albertel 2888: my $js = <<END;
2889: <script type="text/javascript">
1.108 raeburn 2890: function setAction () {
2891: document.modattachments.action = document.modattachments.origpage.value;
2892: document.modattachments.submit();
2893: }
2894: </script>
1.187 albertel 2895: END
2896:
2897: my $start_page =
2898: &Apache::loncommon::start_page('Discussion Post Attachments',$js);
2899: my $end_page =
2900: &Apache::loncommon::end_page();
2901:
2902: $r->print(<<END);
1.198 albertel 2903: $start_page
1.108 raeburn 2904: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2905: <table border="2">
2906: <tr>
2907: <td>
1.124 raeburn 2908: <b>Subject:</b> $subject</b><br /><br />
1.108 raeburn 2909: END
2910: if ($idx) {
2911: if ($attachmenturls) {
2912: my @currold = keys %currattach;
2913: if (@currold > 0) {
2914: $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 2915: foreach my $id (@currold) {
2916: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
2917: $attachurl =~ m#/([^/]+)$#;
1.151 albertel 2918: $r->print('<label><input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'</label><br />'."\n");
1.108 raeburn 2919: }
2920: $r->print("<br />");
2921: }
2922: }
2923: }
1.213 raeburn 2924: if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
1.108 raeburn 2925: $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");
2926: foreach (@{$currnewattach}) {
2927: $_ =~ m#/([^/]+)$#;
1.151 albertel 2928: $r->print('<label><input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'</label><br />'."\n");
1.108 raeburn 2929: }
2930: $r->print("<br />");
2931: }
2932: $r->print(<<END);
2933: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2934: </td>
2935: </tr>
2936: </table>
1.157 albertel 2937: <input type="hidden" name="subject" value="$env{'form.subject'}" />
2938: <input type="hidden" name="comment" value="$env{'form.comment'}" />
2939: <input type="hidden" name="timestamp" value="$env{'form.timestamp'}" />
2940: <input type="hidden" name="idx" value="$env{'form.idx'}" />
2941: <input type="hidden" name="numoldver" value="$env{'form.numoldver'}" />
2942: <input type="hidden" name="origpage" value="$env{'form.origpage'}" />
1.175 www 2943: <input type="hidden" name="blog" value="$env{'form.blog'}" />
1.157 albertel 2944: <input type="hidden" name="discuss" value="$env{'form.discuss'}" />
1.108 raeburn 2945: END
2946: foreach (@{$currnewattach}) {
2947: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2948: }
2949: foreach (@{$currdelold}) {
2950: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2951: }
2952: $r->print(<<END);
2953: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2954: </form>
1.187 albertel 2955: $end_page
1.108 raeburn 2956: END
2957: return;
2958: }
2959:
2960: sub process_attachments {
2961: my ($currnewattach,$currdelold,$keepold) = @_;
1.158 albertel 2962:
2963: @{$currnewattach}=
2964: &Apache::loncommon::get_env_multiple('form.currnewattach');
2965: @{$currdelold}=
2966: &Apache::loncommon::get_env_multiple('form.deloldattach');
1.157 albertel 2967: if (exists($env{'form.delnewattach'})) {
1.158 albertel 2968: my @currdelnew =
2969: &Apache::loncommon::get_env_multiple('form.delnewattach');
1.108 raeburn 2970: my @currnew = ();
2971: foreach my $newone (@{$currnewattach}) {
2972: my $delflag = 0;
2973: foreach (@currdelnew) {
2974: if ($newone eq $_) {
2975: $delflag = 1;
2976: last;
2977: }
2978: }
2979: unless ($delflag) {
2980: push @currnew, $newone;
2981: }
2982: }
2983: @{$currnewattach} = @currnew;
2984: }
1.158 albertel 2985: @{$keepold} = &Apache::loncommon::get_env_multiple('form.keepold');
1.108 raeburn 2986: }
2987:
2988: sub generate_attachments_button {
2989: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2990: my $origpage = $ENV{'REQUEST_URI'};
2991: my $att=$attachnum.' '.&mt("attachments");
2992: my $response = (<<END);
1.205 raeburn 2993: <br />
1.108 raeburn 2994: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2995: Click to add/remove attachments: <input type="button" value="$att"
1.124 raeburn 2996: 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 2997: END
2998: unless ($mode eq 'board') {
2999: $response .= 'javascript:anonchk();';
3000: }
3001: $response .= (<<ENDATTACH);
3002: this.form.submit();" />
3003: <input type="hidden" name="origpage" value="$origpage" />
3004: <input type="hidden" name="idx" value="$idx" />
3005: <input type="hidden" name="timestamp" value="$now" />
3006: <input type="hidden" name="subject" />
3007: <input type="hidden" name="comment" />
1.175 www 3008: <input type="hidden" name="blog" value = "0" />
1.164 albertel 3009: <input type="hidden" name="discuss" value = "0" />
1.108 raeburn 3010: <input type="hidden" name="numoldver" value="$numoldver" />
3011: ENDATTACH
3012: if (defined($deloldattach)) {
3013: if (@{$deloldattach} > 0) {
3014: foreach (@{$deloldattach}) {
3015: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
3016: }
3017: }
3018: }
3019: if (defined($currnewattach)) {
3020: if (@{$currnewattach} > 0) {
3021: foreach (@{$currnewattach}) {
3022: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
3023: }
3024: }
3025: }
3026: $response .= '</form>';
3027: return $response;
3028: }
3029:
3030: sub extract_attachments {
3031: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.116 raeburn 3032: %{$attachments}=();
3033: &get_post_attachments($attachments,$attachmenturls);
3034: foreach my $id (sort keys %{$attachments}) {
3035: if (exists($$attachments{$id}{$numoldver})) {
3036: if (defined($currdelold)) {
3037: if (@{$currdelold} > 0) {
3038: unless (grep/^$id$/,@{$currdelold}) {
3039: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 3040: }
1.113 raeburn 3041: } else {
3042: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 3043: }
1.116 raeburn 3044: } else {
3045: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 3046: }
3047: }
1.116 raeburn 3048: }
3049: my @attached = (sort { $a <=> $b } keys %{$currattach});
3050: if (@attached == 1) {
3051: my $id = $attached[0];
3052: my $attachurl;
3053: if ($attachmenturls =~ m/^<attachment id="0">/) {
3054: $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
3055: } else {
3056: $attachurl = $$attachments{$id}{'filename'};
3057: }
3058: $attachurl=~m|/([^/]+)$|;
3059: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
3060: $1.'</tt></a><br />';
3061: &Apache::lonnet::allowuploaded('/adm/feedback',
3062: $attachurl);
3063: } elsif (@attached > 1) {
3064: $$message.='<ol>';
3065: foreach (@attached) {
3066: my $id = $_;
1.113 raeburn 3067: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.116 raeburn 3068: my ($fname)
3069: =($attachurl=~m|/([^/]+)$|);
3070: $$message .= '<li><a href="'.$attachurl.
3071: '"><tt>'.
3072: $fname.'</tt></a></li>';
1.108 raeburn 3073: &Apache::lonnet::allowuploaded('/adm/feedback',
1.116 raeburn 3074: $attachurl);
1.108 raeburn 3075: }
1.116 raeburn 3076: $$message .= '</ol>';
1.108 raeburn 3077: }
3078: }
3079:
3080: sub construct_attachmenturl {
3081: my ($currnewattach,$keepold,$symb,$idx)=@_;
3082: my $oldattachmenturl;
3083: my $newattachmenturl;
1.113 raeburn 3084: my $startnum = 0;
1.108 raeburn 3085: my $currver = 0;
1.157 albertel 3086: if (($env{'form.editdisc'}) && ($idx)) {
3087: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3088: $env{'course.'.$env{'request.course.id'}.'.domain'},
3089: $env{'course.'.$env{'request.course.id'}.'.num'});
1.108 raeburn 3090: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
3091: if ($contrib{$idx.':history'}) {
3092: if ($contrib{$idx.':history'} =~ /:/) {
3093: my @oldversions = split/:/,$contrib{$idx.':history'};
3094: $currver = 1 + scalar(@oldversions);
3095: } else {
3096: $currver = 2;
3097: }
3098: } else {
3099: $currver = 1;
3100: }
3101: if ($oldattachmenturl) {
1.113 raeburn 3102: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
3103: my %attachments = ();
3104: my $prevver = $currver-1;
3105: &get_post_attachments(\%attachments,$oldattachmenturl);
1.116 raeburn 3106: my $numattach = scalar(keys %attachments);
1.113 raeburn 3107: $startnum += $numattach;
3108: foreach my $num (sort {$a <=> $b} keys %attachments) {
3109: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
1.116 raeburn 3110: foreach $_ (sort {$a <=> $b} keys %{$attachments{$num}}) {
3111: unless ($_ eq 'filename') {
3112: $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
3113: }
1.113 raeburn 3114: }
3115: if (grep/^$num$/,@{$keepold}) {
3116: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108 raeburn 3117: }
1.113 raeburn 3118: $newattachmenturl .= '</attachment>';
1.108 raeburn 3119: }
3120: } else {
1.116 raeburn 3121: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
1.108 raeburn 3122: unless (grep/^0$/,@{$keepold}) {
1.113 raeburn 3123: $newattachmenturl .= '<post id="1">n</post>';
1.108 raeburn 3124: }
1.113 raeburn 3125: $newattachmenturl .= '</attachment>';
1.108 raeburn 3126: $startnum ++;
3127: }
3128: }
3129: }
3130: for (my $i=0; $i<@{$currnewattach}; $i++) {
3131: my $attachnum = $startnum + $i;
1.113 raeburn 3132: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108 raeburn 3133: }
3134: return $newattachmenturl;
3135: }
1.128 raeburn 3136:
3137: sub has_discussion {
3138: my $resourcesref = shift;
3139: my $navmap = Apache::lonnavmaps::navmap->new();
3140: my @allres=$navmap->retrieveResources();
3141: foreach my $resource (@allres) {
3142: if ($resource->hasDiscussion()) {
1.162 albertel 3143: my $ressymb = $resource->wrap_symb();
1.128 raeburn 3144: push @{$resourcesref}, $ressymb;
3145: }
3146: }
3147: return;
1.143 raeburn 3148: }
3149:
3150: sub sort_filter_names {
3151: my ($sort_types,$role_types,$status_types) = @_;
3152: %{$sort_types} = (
3153: ascdate => 'Date order - oldest first',
3154: descdate => 'Date order - newest first',
3155: thread => 'Threaded',
3156: subject => 'By subject',
3157: username => 'By domain and username',
3158: lastfirst => 'By last name, first name'
3159: );
3160: %{$role_types} = (
3161: all => 'All roles',
3162: st => 'Students',
3163: cc => 'Course Coordinators',
3164: in => 'Instructors',
3165: ta => 'TAs',
3166: ep => 'Exam proctors',
3167: ad => 'Administrators',
3168: cr => 'Custom roles'
3169: );
3170: %{$status_types} = (
3171: all => 'Roles of any status',
1.214 ! albertel 3172: Active => 'Only active roles',
! 3173: Expired => 'Only past roles',
! 3174: Future => 'Only future roles',
1.143 raeburn 3175: );
3176: }
1.108 raeburn 3177:
1.6 albertel 3178: sub handler {
3179: my $r = shift;
1.8 www 3180: if ($r->header_only) {
1.71 www 3181: &Apache::loncommon::content_type($r,'text/html');
1.8 www 3182: $r->send_http_header;
3183: return OK;
3184: }
1.15 www 3185:
3186: # --------------------------- Get query string for limited number of parameters
3187:
1.97 raeburn 3188: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.208 raeburn 3189: ['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']);
3190: my $group = $env{'form.group'};
1.180 raeburn 3191: if ($env{'form.editdisc'}) {
1.208 raeburn 3192: if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) {
1.180 raeburn 3193: my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
3194: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3195: my $feedurl=&Apache::lonnet::clutter($url);
1.208 raeburn 3196: &redirect_back($r,$feedurl,&mt('Editing not permitted').'<br />', '0','0','','',$env{'form.previous'},undef,undef,undef,
3197: undef,undef,undef,$group);
1.180 raeburn 3198: return OK;
3199: }
3200: }
1.157 albertel 3201: if ($env{'form.discsymb'}) {
3202: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.discsymb'});
1.111 raeburn 3203: my $readkey = $symb.'_read';
3204: my $chgcount = 0;
1.157 albertel 3205: my %readinghash = &Apache::lonnet::get('nohist_'.$env{'request.course.id'}.'_discuss',[$readkey],$env{'user.domain'},$env{'user.name'});
3206: foreach my $key (keys %env) {
1.111 raeburn 3207: if ($key =~ m/^form\.postunread_(\d+)/) {
3208: if ($readinghash{$readkey} =~ /\.$1\./) {
3209: $readinghash{$readkey} =~ s/\.$1\.//;
3210: $chgcount ++;
3211: }
3212: } elsif ($key =~ m/^form\.postread_(\d+)/) {
3213: unless ($readinghash{$readkey} =~ /\.$1\./) {
3214: $readinghash{$readkey} .= '.'.$1.'.';
3215: $chgcount ++;
3216: }
3217: }
3218: }
3219: if ($chgcount > 0) {
1.157 albertel 3220: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3221: \%readinghash,$env{'user.domain'},$env{'user.name'});
1.111 raeburn 3222: }
1.133 albertel 3223: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />',
1.208 raeburn 3224: '0','0','','',$env{'form.previous'},'','','',
3225: undef,undef,undef,$group);
1.111 raeburn 3226: return OK;
3227: }
1.157 albertel 3228: if ($env{'form.allversions'}) {
1.109 raeburn 3229: &Apache::loncommon::content_type($r,'text/html');
1.187 albertel 3230: &Apache::loncommon::no_cache($r);
1.109 raeburn 3231: $r->send_http_header;
1.187 albertel 3232:
3233: $r->print(&Apache::loncommon::start_page('Discussion Post Versions'));
3234:
1.157 albertel 3235: my $crs='/'.$env{'request.course.id'};
3236: if ($env{'request.course.sec'}) {
3237: $crs.='_'.$env{'request.course.sec'};
1.109 raeburn 3238: }
1.133 albertel 3239: $crs=~s|_|/|g;
1.208 raeburn 3240: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3241: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.157 albertel 3242: my ($symb,$idx)=split(/\:\:\:/,$env{'form.allversions'});
1.133 albertel 3243: ($symb)=&get_feedurl_and_clean_symb($symb);
1.208 raeburn 3244: my $ressymb = &wrap_symb($symb);
3245: my $group = $env{'form.group'};
3246: my $seeid;
3247: if (($group ne '') && (($ressymb =~ m|^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|))) {
3248: if (&check_group_priv($group,'dgp') eq 'ok') {
3249: $seeid = 1;
3250: }
3251: } else {
3252: $seeid = &Apache::lonnet::allowed('rin',$crs);
3253: }
1.109 raeburn 3254: if ($idx > 0) {
1.116 raeburn 3255: my %messages = ();
3256: my %subjects = ();
3257: my %attachmsgs = ();
3258: my %allattachments = ();
3259: my %imsfiles = ();
3260: my ($screenname,$plainname);
1.157 albertel 3261: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3262: $env{'course.'.$env{'request.course.id'}.'.domain'},
3263: $env{'course.'.$env{'request.course.id'}.'.num'});
1.133 albertel 3264: $r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname));
1.109 raeburn 3265: }
1.187 albertel 3266: $r->print(&Apache::loncommon::end_page());
1.109 raeburn 3267: return OK;
3268: }
1.157 albertel 3269: if ($env{'form.posterlist'}) {
3270: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
3271: &print_showposters($r,$symb,$env{'form.previous'},$feedurl,
3272: $env{'form.sortposts'});
1.101 raeburn 3273: return OK;
3274: }
1.157 albertel 3275: if ($env{'form.userpick'}) {
1.133 albertel 3276: my @posters = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.157 albertel 3277: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.userpick'});
1.101 raeburn 3278: my $numpicks = @posters;
1.133 albertel 3279: my %discinfo;
3280: $discinfo{$symb.'_userpick'} = join('&',@posters);
1.157 albertel 3281: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3282: \%discinfo,$env{'user.domain'},$env{'user.name'});
1.175 www 3283: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',
1.157 albertel 3284: '',$env{'form.previous'},$env{'form.sortposts'},'','','',
1.208 raeburn 3285: '',$numpicks,$group);
1.101 raeburn 3286: return OK;
3287: }
1.157 albertel 3288: if ($env{'form.applysort'}) {
3289: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
1.175 www 3290: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',
1.157 albertel 3291: '',$env{'form.previous'},$env{'form.sortposts'},
3292: $env{'form.rolefilter'},$env{'form.statusfilter'},
1.208 raeburn 3293: $env{'form.sectionpick'},$env{'form.grouppick'},
3294: undef,$group);
1.100 raeburn 3295: return OK;
1.157 albertel 3296: } elsif ($env{'form.cmd'} eq 'sortfilter') {
3297: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
3298: &print_sortfilter_options($r,$symb,$env{'form.previous'},$feedurl);
1.100 raeburn 3299: return OK;
1.157 albertel 3300: } elsif ($env{'form.navtime'}) {
1.99 raeburn 3301: my %discinfo = ();
3302: my @resources = ();
1.157 albertel 3303: if (defined($env{'form.navmaps'})) {
3304: if ($env{'form.navmaps'} =~ /:/) {
3305: @resources = split/:/,$env{'form.navmaps'};
1.128 raeburn 3306: } else {
1.157 albertel 3307: @resources = ("$env{'form.navmaps'}");
1.128 raeburn 3308: }
1.99 raeburn 3309: } else {
1.128 raeburn 3310: &has_discussion(\@resources);
1.99 raeburn 3311: }
3312: my $numitems = @resources;
3313: my $feedurl = '/adm/navmaps';
1.157 albertel 3314: if ($env{'form.navurl'}) { $feedurl .= '?'.$env{'form.navurl'}; }
1.99 raeburn 3315: my %lt = &Apache::lonlocal::texthash(
3316: 'mnpa' => 'Marked "New" posts as read in a total of',
1.128 raeburn 3317: 'robb' => 'resources/bulletin boards.',
3318: 'twnp' => 'There are currently no resources or bulletin boards with unread discussion postings.'
1.99 raeburn 3319: );
3320: foreach (@resources) {
3321: my $ressymb=$_;
1.132 albertel 3322: &Apache::lonenc::check_decrypt(\$ressymb);
1.99 raeburn 3323: my $lastkey = $ressymb.'_lastread';
1.157 albertel 3324: $discinfo{$lastkey} = $env{'form.navtime'};
1.99 raeburn 3325: }
1.128 raeburn 3326: my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
3327: if ($numitems > 0) {
1.157 albertel 3328: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3329: \%discinfo,$env{'user.domain'},$env{'user.name'});
1.128 raeburn 3330: } else {
3331: $textline = "<b>$lt{'twnp'}</b>";
3332: }
1.99 raeburn 3333: &Apache::loncommon::content_type($r,'text/html');
3334: $r->send_http_header;
1.150 albertel 3335: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.200 albertel 3336: my %onload;
3337: if ($env{'environment.remote'} ne 'off') {
3338: $onload{'onload'} =
3339: "if (window.name!='loncapaclient') { this.document.reldt.submit(); self.window.close(); }";
3340: }
3341:
1.186 albertel 3342: my $start_page=
3343: &Apache::loncommon::start_page('New posts marked as read',undef,
3344: {'redirect' => [2,$feedurl],
3345: 'only_body' => 1,
1.189 albertel 3346: 'add_entries' => \%onload});
1.186 albertel 3347: my $end_page = &Apache::loncommon::end_page();
1.99 raeburn 3348: $r->print (<<ENDREDIR);
1.186 albertel 3349: $start_page
1.150 albertel 3350: <img align="right" src="$logo" />
1.128 raeburn 3351: $textline
1.99 raeburn 3352: <form name="reldt" action="$feedurl" target="loncapaclient">
3353: </form>
1.187 albertel 3354: <br />
1.186 albertel 3355: $end_page
1.99 raeburn 3356: ENDREDIR
3357: return OK;
1.157 albertel 3358: } elsif ($env{'form.modifydisp'}) {
3359: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.modifydisp'});
1.133 albertel 3360: my ($dispchgA,$dispchgB,$markchg,$toggchg) =
1.157 albertel 3361: split(/_/,$env{'form.changes'});
3362: &print_display_options($r,$symb,$env{'form.previous'},$dispchgA,
1.133 albertel 3363: $dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 3364: return OK;
1.157 albertel 3365: } elsif ($env{'form.markondisp'} || $env{'form.markonread'} ||
3366: $env{'form.allposts'} || $env{'form.onlyunread'} ||
3367: $env{'form.onlyunmark'} || $env{'form.toggoff'} ||
3368: $env{'form.toggon'} || $env{'form.markread'}) {
3369: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
1.137 albertel 3370: my %discinfo;
1.133 albertel 3371: # ------------------------ Modify setting for read/unread toggle for each post
1.157 albertel 3372: if ($env{'form.toggoff'}) { $discinfo{$symb.'_readtoggle'}=0; }
3373: if ($env{'form.toggon'}) { $discinfo{$symb.'_readtoggle'}=1; }
1.133 albertel 3374: # --------- Modify setting for identification of 'NEW' posts in this discussion
1.157 albertel 3375: if ($env{'form.markondisp'}) {
1.137 albertel 3376: $discinfo{$symb.'_lastread'} = time;
3377: $discinfo{$symb.'_markondisp'} = 1;
3378: }
1.157 albertel 3379: if ($env{'form.markonread'}) {
3380: if ( $env{'form.previous'} > 0 ) {
3381: $discinfo{$symb.'_lastread'} = $env{'form.previous'};
1.137 albertel 3382: }
3383: $discinfo{$symb.'_markondisp'} = 0;
1.84 raeburn 3384: }
1.133 albertel 3385: # --------------------------------- Modify display setting for this discussion
1.157 albertel 3386: if ($env{'form.allposts'}) {
1.137 albertel 3387: $discinfo{$symb.'_showonlyunread'} = 0;
3388: $discinfo{$symb.'_showonlyunmark'} = 0;
1.84 raeburn 3389: }
1.157 albertel 3390: if ($env{'form.onlyunread'}) { $discinfo{$symb.'_showonlyunread'} = 1; }
3391: if ($env{'form.onlyunmark'}) { $discinfo{$symb.'_showonlyunmark'} = 1; }
1.137 albertel 3392: # ----------------------------------------------------- Mark new posts not NEW
1.157 albertel 3393: if ($env{'form.markread'}) { $discinfo{$symb.'_lastread'} = time; }
3394: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3395: \%discinfo,$env{'user.domain'},$env{'user.name'});
3396: my $previous=$env{'form.previous'};
3397: if ($env{'form.markondisp'}) { $previous=undef; }
1.133 albertel 3398: &redirect_back($r,$feedurl,&mt('Changed display status').'<br />',
1.208 raeburn 3399: '0','0','','',$previous,'','','','','','',$group);
1.84 raeburn 3400: return OK;
1.157 albertel 3401: } elsif (($env{'form.hide'}) || ($env{'form.unhide'})) {
1.15 www 3402: # ----------------------------------------------------------------- Hide/unhide
1.157 albertel 3403: my $entry=$env{'form.hide'}?$env{'form.hide'}:$env{'form.unhide'};
1.133 albertel 3404: my ($symb,$idx)=split(/\:\:\:/,$entry);
3405: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.15 www 3406:
1.180 raeburn 3407: my $crs='/'.$env{'request.course.id'};
3408: if ($env{'request.course.sec'}) {
3409: $crs.='_'.$env{'request.course.sec'};
3410: }
3411: $crs=~s/\_/\//g;
3412: my $seeid=&Apache::lonnet::allowed('rin',$crs);
3413:
1.208 raeburn 3414: if ($env{'form.hide'} && !$seeid && !(&editing_allowed($env{'form.hide'},$env{'form.group'}))) {
3415: &redirect_back($r,$feedurl,&mt('Deletion not permitted').'<br />', '0','0','','',$env{'form.previous'},'','','','',
3416: undef,undef,$group,);
1.180 raeburn 3417: return OK;
3418: }
3419:
1.157 albertel 3420: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3421: $env{'course.'.$env{'request.course.id'}.'.domain'},
3422: $env{'course.'.$env{'request.course.id'}.'.num'});
1.15 www 3423:
1.133 albertel 3424: my $currenthidden=$contrib{'hidden'};
3425: my $currentstudenthidden=$contrib{'studenthidden'};
1.15 www 3426:
1.157 albertel 3427: if ($env{'form.hide'}) {
1.133 albertel 3428: $currenthidden.='.'.$idx.'.';
3429: unless ($seeid) {
3430: $currentstudenthidden.='.'.$idx.'.';
3431: }
3432: } else {
3433: $currenthidden=~s/\.$idx\.//g;
3434: }
3435: my %newhash=('hidden' => $currenthidden);
1.157 albertel 3436: if ( ($env{'form.hide'}) && (!$seeid) ) {
1.133 albertel 3437: $newhash{'studenthidden'} = $currentstudenthidden;
3438: }
1.38 www 3439:
1.157 albertel 3440: &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
3441: $env{'course.'.$env{'request.course.id'}.'.domain'},
3442: $env{'course.'.$env{'request.course.id'}.'.num'});
1.38 www 3443:
1.133 albertel 3444: &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
1.208 raeburn 3445: '0','0','','',$env{'form.previous'},undef,undef,undef,
3446: undef,undef,undef,$group);
1.135 albertel 3447: return OK;
1.157 albertel 3448: } elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) {
3449: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
3450: if ($env{'form.cmd'} eq 'threadedon') {
1.69 www 3451: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
3452: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
3453: } else {
3454: &Apache::lonnet::del('environment',['threadeddiscussion']);
3455: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 3456: }
1.133 albertel 3457: &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'<br />',
1.208 raeburn 3458: '0','0','','',$env{'form.previous'},undef,undef,undef,
3459: undef,undef,undef,$group);
1.135 albertel 3460: return OK;
1.157 albertel 3461: } elsif ($env{'form.deldisc'}) {
1.38 www 3462: # --------------------------------------------------------------- Hide for good
1.157 albertel 3463: my ($symb,$idx)=split(/\:\:\:/,$env{'form.deldisc'});
1.133 albertel 3464: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.157 albertel 3465: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3466: $env{'course.'.$env{'request.course.id'}.'.domain'},
3467: $env{'course.'.$env{'request.course.id'}.'.num'});
1.135 albertel 3468: my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
1.157 albertel 3469: &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
3470: $env{'course.'.$env{'request.course.id'}.'.domain'},
3471: $env{'course.'.$env{'request.course.id'}.'.num'});
1.135 albertel 3472: &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
1.208 raeburn 3473: '0','0','','',$env{'form.previous'},undef,undef,undef,
3474: undef,undef,undef,$group);
1.135 albertel 3475: return OK;
1.157 albertel 3476: } elsif ($env{'form.preview'}) {
1.33 www 3477: # -------------------------------------------------------- User wants a preview
3478: &show_preview($r);
1.135 albertel 3479: return OK;
1.157 albertel 3480: } elsif ($env{'form.attach'}) {
1.108 raeburn 3481: # -------------------------------------------------------- Work on attachments
3482: &Apache::loncommon::content_type($r,'text/html');
3483: $r->send_http_header;
1.198 albertel 3484: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','discuss','blog']);
1.133 albertel 3485: my (@currnewattach,@currdelold,@keepold);
1.108 raeburn 3486: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1.157 albertel 3487: if (exists($env{'form.addnewattach.filename'})) {
3488: unless (length($env{'form.addnewattach'})>131072) {
3489: my $subdir = 'feedback/'.$env{'form.timestamp'};
1.108 raeburn 3490: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
1.139 albertel 3491: push @currnewattach, $newattachment;
1.108 raeburn 3492: }
3493: }
1.133 albertel 3494: my $attachmenturls;
1.157 albertel 3495: my ($symb) = &get_feedurl_and_clean_symb($env{'form.attach'});
3496: my $idx = $env{'form.idx'};
1.108 raeburn 3497: if ($idx) {
1.157 albertel 3498: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3499: $env{'course.'.$env{'request.course.id'}.'.domain'},
3500: $env{'course.'.$env{'request.course.id'}.'.num'});
1.108 raeburn 3501: $attachmenturls = $contrib{$idx.':attachmenturl'};
3502: }
1.133 albertel 3503: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
3504: $attachmenturls);
1.135 albertel 3505: return OK;
1.157 albertel 3506: } elsif ($env{'form.export'}) {
1.116 raeburn 3507: &Apache::loncommon::content_type($r,'text/html');
3508: $r->send_http_header;
1.157 albertel 3509: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.export'});
1.133 albertel 3510: my $mode='board';
1.116 raeburn 3511: my $status='OPEN';
1.157 albertel 3512: my $previous=$env{'form.previous'};
1.168 albertel 3513: if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library|task)$/) {
1.116 raeburn 3514: $mode='problem';
3515: $status=$Apache::inputtags::status[-1];
3516: }
3517: my $discussion = &list_discussion($mode,$status,$symb);
1.188 albertel 3518: my $start_page =
3519: &Apache::loncommon::start_page('Resource Feedback and Discussion');
3520: my $end_page =
3521: &Apache::loncommon::end_page();
3522: $r->print($start_page.$discussion.$end_page);
1.116 raeburn 3523: return OK;
1.15 www 3524: } else {
3525: # ------------------------------------------------------------- Normal feedback
1.157 albertel 3526: my $feedurl=$env{'form.postdata'};
1.133 albertel 3527: $feedurl=~s/^http\:\/\///;
3528: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
3529: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
3530: $feedurl=~s/\?.+$//;
1.8 www 3531:
1.133 albertel 3532: my $symb;
1.157 albertel 3533: if ($env{'form.replydisc'}) {
3534: $symb=(split(/\:\:\:/,$env{'form.replydisc'}))[0];
1.133 albertel 3535: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3536: $feedurl=&Apache::lonnet::clutter($url);
1.157 albertel 3537: } elsif ($env{'form.editdisc'}) {
3538: $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
1.52 www 3539: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.133 albertel 3540: $feedurl=&Apache::lonnet::clutter($url);
1.157 albertel 3541: } elsif ($env{'form.origpage'}) {
1.133 albertel 3542: $symb="";
3543: } else {
3544: $symb=&Apache::lonnet::symbread($feedurl);
3545: }
3546: unless ($symb) {
1.157 albertel 3547: $symb=$env{'form.symb'};
1.133 albertel 3548: if ($symb) {
3549: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3550: $feedurl=&Apache::lonnet::clutter($url);
3551: }
3552: }
3553: &Apache::lonenc::check_decrypt(\$symb);
3554: my $goahead=1;
1.168 albertel 3555: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.133 albertel 3556: unless ($symb) { $goahead=0; }
3557: }
3558: # backward compatibility (bulletin boards used to be 'wrapped')
1.159 raeburn 3559: &dewrapper(\$feedurl);
1.133 albertel 3560: if (!$goahead) {
3561: # Ambiguous Problem Resource
3562: $r->internal_redirect('/adm/ambiguous');
3563: return OK;
1.31 www 3564: }
1.8 www 3565: # Go ahead with feedback, no ambiguous reference
1.133 albertel 3566: unless (
3567: (
3568: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
3569: )
3570: ||
1.157 albertel 3571: ($env{'request.course.id'} && ($feedurl!~m:^/adm:))
1.133 albertel 3572: ||
1.157 albertel 3573: ($env{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.133 albertel 3574: ) {
1.135 albertel 3575: &Apache::loncommon::content_type($r,'text/html');
3576: $r->send_http_header;
1.133 albertel 3577: # Unable to give feedback
3578: &no_redirect_back($r,$feedurl);
1.178 albertel 3579: return OK;
1.133 albertel 3580: }
1.6 albertel 3581: # --------------------------------------------------- Print login screen header
1.157 albertel 3582: unless ($env{'form.sendit'}) {
1.135 albertel 3583: &Apache::loncommon::content_type($r,'text/html');
3584: $r->send_http_header;
1.141 raeburn 3585: my $options=&screen_header($feedurl,$symb);
1.133 albertel 3586: if ($options) {
3587: &mail_screen($r,$feedurl,$options);
3588: } else {
3589: &fail_redirect($r,$feedurl);
3590: }
3591: return OK;
1.6 albertel 3592: }
3593:
3594: # Get previous user input
1.9 albertel 3595: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.157 albertel 3596: $symb,$env{'user.name'},$env{'user.domain'},
3597: $env{'request.course.id'});
1.6 albertel 3598:
3599: # Get output from resource
3600: my $usersaw=&resource_output($feedurl);
3601:
1.50 albertel 3602: # Get resource answer (need to allow student to view grades for this to work)
3603: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 3604: my $useranswer=&Apache::loncommon::get_student_answers(
1.157 albertel 3605: $symb,$env{'user.name'},$env{'user.domain'},
3606: $env{'request.course.id'});
1.50 albertel 3607: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 3608: # Get attachments, if any, and not too large
3609: my $attachmenturl='';
1.157 albertel 3610: if (($env{'form.origpage'}) || ($env{'form.editdisc'}) ||
3611: ($env{'form.replydisc'})) {
1.133 albertel 3612: my ($symb,$idx);
1.157 albertel 3613: if ($env{'form.replydisc'}) {
3614: ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
3615: } elsif ($env{'form.editdisc'}) {
3616: ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
3617: } elsif ($env{'form.origpage'}) {
3618: $symb = $env{'form.symb'};
1.133 albertel 3619: }
1.132 albertel 3620: &Apache::lonenc::check_decrypt(\$symb);
1.133 albertel 3621: my @currnewattach = ();
3622: my @deloldattach = ();
3623: my @keepold = ();
3624: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
3625: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
3626: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
1.157 albertel 3627: } elsif ($env{'form.attachment.filename'}) {
3628: unless (length($env{'form.attachment'})>131072) {
1.82 albertel 3629: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3630: }
3631: }
1.6 albertel 3632: # Filter HTML out of message (could be nasty)
1.157 albertel 3633: my $message=&clear_out_html($env{'form.comment'});
1.6 albertel 3634:
3635: # Assemble email
1.8 www 3636: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.133 albertel 3637: $usersaw,$useranswer);
1.40 albertel 3638:
1.6 albertel 3639: # Who gets this?
3640: my ($typestyle,%to) = &decide_receiver($feedurl);
3641:
3642: # Actually send mail
1.194 albertel 3643: my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'},
3644: undef,1),
3645: $feedurl,$email,$citations,
1.133 albertel 3646: $attachmenturl,%to);
1.13 www 3647:
3648: # Discussion? Store that.
1.32 albertel 3649: my $numpost=0;
1.207 albertel 3650: if ( ($env{'form.discuss'} ne ''
3651: && $env{'form.discuss'} !~ /^(?:author|question|course|policy)/)
3652: || $env{'form.anondiscuss'} ne '') {
1.194 albertel 3653: my $subject = &clear_out_html($env{'form.subject'},undef,1);
1.201 albertel 3654: my $anonmode=($env{'form.discuss'} eq 'anon' || $env{'form.anondiscuss'} );
1.133 albertel 3655: $typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl,
3656: $subject);
1.32 albertel 3657: $numpost++;
1.14 www 3658: }
1.175 www 3659:
3660: # Add to blog?
3661:
3662: my $blog='';
3663: if ($env{'form.blog'}) {
1.194 albertel 3664: my $subject = &clear_out_html($env{'form.subject'},undef,1);
1.175 www 3665: $status.=&Apache::lonrss::addentry($env{'user.name'},
3666: $env{'user.domain'},
3667: 'CourseBlog_'.$env{'request.course.id'},
3668: $subject,$message,$feedurl,'public');
3669: $blog='<br />'.&mt('Added to my course blog').'<br />';
3670: }
1.133 albertel 3671:
1.6 albertel 3672: # Receipt screen and redirect back to where came from
1.208 raeburn 3673: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group);
1.133 albertel 3674: }
3675: return OK;
3676: }
1.6 albertel 3677:
1.133 albertel 3678: sub wrap_symb {
3679: my ($ressymb)=@_;
3680: if ($ressymb =~ /bulletin___\d+___/) {
3681: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3682: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3683: }
1.6 albertel 3684: }
1.133 albertel 3685: return $ressymb;
3686: }
3687: sub dewrapper {
3688: my ($feedurl)=@_;
3689: if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3690: $$feedurl=~s|^/adm/wrapper||;
3691: }
3692: }
3693:
3694: sub get_feedurl {
3695: my ($symb)=@_;
3696: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3697: my $feedurl = &Apache::lonnet::clutter($url);
3698: &dewrapper(\$feedurl);
3699: return $feedurl;
1.15 www 3700: }
1.1 www 3701:
1.133 albertel 3702: sub get_feedurl_and_clean_symb {
3703: my ($symb)=@_;
3704: &Apache::lonenc::check_decrypt(\$symb);
3705: # backward compatibility (bulletin boards used to be 'wrapped')
3706: unless ($symb =~ m|bulletin___\d+___adm/wrapper|) {
3707: $symb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3708: }
3709: my $feedurl = &get_feedurl($symb);
3710: return ($symb,$feedurl);
3711: }
1.180 raeburn 3712:
3713: sub editing_allowed {
1.208 raeburn 3714: my ($postid,$group) = @_;
3715: $postid = &unescape($postid);
1.180 raeburn 3716: my $can_edit = 0;
1.208 raeburn 3717: if ($group ne '') {
3718: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3719: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3720: if ($postid =~ m|^bulletin___\d+___adm/wrapper(/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard)|) {
3721: if (&check_group_priv($group,'egp') eq 'ok') {
3722: $can_edit = 1;
3723: }
3724: return $can_edit;
3725: }
3726: }
1.180 raeburn 3727: my $cid = $env{'request.course.id'};
3728: my $role = (split(/\./,$env{'request.role'}))[0];
3729: my $section = $env{'request.course.sec'};
1.184 albertel 3730: my $allow_editing_config =
3731: $env{'course.'.$cid.'.allow_discussion_post_editing'};
1.180 raeburn 3732: if ($allow_editing_config =~ m/^\s*yes\s*$/i) {
3733: $can_edit = 1;
3734: } else {
1.184 albertel 3735: foreach my $editor (split(/,/,$allow_editing_config)) {
3736: my ($editor_role,$editor_sec) = split(/:/,$editor);
3737: if ($editor_role eq $role
3738: && defined($editor_sec)
3739: && defined($section)
3740: && $editor_sec eq $section) {
3741: $can_edit = 1;
3742: last;
3743: }
3744: if ($editor_role eq $role
3745: && !defined($editor_sec)) {
3746: $can_edit = 1;
3747: }
3748: }
1.180 raeburn 3749: }
3750: return $can_edit;
3751: }
3752:
1.208 raeburn 3753: sub check_group_priv {
3754: my ($group,$grp_priv) = @_;
3755: foreach my $priv ('mdg','vcg') {
3756: my $checkcourse = $env{'request.course.id'}.
3757: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'');
3758: if (&Apache::lonnet::allowed($priv,$checkcourse)) {
3759: return 'ok';
3760: }
3761: }
3762: if ($grp_priv && $group ne '') {
3763: if (&Apache::lonnet::allowed($grp_priv,$env{'request.course.id'}.'/'.$group)) {
3764: return 'ok';
3765: }
3766: }
3767: return '';
3768: }
3769:
1.211 albertel 3770: sub group_args {
1.208 raeburn 3771: my ($group) = @_;
1.211 albertel 3772: if ($group eq '') { return ''; }
3773: my $extra_args = '&group='.$group;
1.208 raeburn 3774: if (exists($env{'form.ref'})) {
1.211 albertel 3775: $extra_args .= '&ref='.$env{'form.ref'};
1.208 raeburn 3776: }
3777: return $extra_args;
3778: }
3779:
1.1 www 3780: 1;
3781: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>