PageRenderTime 55ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/common/lib/epayment/includes/general.php

https://github.com/xrg/a2billing
PHP | 1329 lines | 950 code | 223 blank | 156 comment | 391 complexity | cea2231d1bbcfca735d7d7e0c141ccae MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. ////
  3. // Stop from parsing any further PHP code
  4. function tep_exit() {
  5. tep_session_close();
  6. exit();
  7. }
  8. ////
  9. // Redirect to another page or site
  10. function tep_redirect($url) {
  11. if ( (strstr($url, "\n") != false) || (strstr($url, "\r") != false) ) {
  12. tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false));
  13. }
  14. if ( (ENABLE_SSL == true) && (getenv('HTTPS') == 'on') ) { // We are loading an SSL page
  15. if (substr($url, 0, strlen(HTTP_SERVER)) == HTTP_SERVER) { // NONSSL url
  16. $url = HTTPS_SERVER . substr($url, strlen(HTTP_SERVER)); // Change it to SSL
  17. }
  18. }
  19. header('Location: ' . $url);
  20. tep_exit();
  21. }
  22. ////
  23. // Parse the data used in the html tags to ensure the tags will not break
  24. function tep_parse_input_field_data($data, $parse) {
  25. return strtr(trim($data), $parse);
  26. }
  27. function tep_output_string($string, $translate = false, $protected = false) {
  28. if ($protected == true) {
  29. return htmlspecialchars($string);
  30. } else {
  31. if ($translate == false) {
  32. return tep_parse_input_field_data($string, array('"' => '&quot;'));
  33. } else {
  34. return tep_parse_input_field_data($string, $translate);
  35. }
  36. }
  37. }
  38. function tep_output_string_protected($string) {
  39. return tep_output_string($string, false, true);
  40. }
  41. function tep_sanitize_string($string) {
  42. $string = ereg_replace(' +', ' ', trim($string));
  43. return preg_replace("/[<>]/", '_', $string);
  44. }
  45. ////
  46. // Return a random row from a database query
  47. function tep_random_select($query) {
  48. $random_product = '';
  49. $random_query = tep_db_query($query);
  50. $num_rows = tep_db_num_rows($random_query);
  51. if ($num_rows > 0) {
  52. $random_row = tep_rand(0, ($num_rows - 1));
  53. tep_db_data_seek($random_query, $random_row);
  54. $random_product = tep_db_fetch_array($random_query);
  55. }
  56. return $random_product;
  57. }
  58. ////
  59. // Return a product's name
  60. // TABLES: products
  61. function tep_get_products_name($product_id, $language = '') {
  62. global $languages_id;
  63. if (empty($language)) $language = $languages_id;
  64. $product_query = tep_db_query("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'");
  65. $product = tep_db_fetch_array($product_query);
  66. return $product['products_name'];
  67. }
  68. ////
  69. // Return a product's special price (returns nothing if there is no offer)
  70. // TABLES: products
  71. function tep_get_products_special_price($product_id) {
  72. $product_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status");
  73. $product = tep_db_fetch_array($product_query);
  74. return $product['specials_new_products_price'];
  75. }
  76. ////
  77. // Return a product's stock
  78. // TABLES: products
  79. function tep_get_products_stock($products_id) {
  80. $products_id = tep_get_prid($products_id);
  81. $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
  82. $stock_values = tep_db_fetch_array($stock_query);
  83. return $stock_values['products_quantity'];
  84. }
  85. ////
  86. // Check if the required stock is available
  87. // If insufficent stock is available return an out of stock message
  88. function tep_check_stock($products_id, $products_quantity) {
  89. $stock_left = tep_get_products_stock($products_id) - $products_quantity;
  90. $out_of_stock = '';
  91. if ($stock_left < 0) {
  92. $out_of_stock = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';
  93. }
  94. return $out_of_stock;
  95. }
  96. ////
  97. // Break a word in a string if it is longer than a specified length ($len)
  98. function tep_break_string($string, $len, $break_char = '-') {
  99. $l = 0;
  100. $output = '';
  101. for ($i=0, $n=strlen($string); $i<$n; $i++) {
  102. $char = substr($string, $i, 1);
  103. if ($char != ' ') {
  104. $l++;
  105. } else {
  106. $l = 0;
  107. }
  108. if ($l > $len) {
  109. $l = 1;
  110. $output .= $break_char;
  111. }
  112. $output .= $char;
  113. }
  114. return $output;
  115. }
  116. ////
  117. // Return all HTTP GET variables, except those passed as a parameter
  118. function tep_get_all_get_params($exclude_array = '') {
  119. global $_GET;
  120. if (!is_array($exclude_array)) $exclude_array = array();
  121. $get_url = '';
  122. if (is_array($_GET) && (sizeof($_GET) > 0)) {
  123. reset($_GET);
  124. while (list($key, $value) = each($_GET)) {
  125. if ( (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {
  126. $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';
  127. }
  128. }
  129. }
  130. return $get_url;
  131. }
  132. ////
  133. // Returns an array with countries
  134. // TABLES: countries
  135. function tep_get_countries($countries_id = '', $with_iso_codes = false) {
  136. $countries_array = array();
  137. if (tep_not_null($countries_id)) {
  138. if ($with_iso_codes == true) {
  139. $countries = tep_db_query("select countries_name, countries_iso_code_2, countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "' order by countries_name");
  140. $countries_values = tep_db_fetch_array($countries);
  141. $countries_array = array('countries_name' => $countries_values['countries_name'],
  142. 'countries_iso_code_2' => $countries_values['countries_iso_code_2'],
  143. 'countries_iso_code_3' => $countries_values['countries_iso_code_3']);
  144. } else {
  145. $countries = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "'");
  146. $countries_values = tep_db_fetch_array($countries);
  147. $countries_array = array('countries_name' => $countries_values['countries_name']);
  148. }
  149. } else {
  150. $countries = tep_db_query("select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_name");
  151. while ($countries_values = tep_db_fetch_array($countries)) {
  152. $countries_array[] = array('countries_id' => $countries_values['countries_id'],
  153. 'countries_name' => $countries_values['countries_name']);
  154. }
  155. }
  156. return $countries_array;
  157. }
  158. ////
  159. // Alias function to tep_get_countries, which also returns the countries iso codes
  160. function tep_get_countries_with_iso_codes($countries_id) {
  161. return tep_get_countries($countries_id, true);
  162. }
  163. ////
  164. // Generate a path to categories
  165. function tep_get_path($current_category_id = '') {
  166. global $cPath_array;
  167. if (tep_not_null($current_category_id)) {
  168. $cp_size = sizeof($cPath_array);
  169. if ($cp_size == 0) {
  170. $cPath_new = $current_category_id;
  171. } else {
  172. $cPath_new = '';
  173. $last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$cPath_array[($cp_size-1)] . "'");
  174. $last_category = tep_db_fetch_array($last_category_query);
  175. $current_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
  176. $current_category = tep_db_fetch_array($current_category_query);
  177. if ($last_category['parent_id'] == $current_category['parent_id']) {
  178. for ($i=0; $i<($cp_size-1); $i++) {
  179. $cPath_new .= '_' . $cPath_array[$i];
  180. }
  181. } else {
  182. for ($i=0; $i<$cp_size; $i++) {
  183. $cPath_new .= '_' . $cPath_array[$i];
  184. }
  185. }
  186. $cPath_new .= '_' . $current_category_id;
  187. if (substr($cPath_new, 0, 1) == '_') {
  188. $cPath_new = substr($cPath_new, 1);
  189. }
  190. }
  191. } else {
  192. $cPath_new = implode('_', $cPath_array);
  193. }
  194. return 'cPath=' . $cPath_new;
  195. }
  196. ////
  197. // Returns the clients browser
  198. function tep_browser_detect($component) {
  199. global $HTTP_USER_AGENT;
  200. return stristr($HTTP_USER_AGENT, $component);
  201. }
  202. ////
  203. // Alias function to tep_get_countries()
  204. function tep_get_country_name($country_id) {
  205. $country_array = tep_get_countries($country_id);
  206. return $country_array['countries_name'];
  207. }
  208. ////
  209. // Returns the zone (State/Province) name
  210. // TABLES: zones
  211. function tep_get_zone_name($country_id, $zone_id, $default_zone) {
  212. $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'");
  213. if (tep_db_num_rows($zone_query)) {
  214. $zone = tep_db_fetch_array($zone_query);
  215. return $zone['zone_name'];
  216. } else {
  217. return $default_zone;
  218. }
  219. }
  220. ////
  221. // Returns the zone (State/Province) code
  222. // TABLES: zones
  223. function tep_get_zone_code($country_id, $zone_id, $default_zone) {
  224. $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'");
  225. if (tep_db_num_rows($zone_query)) {
  226. $zone = tep_db_fetch_array($zone_query);
  227. return $zone['zone_code'];
  228. } else {
  229. return $default_zone;
  230. }
  231. }
  232. ////
  233. // Wrapper function for round()
  234. function tep_round($number, $precision) {
  235. if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) {
  236. $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1);
  237. if (substr($number, -1) >= 5) {
  238. if ($precision > 1) {
  239. $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1');
  240. } elseif ($precision == 1) {
  241. $number = substr($number, 0, -1) + 0.1;
  242. } else {
  243. $number = substr($number, 0, -1) + 1;
  244. }
  245. } else {
  246. $number = substr($number, 0, -1);
  247. }
  248. }
  249. return $number;
  250. }
  251. ////
  252. // Returns the tax rate for a zone / class
  253. // TABLES: tax_rates, zones_to_geo_zones
  254. function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {
  255. global $customer_zone_id, $customer_country_id;
  256. if ( ($country_id == -1) && ($zone_id == -1) ) {
  257. if (!tep_session_is_registered('customer_id')) {
  258. $country_id = STORE_COUNTRY;
  259. $zone_id = STORE_ZONE;
  260. } else {
  261. $country_id = $customer_country_id;
  262. $zone_id = $customer_zone_id;
  263. }
  264. }
  265. $tax_query = tep_db_query("select sum(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . (int)$country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' group by tr.tax_priority");
  266. if (tep_db_num_rows($tax_query)) {
  267. $tax_multiplier = 1.0;
  268. while ($tax = tep_db_fetch_array($tax_query)) {
  269. $tax_multiplier *= 1.0 + ($tax['tax_rate'] / 100);
  270. }
  271. return ($tax_multiplier - 1.0) * 100;
  272. } else {
  273. return 0;
  274. }
  275. }
  276. ////
  277. // Return the tax description for a zone / class
  278. // TABLES: tax_rates;
  279. function tep_get_tax_description($class_id, $country_id, $zone_id) {
  280. $tax_query = tep_db_query("select tax_description from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . (int)$country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' order by tr.tax_priority");
  281. if (tep_db_num_rows($tax_query)) {
  282. $tax_description = '';
  283. while ($tax = tep_db_fetch_array($tax_query)) {
  284. $tax_description .= $tax['tax_description'] . ' + ';
  285. }
  286. $tax_description = substr($tax_description, 0, -3);
  287. return $tax_description;
  288. } else {
  289. return TEXT_UNKNOWN_TAX_RATE;
  290. }
  291. }
  292. ////
  293. // Add tax to a products price
  294. function tep_add_tax($price, $tax) {
  295. global $currencies;
  296. if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {
  297. return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + tep_calculate_tax($price, $tax);
  298. } else {
  299. return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
  300. }
  301. }
  302. // Calculates Tax rounding the result
  303. function tep_calculate_tax($price, $tax) {
  304. global $currencies;
  305. return tep_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
  306. }
  307. ////
  308. // Return the number of products in a category
  309. // TABLES: products, products_to_categories, categories
  310. function tep_count_products_in_category($category_id, $include_inactive = false) {
  311. $products_count = 0;
  312. if ($include_inactive == true) {
  313. $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'");
  314. } else {
  315. $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'");
  316. }
  317. $products = tep_db_fetch_array($products_query);
  318. $products_count += $products['total'];
  319. $child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");
  320. if (tep_db_num_rows($child_categories_query)) {
  321. while ($child_categories = tep_db_fetch_array($child_categories_query)) {
  322. $products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive);
  323. }
  324. }
  325. return $products_count;
  326. }
  327. ////
  328. // Return true if the category has subcategories
  329. // TABLES: categories
  330. function tep_has_category_subcategories($category_id) {
  331. $child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");
  332. $child_category = tep_db_fetch_array($child_category_query);
  333. if ($child_category['count'] > 0) {
  334. return true;
  335. } else {
  336. return false;
  337. }
  338. }
  339. ////
  340. // Returns the address_format_id for the given country
  341. // TABLES: countries;
  342. function tep_get_address_format_id($country_id) {
  343. $address_format_query = tep_db_query("select address_format_id as format_id from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$country_id . "'");
  344. if (tep_db_num_rows($address_format_query)) {
  345. $address_format = tep_db_fetch_array($address_format_query);
  346. return $address_format['format_id'];
  347. } else {
  348. return '1';
  349. }
  350. }
  351. ////
  352. // Return a formatted address
  353. // TABLES: address_format
  354. function tep_address_format($address_format_id, $address, $html, $boln, $eoln) {
  355. $address_format_query = tep_db_query("select address_format as format from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . (int)$address_format_id . "'");
  356. $address_format = tep_db_fetch_array($address_format_query);
  357. $company = tep_output_string_protected($address['company']);
  358. if (isset($address['firstname']) && tep_not_null($address['firstname'])) {
  359. $firstname = tep_output_string_protected($address['firstname']);
  360. $lastname = tep_output_string_protected($address['lastname']);
  361. } elseif (isset($address['name']) && tep_not_null($address['name'])) {
  362. $firstname = tep_output_string_protected($address['name']);
  363. $lastname = '';
  364. } else {
  365. $firstname = '';
  366. $lastname = '';
  367. }
  368. $street = tep_output_string_protected($address['street_address']);
  369. $suburb = tep_output_string_protected($address['suburb']);
  370. $city = tep_output_string_protected($address['city']);
  371. $state = tep_output_string_protected($address['state']);
  372. if (isset($address['country_id']) && tep_not_null($address['country_id'])) {
  373. $country = tep_get_country_name($address['country_id']);
  374. if (isset($address['zone_id']) && tep_not_null($address['zone_id'])) {
  375. $state = tep_get_zone_code($address['country_id'], $address['zone_id'], $state);
  376. }
  377. } elseif (isset($address['country']) && tep_not_null($address['country'])) {
  378. $country = tep_output_string_protected($address['country']);
  379. } else {
  380. $country = '';
  381. }
  382. $postcode = tep_output_string_protected($address['postcode']);
  383. $zip = $postcode;
  384. if ($html) {
  385. // HTML Mode
  386. $HR = '<hr>';
  387. $hr = '<hr>';
  388. if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults
  389. $CR = '<br>';
  390. $cr = '<br>';
  391. $eoln = $cr;
  392. } else { // Use values supplied
  393. $CR = $eoln . $boln;
  394. $cr = $CR;
  395. }
  396. } else {
  397. // Text Mode
  398. $CR = $eoln;
  399. $cr = $CR;
  400. $HR = '----------------------------------------';
  401. $hr = '----------------------------------------';
  402. }
  403. $statecomma = '';
  404. $streets = $street;
  405. if ($suburb != '') $streets = $street . $cr . $suburb;
  406. if ($country == '') $country = tep_output_string_protected($address['country']);
  407. if ($state != '') $statecomma = $state . ', ';
  408. $fmt = $address_format['format'];
  409. eval("\$address = \"$fmt\";");
  410. if ( (ACCOUNT_COMPANY == 'true') && (tep_not_null($company)) ) {
  411. $address = $company . $cr . $address;
  412. }
  413. return $address;
  414. }
  415. ////
  416. // Return a formatted address
  417. // TABLES: customers, address_book
  418. function tep_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = "\n") {
  419. $address_query = tep_db_query("select entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customers_id . "' and address_book_id = '" . (int)$address_id . "'");
  420. $address = tep_db_fetch_array($address_query);
  421. $format_id = tep_get_address_format_id($address['country_id']);
  422. return tep_address_format($format_id, $address, $html, $boln, $eoln);
  423. }
  424. function tep_row_number_format($number) {
  425. if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = '0' . $number;
  426. return $number;
  427. }
  428. function tep_get_categories($categories_array = '', $parent_id = '0', $indent = '') {
  429. global $languages_id;
  430. if (!is_array($categories_array)) $categories_array = array();
  431. $categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
  432. while ($categories = tep_db_fetch_array($categories_query)) {
  433. $categories_array[] = array('id' => $categories['categories_id'],
  434. 'text' => $indent . $categories['categories_name']);
  435. if ($categories['categories_id'] != $parent_id) {
  436. $categories_array = tep_get_categories($categories_array, $categories['categories_id'], $indent . '&nbsp;&nbsp;');
  437. }
  438. }
  439. return $categories_array;
  440. }
  441. function tep_get_manufacturers($manufacturers_array = '') {
  442. if (!is_array($manufacturers_array)) $manufacturers_array = array();
  443. $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
  444. while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
  445. $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name']);
  446. }
  447. return $manufacturers_array;
  448. }
  449. ////
  450. // Return all subcategory IDs
  451. // TABLES: categories
  452. function tep_get_subcategories(&$subcategories_array, $parent_id = 0) {
  453. $subcategories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$parent_id . "'");
  454. while ($subcategories = tep_db_fetch_array($subcategories_query)) {
  455. $subcategories_array[sizeof($subcategories_array)] = $subcategories['categories_id'];
  456. if ($subcategories['categories_id'] != $parent_id) {
  457. tep_get_subcategories($subcategories_array, $subcategories['categories_id']);
  458. }
  459. }
  460. }
  461. // Output a raw date string in the selected locale date format
  462. // $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS
  463. function tep_date_long($raw_date) {
  464. if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;
  465. $year = (int)substr($raw_date, 0, 4);
  466. $month = (int)substr($raw_date, 5, 2);
  467. $day = (int)substr($raw_date, 8, 2);
  468. $hour = (int)substr($raw_date, 11, 2);
  469. $minute = (int)substr($raw_date, 14, 2);
  470. $second = (int)substr($raw_date, 17, 2);
  471. return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));
  472. }
  473. ////
  474. // Output a raw date string in the selected locale date format
  475. // $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS
  476. // NOTE: Includes a workaround for dates before 01/01/1970 that fail on windows servers
  477. function tep_date_short($raw_date) {
  478. if ( ($raw_date == '0000-00-00 00:00:00') || empty($raw_date) ) return false;
  479. $year = substr($raw_date, 0, 4);
  480. $month = (int)substr($raw_date, 5, 2);
  481. $day = (int)substr($raw_date, 8, 2);
  482. $hour = (int)substr($raw_date, 11, 2);
  483. $minute = (int)substr($raw_date, 14, 2);
  484. $second = (int)substr($raw_date, 17, 2);
  485. if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) {
  486. return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));
  487. } else {
  488. return ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)));
  489. }
  490. }
  491. ////
  492. // Parse search string into indivual objects
  493. function tep_parse_search_string($search_str = '', &$objects) {
  494. $search_str = trim(strtolower($search_str));
  495. // Break up $search_str on whitespace; quoted string will be reconstructed later
  496. $pieces = split('[[:space:]]+', $search_str);
  497. $objects = array();
  498. $tmpstring = '';
  499. $flag = '';
  500. for ($k=0; $k<count($pieces); $k++) {
  501. while (substr($pieces[$k], 0, 1) == '(') {
  502. $objects[] = '(';
  503. if (strlen($pieces[$k]) > 1) {
  504. $pieces[$k] = substr($pieces[$k], 1);
  505. } else {
  506. $pieces[$k] = '';
  507. }
  508. }
  509. $post_objects = array();
  510. while (substr($pieces[$k], -1) == ')') {
  511. $post_objects[] = ')';
  512. if (strlen($pieces[$k]) > 1) {
  513. $pieces[$k] = substr($pieces[$k], 0, -1);
  514. } else {
  515. $pieces[$k] = '';
  516. }
  517. }
  518. // Check individual words
  519. if ( (substr($pieces[$k], -1) != '"') && (substr($pieces[$k], 0, 1) != '"') ) {
  520. $objects[] = trim($pieces[$k]);
  521. for ($j=0; $j<count($post_objects); $j++) {
  522. $objects[] = $post_objects[$j];
  523. }
  524. } else {
  525. /* This means that the $piece is either the beginning or the end of a string.
  526. So, we'll slurp up the $pieces and stick them together until we get to the
  527. end of the string or run out of pieces.
  528. */
  529. // Add this word to the $tmpstring, starting the $tmpstring
  530. $tmpstring = trim(ereg_replace('"', ' ', $pieces[$k]));
  531. // Check for one possible exception to the rule. That there is a single quoted word.
  532. if (substr($pieces[$k], -1 ) == '"') {
  533. // Turn the flag off for future iterations
  534. $flag = 'off';
  535. $objects[] = trim($pieces[$k]);
  536. for ($j=0; $j<count($post_objects); $j++) {
  537. $objects[] = $post_objects[$j];
  538. }
  539. unset($tmpstring);
  540. // Stop looking for the end of the string and move onto the next word.
  541. continue;
  542. }
  543. // Otherwise, turn on the flag to indicate no quotes have been found attached to this word in the string.
  544. $flag = 'on';
  545. // Move on to the next word
  546. $k++;
  547. // Keep reading until the end of the string as long as the $flag is on
  548. while ( ($flag == 'on') && ($k < count($pieces)) ) {
  549. while (substr($pieces[$k], -1) == ')') {
  550. $post_objects[] = ')';
  551. if (strlen($pieces[$k]) > 1) {
  552. $pieces[$k] = substr($pieces[$k], 0, -1);
  553. } else {
  554. $pieces[$k] = '';
  555. }
  556. }
  557. // If the word doesn't end in double quotes, append it to the $tmpstring.
  558. if (substr($pieces[$k], -1) != '"') {
  559. // Tack this word onto the current string entity
  560. $tmpstring .= ' ' . $pieces[$k];
  561. // Move on to the next word
  562. $k++;
  563. continue;
  564. } else {
  565. /* If the $piece ends in double quotes, strip the double quotes, tack the
  566. $piece onto the tail of the string, push the $tmpstring onto the $haves,
  567. kill the $tmpstring, turn the $flag "off", and return.
  568. */
  569. $tmpstring .= ' ' . trim(ereg_replace('"', ' ', $pieces[$k]));
  570. // Push the $tmpstring onto the array of stuff to search for
  571. $objects[] = trim($tmpstring);
  572. for ($j=0; $j<count($post_objects); $j++) {
  573. $objects[] = $post_objects[$j];
  574. }
  575. unset($tmpstring);
  576. // Turn off the flag to exit the loop
  577. $flag = 'off';
  578. }
  579. }
  580. }
  581. }
  582. // add default logical operators if needed
  583. $temp = array();
  584. for($i=0; $i<(count($objects)-1); $i++) {
  585. $temp[] = $objects[$i];
  586. if ( ($objects[$i] != 'and') &&
  587. ($objects[$i] != 'or') &&
  588. ($objects[$i] != '(') &&
  589. ($objects[$i+1] != 'and') &&
  590. ($objects[$i+1] != 'or') &&
  591. ($objects[$i+1] != ')') ) {
  592. $temp[] = ADVANCED_SEARCH_DEFAULT_OPERATOR;
  593. }
  594. }
  595. $temp[] = $objects[$i];
  596. $objects = $temp;
  597. $keyword_count = 0;
  598. $operator_count = 0;
  599. $balance = 0;
  600. for($i=0; $i<count($objects); $i++) {
  601. if ($objects[$i] == '(') $balance --;
  602. if ($objects[$i] == ')') $balance ++;
  603. if ( ($objects[$i] == 'and') || ($objects[$i] == 'or') ) {
  604. $operator_count ++;
  605. } elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) {
  606. $keyword_count ++;
  607. }
  608. }
  609. if ( ($operator_count < $keyword_count) && ($balance == 0) ) {
  610. return true;
  611. } else {
  612. return false;
  613. }
  614. }
  615. ////
  616. // Check date
  617. function tep_checkdate($date_to_check, $format_string, &$date_array) {
  618. $separator_idx = -1;
  619. $separators = array('-', ' ', '/', '.');
  620. $month_abbr = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
  621. $no_of_days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  622. $format_string = strtolower($format_string);
  623. if (strlen($date_to_check) != strlen($format_string)) {
  624. return false;
  625. }
  626. $size = sizeof($separators);
  627. for ($i=0; $i<$size; $i++) {
  628. $pos_separator = strpos($date_to_check, $separators[$i]);
  629. if ($pos_separator != false) {
  630. $date_separator_idx = $i;
  631. break;
  632. }
  633. }
  634. for ($i=0; $i<$size; $i++) {
  635. $pos_separator = strpos($format_string, $separators[$i]);
  636. if ($pos_separator != false) {
  637. $format_separator_idx = $i;
  638. break;
  639. }
  640. }
  641. if ($date_separator_idx != $format_separator_idx) {
  642. return false;
  643. }
  644. if ($date_separator_idx != -1) {
  645. $format_string_array = explode( $separators[$date_separator_idx], $format_string );
  646. if (sizeof($format_string_array) != 3) {
  647. return false;
  648. }
  649. $date_to_check_array = explode( $separators[$date_separator_idx], $date_to_check );
  650. if (sizeof($date_to_check_array) != 3) {
  651. return false;
  652. }
  653. $size = sizeof($format_string_array);
  654. for ($i=0; $i<$size; $i++) {
  655. if ($format_string_array[$i] == 'mm' || $format_string_array[$i] == 'mmm') $month = $date_to_check_array[$i];
  656. if ($format_string_array[$i] == 'dd') $day = $date_to_check_array[$i];
  657. if ( ($format_string_array[$i] == 'yyyy') || ($format_string_array[$i] == 'aaaa') ) $year = $date_to_check_array[$i];
  658. }
  659. } else {
  660. if (strlen($format_string) == 8 || strlen($format_string) == 9) {
  661. $pos_month = strpos($format_string, 'mmm');
  662. if ($pos_month != false) {
  663. $month = substr( $date_to_check, $pos_month, 3 );
  664. $size = sizeof($month_abbr);
  665. for ($i=0; $i<$size; $i++) {
  666. if ($month == $month_abbr[$i]) {
  667. $month = $i;
  668. break;
  669. }
  670. }
  671. } else {
  672. $month = substr($date_to_check, strpos($format_string, 'mm'), 2);
  673. }
  674. } else {
  675. return false;
  676. }
  677. $day = substr($date_to_check, strpos($format_string, 'dd'), 2);
  678. $year = substr($date_to_check, strpos($format_string, 'yyyy'), 4);
  679. }
  680. if (strlen($year) != 4) {
  681. return false;
  682. }
  683. if (!settype($year, 'integer') || !settype($month, 'integer') || !settype($day, 'integer')) {
  684. return false;
  685. }
  686. if ($month > 12 || $month < 1) {
  687. return false;
  688. }
  689. if ($day < 1) {
  690. return false;
  691. }
  692. if (tep_is_leap_year($year)) {
  693. $no_of_days[1] = 29;
  694. }
  695. if ($day > $no_of_days[$month - 1]) {
  696. return false;
  697. }
  698. $date_array = array($year, $month, $day);
  699. return true;
  700. }
  701. ////
  702. // Check if year is a leap year
  703. function tep_is_leap_year($year) {
  704. if ($year % 100 == 0) {
  705. if ($year % 400 == 0) return true;
  706. } else {
  707. if (($year % 4) == 0) return true;
  708. }
  709. return false;
  710. }
  711. ////
  712. // Return table heading with sorting capabilities
  713. function tep_create_sort_heading($sortby, $colnum, $heading) {
  714. global $PHP_SELF;
  715. $sort_prefix = '';
  716. $sort_suffix = '';
  717. if ($sortby) {
  718. $sort_prefix = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('page', 'info', 'sort')) . 'page=1&sort=' . $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a')) . '" title="' . tep_output_string(TEXT_SORT_PRODUCTS . ($sortby == $colnum . 'd' || substr($sortby, 0, 1) != $colnum ? TEXT_ASCENDINGLY : TEXT_DESCENDINGLY) . TEXT_BY . $heading) . '" class="productListing-heading">' ;
  719. $sort_suffix = (substr($sortby, 0, 1) == $colnum ? (substr($sortby, 1, 1) == 'a' ? '+' : '-') : '') . '</a>';
  720. }
  721. return $sort_prefix . $heading . $sort_suffix;
  722. }
  723. ////
  724. // Recursively go through the categories and retreive all parent categories IDs
  725. // TABLES: categories
  726. function tep_get_parent_categories(&$categories, $categories_id) {
  727. $parent_categories_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$categories_id . "'");
  728. while ($parent_categories = tep_db_fetch_array($parent_categories_query)) {
  729. if ($parent_categories['parent_id'] == 0) return true;
  730. $categories[sizeof($categories)] = $parent_categories['parent_id'];
  731. if ($parent_categories['parent_id'] != $categories_id) {
  732. tep_get_parent_categories($categories, $parent_categories['parent_id']);
  733. }
  734. }
  735. }
  736. ////
  737. // Construct a category path to the product
  738. // TABLES: products_to_categories
  739. function tep_get_product_path($products_id) {
  740. $cPath = '';
  741. $category_query = tep_db_query("select p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$products_id . "' and p.products_status = '1' and p.products_id = p2c.products_id limit 1");
  742. if (tep_db_num_rows($category_query)) {
  743. $category = tep_db_fetch_array($category_query);
  744. $categories = array();
  745. tep_get_parent_categories($categories, $category['categories_id']);
  746. $categories = array_reverse($categories);
  747. $cPath = implode('_', $categories);
  748. if (tep_not_null($cPath)) $cPath .= '_';
  749. $cPath .= $category['categories_id'];
  750. }
  751. return $cPath;
  752. }
  753. ////
  754. // Return a product ID with attributes
  755. function tep_get_uprid($prid, $params) {
  756. if (is_numeric($prid)) {
  757. $uprid = $prid;
  758. if (is_array($params) && (sizeof($params) > 0)) {
  759. $attributes_check = true;
  760. $attributes_ids = '';
  761. reset($params);
  762. while (list($option, $value) = each($params)) {
  763. if (is_numeric($option) && is_numeric($value)) {
  764. $attributes_ids .= '{' . (int)$option . '}' . (int)$value;
  765. } else {
  766. $attributes_check = false;
  767. break;
  768. }
  769. }
  770. if ($attributes_check == true) {
  771. $uprid .= $attributes_ids;
  772. }
  773. }
  774. } else {
  775. $uprid = tep_get_prid($prid);
  776. if (is_numeric($uprid)) {
  777. if (strpos($prid, '{') !== false) {
  778. $attributes_check = true;
  779. $attributes_ids = '';
  780. // strpos()+1 to remove up to and including the first { which would create an empty array element in explode()
  781. $attributes = explode('{', substr($prid, strpos($prid, '{')+1));
  782. for ($i=0, $n=sizeof($attributes); $i<$n; $i++) {
  783. $pair = explode('}', $attributes[$i]);
  784. if (is_numeric($pair[0]) && is_numeric($pair[1])) {
  785. $attributes_ids .= '{' . (int)$pair[0] . '}' . (int)$pair[1];
  786. } else {
  787. $attributes_check = false;
  788. break;
  789. }
  790. }
  791. if ($attributes_check == true) {
  792. $uprid .= $attributes_ids;
  793. }
  794. }
  795. } else {
  796. return false;
  797. }
  798. }
  799. return $uprid;
  800. }
  801. ////
  802. // Return a product ID from a product ID with attributes
  803. function tep_get_prid($uprid) {
  804. $pieces = explode('{', $uprid);
  805. if (is_numeric($pieces[0])) {
  806. return $pieces[0];
  807. } else {
  808. return false;
  809. }
  810. }
  811. ////
  812. // Return a customer greeting
  813. function tep_customer_greeting() {
  814. global $customer_id, $customer_first_name;
  815. if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) {
  816. $greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_first_name), tep_href_link(FILENAME_PRODUCTS_NEW));
  817. } else {
  818. $greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));
  819. }
  820. return $greeting_string;
  821. }
  822. ////
  823. //! Send email (text/html) using MIME
  824. // This is the central mail function. The SMTP Server should be configured
  825. // correct in php.ini
  826. // Parameters:
  827. // $to_name The name of the recipient, e.g. "Jan Wildeboer"
  828. // $to_email_address The eMail address of the recipient,
  829. // e.g. jan.wildeboer@gmx.de
  830. // $email_subject The subject of the eMail
  831. // $email_text The text of the eMail, may contain HTML entities
  832. // $from_email_name The name of the sender, e.g. Shop Administration
  833. // $from_email_adress The eMail address of the sender,
  834. // e.g. info@mytepshop.com
  835. function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
  836. if (SEND_EMAILS != 'true') return false;
  837. // Instantiate a new mail object
  838. $message = new email(array('X-Mailer: Mailer'));
  839. // Build the text version
  840. $text = strip_tags($email_text);
  841. if (EMAIL_USE_HTML == 'true') {
  842. $message->add_html($email_text, $text);
  843. } else {
  844. $message->add_text($text);
  845. }
  846. // Send message
  847. $message->build_message();
  848. $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);
  849. }
  850. ////
  851. // Check if product has attributes
  852. function tep_has_product_attributes($products_id) {
  853. $attributes_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "'");
  854. $attributes = tep_db_fetch_array($attributes_query);
  855. if ($attributes['count'] > 0) {
  856. return true;
  857. } else {
  858. return false;
  859. }
  860. }
  861. ////
  862. // Get the number of times a word/character is present in a string
  863. function tep_word_count($string, $needle) {
  864. $temp_array = split($needle, $string);
  865. return sizeof($temp_array);
  866. }
  867. function tep_count_modules($modules = '') {
  868. $count = 0;
  869. if (empty($modules)) return $count;
  870. $modules_array = split(';', $modules);
  871. for ($i=0, $n=sizeof($modules_array); $i<$n; $i++) {
  872. $class = substr($modules_array[$i], 0, strrpos($modules_array[$i], '.'));
  873. if (is_object($GLOBALS[$class])) {
  874. if ($GLOBALS[$class]->enabled) {
  875. $count++;
  876. }
  877. }
  878. }
  879. return $count;
  880. }
  881. function tep_count_payment_modules() {
  882. return tep_count_modules(MODULE_PAYMENT_INSTALLED);
  883. }
  884. function tep_count_shipping_modules() {
  885. return tep_count_modules(MODULE_SHIPPING_INSTALLED);
  886. }
  887. function tep_create_random_value($length, $type = 'mixed') {
  888. if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false;
  889. $rand_value = '';
  890. while (strlen($rand_value) < $length) {
  891. if ($type == 'digits') {
  892. $char = tep_rand(0,9);
  893. } else {
  894. $char = chr(tep_rand(0,255));
  895. }
  896. if ($type == 'mixed') {
  897. if (eregi('^[a-z0-9]$', $char)) $rand_value .= $char;
  898. } elseif ($type == 'chars') {
  899. if (eregi('^[a-z]$', $char)) $rand_value .= $char;
  900. } elseif ($type == 'digits') {
  901. if (ereg('^[0-9]$', $char)) $rand_value .= $char;
  902. }
  903. }
  904. return $rand_value;
  905. }
  906. function tep_array_to_string($array, $exclude = '', $equals = '=', $separator = '&') {
  907. if (!is_array($exclude)) $exclude = array();
  908. $get_string = '';
  909. if (sizeof($array) > 0) {
  910. while (list($key, $value) = each($array)) {
  911. if ( (!in_array($key, $exclude)) && ($key != 'x') && ($key != 'y') ) {
  912. $get_string .= $key . $equals . $value . $separator;
  913. }
  914. }
  915. $remove_chars = strlen($separator);
  916. $get_string = substr($get_string, 0, -$remove_chars);
  917. }
  918. return $get_string;
  919. }
  920. function tep_not_null($value) {
  921. if (is_array($value)) {
  922. if (sizeof($value) > 0) {
  923. return true;
  924. } else {
  925. return false;
  926. }
  927. } else {
  928. if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
  929. return true;
  930. } else {
  931. return false;
  932. }
  933. }
  934. }
  935. ////
  936. // Output the tax percentage with optional padded decimals
  937. function tep_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) {
  938. if (strpos($value, '.')) {
  939. $loop = true;
  940. while ($loop) {
  941. if (substr($value, -1) == '0') {
  942. $value = substr($value, 0, -1);
  943. } else {
  944. $loop = false;
  945. if (substr($value, -1) == '.') {
  946. $value = substr($value, 0, -1);
  947. }
  948. }
  949. }
  950. }
  951. if ($padding > 0) {
  952. if ($decimal_pos = strpos($value, '.')) {
  953. $decimals = strlen(substr($value, ($decimal_pos+1)));
  954. for ($i=$decimals; $i<$padding; $i++) {
  955. $value .= '0';
  956. }
  957. } else {
  958. $value .= '.';
  959. for ($i=0; $i<$padding; $i++) {
  960. $value .= '0';
  961. }
  962. }
  963. }
  964. return $value;
  965. }
  966. ////
  967. // Checks to see if the currency code exists as a currency
  968. // TABLES: currencies
  969. function tep_currency_exists($code) {
  970. $code = tep_db_prepare_input($code);
  971. $currency_code = tep_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code = '" . tep_db_input($code) . "'");
  972. if (tep_db_num_rows($currency_code)) {
  973. return $code;
  974. } else {
  975. return false;
  976. }
  977. }
  978. function tep_string_to_int($string) {
  979. return (int)$string;
  980. }
  981. ////
  982. // Parse and secure the cPath parameter values
  983. function tep_parse_category_path($cPath) {
  984. // make sure the category IDs are integers
  985. $cPath_array = array_map('tep_string_to_int', explode('_', $cPath));
  986. // make sure no duplicate category IDs exist which could lock the server in a loop
  987. $tmp_array = array();
  988. $n = sizeof($cPath_array);
  989. for ($i=0; $i<$n; $i++) {
  990. if (!in_array($cPath_array[$i], $tmp_array)) {
  991. $tmp_array[] = $cPath_array[$i];
  992. }
  993. }
  994. return $tmp_array;
  995. }
  996. ////
  997. // Return a random value
  998. function tep_rand($min = null, $max = null) {
  999. static $seeded;
  1000. if (!isset($seeded)) {
  1001. mt_srand((double)microtime()*1000000);
  1002. $seeded = true;
  1003. }
  1004. if (isset($min) && isset($max)) {
  1005. if ($min >= $max) {
  1006. return $min;
  1007. } else {
  1008. return mt_rand($min, $max);
  1009. }
  1010. } else {
  1011. return mt_rand();
  1012. }
  1013. }
  1014. function tep_setcookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = 0) {
  1015. setcookie($name, $value, $expire, $path, (tep_not_null($domain) ? $domain : ''), $secure);
  1016. }
  1017. function tep_get_ip_address() {
  1018. if (isset($_SERVER)) {
  1019. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  1020. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  1021. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  1022. $ip = $_SERVER['HTTP_CLIENT_IP'];
  1023. } else {
  1024. $ip = $_SERVER['REMOTE_ADDR'];
  1025. }
  1026. } else {
  1027. if (getenv('HTTP_X_FORWARDED_FOR')) {
  1028. $ip = getenv('HTTP_X_FORWARDED_FOR');
  1029. } elseif (getenv('HTTP_CLIENT_IP')) {
  1030. $ip = getenv('HTTP_CLIENT_IP');
  1031. } else {
  1032. $ip = getenv('REMOTE_ADDR');
  1033. }
  1034. }
  1035. return $ip;
  1036. }
  1037. function tep_count_customer_orders($id = '', $check_session = true) {
  1038. global $customer_id;
  1039. if (is_numeric($id) == false) {
  1040. if (tep_session_is_registered('customer_id')) {
  1041. $id = $customer_id;
  1042. } else {
  1043. return 0;
  1044. }
  1045. }
  1046. if ($check_session == true) {
  1047. if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) {
  1048. return 0;
  1049. }
  1050. }
  1051. $orders_check_query = tep_db_query("select count(*) as total from " . TABLE_ORDERS . " where customers_id = '" . (int)$id . "'");
  1052. $orders_check = tep_db_fetch_array($orders_check_query);
  1053. return $orders_check['total'];
  1054. }
  1055. function tep_count_customer_address_book_entries($id = '', $check_session = true) {
  1056. global $customer_id;
  1057. if (is_numeric($id) == false) {
  1058. if (tep_session_is_registered('customer_id')) {
  1059. $id = $customer_id;
  1060. } else {
  1061. return 0;
  1062. }
  1063. }
  1064. if ($check_session == true) {
  1065. if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) {
  1066. return 0;
  1067. }
  1068. }
  1069. $addresses_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$id . "'");
  1070. $addresses = tep_db_fetch_array($addresses_query);
  1071. return $addresses['total'];
  1072. }
  1073. // nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \n)
  1074. function tep_convert_linefeeds($from, $to, $string) {
  1075. if ((PHP_VERSION < "4.0.5") && is_array($from)) {
  1076. return ereg_replace('(' . implode('|', $from) . ')', $to, $string);
  1077. } else {
  1078. return str_replace($from, $to, $string);
  1079. }
  1080. }
  1081. function tep_db_prepare_input($string) {
  1082. if (is_string($string)) {
  1083. return trim(stripslashes($string));
  1084. } elseif (is_array($string)) {
  1085. reset($string);
  1086. while (list($key, $value) = each($string)) {
  1087. $string[$key] = tep_db_prepare_input($value);
  1088. }
  1089. return $string;
  1090. } else {
  1091. return $string;
  1092. }
  1093. }
  1094. ////
  1095. // Alias function for Store configuration values in the Administration Tool
  1096. function tep_cfg_select_option($select_array, $key_value, $key = '') {
  1097. $string = '';
  1098. for ($i=0, $n=sizeof($select_array); $i<$n; $i++) {
  1099. $name = ((tep_not_null($key)) ? 'configuration[' . $key . ']' : 'configuration_value');
  1100. $string .= '<br><input type="radio" name="' . $name . '" value="' . $select_array[$i] . '"';
  1101. if ($key_value == $select_array[$i]) $string .= ' CHECKED';
  1102. $string .= '> ' . $select_array[$i];
  1103. }
  1104. return $string;
  1105. }
  1106. ?>