1 |
|
package SL::Printer;
|
2 |
|
|
3 |
|
use strict;
|
4 |
|
|
5 |
|
use SL::DBUtils;
|
6 |
|
|
7 |
|
sub all_printers {
|
8 |
|
$::lxdebug->enter_sub;
|
9 |
|
|
10 |
|
my ($self, %params) = @_;
|
11 |
|
|
12 |
|
my $dbh = $::auth->get_user_dbh($params{login});
|
13 |
|
|
14 |
|
my $query = qq|SELECT * FROM printers ORDER BY printer_description|;
|
15 |
|
my @printers = selectall_hashref_query($::form, $dbh, $query);
|
16 |
|
|
17 |
|
$dbh->disconnect;
|
18 |
|
|
19 |
|
$::lxdebug->leave_sub;
|
20 |
|
|
21 |
|
return wantarray ? @printers : \@printers;
|
22 |
|
}
|
23 |
|
|
24 |
|
sub get_printer {
|
25 |
|
$::lxdebug->enter_sub;
|
26 |
|
|
27 |
|
my ($self, %params) = @_;
|
28 |
|
|
29 |
|
my $dbh = $::auth->get_user_dbh($params{login});
|
30 |
|
|
31 |
|
my $query = qq|SELECT * FROM printers WHERE id = ?|;
|
32 |
|
my ($printer) = selectfirst_hashref_query($::form, $dbh, $query, $params{id});
|
33 |
|
|
34 |
|
$dbh->disconnect;
|
35 |
|
|
36 |
|
$::lxdebug->leave_sub;
|
37 |
|
|
38 |
|
return $printer;
|
39 |
|
}
|
40 |
|
|
41 |
|
sub save_printer {
|
42 |
|
$main::lxdebug->enter_sub();
|
43 |
|
|
44 |
|
my ($self, %params) = @_;
|
45 |
|
|
46 |
|
# connect to database
|
47 |
|
my $dbh = $::auth->get_user_dbh($params{login});
|
48 |
|
my $printer = $params{printer};
|
49 |
|
|
50 |
|
unless ($printer->{id}) {
|
51 |
|
($printer->{id}) = selectfirst_array_query($::form, $dbh, "SELECT nextval('id'::text)");
|
52 |
|
do_query($::form, $dbh, "INSERT INTO printers (id, printer_description) VALUES (?, '')", $printer->{id});
|
53 |
|
}
|
54 |
|
|
55 |
|
my $query = <<SQL;
|
56 |
|
UPDATE printers SET
|
57 |
|
printer_description = ?,
|
58 |
|
template_code = ?,
|
59 |
|
printer_command = ?
|
60 |
|
WHERE id = ?
|
61 |
|
SQL
|
62 |
|
do_query($::form, $dbh, $query,
|
63 |
|
$printer->{printer_description},
|
64 |
|
$printer->{template_code},
|
65 |
|
$printer->{printer_command},
|
66 |
|
$printer->{id},
|
67 |
|
);
|
68 |
|
|
69 |
|
$dbh->commit;
|
70 |
|
$dbh->disconnect;
|
71 |
|
|
72 |
|
$::lxdebug->leave_sub;
|
73 |
|
}
|
74 |
|
|
75 |
|
sub delete_printer {
|
76 |
|
$::lxdebug->enter_sub;
|
77 |
|
|
78 |
|
my ($self, %params) = @_;
|
79 |
|
|
80 |
|
my $dbh = $::auth->get_user_dbh($params{login});
|
81 |
|
|
82 |
|
my $query = qq|DELETE FROM printers WHERE id = ?|;
|
83 |
|
do_query($::form, $dbh, $query, $params{id});
|
84 |
|
|
85 |
|
$dbh->commit;
|
86 |
|
$dbh->disconnect;
|
87 |
|
|
88 |
|
$::lxdebug->leave_sub;
|
89 |
|
}
|
90 |
|
|
91 |
|
1;
|
SL/Printer.pm wird nicht mehr benötigt