Old ineffective sql_trail superseded by new improved db_trail logging only calls...
[fa-stable.git] / gl / includes / db / gl_db_currencies.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
14 function update_currency($curr_abrev, $symbol, $currency, $country, 
15         $hundreds_name, $auto_update)
16 {
17         begin_transaction(__FUNCTION__, func_get_args());
18         $sql = "UPDATE ".TB_PREF."currencies SET currency=".db_escape($currency)
19                 .", curr_symbol=".db_escape($symbol).", country=".db_escape($country)
20                 .", hundreds_name=".db_escape($hundreds_name)
21                 .",auto_update = ".db_escape($auto_update)
22                         ." WHERE curr_abrev = ".db_escape($curr_abrev);
23
24         db_query($sql, "could not update currency for $curr_abrev");
25         commit_transaction();
26 }
27
28 //---------------------------------------------------------------------------------------------
29
30 function add_currency($curr_abrev, $symbol, $currency, $country, 
31         $hundreds_name, $auto_update)
32 {
33         begin_transaction(__FUNCTION__, func_get_args());
34
35         $sql = "INSERT INTO ".TB_PREF."currencies (curr_abrev, curr_symbol, currency, 
36                         country, hundreds_name, auto_update)
37                 VALUES (".db_escape($curr_abrev).", ".db_escape($symbol).", "
38                 .db_escape($currency).", ".db_escape($country).", "
39                 .db_escape($hundreds_name).",".db_escape($auto_update).")";
40
41         db_query($sql, "could not add currency for $curr_abrev");
42
43         $result = db_insert_id();
44         commit_transaction();
45         return $result;
46 }
47
48 //---------------------------------------------------------------------------------------------
49
50 function delete_currency($curr_code)
51 {
52         begin_transaction(__FUNCTION__, func_get_args());
53
54         $sql="DELETE FROM ".TB_PREF."currencies WHERE curr_abrev=".db_escape($curr_code);
55         db_query($sql, "could not delete currency       $curr_code");
56
57         $sql="DELETE FROM ".TB_PREF."exchange_rates WHERE curr_code='$curr_code'";
58         db_query($sql, "could not delete exchange rates for currency $curr_code");
59
60         commit_transaction();
61 }
62
63 //---------------------------------------------------------------------------------------------
64
65 function get_currency($curr_code)
66 {
67         $sql = "SELECT * FROM ".TB_PREF."currencies WHERE curr_abrev=".db_escape($curr_code);
68         $result = db_query($sql, "could not get currency $curr_code");
69
70         $row = db_fetch($result);
71         return $row;
72 }
73
74 //---------------------------------------------------------------------------------------------
75
76 function get_currencies($all=false)
77 {
78         $sql = "SELECT * FROM ".TB_PREF."currencies";
79         if (!$all) $sql .= " WHERE !inactive";
80         return db_query($sql, "could not get currencies");
81 }
82