--- loncom/interface/lonhtmlcommon.pm 2002/08/30 15:35:08 1.9
+++ loncom/interface/lonhtmlcommon.pm 2012/11/29 20:37:07 1.334
@@ -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.334 2012/11/29 20:37:07 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,370 +25,3515 @@
#
# 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 qw(:DEFAULT :match);
+
+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 AscendOrderOptions {
- my ($order, $page, $formName)=@_;
+sub coursepreflink {
+ my ($text,$category)=@_;
+ if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
+ return '&"').'">'.$text.'';
+ } else {
+ return '';
+ }
+}
+
+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 .= '
+END
+}
+
+##############################################
+
+=pod
+
+=item &dependencycheck_js()
+
+Javascript used to open pop-up window containing interface to manage
+dependencies for a web page uploaded diretcly to a course.
+
+=cut
+
+sub dependencycheck_js {
+ my ($symb,$title,$url,$folderpath,$uri) = @_;
+ my $link;
+ if ($symb) {
+ $link = '/adm/dependencies?symb='.&HTML::Entities::encode($symb,'<>&"');
+ } elsif ($folderpath) {
+ $link = '/adm/dependencies?folderpath='.&HTML::Entities::encode($folderpath,'<>&"');
+ $url = $uri;
}
- $Str .= '>'."\n";
+ $link .= (($link=~/\?/)?'&':'?').'title='.
+ &HTML::Entities::encode($title,'<>&"');
+ if ($url) {
+ $link .= '&url='.&HTML::Entities::encode($url,'<>&"');
+ }
+ return <
+ //
+
+ENDJS
+}
+
+##############################################
+##############################################
+
+=pod
+
+=item &authorbombs()
+
+=cut
- my $selected = 0;
- foreach my $sequence (split(':',$data->{'orderedSequences'})) {
- $Str .= ''."\n";
- }
- $Str .= ''.
+ &Apache::loncommon::help_open_topic('About_Bombs');
+ }
}
- $Str .= '>All Maps'."\n";
+ return '';
+}
- $Str .= ''."\n";
+##############################################
+##############################################
- return $Str;
+sub recent_filename {
+ my $area=shift;
+ return 'nohist_recent_'.&escape($area);
}
-sub ProblemOptions {
- my ($data, $page, $map, $formName)=@_;
- my $Str = '';
- $Str .= ''."\n";
}
-sub MultipleSectionSelect {
- my ($sections,$selectedSections)=@_;
+########################################################
+########################################################
- my $Str = '';
- $Str .= ''."\n";
+=pod
+
+=item Progess Window Handling Routines
+
+These routines handle the creation, update, increment, and closure of
+progress windows. The progress window reports to the user the number
+of items completed and an estimate of the time required to complete the rest.
+
+=over 4
+
+
+=item &Create_PrgWin()
+
+Writes javascript to the client to open a progress window and returns a
+data structure used for bookkeeping.
+
+Inputs
+
+=over 4
+
+=item $r Apache request
+
+=item $number_to_do The total number of items being processed.
+
+=back
+
+Returns a hash containing the progress state data structure.
+
+
+=item &Update_PrgWin()
+
+Updates the text in the progress indicator. Does not increment the count.
+See &Increment_PrgWin.
+
+Inputs:
+
+=over 4
+
+=item $r Apache request
+
+=item $prog_state Pointer to the data structure returned by &Create_PrgWin
+
+=item $displaystring The string to write to the status indicator
+
+=back
+
+Returns: none
+
+
+=item Increment_PrgWin()
+
+Increment the count of items completed for the progress window by $step or 1 if no step is provided.
+
+Inputs:
+
+=over 4
+
+=item $r Apache request
+
+=item $prog_state Pointer to the data structure returned by Create_PrgWin
+
+=item $extraInfo A description of the items being iterated over. Typically
+'student'.
+
+=item $step (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
+
+=back
+
+Returns: none
+
+
+=item &Close_PrgWin()
+
+Closes the progress window.
+
+Inputs:
+
+=over 4
+
+=item $r Apache request
+
+=item $prog_state Pointer to the data structure returned by Create_PrgWin
+
+=back
+
+Returns: none
+
+=back
+
+=cut
- foreach (@$sections) {
- $Str .= '
+ENDTWO
+ if (!$no_separator) {
+ $output .= <<"ENDTWO";
+
+
+
+
+ENDTWO
+ }
+ return $output;
+}
-$cache: This is a pointer to a hash that is tied to the cached data
+} # End: row_count block for pick_box
-$name: The name and domain of the current student in name:domain format
+sub role_select_row {
+ my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
+ my $crstype = 'Course';
+ if ($cdom ne '' && $cnum ne '') {
+ $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
+ }
+ my $output;
+ if (defined($title)) {
+ $output = &row_title($title,$css_class);
+ }
+ $output .= qq|
+ \n|;
+ foreach my $role (@$roles) {
+ my $plrole;
+ if ($role eq 'ow') {
+ $plrole = &mt('Course Owner');
+ } elsif ($role eq 'cr') {
+ if ($show_separate_custom) {
+ if ($cdom ne '' && $cnum ne '') {
+ my %course_customroles = &course_custom_roles($cdom,$cnum);
+ foreach my $crrole (sort(keys(%course_customroles))) {
+ my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|);
+ $output .= '
';
+ }
+ return $return;
+}
+
+##############################################
+##############################################
+
+# topic_bar
+#
+# Generates a div containing an (optional) number with a white background followed by a
+# title with a background color defined in the corresponding CSS: LC_topic_bar
+# Inputs:
+# 1. number to display.
+# If input for number is empty only the title will be displayed.
+# 2. title text to display.
+# 3. optional id for the
+# Outputs - a scalar containing html mark-up for the div.
+
+sub topic_bar {
+ my ($num,$title,$id) = @_;
+ my $number = '';
+ if ($num ne '') {
+ $number = ''.$num.'';
+ }
+ if ($id ne '') {
+ $id = 'id="'.$id.'"';
+ }
+ return '
'.$number.$title.'
';
+}
+
+##############################################
+##############################################
+# echo_form_input
+#
+# Generates html markup to add form elements from the referrer page
+# as hidden form elements (values encoded) in the new page.
+#
+# Intended to support two types of use
+# (a) to allow backing up to earlier pages in a multi-page
+# form submission process using a breadcrumb trail.
+#
+# (b) to allow the current page to be reloaded with form elements
+# set on previous page to remain unchanged. An example would
+# be where the a page containing a dynamically-built table of data is
+# is to be redisplayed, with only the sort order of the data changed.
+#
+# Inputs:
+# 1. Reference to array of form elements in the submitted form on
+# the referrer page which are to be excluded from the echoed elements.
+#
+# 2. Reference to array of regular expressions, which if matched in the
+# name of the form element n the referrer page will be omitted from echo.
+#
+# Outputs: A scalar containing the html markup for the echoed form
+# elements (all as hidden elements, with values encoded).
- for(my $index=0; $index<(scalar @$keyID); $index++) {
- $currentColumn=$data->{$name.':'.$keyID->[$index]};
- if($format eq 'preformatted') {
- my @dataLength=split(//,$currentColumn);
- my $length=scalar @dataLength;
- $currentColumn.= (' 'x
- ($data->{$keyID->[$index].':columnWidth'}-$length));
+sub echo_form_input {
+ my ($excluded,$regexps) = @_;
+ my $output = '';
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ my $match = 0;
+ if (ref($excluded) eq 'ARRAY') {
+ next if (grep(/^\Q$name\E$/,@{$excluded}));
+ }
+ if (ref($regexps) eq 'ARRAY') {
+ if (@{$regexps} > 0) {
+ foreach my $regexp (@{$regexps}) {
+ if ($name =~ /$regexp/) {
+ $match = 1;
+ last;
+ }
+ }
+ }
+ }
+ next if ($match);
+ if (ref($env{$key}) eq 'ARRAY') {
+ foreach my $value (@{$env{$key}}) {
+ $value = &HTML::Entities::encode($value,'<>&"');
+ $output .= ''."\n";
+ }
+ } else {
+ my $value = &HTML::Entities::encode($env{$key},'<>&"');
+ $output .= ''."\n";
+ }
}
+ }
+ return $output;
+}
- my $tempString = $displayString;
- $tempString =~ s/DISPLAYDATA/$currentColumn/;
+##############################################
+##############################################
+# set_form_elements
+#
+# Generates javascript to set form elements to values based on
+# corresponding values for the same form elements when the page was
+# previously submitted.
+#
+# Last submission values are read from hidden form elements in referring
+# page which have the same name, i.e., generated by &echo_form_input().
+#
+# Intended to be called by onload event.
+#
+# Inputs:
+# (a) Reference to hash of echoed form elements to be set.
+#
+# In the hash, keys are the form element names, and the values are the
+# element type (selectbox, radio, checkbox or text -for textbox, textarea or
+# hidden).
+#
+# (b) Optional reference to hash of stored elements to be set.
+#
+# If the page being displayed is a page which permits modification of
+# previously stored data, e.g., the first page in a multi-page submission,
+# then if stored is supplied, form elements will be set to the last stored
+# values. If user supplied values are also available for the same elements
+# these will replace the stored values.
+#
+# Output:
+#
+# javascript function - set_form_elements() which sets form elements,
+# expects an argument: formname - the name of the form according to
+# the DOM, e.g., document.compose
+
+sub set_form_elements {
+ my ($elements,$stored) = @_;
+ my %values;
+ my $output .= 'function setFormElements(courseForm) {
+';
+ if (defined($stored)) {
+ foreach my $name (keys(%{$stored})) {
+ if (exists($$elements{$name})) {
+ if (ref($$stored{$name}) eq 'ARRAY') {
+ $values{$name} = $$stored{$name};
+ } else {
+ @{$values{$name}} = ($$stored{$name});
+ }
+ }
+ }
+ }
- $Str .= $tempString;
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ if (exists($$elements{$name})) {
+ @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
+ }
+ }
}
- return $Str;
+ foreach my $name (keys(%values)) {
+ for (my $i=0; $i<@{$values{$name}}; $i++) {
+ $values{$name}[$i] = &HTML::Entities::decode($values{$name}[$i],'<>&"');
+ $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
+ $values{$name}[$i] =~ s/"/\\"/g;
+ }
+ if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) {
+ my $numvalues = @{$values{$name}};
+ if ($numvalues > 1) {
+ my $valuestring = join('","',@{$values{$name}});
+ $output .= qq|
+ var textvalues = new Array ("$valuestring");
+ var total = courseForm.elements['$name'].length;
+ if (total > $numvalues) {
+ total = $numvalues;
+ }
+ for (var i=0; iprint('");
+##############################################
+##############################################
+
+sub file_submissionchk_js {
+ my ($turninpaths,$multiples) = @_;
+ my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item').'\\n'.
+ &mt('Continue submission and overwrite the file(s)?');
+ my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'.
+ &mt('Continue submission with these files removed?');
+ my ($turninpathtext,$multtext,$arrayindexofjs);
+ if (ref($turninpaths) eq 'HASH') {
+ foreach my $key (sort(keys(%{$turninpaths}))) {
+ $turninpathtext .= " if (prefix == '$key') {\n".
+ " return '$turninpaths->{$key}';\n".
+ " }\n";
+ }
+ }
+ $turninpathtext .= " return '';\n";
+ if (ref($multiples) eq 'HASH') {
+ foreach my $key (sort(keys(%{$multiples}))) {
+ $multtext .= " if (prefix == '$key') {\n".
+ " return '$multiples->{$key}';\n".
+ " }\n";
+ }
+ }
+ $multtext .= " return '';\n";
- $r->rflush();
+ $arrayindexofjs = &Apache::loncommon::javascript_array_indexof();
+ return <<"ENDSCRIPT";
+');
- $r->rflush();
+function getIndexByName(formname,item) {
+ for (var i=0;iprint(''."\n");
- $r->rflush();
+function overwritten_check(formname,path,multiresp,part,prefix) {
+ var result = [];
+ result['overwrite'] = [];
+ result['delete'] = [];
+ var elemnum = formname.elements.length;
+ if (elemnum == 0) {
+ return result;
+ }
+ var uploadstr;
+ var deletestr;
+ if ((prefix != undefined) && (prefix != '')) {
+ var prepend = prefix+'_';
+ uploadstr = new RegExp("^"+prepend+"HWFILE"+part+".+\$");
+ deletestr = new RegExp("^"+prepend+"HWFILE"+part+".+_\\\\d+_delete\$");
+ multiresp = check_for_multiples(prepend);
+ path = check_for_turninpath(prepend);
+ } else {
+ uploadstr = new RegExp("^HWFILE"+part+".+\$");
+ deletestr = new RegExp("^HWFILE"+part+".+_\\\\d+_delete\$");
+ }
+ var alluploads = [];
+ var allchecked = [];
+ var allskipdel = [];
+ var fnametrim = /[^\\/\\\\]+\$/;
+ for (var i=0; i 0) {
+ if ((formname.elements[alluploads[j]].value != undefined) &&
+ (formname.elements[alluploads[j]].value != '')) {
+ var filepath = formname.elements[alluploads[j]].value;
+ var newfilename = fnametrim.exec(filepath);
+ if (newfilename != null) {
+ var filename = String(newfilename);
+ var nospaces = filename.replace(/\\s+/g,'_');
+ var nospecials = nospaces.replace(/[^\\/\\w\\.\\-]/g,'');
+ var cleanfilename = nospecials.replace(/\\.(\\d+\\.)/g,"_\$1");
+ if (cleanfilename != '') {
+ var fullpath = path+"/"+cleanfilename;
+ if (multiresp == 1) {
+ var partid = String(alluploads[i]);
+ var subdir = partid.replace(/^\\d*.?\\d*_?HWFILE/,'');
+ if (subdir != "" && subdir != undefined) {
+ fullpath = path+"/"+subdir+"/"+cleanfilename;
+ }
+ }
+ for (var m=0; m 0) {
+ if (allskipdel.length > 0) {
+ for (var n=0; n
+
+
+$arrayindexofjs
+
+ENDSCRIPT
+}
+
+##############################################
+##############################################
+
+sub resize_scrollbox_js {
+ my ($context,$tabidstr) = @_;
+ my (%names,$paddingwfrac,$offsetwfrac,$offsetv,$minw,$minv);
+ if ($context eq 'docs') {
+ %names = (
+ boxw => 'contenteditor',
+ item => 'contentlist',
+ header => 'uploadfileresult',
+ scroll => 'contentscroll',
+ boxh => 'contenteditor',
+ );
+ $paddingwfrac = 0.09;
+ $offsetwfrac = 0.015;
+ $offsetv = 20;
+ $minw = 250;
+ $minv = 200;
+ } elsif ($context eq 'params') {
+ %names = (
+ boxw => 'parameditor',
+ item => 'mapmenuinner',
+ header => 'parmstep1',
+ scroll => 'mapmenuscroll',
+ boxh => 'parmlevel',
+ );
+ $paddingwfrac = 0.2;
+ $offsetwfrac = 0.015;
+ $offsetv = 80;
+ $minw = 100;
+ $minv = 100;
+ }
+ my $viewport_js = &Apache::loncommon::viewport_geometry_js();
+ my $output = '
+
+window.onresize=callResize;
+
+';
+ if ($context eq 'docs') {
+ $output .= '
+var activeTab;
+';
+ }
+ $output .= <<"FIRST";
+
+$viewport_js
+
+function resize_scrollbox(scrollboxname,chkw,chkh) {
+ var scrollboxid = 'div_'+scrollboxname;
+ var scrolltableid = 'table_'+scrollboxname;
+ var scrollbox;
+ var scrolltable;
+
+ if (document.getElementById("$names{'boxw'}") == null) {
+ return;
+ }
+
+ if (document.getElementById(scrollboxid) == null) {
+ return;
+ } else {
+ scrollbox = document.getElementById(scrollboxid);
+ }
+
+
+ if (document.getElementById(scrolltableid) == null) {
+ return;
+ } else {
+ scrolltable = document.getElementById(scrolltableid);
+ }
+
+ init_geometry();
+ var vph = Geometry.getViewportHeight();
+ var vpw = Geometry.getViewportWidth();
+
+FIRST
+ if ($context eq 'docs') {
+ $output .= "
+ var alltabs = ['$tabidstr'];
+";
+ } elsif ($context eq 'params') {
+ $output .= "
+ if (document.getElementById('$names{'boxh'}') == null) {
+ return;
+ }
+";
+ }
+ $output .= <<"SECOND";
+ var listwchange;
+ if (chkw == 1) {
+ var boxw = document.getElementById("$names{'boxw'}").offsetWidth;
+ var itemw;
+ var itemid = document.getElementById("$names{'item'}");
+ if (itemid != null) {
+ itemw = itemid.offsetWidth;
+ }
+ var itemwstart = itemw;
+
+ var scrollboxw = scrollbox.offsetWidth;
+ var scrollboxscrollw = scrollbox.scrollWidth;
+
+ var offsetw = parseInt(vpw * $offsetwfrac);
+ var paddingw = parseInt(vpw * $paddingwfrac);
+
+ var minscrollboxw = $minw;
+ var maxcolw = 0;
+SECOND
+ if ($context eq 'docs') {
+ $output .= <<"DOCSONE";
+ var actabw = 0;
+ for (var i=0; i maxcolw) {
+ maxcolw = actabw;
+ }
+ } else {
+ if (document.getElementById(alltabs[i]) != null) {
+ var thistab = document.getElementById(alltabs[i]);
+ thistab.style.visibility = 'hidden';
+ thistab.style.display = 'block';
+ var tabw = document.getElementById(alltabs[i]).offsetWidth;
+ thistab.style.display = 'none';
+ thistab.style.visibility = '';
+ if (tabw > maxcolw) {
+ maxcolw = tabw;
+ }
+ }
+ }
+ }
+DOCSONE
+ } elsif ($context eq 'params') {
+ $output .= <<"PARAMSONE";
+ var parmlevelrows = new Array();
+ var mapmenucells = new Array();
+ parmlevelrows = document.getElementById("$names{'boxh'}").rows;
+ var numrows = parmlevelrows.length;
+ if (numrows > 1) {
+ mapmenucells = parmlevelrows[2].getElementsByTagName('td');
+ }
+ maxcolw = mapmenucells[0].offsetWidth;
+PARAMSONE
+ }
+ $output .= <<"THIRD";
+ if (maxcolw > 0) {
+ var newscrollboxw;
+ if (maxcolw+paddingw+scrollboxscrollw scrollboxheight) {
+ if (freevspace > offsetv) {
+ newscrollboxheight = scrollboxheight+freevspace-offsetv;
+ if (newscrollboxheight < minvscrollbox) {
+ newscrollboxheight = minvscrollbox;
+ }
+ scrollbox.style.height = newscrollboxheight+"px";
+ }
+ }
+ }
+ scrollboxheight = scrollbox.offsetHeight;
+ var itemh = document.getElementById("$names{'item'}").offsetHeight;
+
+ if (scrollboxscrollheight <= scrollboxheight) {
+ if ((itemh+offsetv)&');
+ if ($symb) {
+ $cfile .= '&symb='.&HTML::Entities::encode($symb,'"<>&');
+ } elsif ($folderpath) {
+ $cfile .= '&folderpath='.&HTML::Entities::encode($folderpath,'"<>&');
+ }
+ if ($forceedit) {
+ $cfile .= '&forceedit=1';
+ }
+ if ($forcereg) {
+ $cfile .= '®ister=1';
+ }
+ $jscall = "need_switchserver('$cfile');";
+ }
+ } else {
+ unless ($cfile =~ m{^/priv/}) {
+ if ($symb) {
+ $cfile .= (($cfile=~/\?/)?'&':'?')."symb=$symb";
+ } elsif ($folderpath) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').
+ 'folderpath='.&HTML::Entities::encode(&escape($folderpath),'"<>&');
+ if ($title) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').
+ 'title='.&HTML::Entities::encode(&escape($title),'"<>&');
+ }
+ if ($idx) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').'idx='.$idx;
+ }
+ if ($suppurl) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').
+ 'suppurl='.&HTML::Entities::encode(&escape($suppurl));
+ }
+ }
+ if ($forceedit) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').'forceedit=1';
+ }
+ if ($forcereg) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').'register=1';
+ }
+ }
+ $jscall = "go('$cfile')";
+ }
+ return $jscall;
+}
+
+##############################################
+##############################################
+
+# javascript_valid_email
+#
+# Generates javascript to validate an e-mail address.
+# Returns a javascript function which accetps a form field as argumnent, and
+# returns false if field.value does not satisfy two regular expression matches
+# for a valid e-mail address. Backwards compatible with old browsers without
+# support for javascript RegExp (just checks for @ in field.value in this case).
+
+sub javascript_valid_email {
+ my $scripttag .= <<'END';
+function validmail(field) {
+ var str = field.value;
+ if (window.RegExp) {
+ var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
+ var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
+ var reg1 = new RegExp(reg1str);
+ var reg2 = new RegExp(reg2str);
+ if (!reg1.test(str) && reg2.test(str)) {
+ return true;
+ }
+ return false;
+ }
+ else
+ {
+ if(str.indexOf("@") >= 0) {
+ return true;
+ }
+ return false;
+ }
+}
+END
+ return $scripttag;
+}
+
+
+# USAGE: htmltag(element, content, {attribute => value,...});
+#
+# EXAMPLES:
+# - htmltag('a', 'this is an anchor', {href => 'www.example.com',
+# title => 'this is a title'})
+#
+# - You might want to set up needed tags like:
+#
+# my $h3 = sub { return htmltag( "h3", @_ ) };
+#
+# ... and use them: $h3->("This is a headline")
+#
+# - To set up a couple of tags, see sub inittags
+#
+# NOTES:
+# - Empty elements, such as are correctly terminated,
+# i.e. htmltag('br') returns
+# - Empty attributes (title="") are filtered out.
+# - The function will not check for deprecated attributes.
+#
+# OUTPUT: content enclosed in xhtml conform tags
+sub htmltag{
+ return
+ qq|<$_[0]|
+ . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } )
+ . ($_[1] ? qq|>$_[1]$_[0]>| : qq|/>|). "\n";
+};
+
+
+# USAGE: inittags(@tags);
+#
+# EXAMPLES:
+# - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )
+# $h1->("This is a headline") #Returns:
This is a headline
+#
+# NOTES: See sub htmltag for further information.
+#
+# OUTPUT: List of subroutines.
+sub inittags {
+ my @tags = @_;
+ return map { my $tag = $_;
+ sub { return htmltag( $tag, @_ ) }
+ } @tags;
+}
+
+
+# USAGE: scripttag(scriptcode, [start|end|both]);
+#
+# EXAMPLES:
+# - scripttag("alert('Hello World!')", 'both')
+# returns:
+#
+#
+# NOTES:
+# - works currently only for javascripts
+#
+# OUTPUT:
+# Scriptcode properly enclosed in