function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') { global ${$link}; ${$link} = mysql_connect($server, $username, $password); if (${$link}) { tep_db_select_db($database, $link); } return ${$link}; }
function tep_upload_order($order_id, $delimiter = ',', $upload_dir = '') { if (empty($upload_dir)) { $upload_dir = UPLOAD_DIR . 'orders1/'; } // $order_info_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'"); // if (tep_db_num_rows($order_info_query) < 1) return false; $order_info = tep_db_fetch_array($order_info_query); $insert_id = $order_info['orders_id']; $insert_id = $order_id; $order = new order($insert_id); $shop_info_query = tep_db_query("select shops_url, shops_ssl, shops_prefix, shops_database from " . TABLE_SHOPS . " where shops_id = '" . (int) $order->info['shops_id'] . "'"); $shop_info = tep_db_fetch_array($shop_info_query); $domain_zone = $shop_info['shops_prefix']; $payment_modules = tep_get_payment_modules($order->info['shops_id']); $shipping_modules = tep_get_shipping_modules($order->info['shops_id']); $order_file = $upload_dir . $domain_zone . $insert_id . '.csv'; if (!file_exists($order_file)) { $fp = fopen($order_file, 'w'); $order_history_link = ($order->info['enabled_ssl'] == '1' && tep_not_null($shop_info['shops_ssl']) ? $shop_info['shops_ssl'] : $shop_info['shops_url']) . '/account_history_info.php?order_id=' . $insert_id; $order_total_sum = 0; $order_shipping_sum = 0; $order_discount_sum = 0; reset($order->totals); while (list(, $order_total) = each($order->totals)) { if ($order_total['class'] == 'ot_total') { $order_total_sum = $order_total['value']; } elseif ($order_total['class'] == 'ot_shipping') { $order_shipping_sum = $order_total['value']; $order_shipping_title = $order_total['title']; } elseif (($order_total['class'] == 'ot_discount' || $order_total['class'] == 'ot_custom') && $order_total['value'] < 0) { $order_discount_sum = $order_total['value']; } } $order_payment_id = $order->info['payment_method_class']; if (empty($order_payment_id)) { reset($payment_modules); $payment_found = false; while (list($k, $v) = each($payment_modules)) { if (strpos($v, $order->info['payment_method']) !== false) { $order_payment_id = $k; break; } } if (empty($order_payment_id)) { $order_payment_id = $order->info['payment_method']; } } $order_shipping_id = $order->delivery['delivery_method_class']; if (empty($order_shipping_id)) { reset($shipping_modules); $shipping_found = false; while (list($k, $v) = each($shipping_modules)) { if (strpos($v, $order_shipping_title) !== false) { $order_shipping_id = $k; break; } } if (empty($order_shipping_id)) { $order_shipping_id = $order_shipping_title; } } $self_delivery_id = $order->delivery['delivery_self_address_id']; if (tep_not_null($order->delivery['delivery_self_address']) && (int) $self_delivery_id <= 0) { $shop_info_query = tep_db_query("select shops_database from " . TABLE_SHOPS . " where shops_id = '" . (int) $order->info['shops_id'] . "'"); $shop_info = tep_db_fetch_array($shop_info_query); tep_db_select_db($shop_info['shops_database']); $self_delivery_query = tep_db_query("select self_delivery_id, self_delivery_cost, self_delivery_free, entry_suburb as suburb, entry_city as city, entry_street_address as street_address, entry_telephone as telephone, self_delivery_description from " . TABLE_SELF_DELIVERY . " where 1 order by city, street_address"); while ($self_delivery = tep_db_fetch_array($self_delivery_query)) { $self_delivery_address = tep_address_format($order->delivery['format_id'], $self_delivery, 1, '', ', '); if (strpos($order->delivery['delivery_self_address'], $self_delivery_address) !== false) { $self_delivery_id = $self_delivery['self_delivery_id']; break; } } tep_db_select_db(DB_DATABASE); if ($self_delivery_id == 0) { $self_delivery_id = $order->info['self_delivery']; } } $date_purchased = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3.$2.$1 $4:$5:$6', $order->info['date_purchased']); $date_purchased = preg_replace('/\\s{2,}/', ' ', $date_purchased); $is_europe = ''; $europe_check_query = tep_db_query("select count(*) as total from setbook_eu." . TABLE_COUNTRIES . " where countries_name like '" . tep_db_input($order->delivery['country']) . "' or countries_ru_name like '" . tep_db_input($order->delivery['country']) . "' or countries_iso_code_2 like '" . tep_db_input($order->delivery['country']) . "' or countries_iso_code_3 like '" . tep_db_input($order->delivery['country']) . "'"); $europe_check = tep_db_fetch_array($europe_check_query); if ($europe_check['total'] > 0) { $is_europe = 'e'; } $order_delivery_country_code = ''; $country_code_info_query = tep_db_query("select countries_iso_code_2 from " . $shop_info['shops_database'] . "." . TABLE_COUNTRIES . " where countries_name = '" . tep_db_input($order->delivery['country']) . "' or countries_ru_name = '" . tep_db_input($order->delivery['country']) . "'"); $country_code_info = tep_db_fetch_array($country_code_info_query); $order_delivery_country_code = $country_code_info['countries_iso_code_2']; if ($order_delivery_country_code == '') { $order_delivery_country = strtolower($order->delivery['country']); $all_countries_file = UPLOAD_DIR . 'csv/all_countries.csv'; $fc = fopen($all_countries_file, 'r'); while ((list($country_name, $country_ru_name, $country_iso_code_2, $country_iso_code_3) = fgetcsv($fc, 40000, ";")) !== FALSE) { $country_name = strtolower($country_name); $country_ru_name = strtolower($country_ru_name); $country_iso_code_3 = strtolower($country_iso_code_3); if ($order_delivery_country == $country_name || $order_delivery_country == $country_ru_name || $order_delivery_country == $country_iso_code_3) { $order_delivery_country_code = $country_iso_code_2; break; } } fclose($fc); } if ($order_delivery_country_code == '') { $fc = fopen($all_countries_file, 'r'); while ((list($country_name, $country_ru_name, $country_iso_code_2, $country_iso_code_3) = fgetcsv($fc, 40000, ";")) !== FALSE) { $country_name = strtolower($country_name); $country_ru_name = strtolower($country_ru_name); if (strpos($country_name, $order_delivery_country) !== false || strpos($country_ru_name, $order_delivery_country) !== false || strpos($country_iso_code_3, $order_delivery_country) !== false) { $order_delivery_country_code = $country_iso_code_2; break; } } fclose($fc); } $common_data = array($insert_id, $date_purchased, $order->info['shops_id'], $order->customer['id'], $order->customer['email_address'], $order->delivery['name'], '', '', $order_payment_id, $order_shipping_id, str_replace(',', '.', $order_shipping_sum), $order->info['currency'], str_replace(',', '.', $order->info['currency_value']), tep_html_entity_decode($order->delivery['state']), tep_html_entity_decode($order->delivery['suburb']), tep_html_entity_decode($order->delivery['city']), $order->delivery['postcode'], tep_html_entity_decode($order->delivery['street_address']), $order->delivery['telephone'], tep_html_entity_decode($order->info['comments']), $self_delivery_id, $order_history_link, str_replace(',', '.', $order_total_sum), str_replace(',', '.', abs($order_discount_sum)), tep_html_entity_decode($order->customer['company']), $order->customer['company_inn'], $order->customer['company_kpp'], $order->customer['company_address_corporate'], $is_europe, $order->info['delivery_transfer_days'], $order->info['code'], $order->delivery['country'], tep_html_entity_decode($order_delivery_country_code), $order->customer['company_corporate']); fputcsvsafe($fp, $common_data, $delimiter); // tep_db_query("update " . TABLE_ORDERS . " set payment_method_class = '" . tep_db_input($order_payment_id) . "', delivery_method_class = '" . tep_db_input($order_shipping_id) . "', delivery_self_address_id = '" . (int)$self_delivery_id . "' where orders_id = '" . (int)$insert_id . "'"); reset($order->products); while (list(, $product) = each($order->products)) { $product_code = (int) str_replace('bbk', '', $product['code']); $common_data = array($product['type'], $product_code, $product['qty'], str_replace(',', '.', $product['final_price']), $product['id'], $product['seller_code'], $product['name'], tep_get_products_name($product['id']), $product['code'], $product['warranty']); fputcsvsafe($fp, $common_data, $delimiter); } fclose($fp); } }
$product_check_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " where products_code = '" . tep_db_input($product_code) . "' and products_types_id = '" . (int) $product_type . "'"); $product_check = tep_db_fetch_array($product_check_query); if ($product_check['products_id'] > 0) { $shops_query = tep_db_query("select shops_database from " . TABLE_SHOPS . " where shops_database <> ''"); while ($shops = tep_db_fetch_array($shops_query)) { tep_db_select_db($shops['shops_database']); tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '" . (int) $product_new_status . "' where products_id = '" . (int) $product_check['products_id'] . "'"); tep_db_query("update " . TABLE_PRODUCTS_INFO . " set products_status = '" . (int) $product_new_status . "' where products_id = '" . (int) $product_check['products_id'] . "'"); if (tep_db_table_exists($shops['shops_database'], 'temp_' . TABLE_PRODUCTS)) { tep_db_query("update temp_" . TABLE_PRODUCTS . " set products_status = '" . (int) $product_new_status . "' where products_id = '" . (int) $product_check['products_id'] . "'"); } if (tep_db_table_exists($shops['shops_database'], 'temp_' . TABLE_PRODUCTS_INFO)) { tep_db_query("update temp_" . TABLE_PRODUCTS_INFO . " set products_status = '" . (int) $product_new_status . "' where products_id = '" . (int) $product_check['products_id'] . "'"); } } tep_db_select_db(DB_DATABASE); // tep_db_query("update " . TABLE_PRODUCTS_TYPES . " set products_last_modified = now() where products_types_id = '1'"); die('OK'); } } die('FAIL'); } elseif ($HTTP_GET_VARS['action'] == 'get_currency_value') { die($currencies->get_value($HTTP_GET_VARS['currency'])); } elseif ($HTTP_GET_VARS['action'] == 'get_product_price') { $product_info_query = tep_db_query("select if(s.specials_new_products_price>'0', s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on (s.products_id = p.products_id and s.status = '1' and s.specials_new_products_price > 0 and s.language_id = '" . (int) $languages_id . "') where p.products_code = 'bbk" . sprintf('%010d', (int) $HTTP_GET_VARS['code']) . "' and p.products_types_id = '" . (int) $HTTP_GET_VARS['type'] . "'"); $product_info = tep_db_fetch_array($product_info_query); die($product_info['products_price']); } $http_r = preg_replace('/^https?:\\/\\//i', '', str_replace('www.', '', $_SERVER['HTTP_REFERER'])); $http_s = preg_replace('/^https?:\\/\\//i', '', str_replace('www.', '', HTTP_SERVER . DIR_WS_CATALOG)); if ($HTTP_GET_VARS['link'] == 'mail') {
while ($series = tep_db_fetch_array($series_query)) { $series_code = 'bsr' . sprintf('%010d', (int) $series['series_id']); tep_db_query("update " . TABLE_SERIES . " set series_code = '" . tep_db_input($series_code) . "' where series_id = '" . (int) $series['series_id'] . "'"); } die('done'); $order_currencies = array('RUR' => 4, 'USD' => 3, 'EUR' => 3); arsort($order_currencies); list($order_currency1) = each($order_currencies); list($order_currency2) = each($order_currencies); list($order_currency3) = each($order_currencies); echo $order_currency1 . ' - ' . $order_currency2 . ' - ' . $order_currency3; die; tep_set_time_limit(300); $shops_query = tep_db_query("select shops_database from " . TABLE_SHOPS . " where shops_database <> ''"); while ($shops = tep_db_fetch_array($shops_query)) { tep_db_select_db($shops['shops_database']); $fp = fopen(UPLOAD_DIR . 'csv/countries_phone_codes.csv', 'r'); while ((list($country_code, $phone_code) = fgetcsv($fp, 16, ";")) !== FALSE) { if (tep_not_null($country_code)) { tep_db_query("update " . TABLE_COUNTRIES . " set countries_phone_code = '" . (int) $phone_code . "' where countries_iso_code_2 = '" . tep_db_input($country_code) . "'"); } } fclose($fp); } die; tep_set_time_limit(300); $fp = fopen(UPLOAD_DIR . 'csv/cities.csv', 'r'); while ((list($city_id, $delivery_days) = fgetcsv($fp, 16, ";")) !== FALSE) { if (tep_not_null($city_id)) { tep_db_query("update " . TABLE_CITIES . " set city_delivery_days = '" . (int) $delivery_days . "' where city_id = '" . tep_db_input($city_id) . "'"); }
function tep_get_shops_countries($shop_id = 0, $listing_status = '') { global $languages_id; $countries = array(); $shops_query = tep_db_query("select shops_id, shops_database, shops_url, shops_ssl from " . TABLE_SHOPS . " where shops_database <> ''" . ($shop_id > 0 ? " and shops_id = '" . (int) $shop_id . "'" : "") . (strlen($listing_status) > 0 ? " and shops_listing_status = '" . (int) $listing_status . "'" : "") . " order by sort_order"); while ($shops = tep_db_fetch_array($shops_query)) { tep_db_select_db($shops['shops_database']); $countries_query = tep_db_query("select countries_id, countries_iso_code_2, countries_iso_code_3, countries_name, countries_ru_name, address_format_id, countries_phone_code from " . TABLE_COUNTRIES . " where language_id = '" . (int) $languages_id . "' order by sort_order, countries_ru_name"); while ($countries_row = tep_db_fetch_array($countries_query)) { $countries_row['countries_ru_name'] = ucwords(strtolower($countries_row['countries_ru_name'])); $countries[$countries_row['countries_iso_code_2']] = array('country_id' => $countries_row['countries_id'], 'country_name' => $countries_row['countries_name'], 'country_ru_name' => $countries_row['countries_ru_name'], 'country_code' => $countries_row['countries_iso_code_2'], 'country_code_3' => $countries_row['countries_iso_code_3'], 'address_format_id' => $countries_row['address_format_id'], 'country_code' => $countries_row['countries_iso_code_2'], 'shop_id' => $shops['shops_id'], 'shop_url' => $shops['shops_url'], 'shop_ssl' => $shops['shops_ssl'], 'shop_db' => $shops['shops_database'], 'phone_code' => $countries_row['countries_phone_code'], 'flag' => tep_image(DIR_WS_ICONS . 'flags/' . strtolower($countries_row['countries_iso_code_2']) . '.gif')); if ($countries_row['countries_iso_code_2'] == 'DE') { $countries['EU'] = array('country_id' => '0', 'country_name' => 'European Union', 'country_ru_name' => 'Европейский Союз', 'country_code' => 'EU', 'country_code_3' => 'EUR', 'address_format_id' => $countries_row['address_format_id'], 'shop_id' => $shops['shops_id'], 'shop_url' => $shops['shops_url'], 'shop_db' => $shops['shops_database'], 'phone_code' => '', 'flag' => tep_image(DIR_WS_ICONS . 'flags/' . strtolower('EU') . '.gif')); } } } tep_db_select_db(DB_DATABASE); return $countries; }
tep_db_query("set character_set_results='cp1251'"); tep_db_query("set collation_connection='cp1251_general_ci'"); tep_db_query("set names cp1251"); } $domain_info_query = tep_db_query("select * from " . TABLE_SHOPS . " where shops_url = '" . tep_db_input(HTTP_SERVER) . "'"); $domain_info = tep_db_fetch_array($domain_info_query); list($default_currency) = explode(',', $domain_info['shops_currency']); define('DEFAULT_CURRENCY', $default_currency); define('SHOP_ID', $domain_info['shops_id']); define('SHOP_DESCRIPTION', $domain_info['shops_description']); define('DOMAIN_ZONE', substr($domain_info['shops_url'], strrpos($domain_info['shops_url'], '.') + 1)); define('SHOP_PREFIX', $domain_info['shops_prefix']); define('DIR_WS_CATALOG_TEMPLATES', DIR_WS_CATALOG . 'includes/templates/' . $domain_info['shops_templates_dir'] . '/'); define('DIR_FS_CATALOG_TEMPLATES', DIR_FS_CATALOG . 'includes/templates/' . $domain_info['shops_templates_dir'] . '/'); define('EMAIL_USE_HTML', $domain_info['shops_email_use_html'] == '1' ? 'true' : 'false'); tep_db_select_db($domain_info['shops_database']); $shop_ssl_status = 'off'; if (!empty($domain_info['shops_ssl']) && $domain_info['shops_ssl'] != $domain_info['shops_url']) { $shop_ssl_status = 'on'; } define('SHOP_SSL_STATUS', $shop_ssl_status); define('ENABLE_SSL', SHOP_SSL_STATUS == 'on' ? true : false); // set application wide parameters $configuration_query = tep_db_query("select configuration_key, configuration_value from " . TABLE_CONFIGURATION); while ($configuration = tep_db_fetch_array($configuration_query)) { define($configuration['configuration_key'], $configuration['configuration_value']); } if (preg_match_all('/([^dar]win[dows]*)[\\s]?([0-9a-z]*)[\\w\\s]?([a-z0-9.]*)/i', $_SERVER['SERVER_SOFTWARE'], $match) || preg_match('/(68[k0]{1,3})|(ppc mac os x)|([p\\S]{1,5}pc)|(darwin)/i', $_SERVER['SERVER_SOFTWARE'], $match)) { define('EMAIL_TRANSPORT', 'smtp'); define('EMAIL_LINEFEED', "\r\n"); } else {
<?php $server = $_POST['db_host']; $port = $_POST['db_port']; $username = $_POST['db_username']; $password = $_POST['db_password']; $database = $_POST['db_name']; tep_db_connect($server . (strlen($port) > 0 ? ':' . $port : ''), $username, $password); tep_db_select_db($database);