|
ZenCart_Documentation
1.5.0
http://www.collinsharper.com
|
00001 <?php 00010 require('includes/application_top.php'); 00011 00012 require(DIR_WS_CLASSES . 'currencies.php'); 00013 $currencies = new currencies(); 00014 00015 $action = (isset($_GET['action']) ? $_GET['action'] : ''); 00016 00017 if (zen_not_null($action)) { 00018 switch ($action) { 00019 case 'insert': 00020 case 'save': 00021 if ($_POST['title'] == '' || $_POST['code'] == '' ) { 00022 $_GET['action']= ''; 00023 $messageStack->add_session(ERROR_INVALID_CURRENCY_ENTRY, 'error'); 00024 zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'])); 00025 break; 00026 } 00027 00028 if (isset($_GET['cID'])) $currency_id = zen_db_prepare_input($_GET['cID']); 00029 $title = zen_db_prepare_input($_POST['title']); 00030 $code = strtoupper(zen_db_prepare_input($_POST['code'])); 00031 $symbol_left = zen_db_prepare_input($_POST['symbol_left']); 00032 $symbol_right = zen_db_prepare_input($_POST['symbol_right']); 00033 $decimal_point = zen_db_prepare_input($_POST['decimal_point']); 00034 $thousands_point = zen_db_prepare_input($_POST['thousands_point']); 00035 $decimal_places = zen_db_prepare_input((int)$_POST['decimal_places']); 00036 $value = zen_db_prepare_input((float)$_POST['value']); 00037 00038 // special handling for currencies which don't support decimal places 00039 if ($decimal_point == '0' || $code == 'JPY') { 00040 $value = (int)$value; 00041 $decimal_places = 0; 00042 } 00043 00044 $sql_data_array = array('title' => $title, 00045 'code' => $code, 00046 'symbol_left' => $symbol_left, 00047 'symbol_right' => $symbol_right, 00048 'decimal_point' => $decimal_point, 00049 'thousands_point' => $thousands_point, 00050 'decimal_places' => $decimal_places, 00051 'value' => $value); 00052 00053 if ($action == 'insert') { 00054 zen_db_perform(TABLE_CURRENCIES, $sql_data_array); 00055 $currency_id = zen_db_insert_id(); 00056 } elseif ($action == 'save') { 00057 zen_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "currencies_id = '" . (int)$currency_id . "'"); 00058 } 00059 00060 if (isset($_POST['default']) && ($_POST['default'] == 'on')) { 00061 $db->Execute("update " . TABLE_CONFIGURATION . " 00062 set configuration_value = '" . zen_db_input($code) . "' 00063 where configuration_key = 'DEFAULT_CURRENCY'"); 00064 } 00065 00066 zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $currency_id)); 00067 break; 00068 case 'deleteconfirm': 00069 // demo active test 00070 if (zen_admin_demo()) { 00071 $_GET['action']= ''; 00072 $messageStack->add_session(ERROR_ADMIN_DEMO, 'caution'); 00073 zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'])); 00074 } 00075 $currencies_id = zen_db_prepare_input($_POST['cID']); 00076 00077 $currency = $db->Execute("select currencies_id 00078 from " . TABLE_CURRENCIES . " 00079 where code = '" . zen_db_input(DEFAULT_CURRENCY) . "'"); 00080 if ($currency->fields['currencies_id'] == $currencies_id) { 00081 $db->Execute("update " . TABLE_CONFIGURATION . " 00082 set configuration_value = '' 00083 where configuration_key = 'DEFAULT_CURRENCY'"); 00084 } 00085 $db->Execute("delete from " . TABLE_CURRENCIES . " 00086 where currencies_id = '" . (int)$currencies_id . "'"); 00087 00088 zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'])); 00089 break; 00090 case 'update_currencies': 00091 $server_used = CURRENCY_SERVER_PRIMARY; 00092 zen_set_time_limit(600); 00093 $currency = $db->Execute("select currencies_id, code, title, decimal_places from " . TABLE_CURRENCIES); 00094 while (!$currency->EOF) { 00095 $quote_function = 'quote_' . CURRENCY_SERVER_PRIMARY . '_currency'; 00096 $rate = $quote_function($currency->fields['code']); 00097 00098 if (empty($rate) && (zen_not_null(CURRENCY_SERVER_BACKUP))) { 00099 // failed to get currency quote from primary server - attempting to use backup server instead 00100 $messageStack->add_session(sprintf(WARNING_PRIMARY_SERVER_FAILED, CURRENCY_SERVER_PRIMARY, $currency->fields['title'], $currency->fields['code']), 'warning'); 00101 $quote_function = 'quote_' . CURRENCY_SERVER_BACKUP . '_currency'; 00102 $rate = $quote_function($currency->fields['code']); 00103 $server_used = CURRENCY_SERVER_BACKUP; 00104 } 00105 00106 /* Add currency uplift */ 00107 if ($rate != 1 && defined('CURRENCY_UPLIFT_RATIO') && (int)CURRENCY_UPLIFT_RATIO != 0) { 00108 $rate = (string)((float)$rate * (float)CURRENCY_UPLIFT_RATIO); 00109 } 00110 00111 // special handling for currencies which don't support decimal places 00112 if ($currency->fields['decimal_places'] == '0') { 00113 $rate = (int)$rate; 00114 } 00115 00116 if (zen_not_null($rate) && $rate > 0) { 00117 $db->Execute("update " . TABLE_CURRENCIES . " 00118 set value = '" . $rate . "', last_updated = now() 00119 where currencies_id = '" . (int)$currency->fields['currencies_id'] . "'"); 00120 $messageStack->add_session(sprintf(TEXT_INFO_CURRENCY_UPDATED, $currency->fields['title'], $currency->fields['code'], $server_used), 'success'); 00121 } else { 00122 $messageStack->add_session(sprintf(ERROR_CURRENCY_INVALID, $currency->fields['title'], $currency->fields['code'], $server_used), 'error'); 00123 } 00124 $currency->MoveNext(); 00125 } 00126 00127 zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $_GET['cID'])); 00128 break; 00129 case 'delete': 00130 // demo active test 00131 if (zen_admin_demo()) { 00132 $_GET['action']= ''; 00133 $messageStack->add_session(ERROR_ADMIN_DEMO, 'caution'); 00134 zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $_GET['cID'])); 00135 } 00136 $currencies_id = zen_db_prepare_input($_GET['cID']); 00137 00138 $currency = $db->Execute("select code 00139 from " . TABLE_CURRENCIES . " 00140 where currencies_id = '" . (int)$currencies_id . "'"); 00141 00142 $remove_currency = true; 00143 if ($currency->fields['code'] == DEFAULT_CURRENCY) { 00144 $remove_currency = false; 00145 $messageStack->add(ERROR_REMOVE_DEFAULT_CURRENCY, 'error'); 00146 } 00147 break; 00148 } 00149 } 00150 ?> 00151 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> 00152 <html <?php echo HTML_PARAMS; ?>> 00153 <head> 00154 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> 00155 <title><?php echo TITLE; ?></title> 00156 <link rel="stylesheet" type="text/css" href="includes/stylesheet.css"> 00157 <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS"> 00158 <script language="javascript" src="includes/menu.js"></script> 00159 <script language="javascript" src="includes/general.js"></script> 00160 <script type="text/javascript"> 00161 <!-- 00162 function init() 00163 { 00164 cssjsmenu('navbar'); 00165 if (document.getElementById) 00166 { 00167 var kill = document.getElementById('hoverJS'); 00168 kill.disabled = true; 00169 } 00170 } 00171 // --> 00172 </script> 00173 </head> 00174 <body onLoad="init()"> 00175 <!-- header //--> 00176 <?php require(DIR_WS_INCLUDES . 'header.php'); ?> 00177 <!-- header_eof //--> 00178 00179 <!-- body //--> 00180 <table border="0" width="100%" cellspacing="2" cellpadding="2"> 00181 <tr> 00182 <!-- body_text //--> 00183 <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2"> 00184 <tr> 00185 <td><table border="0" width="100%" cellspacing="0" cellpadding="0"> 00186 <tr> 00187 <td class="pageHeading"><?php echo HEADING_TITLE; ?></td> 00188 <td class="pageHeading" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td> 00189 </tr> 00190 </table></td> 00191 </tr> 00192 <tr> 00193 <td><table border="0" width="100%" cellspacing="0" cellpadding="0"> 00194 <tr> 00195 <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2"> 00196 <tr class="dataTableHeadingRow"> 00197 <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CURRENCY_NAME; ?></td> 00198 <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CURRENCY_CODES; ?></td> 00199 <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_CURRENCY_VALUE; ?></td> 00200 <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?> </td> 00201 </tr> 00202 <?php 00203 $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"; 00204 $currency_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS, $currency_query_raw, $currency_query_numrows); 00205 $currency = $db->Execute($currency_query_raw); 00206 while (!$currency->EOF) { 00207 if ((!isset($_GET['cID']) || (isset($_GET['cID']) && ($_GET['cID'] == $currency->fields['currencies_id']))) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) { 00208 $cInfo = new objectInfo($currency->fields); 00209 } 00210 00211 if (isset($cInfo) && is_object($cInfo) && ($currency->fields['currencies_id'] == $cInfo->currencies_id) ) { 00212 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"; 00213 } else { 00214 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"; 00215 } 00216 00217 if (DEFAULT_CURRENCY == $currency->fields['code']) { 00218 echo ' <td class="dataTableContent"><b>' . $currency->fields['title'] . ' (' . TEXT_DEFAULT . ')</b></td>' . "\n"; 00219 } else { 00220 echo ' <td class="dataTableContent">' . $currency->fields['title'] . '</td>' . "\n"; 00221 } 00222 ?> 00223 <td class="dataTableContent"><?php echo $currency->fields['code']; ?></td> 00224 <td class="dataTableContent" align="right"><?php echo number_format($currency->fields['value'], 8); ?></td> 00225 <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>'; } ?> </td> 00226 </tr> 00227 <?php 00228 $currency->MoveNext(); 00229 } 00230 ?> 00231 <tr> 00232 <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2"> 00233 <tr> 00234 <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> 00235 <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> 00236 </tr> 00237 <?php 00238 if (empty($action)) { 00239 ?> 00240 <tr> 00241 <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> 00242 <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> 00243 </tr> 00244 <?php 00245 } 00246 ?> 00247 </table></td> 00248 </tr> 00249 </table></td> 00250 <?php 00251 $heading = array(); 00252 $contents = array(); 00253 00254 switch ($action) { 00255 case 'new': 00256 $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_CURRENCY . '</b>'); 00257 00258 $contents = array('form' => zen_draw_form('currencies', FILENAME_CURRENCIES, 'page=' . $_GET['page'] . (isset($cInfo) ? '&cID=' . $cInfo->currencies_id : '') . '&action=insert')); 00259 $contents[] = array('text' => TEXT_INFO_INSERT_INTRO); 00260 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . '<br>' . zen_draw_input_field('title')); 00261 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_CODE . '<br>' . zen_draw_input_field('code')); 00262 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . '<br>' . zen_draw_input_field('symbol_left')); 00263 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_RIGHT . '<br>' . zen_draw_input_field('symbol_right')); 00264 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . '<br>' . zen_draw_input_field('decimal_point')); 00265 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_THOUSANDS_POINT . '<br>' . zen_draw_input_field('thousands_point')); 00266 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_PLACES . '<br>' . zen_draw_input_field('decimal_places')); 00267 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_VALUE . '<br>' . zen_draw_input_field('value')); 00268 $contents[] = array('text' => '<br>' . zen_draw_checkbox_field('default') . ' ' . TEXT_INFO_SET_AS_DEFAULT); 00269 $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>'); 00270 break; 00271 case 'edit': 00272 $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_CURRENCY . '</b>'); 00273 00274 $contents = array('form' => zen_draw_form('currencies', FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->currencies_id . '&action=save')); 00275 $contents[] = array('text' => TEXT_INFO_EDIT_INTRO); 00276 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . '<br>' . zen_draw_input_field('title', htmlspecialchars($cInfo->title, ENT_COMPAT, CHARSET, TRUE))); 00277 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_CODE . '<br>' . zen_draw_input_field('code', htmlspecialchars($cInfo->code, ENT_COMPAT, CHARSET, TRUE))); 00278 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . '<br>' . zen_draw_input_field('symbol_left', htmlspecialchars($cInfo->symbol_left, ENT_COMPAT, CHARSET, TRUE))); 00279 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_RIGHT . '<br>' . zen_draw_input_field('symbol_right', htmlspecialchars($cInfo->symbol_right, ENT_COMPAT, CHARSET, TRUE))); 00280 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . '<br>' . zen_draw_input_field('decimal_point', htmlspecialchars($cInfo->decimal_point, ENT_COMPAT, CHARSET, TRUE))); 00281 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_THOUSANDS_POINT . '<br>' . zen_draw_input_field('thousands_point', htmlspecialchars($cInfo->thousands_point, ENT_COMPAT, CHARSET, TRUE))); 00282 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_PLACES . '<br>' . zen_draw_input_field('decimal_places', $cInfo->decimal_places)); 00283 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_VALUE . '<br>' . zen_draw_input_field('value', $cInfo->value)); 00284 if (DEFAULT_CURRENCY != $cInfo->code) $contents[] = array('text' => '<br>' . zen_draw_checkbox_field('default') . ' ' . TEXT_INFO_SET_AS_DEFAULT); 00285 $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>'); 00286 break; 00287 case 'delete': 00288 $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_CURRENCY . '</b>'); 00289 $contents = array('form'=>zen_draw_form('delete', FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&action=deleteconfirm') . zen_draw_hidden_field('cID', $cInfo->currencies_id)); 00290 $contents[] = array('text' => TEXT_INFO_DELETE_INTRO); 00291 $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'); 00292 $contents[] = array('text' => '<br><b>' . $cInfo->title . '</b>'); 00293 break; 00294 default: 00295 if (is_object($cInfo)) { 00296 $heading[] = array('text' => '<b>' . $cInfo->title . '</b>'); 00297 00298 $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>'); 00299 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_TITLE . ' ' . $cInfo->title); 00300 $contents[] = array('text' => TEXT_INFO_CURRENCY_CODE . ' ' . $cInfo->code); 00301 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_SYMBOL_LEFT . ' ' . $cInfo->symbol_left); 00302 $contents[] = array('text' => TEXT_INFO_CURRENCY_SYMBOL_RIGHT . ' ' . $cInfo->symbol_right); 00303 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_DECIMAL_POINT . ' ' . $cInfo->decimal_point); 00304 $contents[] = array('text' => TEXT_INFO_CURRENCY_THOUSANDS_POINT . ' ' . $cInfo->thousands_point); 00305 $contents[] = array('text' => TEXT_INFO_CURRENCY_DECIMAL_PLACES . ' ' . $cInfo->decimal_places); 00306 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_LAST_UPDATED . ' ' . zen_date_short($cInfo->last_updated)); 00307 $contents[] = array('text' => TEXT_INFO_CURRENCY_VALUE . ' ' . number_format($cInfo->value, 8)); 00308 $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENCY_EXAMPLE . '<br>' . $currencies->format('30', false, DEFAULT_CURRENCY) . ' = ' . $currencies->format('30', true, $cInfo->code)); 00309 } 00310 break; 00311 } 00312 00313 if ( (zen_not_null($heading)) && (zen_not_null($contents)) ) { 00314 echo ' <td width="25%" valign="top">' . "\n"; 00315 00316 $box = new box; 00317 echo $box->infoBox($heading, $contents); 00318 00319 echo ' </td>' . "\n"; 00320 } 00321 ?> 00322 </tr> 00323 </table></td> 00324 </tr> 00325 </table></td> 00326 <!-- body_text_eof //--> 00327 </tr> 00328 </table> 00329 <!-- body_eof //--> 00330 00331 <!-- footer //--> 00332 <?php require(DIR_WS_INCLUDES . 'footer.php'); ?> 00333 <!-- footer_eof //--> 00334 <br> 00335 </body> 00336 </html> 00337 <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>