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