unstable-Zweig als Kopie des "alten" trunks erstellt.
[kivitendo-erp.git] / SL / XIII.pm
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #
8 # XIII form retrieval
9 #
10 #======================================================================
11
12 package XIII;
13
14
15 sub retrieve_form {
16   $main::lxdebug->enter_sub();
17
18   my ($self, $myconfig, $form) = @_;
19
20   my $dbh = $form->dbconnect($myconfig);
21   my $query = qq|SELECT f.line
22                  FROM xiii_forms f
23                  WHERE f.file = '$form->{file}'
24                  AND f.dbname = '$myconfig->{dbname}'
25                  ORDER BY f.oid|;
26   my $sth = $dbh->prepare($query);
27   $sth->execute || $form->dberror($query);
28   
29   my $ref;
30   
31   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
32     push @{ $form->{body} }, $ref->{line};
33   }
34   
35   $sth->finish;
36
37   $dbh->disconnect;
38
39   $main::lxdebug->leave_sub();
40 }
41
42
43
44 sub delete_form {
45   $main::lxdebug->enter_sub();
46
47   my ($self, $myconfig, $form) = @_;
48
49   # connect to database, turn AutoCommit off
50   my $dbh = $form->dbconnect_noauto($myconfig);
51
52   my $query = qq|DELETE FROM xiii_forms
53                  WHERE file = '$form->{file}'
54                  AND dbname = '$myconfig->{dbname}'|;
55   $dbh->do($query) || $form->dberror($query);
56   
57   # commit and redirect
58   $rc = $dbh->commit;
59   $dbh->disconnect;
60     
61   $main::lxdebug->leave_sub();
62
63   return $rc;
64 }
65
66
67 sub save_form {
68   $main::lxdebug->enter_sub();
69
70   my ($self, $myconfig, $form) = @_;
71
72   # connect to database, turn AutoCommit off
73   my $dbh = $form->dbconnect_noauto($myconfig);
74
75   my $query = qq|DELETE FROM xiii_forms
76                  WHERE file = '$form->{file}'
77                  AND dbname = '$myconfig->{dbname}'|;
78   $dbh->do($query) || $form->dberror($query);
79   
80  
81   $query = qq|INSERT INTO xiii_forms (line, file, dbname)
82               VALUES (?, '$form->{file}', '$myconfig->{dbname}')|;
83     
84   $sth = $dbh->prepare($query);
85
86
87   foreach $line (split /\r/, $form->{body}) {
88     $sth->execute($line) || $form->dberror($query);
89     $sth->finish;
90   }
91
92   $rc = $dbh->commit;
93   $dbh->disconnect;
94
95   $main::lxdebug->leave_sub();
96
97   return $rc;
98 }
99
100
101 1;
102