Recurrent Invoices: fixed buggy call to non existing function and payment terms type...
[fa-stable.git] / admin / db / printers_db.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12
13 function write_printer_def($id, $name, $descr, $queue, $host, $port, $timeout)
14 {
15         begin_transaction(__FUNCTION__, func_get_args());
16
17         if ($id>0)
18                 $sql = "UPDATE ".TB_PREF."printers SET description=".db_escape($descr)
19                 .",name=".db_escape($name).",queue=".db_escape($queue)
20                 .",host=".db_escape($host).",port=".db_escape($port).",timeout=".db_escape($timeout)
21                 ." WHERE id=".db_escape($id);
22         else
23                 $sql = "INSERT INTO ".TB_PREF."printers ("
24                         ."name,description,queue,host,port,timeout) "
25                         ."VALUES (".db_escape($name).",".db_escape($descr).","
26                         .db_escape($queue).",".db_escape($host).",".db_escape($port).",".db_escape($timeout).")";
27
28         $result = db_query($sql,"could not write printer definition");
29
30         commit_transaction();
31         return  $result ? ($id ? $id : db_insert_id()) : false;
32 }
33
34 function get_all_printers() 
35 {
36         $sql = "SELECT * FROM ".TB_PREF."printers";
37         return db_query($sql,"could not get printer definitions");
38 }
39
40 function get_printer($id)
41 {
42                 $sql = "SELECT * FROM ".TB_PREF."printers
43                         WHERE id=".db_escape($id);
44
45                 $result = db_query($sql,"could not get printer definition");
46                 return  db_fetch($result);
47 }
48
49 function delete_printer($id)
50 {
51         begin_transaction(__FUNCTION__, func_get_args());
52
53         $sql="DELETE FROM ".TB_PREF."printers WHERE id=".db_escape($id);
54         db_query($sql,"could not delete printer definition");
55
56         commit_transaction();
57 }
58 //============================================================================
59 // printer profiles functions
60 //
61 function update_printer_profile($name, $dest)
62 {
63         begin_transaction(__FUNCTION__, func_get_args());
64
65         foreach( $dest as $rep => $printer) {
66                 if ($printer != '' || $rep == '') {
67                         $sql = "REPLACE INTO ".TB_PREF."print_profiles "
68                         ."(profile, report, printer) VALUES ("
69                         .db_escape($name).","
70                         .db_escape($rep).","
71                         .db_escape($printer ? $printer: null, true).")";
72                 } else {
73                         $sql = "DELETE FROM ".TB_PREF."print_profiles WHERE ("
74                                 ."report=" . db_escape($rep)
75                                 ." AND profile=".db_escape($name).")";
76                 }
77                 $result = db_query($sql,"could not update printing profile");
78                 if(!$result) {
79                         return false;
80                 }
81         }
82
83         commit_transaction();
84         return true;
85 }
86 //
87 //      Get destination for report defined in given printing profile.
88 //
89 function get_report_printer($profile, $report)
90 {
91         $sql = "SELECT printer FROM ".TB_PREF."print_profiles WHERE "
92                 ."profile=".db_escape($profile)." AND report=";
93
94         $result = db_query($sql.db_escape($report), 'report printer lookup failed');
95
96         if (!$result) return false;
97         $ret = db_fetch($result);
98         if ($ret === false) {
99                 $result = db_query($sql."''", 'default report printer lookup failed');
100                 if (!$result) return false;
101
102                 $ret = db_fetch($result);
103                 if (!$ret) return false;
104         }
105         return get_printer($ret['printer']);
106 }
107
108 function delete_printer_profile($name)
109 {
110         begin_transaction(__FUNCTION__, func_get_args());
111
112         $sql="DELETE FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
113         $result = db_query($sql,"could not delete printing profile");
114
115         commit_transaction();
116         return $result;
117 }
118 //
119 // Get all report destinations for given profile.
120 //
121 function get_print_profile($name)
122 {
123         $sql = "SELECT  * FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
124         return db_query($sql,"could not get printing profile");
125 }
126