2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 function write_printer_def($id, $name, $descr, $queue, $host, $port, $timeout)
15 $sql = "UPDATE ".TB_PREF."printers SET description=".db_escape($descr)
16 .",name=".db_escape($name).",queue=".db_escape($queue)
17 .",host=".db_escape($host).",port='$port',timeout='$timeout' "
20 $sql = "INSERT INTO ".TB_PREF."printers ("
21 ."name,description,queue,host,port,timeout) "
22 ."VALUES (".db_escape($name).",".db_escape($descr).","
23 .db_escape($queue).",".db_escape($host).",'$port','$timeout')";
25 return db_query($sql,"could not write printer definition");
28 function get_all_printers()
30 $sql = "SELECT * FROM ".TB_PREF."printers";
31 return db_query($sql,"could not get printer definitions");
34 function get_printer($id)
36 $sql = "SELECT * FROM ".TB_PREF."printers
39 $result = db_query($sql,"could not get printer definition");
40 return db_fetch($result);
43 //============================================================================
44 // printer profiles functions
46 function update_printer_profile($name, $dest)
48 foreach( $dest as $rep => $printer) {
49 if ($printer != '' || $rep == '') {
50 $sql = "REPLACE INTO ".TB_PREF."print_profiles "
51 ."(profile, report, printer) VALUES ("
54 .db_escape($printer).")";
56 $sql = "DELETE FROM ".TB_PREF."print_profiles WHERE ("
57 ."report=" . db_escape($rep)
58 ." AND profile=".db_escape($name).")";
60 $result = db_query($sql,"could not update printing profile");
68 // Get destination for report defined in given printing profile.
70 function get_report_printer($profile, $report)
72 $sql = "SELECT printer FROM ".TB_PREF."print_profiles WHERE "
73 ."profile=".db_escape($profile)." AND report=";
75 $result = db_query($sql.db_escape($report), 'report printer lookup failed');
77 if (!$result) return false;
78 $ret = db_fetch($result);
80 $result = db_query($sql."''", 'default report printer lookup failed');
81 if (!$result) return false;
83 $ret = db_fetch($result);
84 if (!$ret) return false;
86 return get_printer($ret['printer']);
89 function delete_printer_profile($name)
91 $sql="DELETE FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
92 return db_query($sql,"could not delete printing profile");
95 // Get all report destinations for given profile.
97 function get_print_profile($name)
99 $sql = "SELECT * FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
100 return db_query($sql,"could not get printing profile");