Quick Search:

View

Revision:

Diff

Diff from 978 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/tags/oscommerce-3.0a3/admin/currencies.php

Annotated File View

hpdl
1
1 <?php
2 /*
mattice
151
3   $Id: currencies.php 761 2006-08-23 12:37:56Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
410
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
13   require('includes/application_top.php');
14
15   require('../includes/classes/currencies.php');
16   $osC_Currencies = new osC_Currencies();
17
18   $action = (isset($_GET['action']) ? $_GET['action'] : '');
19
20   if (!isset($_GET['page']) || (isset($_GET['page']) && !is_numeric($_GET['page']))) {
21     $_GET['page'] = 1;
22   }
23
24   if (!empty($action)) {
25     switch ($action) {
26       case 'save':
27         if (isset($_GET['cID']) && is_numeric($_GET['cID'])) {
28           $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');
29           $Qcurrency->bindInt(':currencies_id', $_GET['cID']);
30         } else {
31           $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)');
32         }
33         $Qcurrency->bindTable(':table_currencies', TABLE_CURRENCIES);
34         $Qcurrency->bindValue(':title', $_POST['title']);
35         $Qcurrency->bindValue(':code', $_POST['code']);
36         $Qcurrency->bindValue(':symbol_left', $_POST['symbol_left']);
37         $Qcurrency->bindValue(':symbol_right', $_POST['symbol_right']);
38         $Qcurrency->bindInt(':decimal_places', $_POST['decimal_places']);
39         $Qcurrency->bindValue(':value', $_POST['value']);
40         $Qcurrency->execute();
41
42         if ($osC_Database->isError() === false) {
43           if (isset($_GET['cID']) && is_numeric($_GET['cID'])) {
44             $currency_id = $_GET['cID'];
45           } else {
46             $currency_id = $osC_Database->nextID();
47           }
48
49           if ( (isset($_POST['default']) && ($_POST['default'] == 'on')) || (isset($_POST['is_default']) && ($_POST['is_default'] == 'true') && ($_POST['code'] != DEFAULT_CURRENCY)) ) {
50             $Qupdate = $osC_Database->query('update :table_configuration set configuration_value = :configuration_value where configuration_key = :configuration_key');
51             $Qupdate->bindTable(':table_configuration', TABLE_CONFIGURATION);
52             $Qupdate->bindValue(':configuration_value', $_POST['code']);
53             $Qupdate->bindValue(':configuration_key', 'DEFAULT_CURRENCY');
54             $Qupdate->execute();
55
56             if ($Qupdate->affectedRows()) {
57               osC_Cache::clear('configuration');
58             }
59           }
60
hpdl
761
61           osC_Cache::clear('currencies');
62
hpdl
1
63           $osC_MessageStack->add_session('header', SUCCESS_DB_ROWS_UPDATED, 'success');
64         } else {
65           $osC_MessageStack->add_session('header', ERROR_DB_ROWS_NOT_UPDATED, 'error');
66         }
67
hpdl
758
68         osc_redirect(osc_href_link_admin(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $currency_id));
hpdl
1
69         break;
70       case 'deleteconfirm':
71         if (isset($_GET['cID']) && is_numeric($_GET['cID'])) {
72           $Qcheck = $osC_Database->query('select code from :table_currencies where currencies_id = :currencies_id');
73           $Qcheck->bindTable(':table_currencies', TABLE_CURRENCIES);
74           $Qcheck->bindInt(':currencies_id', $_GET['cID']);
75           $Qcheck->execute();
76
77           if ($Qcheck->value('code') != DEFAULT_CURRENCY) {
78             $Qdelete = $osC_Database->query('delete from :table_currencies where currencies_id = :currencies_id');
79             $Qdelete->bindTable(':table_currencies', TABLE_CURRENCIES);
80             $Qdelete->bindInt(':currencies_id', $_GET['cID']);
81             $Qdelete->execute();
82
83             if ($osC_Database->isError() === false) {
hpdl
761
84               osC_Cache::clear('currencies');
85
hpdl
1
86               $osC_MessageStack->add_session('header', SUCCESS_DB_ROWS_UPDATED, 'success');
87             } else {
88               $osC_MessageStack->add_session('header', ERROR_DB_ROWS_NOT_UPDATED, 'error');
89             }
90           }
91         }
92
hpdl
758
93         osc_redirect(osc_href_link_admin(FILENAME_CURRENCIES, 'page=' . $_GET['page']));
hpdl
1
94         break;
95       case 'update_currencies':
96         if (isset($_POST['service']) && (($_POST['service'] == 'oanda') || ($_POST['service'] == 'xe'))) {
97           $quote_function = 'quote_' . $_POST['service'] . '_currency';
98
99           $Qcurrencies = $osC_Database->query('select currencies_id, code, title from :table_currencies');
100           $Qcurrencies->bindTable(':table_currencies', TABLE_CURRENCIES);
101           $Qcurrencies->execute();
102
103           while ($Qcurrencies->next()) {
104             $rate = $quote_function($Qcurrencies->value('code'));
105
106             if (!empty($rate)) {
107               $Qupdate = $osC_Database->query('update :table_currencies set value = :value, last_updated = now() where currencies_id = :currencies_id');
108               $Qupdate->bindTable(':table_currencies', TABLE_CURRENCIES);
109               $Qupdate->bindValue(':value', $rate);
110               $Qupdate->bindInt(':currencies_id', $Qcurrencies->valueInt('currencies_id'));
111               $Qupdate->execute();
112
113               $osC_MessageStack->add_session('header', sprintf(TEXT_INFO_CURRENCY_UPDATED, $Qcurrencies->value('title'), $Qcurrencies->value('code'), $_POST['service']), 'success');
114             } else {
115               $osC_MessageStack->add_session('header', sprintf(ERROR_CURRENCY_INVALID, $Qcurrencies->value('title'), $Qcurrencies->value('code'), $_POST['service']), 'error');
116             }
117           }
118
hpdl
761
119           osC_Cache::clear('currencies');
120
hpdl
758
121           osc_redirect(osc_href_link_admin(FILENAME_CURRENCIES));
hpdl
1
122         }
123         break;
124     }
125   }
126
127   $page_contents = 'currencies.php';
128
129   require('templates/default.php');
130
131   require('includes/application_bottom.php');
132 ?>