function cw_import_users($xcart_conf) { cw_load('crypt', 'user'); extract($xcart_conf); extract(cw_vers_diff_attr($conn)); fout("<br /><br />Import of Users...<br />"); if ($clean_users) { $cw_admins = cw_query("select * from cw_customers u left join cw_customers_addresses a\n\t\t\ton u.customer_id=a.customer_id and a.main=1 where u.usertype='A'"); db_query("TRUNCATE TABLE cw_customers"); db_query("TRUNCATE TABLE cw_customers_system_info"); db_query("TRUNCATE TABLE cw_customers_customer_info"); } $users_per_run = 500; global $page; if (!isset($page)) { $page = 1; } $users_offset = $users_per_run * ($page - 1); $users_count = $users_per_run; $where_ids_range = "WHERE id > 58965"; $users = cw_query("select * from xcart_customers {$where_ids_range} order by usertype in ('P','A') desc, login=email desc limit {$users_offset}, {$users_count}", $conn); $users_count = count($users); $processed_customers = array(); $i = 1; $em = array(); $user_ind = array(); foreach ($users as $k => $v) { $v['password'] = cw_user_get_hashed_password(text_decrypt($v['password'], $blowfish_key)); extract($v); $membership_id = $membershipid; //$email=$login; if ($uwithid) { $customer_id = $id; } else { $customer_id = $i++; } $processed_customers[] = $id; $language = strtoupper($language); if (in_array($email, $em)) { $log = str_replace(" ", "-", $login); $email = "{$log}-{$email}"; $users[$k]['email'] = "{$log}-{$email}"; } $em[] = $email; if ($usertype == 'A' || $usertype == 'P') { $usertype = 'A'; } else { $usertype = 'C'; } $arr = compact('customer_id', 'usertype', 'password', 'email', 'status', 'membership_id', 'language'); $usrs[$customer_id] = $arr; cw_array2insert_esc('cw_customers', $arr); $creation_customer_id = $customer_id; $creation_date = $first_login; //time(); $modification_customer_id = $customer_id; $modification_date = time(); //$last_login=time(); - already extracted $arr = compact('customer_id', 'creation_customer_id', 'creation_date', 'modification_customer_id', 'modification_date', 'last_login'); cw_array2insert_esc('cw_customers_system_info', $arr); $web_user = 1; cw_array2insert_esc('cw_customers_customer_info', compact('customer_id', 'web_user')); $ul[] = $email; $companies[$customer_id] = $company; $user_ind[$login] = $customer_id; $users[$k]['userid'] = $customer_id; fout(); } fout("<br /><br />Import of an Address Book...<br />"); if ($clean_users) { db_query("TRUNCATE TABLE cw_customers_addresses"); } //$i=10000; //address book id start if ($withab) { $addresses = cw_query("select * from xcart_address_book where userid in ('" . implode("','", $processed_customers) . "')", $conn); } else { foreach ($users as $v) { extract($v); if ($b_firstname != '' || 1) { //$id=$i++; $firstname = $b_firstname; $lastname = $b_lastname; $address = $b_address; $city = $b_city; $county = $b_county; $state = $b_state; $country = $b_country; $zipcode = $b_zipcode; $default_b = 'Y'; $default_s = 'N'; $addresses[] = compact('id', 'userid', 'firstname', 'lastname', 'address', 'city', 'county', 'state', 'country', 'zipcode', 'default_b', 'default_s', 'phone', 'fax'); } if ($s_firstname != '' || 1) { //$id=$i++; $firstname = $s_firstname; $lastname = $s_lastname; $address = $s_address; $city = $s_city; $county = $s_county; $state = $s_state; $country = $s_country; $zipcode = $s_zipcode; $default_b = 'N'; $default_s = 'Y'; $addresses[] = compact('id', 'userid', 'firstname', 'lastname', 'address', 'city', 'county', 'state', 'country', 'zipcode', 'default_b', 'default_s', 'phone', 'fax'); } } } unset($users); $cust_addr_ids = array(); foreach ($addresses as $v) { extract($v); $address_id = $id; $customer_id = $userid; $region = $county; $main = $default_b == 'Y' ? 1 : 0; $current = $default_s == 'Y' ? 1 : 0; if (isset($companies[$customer_id])) { $company = $companies[$customer_id]; } else { $company = ''; } $arr = compact('address_id', 'customer_id', 'main', 'current', 'firstname', 'lastname', 'address', 'city', 'state', 'country', 'region', 'zipcode', 'phone', 'fax', 'company'); cw_array2insert_esc('cw_customers_addresses', $arr); $cust_addr_ids[$customer_id] = array(); if ($main) { $cust_addr_ids[$customer_id]['main'] = $address_id; } if ($current) { $cust_addr_ids[$customer_id]['current'] = $address_id; } fout(); } unset($addresses); if (isset($cw_admins) && is_array($cw_admins) && !empty($cw_admins)) { $uid = intval(cw_query_first_cell("select customer_id from cw_customers order by customer_id desc limit 1")) + 1; foreach ($cw_admins as $v) { if (!in_array($v['email'], $ul)) { $v['customer_id'] = $uid; extract($v); compact('customer_id', 'usertype', 'password', 'email', 'status', 'membership_id', 'language'); cw_array2insert_esc('cw_customers', $v); $ul[] = $v['email']; $creation_date = time(); $creation_customer_id = $customer_id; $modification_customer_id = $customer_id; $modification_date = time(); $last_login = time(); $arr = compact('customer_id', 'creation_customer_id', 'creation_date', 'modification_customer_id', 'modification_date', 'last_login'); cw_array2insert_esc('cw_customers_system_info', $arr); $web_user = 1; cw_array2insert_esc('cw_customers_customer_info', compact('customer_id', 'web_user')); if (!isset($firstname) || ($firstname = '')) { $firstname = 'Admin'; } if (!isset($lastname) || ($lastname = '')) { $lastname = 'Admin'; } $main = 1; $arr = compact('customer_id', 'main', 'current', 'firstname', 'lastname', 'address', 'state', 'country', 'region', 'zipcode', 'phone', 'fax', 'company'); cw_array2insert_esc('cw_customers_addresses', $arr); $uid++; } } } // wishlists /* $wishlist=cw_query("select * from xcart_wishlist",$conn); db_query ("TRUNCATE TABLE cw_wishlist"); foreach ($wishlist as $v) { extract($v); if ($uwithid) $customer_id=$userid; else $customer_id=$user_ind[$login]; $wishlist_id=$wishlistid; $product_id=$productid; $arr=compact('wishlist_id','customer_id','product_id','amount','amount_purchased','options','event_id','object'); cw_array2insert_esc ('cw_wishlist',$arr); fout(); } */ fout("<br /><br />Import of Orders & Invoices...<br />"); //print_r($cust_addr_ids); // orders, invoices if ($clean_docs) { db_query("TRUNCATE TABLE cw_docs"); db_query("TRUNCATE TABLE cw_docs_info"); db_query("TRUNCATE TABLE cw_docs_settings"); db_query("TRUNCATE TABLE cw_docs_user_info"); } $orders_per_run = 250; $orders_offset = $orders_per_run * ($page - 1); $orders_count = $orders_per_run; $where_orderids_range = "WHERE orderid > 63375"; $orders = cw_query("select * from xcart_orders {$where_orderids_range} limit {$orders_offset}, {$orders_count}", $conn); $orders_count = count($orders); $doc_ids = array(); $processed_orders = array(); //$doc_id=$doc_info_id=1; $type = "O"; //$_display_id=$_display_doc_id=1; foreach ($orders as $v) { extract($v); //$doc_ids[$orderid]=$doc_id; $doc_id = $orderid; $processed_orders[] = $orderid; $doc_info_id = $doc_id; $doc_ids[$orderid] = $orderid; $year = date("Y", $date); $display_id = "SW " . $doc_id; $display_doc_id = $doc_id; $arr = compact('doc_id', 'doc_info_id', 'type', 'display_id', 'display_doc_id', 'year', 'date', 'status'); cw_array2insert_esc('cw_docs', $arr); $payment_id = $paymentid; $display_total = $total; $display_subtotal = $subtotal; $shipping_id = $shippingid; $details = cw_crypt_text(text_decrypt($details, $blowfish_key)); $applied_taxes = $taxes_applied; $shipping_id = $shippingid; $display_shipping_cost = $shipping_cost; $shipping_label = isset($shipping) ? $shipping : ''; $payment_label = $payment_method; $discount_value = $discount; $arr = compact('doc_info_id', 'total', 'display_total', 'subtotal', 'display_subtotal', 'extra', 'details', 'payment_id', 'shipping_id', 'shipping_cost', 'notes', 'tax', 'applied_taxes', 'customer_notes', 'payment_label', 'payment_surcharge', 'shipping_id', 'shipping_cost', 'display_shipping_cost', 'shipping_label', 'giftcert_discount', 'coupon', 'coupon_discount', 'discount', 'discount_value'); cw_array2insert_esc('cw_docs_info', $arr); $show_price = 0; $arr = compact('doc_info_id', 'show_price'); cw_array2insert_esc('cw_docs_settings', $arr); if ($uwithid) { $customer_id = $userid; } else { $customer_id = $user_ind[$login]; } $cust_inf = cw_query_first("select c.usertype, c.email from cw_customers where customer_id='{$customer_id}'"); $usertype = $cust_inf['usertype']; $email = $cust_inf['email']; $main_address_id = cw_query_first_cell("select address_id from cw_customers_addresses where customer_id='{$customer_id}' and main=1"); $current_address_id = cw_query_first_cell("select address_id from cw_customers_addresses where customer_id='{$customer_id}' and current=1"); /* $usertype=$usrs[$customer_id]['usertype']; if (isset($cust_addr_ids[$customer_id]['main'])) $main_address_id=$cust_addr_ids[$customer_id]['main']; else $main_address_id=0; if (isset($cust_addr_ids[$customer_id]['current'])) $current_address_id=$cust_addr_ids[$customer_id]['current']; else $current_address_id=0; $email=$usrs[$customer_id]['email']; */ $arr = compact('doc_info_id', 'customer_id', 'usertype', 'main_address_id', 'current_address_id', 'email', 'tax_number', 'tax_exempt'); cw_array2insert_esc('cw_docs_user_info', $arr); $display_id++; $display_doc_id++; $doc_id++; $doc_info_id++; fout(); } unset($orders); unset($usrs); if ($clean_docs) { db_query("TRUNCATE TABLE cw_docs_items"); } $details = cw_query("select * from xcart_order_details where orderid in ('" . implode("','", $processed_orders) . "')", $conn); foreach ($details as $v) { extract($v); $item_id = $itemid; $doc_id = $doc_ids[$orderid]; $product_id = $productid; if ($uwithid) { $warehouse_customer_id = $provider; } else { $warehouse_customer_id = $user_ind[$provider]; } $arr = compact('item_id', 'doc_id', 'product_id', 'productcode', 'product', 'product_options', 'price', 'amount', 'extra_data', 'warehouse_customer_id'); cw_array2insert_esc('cw_docs_items', $arr); } if ($users_count || $orders_count) { return $page + 1; } else { return 0; } }
function cw_user_change_password($customer_id) { global $tables, $smarty, $config; cw_load('mail', 'crypt'); $full_pwd = md5(uniqid(rand())); # 32 chars $from_chr = rand(0, 24); # any 8 chars $new_password = substr($full_pwd, $from_chr, 8); $crypted = addslashes(cw_crypt_text($new_password)); db_query("update {$tables['customers']} set password='******' where customer_id='{$customer}'"); $smarty->assign('new_password', $new_password); $user_email = cw_query_first_cell("select email from {$tables['customers']} where customer_id='{$customer_id}'"); cw_call('cw_send_mail', array($config['Company']['users_department'], $user_email, 'mail/password_modified_subj.tpl', 'mail/password_modified.tpl')); }
} foreach ($doc_ids as $oid) { if (!is_numeric($oid)) { cw_header_location("index.php?target=error_message&error=access_denied&id=8"); } } $smarty->assign('usertype_layout', 'A'); $smarty->assign('doc_id', $doc_id); if ((!$doc_data['doc_id'] || $doc_data['type'] != $docs_type) && $mode != 'edit') { cw_header_location('index.php?target=' . $target); } if (in_array($current_area, array('A', 'P', 'V')) && $action == "status_change") { # Update order $query_data = array('tracking' => $request_prepared['tracking'], 'ship_time' => $request_prepared['ship_time'], 'customer_notes' => $request_prepared['customer_notes'], 'notes' => $request_prepared['notes']); if (isset($details)) { $query_data['details'] = cw_crypt_text($details); } cw_doc_update_info($doc_data['doc_info_id'], $query_data); cw_doc_update_quotes($doc_id, $quote); cw_call('cw_doc_change_status', array($doc_id, $status)); $top_message['content'] = cw_get_langvar_by_name('txt_order_has_been_changed'); cw_header_location("index.php?target={$target}&mode=details&doc_id=" . $doc_id); } if (in_array($current_area, array('A', 'P')) && $action == "delete") { cw_call('cw_doc_delete', array($doc_id)); cw_header_location("index.php?target={$target}" . $query_string); } $smarty->assign('main', 'document'); $predefined_lng_variables[] = 'lbl_doc_info_' . $doc_data['type']; if ($mode == 'edit' && $current_area == 'A') { cw_include('include/orders/order_edit.php');
function cw_doc_place_order($params, $return = null) { extract($params); global $cart, $discount_coupon, $smarty, $config, $addons, $salesman, $adv_campaign_id, $salesman_click_id; global $tables, $to_customer; global $wlid; global $app_main_dir, $REMOTE_ADDR, $PROXY_IP, $CLIENT_IP, $add_to_cart_time; $mintime = 10; cw_load('web'); cw_lock('cw_doc_place_order'); $doc_ids = array(); foreach ($cart['orders'] as $cart_order_idx => $current_order) { # $extra - one serialized field in doc details # use $extra as storage of details which will not be used for orders search or aggregate # $extras - key=>value pairs in doc extras table # use $extras for scalar values which can be used in SQL queries $extra = cw_event('on_place_order_extra', array($current_order)); $extra['additional_fields'] = $userinfo['additional_fields']; if (!empty($current_order['info']['shipping_no_offer'])) { $extra['shipping_no_offer'] = $current_order['info']['shipping_no_offer']; } $extras = cw_event('on_place_order_extras', array($current_order)); //$extras['ip'] = $CLIENT_IP; //$extras['proxy_ip'] = $PROXY_IP; # kornev, each doc has got the same attributes as the other elements, like products # kornev, the attributes should be defined in the params by the pre function $doc_id = cw_doc_create_empty($order_type, array('warehouse_customer_id' => $current_order['warehouse_customer_id']), $params['prefix'], array(), $return['attributes']); $cart['orders'][$cart_order_idx]['created_doc_id'] = $doc_id; $extra['tax_info'] = array('display_taxed_order_totals' => $config['Taxes']['display_taxed_order_totals'], 'display_cart_products_tax_rates' => $config['Taxes']['display_cart_products_tax_rates'] == "Y", 'taxed_subtotal' => $current_order['display_subtotal'], 'taxed_discounted_subtotal' => $current_order['display_discounted_subtotal'], 'taxed_shipping' => $current_order['display_shipping_cost']); $giftcert_discount = $current_order['info']['giftcert_discount']; $applied_taxes = addslashes(serialize($current_order['info']['taxes'])); $discount_coupon = $current_order['coupon']; if (!empty($current_order['coupon'])) { $current_order['coupon'] = cw_query_first_cell("SELECT coupon_type FROM {$tables['discount_coupons']} WHERE coupon='" . addslashes($current_order['coupon']) . "'") . "``" . $current_order['coupon']; } $current_order['userinfo'] = $userinfo; $current_order['new'] = true; // Flag can be used in cw_doc_update to differ just placed empty doc from update of existing doc $current_order['info']['shipping_id'] = $cart['info']['shipping_id']; $current_order['info']['payment_id'] = $cart['info']['payment_id']; $current_order['info']['payment_label'] = $cart['info']['payment_label']; $current_order['info']['quote_doc_id'] = isset($cart['info']['quote_doc_id']) ? $cart['info']['quote_doc_id'] : null; $current_order['info']['details'] = addslashes(cw_crypt_text($order_details)); $current_order['info']['customer_notes'] = addslashes($customer_notes); if ($config['Appearance']['show_cart_summary'] == 'Y') { $current_order['info']['shipping_id'] = $cart['info']['shipping_arr'][$current_order['warehouse_customer_id']]; } $current_order['info']['extra'] = $extra; $current_order['info']['extras'] = $_extras; $current_order['status'] = $order_status; $doc_info = cw_doc_get_basic_info($doc_id); $current_order['info']['doc_info_id'] = $doc_info['doc_info_id']; $current_order['info']['warehouse_customer_id'] = $current_order['warehouse_customer_id']; $current_order['userinfo']['main_address']['address_id'] = $doc_info['main_address_id']; $current_order['userinfo']['current_address']['address_id'] = $doc_info['current_address_id']; cw_log_add('doc_placed', array('doc_id' => $doc_id, 'current_order' => $current_order, 'cart' => $cart)); cw_call('cw_doc_update', array($doc_id, $current_order)); $doc_ids[] = $doc_id; $order = cw_call('cw_doc_get', array($doc_id)); if ($discount_coupon) { // artem, TODO: no SQL $_per_user = cw_query_first_cell("SELECT per_user FROM {$tables['discount_coupons']} WHERE coupon='{$discount_coupon}' LIMIT 1"); if ($_per_user == "Y") { $_need_to_update = cw_query_first_cell("SELECT COUNT(*) FROM {$tables['discount_coupons_login']} WHERE coupon='{$discount_coupon}' AND customer_id='" . intval($userinfo['customer_id']) . "' LIMIT 1"); if ($_need_to_update > 0) { db_query("UPDATE {$tables['discount_coupons_login']} SET times_used=times_used+1 WHERE coupon='{$discount_coupon}' AND customer_id='" . intval($userinfo['customer_id']) . "'"); } else { db_query("INSERT INTO {$tables['discount_coupons_login']} (coupon, customer_id, times_used) VALUES ('{$discount_coupon}', '" . intval($userinfo['customer_id']) . "', '1')"); } } else { db_query("UPDATE {$tables['discount_coupons']} SET times_used=times_used+1 WHERE coupon='{$discount_coupon}'"); db_query("UPDATE {$tables['discount_coupons']} SET status='U' WHERE coupon='{$discount_coupon}' AND times_used=times"); } $discount_coupon = ""; } # Mail template processing $admin_notify = $order_status == "Q" && $config['Email']['enable_order_notif'] == "Y" || $order_status == "I" && $config['Email']['enable_init_order_notif'] == "Y"; $customer_notify = $order_status == "Q" || $order_status == "I" && $config['Email']['enable_init_order_notif_customer'] == "Y"; $doc_data = $doc_data_customer = cw_call('cw_doc_get', array($doc_id)); if ($customer_notify) { $to_customer = $userinfo['language'] ? $userinfo['language'] : $config['default_customer_language']; $doc_data_customer['products'] = cw_doc_translate_products($doc_data['products'], $to_customer); $smarty->assign('doc_data', $doc_data_customer); if ($doc_data['info']['layout_id']) { $layout = cw_web_get_layout_by_id($doc_data['info']['layout_id']); } else { $layout = cw_call('cw_web_get_layout', array('docs_' . $doc_data['type']), true); } $smarty->assign('layout_data', $layout); $smarty->assign('info', $doc_data['info']); $smarty->assign('products', $doc_data_customer['products']); $smarty->assign('order', $doc_data); $smarty->assign('doc', $doc_data); $smarty->assign('is_email_invoice', 'Y'); cw_call('cw_send_mail', array($config['Company']['orders_department'], $userinfo['email'], 'mail/docs/customer_subj.tpl', 'mail/docs/customer.tpl', null, false, true)); $smarty->assign('is_email_invoice', 'N'); } if ($admin_notify) { # Notify orders department by email $smarty->assign('doc_data', $doc_data); $smarty->assign('usertype_layout', 'A'); $smarty->assign('is_email_invoice', 'Y'); cw_call('cw_send_mail', array($userinfo['email'], $config['Company']['orders_department'], 'mail/docs/admin_subj.tpl', 'mail/docs/admin.tpl', $config['default_admin_language'], true)); $smarty->assign('is_email_invoice', 'N'); $smarty->assign('usertype_layout', ''); # Notify warehouse (or warehouses) by email if ($config['Email']['send_notifications_to_warehouse'] == "Y") { $pr_result = cw_query_first("SELECT email, language FROM {$tables['customers']} WHERE customer_id='{$current_order['warehouse_customer_id']}'"); $prov_email = $pr_result['email']; if ($prov_email != $config['Company']['orders_department']) { $to_customer = $pr_result['language']; if (empty($to_customer)) { $to_customer = $config['default_admin_language']; } $smarty->assign('is_email_invoice', 'Y'); cw_call('cw_send_mail', array($userinfo['email'], $prov_email, 'mail/docs/admin_subj.tpl', 'mail/docs/admin.tpl')); $smarty->assign('is_email_invoice', 'N'); } } } if ($addons['survey'] && AREA_TYPE == 'C') { cw_load('surveys'); cw_check_surveys_events("OPL", $doc_data); } //cw_call('cw_doc_save_history_totals_by_customer', array(array(intval($userinfo['customer_id'])))); cw_call('cw_doc_save_history_categories', array(array($doc_id))); cw_call('cw_doc_save_history_attributes', array(array($doc_id))); } # Send notifications to orders department and warehouses when product amount in stock is low foreach ($cart['products'] as $product) { if (!empty($product['distribution']) && $addons['egoods']) { continue; } # kornev, TOFIX if ($addons['product_options'] && $product['extra_data']['product_options']) { $avail_now = cw_get_options_amount($product['extra_data']['product_options'], $product['product_id']); } else { $avail_now = cw_query_first_cell("SELECT avail FROM {$tables['products_warehouses_amount']} WHERE product_id='" . $product['product_id'] . "' AND warehouse_customer_id ='" . $product['warehouse_customer_id'] . "'"); } if ($product['low_avail_limit'] >= $avail_now && $config['Email']['eml_lowlimit_warning'] == 'Y') { # Mail template processing $product['avail'] = $avail_now; $smarty->assign('product', $product); cw_call('cw_send_mail', array($config['Company']['orders_department'], $config['Company']['orders_department'], 'mail/lowlimit/subj.tpl', 'mail/lowlimit/body.tpl')); $pr_result = cw_query_first("SELECT email, language FROM {$tables['customers']} WHERE customer_id='" . $product['warehouse_customer_id'] . "'"); } } cw_unlock('cw_doc_place_order'); return $doc_ids; }