--- loncom/interface/lonfeedback.pm 2005/04/11 15:29:38 1.161 +++ loncom/interface/lonfeedback.pm 2006/01/11 08:31:37 1.178 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.161 2005/04/11 15:29:38 albertel Exp $ +# $Id: lonfeedback.pm,v 1.178 2006/01/11 08:31:37 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -39,12 +39,14 @@ use Apache::lonnet; use Apache::lonhtmlcommon(); use Apache::lonnavmaps; use Apache::lonenc(); +use Apache::lonrss(); use HTML::LCParser(); use Apache::lonspeller(); use Cwd; sub discussion_open { my ($status,$symb)=@_; + if ($env{'request.role.adv'}) { return 1; } if (defined($status) && !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER' || $status eq 'OPEN')) { @@ -97,7 +99,7 @@ sub list_discussion { $ressymb=&wrap_symb($ressymb); my $encsymb=&Apache::lonenc::check_encrypt($ressymb); my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs) - && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form)$/)); + && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form|task)$/)); my %usernamesort = (); my %namesort =(); @@ -113,7 +115,7 @@ sub list_discussion { my $toggkey = $ressymb.'_readtoggle'; my $readkey = $ressymb.'_read'; $ressymb=$encsymb; - my %dischash = &Apache::lonnet::get('nohist_'.$env{'request.course.id'}.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$env{'user.domain'},$env{'user.name'}); + my %dischash = &Apache::lonnet::get('nohist_'.$cid.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$env{'user.domain'},$env{'user.name'}); my %discinfo = (); my $showonlyunread = 0; my $showunmark = 0; @@ -154,7 +156,9 @@ sub list_discussion { my %roleshash = (); my %roleinfo = (); if ($env{'form.rolefilter'}) { - %roleshash = &Apache::lonnet::dump('nohist_userroles',$env{'course.'.$env{'request.course.id'}.'.domain'},$env{'course.'.$env{'request.course.id'}.'.num'}); + %roleshash = &Apache::lonnet::dump('nohist_userroles', + $env{'course.'.$cid.'.domain'}, + $env{'course.'.$cid.'.num'}); foreach (keys %roleshash) { my ($role,$uname,$udom,$sec) = split/:/,$_; if ($role =~ /^cr/) { @@ -171,9 +175,8 @@ sub list_discussion { } } my ($classlist) = &Apache::loncoursedata::get_classlist( - $env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + $env{'course.'.$cid.'.domain'}, + $env{'course.'.$cid.'.num'}); my $sec_index = &Apache::loncoursedata::CL_SECTION(); my $status_index = &Apache::loncoursedata::CL_STATUS(); while (my ($student,$data) = each %$classlist) { @@ -235,7 +238,8 @@ sub list_discussion { my %notshown = (); my %newitem = (); my $maxdepth=0; - + my %anonhash=(); + my $anoncnt=0; my $target=''; unless ($env{'browser.interface'} eq 'textual' || $env{'environment.remote'} eq 'off' ) { @@ -245,8 +249,8 @@ sub list_discussion { my $now = time; $discinfo{$visitkey} = $visit; - &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_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,$statusfilter,$toggkey,$outputtarget); + &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,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt); my $discussion=''; my $manifestfile; @@ -390,19 +394,20 @@ imscp_v1p1.xsd http://www.imsglobal.org/ $discussion.='
'; $discussion .='
'. ''; + my $escsymb=&Apache::lonnet::escape($ressymb); if ($visible>2) { $discussion.=''; if ($newpostsflag) { if (!$markondisp) { - $discussion .=''; } @@ -430,7 +437,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ if ($numhidden > 0) { my $colspan = $maxdepth+1; $discussion.="\n".'
'. - '  '. - '   -   '.&mt('Mark NEW posts no longer new').'  '; + $discussion .=''. + &mt('Preferences on what is marked as NEW'). + '
'.&mt('Mark NEW posts no longer new').''; } else { $discussion .= '
 
'. - ''. + &Apache::lonnet::escape($ressymb).':::" '.$target.'>'. ''. &mt('Post Discussion').'
'; } @@ -753,10 +760,11 @@ ENDDISCUSS } sub build_posting_display { - my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$statusfilter,$toggkey,$outputtarget) = @_; + my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt) = @_; my @original=(); my @index=(); my $symb=&Apache::lonenc::check_decrypt($ressymb); + my $escsymb=&Apache::lonnet::escape($ressymb); my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); @@ -820,6 +828,13 @@ sub build_posting_display { my %allattachments = (); my ($screenname,$plainname); my $sender = &mt('Anonymous'); +# Anonymous users getting number within a discussion +# Since idx is in static order, this should give the same sequence every time. + my $key=$contrib{$idx.':sendername'}.'@'.$contrib{$idx.':senderdomain'}; + unless ($$anonhash{$key}) { + $anoncnt++; + $$anonhash{$key}=&mt('Anonymous').' '.$anoncnt; + } my ($message,$subject,$vgrlink,$ctlink); &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver); @@ -858,7 +873,7 @@ sub build_posting_display { $contrib{$idx.':sendername'}.' at '. $contrib{$idx.':senderdomain'}.')'; if ($contrib{$idx.':anonymous'}) { - $sender.=' ['.&mt('anonymous').'] '. + $sender.=' ['.$$anonhash{$key}.'] '. $screenname; } @@ -894,13 +909,13 @@ sub build_posting_display { if ($env{'course.'.$env{'request.course.id'}.'.allow_discussion_post_editing'} =~ m/yes/i) { if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { $sender.=' '.&mt('Edit').''; unless ($seeid) { - $sender.=" '; } } @@ -909,7 +924,7 @@ sub build_posting_display { if ($hidden) { unless ($studenthidden) { $sender.=' '; } $sender.=' '.&mt('Display all versions').''; + $$discussionitems[$idx] .= '  '.&mt('Display all versions').''; } $$discussionitems[$idx].='
'.&mt('Earlier version(s) were posted on: '); if ($contrib{$idx.':history'} =~ m/:/) { @@ -1164,11 +1181,11 @@ sub get_post_contents { # $$screenname=&Apache::loncommon::screenname( # $$contrib{$idx.':sendername'}, # $$contrib{$idx.':senderdomain'}); -# $$plainname=&Apache::loncommon::nickname( -# $$contrib{$idx.':sendername'}, -# $$contrib{$idx.':senderdomain'}); - ($$screenname,$$plainname)=($$contrib{$idx.':screenname'}, - $$contrib{$idx.':plainname'}); + $$plainname=&Apache::loncommon::nickname( + $$contrib{$idx.':sendername'}, + $$contrib{$idx.':senderdomain'}); + $$screenname=$$contrib{$idx.':screenname'}; + my $sender=&Apache::loncommon::aboutmewrapper( $$plainname, $$contrib{$idx.':sendername'}, @@ -1180,11 +1197,7 @@ sub get_post_contents { if ($type eq 'allversions' || $type eq 'export') { $start = 0; if ($$contrib{$idx.':history'}) { - if ($$contrib{$idx.':history'} =~ m/:/) { - @postversions = split/:/,$$contrib{$idx.':history'}; - } else { - @postversions = ("$$contrib{$idx.':history'}"); - } + @postversions = split(/:/,$$contrib{$idx.':history'}); } &get_post_versions($messages,$$contrib{$idx.':message'},1); &get_post_versions($subjects,$$contrib{$idx.':subject'},1); @@ -1205,7 +1218,7 @@ sub get_post_contents { my ($timesent,$attachmsg); my %currattach = (); $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]); - $$messages{$i}=~s/\n/\
/g; + &newline_to_br(\$messages->{$i}); $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i}); $$subjects{$i}=~s/\n/\
/g; $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i}); @@ -1288,7 +1301,7 @@ sub replicate_attachments { sub mail_screen { my ($r,$feedurl,$options) = @_; if (exists($env{'form.origpage'})) { - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss','blog']); } my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion', '','onLoad="window.focus();setposttype();"'); @@ -1375,7 +1388,7 @@ END &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver); $message = $msgversions{$numoldver}; } - $message=~s/\n/\
/g; + &newline_to_br(\$message); $quote='
'.&Apache::lontexconvert::msgtexconverted($message).'
'; if ($idx > 0) { my %subversions = (); @@ -1472,6 +1485,11 @@ $htmlheader rec=1; } } + if (typeof(document.mailform.elements.blog)!="undefined") { + if (document.mailform.elements.blog.checked) { + rec=1; + } + } if (rec) { if (typeof(document.mailform.onsubmit)=='function') { @@ -2128,7 +2146,7 @@ ENDFAILREDIR } sub redirect_back { - my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$numpicks) = @_; + my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$numpicks) = @_; my $sorttag = ''; my $roletag = ''; my $statustag = ''; @@ -2210,6 +2228,7 @@ $html $typestyle Sent $sendsomething message(s), and $sendposts post(s). +$blog $status $prevtag @@ -2259,7 +2278,7 @@ sub screen_header { my $msgoptions=''; my $discussoptions=''; unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) { - if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) { + if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) { $msgoptions= '

'; @@ -2292,8 +2311,11 @@ sub screen_header { &mt('Contribution to course discussion of resource'); $discussoptions.='
'; + ' ('.&mt('name only visible to course faculty').') '. + ''.&mt('Change Screenname').''; } + #$discussoptions.='
'; } if ($msgoptions) { $msgoptions='

'.&mt('Sending Messages').'

'.$msgoptions; } if ($discussoptions) { @@ -2375,17 +2397,48 @@ sub secapply { return ''; } +=pod + +=over 4 + +=item * + +decide_receiver($feedurl,$author,$question,$course,$policy,$defaultflag); + +Arguments + $feedurl - /res/ url of resource (only need if $author is true) + $author,$question,$course,$policy - all true/false parameters + if true will attempt to find the addresses of user that should receive + this type of feedback (author - feedback to author of resource $feedurl, + $question 'Resource Content Questions', $course 'Course Content Question', + $policy 'Course Policy') + (Additionally it also checks $env for whether the corresponding form. + element exists, for ease of use in a html response context) + + $defaultflag - (internal should be left blank) if true gather addresses + that aren't for a section even if I have a section + (used for reccursion internally, first we look for + addresses for our specific section then we recurse + and look for non section addresses) + +Returns + $typestyle - string of html text, describing what addresses were found + %to - a hash, which keys are addresses of users to send messages to + the keys will look like name:domain + +=cut + sub decide_receiver { my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_; my $typestyle=''; my %to=(); if ($env{'form.author'}||$author) { - $typestyle.='Submitting as Author Feedback
'; + $typestyle.='Submitting as Author Feedback
'; $feedurl=~/^\/res\/(\w+)\/(\w+)\//; $to{$2.':'.$1}=1; } if ($env{'form.question'}||$question) { - $typestyle.='Submitting as Question
'; + $typestyle.='Submitting as Question
'; foreach (split(/\,/, $env{'course.'.$env{'request.course.id'}.'.question.email'}) ) { @@ -2572,7 +2625,7 @@ sub show_preview { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; my $message=&clear_out_html($env{'form.comment'}); - $message=~s/\n/\
/g; + &newline_to_br(\$message); $message=&Apache::lonspeller::markeduptext($message); $message=&Apache::lontexconvert::msgtexconverted($message); my $subject=&clear_out_html($env{'form.subject'}); @@ -2585,14 +2638,39 @@ sub show_preview { $message.'
'); } + +sub newline_to_br { + my ($message)=@_; + my $newmessage; + my $parser=HTML::LCParser->new($message); + while (my $token=$parser->get_token()) { + if ($token->[0] eq 'T') { + my $text=$token->[1]; + $text=~s/\n/\
/g; + $newmessage.=$text; + } elsif ($token->[0] eq 'D' || $token->[0] eq 'C') { + $newmessage.=$token->[1]; + } elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') { + $newmessage.=$token->[2]; + } elsif ($token->[0] eq 'S') { + $newmessage.=$token->[4]; + } + + } + $$message=$newmessage; +} + sub generate_preview_button { + my ($formname,$fieldname)=@_; + unless ($formname) { $formname='mailform'; } + unless ($fieldname) { $fieldname='comment'; } my $pre=&mt("Show Preview and Check Spelling"); return(< +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 } @@ -2667,6 +2745,7 @@ END + END foreach (@{$currnewattach}) { @@ -2731,8 +2810,9 @@ this.form.submit();" /> - + + ENDATTACH if (defined($deloldattach)) { @@ -2866,10 +2946,7 @@ sub has_discussion { my @allres=$navmap->retrieveResources(); foreach my $resource (@allres) { if ($resource->hasDiscussion()) { - my $ressymb = $resource->symb(); - if ($ressymb =~ m-___adm/\w+/\w+/\d+/bulletinboard$-) { - $ressymb = $resource->wrap_symb(); - } + my $ressymb = $resource->wrap_symb(); push @{$resourcesref}, $ressymb; } } @@ -2939,7 +3016,7 @@ sub handler { \%readinghash,$env{'user.domain'},$env{'user.name'}); } &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'
', - '0','0','',$env{'form.previous'},'','','',); + '0','0','','',$env{'form.previous'},'','','',); return OK; } if ($env{'form.allversions'}) { @@ -2991,14 +3068,14 @@ END $discinfo{$symb.'_userpick'} = join('&',@posters); &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss', \%discinfo,$env{'user.domain'},$env{'user.name'}); - &redirect_back($r,$feedurl,&mt('Changed sort/filter').'
','0','0', + &redirect_back($r,$feedurl,&mt('Changed sort/filter').'
','0','0','', '',$env{'form.previous'},$env{'form.sortposts'},'','','', $numpicks); return OK; } if ($env{'form.applysort'}) { my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'}); - &redirect_back($r,$feedurl,&mt('Changed sort/filter').'
','0','0', + &redirect_back($r,$feedurl,&mt('Changed sort/filter').'
','0','0','', '',$env{'form.previous'},$env{'form.sortposts'}, $env{'form.rolefilter'},$env{'form.statusfilter'}, $env{'form.sectionpick'}); @@ -3102,7 +3179,7 @@ ENDREDIR my $previous=$env{'form.previous'}; if ($env{'form.markondisp'}) { $previous=undef; } &redirect_back($r,$feedurl,&mt('Changed display status').'
', - '0','0','',$previous); + '0','0','','',$previous); return OK; } elsif (($env{'form.hide'}) || ($env{'form.unhide'})) { # ----------------------------------------------------------------- Hide/unhide @@ -3142,7 +3219,7 @@ ENDREDIR $env{'course.'.$env{'request.course.id'}.'.num'}); &redirect_back($r,$feedurl,&mt('Changed discussion status').'
', - '0','0','',$env{'form.previous'}); + '0','0','','',$env{'form.previous'}); return OK; } elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) { my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'}); @@ -3154,7 +3231,7 @@ ENDREDIR &Apache::lonnet::delenv('environment\.threadeddiscussion'); } &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'
', - '0','0','',$env{'form.previous'}); + '0','0','','',$env{'form.previous'}); return OK; } elsif ($env{'form.deldisc'}) { # --------------------------------------------------------------- Hide for good @@ -3168,7 +3245,7 @@ ENDREDIR $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'}); + '0','0','','',$env{'form.previous'}); return OK; } elsif ($env{'form.preview'}) { # -------------------------------------------------------- User wants a preview @@ -3178,7 +3255,7 @@ ENDREDIR # -------------------------------------------------------- Work on attachments &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss','blog']); my (@currnewattach,@currdelold,@keepold); &process_attachments(\@currnewattach,\@currdelold,\@keepold); if (exists($env{'form.addnewattach.filename'})) { @@ -3207,7 +3284,7 @@ ENDREDIR my $mode='board'; my $status='OPEN'; my $previous=$env{'form.previous'}; - if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library)$/) { + if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library|task)$/) { $mode='problem'; $status=$Apache::inputtags::status[-1]; } @@ -3246,7 +3323,7 @@ ENDREDIR } &Apache::lonenc::check_decrypt(\$symb); my $goahead=1; - if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) { + if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) { unless ($symb) { $goahead=0; } } # backward compatibility (bulletin boards used to be 'wrapped') @@ -3270,6 +3347,7 @@ ENDREDIR $r->send_http_header; # Unable to give feedback &no_redirect_back($r,$feedurl); + return OK; } # --------------------------------------------------- Print login screen header unless ($env{'form.sendit'}) { @@ -3346,9 +3424,21 @@ ENDREDIR $subject); $numpost++; } + +# Add to blog? + + my $blog=''; + if ($env{'form.blog'}) { + 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').'
'; + } # Receipt screen and redirect back to where came from - &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$env{'form.previous'}); + &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'}); } return OK; }