Zen Cart PHP Cross Reference Customer Relationship Management

Source: /admin/currencies.php - 337 lines - 20170 bytes - Summary - Text - Print

   1  <?php
   2  /**

   3   * @package admin

   4   * @copyright Copyright 2003-2011 Zen Cart Development Team

   5   * @copyright Portions Copyright 2003 osCommerce

   6   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

   7   * @version $Id: currencies.php 19330 2011-08-07 06:32:56Z drbyte $

   8   */
   9  
  10    require ('includes/application_top.php');
  11  
  12    require (DIR_WS_CLASSES . 'currencies.php');
  13    $currencies = new currencies();
  14  
  15    $action = (isset($_GET['action']) ? $_GET['action'] : '');
  16  
  17    if (zen_not_null($action)) {
  18      switch ($action) {
  19        case 'insert':
  20        case 'save':
  21          if ($_POST['title'] == '' || $_POST['code'] == '' ) {
  22            $_GET['action']= '';
  23            $messageStack->add_session(ERROR_INVALID_CURRENCY_ENTRY, 'error');
  24            zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page']));
  25            break;
  26          }
  27  
  28          if (isset($_GET['cID'])) $currency_id = zen_db_prepare_input($_GET['cID']);
  29          $title = zen_db_prepare_input($_POST['title']);
  30          $code = strtoupper(zen_db_prepare_input($_POST['code']));
  31          $symbol_left = zen_db_prepare_input($_POST['symbol_left']);
  32          $symbol_right = zen_db_prepare_input($_POST['symbol_right']);
  33          $decimal_point = zen_db_prepare_input($_POST['decimal_point']);
  34          $thousands_point = zen_db_prepare_input($_POST['thousands_point']);
  35          $decimal_places = zen_db_prepare_input((int)$_POST['decimal_places']);
  36          $value = zen_db_prepare_input((float)$_POST['value']);
  37  
  38          // special handling for currencies which don't support decimal places

  39          if ($decimal_point == '0' || $code == 'JPY') {
  40            $value = (int)$value;
  41            $decimal_places = 0;
  42          }
  43  
  44          $sql_data_array = array('title' => $title,
  45                                  'code' => $code,
  46                                  'symbol_left' => $symbol_left,
  47                                  'symbol_right' => $symbol_right,
  48                                  'decimal_point' => $decimal_point,
  49                                  'thousands_point' => $thousands_point,
  50                                  'decimal_places' => $decimal_places,
  51                                  'value' => $value);
  52  
  53          if ($action == 'insert') {
  54            zen_db_perform(TABLE_CURRENCIES, $sql_data_array);
  55            $currency_id = zen_db_insert_id();
  56          } elseif ($action == 'save') {
  57            zen_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "currencies_id = '" . (int)$currency_id . "'");
  58          }
  59  
  60          if (isset($_POST['default']) && ($_POST['default'] == 'on')) {
  61            $db->Execute("update " . TABLE_CONFIGURATION . "
  62                          set configuration_value = '" . zen_db_input($code) . "'
  63                          where configuration_key = 'DEFAULT_CURRENCY'");
  64          }
  65  
  66          zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $currency_id));
  67          break;
  68        case 'deleteconfirm':
  69          // demo active test

  70          if (zen_admin_demo()) {
  71            $_GET['action']= '';
  72            $messageStack->add_session(ERROR_ADMIN_DEMO, 'caution');
  73            zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page']));
  74          }
  75          $currencies_id = zen_db_prepare_input($_POST['cID']);
  76  
  77          $currency = $db->Execute("select currencies_id
  78                                    from " . TABLE_CURRENCIES . "
  79                                    where code = '" . zen_db_input(DEFAULT_CURRENCY) . "'");
  80          if ($currency->fields['currencies_id'] == $currencies_id) {
  81            $db->Execute("update " . TABLE_CONFIGURATION . "
  82                          set configuration_value = ''
  83                          where configuration_key = 'DEFAULT_CURRENCY'");
  84          }
  85          $db->Execute("delete from " . TABLE_CURRENCIES . "
  86                        where currencies_id = '" . (int)$currencies_id . "'");
  87  
  88          zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page']));
  89          break;
  90        case 'update_currencies':
  91          $server_used = CURRENCY_SERVER_PRIMARY;
  92          zen_set_time_limit(600);
  93          $currency = $db->Execute("select currencies_id, code, title, decimal_places from " . TABLE_CURRENCIES);
  94          while (!$currency->EOF) {
  95            $quote_function = 'quote_' . CURRENCY_SERVER_PRIMARY . '_currency';
  96            $rate = $quote_function($currency->fields['code']);
  97  
  98            if (empty($rate) && (zen_not_null(CURRENCY_SERVER_BACKUP))) {
  99              // failed to get currency quote from primary server - attempting to use backup server instead

 100              $messageStack->add_session(sprintf(WARNING_PRIMARY_SERVER_FAILED, CURRENCY_SERVER_PRIMARY, $currency->fields['title'], $currency->fields['code']), 'warning');
 101              $quote_function = 'quote_' . CURRENCY_SERVER_BACKUP . '_currency';
 102              $rate = $quote_function($currency->fields['code']);
 103              $server_used = CURRENCY_SERVER_BACKUP;
 104            }
 105  
 106            /* Add currency uplift */

 107            if ($rate != 1 && defined('CURRENCY_UPLIFT_RATIO') && (int)CURRENCY_UPLIFT_RATIO != 0) {
 108              $rate = (string)((float)$rate * (float)CURRENCY_UPLIFT_RATIO);
 109            }
 110  
 111            // special handling for currencies which don't support decimal places

 112            if ($currency->fields['decimal_places'] == '0') {
 113              $rate = (int)$rate;
 114            }
 115  
 116            if (zen_not_null($rate) && $rate > 0) {
 117              $db->Execute("update " . TABLE_CURRENCIES . "
 118                            set value = '" . $rate . "', last_updated = now()
 119                            where currencies_id = '" . (int)$currency->fields['currencies_id'] . "'");
 120              $messageStack->add_session(sprintf(TEXT_INFO_CURRENCY_UPDATED, $currency->fields['title'], $currency->fields['code'], $server_used), 'success');
 121            } else {
 122              $messageStack->add_session(sprintf(ERROR_CURRENCY_INVALID, $currency->fields['title'], $currency->fields['code'], $server_used), 'error');
 123            }
 124            $currency->MoveNext();
 125          }
 126  
 127          zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $_GET['cID']));
 128          break;
 129        case 'delete':
 130          // demo active test

 131          if (zen_admin_demo()) {
 132            $_GET['action']= '';
 133            $messageStack->add_session(ERROR_ADMIN_DEMO, 'caution');
 134            zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $_GET['cID']));
 135          }
 136          $currencies_id = zen_db_prepare_input($_GET['cID']);
 137  
 138          $currency = $db->Execute("select code
 139                                    from " . TABLE_CURRENCIES . "
 140                                    where currencies_id = '" . (int)$currencies_id . "'");
 141  
 142          $remove_currency = true;
 143          if ($currency->fields['code'] == DEFAULT_CURRENCY) {
 144            $remove_currency = false;
 145            $messageStack->add(ERROR_REMOVE_DEFAULT_CURRENCY, 'error');
 146          }
 147          break;
 148      }
 149    }
 150  ?>
 151  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 152  <html <?php echo HTML_PARAMS; ?>>
 153  <head>
 154  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 155  <title><?php echo TITLE; ?></title>
 156  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
 157  <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
 158  <script language="javascript" src="includes/menu.js"></script>
 159  <script language="javascript" src="includes/general.js"></script>
 160  <script type="text/javascript">
 161    <!--
 162    function init()
 163    {
 164      cssjsmenu('navbar');
 165      if (document.getElementById)
 166      {
 167        var kill = document.getElementById('hoverJS');
 168        kill.disabled = true;
 169      }
 170    }
 171    // -->

 172  </script>
 173  </head>
 174  <body onLoad="init()">
 175  <!-- header //-->
 176  <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
 177  <!-- header_eof //-->
 178  
 179  <!-- body //-->
 180  <table border="0" width="100%" cellspacing="2" cellpadding="2">
 181    <tr>
 182  <!-- body_text //-->
 183      <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 184        <tr>
 185          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 186            <tr>
 187              <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
 188              <td class="pageHeading" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
 189            </tr>
 190          </table></td>
 191        </tr>
 192        <tr>
 193          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 194            <tr>
 195              <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 196                <tr class="dataTableHeadingRow">
 197                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CURRENCY_NAME; ?></td>
 198                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CURRENCY_CODES; ?></td>
 199                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_CURRENCY_VALUE; ?></td>
 200                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
 201                </tr>
 202  <?php
 203    $currency_query_raw = "select currencies_id, title, code, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, last_updated, value from " . TABLE_CURRENCIES . " order by title";
 204    $currency_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS, $currency_query_raw, $currency_query_numrows);
 205    $currency = $db->Execute($currency_query_raw);
 206    while (!$currency->EOF) {
 207      if ((!isset($_GET['cID']) || (isset($_GET['cID']) && ($_GET['cID'] == $currency->fields['currencies_id']))) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) {
 208        $cInfo = new objectInfo($currency->fields);
 209      }
 210  
 211      if (isset($cInfo) && is_object($cInfo) && ($currency->fields['currencies_id'] == $cInfo->currencies_id) ) {
 212        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->currencies_id . '&action=edit') . '\'">' . "\n";
 213      } else {
 214        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $currency->fields['currencies_id']) . '\'">' . "\n";
 215      }
 216  
 217      if (DEFAULT_CURRENCY == $currency->fields['code']) {
 218        echo '                <td class="dataTableContent"><b>' . $currency->fields['title'] . ' (' . TEXT_DEFAULT . ')</b></td>' . "\n";
 219      } else {
 220        echo '                <td class="dataTableContent">' . $currency->fields['title'] . '</td>' . "\n";
 221      }
 222  ?>
 223                  <td class="dataTableContent"><?php echo $currency->fields['code']; ?></td>
 224                  <td class="dataTableContent" align="right"><?php echo number_format($currency->fields['value'], 8); ?></td>
 225                  <td class="dataTableContent" align="right"><?php if (isset($cInfo) && is_object($cInfo) && ($currency->fields['currencies_id'] == $cInfo->currencies_id) ) { echo zen_image(DIR_WS_IMAGES . 'icon_arrow_right.gif'); } else { echo '<a href="' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $currency->fields['currencies_id']) . '">' . zen_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
 226                </tr>
 227  <?php
 228      $currency->MoveNext();
 229    }
 230  ?>
 231                <tr>
 232                  <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 233                    <tr>
 234                      <td class="smallText" valign="top"><?php echo $currency_split->display_count($currency_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_CURRENCIES); ?></td>
 235                      <td class="smallText" align="right"><?php echo $currency_split->display_links($currency_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $_GET['page']); ?></td>
 236                    </tr>
 237  <?php
 238    if (empty($action)) {
 239  ?>
 240                    <tr>
 241                      <td><?php if (CURRENCY_SERVER_PRIMARY) { echo '<a href="' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->currencies_id . '&action=update_currencies') . '">' . zen_image_button('button_update_currencies.gif', IMAGE_UPDATE_CURRENCIES) . '</a>'; } ?></td>
 242                      <td align="right"><?php echo '<a href="' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->currencies_id . '&action=new') . '">' . zen_image_button('button_new_currency.gif', IMAGE_NEW_CURRENCY) . '</a>'; ?></td>
 243                    </tr>
 244  <?php
 245    }
 246  ?>
 247                  </table></td>
 248                </tr>
 249              </table></td>
 250  <?php
 251    $heading = array();
 252    $contents = array();
 253  
 254    switch ($action) {
 255      case 'new':
 256        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_CURRENCY . '</b>');
 257  
 258        $contents = array('form' => zen_draw_form('currencies', FILENAME_CURRENCIES, 'page=' . $_GET['page'] . (isset($cInfo) ? '&cID=' . $cInfo->currencies_id : '') . '&action=insert'));
 259        $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);
 260        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . '<br>' . zen_draw_input_field('title'));
 261        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_CODE . '<br>' . zen_draw_input_field('code'));
 262        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . '<br>' . zen_draw_input_field('symbol_left'));
 263        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_RIGHT . '<br>' . zen_draw_input_field('symbol_right'));
 264        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . '<br>' . zen_draw_input_field('decimal_point'));
 265        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_THOUSANDS_POINT . '<br>' . zen_draw_input_field('thousands_point'));
 266        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_PLACES . '<br>' . zen_draw_input_field('decimal_places'));
 267        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_VALUE . '<br>' . zen_draw_input_field('value'));
 268        $contents[] = array('text' => '<br>' . zen_draw_checkbox_field('default') . ' ' . TEXT_INFO_SET_AS_DEFAULT);
 269        $contents[] = array('align' => 'center', 'text' => '<br>' . zen_image_submit('button_insert.gif', IMAGE_INSERT) . ' <a href="' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $_GET['cID']) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 270        break;
 271      case 'edit':
 272        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_CURRENCY . '</b>');
 273  
 274        $contents = array('form' => zen_draw_form('currencies', FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->currencies_id . '&action=save'));
 275        $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
 276        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . '<br>' . zen_draw_input_field('title', htmlspecialchars($cInfo->title, ENT_COMPAT, CHARSET, TRUE)));
 277        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_CODE . '<br>' . zen_draw_input_field('code', htmlspecialchars($cInfo->code, ENT_COMPAT, CHARSET, TRUE)));
 278        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . '<br>' . zen_draw_input_field('symbol_left', htmlspecialchars($cInfo->symbol_left, ENT_COMPAT, CHARSET, TRUE)));
 279        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_RIGHT . '<br>' . zen_draw_input_field('symbol_right', htmlspecialchars($cInfo->symbol_right, ENT_COMPAT, CHARSET, TRUE)));
 280        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . '<br>' . zen_draw_input_field('decimal_point', htmlspecialchars($cInfo->decimal_point, ENT_COMPAT, CHARSET, TRUE)));
 281        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_THOUSANDS_POINT . '<br>' . zen_draw_input_field('thousands_point', htmlspecialchars($cInfo->thousands_point, ENT_COMPAT, CHARSET, TRUE)));
 282        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_PLACES . '<br>' . zen_draw_input_field('decimal_places', $cInfo->decimal_places));
 283        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_VALUE . '<br>' . zen_draw_input_field('value', $cInfo->value));
 284        if (DEFAULT_CURRENCY != $cInfo->code) $contents[] = array('text' => '<br>' . zen_draw_checkbox_field('default') . ' ' . TEXT_INFO_SET_AS_DEFAULT);
 285        $contents[] = array('align' => 'center', 'text' => '<br>' . zen_image_submit('button_update.gif', IMAGE_UPDATE) . ' <a href="' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->currencies_id) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 286        break;
 287      case 'delete':
 288        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_CURRENCY . '</b>');
 289        $contents = array('form'=>zen_draw_form('delete', FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&action=deleteconfirm') . zen_draw_hidden_field('cID', $cInfo->currencies_id));
 290        $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
 291        $contents[] = array('text'=> (($remove_currency) ? zen_image_submit('button_delete.gif', IMAGE_DELETE) : '') . ' <a href="' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $_GET['cID']) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>', 'align'=>'center');
 292        $contents[] = array('text' => '<br><b>' . $cInfo->title . '</b>');
 293        break;
 294      default:
 295        if (is_object($cInfo)) {
 296          $heading[] = array('text' => '<b>' . $cInfo->title . '</b>');
 297  
 298          $contents[] = array('align' => 'center', 'text' => '<a href="' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->currencies_id . '&action=edit') . '">' . zen_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->currencies_id . '&action=delete') . '">' . zen_image_button('button_delete.gif', IMAGE_DELETE) . '</a>');
 299          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . ' ' . $cInfo->title);
 300          $contents[] = array('text' => TEXT_INFO_CURRENCY_CODE . ' ' . $cInfo->code);
 301          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . ' ' . $cInfo->symbol_left);
 302          $contents[] = array('text' => TEXT_INFO_CURRENCY_SYMBOL_RIGHT . ' ' . $cInfo->symbol_right);
 303          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . ' ' . $cInfo->decimal_point);
 304          $contents[] = array('text' => TEXT_INFO_CURRENCY_THOUSANDS_POINT . ' ' . $cInfo->thousands_point);
 305          $contents[] = array('text' => TEXT_INFO_CURRENCY_DECIMAL_PLACES . ' ' . $cInfo->decimal_places);
 306          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_LAST_UPDATED . ' ' . zen_date_short($cInfo->last_updated));
 307          $contents[] = array('text' => TEXT_INFO_CURRENCY_VALUE . ' ' . number_format($cInfo->value, 8));
 308          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_EXAMPLE . '<br>' . $currencies->format('30', false, DEFAULT_CURRENCY) . ' = ' . $currencies->format('30', true, $cInfo->code));
 309        }
 310        break;
 311    }
 312  
 313    if ( (zen_not_null($heading)) && (zen_not_null($contents)) ) {
 314      echo '            <td width="25%" valign="top">' . "\n";
 315  
 316      $box = new box;
 317      echo $box->infoBox($heading, $contents);
 318  
 319      echo '            </td>' . "\n";
 320    }
 321  ?>
 322            </tr>
 323          </table></td>
 324        </tr>
 325      </table></td>
 326  <!-- body_text_eof //-->
 327    </tr>
 328  </table>
 329  <!-- body_eof //-->
 330  
 331  <!-- footer //-->
 332  <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
 333  <!-- footer_eof //-->
 334  <br>
 335  </body>
 336  </html>
 337  <?php require (DIR_WS_INCLUDES . 'application_bottom.php'); ?>

title

Description

title

Description

title

Description

title

title

Body