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