--- loncom/interface/lonhtmlcommon.pm 2005/05/28 00:35:47 1.105 +++ loncom/interface/lonhtmlcommon.pm 2009/11/19 10:25:02 1.246 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.105 2005/05/28 00:35:47 www Exp $ +# $Id: lonhtmlcommon.pm,v 1.246 2009/11/19 10:25:02 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,6 +60,88 @@ use Time::Local; use Time::HiRes; use Apache::lonlocal; use Apache::lonnet; +use LONCAPA; + +############################################## +############################################## + +=pod + +=item confirm_success + +Successful completion of an operation message + +=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"; + } +} + +############################################## +############################################## + +=pod + +=item dragmath_button + +Creates a button that launches a dragmath popup-window, in which an +expression can be edited and pasted as LaTeX into a specified textarea. + + textarea - Name of the textarea to edit. + helpicon - If true, show a help icon to the right of the button. + +=cut + +sub dragmath_button { + my ($textarea,$helpicon) = @_; + my $help_text; + if ($helpicon) { + $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor'); + } + my $buttontext=&mt('Edit Math'); + return <$help_text +ENDDRAGMATH +} + +############################################## + +=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 +} + ############################################## ############################################## @@ -76,12 +158,12 @@ use Apache::lonnet; sub authorbombs { my $url=shift; $url=&Apache::lonnet::declutter($url); - my ($udom,$uname)=($url=~/^(\w+)\/(\w+)\//); + my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/}); my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom); - foreach (keys %bombs) { - if ($_=~/^$udom\/$uname\//) { + foreach my $bomb (keys(%bombs)) { + if ($bomb =~ /^$udom\/$uname\//) { return ''. + '">'.&mt('Bomb').''. &Apache::loncommon::help_open_topic('About_Bombs'); } } @@ -93,29 +175,35 @@ sub authorbombs { sub recent_filename { my $area=shift; - return 'nohist_recent_'.&Apache::lonnet::escape($area); + return 'nohist_recent_'.&escape($area); } sub store_recent { - my ($area,$name,$value)=@_; + my ($area,$name,$value,$freeze)=@_; my $file=&recent_filename($area); my %recent=&Apache::lonnet::dump($file); - if (scalar(keys(%recent))>10) { + if (scalar(keys(%recent))>20) { # remove oldest value - my $oldest=time; + my $oldest=time(); my $delkey=''; - foreach (keys %recent) { - my $thistime=(split(/\&/,$recent{$_}))[0]; - if ($thistime<$oldest) { + foreach my $item (keys(%recent)) { + my $thistime=(split(/\&/,$recent{$item}))[0]; + if (($thistime ne "always_include") && ($thistime<$oldest)) { $oldest=$thistime; - $delkey=$_; + $delkey=$item; } } &Apache::lonnet::del($file,[$delkey]); } # store new value + my $timestamp; + if ($freeze) { + $timestamp = "always_include"; + } else { + $timestamp = time(); + } &Apache::lonnet::put($file,{ $name => - time.'&'.&Apache::lonnet::escape($value) }); + $timestamp.'&'.&escape($value) }); } sub remove_recent { @@ -130,11 +218,12 @@ sub select_recent { my $return="\n'; return $Str; @@ -201,7 +312,29 @@ sub checkbox { $Str .= 'value="'.$value.'"'; } if ($checked) { - $Str .= ' checked="1"'; + $Str .= ' checked="checked"'; + } + $Str .= ' />'; + return $Str; +} + + +=pod + +=item radiobutton + +=cut + +############################################## +############################################## +sub radio { + my ($name,$checked,$value) = @_; + my $Str = ' + ENDJS - $result .= ' '; + $result .= ' '; my $monthselector = qq{'; # Day my $dayselector = qq{}; # Year - my $yearselector = qq{}; + my $yearselector = qq{}; # my $hourselector = qq{}; - my $cal_link = qq{}; + my $cal_link; + if (!$nolink) { + $cal_link = qq{}; + } # + my $tzone = ' '.$tzname.' '; if ($no_hh_mm_ss) { - $result .= &mt('[_1] [_2] [_3] [_4]Select Date[_5]', - $monthselector,$dayselector,$yearselector, - $cal_link,''); + $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 [_7]Select Date[_8]', - $monthselector,$dayselector,$yearselector, - $hourselector,$minuteselector,$secondselector, - $cal_link,''); + $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"; + $result .= "\n\n"; return $result; } +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); +} + +sub build_url { + my ($base, $fields)=@_; + my $url; + $url = $base.'?'; + foreach my $key (keys(%$fields)) { + $url.=&escape($key).'='.&escape($$fields{$key}).'&'; + } + $url =~ s/&$//; + return $url; +} + + ############################################## ############################################## @@ -418,7 +609,7 @@ Inputs: =item $dname -The name passed to &datesetter, which prefixes the form elements. +The name passed to &date_setter, which prefixes the form elements. =item $defaulttime @@ -471,20 +662,33 @@ sub get_date_from_form { if (defined($env{'form.'.$dname.'_month'})) { my $tmpmonth = $env{'form.'.$dname.'_month'}; if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) { - $month = $tmpmonth - 1; + $month = $tmpmonth; } } if (defined($env{'form.'.$dname.'_year'})) { my $tmpyear = $env{'form.'.$dname.'_year'}; - if (($tmpyear =~ /^\d+$/) && ($tmpyear > 1900)) { - $year = $tmpyear - 1900; + if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) { + $year = $tmpyear; } } - if (($year<70) || ($year>137)) { return undef; } + if (($year<1970) || ($year>2037)) { return undef; } if (defined($sec) && defined($min) && defined($hour) && - defined($day) && defined($month) && defined($year) && - eval(&timelocal($sec,$min,$hour,$day,$month,$year))) { - return &timelocal($sec,$min,$hour,$day,$month,$year); + defined($day) && defined($month) && defined($year)) { + my $timezone = &Apache::lonlocal::gettimezone(); + my $dt = DateTime->new( year => $year, + month => $month, + day => $day, + hour => $hour, + minute => $min, + second => $sec, + time_zone => $timezone, + ); + my $epoch_time = $dt->epoch; + if ($epoch_time ne '') { + return $epoch_time; + } else { + return undef; + } } else { return undef; } @@ -506,11 +710,13 @@ parameter setting wizard. ############################################## sub pjump_javascript_definition { my $Str = <'. - &mt('Currently Enrolled').''."\n"; - $Str .= ''."\n"; - $Str .= ''."\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 .= '