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