[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/ -> currencies.php (source)

   1  <?php
   2  /*

   3  $Id: currencies.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13    require ('includes/application_top.php');
  14  
  15    require (DIR_WS_CLASSES . 'currencies.php');
  16    $currencies = new currencies();
  17  
  18    $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  19  
  20    if (tep_not_null($action)) {
  21      switch ($action) {
  22        case 'insert':
  23        case 'save':
  24          if (isset($HTTP_GET_VARS['cID'])) $currency_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);
  25          $title = tep_db_prepare_input($HTTP_POST_VARS['title']);
  26          $code = tep_db_prepare_input($HTTP_POST_VARS['code']);
  27          $symbol_left = tep_db_prepare_input($HTTP_POST_VARS['symbol_left']);
  28          $symbol_right = tep_db_prepare_input($HTTP_POST_VARS['symbol_right']);
  29          $decimal_point = tep_db_prepare_input($HTTP_POST_VARS['decimal_point']);
  30          $thousands_point = tep_db_prepare_input($HTTP_POST_VARS['thousands_point']);
  31          $decimal_places = tep_db_prepare_input($HTTP_POST_VARS['decimal_places']);
  32          $value = tep_db_prepare_input($HTTP_POST_VARS['value']);
  33  
  34          $sql_data_array = array('title' => $title,
  35                                  'code' => $code,
  36                                  'symbol_left' => $symbol_left,
  37                                  'symbol_right' => $symbol_right,
  38                                  'decimal_point' => $decimal_point,
  39                                  'thousands_point' => $thousands_point,
  40                                  'decimal_places' => $decimal_places,
  41                                  'value' => $value);
  42  
  43          if ($action == 'insert') {
  44            tep_db_perform(TABLE_CURRENCIES, $sql_data_array);
  45            $currency_id = tep_db_insert_id();
  46          } elseif ($action == 'save') {
  47            tep_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "currencies_id = '" . (int)$currency_id . "'");
  48          }
  49  
  50          if (isset($HTTP_POST_VARS['default']) && ($HTTP_POST_VARS['default'] == 'on')) {
  51            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($code) . "' where configuration_key = 'DEFAULT_CURRENCY'");
  52          }
  53  
  54          tep_redirect(tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $currency_id));
  55          break;
  56        case 'deleteconfirm':
  57          $currencies_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);
  58  
  59          $currency_query = tep_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code = '" . DEFAULT_CURRENCY . "'");
  60          $currency = tep_db_fetch_array($currency_query);
  61  
  62          if ($currency['currencies_id'] == $currencies_id) {
  63            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '' where configuration_key = 'DEFAULT_CURRENCY'");
  64          }
  65  
  66          tep_db_query("delete from " . TABLE_CURRENCIES . " where currencies_id = '" . (int)$currencies_id . "'");
  67  
  68          tep_redirect(tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page']));
  69          break;
  70        case 'update':
  71          $server_used = CURRENCY_SERVER_PRIMARY;
  72  
  73          $currency_query = tep_db_query("select currencies_id, code, title from " . TABLE_CURRENCIES);
  74          while ($currency = tep_db_fetch_array($currency_query)) {
  75            $quote_function = 'quote_' . CURRENCY_SERVER_PRIMARY . '_currency';
  76            $rate = $quote_function($currency['code']);
  77  
  78            if (empty($rate) && (tep_not_null(CURRENCY_SERVER_BACKUP))) {
  79              $messageStack->add_session(sprintf(WARNING_PRIMARY_SERVER_FAILED, CURRENCY_SERVER_PRIMARY, $currency['title'], $currency['code']), 'warning');
  80  
  81              $quote_function = 'quote_' . CURRENCY_SERVER_BACKUP . '_currency';
  82              $rate = $quote_function($currency['code']);
  83  
  84              $server_used = CURRENCY_SERVER_BACKUP;
  85            }
  86  
  87            if (tep_not_null($rate)) {
  88              tep_db_query("update " . TABLE_CURRENCIES . " set value = '" . $rate . "', last_updated = now() where currencies_id = '" . (int)$currency['currencies_id'] . "'");
  89  
  90              $messageStack->add_session(sprintf(TEXT_INFO_CURRENCY_UPDATED, $currency['title'], $currency['code'], $server_used), 'success');
  91            } else {
  92              $messageStack->add_session(sprintf(ERROR_CURRENCY_INVALID, $currency['title'], $currency['code'], $server_used), 'error');
  93            }
  94          }
  95  
  96          tep_redirect(tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $HTTP_GET_VARS['cID']));
  97          break;
  98        case 'delete':
  99          $currencies_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);
 100  
 101          $currency_query = tep_db_query("select code from " . TABLE_CURRENCIES . " where currencies_id = '" . (int)$currencies_id . "'");
 102          $currency = tep_db_fetch_array($currency_query);
 103  
 104          $remove_currency = true;
 105          if ($currency['code'] == DEFAULT_CURRENCY) {
 106            $remove_currency = false;
 107            $messageStack->add(ERROR_REMOVE_DEFAULT_CURRENCY, 'error');
 108          }
 109          break;
 110      }
 111    }
 112  ?>
 113  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 114  <html <?php echo HTML_PARAMS; ?>>
 115  <head>
 116  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 117  <title><?php echo TITLE; ?></title>
 118  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
 119  <script language="javascript" src="includes/general.js"></script>
 120  </head>
 121  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
 122  <!-- header //-->
 123  <?php require (DIR_WS_INCLUDES . 'header.php'); ?>
 124  <!-- header_eof //-->
 125  
 126  <!-- body //-->
 127  <table border="0" width="100%" cellspacing="2" cellpadding="2">
 128    <tr>
 129      <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
 130  <!-- left_navigation //-->
 131  <?php require (DIR_WS_INCLUDES . 'column_left.php'); ?>
 132  <!-- left_navigation_eof //-->
 133      </table></td>
 134  <!-- body_text //-->
 135      <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 136        <tr>
 137          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 138            <tr>
 139              <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
 140              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
 141            </tr>
 142          </table></td>
 143        </tr>
 144        <tr>
 145          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 146            <tr>
 147              <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 148                <tr class="dataTableHeadingRow">
 149                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CURRENCY_NAME; ?></td>
 150                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CURRENCY_CODES; ?></td>
 151                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_CURRENCY_VALUE; ?></td>
 152                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
 153                </tr>
 154  <?php
 155    $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";
 156    $currency_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $currency_query_raw, $currency_query_numrows);
 157    $currency_query = tep_db_query($currency_query_raw);
 158    while ($currency = tep_db_fetch_array($currency_query)) {
 159      if ((!isset($HTTP_GET_VARS['cID']) || (isset($HTTP_GET_VARS['cID']) && ($HTTP_GET_VARS['cID'] == $currency['currencies_id']))) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) {
 160        $cInfo = new objectInfo($currency);
 161      }
 162  
 163      if (isset($cInfo) && is_object($cInfo) && ($currency['currencies_id'] == $cInfo->currencies_id) ) {
 164        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id . '&action=edit') . '\'">' . "\n";
 165      } else {
 166        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $currency['currencies_id']) . '\'">' . "\n";
 167      }
 168  
 169      if (DEFAULT_CURRENCY == $currency['code']) {
 170        echo '                <td class="dataTableContent"><b>' . $currency['title'] . ' (' . TEXT_DEFAULT . ')</b></td>' . "\n";
 171      } else {
 172        echo '                <td class="dataTableContent">' . $currency['title'] . '</td>' . "\n";
 173      }
 174  ?>
 175                  <td class="dataTableContent"><?php echo $currency['code']; ?></td>
 176                  <td class="dataTableContent" align="right"><?php echo number_format($currency['value'], 8); ?></td>
 177                  <td class="dataTableContent" align="right"><?php if (isset($cInfo) && is_object($cInfo) && ($currency['currencies_id'] == $cInfo->currencies_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif'); } else { echo '<a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $currency['currencies_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
 178                </tr>
 179  <?php
 180    }
 181  ?>
 182                <tr>
 183                  <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 184                    <tr>
 185                      <td class="smallText" valign="top"><?php echo $currency_split->display_count($currency_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_CURRENCIES); ?></td>
 186                      <td class="smallText" align="right"><?php echo $currency_split->display_links($currency_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page']); ?></td>
 187                    </tr>
 188  <?php
 189    if (empty($action)) {
 190  ?>
 191                    <tr>
 192                      <td><?php if (CURRENCY_SERVER_PRIMARY) { echo '<a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id . '&action=update') . '">' . tep_image_button('button_update_currencies.gif', IMAGE_UPDATE_CURRENCIES) . '</a>'; } ?></td>
 193                      <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id . '&action=new') . '">' . tep_image_button('button_new_currency.gif', IMAGE_NEW_CURRENCY) . '</a>'; ?></td>
 194                    </tr>
 195  <?php
 196    }
 197  ?>
 198                  </table></td>
 199                </tr>
 200              </table></td>
 201  <?php
 202    $heading = array();
 203    $contents = array();
 204  
 205    switch ($action) {
 206      case 'new':
 207        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_CURRENCY . '</b>');
 208  
 209        $contents = array('form' => tep_draw_form('currencies', FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . (isset($cInfo) ? '&cID=' . $cInfo->currencies_id : '') . '&action=insert'));
 210        $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);
 211        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . '<br>' . tep_draw_input_field('title'));
 212        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_CODE . '<br>' . tep_draw_input_field('code'));
 213        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . '<br>' . tep_draw_input_field('symbol_left'));
 214        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_RIGHT . '<br>' . tep_draw_input_field('symbol_right'));
 215        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . '<br>' . tep_draw_input_field('decimal_point'));
 216        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_THOUSANDS_POINT . '<br>' . tep_draw_input_field('thousands_point'));
 217        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_PLACES . '<br>' . tep_draw_input_field('decimal_places'));
 218        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_VALUE . '<br>' . tep_draw_input_field('value'));
 219        $contents[] = array('text' => '<br>' . tep_draw_checkbox_field('default') . ' ' . TEXT_INFO_SET_AS_DEFAULT);
 220        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_insert.gif', IMAGE_INSERT) . ' <a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $HTTP_GET_VARS['cID']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 221        break;
 222      case 'edit':
 223        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_CURRENCY . '</b>');
 224  
 225        $contents = array('form' => tep_draw_form('currencies', FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id . '&action=save'));
 226        $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
 227        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . '<br>' . tep_draw_input_field('title', $cInfo->title));
 228        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_CODE . '<br>' . tep_draw_input_field('code', $cInfo->code));
 229        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . '<br>' . tep_draw_input_field('symbol_left', $cInfo->symbol_left));
 230        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_RIGHT . '<br>' . tep_draw_input_field('symbol_right', $cInfo->symbol_right));
 231        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . '<br>' . tep_draw_input_field('decimal_point', $cInfo->decimal_point));
 232        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_THOUSANDS_POINT . '<br>' . tep_draw_input_field('thousands_point', $cInfo->thousands_point));
 233        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_PLACES . '<br>' . tep_draw_input_field('decimal_places', $cInfo->decimal_places));
 234        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_VALUE . '<br>' . tep_draw_input_field('value', $cInfo->value));
 235        if (DEFAULT_CURRENCY != $cInfo->code) $contents[] = array('text' => '<br>' . tep_draw_checkbox_field('default') . ' ' . TEXT_INFO_SET_AS_DEFAULT);
 236        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . ' <a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 237        break;
 238      case 'delete':
 239        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_CURRENCY . '</b>');
 240  
 241        $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
 242        $contents[] = array('text' => '<br><b>' . $cInfo->title . '</b>');
 243        $contents[] = array('align' => 'center', 'text' => '<br>' . (($remove_currency) ? '<a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id . '&action=deleteconfirm') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>' : '') . ' <a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 244        break;
 245      default:
 246        if (is_object($cInfo)) {
 247          $heading[] = array('text' => '<b>' . $cInfo->title . '</b>');
 248  
 249          $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $cInfo->currencies_id . '&action=delete') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>');
 250          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . ' ' . $cInfo->title);
 251          $contents[] = array('text' => TEXT_INFO_CURRENCY_CODE . ' ' . $cInfo->code);
 252          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . ' ' . $cInfo->symbol_left);
 253          $contents[] = array('text' => TEXT_INFO_CURRENCY_SYMBOL_RIGHT . ' ' . $cInfo->symbol_right);
 254          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . ' ' . $cInfo->decimal_point);
 255          $contents[] = array('text' => TEXT_INFO_CURRENCY_THOUSANDS_POINT . ' ' . $cInfo->thousands_point);
 256          $contents[] = array('text' => TEXT_INFO_CURRENCY_DECIMAL_PLACES . ' ' . $cInfo->decimal_places);
 257          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_LAST_UPDATED . ' ' . tep_date_short($cInfo->last_updated));
 258          $contents[] = array('text' => TEXT_INFO_CURRENCY_VALUE . ' ' . number_format($cInfo->value, 8));
 259          $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_EXAMPLE . '<br>' . $currencies->format('30', false, DEFAULT_CURRENCY) . ' = ' . $currencies->format('30', true, $cInfo->code));
 260        }
 261        break;
 262    }
 263  
 264    if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
 265      echo '            <td width="25%" valign="top">' . "\n";
 266  
 267      $box = new box;
 268      echo $box->infoBox($heading, $contents);
 269  
 270      echo '            </td>' . "\n";
 271    }
 272  ?>
 273            </tr>
 274          </table></td>
 275        </tr>
 276      </table></td>
 277  <!-- body_text_eof //-->
 278    </tr>
 279  </table>
 280  <!-- body_eof //-->
 281  
 282  <!-- footer //-->
 283  <?php require (DIR_WS_INCLUDES . 'footer.php'); ?>
 284  <!-- footer_eof //-->
 285  <br>
 286  </body>
 287  </html>
 288  <?php require (DIR_WS_INCLUDES . 'application_bottom.php'); ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7