--- loncom/interface/lonfeedback.pm 2009/07/09 12:53:28 1.275 +++ loncom/interface/lonfeedback.pm 2012/04/30 03:51:40 1.290.2.7.2.4 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.275 2009/07/09 12:53:28 kalberla Exp $ +# $Id: lonfeedback.pm,v 1.290.2.7.2.4 2012/04/30 03:51:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,7 @@ use Apache::lonnavmaps; use Apache::lonenc(); use Apache::lonrss(); use HTML::LCParser(); +#use HTML::Tidy::libXML; use Apache::lonspeller(); use Apache::longroup; use Cwd; @@ -48,15 +49,24 @@ use LONCAPA; sub discussion_open { my ($status,$symb)=@_; +# Advanced roles can always discuss if ($env{'request.role.adv'}) { return 1; } +# Get discussion closing date + my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb); +# If it is defined and in the future, the instructor wants this discussion to be open + if (defined($close) && $close ne '' && $close > time) { + return 1; + } +# It was not explicitly open, check if the problem is available. +# If the problem is not available, close the discussion if (defined($status) && - !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER' - || $status eq 'OPEN')) { - return 0; + !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER' + || $status eq 'OPEN')) { + return 0; } - my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb); +# The problem is available, but check if the instructor explictly closed discussion if (defined($close) && $close ne '' && $close < time) { - return 0; + return 0; } return 1; } @@ -72,6 +82,26 @@ sub discussion_visible { return 1; } +sub discussion_vote_available { + my ($status,$symb)=@_; + my $canvote=&Apache::lonnet::EXT('resource.0.discussvote',$symb); + if ((lc($canvote) eq 'yes') || + ((lc($canvote) eq 'notended') && (&discussion_open($status,$symb)))) { + return 1; + } +} + +sub get_realsymb { + my ($symb) = @_; + my $realsymb = $symb; + if ($symb=~/^bulletin___/) { + my $filename=(&Apache::lonnet::decode_symb($symb))[2]; + $filename=~s{^adm/wrapper/}{}; + $realsymb=&Apache::lonnet::symbread($filename); + } + return $realsymb; +} + sub list_discussion { my ($mode,$status,$ressymb,$imsextras,$group)=@_; unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); } @@ -172,6 +202,7 @@ sub list_discussion { my $cdom = $env{'course.'.$cid.'.domain'}; my $cnum = $env{'course.'.$cid.'.num'}; + my $crstype = &Apache::loncommon::course_type(); # Get information about students and non-students in course for filtering display of posts my %roleshash = (); @@ -246,14 +277,14 @@ sub list_discussion { $visit ++; my $seeid; - if (($group ne '') && ($mode eq 'board') && - ($ressymb =~ m|^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|)) { - if (&check_group_priv($group,'dgp') eq 'ok') { - $seeid = 1; - } - } else { - $seeid=&Apache::lonnet::allowed('rin',$crs); + if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + $seeid = 1; } + my $seehidden = &can_see_hidden($mode,$ressymb,undef,$group,$cdom,$cnum,$crs); +# Is voting on discussions available + my $realsymb = &get_realsymb($ressymb); + my $canvote = &discussion_vote_available($status,$realsymb); + my @discussionitems=(); my %shown = (); my @posteridentity=(); @@ -280,7 +311,7 @@ sub list_discussion { $discinfo{$visitkey} = $visit; &Apache::lonnet::put('nohist_'.$cid.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'}); - &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,$prevread,$sortposts,$encsymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group); + &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$seehidden,$canvote,$prevread,$sortposts,$encsymb,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group); my $discussion=''; my $manifestfile; @@ -315,6 +346,7 @@ sub list_discussion { 'dpwn' => 'Deleted posts will no longer be visible to you and other students', 'bwco' => 'but will continue to be visible to your instructor', 'depo' => 'Deleted posts will no longer be visible to you or anyone else.', + 'discussions' => 'DISCUSSIONS' ); my $currdisp = $lt{'allposts'}; @@ -355,10 +387,10 @@ sub list_discussion { $togglink = 'toggoff'; } - $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink; + $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink; if ($newpostsflag) { - $chglink .= '&previous='.$prevread; + $chglink .= '&previous='.$prevread; } $chglink.=&group_args($group); @@ -366,8 +398,7 @@ sub list_discussion { # Print the discusssion if ($outputtarget eq 'tex') { $discussion.='{\tiny \vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'. - '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'. - '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'. + '\textbf{'.$lt{'discussions'}.'}\makebox[2 cm][b]{\hrulefill}\vskip 0 mm'. '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'. '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}}'; } elsif ($outputtarget eq 'export') { @@ -401,8 +432,7 @@ sub list_discussion { my $manifestfilename = $tempexport.$manifest; if ($manifestfile = Apache::File->new('>'.$manifestfilename)) { $manifestok=1; - print $manifestfile qq| - + print $manifestfile qq| - |; + |); $discussion.='
'. "\n".''; $discussion .= &action_links_bar($colspan,$ressymb,$visible, $newpostsflag,$group, - $prevread,$markondisp); + $prevread,$markondisp,$seehidden); my $escsymb=&escape($ressymb); my $numhidden = keys(%notshown); if ($numhidden > 0) { @@ -449,7 +478,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ $discussion.="\n".''; } $discussion .= (<'; + } } } - } else { + if (!(&discussion_open($status)) && ($outputtarget ne 'tex')) { + $discussion.= ''. + &mt('This discussion is closed.').''; + } + } elsif ($outputtarget ne 'tex') { $discussion.=''; + $discussion.= &send_message_link($ressymb).''; } return $discussion; } +sub can_see_hidden { + my ($mode,$ressymb,$feedurl,$group,$cdom,$cnum,$crs) = @_; + my $seehidden; + if ($env{'request.course.id'}) { + unless ($cdom ne '' && $cnum ne '') { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + } + if ($crs eq '') { + $crs = '/'.$env{'request.course.id'}; + if ($env{'request.course.sec'}) { + $crs.='_'.$env{'request.course.sec'}; + } + $crs=~s{_}{/}g; + } + if ($mode eq '') { + $mode='board'; + if ($feedurl =~ /$LONCAPA::assess_re/) { + $mode='problem'; + } + } + if (($group ne '') && ($mode eq 'board') && + ($ressymb =~ m{^bulletin___\d+\Q___adm/wrapper/adm/$cdom/$cnum/\E\d+/bulletinboard$})) { + if (&check_group_priv($group,'dgp') eq 'ok') { + $seehidden = 1; + } + } else { + $seehidden=&Apache::lonnet::allowed('rin',$crs); + } + } + return $seehidden; +} + +sub discussion_link { + my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds,$title) = @_; + my $link = ''; + return $link; +} + sub send_feedback_link { my ($ressymb,$target) = @_; my $output = ''. @@ -769,45 +863,54 @@ sub send_message_link { my $output = ''. ' '.&mt('Send Feedback').''; return $output; } sub action_links_bar { - my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_; + my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp, + $seehidden) = @_; my $discussion = ' - END $r->print(&Apache::loncommon::end_data_table_row()); @@ -1964,7 +2243,7 @@ END $r->print(<$lt{'dotm'} - + END my $save = &mt('Save'); $r->print(&Apache::loncommon::end_data_table_row()); @@ -1978,7 +2257,7 @@ END - + END if (exists($env{'form.group'})) { $r->print(''); @@ -2009,7 +2288,14 @@ sub print_sortfilter_options { my $group_sel = ''; my $numgroupvis = 5; my %sectioncount = &Apache::loncommon::get_sections(); - + my @courseroles = qw(st ad ep ta in); + my $crstype = &Apache::loncommon::course_type(); + my $ccrole = 'cc'; + if ($crstype eq 'Community') { + $ccrole = 'co'; + } + push(@courseroles,$ccrole); + if ($env{'request.course.sec'} !~ /^\s*$/) { #Restrict section choice to current section @sections = ('all',$env{'request.course.sec'}); $numvisible = 2; @@ -2072,7 +2358,7 @@ sub print_sortfilter_options { my %sort_types = (); my %role_types = (); my %status_types = (); - &sort_filter_names(\%sort_types,\%role_types,\%status_types); + &sort_filter_names(\%sort_types,\%role_types,\%status_types,$crstype); my $js = < @@ -2124,17 +2410,17 @@ $start_page

'. ''.&mt('Show all posts').' '.&mt('to display').' '. @@ -514,7 +543,6 @@ imscp_v1p1.xsd http://www.imsglobal.org/ $threadinsert='
Reply: '.$thisdepth.''; } $discussionitems[$alldiscussion{$post}]=~s/<\/td>]*)>/$threadinsert<\/td>
/; - $discussionitems[$alldiscussion{$post}]=~s/]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g; $discussionitems[$alldiscussion{$post}]=~s/(|<\/b>|<\/a>|]+)>)//g; $discussionitems[$alldiscussion{$post}]='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.$discussionitems[$alldiscussion{$post}]; @@ -529,11 +557,11 @@ imscp_v1p1.xsd http://www.imsglobal.org/ print $manifestfile "\n". ''. - ''.$imsitems{$alldiscussion{$post}}{'title'}.''; + ''.$imsitems{$alldiscussion{$post}}{'title'}.''; $imsresources .= "\n". ''."\n". ''."\n". - $imsfiles{$alldiscussion{$post}}{$imsitems{$alldiscussion{$post}}{'currversion'}}."\n". + $imsfiles{$alldiscussion{$post}}{$imsitems{$alldiscussion{$post}}{'currversion'}}.''."\n". ''; } my $postingfile; @@ -568,7 +596,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ + $lt{'cuse'}:
- $lt{'cuse'}:   END @@ -590,7 +618,7 @@ END   - $lt{'chgt'}? + $lt{'chgt'}?
@@ -600,7 +628,7 @@ END my %sort_types = (); my %role_types = (); my %status_types = (); - &sort_filter_names(\%sort_types,\%role_types,\%status_types); + &sort_filter_names(\%sort_types,\%role_types,\%status_types,$crstype); $discussion .= '
'.&mt('Sorted by').': '.$sort_types{$sortposts}.'
'; if (defined($env{'form.totposters'})) { @@ -645,7 +673,7 @@ END $discussion.='
'. ''."\n". ''."\n". + ' onclick="this.form.submit();" />'."\n". '
$lt{$discdisp} +
- +
$lt{$disctogg}
- - - - - - - - - - - + + + + + + + + + + + @@ -2188,7 +2475,7 @@ $start_page
- + END if (exists($env{'form.group'})) { $r->print(''); @@ -2211,24 +2498,11 @@ sub print_showposters { $r->send_http_header; &Apache::lonenc::check_encrypt(\$symb); - my $crs='/'.$env{'request.course.id'}; - if ($env{'request.course.sec'}) { - $crs.='_'.$env{'request.course.sec'}; - } - $crs=~s/\_/\//g; - my $seeid; my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; my $group = $env{'form.group'}; my $ressymb = &wrap_symb($symb); - if (($group ne '') && - ($ressymb =~ m|^bulletin___ \d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|)) { - if (&check_group_priv($group,'dgp') eq 'ok') { - $seeid = 1; - } - } else { - $seeid=&Apache::lonnet::allowed('rin',$crs); - } + my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum); my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, $cdom,$cnum); my %namesort = (); @@ -2244,7 +2518,7 @@ sub print_showposters { for (my $idx=1;$idx<=$contrib{'version'};$idx++) { my $hidden=($contrib{'hidden'}=~/\.$idx\./); my $deleted=($contrib{'deleted'}=~/\.$idx\./); - unless ((($hidden) && (!$seeid)) || ($deleted)) { + unless ((($hidden) && (!$seehidden)) || ($deleted)) { if ((!$contrib{$idx.':anonymous'}) || (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) { my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'}); my $lastname = $names{'lastname'}; @@ -2311,7 +2585,7 @@ END
- + $end_page END @@ -2383,7 +2657,7 @@ sub fail_redirect { my ($r,$feedurl) = @_; if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' }; my %lt = &Apache::lonlocal::texthash( - 'sorr' => 'Sorry, no recipients ...', + 'sorr' => 'Sorry, no recipients ...', ); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); $r->print(&Apache::loncommon::start_page('Feedback not sent',undef, @@ -2414,7 +2688,7 @@ sub redirect_back { if ($previous > 0) { $qrystr = 'previous='.$previous; if ($feedurl =~ /\?register=1/) { - $feedurl .= '&'.$qrystr; + $feedurl .= '&'.$qrystr; } else { $feedurl .= '?'.$qrystr; } @@ -2423,18 +2697,18 @@ sub redirect_back { if (defined($sort)) { my $sortqry = 'sortposts='.$sort; if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) { - $feedurl .= '&'.$sortqry; + $feedurl .= '&'.$sortqry; } else { $feedurl .= '?'.$sortqry; } $sorttag = ''; if (defined($numpicks)) { my $userpickqry = 'totposters='.$numpicks; - $feedurl .= '&'.$userpickqry; + $feedurl .= '&'.$userpickqry; $userpicktag = ''; } else { if (ref($sectionpick) eq 'ARRAY') { - $feedurl .= '§ionpick='; + $feedurl .= '&sectionpick='; $sectag .= ''; } else { - $feedurl .= '§ionpick='.$sectionpick; + $feedurl .= '&sectionpick='.$sectionpick; $sectag = ''; } if (ref($grouppick) eq 'ARRAY') { - $feedurl .= '&grouppick='; + $feedurl .= '&grouppick='; $sectag .= ''; } else { - $feedurl .= '&grouppick='.$grouppick; + $feedurl .= '&grouppick='.$grouppick; $grptag = ''; } if (ref($rolefilter) eq 'ARRAY') { - $feedurl .= '&rolefilter='; + $feedurl .= '&rolefilter='; $roletag .= ''; } else { - $feedurl .= '&rolefilter='.$rolefilter; + $feedurl .= '&rolefilter='.$rolefilter; $roletag = ''; } - $feedurl .= '&statusfilter='.$statusfilter; + $feedurl .= '&statusfilter='.$statusfilter; $statustag =''; } } @@ -2530,7 +2804,7 @@ ENDREDIR sub no_redirect_back { my ($r,$feedurl) = @_; - my $nofeed=&mt('Sorry, no feedback possible on this resource ...'); + my $nofeed=&mt('Sorry, no feedback possible on this resource ...'); my %onload; if ($env{'environment.remote'} ne 'off') { @@ -2543,7 +2817,7 @@ sub no_redirect_back { 'add_entries' => \%onload,); if ($feedurl !~ m{^/adm/feedback}) { - $body_options{'rediect'} = [2,$feedurl]; + $body_options{'redirect'} = [2,$feedurl]; } my $start_page= &Apache::loncommon::start_page('Feedback not sent',undef, @@ -2563,7 +2837,23 @@ ENDNOREDIRTWO } sub screen_header { - my ($feedurl,$symb) = @_; + my ($feedurl,$symb,$group) = @_; + my $crscontent = &mt('Question/Comment/Feedback about course content'); + my $crspolicy = &mt('Question/Comment/Feedback about course policy'); + my $contribdisc = &mt('Contribution to course discussion of resource'); + my $anoncontrib = &mt('Anonymous contribution to course discussion of resource'); + my $namevis = &mt('name only visible to course faculty'); + my $crstype; + if ($env{'request.course.id'}) { + $crstype = &Apache::loncommon::course_type(); + if ($crstype eq 'Community') { + $crscontent = &mt('Question/Comment/Feedback about community content'); + $crspolicy = &mt('Question/Comment/Feedback about community policy'); + $contribdisc = &mt('Contribution to community discussion of resource'); + $anoncontrib = &mt('Anonymous contribution to community discussion of resource'); + $namevis = &mt('name only visible to community facilitators'); + } + } my $msgoptions=''; my $discussoptions=''; unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) { @@ -2584,42 +2874,46 @@ sub screen_header { if (&feedback_available(0,1)) { $msgoptions.= '

'; } if (&feedback_available(0,0,1)) { $msgoptions.= '

'; } } if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) { my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards'); - if (!$blocked && &discussion_open(undef,$symb) && - &Apache::lonnet::allowed('pch', + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $realsymb = &get_realsymb($symb); + if (!$blocked && &discussion_open(undef,$realsymb) && + (&Apache::lonnet::allowed('pch', $env{'request.course.id'}. - ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) || + (($group ne '') && ($symb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$}) && (&check_group_priv($group,'pgd') eq 'ok')))) { $discussoptions='
'. + $contribdisc. + '
'. ''.&mt('Change Screenname').''; my $blockblog = &Apache::loncommon::blocking_status('blogs'); if (!$blockblog) { - $discussoptions.= &add_blog_checkbox(); + $discussoptions.= &add_blog_checkbox($crstype); } } } if ($msgoptions) { - $msgoptions='

' - .' '.&mt('Send Feedback').'

' + $msgoptions='

' + .' '.&mt('Send Feedback').'

'.&Apache::lonhtmlcommon::coursepreflink(&mt('Feedback Settings'),'feedback').'

' .$msgoptions; } if ($discussoptions) { - $discussoptions='

' - .' '.&mt('Discussion Contributions').'

' + $discussoptions='

' + .' '.&mt('Discussion Contributions').'

'.&Apache::lonhtmlcommon::coursepreflink(&mt('Discussion Settings'),'discussion').'

' .$discussoptions; } return $msgoptions.$discussoptions; @@ -2639,9 +2933,7 @@ sub resource_output { } sub clear_out_html { - my ($message,$override,$ignore_htmlarea)=@_; - if (!$ignore_htmlarea - && !&Apache::lonhtmlcommon::htmlareablocked()) { return $message; } + my ($message,$override)=@_; # Always allow the -tag my %html=(M=>1); # Check if more is allowed @@ -2650,11 +2942,12 @@ sub clear_out_html { ($override)) { # allows


      • #

        - # + #

  • $lt{'soor'} $lt{'sprs'} $lt{'spur'} $lt{'spse'} $lt{'spgr'} $lt{'psub'}$lt{'soor'} $lt{'sprs'} $lt{'spur'} $lt{'spse'} $lt{'spgr'} $lt{'psub'}
    @@ -2161,10 +2447,11 @@ $start_page
    %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1, - BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1, - M=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1, - H1=>1, H2=>1, H3=>1, H4=>1, H5=>1); + BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, PRE=>1, DIV=>1, IMG=>1, + M=>1, CHEM=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1, + H1=>1, H2=>1, H3=>1, H4=>1, H5=>1, H6=>1, + TABLE=>1, TR=>1, TD=>1, TH=>1, TBODY=>1); } # Do the substitution of everything that is not explicitly allowed $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/ @@ -2671,6 +2964,9 @@ sub assemble_email { 'orig' => 'Original screen output (if applicable)', 'corr' => 'Correct Answer(s) (if applicable)', ); + if (&Apache::loncommon::course_type() eq 'Community') { + $lt{'prev'} = &mt('Previous attempts of member (if applicable)'); + } my $email=<<"ENDEMAIL"; $message ENDEMAIL @@ -2735,18 +3031,41 @@ sub send_msg { return ($status,$sendsomething); } +# Store feedback "likes" + +sub storefeedbacklikes { + my ($likes,$uname,$udom,$course)=@_; + unless ($likes) { $likes=0; } + if ($likes>0) { $likes=1; } + if ($likes<0) { $likes=-1; } + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my %record=&getfeedbackrecords($uname,$udom,$course); + my $totallikes=$record{'totallikes'}; + $totallikes+=$likes; + my %newrecord=('likes_user' => $env{'user.name'}, + 'likes_domain' => $env{'user.domain'}, + 'likes' => $likes, + 'totallikes' => $totallikes); + return &Apache::lonnet::cstore(\%newrecord,'_feedback',$course,$udom,$uname); +} + sub adddiscuss { - my ($symb,$email,$anon,$attachmenturl,$subject)=@_; + my ($symb,$email,$anon,$attachmenturl,$subject,$group)=@_; my $status=''; - my $realsymb; - if ($symb=~/^bulletin___/) { - my $filename=(&Apache::lonnet::decode_symb($symb))[2]; - $filename=~s|^adm/wrapper/||; - $realsymb=&Apache::lonnet::symbread($filename); + my $realsymb = &get_realsymb($symb); + my ($cnum,$cdom); + if ($env{'request.course.id'}) { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; } + my $realsymb; if (&discussion_open(undef,$realsymb) && - &Apache::lonnet::allowed('pch',$env{'request.course.id'}. - ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + (&Apache::lonnet::allowed('pch',$env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) || + (($group ne '') && (&check_group_priv($group,'pgd') eq 'ok') && + ($symb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$})))) { my %contrib=('message' => $email, 'sendername' => $env{'user.name'}, @@ -2826,7 +3145,7 @@ sub adddiscuss { $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); } - my %record=&Apache::lonnet::restore('_discussion'); + my %record=&getdiscussionrecords(); my ($temp)=keys(%record); unless ($temp=~/^error\:/) { my %newrecord=(); @@ -2834,6 +3153,7 @@ sub adddiscuss { $newrecord{'subnumber'}=$record{'subnumber'}+1; $status.='
    '.&mt('Registering').': '. &Apache::lonnet::cstore(\%newrecord,'_discussion'); + &updatekarma(); } } else { $status.='Failed.'; @@ -2841,6 +3161,107 @@ sub adddiscuss { return $status.'
    '; } +# Routine to get the complete discussion records + +sub getdiscussionrecords { + my ($uname,$udom,$course)=@_; + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my %record=&Apache::lonnet::restore('_discussion',$course,$udom,$uname); + return %record; +} + +# Routine to get discussion statistics + +sub getdiscussionstats { + my %record=&getdiscussionrecords(@_); + my $totalvotes = $record{'totallikes'} + $record{'totalunlikes'}; + return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$totalvotes); +} + +# Calculate discussion karma + +sub calcdiscussionkarma { + my ($subs,$pts,$likes,$votes)=&getdiscussionstats(@_); + my $karma=0; + if ($votes>0) { + $karma=int(.1+5.*(1.-exp(-$subs/10.))*$likes/$votes); + if ($karma<0) { $karma=0; } + if ($karma>5) { $karma=5; } + } + return $karma; +} + +# Update karma + +sub updatekarma { + my ($uname,$udom,$course)=@_; + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my $karma=&calcdiscussionkarma($uname,$udom,$course); + &Apache::lonnet::cstore({ 'karma' => $karma },'_discussion',$course,$udom,$uname); + &Apache::lonnet::do_cache_new('karma',$uname.':'.$udom.':'.$course,$karma,3600); + return $karma; +} + +# Retrieve karma + +sub userkarma { + my ($uname,$udom,$course)=@_; + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my $hashkey=$uname.':'.$udom.':'.$course; + my ($karma,$cached)=&Apache::lonnet::is_cached_new('karma',$hashkey); + if ($cached) { + return $karma; + } + my %userdisc=&getdiscussionrecords($uname,$udom,$course); + $karma=$userdisc{'karma'}; + &Apache::lonnet::do_cache_new('karma',$hashkey,$karma,3600); + return $karma; +} + +# Store discussion credit + +sub storediscussionpoints { + my ($points,$uname,$udom,$course)=@_; + unless ($points) { $points=0; } + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my %record=('grader_user' => $env{'user.name'}, + 'grader_domain' => $env{'user.domain'}, + 'points' => $points); + return &Apache::lonnet::cstore(\%record,'_discussion',$course,$udom,$uname); +} + +# Store discussion "likes" + +sub storediscussionlikes { + my ($chglikes,$chgunlikes,$uname,$udom,$course,$context)=@_; + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my %record=&getdiscussionrecords($uname,$udom,$course); + my $totallikes=$record{'totallikes'}; + my $totalunlikes=$record{'totalunlikes'}; + $totallikes += $chglikes; + $totalunlikes += $chgunlikes; + my %newrecord=('likes_user' => $env{'user.name'}, + 'likes_domain' => $env{'user.domain'}, + 'totallikes' => $totallikes, + 'totalunlikes' => $totalunlikes, + 'context' => $context); + my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname); + if ($status eq 'ok') { + &updatekarma($uname,$udom,$course); + } + return $status; +} + sub get_discussion_info { my ($idx,%contrib) = @_; my $changelast = 0; @@ -2897,7 +3318,7 @@ sub show_preview { &newline_to_br(\$message); $message=&Apache::lonspeller::markeduptext($message); $message=&Apache::lontexconvert::msgtexconverted($message); - my $subject=&clear_out_html($env{'form.subject'},undef,1); + my $subject=&clear_out_html($env{'form.subject'}); $subject=~s/\n/\
    /g; $subject=&Apache::lontexconvert::msgtexconverted($subject); @@ -2917,6 +3338,31 @@ sub show_preview { ); } +sub contains_block_html { + my ($message)=@_; + return ($message =~ m{ + <(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div) + \s* + (\w+\=['"]\w+['"])* + \s* + ( + \s*/>| + >.* + )}xs + ); +} + +sub tidy_html { + my ($message)=@_; +# my $tidy = HTML::Tidy::libXML->new(); +# my $xhtml = $tidy->clean($message, 'utf-8', 1); +# $xhtml =~ m/(.*)<\/body>/is; +# my $clean = $1; +# # remove any empty block-level tags +# $clean =~ s/<(table|p|div|tbody|blockquote|m|pre|algebra|center|ol|ul|span|h1|h2|h3|h4|h5|h6)\s*\/>//i; +# $message=$clean; + return $message; +} sub newline_to_br { my ($message)=@_; @@ -2950,7 +3396,7 @@ sub generate_preview_button { +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();" /> ENDPREVIEW } @@ -2976,11 +3422,15 @@ sub modify_attachments { END + # Breadcrumbs + my $brcrum = [{'href' => '', + 'text' => 'Discussion Post Attachments'}]; my $start_page = - &Apache::loncommon::start_page('Discussion Post Attachments',$js); + &Apache::loncommon::start_page('Discussion Post Attachments',$js, + {'bread_crumbs' => $brcrum,}); my $orig_subject = &unescape($env{'form.subject'}); - my $subject=&clear_out_html($orig_subject,undef,1); + my $subject=&clear_out_html($orig_subject); $subject=~s/\n/\
    /g; $subject=&Apache::lontexconvert::msgtexconverted($subject); my $timestamp=$env{'form.timestamp'}; @@ -3005,7 +3455,7 @@ $toolarge
    @@ -3056,7 +3506,7 @@ END $r->print(''."\n"); } $r->print(< + $end_page END @@ -3103,7 +3553,7 @@ sub generate_attachments_button {
    $lt{'clic'}: 
    -
    '."\n"; +
    '."\n"; return $output; } @@ -3287,8 +3743,9 @@ sub has_discussion { } sub sort_filter_names { - my ($sort_types,$role_types,$status_types) = @_; - %{$sort_types} = ( + my ($sort_types,$role_types,$status_types,$crstype) = @_; + if (ref($sort_types) eq 'HASH') { + %{$sort_types} = ( ascdate => 'Date order - oldest first', descdate => 'Date order - newest first', thread => 'Threaded', @@ -3296,22 +3753,28 @@ sub sort_filter_names { username => 'By domain and username', lastfirst => 'By last name, first name' ); - %{$role_types} = ( - all => 'All roles', - st => 'Students', - cc => 'Course Coordinators', - in => 'Instructors', - ta => 'TAs', - ep => 'Exam proctors', - ad => 'Administrators', - cr => 'Custom roles' - ); - %{$status_types} = ( + } + my @courseroles = qw(st in ta ep ad); + if ($crstype eq 'Community') { + push(@courseroles,'co'); + } else { + push(@courseroles,'cc'); + } + if (ref($role_types) eq 'HASH') { + foreach my $role (@courseroles) { + $role_types->{$role} = &Apache::lonnet::plaintext($role,$crstype); + } + $role_types->{'all'} = 'All roles'; + $role_types->{'cr'} = 'Custom role'; + } + if (ref($status_types) eq 'HASH') { + %{$status_types} = ( all => 'Roles of any status', Active => 'Only active roles', Expired => 'Only past roles', Future => 'Only future roles', ); + } } sub handler { @@ -3325,14 +3788,16 @@ sub handler { # --------------------------- Get query string for limited number of parameters &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['hide','unhide','deldisc','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']); + ['like','unlike','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']); my $group = $env{'form.group'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; my %attachmax = ( text => &mt('(128 KB max size)'), num => 131072, ); if ($env{'form.editdisc'}) { - if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) { + if (!(&editing_allowed($env{'form.editdisc'},$group))) { my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0]; my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); my $feedurl=&Apache::lonnet::clutter($url); @@ -3373,38 +3838,32 @@ sub handler { &Apache::loncommon::no_cache($r); $r->send_http_header; - $r->print(&Apache::loncommon::start_page('Discussion Post Versions')); + # Breadcrumbs + my $brcrum = [{'href' => '', + 'text' => 'Discussion Post Versions'}]; + + $r->print(&Apache::loncommon::start_page('Discussion Post Versions',undef, + {'bread_crumbs' => $brcrum,}) + ); - my $crs='/'.$env{'request.course.id'}; - if ($env{'request.course.sec'}) { - $crs.='_'.$env{'request.course.sec'}; - } - $crs=~s|_|/|g; - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; my ($symb,$idx)=split(/\:\:\:/,$env{'form.allversions'}); - ($symb)=&get_feedurl_and_clean_symb($symb); + ($symb, my $feedurl)=&get_feedurl_and_clean_symb($symb); my $ressymb = &wrap_symb($symb); - my $group = $env{'form.group'}; my $seeid; - if (($group ne '') && (($ressymb =~ m|^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$|))) { - if (&check_group_priv($group,'dgp') eq 'ok') { - $seeid = 1; - } - } else { - $seeid = &Apache::lonnet::allowed('rin',$crs); + if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) { + $seeid = 1; } + my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum); if ($idx > 0) { my %messages = (); my %subjects = (); my %attachmsgs = (); my %allattachments = (); my %imsfiles = (); - my ($screenname,$plainname); + my ($screenname,$plainname,$showaboutme); my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); - $r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname)); + $cdom,$cnum); + $r->print(&get_post_contents(\%contrib,$idx,$seeid,$seehidden,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname,\$showaboutme)); } $r->print(&Apache::loncommon::end_page()); return OK; @@ -3546,37 +4005,32 @@ ENDREDIR my $entry=$env{'form.hide'}?$env{'form.hide'}:$env{'form.unhide'}; my ($symb,$idx)=split(/\:\:\:/,$entry); ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); + my $ressymb = &wrap_symb($symb); - my $crs='/'.$env{'request.course.id'}; - if ($env{'request.course.sec'}) { - $crs.='_'.$env{'request.course.sec'}; - } - $crs=~s/\_/\//g; - my $seeid=&Apache::lonnet::allowed('rin',$crs); - - if ($env{'form.hide'} && !$seeid && !(&editing_allowed($env{'form.hide'},$env{'form.group'}))) { - &redirect_back($r,$feedurl,&mt('Deletion not permitted').'
    ', '0','0','','',$env{'form.previous'},'','','','', - undef,undef,$group,); + my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum); + unless (($seehidden) || (&editing_allowed($env{'form.hide'},$group))) { + &redirect_back($r,$feedurl,&mt('Hiding not permitted').'
    ', + '0','0','','',$env{'form.previous'},'','','','', + undef,undef,$group,); return OK; } my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); my $currenthidden=$contrib{'hidden'}; my $currentstudenthidden=$contrib{'studenthidden'}; if ($env{'form.hide'}) { $currenthidden.='.'.$idx.'.'; - unless ($seeid) { + unless ($seehidden) { $currentstudenthidden.='.'.$idx.'.'; } } else { $currenthidden=~s/\.$idx\.//g; } my %newhash=('hidden' => $currenthidden); - if ( ($env{'form.hide'}) && (!$seeid) ) { + if ( ($env{'form.hide'}) && (!$seehidden) ) { $newhash{'studenthidden'} = $currentstudenthidden; } if ($env{'form.hide'}) { @@ -3585,16 +4039,195 @@ ENDREDIR ($changelast,$newlast) = &get_discussion_info($idx,%contrib); if ($changelast) { &Apache::lonnet::put('discussiontimes',{$symb => $newlast}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); } } - &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + my $result; + if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, + $cdom,$cnum) eq 'ok') { + my $prefix=$symb.':'.$idx.':'; + my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum, + '^'.$prefix); + my ($totallikes,$totalunlikes); + if (ref($likes{$prefix.'likers'}) eq 'HASH') { + $totallikes = scalar(keys(%{$likes{$prefix.'likers'}})); + } + if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { + $totalunlikes = scalar(keys(%{$likes{$prefix.'unlikers'}})); + } + if ($totallikes || $totalunlikes) { + my ($chglikes,$chgunlikes,$context); + if ($env{'form.hide'}) { + $chglikes = -1 * $totallikes; + $chgunlikes = -1 * $totalunlikes; + $context = 'hide'; + } else { + $chglikes = $totallikes; + $chgunlikes = $totalunlikes; + $context = 'unhide'; + } + &storediscussionlikes($chglikes,$chgunlikes, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}, + $env{'request.course.id'}, + $context); - &redirect_back($r,$feedurl,&mt('Changed discussion status').'
    ', - '0','0','','',$env{'form.previous'},undef,undef,undef, + } + $result = &mt('Changed discussion status'); + } else { + $result = &mt('Discussion status unchanged'); + } + &redirect_back($r,$feedurl,$result.'
    ','0','0','','', + $env{'form.previous'},undef,undef,undef, + undef,undef,undef,$group); + return OK; + } elsif (($env{'form.like'}) || ($env{'form.unlike'})) { +# ----------------------------------------------------------------- Like/unlike + my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'}; + my ($symb,$idx)=split(/\:\:\:/,$entry); + ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); + my $result; + if ($idx > 0) { + my $realsymb = &get_realsymb($symb); + my $status='OPEN'; + if ($Apache::lonhomework::parsing_a_problem || + $Apache::lonhomework::parsing_a_task) { + $status=$Apache::inputtags::status[-1]; + } + if (&discussion_vote_available($status,$realsymb)) { + my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, + $cdom,$cnum); + my $ownpost; + if (($contrib{$idx.':sendername'} eq $env{'user.name'}) && + ($contrib{$idx.':senderdomain'} eq $env{'user.domain'})) { + $ownpost = 1; + } + if ($ownpost || $contrib{$idx.':hidden'} || $contrib{$idx.':deleted'}) { + $result = &mt('Vote not registered.').' '; + } + if ($ownpost) { + $result .= &mt('No voting for your own posts.'); + } elsif ($contrib{$idx.':hidden'}) { + $result .= &mt('No voting for hidden posts.'); + } elsif ($contrib{$idx.':deleted'}) { + $result .= &mt('No voting for deleted posts.'); + } else { +# +# Likes and unlikes are in db-file "disclikes" of the course +# The prefix is the $symb to identify the resource discussion, +# and the $idx to identify the entry +# + my $prefix=$symb.':'.$idx.':'; + my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum, + '^'.$prefix); + +# Get current like or unlike status for the $idx for this user. + my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; + my ($userlikes,$userunlikes); + if (ref($likes{$prefix.'likers'}) eq 'HASH') { + if (exists($likes{$prefix.'likers'}{$thisuser})) { + $userlikes = 1; + } + } + if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { + if (exists($likes{$prefix.'unlikers'}{$thisuser})) { + $userunlikes = 1; + } + } +# Get the current "likes" count + my $likescount=$likes{$prefix.'likes'}; +# Find out if they already voted +# Users cannot like a post twice, or unlike it twice. +# They can change their mind, though. + my $alreadyflag=0; + my $votetype; + if ($env{'form.like'}) { + if ($userlikes) { + $alreadyflag=1; + } elsif ($userunlikes) { + delete($likes{$prefix.'unlikers'}{$thisuser}); + $votetype = 'switch'; + $likescount++; + } else { + if (ref($likes{$prefix.'likers'}) eq 'HASH') { + $likes{$prefix.'likers'}{$thisuser} = 1; + } else { + $likes{$prefix.'likers'} = {$thisuser => 1}; + } + $likescount++; + } + } else { + if ($userunlikes) { + $alreadyflag=1; + } elsif ($userlikes) { + delete($likes{$prefix.'likers'}{$thisuser}); + $votetype = 'switch'; + $likescount--; + } else { + if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { + $likes{$prefix.'unlikers'}{$thisuser} = 1; + } else { + $likes{$prefix.'unlikers'} = {$thisuser => 1}; + } + $likescount--; + } + } +# $alreadyflag would be 1 if they tried to double-like or double-unlike + if ($alreadyflag) { + if ($env{'form.like'}) { + $result= &mt("'Like' already registered"); + } else { + $result= &mt("'Unlike' already registered"); + } + } else { + my %newhash=($prefix.'likes' => $likescount, + $prefix.'likers' => $likes{$prefix.'likers'}, + $prefix.'unlikers' => $likes{$prefix.'unlikers'}); +# Store data in db-file "disclikes" + if (&Apache::lonnet::put('disclikes',\%newhash,$cdom,$cnum) eq 'ok') { +# Also store with the person who posted the liked/unliked entry + my ($chglike,$chgunlike); + if ($env{'form.like'}) { + if ($votetype eq 'switch') { + $chglike = 0; + $chgunlike = -1; + } else { + $chglike = 1; + $chgunlike = 0; + } + &storediscussionlikes($chglike,$chgunlike, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}, + $env{'request.course.id'},'like'); + $result=&mt("Registered 'Like'"); + } else { + if ($votetype eq 'switch') { + $chglike = -1; + $chgunlike = 0; + } else { + $chglike = 0; + $chgunlike = 1; + } + &storediscussionlikes($chglike,$chgunlike, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}, + $env{'request.course.id'},'unlike'); + $result=&mt("Registered 'Unlike'"); + } + } else { +# Oops, something went wrong + $result=&mt("Failed to register vote"); + } + } + } + } else { + $result=&mt('Voting unavailable for this discussion'); + } + } else { + $result=&mt('Invalid post number'); + } + &redirect_back($r,$feedurl,$result.'
    ', + '0','0','','',$env{'form.previous'},undef,undef,undef, undef,undef,undef,$group); return OK; } elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) { @@ -3614,20 +4247,50 @@ ENDREDIR # --------------------------------------------------------------- Hide for good my ($symb,$idx)=split(/\:\:\:/,$env{'form.deldisc'}); ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); + my $ressymb=&wrap_symb($symb); + unless (&can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum)) { + &redirect_back($r,$feedurl,&mt('Deletion not permitted').'
    ', + '0','0','','',$env{'form.previous'},'','','','', + undef,undef,$group); + return OK; + } my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); my ($changelast,$newlast) = &get_discussion_info($idx,%contrib); if ($changelast) { &Apache::lonnet::put('discussiontimes',{$symb => $newlast}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); } my %newhash=('deleted' => $contrib{'deleted'}.".$idx."); - &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); - &redirect_back($r,$feedurl,&mt('Changed discussion status').'
    ', - '0','0','','',$env{'form.previous'},undef,undef,undef, + + my $result; + if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, + $cdom,$cnum) eq 'ok') { + $result = &mt('Changed discussion status'); + my $prefix=$symb.':'.$idx.':'; + my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum, + '^'.$prefix); + my ($totallikes,$totalunlikes); + if (ref($likes{$prefix.'likers'}) eq 'HASH') { + $totallikes = scalar(keys(%{$likes{$prefix.'likers'}})); + } + if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { + $totalunlikes = scalar(keys(%{$likes{$prefix.'unlikers'}})); + } + if ($totallikes || $totalunlikes) { + my $chglikes = -1 * $totallikes; + my $chgunlikes = -1 * $totalunlikes; + &storediscussionlikes($chglikes,$chgunlikes, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}, + $env{'request.course.id'}, + 'delete'); + } + } else { + $result = &mt('Discussion status unchanged'); + } + &redirect_back($r,$feedurl,$result.'
    ','0','0','','', + $env{'form.previous'},undef,undef,undef, undef,undef,undef,$group); return OK; } elsif ($env{'form.preview'}) { @@ -3655,8 +4318,7 @@ ENDREDIR my $idx = $env{'form.idx'}; if ($idx) { my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $cdom,$cnum); $attachmenturls = $contrib{$idx.':attachmenturl'}; } &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx, @@ -3680,6 +4342,55 @@ ENDREDIR &Apache::loncommon::end_page(); $r->print($start_page.$discussion.$end_page); return OK; + } elsif ($env{'form.undeleteall'}) { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.undeleteall'}); + my $ressymb=&wrap_symb($symb); + $r->print(&Apache::loncommon::start_page('Undelete all deleted discussion entries')); + if (&can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum)) { + my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, + $cdom,$cnum); + $contrib{'deleted'} =~ s/^\.//; + $contrib{'deleted'} =~ s/\.$//; + if ($contrib{'deleted'} ne '') { + if (&Apache::lonnet::store({'deleted' => ''},$symb,$env{'request.course.id'}, + $cdom,$cnum) eq 'ok') { + my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,'^'.$symb.':'); + my @ids = split(/\.\./,$contrib{'deleted'}); + my (%chglikes,%chgunlikes); + foreach my $idx (@ids) { + my $uname = $contrib{$idx.':sendername'}; + my $udom = $contrib{$idx.':senderdomain'}; + my ($totallikes,$totalunlikes); + if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') { + $totallikes = scalar(keys(%{$likes{$symb.':'.$idx.':likers'}})); + } + if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') { + $totalunlikes = scalar(keys(%{$likes{$symb.':'.$idx.':unlikers'}})); + } + if ($totallikes || $totalunlikes) { + $chglikes{$uname.':'.$udom} += $totallikes; + $chgunlikes{$uname.':'.$udom} += $totalunlikes; + } + } + foreach my $user (keys(%chglikes)) { + my ($uname,$udom) = split(/:/,$user); + &storediscussionlikes($chglikes{$user},$chgunlikes{$user}, + $uname,$udom,$env{'request.course.id'}, + 'undelete'); + } + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries"))); + } else { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1)); + } + } else { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("No entries to undelete"),1)); + } + $r->print("
    ".&mt("Return and reload").""); + } + $r->print(&Apache::loncommon::end_page()); + return OK; } else { # ------------------------------------------------------------- Normal feedback my $feedurl=$env{'form.postdata'}; @@ -3694,7 +4405,7 @@ ENDREDIR } elsif ($env{'form.editdisc'}) { $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0]; } elsif ($env{'form.origpage'}) { - $symb=""; + $symb=""; } else { $symb=&Apache::lonnet::symbread($feedurl); } @@ -3747,7 +4458,7 @@ ENDREDIR return OK; } } - my $options=&screen_header($feedurl,$symb); + my $options=&screen_header($feedurl,$symb,$group); if ($options) { &mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'}); } else { @@ -3803,7 +4514,12 @@ ENDREDIR } } # Filter HTML out of message (could be nasty) - my $message=&clear_out_html($env{'form.comment'}); + my $override; + if ($env{'form.discuss'} =~ /^(?:author|question|course|policy)$/) { + $override = 1; + } + my $message=&clear_out_html($env{'form.comment'},$override); + # Assemble email my ($email,$citations)=&assemble_email($message,$prevattempts, @@ -3813,8 +4529,7 @@ ENDREDIR my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl); # Actually send mail - my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}, - undef,1), + my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}), $feedurl,$email,$citations, $attachmenturl,$usersymb,%to); @@ -3823,10 +4538,10 @@ ENDREDIR if ( ($env{'form.discuss'} ne '' && $env{'form.discuss'} !~ /^(?:author|question|course|policy)/) || $env{'form.anondiscuss'} ne '') { - my $subject = &clear_out_html($env{'form.subject'},undef,1); + my $subject = &clear_out_html($env{'form.subject'}); my $anonmode=($env{'form.discuss'} eq 'anon' || $env{'form.anondiscuss'} ); $typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl, - $subject); + $subject,$group); $numpost++; } @@ -3834,12 +4549,16 @@ ENDREDIR my $blog=''; if ($env{'form.blog'}) { - my $subject = &clear_out_html($env{'form.subject'},undef,1); + my $subject = &clear_out_html($env{'form.subject'}); $status.=&Apache::lonrss::addentry($env{'user.name'}, $env{'user.domain'}, 'CourseBlog_'.$env{'request.course.id'}, $subject,$message,$feedurl,'public'); - $blog='
    '.&mt('Added to my course blog').'
    '; + if (&Apache::loncommon::course_type() eq 'Community') { + $blog='
    '.&mt('Added to my community blog').'
    '; + } else { + $blog='
    '.&mt('Added to my course blog').'
    '; + } } # Receipt screen and redirect back to where came from @@ -3866,6 +4585,7 @@ sub wrap_symb { } return $ressymb; } + sub dewrapper { my ($feedurl)=@_; if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) { @@ -4019,8 +4739,16 @@ None =item discussion_visible() +=item discussion_vote_available() + +=item get_realsymb() + =item list_discussion() +=item can_see_hidden() + +=item discussion_link() + =item send_feedback_link() =item send_message_link() @@ -4075,6 +4803,8 @@ None =item newline_to_br() +=item tidy_html() + =item generate_preview_button() =item modify_attachments()
    - Subject: $subject

    + Subject: $subject

    END if ($idx) { if ($attachmenturls) { @@ -3033,7 +3483,7 @@ END
    - $lt{'adda'} + $lt{'adda'}