X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fcommon.pl;h=b661c34dce81d89518607058db80bed521b11f32;hb=fc490063361896eb3b2aa0939fc0df716ae38262;hp=fb98b70c0fce135943cfd575adf463f5b5b27383;hpb=595dc614f285c4ad859ab410e2c0e32026dd2dce;p=kivitendo-erp.git diff --git a/bin/mozilla/common.pl b/bin/mozilla/common.pl index fb98b70c0..b661c34dc 100644 --- a/bin/mozilla/common.pl +++ b/bin/mozilla/common.pl @@ -9,16 +9,18 @@ # ###################################################################### -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 $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 +30,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), @_)) { + 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 { @@ -73,7 +97,7 @@ sub select_employee_internal { restore_form($form->{"old_form"}); - &{ $callback_sub }($new_id, $new_name); + call_sub($callback_sub, $new_id, $new_name); $lxdebug->leave_sub(); } @@ -143,7 +167,7 @@ sub select_part_internal { restore_form($form->{"old_form"}); - &{ $callback_sub }($new_item); + call_sub($callback_sub, $new_item); $lxdebug->leave_sub(); } @@ -400,68 +424,163 @@ sub calculate_qty { $lxdebug->leave_sub(); } -sub calculate_alu { +sub set_longdescription { + $lxdebug->enter_sub(); + + + my $callback = "$form->{script}?action=set_longdescription&"; + map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } + (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); + + $form->{"title"} = $locale->text("Enter longdescription"); + $form->header(); + print($form->parse_html_template("generic/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 ($length, $weight) = split /\r\n/,$form->{formel}; + my ($dateformat, $longformat, @indices) = @_; + + $dateformat = $myconfig{"dateformat"} unless ($dateformat); + + foreach my $idx (@indices) { + next unless (defined($form->{$idx})); - map({ $form->{$_} = "" } (qw(qty_alu price_alu total_alu qty_eloxal price_eloxal total_eloxal total))); + if (!ref($form->{$idx})) { + $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx}, + $dateformat, $longformat); - if ($form->{description} =~ /.*Alupreisberechnung.*/) { - $form->{description} =~ /.*Alupreisberechnung:\n(.*)kg Aluminiumprofil Einzelpreis: (.*) Gesamt: (.*)\n(.*)m Eloxal Einzelpreis: (.*) Gesamt: (.*)/; - $form->{qty_alu} = $1; - $form->{price_alu} = $2; - $form->{total_alu} = $3; - $form->{qty_eloxal} = $4; - $form->{price_eloxal} = $5; - $form->{total_eloxal} = $6; - $form->{total} = $form->format_amount(\%myconfig, ($form->parse_amount(\%myconfig, $form->{total_alu}) + $form->parse_amount(\%myconfig, $form->{total_eloxal}))); + } 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); + } + } } - ($form->{description}, $null) = split /\nAlupreisberechnung/, $form->{description}; - my $callback = "$form->{script}?action=vendor_selection&"; - map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); + $lxdebug->leave_sub(); +} - my @header_sort = qw(name customernumber address); - my %header_title = ( "name" => $locale->text("Name"), - "customernumber" => $locale->text("Customer Number"), - "address" => $locale->text("Address"), - ); - ($null, $form->{weight}) = split / /, $weight; - ($null, $form->{length}) = split / /, $length; +sub reformat_numbers { + $lxdebug->enter_sub(); - $form->{calc_weight} = $form->parse_amount(\%myconfig, $form->{weight}); - $form->{calc_length} = $form->parse_amount(\%myconfig, $form->{length}); + my ($numberformat, $places, @indices) = @_; + return $lxdebug->leave_sub() + if (!$numberformat || ($numberformat eq $myconfig{"numberformat"})); - my @header = - map(+{ "column_title" => $header_title{$_}, - "column" => $_, - }, - @header_sort); + foreach my $idx (@indices) { + next unless (defined($form->{$idx})); - $form->{"title"} = $locale->text("Enter values for aluminium calculation"); - $form->header(); - print($form->parse_html_template("generic/calculate_alu")); + 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(); +} -sub set_longdescription { +sub call_sub { $lxdebug->enter_sub(); + my $name = shift; - my $callback = "$form->{script}?action=set_longdescription&"; - map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); + if (!$name) { + $form->error($locale->text("Trying to call a sub without a name")); + } - $form->{"title"} = $locale->text("Enter longdescription"); - $form->header(); - print($form->parse_html_template("generic/set_longdescription")); + $name =~ s/[^a-zA-Z0-9_]//g; + + if (!defined(&{ $name })) { + $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name)); + } + + &{ $name }(@_); $lxdebug->leave_sub(); } +sub show_vc_details { + $lxdebug->enter_sub(); + + $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor"; + $form->isblank("vc_id", + $form->{vc} eq "customer" ? + $locale->text("No customer has been selected yet.") : + $locale->text("No vendor has been selected yet.")); + + Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id}); + + $form->{title} = $form->{vc} eq "customer" ? + $locale->text("Customer details") : $locale->text("Vendor details"); + $form->header(); + print($form->parse_html_template("common/show_vc_details", + { "is_customer" => $form->{vc} eq "customer" })); + + $lxdebug->leave_sub(); +} + 1;