+ #quote select[customer|vendor] Bug 133
+ $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
+
+ #substitute \n and \r to \s (bug 543)
+ $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
+
+ my @old_project_ids = ($form->{"globalproject_id"}, grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{"rowcount"});
+
+ my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
+ $form->get_lists("contacts" => "ALL_CONTACTS",
+ "shipto" => "ALL_SHIPTO",
+ "projects" => { "key" => "ALL_PROJECTS",
+ "all" => 0,
+ "old_id" => \@old_project_ids },
+ "employees" => "ALL_EMPLOYEES",
+ "salesmen" => "ALL_SALESMEN",
+ "taxzones" => "ALL_TAXZONES",
+ "payments" => "ALL_PAYMENTS",
+ "currencies" => "ALL_CURRENCIES",
+ $vc => { key => "ALL_" . uc($vc),
+ limit => $myconfig{vclimit} + 1 },
+ "price_factors" => "ALL_PRICE_FACTORS");
+
+ # contacts
+ @values = ("", map { $_->{cp_id} } @{ $form->{ALL_CONTACTS} });
+ %labels = map { $_->{cp_id} => $_->{"cp_name"} . ($_->{cp_abteilung} ? " ($_->{cp_abteilung})" : "") } @{ $form->{ALL_CONTACTS} };
+ $TMPL_VAR{contact} = NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
+ '-labels' => \%labels, '-default' => $form->{"cp_id"})) if scalar @values > 1;
+
+ # vendor/customer
+ @values = map { "$_->{name}--$_->{id}" } @{ $form->{uc "all_$form->{vc}s" } };
+ %labels = map { +"$_->{name}--$_->{id}" => $_->{name} } @{ $form->{uc "all_$form->{vc}s" } };
+ push @custom_hiddens, "$form->{vc}_id";
+ push @custom_hiddens, "old$form->{vc}";
+ push @custom_hiddens, "select$form->{vc}";
+ $TMPL_VAR{vc} = sprintf qq|<th align="right">%s</th><td>%s<input type="button" value="?" onclick="show_vc_details('$form->{vc}')"></td>|,
+ $locale->text(ucfirst $form->{vc}),
+ ($myconfig{vclimit} <= scalar(@values))
+ ? $cgi->textfield(-value => H($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/), -name => $form->{vc})
+ : NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
+ '-onChange' => "document.getElementById('update_button').click();",
+ '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px'));
+
+ # payments (for footer)
+ @values = ("", map { $_->{id} } @{ $form->{ALL_PAYMENTS} });
+ %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_PAYMENTS} };
+ $TMPL_VAR{payments} = NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
+ '-labels' => \%labels, '-default' => $form->{payment_id}));
+
+ # shipto
+ @values = ("", map { $_->{shipto_id} } @{ $form->{ALL_SHIPTO} });
+ $TMPL_VAR{ALL_SHIPTO} = $form->{ALL_SHIPTO};
+ for my $item ( @{ $TMPL_VAR{ALL_SHIPTO} }) {
+ $item->{label} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
+ }
+ %labels = map { my $item=$_; $_->{shipto_id} => join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city) } @{ $form->{ALL_SHIPTO} };
+ $TMPL_VAR{shipto} = NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
+ '-labels' => \%labels, '-default' => $form->{"shipto_id"})) if scalar @values > 1;
+
+ # projects
+ @values = ("", map { $_->{id} } @{ $form->{ALL_PROJECTS} });
+ %labels = map { $_->{id} => $_->{projectnumber} } @{ $form->{ALL_PROJECTS} };
+ $TMPL_VAR{globalprojectnumber} = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
+ '-labels' => \%labels, '-default' => $form->{"globalproject_id"}));
+
+ # salesmen
+ @values = map { $_->{id} } @{ $form->{ALL_SALESMEN} };
+ %labels = map { $_->{id} => ($_->{name} || $_->{login}) } @{ $form->{ALL_SALESMEN} };
+ $TMPL_VAR{salesmen} = NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
+ '-values' => \@values, '-labels' => \%labels)) if $form->{type} =~ /^sales_/ && scalar @values;
+
+ # employees
+ @values = map { $_->{id} } @{ $form->{ALL_EMPLOYEES} };
+ %labels = map { $_->{id} => $_->{name} || $_->{login} } @{ $form->{ALL_EMPLOYEES} };
+ $TMPL_VAR{employee} = NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
+ '-values' => \@values, '-labels' => \%labels));
+
+ # taxzone
+ @values = map { $_->{id} } @{ $form->{ALL_TAXZONES} };
+ %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_TAXZONES} };
+ $TMPL_VAR{taxzone} = NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
+ '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px'));
+
+ # currencies and exchangerate
+ @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
+ %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
+ $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
+ $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency} && $form->{exchangerate};
+ $TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
+ '-values' => \@values, '-labels' => \%labels)) if scalar @values;
+ push @custom_hiddens, "forex";
+ push @custom_hiddens, "exchangerate" if $form->{forex};
+
+ # credit remaining
+ $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
+ $TMPL_VAR{is_credit_remaining_negativ} = ($form->{creditremaining} =~ /-/) ? "0" : "1";
+
+ # business
+ $TMPL_VAR{business_label} = ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type'));
+
+ push @custom_hiddens, "ordnumber" if $form->{type} =~ /_quotation$/;
+ push @custom_hiddens, "customer_klass" if $form->{vc} eq 'customer';
+
+ $credittext = $locale->text('Credit Limit exceeded!!!');
+
+ $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
+ : ($form->{resubmit}) ? "document.oe.submit()"
+ : ($creditwarning) ? "alert('$credittext')"
+ : "focus()";
+
+ $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
+ $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
+ $TMPL_VAR{onload} = $onload;
+
+ $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
+ $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
+ $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;