+ $form->{PD}{ $form->{formname} } = "selected";
+ $form->{DF}{ $form->{format} } = "selected";
+ $form->{OP}{ $form->{media} } = "selected";
+ $form->{SM}{ $form->{formname} } = "selected";
+
+ push @FORMNAME, grep $_,
+ ($form->{type} eq 'purchase_order') ? (
+ opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')),
+ opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List'))
+ ) : undef,
+ ($form->{type} eq 'credit_note') ?
+ opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef,
+ ($form->{type} eq 'sales_order') ? (
+ opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')),
+ opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
+ ) : undef,
+ ($form->{type} =~ /sales_quotation$/) ?
+ opthash('sales_quotation', $form->{PD}{sales_quotation}, $locale->text('Quotation')) : undef,
+ ($form->{type} =~ /request_quotation$/) ?
+ opthash('request_quotation', $form->{PD}{request_quotation}, $locale->text('Request for Quotation')) : undef,
+ ($form->{type} eq 'invoice') ? (
+ opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')),
+ opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
+ ) : undef,
+ ($form->{type} eq 'invoice' && $form->{storno}) ? (
+ opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')),
+ opthash("storno_packing_list", $form->{PD}{storno_packing_list}, $locale->text('Storno Packing List'))
+ ) : undef,
+ ($form->{type} =~ /_delivery_order$/) ? (
+ opthash($form->{type}, $form->{PD}{$form->{type}}, $locale->text('Delivery Order')),
+ opthash('pick_list', $form->{PD}{pick_list}, $locale->text('Pick List')),
+ ) : undef,
+ ($form->{type} eq 'credit_note') ?
+ opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef;
+
+ push @SENDMODE,
+ opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')),
+ opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
+ if ($form->{media} eq 'email');
+
+ push @MEDIA, grep $_,
+ opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
+ (scalar @{ $form->{printers} } && $latex_templates) ?
+ opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
+ ($latex_templates && !$options{no_queue}) ?
+ opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
+ if ($form->{media} ne 'email');
+
+ push @FORMAT, grep $_,
+ ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)
+ && !$options{no_opendocument_pdf}) ?
+ opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef,
+ ($latex_templates) ?
+ opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')) : undef,
+ ($latex_templates && !$options{no_postscript}) ?
+ opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript')) : undef,
+ (!$options{no_html}) ?
+ opthash("html", $form->{DF}{html}, "HTML") : undef,
+ ($opendocument_templates && !$options{no_opendocument}) ?
+ opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef;
+
+ push @LANGUAGE_ID,
+ map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
+ if (ref $form->{languages} eq 'ARRAY');
+
+ push @PRINTER_ID,
+ map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
+ if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } });
+
+ @SELECTS = map { sname => lc $_, DATA => \@$_, show => !$options{"hide_" . lc($_)} && scalar @$_ }, qw(FORMNAME LANGUAGE_ID FORMAT SENDMODE MEDIA PRINTER_ID);
+
+ my %dont_display_groupitems = (
+ 'dunning' => 1,
+ );
+
+ %template_vars = (
+ display_copies => scalar @{ $form->{printers} } && $latex_templates && $form->{media} ne 'email',
+ display_remove_draft => (!$form->{id} && $form->{draft_id}),
+ display_groupitems => !$dont_display_groupitems{$form->{type}},
+ groupitems_checked => $form->{groupitems} ? "checked" : '',
+ remove_draft_checked => $form->{remove_draft} ? "checked" : ''
+ );