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