X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fcommon.pl;h=97391b2a9e2f7af31d3dda8bcac10ce6c62bfb91;hb=2cf0b165a479c86d378e795ca5d0745a901f422f;hp=c7dbfe5f22655a529153caaaebfa48b28c384a1b;hpb=92daa1a66a9ff737c92df86da3c28d663c421032;p=kivitendo-erp.git diff --git a/bin/mozilla/common.pl b/bin/mozilla/common.pl index c7dbfe5f2..97391b2a9 100644 --- a/bin/mozilla/common.pl +++ b/bin/mozilla/common.pl @@ -9,16 +9,19 @@ # ###################################################################### -use Data::Dumper; +use SL::Form; +use YAML; use SL::Common; sub save_form { $lxdebug->enter_sub(); - my $old_form = ""; - map({ $old_form .= "$_=" . $form->escape($form->{$_}) . '&'; } keys(%{$form})); - chop($old_form); + my $yaml = new YAML; + my $old_form = $yaml->dump($form); + $old_form =~ s|!|!!|g; + $old_form =~ s|\n|!n|g; + $old_form =~ s|\r|!r|g; $lxdebug->leave_sub(); @@ -28,16 +31,38 @@ sub save_form { sub restore_form { $lxdebug->enter_sub(); - my ($old_form) = @_; + my ($old_form, $no_delete) = @_; - map({ delete($form->{$_}); } keys(%{$form})); + map({ delete($form->{$_}); } keys(%{$form})) unless ($no_delete); + $old_form =~ s|!r|\r|g; + $old_form =~ s|!n|\n|g; + $old_form =~ s|!!|!|g; + my $new_form = YAML::Load($old_form); + map({ $form->{$_} = $new_form->{$_}; } keys(%{$new_form})); - foreach my $pair (split('&', $old_form)) { - my ($key, $value) = split('=', $form->unescape($pair), 2); - $form->{$key} = $value; + $lxdebug->leave_sub(); +} + +sub build_std_url { + $lxdebug->enter_sub(); + + my $url = "$form->{script}?"; + my $first = 1; + foreach my $key ((qw(login password path), @_)) { + next unless ($key); + $url .= "&" unless ($first); + $first = 0; + + if ($key =~ /=/) { + $url .= $key; + } else { + $url .= "${key}=" . E($form->{$key}); + } } $lxdebug->leave_sub(); + + return $url; } sub select_employee { @@ -415,4 +440,108 @@ sub set_longdescription { $lxdebug->leave_sub(); } +sub H { + return $form->quote_html($_[0]); +} + +sub Q { + return $form->quote($_[0]); +} + +sub E { + return $form->escape($_[0]); +} + +sub NTI { + my ($element) = @_; + + $element =~ s/tabindex\s*=\s*"\d+"//; + return $element; +} + +sub format_dates { + $lxdebug->enter_sub(); + + my ($dateformat, $longformat, @indices) = @_; + + $dateformat = $myconfig{"dateformat"} unless ($dateformat); + + foreach my $idx (@indices) { + next unless (defined($form->{$idx})); + + if (!ref($form->{$idx})) { + $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx}, + $dateformat, $longformat); + + } elsif (ref($form->{$idx}) eq "ARRAY") { + for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { + $form->{$idx}->[$i] = + $locale->reformat_date(\%myconfig, $form->{$idx}->[$i], + $dateformat, $longformat); + } + } + } + + $lxdebug->leave_sub(); +} + +sub reformat_numbers { + $lxdebug->enter_sub(); + + my ($numberformat, $places, @indices) = @_; + + return $lxdebug->leave_sub() + if (!$numberformat || ($numberformat eq $myconfig{"numberformat"})); + + foreach my $idx (@indices) { + next unless (defined($form->{$idx})); + + if (!ref($form->{$idx})) { + $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx}); + + } elsif (ref($form->{$idx}) eq "ARRAY") { + for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { + $form->{$idx}->[$i] = + $form->parse_amount(\%myconfig, $form->{$idx}->[$i]); + } + } + } + + my $saved_numberformat = $myconfig{"numberformat"}; + $myconfig{"numberformat"} = $numberformat; + + foreach my $idx (@indices) { + next unless (defined($form->{$idx})); + + if (!ref($form->{$idx})) { + $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places); + + } elsif (ref($form->{$idx}) eq "ARRAY") { + for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { + $form->{$idx}->[$i] = + $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places); + } + } + } + + $myconfig{"numberformat"} = $saved_numberformat; + + $lxdebug->leave_sub(); +} + +sub show_history { + $lxdebug->enter_sub(); + my $dbh = $form->dbconnect(\%myconfig); + + $form->{title} = $locale->text("History"); + $form->header(); + print $form->parse_html_template( "common/show_history", { + "DATEN" => $form->get_history($dbh,$form->{input_name}), + "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0") + } ); + + $dbh->disconnect(); + $lxdebug->leave_sub(); +} + 1;