PageRenderTime 63ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/var/upgrade/4.4.2-4.4.3/init.php

https://github.com/DX66/private_sales
PHP | 1301 lines | 859 code | 250 blank | 192 comment | 139 complexity | 26f58bf990f9bb9fb11fdd7cb93b7ce8 MD5 | raw file
  1. <?php
  2. /* vim: set ts=4 sw=4 sts=4 et: */
  3. /*****************************************************************************\
  4. +-----------------------------------------------------------------------------+
  5. | X-Cart |
  6. | Copyright (c) 2001-2011 Ruslan R. Fazlyev <rrf@x-cart.com> |
  7. | All rights reserved. |
  8. +-----------------------------------------------------------------------------+
  9. | PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
  10. | FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE |
  11. | AT THE FOLLOWING URL: http://www.x-cart.com/license.php |
  12. | |
  13. | THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE |
  14. | THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. |
  15. | FAZLYEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING |
  16. | AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). |
  17. | PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT |
  18. | CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, |
  19. | COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY |
  20. | (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS |
  21. | LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS |
  22. | AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND |
  23. | OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS |
  24. | AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE |
  25. | THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.|
  26. | THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. |
  27. | |
  28. | The Initial Developer of the Original Code is Ruslan R. Fazlyev |
  29. | Portions created by Ruslan R. Fazlyev are Copyright (C) 2001-2011 |
  30. | Ruslan R. Fazlyev. All Rights Reserved. |
  31. +-----------------------------------------------------------------------------+
  32. \*****************************************************************************/
  33. /**
  34. * X-Cart initialization
  35. *
  36. * @category X-Cart
  37. * @package X-Cart
  38. * @subpackage Lib
  39. * @author Ruslan R. Fazlyev <rrf@x-cart.com>
  40. * @copyright Copyright (c) 2001-2011 Ruslan R. Fazlyev <rrf@x-cart.com>
  41. * @license http://www.x-cart.com/license.php X-Cart license agreement
  42. * @version $Id: init.php,v 1.179.2.14 2011/01/10 13:11:43 ferz Exp $
  43. * @link http://www.x-cart.com/
  44. * @see ____file_see____
  45. */
  46. if (!defined('XCART_START')) { header("Location: index.php"); die("Access denied"); }
  47. require_once $xcart_dir . '/prepare.php';
  48. set_include_path($xcart_dir . XC_DS . 'include' .XC_DS. 'lib' .XC_DS. 'PEAR');
  49. require_once $xcart_dir . '/include/func/func.core.php';
  50. x_load(
  51. 'db',
  52. 'files',
  53. 'compat',
  54. 'gd',
  55. 'clean_urls',
  56. 'memcache'
  57. );
  58. func_set_memory_limit('32M');
  59. /**
  60. * Allow displaying content in functions, registered in register_shutdown_function()
  61. */
  62. $zlib_oc = ini_get('zlib.output_compression');
  63. if (
  64. !empty($zlib_oc)
  65. || version_compare(phpversion(), '4.0.6') <= 0
  66. ) {
  67. define('NO_RSFUNCTION', true);
  68. }
  69. unset($zlib_oc);
  70. if (version_compare(phpversion(), '5.0.0') >= 0) {
  71. define('X_PHP5x_COMPAT', true);
  72. }
  73. if (
  74. function_exists('date_default_timezone_get')
  75. && function_exists('date_default_timezone_set')
  76. ) {
  77. @date_default_timezone_set(@date_default_timezone_get());
  78. }
  79. if (version_compare(phpversion(), '5.3.0') >= 0) {
  80. define('X_PHP530_COMPAT', true);
  81. }
  82. if (!@is_readable($xcart_dir . '/config.php')) {
  83. func_show_error_page("Cannot read config!");
  84. }
  85. require_once $xcart_dir . '/config.php';
  86. if (
  87. file_exists($xcart_dir . '/config.local.php')
  88. && is_readable($xcart_dir . '/config.local.php')
  89. ) {
  90. include_once $xcart_dir . '/config.local.php';
  91. }
  92. /**
  93. * This directive defines if some secured information would be
  94. * shown on the WEB (file system structure, MySQL internal error)
  95. * Currently it depends on $debug_mode value.
  96. */
  97. $display_critical_errors = in_array($debug_mode, array(1, 3));
  98. /**
  99. * HTTP & HTTPS locations
  100. */
  101. $http_location = 'http://' . $xcart_http_host . $xcart_web_dir;
  102. $https_location = 'https://' . $xcart_https_host . $xcart_web_dir;
  103. $current_location = $HTTPS ? $https_location : $http_location;
  104. if (
  105. (
  106. !isset($is_install_preview)
  107. || $is_install_preview != 'Y'
  108. )
  109. && !defined('XCART_EXT_ENV')
  110. && (
  111. empty($sql_host)
  112. || $sql_host == '%SQL_HOST%'
  113. || empty($sql_user)
  114. || $sql_user == '%SQL_USER%'
  115. || empty($sql_db)
  116. || $sql_db == '%SQL_DB%'
  117. || $sql_password == '%SQL_PASSWORD%'
  118. )
  119. ) {
  120. $message = "X-Cart software cannot connect to the MySQL database because your MySQL account information is missing from X-Cart's configuration file config.php.";
  121. $install_script = $xcart_dir . XC_DS . 'install.php';
  122. $install_script = (file_exists($install_script) && is_readable($install_script))
  123. ? func_get_xcart_home() . '/install.php'
  124. : false;
  125. $extra_info = "<p>This may be caused by that X-Cart installation has not been carried out or the file config.php has been edited in a wrong way. ";
  126. if ($install_script) {
  127. $extra_info .= "If you think X-Cart installation has not been performed or has not been completed properly, use the link below to run X-Cart's installation script.";
  128. }
  129. $extra_info .= "</p>";
  130. $extra_info .= "<p>If the installation process has been completed, but you are getting this message, the problem is likely caused by incorrect information in your config.php file. Check the file config.php and make sure the SQL database details settings in it are correct.</p>";
  131. if (false !== $install_script) {
  132. $extra_info .= "<p><a href='$install_script'>Run the installation script</a></p>";
  133. }
  134. func_show_error_page("Cannot connect to the database", $message, $extra_info);
  135. }
  136. $file_temp_dir = $var_dirs['tmp'];
  137. /**
  138. * SQL tables aliases...
  139. */
  140. // WARNING!!!
  141. // Do not change the table name prefix in $sql_tbl!
  142. // Otherwise you will not be able to upgrade and reinstall the software.
  143. $sql_tbl = array (
  144. 'address_book' => 'xcart_address_book',
  145. 'amazon_data' => 'xcart_amazon_data',
  146. 'amazon_orders' => 'xcart_amazon_orders',
  147. 'delayed_queries' => 'xcart_delayed_queries',
  148. 'benchmark_pages' => 'xcart_benchmark_pages',
  149. 'categories' => 'xcart_categories',
  150. 'categories_subcount' => 'xcart_categories_subcount',
  151. 'categories_lng' => 'xcart_categories_lng',
  152. 'category_bookmarks' => 'xcart_category_bookmarks',
  153. 'category_memberships' => 'xcart_category_memberships',
  154. 'cc_gestpay_data' => 'xcart_cc_gestpay_data',
  155. 'cc_pp3_data' => 'xcart_cc_pp3_data',
  156. 'ccprocessors' => 'xcart_ccprocessors',
  157. 'change_password' => 'xcart_change_password',
  158. 'clean_urls' => 'xcart_clean_urls',
  159. 'clean_urls_history' => 'xcart_clean_urls_history',
  160. 'config' => 'xcart_config',
  161. 'contact_fields' => 'xcart_contact_fields',
  162. 'counties' => 'xcart_counties',
  163. 'countries' => 'xcart_countries',
  164. 'country_currencies' => 'xcart_country_currencies',
  165. 'currencies' => 'xcart_currencies',
  166. 'customers' => 'xcart_customers',
  167. 'delivery' => 'xcart_delivery',
  168. 'discount_coupons' => 'xcart_discount_coupons',
  169. 'discount_coupons_login' => 'xcart_discount_coupons_login',
  170. 'discounts' => 'xcart_discounts',
  171. 'discount_memberships' => 'xcart_discount_memberships',
  172. 'download_keys' => 'xcart_download_keys',
  173. 'export_ranges' => 'xcart_export_ranges',
  174. 'extra_fields' => 'xcart_extra_fields',
  175. 'extra_fields_lng' => 'xcart_extra_fields_lng',
  176. 'extra_field_values' => 'xcart_extra_field_values',
  177. 'featured_products' => 'xcart_featured_products',
  178. 'form_ids' => 'xcart_form_ids',
  179. 'gcheckout_orders' => 'xcart_gcheckout_orders',
  180. 'gcheckout_restrictions' => 'xcart_gcheckout_restrictions',
  181. 'ge_products' => 'xcart_ge_products',
  182. 'giftcerts' => 'xcart_giftcerts',
  183. 'images_G' => 'xcart_images_G',
  184. 'images_T' => 'xcart_images_T',
  185. 'images_P' => 'xcart_images_P',
  186. 'images_D' => 'xcart_images_D',
  187. 'images_C' => 'xcart_images_C',
  188. 'images_M' => 'xcart_images_M',
  189. 'import_cache' => 'xcart_import_cache',
  190. 'iterations' => 'xcart_iterations',
  191. 'language_codes' => 'xcart_language_codes',
  192. 'languages' => 'xcart_languages',
  193. 'languages_alt' => 'xcart_languages_alt',
  194. 'login_history' => 'xcart_login_history',
  195. 'manufacturers' => 'xcart_manufacturers',
  196. 'manufacturers_lng' => 'xcart_manufacturers_lng',
  197. 'memberships' => 'xcart_memberships',
  198. 'memberships_lng' => 'xcart_memberships_lng',
  199. 'modules' => 'xcart_modules',
  200. 'newsletter' => 'xcart_newsletter',
  201. 'newslist_subscription' => 'xcart_newslist_subscription',
  202. 'newslists' => 'xcart_newslists',
  203. 'old_passwords' => 'xcart_old_passwords',
  204. 'order_details' => 'xcart_order_details',
  205. 'order_extras' => 'xcart_order_extras',
  206. 'orders' => 'xcart_orders',
  207. 'packages_cache' => 'xcart_packages_cache',
  208. 'pages' => 'xcart_pages',
  209. 'payment_methods' => 'xcart_payment_methods',
  210. 'pmethod_memberships' => 'xcart_pmethod_memberships',
  211. 'pricing' => 'xcart_pricing',
  212. 'product_bookmarks' => 'xcart_product_bookmarks',
  213. 'product_links' => 'xcart_product_links',
  214. 'product_memberships' => 'xcart_product_memberships',
  215. 'product_reviews' => 'xcart_product_reviews',
  216. 'product_rnd_keys' => 'xcart_product_rnd_keys',
  217. 'product_taxes' => 'xcart_product_taxes',
  218. 'product_votes' => 'xcart_product_votes',
  219. 'products' => 'xcart_products',
  220. 'products_categories' => 'xcart_products_categories',
  221. 'products_lng' => 'xcart_products_lng',
  222. 'provider_product_commissions' => 'xcart_provider_product_commissions',
  223. 'provider_commissions' => 'xcart_provider_commissions',
  224. 'quick_flags' => 'xcart_quick_flags',
  225. 'quick_prices' => 'xcart_quick_prices',
  226. 'referers' => 'xcart_referers',
  227. 'register_fields' => 'xcart_register_fields',
  228. 'register_field_values' => 'xcart_register_field_values',
  229. 'secure3d_data' => 'xcart_secure3d_data',
  230. 'seller_addresses' => 'xcart_seller_addresses',
  231. 'session_history' => 'xcart_session_history',
  232. 'sessions_data' => 'xcart_sessions_data',
  233. 'session_unknown_sid' => 'xcart_session_unknown_sid',
  234. 'setup_images' => 'xcart_setup_images',
  235. 'shipping' => 'xcart_shipping',
  236. 'shipping_cache' => 'xcart_shipping_cache',
  237. 'shipping_labels' => 'xcart_shipping_labels',
  238. 'shipping_options' => 'xcart_shipping_options',
  239. 'shipping_rates' => 'xcart_shipping_rates',
  240. 'split_checkout' => 'xcart_split_checkout',
  241. 'states' => 'xcart_states',
  242. 'stats_adaptive' => 'xcart_stats_adaptive',
  243. 'stats_cart_funnel' => 'xcart_stats_cart_funnel',
  244. 'stats_customers_products' => 'xcart_stats_customers_products',
  245. 'stats_pages' => 'xcart_stats_pages',
  246. 'stats_pages_paths' => 'xcart_stats_pages_paths',
  247. 'stats_pages_views' => 'xcart_stats_pages_views',
  248. 'stats_search' => 'xcart_stats_search',
  249. 'stats_shop' => 'xcart_stats_shop',
  250. 'tax_rate_memberships' => 'xcart_tax_rate_memberships',
  251. 'tax_rates' => 'xcart_tax_rates',
  252. 'taxes' => 'xcart_taxes',
  253. 'temporary_data' => 'xcart_temporary_data',
  254. 'titles' => 'xcart_titles',
  255. 'wishlist' => 'xcart_wishlist',
  256. 'users_online' => 'xcart_users_online',
  257. 'zone_element' => 'xcart_zone_element',
  258. 'zones' => 'xcart_zones',
  259. );
  260. /**
  261. * Redefine error_reporting option
  262. */
  263. if (defined('X_PHP530_COMPAT')) {
  264. $x_error_reporting = $x_error_reporting & !(E_DEPRECATED | E_USER_DEPRECATED);
  265. }
  266. error_reporting($x_error_reporting);
  267. /**
  268. * Fix broken path for some hostings
  269. */
  270. $_tmp = @parse_url($current_location);
  271. $xcart_web_dir = empty($_tmp['path']) ? '' : $_tmp['path'];
  272. if ($HTTPS_RELAY) {
  273. // Fix wrong PHP_SELF for HTTPS relay
  274. $_tmp = @parse_url($http_location);
  275. $PHP_SELF = empty($_tmp['path'])
  276. ? $xcart_web_dir . $PHP_SELF
  277. : $xcart_web_dir . preg_replace("/^" . preg_quote($_tmp['path'], "/")."/", "", $PHP_SELF);
  278. $_SERVER['PHP_SELF'] = $PHP_SELF;
  279. $xcart_web_dir = preg_replace("/\/[\w\d_-]+\.[\w\d]+$/", '', $PHP_SELF);
  280. $for_replace = false;
  281. switch(AREA_TYPE) {
  282. case 'C':
  283. $for_replace = DIR_CUSTOMER;
  284. break;
  285. case 'A':
  286. $for_replace = DIR_ADMIN;
  287. break;
  288. case 'P':
  289. $for_replace = DIR_PROVIDER;
  290. break;
  291. case 'B':
  292. $for_replace = DIR_PARTNER;
  293. break;
  294. }
  295. if (false !== $for_replace) {
  296. $xcart_web_dir = preg_replace('/' . preg_quote($for_replace, '/') . "$/", '', $xcart_web_dir);
  297. }
  298. }
  299. $_tmp = @parse_url($https_location);
  300. $xcart_https_host = $_tmp['host'];
  301. unset($_tmp);
  302. $_tmp = @parse_url($http_location);
  303. $xcart_http_host = $_tmp['host'];
  304. unset($_tmp);
  305. /**
  306. * Create URL
  307. */
  308. $request_uri_info = @parse_url($REQUEST_URI);
  309. $php_url = array(
  310. 'url' => 'http'
  311. . (
  312. $HTTPS
  313. ? 's://'
  314. . $xcart_https_host
  315. : '://'
  316. . $xcart_http_host
  317. )
  318. . (
  319. !zerolen($request_uri_info['path'])
  320. ? $request_uri_info['path']
  321. : $PHP_SELF
  322. ),
  323. 'query_string' => $QUERY_STRING,
  324. );
  325. /**
  326. * Check internal temporary directories
  327. */
  328. $var_dirs_rules = array (
  329. 'cache' => array (
  330. '.htaccess' => "<FilesMatch \"\\.(css|js)$\">\nAllow from all\n</FilesMatch>\n"
  331. )
  332. );
  333. foreach ($var_dirs as $k => $v) {
  334. if (
  335. !file_exists($v)
  336. || !is_dir($v)
  337. ) {
  338. @unlink($v);
  339. func_mkdir($v);
  340. }
  341. if (
  342. !is_writable($v)
  343. || !is_dir($v)
  344. ) {
  345. $dir_info = $display_critical_errors ? $v : '';
  346. func_show_error_page("Cannot write data to the temporary directory $dir_info", "Please check if it exists, and has writable permissions.");
  347. }
  348. if (
  349. !empty($var_dirs_rules[$k])
  350. && is_array($var_dirs_rules[$k])
  351. ) {
  352. foreach ($var_dirs_rules[$k] as $f => $c) {
  353. if (file_exists($v . '/' . $f))
  354. continue;
  355. if ($__fp = @fopen($v . '/' . $f, 'w')) {
  356. @fwrite($__fp, $c);
  357. @fclose($__fp);
  358. func_chmod_file($v . '/' . $f, 0644);
  359. }
  360. }
  361. }
  362. }
  363. if (!file_exists($xcart_dir . '/var/.htaccess')) {
  364. if ($fp = @fopen($xcart_dir . '/var/.htaccess', 'w')) {
  365. @fwrite($fp, "Order Deny,Allow\nDeny from all\n");
  366. @fclose($fp);
  367. func_chmod_file($xcart_dir . '/var/.htaccess', 0644);
  368. }
  369. }
  370. /**
  371. * Initialize logging
  372. */
  373. require_once $xcart_dir . '/include/logging.php';
  374. /**
  375. * Include functions
  376. */
  377. include_once($xcart_dir . '/include/bench.php');
  378. /**
  379. * Connect to database
  380. */
  381. $mysql_error_count = 0;
  382. db_connection($sql_host, $sql_user, $sql_db, $sql_password);
  383. /**
  384. * Read config variables from Database
  385. * These variables are used inside php scripts, not in smarty templates
  386. */
  387. global $memcache;
  388. $get_config = true;
  389. if ($memcache) {
  390. $config = func_get_mcache_data('inner_config');
  391. $get_config = false === $config;
  392. register_shutdown_function('func_remove_mcache_config');
  393. }
  394. if ($get_config) {
  395. $c_result = db_query("SELECT name, value, category FROM $sql_tbl[config] WHERE type != 'separator'");
  396. $config = array();
  397. if ($c_result) {
  398. while ($row = db_fetch_row($c_result)) {
  399. if (!empty($row[2])) {
  400. if ('XCART_INNER_EVENTS' !== $row[2]) {
  401. $config[$row[2]][$row[0]] = $row[1];
  402. }
  403. } else {
  404. $config[$row[0]] = $row[1];
  405. }
  406. }
  407. }
  408. db_free_result($c_result);
  409. if ($memcache) {
  410. func_store_mcache_data('inner_config', $config);
  411. }
  412. }
  413. /*
  414. * Check PHP ini since last launch and write changes to log file
  415. */
  416. if ($config['General']['skip_log_phpini_changes'] != 'Y') {
  417. func_check_phpini_changes();
  418. }
  419. /**
  420. * Initialize alt_skin feature
  421. */
  422. require_once $xcart_dir . '/include/alt_skin.php';
  423. /**
  424. * Create Smarty object
  425. */
  426. if (!include $xcart_dir . '/smarty.php') {
  427. func_show_error_page("Cannot launch template engine!", '');
  428. }
  429. $smarty->assign('alt_skin_info', $alt_skin_info);
  430. $smarty->assign('alt_skins_info', $altSkinsInfo);
  431. /**
  432. * Init miscellaneous vars
  433. */
  434. $smarty ->assign('skin_config', $skin_config_file);
  435. $mail_smarty->assign('skin_config', $skin_config_file);
  436. $smarty ->assign('http_location', $http_location);
  437. $mail_smarty->assign('http_location', $http_location);
  438. $smarty ->assign('https_location', $https_location);
  439. $mail_smarty->assign('https_location', $https_location);
  440. $smarty ->assign('xcart_web_dir', $xcart_web_dir);
  441. $smarty ->assign('current_location', $current_location);
  442. $smarty ->assign('php_url', $php_url);
  443. foreach ($var_dirs_web as $k => $v) {
  444. $var_dirs_web[$k] = $current_location . $v;
  445. }
  446. $smarty->assign_by_ref('var_dirs_web', $var_dirs_web);
  447. $xcart_catalogs = array (
  448. 'admin' => $current_location . DIR_ADMIN,
  449. 'customer' => $current_location . DIR_CUSTOMER,
  450. 'provider' => $current_location . DIR_PROVIDER,
  451. 'partner' => $current_location . DIR_PARTNER,
  452. );
  453. $xcart_catalogs_insecure = array (
  454. 'admin' => $http_location . DIR_ADMIN,
  455. 'customer' => $http_location . DIR_CUSTOMER,
  456. 'provider' => $http_location . DIR_PROVIDER,
  457. 'partner' => $http_location . DIR_PARTNER,
  458. );
  459. $xcart_catalogs_secure = array (
  460. 'admin' => $https_location . DIR_ADMIN,
  461. 'customer' => $https_location . DIR_CUSTOMER,
  462. 'provider' => $https_location . DIR_PROVIDER,
  463. 'partner' => $https_location . DIR_PARTNER,
  464. );
  465. $smarty ->assign('catalogs', $xcart_catalogs);
  466. $smarty ->assign('catalogs_secure', $xcart_catalogs_secure);
  467. $mail_smarty ->assign('catalogs', $xcart_catalogs);
  468. $mail_smarty ->assign('catalogs_secure', $xcart_catalogs_secure);
  469. /**
  470. * Files directories
  471. */
  472. $files_dir_name = $xcart_dir . $files_dir;
  473. $files_http_location = $http_location . $files_webdir;
  474. $smarty->assign('files_location', $files_dir_name);
  475. $templates_repository = $xcart_dir . $templates_repository_dir;
  476. /**
  477. * Include data cache functionality
  478. */
  479. include_once($xcart_dir . '/include/data_cache.php');
  480. $sql_vars = func_data_cache_get('sql_vars');
  481. $sql_max_allowed_packet = intval($sql_vars['max_allowed_packet']);
  482. if (preg_match("/^(\d+\.\d+\.\d+)/", mysql_get_server_info(), $match)) {
  483. define('X_MYSQL_VERSION', $match[1]);
  484. if (version_compare(X_MYSQL_VERSION, '5.0.0') >= 0)
  485. db_query("SET sql_mode = 'MYSQL40'");
  486. if (version_compare(X_MYSQL_VERSION, '5.0.17') > 0)
  487. define('X_MYSQL5_COMP_MODE', true);
  488. if (version_compare(X_MYSQL_VERSION, '5.0.18') == 0)
  489. define('X_MYSQL5018_COMP_MODE', true);
  490. if (version_compare(X_MYSQL_VERSION, '4.1.0') >= 0)
  491. define('X_MYSQL41_COMP_MODE', true);
  492. if (version_compare(X_MYSQL_VERSION, '4.0.0') >= 0)
  493. define('X_MYSQL40_COMP_MODE', true);
  494. }
  495. if (is_numeric($sql_vars['lower_case_table_names'])) {
  496. define('X_MYSQL_LOWER_CASE_TABLE_NAMES', intval($sql_vars['lower_case_table_names']));
  497. }
  498. $md5_check_devlicense = '726e5429de89a8afb5fe2ed1040fb852';
  499. /**
  500. * Set MySQL variable 'max_join_size'
  501. */
  502. if (intval($sql_vars['max_join_size']) < 1073741824) {
  503. db_query("SET OPTION SQL_MAX_JOIN_SIZE=1073741824");
  504. }
  505. /**
  506. * Retrive registration information from database
  507. */
  508. $shop_evaluation = func_is_evaluation();
  509. $smarty->assign('shop_evaluation', $shop_evaluation);
  510. /**
  511. * Schema to test .htaccess file if some configuration variables are on.
  512. */
  513. $schemaTestHtaccess = array(
  514. array(
  515. 'config' => array(
  516. 'SEO',
  517. 'clean_urls_enabled',
  518. ),
  519. 'htaccessWord' => 'dispatcher.php [L]',
  520. ),
  521. );
  522. $htaccessWarning = array();
  523. foreach ($schemaTestHtaccess as $schemaUnit) {
  524. if (
  525. 'Y' == $config[$schemaUnit['config'][0]][$schemaUnit['config'][1]]
  526. && !func_test_htaccess($schemaUnit['htaccessWord'])
  527. ) {
  528. if (
  529. defined('AREA_TYPE')
  530. && 'C' == constant('AREA_TYPE')
  531. ) {
  532. $config[$schemaUnit['config'][0]][$schemaUnit['config'][1]] = 'N';
  533. } else {
  534. $htaccessWarning[$schemaUnit['config'][0]] = "Y";
  535. }
  536. }
  537. }
  538. $smarty->assign('htaccess_warning', $htaccessWarning);
  539. $config['Sessions']['session_length'] = $use_session_length;
  540. /**
  541. * Timezone offset (sec) = N hours x 60 minutes x 60 seconds
  542. */
  543. $config['Appearance']['timezone_offset'] = intval($config['Appearance']['timezone_offset'] * 3600);
  544. /**
  545. * Define 'End year' for date selectors in the templates
  546. */
  547. $config['Company']['end_year'] = func_date('Y', XC_TIME + $config['Appearance']['timezone_offset']);
  548. /**
  549. * Last database backup date
  550. */
  551. if (!empty($config['db_backup_date']))
  552. $config['db_backup_date'] += $config['Appearance']['timezone_offset'];
  553. $config['available_images']['T'] = "U";
  554. $config['available_images']['P'] = "U";
  555. $config['available_images']['C'] = "U";
  556. $config['available_images']['G'] = "U";
  557. $config['substitute_images']['P'] = "T";
  558. $httpsmod_active = NULL;
  559. if (!defined('QUICK_START')) {
  560. if (empty($config['Appearance']['thumbnail_width']))
  561. $config['Appearance']['thumbnail_width'] = 0;
  562. if (empty($config['Appearance']['date_format']))
  563. $config['Appearance']['date_format'] = "%d-%m-%Y";
  564. $config['Appearance']['datetime_format'] =
  565. $config['Appearance']['date_format'] . " " . $config['Appearance']['time_format'];
  566. }
  567. $config['Appearance']['thumbnail_width'] = intval($config['Appearance']['thumbnail_width']);
  568. /**
  569. * Prepare session
  570. */
  571. include_once $xcart_dir . '/include/sessions.php';
  572. include_once $xcart_dir . '/include/unallowed_request.php';
  573. // Search engine bots & spiders identificator
  574. if (is_readable($xcart_dir . '/include/bots.php')) {
  575. require_once $xcart_dir . '/include/bots.php';
  576. }
  577. if (!defined('QUICK_START')) {
  578. include_once($xcart_dir . '/include/blowfish.php');
  579. // Start Blowfish class
  580. $blowfish = new ctBlowfish();
  581. }
  582. /**
  583. * Prepare number variables
  584. */
  585. include_once $xcart_dir . '/include/number_conv.php';
  586. if (!defined('QUICK_START')) {
  587. /**
  588. * Define default user profile fields
  589. */
  590. $default_user_profile_fields = array(
  591. 'title' => array(
  592. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N'),
  593. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N')
  594. ),
  595. 'firstname' => array(
  596. 'avail' => array('A' => 'Y', 'P' => 'Y', 'B' => 'Y', 'C' => 'Y', 'H' => 'N'),
  597. 'required' => array('A' => 'Y', 'P' => 'Y', 'B' => 'Y', 'C' => 'Y', 'H' => 'N')
  598. ),
  599. 'lastname' => array(
  600. 'avail' => array('A' => 'Y', 'P' => 'Y', 'B' => 'Y', 'C' => 'Y', 'H' => 'N'),
  601. 'required' => array('A' => 'Y', 'P' => 'Y', 'B' => 'Y', 'C' => 'Y', 'H' => 'N')
  602. ),
  603. 'company' => array(
  604. 'avail' => array('A' => 'Y', 'P' => 'Y', 'B' => 'Y', 'C' => 'Y', 'H' => 'N'),
  605. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N')
  606. ),
  607. 'url' => array(
  608. 'avail' => array('A' => 'Y', 'P' => 'Y', 'B' => 'Y', 'C' => 'Y', 'H' => 'N'),
  609. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N')
  610. ),
  611. 'ssn' => array (
  612. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'Y', 'C' => 'N' ,'H' => 'N'),
  613. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'Y', 'C' => 'N', 'H' => 'N')
  614. ),
  615. 'tax_number' => array (
  616. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'Y', 'C' => 'Y' ,'H' => 'N'),
  617. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'Y', 'C' => 'N', 'H' => 'N')
  618. )
  619. );
  620. /**
  621. * Define default address book fields
  622. */
  623. $default_address_book_fields = array(
  624. 'title' => array (
  625. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N'),
  626. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N')
  627. ),
  628. 'firstname' => array(
  629. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  630. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y')
  631. ),
  632. 'lastname' => array(
  633. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  634. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y')
  635. ),
  636. 'address' => array(
  637. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  638. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y')
  639. ),
  640. 'address_2' => array(
  641. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  642. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N')
  643. ),
  644. 'city' => array(
  645. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  646. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y')
  647. ),
  648. 'county' => array(
  649. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N'),
  650. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N')
  651. ),
  652. 'state' => array(
  653. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  654. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y')
  655. ),
  656. 'country' => array(
  657. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  658. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y')
  659. ),
  660. 'zipcode' => array(
  661. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  662. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y')
  663. ),
  664. 'phone' => array(
  665. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  666. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N')
  667. ),
  668. 'fax' => array(
  669. 'avail' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'Y', 'H' => 'Y'),
  670. 'required' => array('A' => 'N', 'P' => 'N', 'B' => 'N', 'C' => 'N', 'H' => 'N')
  671. )
  672. );
  673. /**
  674. * Define default contact us fields
  675. */
  676. $default_contact_us_fields = array(
  677. 'department' => array(
  678. 'avail' => 'Y',
  679. 'required' => 'Y'
  680. ),
  681. 'username' => array(
  682. 'avail' => 'Y',
  683. 'required' => 'Y'
  684. ),
  685. 'title' => array(
  686. 'avail' => 'N',
  687. 'required' => 'N'
  688. ),
  689. 'firstname' => array(
  690. 'avail' => 'Y',
  691. 'required' => 'Y'
  692. ),
  693. 'lastname' => array(
  694. 'avail' => 'Y',
  695. 'required' => 'Y'
  696. ),
  697. 'company' => array(
  698. 'avail' => 'Y',
  699. 'required' => 'N'
  700. ),
  701. 'b_address' => array(
  702. 'avail' => 'Y',
  703. 'required' => 'Y'
  704. ),
  705. 'b_address_2' => array(
  706. 'avail' => 'Y',
  707. 'required' => 'N'
  708. ),
  709. 'b_city' => array(
  710. 'avail' => 'Y',
  711. 'required' => 'Y'
  712. ),
  713. 'b_county' => array(
  714. 'avail' => 'Y',
  715. 'required' => 'Y'
  716. ),
  717. 'b_state' => array(
  718. 'avail' => 'Y',
  719. 'required' => 'Y'
  720. ),
  721. 'b_country' => array(
  722. 'avail' => 'Y',
  723. 'required' => 'Y'
  724. ),
  725. 'b_zipcode' => array(
  726. 'avail' => 'Y',
  727. 'required' => 'Y'
  728. ),
  729. 'phone' => array(
  730. 'avail' => 'Y',
  731. 'required' => 'Y'
  732. ),
  733. 'email' => array(
  734. 'avail' => 'Y',
  735. 'required' => 'Y'
  736. ),
  737. 'fax' => array(
  738. 'avail' => 'Y',
  739. 'required' => 'N'
  740. ),
  741. 'url' => array(
  742. 'avail' => 'Y',
  743. 'required' => 'N'
  744. )
  745. );
  746. /**
  747. * Define shipping estimator fields
  748. */
  749. $shipping_estimate_fields = array(
  750. 'city' => array(
  751. 'avail' => 'Y',
  752. 'required' => ''
  753. ),
  754. 'county' => array(
  755. 'avail' => 'Y',
  756. 'required' => ''
  757. ),
  758. 'state' => array(
  759. 'avail' => 'Y',
  760. 'required' => 'Y'
  761. ),
  762. 'country' => array(
  763. 'avail' => 'Y',
  764. 'required' => 'Y'
  765. ),
  766. 'zipcode' => array(
  767. 'avail' => 'Y',
  768. 'required' => 'Y'
  769. )
  770. );
  771. if ($config['General']['use_counties'] != 'Y') {
  772. // Disable county usage
  773. $default_address_book_fields['county']['avail'] = 'N';
  774. $default_address_book_fields['county']['required'] = 'N';
  775. $default_contact_us_fields['b_county']['avail'] = 'N';
  776. $default_contact_us_fields['b_county']['required'] = 'N';
  777. $shipping_estimate_fields['county']['avail'] = 'N';
  778. }
  779. $taxes_units = array(
  780. 'ST' => 'lbl_subtotal',
  781. 'DST' => 'lbl_discounted_subtotal',
  782. 'SH' => 'lbl_shipping_cost',
  783. );
  784. // Unserialize & Assign Right-to-Left languages
  785. if (isset($config['r2l_languages']))
  786. $config['r2l_languages'] = unserialize ($config['r2l_languages']);
  787. // Unserialize & Assign card types
  788. if (!empty($config['card_types']))
  789. $config['card_types'] = unserialize ($config['card_types']);
  790. if (
  791. defined('AREA_TYPE')
  792. && 'C' == constant('AREA_TYPE')
  793. && is_array($config['card_types'])
  794. ) {
  795. foreach ($config['card_types'] as $key => $value) {
  796. if (empty($value['active'])) {
  797. unset($config['card_types'][$key]);
  798. }
  799. }
  800. }
  801. $smarty->assign ('card_types', $config['card_types']);
  802. // Include webmaster mode
  803. if (
  804. file_exists($xcart_dir . '/include/webmaster.php')
  805. && is_readable($xcart_dir . '/include/webmaster.php')
  806. ) {
  807. include_once $xcart_dir . '/include/webmaster.php';
  808. }
  809. if(
  810. $config['General']['enable_debug_console'] == 'Y'
  811. || $editor_mode == 'editor'
  812. ) {
  813. $smarty->debugging = true;
  814. }
  815. // IP addresses
  816. $smarty->assign('PROXY_IP', $PROXY_IP);
  817. $smarty->assign('CLIENT_IP', $CLIENT_IP);
  818. $smarty->assign('REMOTE_ADDR', $REMOTE_ADDR);
  819. $mail_smarty->assign('PROXY_IP', $PROXY_IP);
  820. $mail_smarty->assign('CLIENT_IP', $CLIENT_IP);
  821. $mail_smarty->assign('REMOTE_ADDR', $REMOTE_ADDR);
  822. // Disable Clean URLs functionality if a request is performed by the HTML Catalog generator script.
  823. if (defined('IS_ROBOT') && defined('ROBOT') && constant('ROBOT') == 'X-Cart Catalog Generator') {
  824. $config['SEO']['clean_urls_enabled'] = 'N';
  825. }
  826. // Adaptives section
  827. if (
  828. file_exists($xcart_dir . '/include/adaptives.php')
  829. && is_readable($xcart_dir . '/include/adaptives.php')
  830. ) {
  831. include_once $xcart_dir . '/include/adaptives.php';
  832. }
  833. }
  834. /**
  835. * Crontab tasks list
  836. */
  837. $cron_tasks = array();
  838. $cron_tasks[] = array(
  839. 'x_load' => 'payment',
  840. 'function' => 'func_check_preauth_expiration'
  841. );
  842. $cron_tasks[] = array(
  843. 'x_load' => 'payment',
  844. 'function' => 'func_check_preauth_expiration_ttl'
  845. );
  846. /**
  847. * Read Modules and put in into $active_modules
  848. */
  849. $import_specification = array();
  850. $active_modules = func_data_cache_get('modules');
  851. if (!is_array($active_modules))
  852. $active_modules = array();
  853. $active_modules["Simple_Mode"] = true;
  854. $shop_type = "GOLD";
  855. $addons = array();
  856. $body_onload = '';
  857. $tbl_demo_data = $tbl_keys = array();
  858. $css_files = array();
  859. $custom_styles = array();
  860. $container_classes = array();
  861. $predefined_setup_images = array();
  862. $image_caches = array();
  863. $smarty->assign('shop_type', $shop_type);
  864. x_load('image');
  865. // Define checkout module
  866. if (!defined('AREA_TYPE') || AREA_TYPE == 'C') {
  867. x_session_register('flc_forced', false);
  868. if (isset($force_flc)) {
  869. $flc_forced = true;
  870. }
  871. $checkout_module = empty($config['General']['checkout_module']) || $flc_forced
  872. ? 'Fast_Lane_Checkout'
  873. : $config['General']['checkout_module'];
  874. $active_modules[$checkout_module] = true;
  875. $smarty->assign('checkout_module', $checkout_module);
  876. }
  877. if ($active_modules) {
  878. foreach ($active_modules as $active_module => $tmp) {
  879. $_module_dir = $xcart_dir . XC_DS . 'modules' . XC_DS . $active_module;
  880. $_config_file = $_module_dir . XC_DS . 'config.php';
  881. $_func_file = $_module_dir . XC_DS . 'func.php';
  882. if (
  883. file_exists($_config_file)
  884. && is_readable($_config_file)
  885. ) {
  886. include $_config_file;
  887. }
  888. if (
  889. file_exists($_func_file)
  890. && is_readable($_func_file)
  891. ) {
  892. include $_func_file;
  893. }
  894. }
  895. }
  896. $smarty->assign_by_ref('active_modules', $active_modules);
  897. $mail_smarty->assign_by_ref('active_modules', $active_modules);
  898. $config['setup_images'] = func_data_cache_get("setup_images");
  899. foreach ($config['available_images'] as $k => $v) {
  900. if (isset($config['setup_images'][$k]))
  901. continue;
  902. if (isset($predefined_setup_images[$k])) {
  903. $config['setup_images'][$k] = $predefined_setup_images[$k];
  904. continue;
  905. }
  906. $config['setup_images'][$k] = array (
  907. 'itype' => $k,
  908. 'location' => 'DB',
  909. 'save_url' => '',
  910. 'size_limit' => 0,
  911. 'md5_check' => '',
  912. 'default_image' => './default_image.gif',
  913. 'image_x' => 124,
  914. 'image_y' => 74
  915. );
  916. }
  917. $config['images_dimensions']['T']['width'] = $config['Appearance']['thumbnail_width'];
  918. $config['images_dimensions']['T']['height'] = $config['Appearance']['thumbnail_height'];
  919. $config['images_dimensions']['P']['width'] = 300;
  920. $config['images_dimensions']['P']['height'] = 225;
  921. $preview_image = 'preview_image.gif';
  922. if (empty($config['User_Profiles']['register_fields']))
  923. $config['User_Profiles']['register_fields'] = serialize(array());
  924. $config['Appearance']['ui_date_format'] = func_get_ui_date_format();
  925. $smarty->assign('single_mode', $single_mode);
  926. func_image_cache_assign('C', 'catthumbn');
  927. /**
  928. * If Antibot turned off after it was loaded
  929. */
  930. if (empty($active_modules['Image_Verification'])) {
  931. x_session_unregister('antibot_validation_val');
  932. x_session_unregister('antibot_friend_err');
  933. x_session_unregister('antibot_contactus_err');
  934. x_session_unregister('antibot_err');
  935. }
  936. if (!defined('QUICK_START')) {
  937. // Assign config array to smarty
  938. $smarty ->assign_by_ref('config', $config);
  939. $mail_smarty->assign_by_ref('config', $config);
  940. // Assign Smarty delimiters
  941. $smarty ->assign('ldelim', "{");
  942. $mail_smarty->assign('ldelim', "{");
  943. $smarty ->assign('rdelim', "}");
  944. $mail_smarty->assign('rdelim', "}");
  945. if (
  946. (
  947. isset($_GET['delimiter'])
  948. && $_GET['delimiter'] == 'tab'
  949. ) || (
  950. isset($_POST['delimiter'])
  951. && $_POST['delimiter'] == 'tab'
  952. )
  953. ) {
  954. $delimiter = "\t";
  955. }
  956. // Assign email regular expression
  957. $smarty->assign('email_validation_regexp', func_email_validation_regexp());
  958. $smarty->assign('clean_url_validation_regexp', func_clean_url_validation_regexp());
  959. }
  960. /**
  961. * Init modules
  962. */
  963. if (is_array($active_modules)) {
  964. $_active_modules = $active_modules;
  965. foreach ($_active_modules as $__k => $__v) {
  966. if (file_exists($xcart_dir . '/modules/' . $__k . '/init.php')) {
  967. include $xcart_dir . '/modules/' . $__k . '/init.php';
  968. }
  969. }
  970. unset($_active_modules);
  971. }
  972. /**
  973. * Session-based cron
  974. */
  975. if (!defined('QUICK_START') && defined('NEW_SESSION')) {
  976. $config['General']['cron_call_per_new_session'] = max(intval($config['General']['cron_call_per_new_session']), 0);
  977. if ($config['General']['cron_call_per_new_session'] > 0) {
  978. $config['cron_counter'] = max(intval(@$config['cron_counter']), 0);
  979. $config['cron_counter']++;
  980. if ($config['cron_counter'] >= $config['General']['cron_call_per_new_session']) {
  981. define('X_INTERNAL_CRON', true);
  982. require($xcart_dir . '/cron.php');
  983. $config['cron_counter'] = 0;
  984. }
  985. func_array2insert(
  986. 'config',
  987. array(
  988. 'name' => 'cron_counter',
  989. 'value' => $config['cron_counter']
  990. ),
  991. true
  992. );
  993. }
  994. }
  995. /**
  996. * Clean temporary data
  997. */
  998. if ((rand() % 10) == 0) {
  999. db_query("DELETE FROM $sql_tbl[temporary_data] WHERE expire < " . XC_TIME);
  1000. }
  1001. /**
  1002. * Remember visitor for a long time period
  1003. */
  1004. $remember_user = true;
  1005. /**
  1006. * Time period for which user info should be stored (days)
  1007. */
  1008. $remember_user_days = 30;
  1009. $smarty ->assign('current_area', func_get_current_area());
  1010. $mail_smarty ->assign('current_area', func_get_current_area());
  1011. /**
  1012. * Redirect from alias host to main host
  1013. */
  1014. if (!defined('XCART_EXT_ENV') && $REQUEST_METHOD == 'GET' && isset($_SERVER['HTTP_HOST'])) {
  1015. $tmp = explode(":", $_SERVER['HTTP_HOST'], 2);
  1016. $server_http_host = strtolower($tmp[0]);
  1017. if ($server_http_host != strtolower($xcart_http_host) && $server_http_host != strtolower($xcart_https_host) && (!$HTTPS || !$HTTPS_RELAY))
  1018. func_header_location(($HTTPS ? "https://".$xcart_https_host : "http://".$xcart_http_host) . $REQUEST_URI, true, 301);
  1019. }
  1020. /**
  1021. * Initialize character set of database. Used in func_translit function
  1022. */
  1023. $config['db_charset'] = defined('X_MYSQL40_COMP_MODE') ? $sql_vars['character_set_client'] : $sql_vars['character_set'];
  1024. unset($sql_vars);
  1025. // Define name of the auth field depending on login setting: email or username
  1026. $login_field_name = func_get_langvar_by_name(
  1027. 'lbl_' . ($config['email_as_login'] == 'Y' ? 'email' : 'username'),
  1028. NULL,
  1029. false,
  1030. true
  1031. );
  1032. $smarty->assign('login_field_name', $login_field_name);
  1033. // Detect modal dialog window
  1034. if (isset($_GET['open_in_layer'])) {
  1035. $smarty->assign('is_modal_popup', true);
  1036. }
  1037. if (isset($_GET['is_ajax_request'])) {
  1038. $smarty->assign('is_ajax_request', true);
  1039. }
  1040. // Check if the cookies are enabled in the browser
  1041. require $xcart_dir . '/include/nocookie_warning.php';
  1042. /**
  1043. * WARNING !
  1044. * Please ensure that you have no whitespaces / empty lines below this message.
  1045. * Adding a whitespace or an empty line below this line will cause a PHP error.
  1046. */
  1047. ?>