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 ***********************************************************************/
13 function write_printer_def($id, $name, $descr, $queue, $host, $port, $timeout)
15 begin_transaction(__FUNCTION__, func_get_args());
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);
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).")";
28 $result = db_query($sql,"could not write printer definition");
31 return $result ? ($id ? $id : db_insert_id()) : false;
34 function get_all_printers()
36 $sql = "SELECT * FROM ".TB_PREF."printers";
37 return db_query($sql,"could not get printer definitions");
40 function get_printer($id)
42 $sql = "SELECT * FROM ".TB_PREF."printers
43 WHERE id=".db_escape($id);
45 $result = db_query($sql,"could not get printer definition");
46 return db_fetch($result);
49 function delete_printer($id)
51 begin_transaction(__FUNCTION__, func_get_args());
53 $sql="DELETE FROM ".TB_PREF."printers WHERE id=".db_escape($id);
54 db_query($sql,"could not delete printer definition");
58 //============================================================================
59 // printer profiles functions
61 function update_printer_profile($name, $dest)
63 begin_transaction(__FUNCTION__, func_get_args());
65 foreach( $dest as $rep => $printer) {
66 if ($printer != '' || $rep == '') {
67 $sql = "REPLACE INTO ".TB_PREF."print_profiles "
68 ."(profile, report, printer) VALUES ("
71 .db_escape($printer ? $printer: null, true).")";
73 $sql = "DELETE FROM ".TB_PREF."print_profiles WHERE ("
74 ."report=" . db_escape($rep)
75 ." AND profile=".db_escape($name).")";
77 $result = db_query($sql,"could not update printing profile");
87 // Get destination for report defined in given printing profile.
89 function get_report_printer($profile, $report)
91 $sql = "SELECT printer FROM ".TB_PREF."print_profiles WHERE "
92 ."profile=".db_escape($profile)." AND report=";
94 $result = db_query($sql.db_escape($report), 'report printer lookup failed');
96 if (!$result) return false;
97 $ret = db_fetch($result);
99 $result = db_query($sql."''", 'default report printer lookup failed');
100 if (!$result) return false;
102 $ret = db_fetch($result);
103 if (!$ret) return false;
105 return get_printer($ret['printer']);
108 function delete_printer_profile($name)
110 begin_transaction(__FUNCTION__, func_get_args());
112 $sql="DELETE FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
113 $result = db_query($sql,"could not delete printing profile");
115 commit_transaction();
119 // Get all report destinations for given profile.
121 function get_print_profile($name)
123 $sql = "SELECT * FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
124 return db_query($sql,"could not get printing profile");