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