342cddc4eb6275c6a45424fa861c760547cc8eb7
[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         $sql = "UPDATE ".TB_PREF."currencies SET currency=".db_escape($currency).", curr_symbol='$symbol',
18                 country=".db_escape($country).", hundreds_name=".db_escape($hundreds_name)
19                 .",auto_update = '$auto_update'"." WHERE curr_abrev = '$curr_abrev'";
20
21         db_query($sql, "could not update currency for $curr_abrev");
22 }
23
24 //---------------------------------------------------------------------------------------------
25
26 function add_currency($curr_abrev, $symbol, $currency, $country, 
27         $hundreds_name, $auto_update)
28 {
29         $sql = "INSERT INTO ".TB_PREF."currencies (curr_abrev, curr_symbol, currency, country, 
30                 hundreds_name, auto_update)
31                 VALUES (".db_escape($curr_abrev).", '$symbol', ".db_escape($currency)
32                 .", ".db_escape($country).", ".db_escape($hundreds_name)
33                 .",".db_escape($auto_update).")";
34
35         db_query($sql, "could not add currency for $curr_abrev");
36 }
37
38 //---------------------------------------------------------------------------------------------
39
40 function delete_currency($curr_code)
41 {
42         $sql="DELETE FROM ".TB_PREF."currencies WHERE curr_abrev='$curr_code'";
43         db_query($sql, "could not delete currency       $curr_code");
44
45         $sql="DELETE FROM ".TB_PREF."exchange_rates WHERE curr_code='$curr_code'";
46         db_query($sql, "could not delete exchange rates for currency $curr_code");
47 }
48
49 //---------------------------------------------------------------------------------------------
50
51 function get_currency($curr_code)
52 {
53         $sql = "SELECT * FROM ".TB_PREF."currencies WHERE curr_abrev='$curr_code'";
54         $result = db_query($sql, "could not get currency $curr_code");
55
56         $row = db_fetch($result);
57         return $row;
58 }
59
60 //---------------------------------------------------------------------------------------------
61
62 function get_currencies($all=false)
63 {
64         $sql = "SELECT * FROM ".TB_PREF."currencies";
65         if (!$all) $sql .= " WHERE !inactive";
66         return db_query($sql, "could not get currencies");
67 }
68
69 //---------------------------------------------------------------------------------------------
70
71 ?>