Revision 2500bc30
Von Bernd Bleßmann vor fast 9 Jahren hinzugefügt
SL/Helper/PrintOptions.pm | ||
---|---|---|
1 |
package SL::Helper::PrintOptions; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use List::MoreUtils qw(any); |
|
6 |
|
|
7 |
|
|
8 |
# generate the printing options displayed at the bottom of oe and is forms. |
|
9 |
# this function will attempt to guess what type of form is displayed, and will generate according options |
|
10 |
# |
|
11 |
# about the coding: |
|
12 |
# this version builds the arrays of options pretty directly. if you have trouble understanding how, |
|
13 |
# the opthash function builds hashrefs which are then pieced together for the template arrays. |
|
14 |
# unneeded options are "undef"ed out, and then grepped out. |
|
15 |
# |
|
16 |
# the inline options is untested, but intended to be used later in metatemplating |
|
17 |
sub get_print_options { |
|
18 |
my ($class, %params) = @_; |
|
19 |
|
|
20 |
my $form = $params{form} || $::form; |
|
21 |
my $myconfig = $params{myconfig} || \%::myconfig; |
|
22 |
my $locale = $params{locale} || $::locale; |
|
23 |
my $options = $params{options}; |
|
24 |
|
|
25 |
# names 3 parameters and returns a hashref, for use in templates |
|
26 |
sub opthash { +{ value => shift, selected => shift, oname => shift } } |
|
27 |
my (@FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = (); |
|
28 |
|
|
29 |
# note: "||"-selection is only correct for values where "0" is _not_ a correct entry |
|
30 |
$form->{sendmode} = "attachment"; |
|
31 |
$form->{format} = $form->{format} || $myconfig->{template_format} || "pdf"; |
|
32 |
$form->{copies} = $form->{copies} || $myconfig->{copies} || 3; |
|
33 |
$form->{media} = $form->{media} || $myconfig->{default_media} || "screen"; |
|
34 |
$form->{printer_id} = defined $form->{printer_id} ? $form->{printer_id} : |
|
35 |
defined $myconfig->{default_printer_id} ? $myconfig->{default_printer_id} : ""; |
|
36 |
|
|
37 |
$form->{PD}{ $form->{formname} } = "selected"; |
|
38 |
$form->{DF}{ $form->{format} } = "selected"; |
|
39 |
$form->{OP}{ $form->{media} } = "selected"; |
|
40 |
$form->{SM}{ $form->{sendmode} } = "selected"; |
|
41 |
|
|
42 |
push @FORMNAME, grep $_, |
|
43 |
($form->{type} eq 'purchase_order') ? ( |
|
44 |
opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')), |
|
45 |
opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List')) |
|
46 |
) : undef, |
|
47 |
($form->{type} eq 'credit_note') ? |
|
48 |
opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef, |
|
49 |
($form->{type} eq 'sales_order') ? ( |
|
50 |
opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')), |
|
51 |
opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')), |
|
52 |
) : undef, |
|
53 |
($form->{type} =~ /sales_quotation$/) ? |
|
54 |
opthash('sales_quotation', $form->{PD}{sales_quotation}, $locale->text('Quotation')) : undef, |
|
55 |
($form->{type} =~ /request_quotation$/) ? |
|
56 |
opthash('request_quotation', $form->{PD}{request_quotation}, $locale->text('Request for Quotation')) : undef, |
|
57 |
($form->{type} eq 'invoice') ? ( |
|
58 |
opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')), |
|
59 |
opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')), |
|
60 |
) : undef, |
|
61 |
($form->{type} eq 'invoice' && $form->{storno}) ? ( |
|
62 |
opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')), |
|
63 |
) : undef, |
|
64 |
($form->{type} =~ /_delivery_order$/) ? ( |
|
65 |
opthash($form->{type}, $form->{PD}{$form->{type}}, $locale->text('Delivery Order')), |
|
66 |
opthash('pick_list', $form->{PD}{pick_list}, $locale->text('Pick List')), |
|
67 |
) : undef; |
|
68 |
|
|
69 |
push @SENDMODE, |
|
70 |
opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')), |
|
71 |
opthash("inline", $form->{SM}{inline}, $locale->text('In-line')) |
|
72 |
if ($form->{media} eq 'email'); |
|
73 |
|
|
74 |
my $printable_templates = any { $::lx_office_conf{print_templates}->{$_} } qw(latex opendocument); |
|
75 |
push @MEDIA, grep $_, |
|
76 |
opthash("screen", $form->{OP}{screen}, $locale->text('Screen')), |
|
77 |
($printable_templates && $form->{printers} && scalar @{ $form->{printers} }) ? |
|
78 |
opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef, |
|
79 |
($printable_templates && !$options->{no_queue}) ? |
|
80 |
opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef |
|
81 |
if ($form->{media} ne 'email'); |
|
82 |
|
|
83 |
push @FORMAT, grep $_, |
|
84 |
($::lx_office_conf{print_templates}->{opendocument} && $::lx_office_conf{applications}->{openofficeorg_writer} && $::lx_office_conf{applications}->{xvfb} |
|
85 |
&& (-x $::lx_office_conf{applications}->{openofficeorg_writer}) && (-x $::lx_office_conf{applications}->{xvfb}) |
|
86 |
&& !$options->{no_opendocument_pdf}) ? |
|
87 |
opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef, |
|
88 |
($::lx_office_conf{print_templates}->{latex}) ? |
|
89 |
opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')) : undef, |
|
90 |
($::lx_office_conf{print_templates}->{latex} && !$options->{no_postscript}) ? |
|
91 |
opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript')) : undef, |
|
92 |
(!$options->{no_html}) ? |
|
93 |
opthash("html", $form->{DF}{html}, "HTML") : undef, |
|
94 |
($::lx_office_conf{print_templates}->{opendocument} && !$options->{no_opendocument}) ? |
|
95 |
opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef, |
|
96 |
($::lx_office_conf{print_templates}->{excel} && !$options->{no_excel}) ? |
|
97 |
opthash("excel", $form->{DF}{excel}, $locale->text("Excel")) : undef; |
|
98 |
|
|
99 |
push @LANGUAGE_ID, |
|
100 |
map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} } |
|
101 |
if (ref $form->{languages} eq 'ARRAY'); |
|
102 |
|
|
103 |
push @PRINTER_ID, |
|
104 |
map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} } |
|
105 |
if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } }); |
|
106 |
|
|
107 |
@SELECTS = map { |
|
108 |
sname => $_->[1], |
|
109 |
DATA => $_->[0], |
|
110 |
show => !$options->{"hide_" . $_->[1]} && scalar @{ $_->[0] } |
|
111 |
}, |
|
112 |
[ \@FORMNAME, 'formname', ], |
|
113 |
[ \@LANGUAGE_ID, 'language_id', ], |
|
114 |
[ \@FORMAT, 'format', ], |
|
115 |
[ \@SENDMODE, 'sendmode', ], |
|
116 |
[ \@MEDIA, 'media', ], |
|
117 |
[ \@PRINTER_ID, 'printer_id', ]; |
|
118 |
|
|
119 |
my %dont_display_groupitems = ( |
|
120 |
'dunning' => 1, |
|
121 |
'letter' => 1, |
|
122 |
); |
|
123 |
|
|
124 |
my %template_vars = ( |
|
125 |
display_copies => scalar @{ $form->{printers} || [] } && $::lx_office_conf{print_templates}->{latex} && $form->{media} ne 'email', |
|
126 |
display_remove_draft => (!$form->{id} && $form->{draft_id}), |
|
127 |
display_groupitems => !$dont_display_groupitems{$form->{type}}, |
|
128 |
groupitems_checked => $form->{groupitems} ? "checked" : '', |
|
129 |
remove_draft_checked => $form->{remove_draft} ? "checked" : '' |
|
130 |
); |
|
131 |
|
|
132 |
return $form->parse_html_template("generic/print_options", { SELECTS => \@SELECTS, %template_vars } ); |
|
133 |
} |
|
134 |
|
|
135 |
|
|
136 |
1; |
|
137 |
|
bin/mozilla/io.pl | ||
---|---|---|
1083 | 1083 |
$main::lxdebug->leave_sub(); |
1084 | 1084 |
} |
1085 | 1085 |
|
1086 |
# generate the printing options displayed at the bottom of oe and is forms. |
|
1087 |
# this function will attempt to guess what type of form is displayed, and will generate according options |
|
1088 |
# |
|
1089 |
# about the coding: |
|
1090 |
# this version builds the arrays of options pretty directly. if you have trouble understanding how, |
|
1091 |
# the opthash function builds hashrefs which are then pieced together for the template arrays. |
|
1092 |
# unneeded options are "undef"ed out, and then grepped out. |
|
1093 |
# |
|
1094 |
# the inline options is untested, but intended to be used later in metatemplating |
|
1095 | 1086 |
sub print_options { |
1096 |
$main::lxdebug->enter_sub();
|
|
1087 |
$::lxdebug->enter_sub(); |
|
1097 | 1088 |
|
1098 |
my $form = $main::form; |
|
1099 |
my %myconfig = %main::myconfig; |
|
1100 |
my $locale = $main::locale; |
|
1089 |
my (%options) = @_; |
|
1101 | 1090 |
|
1102 | 1091 |
_check_io_auth(); |
1103 | 1092 |
|
1104 |
my %options = @_; |
|
1105 |
|
|
1106 |
# names 3 parameters and returns a hashref, for use in templates |
|
1107 |
sub opthash { +{ value => shift, selected => shift, oname => shift } } |
|
1108 |
my (@FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = (); |
|
1109 |
|
|
1110 |
# note: "||"-selection is only correct for values where "0" is _not_ a correct entry |
|
1111 |
$form->{sendmode} = "attachment"; |
|
1112 |
$form->{format} = $form->{format} || $myconfig{template_format} || "pdf"; |
|
1113 |
$form->{copies} = $form->{copies} || $myconfig{copies} || 3; |
|
1114 |
$form->{media} = $form->{media} || $myconfig{default_media} || "screen"; |
|
1115 |
$form->{printer_id} = defined $form->{printer_id} ? $form->{printer_id} : |
|
1116 |
defined $myconfig{default_printer_id} ? $myconfig{default_printer_id} : ""; |
|
1117 |
|
|
1118 |
$form->{PD}{ $form->{formname} } = "selected"; |
|
1119 |
$form->{DF}{ $form->{format} } = "selected"; |
|
1120 |
$form->{OP}{ $form->{media} } = "selected"; |
|
1121 |
$form->{SM}{ $form->{sendmode} } = "selected"; |
|
1122 |
|
|
1123 |
push @FORMNAME, grep $_, |
|
1124 |
($form->{type} eq 'purchase_order') ? ( |
|
1125 |
opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')), |
|
1126 |
opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List')) |
|
1127 |
) : undef, |
|
1128 |
($form->{type} eq 'credit_note') ? |
|
1129 |
opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef, |
|
1130 |
($form->{type} eq 'sales_order') ? ( |
|
1131 |
opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')), |
|
1132 |
opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')), |
|
1133 |
) : undef, |
|
1134 |
($form->{type} =~ /sales_quotation$/) ? |
|
1135 |
opthash('sales_quotation', $form->{PD}{sales_quotation}, $locale->text('Quotation')) : undef, |
|
1136 |
($form->{type} =~ /request_quotation$/) ? |
|
1137 |
opthash('request_quotation', $form->{PD}{request_quotation}, $locale->text('Request for Quotation')) : undef, |
|
1138 |
($form->{type} eq 'invoice') ? ( |
|
1139 |
opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')), |
|
1140 |
opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')), |
|
1141 |
) : undef, |
|
1142 |
($form->{type} eq 'invoice' && $form->{storno}) ? ( |
|
1143 |
opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')), |
|
1144 |
) : undef, |
|
1145 |
($form->{type} =~ /_delivery_order$/) ? ( |
|
1146 |
opthash($form->{type}, $form->{PD}{$form->{type}}, $locale->text('Delivery Order')), |
|
1147 |
opthash('pick_list', $form->{PD}{pick_list}, $locale->text('Pick List')), |
|
1148 |
) : undef; |
|
1149 |
|
|
1150 |
push @SENDMODE, |
|
1151 |
opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')), |
|
1152 |
opthash("inline", $form->{SM}{inline}, $locale->text('In-line')) |
|
1153 |
if ($form->{media} eq 'email'); |
|
1154 |
|
|
1155 |
my $printable_templates = any { $::lx_office_conf{print_templates}->{$_} } qw(latex opendocument); |
|
1156 |
push @MEDIA, grep $_, |
|
1157 |
opthash("screen", $form->{OP}{screen}, $locale->text('Screen')), |
|
1158 |
($printable_templates && $form->{printers} && scalar @{ $form->{printers} }) ? |
|
1159 |
opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef, |
|
1160 |
($printable_templates && !$options{no_queue}) ? |
|
1161 |
opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef |
|
1162 |
if ($form->{media} ne 'email'); |
|
1163 |
|
|
1164 |
push @FORMAT, grep $_, |
|
1165 |
($::lx_office_conf{print_templates}->{opendocument} && $::lx_office_conf{applications}->{openofficeorg_writer} && $::lx_office_conf{applications}->{xvfb} |
|
1166 |
&& (-x $::lx_office_conf{applications}->{openofficeorg_writer}) && (-x $::lx_office_conf{applications}->{xvfb}) |
|
1167 |
&& !$options{no_opendocument_pdf}) ? |
|
1168 |
opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef, |
|
1169 |
($::lx_office_conf{print_templates}->{latex}) ? |
|
1170 |
opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')) : undef, |
|
1171 |
($::lx_office_conf{print_templates}->{latex} && !$options{no_postscript}) ? |
|
1172 |
opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript')) : undef, |
|
1173 |
(!$options{no_html}) ? |
|
1174 |
opthash("html", $form->{DF}{html}, "HTML") : undef, |
|
1175 |
($::lx_office_conf{print_templates}->{opendocument} && !$options{no_opendocument}) ? |
|
1176 |
opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef, |
|
1177 |
($::lx_office_conf{print_templates}->{excel} && !$options{no_excel}) ? |
|
1178 |
opthash("excel", $form->{DF}{excel}, $locale->text("Excel")) : undef; |
|
1179 |
|
|
1180 |
push @LANGUAGE_ID, |
|
1181 |
map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} } |
|
1182 |
if (ref $form->{languages} eq 'ARRAY'); |
|
1183 |
|
|
1184 |
push @PRINTER_ID, |
|
1185 |
map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} } |
|
1186 |
if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } }); |
|
1187 |
|
|
1188 |
@SELECTS = map { |
|
1189 |
sname => $_->[1], |
|
1190 |
DATA => $_->[0], |
|
1191 |
show => !$options{"hide_" . $_->[1]} && scalar @{ $_->[0] } |
|
1192 |
}, |
|
1193 |
[ \@FORMNAME, 'formname', ], |
|
1194 |
[ \@LANGUAGE_ID, 'language_id', ], |
|
1195 |
[ \@FORMAT, 'format', ], |
|
1196 |
[ \@SENDMODE, 'sendmode', ], |
|
1197 |
[ \@MEDIA, 'media', ], |
|
1198 |
[ \@PRINTER_ID, 'printer_id', ]; |
|
1199 |
|
|
1200 |
my %dont_display_groupitems = ( |
|
1201 |
'dunning' => 1, |
|
1202 |
'letter' => 1, |
|
1203 |
); |
|
1204 |
|
|
1205 |
my %template_vars = ( |
|
1206 |
display_copies => scalar @{ $form->{printers} || [] } && $::lx_office_conf{print_templates}->{latex} && $form->{media} ne 'email', |
|
1207 |
display_remove_draft => (!$form->{id} && $form->{draft_id}), |
|
1208 |
display_groupitems => !$dont_display_groupitems{$form->{type}}, |
|
1209 |
groupitems_checked => $form->{groupitems} ? "checked" : '', |
|
1210 |
remove_draft_checked => $form->{remove_draft} ? "checked" : '' |
|
1211 |
); |
|
1093 |
my $inline = delete $options{inline}; |
|
1212 | 1094 |
|
1213 |
my $print_options = $form->parse_html_template("generic/print_options", { SELECTS => \@SELECTS, %template_vars } ); |
|
1095 |
require SL::Helper::PrintOptions; |
|
1096 |
my $print_options = SL::Helper::PrintOptions->get_print_options( |
|
1097 |
form => $::form, |
|
1098 |
myconfig => \%::myconfig, |
|
1099 |
locale => $::locale, |
|
1100 |
options => \%options); |
|
1214 | 1101 |
|
1215 |
if ($options{inline}) {
|
|
1216 |
$main::lxdebug->leave_sub();
|
|
1102 |
if ($inline) {
|
|
1103 |
$::lxdebug->leave_sub(); |
|
1217 | 1104 |
return $print_options; |
1218 | 1105 |
} |
1219 | 1106 |
|
1220 | 1107 |
print $print_options; |
1221 |
|
|
1222 |
$main::lxdebug->leave_sub(); |
|
1108 |
$::lxdebug->leave_sub(); |
|
1223 | 1109 |
} |
1224 | 1110 |
|
1111 |
|
|
1225 | 1112 |
sub print { |
1226 | 1113 |
$main::lxdebug->enter_sub(); |
1227 | 1114 |
|
Auch abrufbar als: Unified diff
print_options in Helper ausgelagert.