hpdl
|
1204
|
1
|
<?php
|
|
2
|
/*
|
|
3
|
$Id: $
|
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
1374
|
8
|
Copyright (c) 2007 osCommerce
|
hpdl
|
1204
|
9
|
|
hpdl
|
1498
|
10
|
This program is free software; you can redistribute it and/or modify
|
|
11
|
it under the terms of the GNU General Public License v2 (1991)
|
|
12
|
as published by the Free Software Foundation.
|
hpdl
|
1204
|
13
|
*/
|
|
14
|
|
|
15
|
require('../includes/classes/currencies.php');
|
|
16
|
|
|
17
|
class osC_Currencies_Admin extends osC_Currencies {
|
|
18
|
function getData($id = null) {
|
|
19
|
if ( !empty($id) ) {
|
|
20
|
$currency_code = $this->getCode($id);
|
|
21
|
|
|
22
|
return array_merge($this->currencies[$currency_code], array('code' => $currency_code));
|
|
23
|
}
|
|
24
|
|
|
25
|
return $this->currencies;
|
|
26
|
}
|
|
27
|
|
|
28
|
function save($id = null, $data, $set_default = false) {
|
|
29
|
global $osC_Database;
|
|
30
|
|
hpdl
|
1374
|
31
|
$osC_Database->startTransaction();
|
|
32
|
|
hpdl
|
1204
|
33
|
if ( is_numeric($id) ) {
|
|
34
|
$Qcurrency = $osC_Database->query('update :table_currencies set title = :title, code = :code, symbol_left = :symbol_left, symbol_right = :symbol_right, decimal_places = :decimal_places, value = :value where currencies_id = :currencies_id');
|
|
35
|
$Qcurrency->bindInt(':currencies_id', $id);
|
|
36
|
} else {
|
|
37
|
$Qcurrency = $osC_Database->query('insert into :table_currencies (title, code, symbol_left, symbol_right, decimal_places, value) values (:title, :code, :symbol_left, :symbol_right, :decimal_places, :value)');
|
|
38
|
}
|
|
39
|
|
|
40
|
$Qcurrency->bindTable(':table_currencies', TABLE_CURRENCIES);
|
|
41
|
$Qcurrency->bindValue(':title', $data['title']);
|
|
42
|
$Qcurrency->bindValue(':code', $data['code']);
|
|
43
|
$Qcurrency->bindValue(':symbol_left', $data['symbol_left']);
|
|
44
|
$Qcurrency->bindValue(':symbol_right', $data['symbol_right']);
|
|
45
|
$Qcurrency->bindInt(':decimal_places', $data['decimal_places']);
|
|
46
|
$Qcurrency->bindValue(':value', $data['value']);
|
hpdl
|
1374
|
47
|
$Qcurrency->setLogging($_SESSION['module'], $id);
|
hpdl
|
1204
|
48
|
$Qcurrency->execute();
|
|
49
|
|
|
50
|
if ( !$osC_Database->isError() ) {
|
|
51
|
if ( !is_numeric($id) ) {
|
|
52
|
$id = $osC_Database->nextID();
|
|
53
|
}
|
|
54
|
|
|
55
|
if ( $set_default === true ) {
|
|
56
|
$Qupdate = $osC_Database->query('update :table_configuration set configuration_value = :configuration_value where configuration_key = :configuration_key');
|
|
57
|
$Qupdate->bindTable(':table_configuration', TABLE_CONFIGURATION);
|
|
58
|
$Qupdate->bindValue(':configuration_value', $data['code']);
|
|
59
|
$Qupdate->bindValue(':configuration_key', 'DEFAULT_CURRENCY');
|
hpdl
|
1374
|
60
|
$Qupdate->setLogging($_SESSION['module'], $id);
|
hpdl
|
1204
|
61
|
$Qupdate->execute();
|
hpdl
|
1616
|
62
|
}
|
hpdl
|
1204
|
63
|
|
hpdl
|
1616
|
64
|
if ( !$osC_Database->isError() ) {
|
|
65
|
$osC_Database->commitTransaction();
|
|
66
|
|
|
67
|
osC_Cache::clear('currencies');
|
|
68
|
|
|
69
|
if ( ( $set_default === true ) && $Qupdate->affectedRows() ) {
|
hpdl
|
1204
|
70
|
osC_Cache::clear('configuration');
|
|
71
|
}
|
hpdl
|
1616
|
72
|
|
|
73
|
return true;
|
hpdl
|
1204
|
74
|
}
|
hpdl
|
1616
|
75
|
}
|
hpdl
|
1204
|
76
|
|
hpdl
|
1616
|
77
|
$osC_Database->rollbackTransaction();
|
hpdl
|
1204
|
78
|
|
|
79
|
return false;
|
|
80
|
}
|
|
81
|
|
|
82
|
function delete($id) {
|
|
83
|
global $osC_Database;
|
|
84
|
|
|
85
|
$Qcheck = $osC_Database->query('select code from :table_currencies where currencies_id = :currencies_id');
|
|
86
|
$Qcheck->bindTable(':table_currencies', TABLE_CURRENCIES);
|
|
87
|
$Qcheck->bindInt(':currencies_id', $id);
|
|
88
|
$Qcheck->execute();
|
|
89
|
|
|
90
|
if ( $Qcheck->value('code') != DEFAULT_CURRENCY ) {
|
|
91
|
$Qdelete = $osC_Database->query('delete from :table_currencies where currencies_id = :currencies_id');
|
|
92
|
$Qdelete->bindTable(':table_currencies', TABLE_CURRENCIES);
|
|
93
|
$Qdelete->bindInt(':currencies_id', $id);
|
hpdl
|
1374
|
94
|
$Qdelete->setLogging($_SESSION['module'], $id);
|
hpdl
|
1204
|
95
|
$Qdelete->execute();
|
|
96
|
|
|
97
|
if ( !$osC_Database->isError() ) {
|
|
98
|
osC_Cache::clear('currencies');
|
|
99
|
|
|
100
|
return true;
|
|
101
|
}
|
|
102
|
}
|
|
103
|
|
|
104
|
return false;
|
|
105
|
}
|
|
106
|
|
|
107
|
function updateRates($service) {
|
|
108
|
global $osC_Database;
|
|
109
|
|
|
110
|
$updated = array('0' => array(), '1' => array());
|
|
111
|
|
|
112
|
$Qcurrencies = $osC_Database->query('select currencies_id, code, title from :table_currencies');
|
|
113
|
$Qcurrencies->bindTable(':table_currencies', TABLE_CURRENCIES);
|
|
114
|
$Qcurrencies->execute();
|
|
115
|
|
|
116
|
while ( $Qcurrencies->next() ) {
|
|
117
|
$rate = call_user_func('quote_' . $service . '_currency', $Qcurrencies->value('code'));
|
|
118
|
|
|
119
|
if ( !empty($rate) ) {
|
|
120
|
$Qupdate = $osC_Database->query('update :table_currencies set value = :value, last_updated = now() where currencies_id = :currencies_id');
|
|
121
|
$Qupdate->bindTable(':table_currencies', TABLE_CURRENCIES);
|
|
122
|
$Qupdate->bindValue(':value', $rate);
|
|
123
|
$Qupdate->bindInt(':currencies_id', $Qcurrencies->valueInt('currencies_id'));
|
hpdl
|
1374
|
124
|
$Qupdate->setLogging($_SESSION['module'], $Qcurrencies->valueInt('currencies_id'));
|
hpdl
|
1204
|
125
|
$Qupdate->execute();
|
|
126
|
|
|
127
|
$updated[1][] = array('title' => $Qcurrencies->value('title'),
|
|
128
|
'code' => $Qcurrencies->value('code'));
|
|
129
|
} else {
|
|
130
|
$updated[0][] = array('title' => $Qcurrencies->value('title'),
|
|
131
|
'code' => $Qcurrencies->value('code'));
|
|
132
|
}
|
|
133
|
}
|
|
134
|
|
|
135
|
osC_Cache::clear('currencies');
|
|
136
|
|
|
137
|
return $updated;
|
|
138
|
}
|
|
139
|
}
|
|
140
|
?>
|