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)
16 $sql = "UPDATE ".TB_PREF."printers SET description=".db_escape($descr)
17 .",name=".db_escape($name).",queue=".db_escape($queue)
18 .",host=".db_escape($host).",port='$port',timeout='$timeout' "
21 $sql = "INSERT INTO ".TB_PREF."printers ("
22 ."name,description,queue,host,port,timeout) "
23 ."VALUES (".db_escape($name).",".db_escape($descr).","
24 .db_escape($queue).",".db_escape($host).",'$port','$timeout')";
26 return db_query($sql,"could not write printer definition");
29 function get_all_printers()
31 $sql = "SELECT * FROM ".TB_PREF."printers";
32 return db_query($sql,"could not get printer definitions");
35 function get_printer($id)
37 $sql = "SELECT * FROM ".TB_PREF."printers
40 $result = db_query($sql,"could not get printer definition");
41 return db_fetch($result);
44 //============================================================================
45 // printer profiles functions
47 function update_printer_profile($name, $dest)
49 foreach( $dest as $rep => $printer) {
50 if ($printer != '' || $rep == '') {
51 $sql = "REPLACE INTO ".TB_PREF."print_profiles "
52 ."(profile, report, printer) VALUES ("
55 .db_escape($printer).")";
57 $sql = "DELETE FROM ".TB_PREF."print_profiles WHERE ("
58 ."report=" . db_escape($rep)
59 ." AND profile=".db_escape($name).")";
61 $result = db_query($sql,"could not update printing profile");
69 // Get destination for report defined in given printing profile.
71 function get_report_printer($profile, $report)
73 $sql = "SELECT printer FROM ".TB_PREF."print_profiles WHERE "
74 ."profile=".db_escape($profile)." AND report=";
76 $result = db_query($sql.db_escape($report), 'report printer lookup failed');
78 if (!$result) return false;
79 $ret = db_fetch($result);
81 $result = db_query($sql."''", 'default report printer lookup failed');
82 if (!$result) return false;
84 $ret = db_fetch($result);
85 if (!$ret) return false;
87 return get_printer($ret['printer']);
90 function delete_printer_profile($name)
92 $sql="DELETE FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
93 return db_query($sql,"could not delete printing profile");
96 // Get all report destinations for given profile.
98 function get_print_profile($name)
100 $sql = "SELECT * FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
101 return db_query($sql,"could not get printing profile");