--- loncom/interface/lonhtmlcommon.pm 2003/05/12 22:04:41 1.21 +++ loncom/interface/lonhtmlcommon.pm 2004/04/07 22:33:00 1.63 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.21 2003/05/12 22:04:41 matthew Exp $ +# $Id: lonhtmlcommon.pm,v 1.63 2004/04/07 22:33:00 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -56,6 +56,8 @@ html. package Apache::lonhtmlcommon; use Time::Local; +use Time::HiRes; +use Apache::lonlocal; use strict; ############################################## @@ -63,8 +65,120 @@ use strict; =pod +=item authorbombs + +=cut + +############################################## +############################################## + +sub authorbombs { + my $url=shift; + $url=&Apache::lonnet::declutter($url); + my ($udom,$uname)=($url=~/^(\w+)\/(\w+)\//); + my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom); + foreach (keys %bombs) { + if ($_=~/^$udom\/$uname\//) { + return ''. + &Apache::loncommon::help_open_topic('About_Bombs'); + } + } + return ''; +} + +############################################## +############################################## + +sub recent_filename { + my $area=shift; + return 'nohist_recent_'.&Apache::lonnet::escape($area); +} + +sub store_recent { + my ($area,$name,$value)=@_; + my $file=&recent_filename($area); + my %recent=&Apache::lonnet::dump($file); + if (scalar(keys(%recent))>10) { +# remove oldest value + my $oldest=time; + my $delkey=''; + foreach (keys %recent) { + my $thistime=(split(/\&/,$recent{$_}))[0]; + if ($thistime<$oldest) { + $oldest=$thistime; + $delkey=$_; + } + } + &Apache::lonnet::del($file,[$delkey]); + } +# store new value + &Apache::lonnet::put($file,{ $name => + time.'&'.&Apache::lonnet::escape($value) }); +} + +sub select_recent { + my ($area,$fieldname,$event)=@_; + my %recent=&Apache::lonnet::dump(&recent_filename($area)); + my $return="\n\n"; + return $return; +} + + +=pod + +=item textbox + +=cut + +############################################## +############################################## +sub textbox { + my ($name,$value,$size,$special) = @_; + $size = 40 if (! defined($size)); + my $Str = ''; + return $Str; +} + +############################################## +############################################## + +=pod + +=item checkbox + +=cut + +############################################## +############################################## +sub checkbox { + my ($name,$value) = @_; + my $Str = ''; + return $Str; +} + +############################################## +############################################## + +=pod + =item &date_setter +&date_setter returns html and javascript for a compact date-setting form. +To retrieve values from it, use &get_date_from_form(). + Inputs =over 4 @@ -82,19 +196,47 @@ The current setting for this time parame 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) = @_; + my ($formname,$dname,$currentvalue,$special,$includeempty,$state) = @_; + if (! defined($state) || $state ne 'disabled') { + $state = ''; + } if (! defined($currentvalue) || $currentvalue eq 'now') { - $currentvalue = time; + unless ($includeempty) { + $currentvalue = time; + } else { + $currentvalue = 0; + } } # other potentially useful values: wkday,yrday,is_daylight_savings - my ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = - localtime($currentvalue); - $year += 1900; + my ($sec,$min,$hour,$mday,$month,$year)=('','','','','',''); + if ($currentvalue) { + ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = + localtime($currentvalue); + $year += 1900; + } my $result = "\n\n"; $result .= < @@ -128,57 +270,99 @@ sub date_setter { 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; + } + + 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; + } + + 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 .= " \n"; - $result .= " \n"; - $result .= " \n"; $result .= "  "; - $result .= " \n"; + if ($includeempty) { $result.=""; } for (my $h = 0;$h<24;$h++) { $result .= "