Inserted Copyright Notice and fixed graphic items
[fa-stable.git] / admin / db / printers_db.inc
1 <?php
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)
13 {
14         if ($id>0)
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' "
18                 ."WHERE id=$id";
19         else 
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')";
24
25         return db_query($sql,"could not write printer definition");
26 }
27
28 function get_all_printers() 
29 {
30         $sql = "SELECT * FROM ".TB_PREF."printers";
31         return db_query($sql,"could not get printer definitions");
32 }
33
34 function get_printer($id)
35 {
36                 $sql = "SELECT * FROM ".TB_PREF."printers
37                         WHERE id=$id";
38
39                 $result = db_query($sql,"could not get printer definition");
40                 return  db_fetch($result);
41 }
42
43 //============================================================================
44 // printer profiles functions
45 //
46 function update_printer_profile($name, $dest)
47 {
48         foreach( $dest as $rep => $printer) {
49                 if ($printer != '' || $rep == '') {
50                         $sql = "REPLACE INTO ".TB_PREF."print_profiles "
51                         ."(profile, report, printer) VALUES ("
52                         .db_escape($name).","
53                         .db_escape($rep).","
54                         .db_escape($printer).")";
55                 } else {
56                         $sql = "DELETE FROM ".TB_PREF."print_profiles WHERE ("
57                                 ."report=" . db_escape($rep)
58                                 ." AND profile=".db_escape($name).")";
59                 }
60                 $result = db_query($sql,"could not update printing profile");
61                 if(!$result) {
62                         return false;
63                 }
64         }
65         return true;
66 }
67 //
68 //      Get destination for report defined in given printing profile.
69 //
70 function get_report_printer($profile, $report)
71 {
72         $sql = "SELECT printer FROM ".TB_PREF."print_profiles WHERE "
73                 ."profile=".db_escape($profile)." AND report=";
74
75         $result = db_query($sql.db_escape($report), 'report printer lookup failed');
76
77         if (!$result) return false;
78         $ret = db_fetch($result);
79         if ($ret === false) {
80                 $result = db_query($sql."''", 'default report printer lookup failed');
81                 if (!$result) return false;
82
83                 $ret = db_fetch($result);
84                 if (!$ret) return false;
85         }
86         return get_printer($ret['printer']);
87 }
88
89 function delete_printer_profile($name)
90 {
91         $sql="DELETE FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
92         return db_query($sql,"could not delete printing profile");
93 }
94 //
95 // Get all report destinations for given profile.
96 //
97 function get_print_profile($name)
98 {
99         $sql = "SELECT  * FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
100         return db_query($sql,"could not get printing profile");
101 }
102
103 ?>