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