--- loncom/interface/lonhtmlcommon.pm 2002/08/30 15:35:08 1.9 +++ loncom/interface/lonhtmlcommon.pm 2009/06/10 13:32:38 1.223 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.9 2002/08/30 15:35:08 stredwic Exp $ +# $Id: lonhtmlcommon.pm,v 1.223 2009/06/10 13:32:38 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,370 +25,2186 @@ # # 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 LONCAPA; -sub AscendOrderOptions { - my ($order, $page, $formName)=@_; +############################################## +############################################## - my $OpSel1 = ''; - my $OpSel2 = ''; +=pod - if($order eq 'Ascending') { - $OpSel1 = ' selected'; - } else { - $OpSel2 = ' selected'; - } +=item confirm_success - my $Str = ''; - $Str .= ''."\n"; +Successful completion of an operation message - return $Str; +=cut + +sub confirm_success { + my ($message,$failure)=@_; + if ($failure) { + return ''."\n" + .''.&mt('Error').' '."\n" + .$message."\n" + .''."\n"; + } else { + return ''."\n" + .''.&mt('Ok').' '."\n" + .$message."\n" + .''."\n"; + } } -sub MapOptions { - my ($data, $page, $formName)=@_; - my $Str = ''; - $Str .= ''."\n"; +############################################## - 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 ProblemOptions { - my ($data, $page, $map, $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); + $return.="\n'; + } } - $Str .= '= $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; +} + + + +=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 PartOptions { - my ($data, $page, $parts, $formName)=@_; - my $Str = ''; +############################################## +############################################## + +=pod + +=item checkbox + +=cut - if(!defined($parts)) { - return ''; +############################################## +############################################## +sub checkbox { + my ($name,$checked,$value) = @_; + my $Str = '{$page.'PartSelect'} eq $part) { - $Str .= ' selected'; - $selected = 1; +The current setting for this time parameter. A unix format time +(time in seconds since the beginning of Jan 1st, 1970, GMT. +An undefined value is taken to indicate the value is the current time. +Also, to be explicit, a value of 'now' also indicates the current time. + +=item $special + +Additional html/javascript to be associated with each element in +the date_setter. See lonparmset for example usage. + +=item $includeempty + +=item $state + +Specifies the initial state of the form elements. Either 'disabled' or empty. +Defaults to empty, which indiciates the form elements are not disabled. + +=back + +Bugs + +The method used to restrict user input will fail in the year 2400. + +=cut + +############################################## +############################################## +sub date_setter { + my ($formname,$dname,$currentvalue,$special,$includeempty,$state, + $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_; + my $now = time; + my $wasdefined=1; + if (! defined($state) || $state ne 'disabled') { + $state = ''; + } + if (! defined($no_hh_mm_ss)) { + $no_hh_mm_ss = 0; + } + if ($currentvalue eq 'now') { + $currentvalue = $now; + } + if ((!defined($currentvalue)) || ($currentvalue eq '')) { + $wasdefined=0; + if ($includeempty) { + $currentvalue = 0; + } else { + $currentvalue = $now; + } + } + # other potentially useful values: wkday,yrday,is_daylight_savings + my $tzname; + my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','',''); + if ($currentvalue) { + ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); + } + unless ($wasdefined) { + ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($now); + if (($defhour) || ($defmin) || ($defsec)) { + $sec=($defsec?$defsec:0); + $min=($defmin?$defmin:0); + $hour=($defhour?$defhour:0); + } elsif (!$includeempty) { + $sec=0; + $min=0; + $hour=0; } - $Str .= '>'.$part.''."\n"; } - $Str .= ' +// 31) { + document.$formname.$dname\_day.value = 31; + } + if ((month == 1) || (month == 3) || (month == 5) || + (month == 7) || (month == 8) || (month == 10) || + (month == 12)) { + if (day > 31) { + document.$formname.$dname\_day.value = 31; + day = 31; + } + } else if (month == 2 ) { + if ((year % 4 == 0) && (year % 100 != 0)) { + if (day > 29) { + document.$formname.$dname\_day.value = 29; + } + } else if (day > 29) { + document.$formname.$dname\_day.value = 28; + } + } else if (day > 30) { + document.$formname.$dname\_day.value = 30; + } + } + + function $dname\_disable() { + document.$formname.$dname\_month.disabled=true; + document.$formname.$dname\_day.disabled=true; + document.$formname.$dname\_year.disabled=true; + document.$formname.$dname\_hour.disabled=true; + document.$formname.$dname\_minute.disabled=true; + document.$formname.$dname\_second.disabled=true; } - $Str .= '>All Parts'."\n"; - $Str .= ''."\n"; + function $dname\_enable() { + document.$formname.$dname\_month.disabled=false; + document.$formname.$dname\_day.disabled=false; + document.$formname.$dname\_year.disabled=false; + document.$formname.$dname\_hour.disabled=false; + document.$formname.$dname\_minute.disabled=false; + document.$formname.$dname\_second.disabled=false; + } - return $Str; + function $dname\_opencalendar() { + if (! document.$formname.$dname\_month.disabled) { + var calwin=window.open( +"/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+ +document.$formname.$dname\_month.value+"&year="+ +document.$formname.$dname\_year.value, + "LONCAPAcal", + "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no"); + } + + } +// ]]> + +ENDJS + $result .= ' '; + my $monthselector = qq{'; + # Day + my $dayselector = qq{}; + # Year + my $yearselector = qq{}; + # + my $hourselector = qq{\n"; + my $minuteselector = qq{}; + my $secondselector= qq{}; + my $cal_link; + if (!$nolink) { + $cal_link = qq{}; + } + # + my $tzone = ' '.$tzname.' '; + if ($no_hh_mm_ss) { + $result .= &mt('[_1] [_2] [_3] ', + $monthselector,$dayselector,$yearselector). + $tzone; + if (!$nolink) { + $result .= &mt('[_1]Select Date[_2]',$cal_link,''); + } + } else { + $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ', + $monthselector,$dayselector,$yearselector, + $hourselector,$minuteselector,$secondselector). + $tzone; + if (!$nolink) { + $result .= &mt('[_1]Select Date[_2]',$cal_link,''); + } + } + $result .= "\n\n"; + return $result; } -sub StudentOptions { - my ($cache, $students, $selectedName, $page, $formName)=@_; +sub get_timedates { + my ($epoch) = @_; + my $dt = DateTime->from_epoch(epoch => $epoch) + ->set_time_zone(&Apache::lonlocal::gettimezone()); + my $tzname = $dt->time_zone_short_name(); + my $sec = $dt->second; + my $min = $dt->minute; + my $hour = $dt->hour; + my $mday = $dt->day; + my $month = $dt->month; + if ($month) { + $month --; + } + my $year = $dt->year; + return ($tzname,$sec,$min,$hour,$mday,$month,$year); +} - my $Str = ''; - $Str .= ''."\n"; +############################################## +############################################## + +=pod +=item &pjump_javascript_definition() + +Returns javascript defining the 'pjump' function, which opens up a +parameter setting wizard. + +=cut + +############################################## +############################################## +sub pjump_javascript_definition { + my $Str = <Active'."\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 .= '