--- loncom/interface/lonhtmlcommon.pm 2002/08/01 20:49:06 1.6 +++ loncom/interface/lonhtmlcommon.pm 2012/06/04 16:59:00 1.318 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.6 2002/08/01 20:49:06 stredwic Exp $ +# $Id: lonhtmlcommon.pm,v 1.318 2012/06/04 16:59:00 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,274 +25,3308 @@ # # http://www.lon-capa.org/ # +###################################################################### +###################################################################### + +=pod + +=head1 NAME + +Apache::lonhtmlcommon - routines to do common html things + +=head1 SYNOPSIS + +Referenced by other mod_perl Apache modules. + +=head1 INTRODUCTION + +lonhtmlcommon is a collection of subroutines used to present information +in a consistent html format, or provide other functionality related to +html. + +=head2 General Subroutines + +=over 4 + +=cut + +###################################################################### +###################################################################### package Apache::lonhtmlcommon; use strict; +use Time::Local; +use Time::HiRes; +use Apache::lonlocal; +use Apache::lonnet; +use HTML::Entities(); +use LONCAPA; + +sub java_not_enabled { + return "\n".''. + &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.'). + "\n"; +} + +sub coursepreflink { + my ($text,$category)=@_; + if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) { + return '&"').'">'.$text.''; + } else { + return ''; + } +} -sub AscendOrderOptions { - my ($order, $page, $formName)=@_; +sub raw_href_to_link { + my ($message)=@_; + $message=~s/(https?\:\/\/[^\s\'\"\<]+)([\s\<]|$)/$1<\/tt><\/a>$2/gi; + return $message; +} - my $OpSel1 = ''; - my $OpSel2 = ''; +sub entity_encode { + my ($text)=@_; + return &HTML::Entities::encode($text, '<>&"'); +} - if($order eq 'Ascending') { - $OpSel1 = ' selected'; +sub direct_parm_link { + my ($linktext,$symb,$filter,$part,$target)=@_; + $symb=&entity_encode($symb); + $filter=&entity_encode($filter); + $part=&entity_encode($part); + if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) { + return "$linktext"; } else { - $OpSel2 = ' selected'; + return $linktext; } +} +############################################## +############################################## - my $Str = ''; - $Str .= ''."\n"; + my $buttontext=&mt('Edit Math'); + return <$help_text +ENDDRAGMATH +} - return $Str; +############################################## + +=pod + +=item &dragmath_js() + +Javascript used to open pop-up window containing dragmath applet which +can be used to paste LaTeX into a textarea. + +=cut + +sub dragmath_js { + my ($popup) = @_; + return < + // + + +ENDDRAGMATHJS } -sub MapOptions { - my ($data, $page, $formName)=@_; - my $Str = ''; - $Str .= '\n"; + foreach my $value (sort(keys(%recent))) { + unless ($value =~/^error\:/) { + my $escaped = &Apache::loncommon::escape_url($value); + &Apache::loncommon::inhibit_menu_check(\$escaped); + if ($area eq 'residx') { + next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value))); + } + $return.="\n'; + } + } + $return.="\n\n"; + return $return; +} + +sub get_recent { + my ($area, $n) = @_; + my %recent=&Apache::lonnet::dump(&recent_filename($area)); + +# Create hash with key as time and recent as value +# Begin filling return_hash with any 'always_include' option + my %time_hash = (); + my %return_hash = (); + foreach my $item (keys(%recent)) { + my ($thistime,$thisvalue)=(split(/\&/,$recent{$item})); + if ($thistime eq 'always_include') { + $return_hash{$item} = &unescape($thisvalue); + $n--; + } else { + $time_hash{$thistime} = $item; + } + } + +# Sort by decreasing time and return key value pairs + my $idx = 1; + foreach my $item (reverse(sort(keys(%time_hash)))) { + $return_hash{$time_hash{$item}} = + &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]); + if ($n && ($idx++ >= $n)) {last;} + } + + return %return_hash; +} + +sub get_recent_frozen { + my ($area) = @_; + my %recent=&Apache::lonnet::dump(&recent_filename($area)); + +# Create hash with all 'frozen' items + my %return_hash = (); + foreach my $item (keys(%recent)) { + my ($thistime,$thisvalue)=(split(/\&/,$recent{$item})); + if ($thistime eq 'always_include') { + $return_hash{$item} = &unescape($thisvalue); + } + } + return %return_hash; +} - $Str .= ''."\n"; + +=pod + +=item &textbox() + +=cut + +############################################## +############################################## +sub textbox { + my ($name,$value,$size,$special) = @_; + $size = 40 if (! defined($size)); + $value = &HTML::Entities::encode($value,'<>&"'); + my $Str = ''; return $Str; } -sub StudentOptions { - my ($cache, $students, $selectedName, $page, $formName)=@_; +############################################## +############################################## - my $Str = ''; - $Str .= '}; + # Month + my @Months = qw/January February March April May June + July August September October November December/; + # Pad @Months with a bogus value to make indexing easier + unshift(@Months,'If you can read this an error occurred'); + if ($includeempty) { $monthselector.=""; } + for(my $m = 1;$m <=$#Months;$m++) { + $monthselector .= qq{ '."\n"; - $Str .= 'Expired'."\n"; - $Str .= 'Any'."\n"; + foreach my $type (['Active', &mt('Currently Has Access')], + ['Future', &mt('Will Have Future Access')], + ['Expired', &mt('Previously Had Access')], + ['Any', &mt('Any Access Status')]) { + my ($name,$label) = @$type; + $Str .= '