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