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