public static function apiUpdateOrder($order, $response) { if (!defined('ORDER_MANAGEMENT')) { define('ORDER_MANAGEMENT', true); } if (!empty($order['status'])) { $statuses = fn_get_statuses(STATUSES_ORDER, false, true); if (!isset($statuses[$order['status']])) { $response->addError('ERROR_OBJECT_UPDATE', str_replace('[object]', 'orders', __('twgadmin_wrong_api_object_data'))); } else { fn_change_order_status($order['order_id'], $order['status']); } } $cart = array(); fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(array(), array(), false, 'C'); fn_form_cart($order['order_id'], $cart, $customer_auth); $cart['order_id'] = $order['order_id']; // update only profile data $profile_data = fn_check_table_fields($order, 'user_profiles'); $cart['user_data'] = fn_array_merge($cart['user_data'], $profile_data); $cart['user_data'] = fn_array_merge($cart['user_data'], $order); fn_calculate_cart_content($cart, $customer_auth, 'A', true, 'I'); if (!empty($order['details'])) { db_query('UPDATE ?:orders SET details = ?s WHERE order_id = ?i', $order['details'], $order['order_id']); } if (!empty($order['notes'])) { $cart['notes'] = $order['notes']; } fn_update_payment_surcharge($cart, $customer_auth); list($order_id, $process_payment) = fn_place_order($cart, $customer_auth, 'save'); return array($order_id, $process_payment); }
/** * Setup complete action * * @param array $params Request variables * * @return bool Always true */ public function actionComplete($params = array()) { $validator = new Validator(); $app = App::instance(); fn_define('CART_LANGUAGE', $app->getCurrentLangCode()); fn_define('DESCR_SL', $app->getCurrentLangCode()); $database = $app->getFromStorage('database_settings'); if (!empty($database)) { $result = $validator->isMysqlSettingsValid($database['host'], $database['name'], $database['user'], $database['password'], $database['table_prefix'], $database['database_backend'], false); if ($result) { // Delete installer after store was installed. fn_rm(Registry::get('config.dir.root') . '/install'); session_destroy(); $this->_prepareHttpData(); Session::init($params); $user_data = array('user_id' => 1, 'user_type' => 'A', 'area' => 'A', 'login' => 'admin', 'is_root' => 'Y', 'company_id' => 0); $_SESSION['auth'] = fn_fill_auth($user_data, array(), false, 'A'); if (is_file(Registry::get('config.dir.root') . '/install/index.php')) { $_SESSION['notifications']['installer'] = array('type' => 'W', 'title' => 'warning', 'message' => 'delete_install_folder', 'message_state' => 'S', 'new' => true, 'extra' => '', 'init_message' => true); } $redirect_url = Registry::get('config.http_location') . '/' . Registry::get('config.admin_index') . '?welcome'; fn_redirect($redirect_url); } } fn_redirect('install/index.php'); return true; }
function fn_exim_google_export_format_price($product_price, $product_id = 0) { static $auth; if (empty($auth)) { $auth = fn_fill_auth(); } $product = fn_get_product_data($product_id, $auth, CART_LANGUAGE, false, false, false, false, false, false, false); fn_promotion_apply('catalog', $product, $auth); $_discount = 0; if (!empty($product['discount'])) { $_discount = $product['discount']; } return fn_format_price($product_price - $_discount, CART_PRIMARY_CURRENCY, null, false); }
function fn_form_cart($order_id, &$cart, &$auth) { $order_info = fn_get_order_info($order_id, false, false); if (empty($order_info)) { fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('order'))), '', '404'); return false; } // Fill the cart foreach ($order_info['products'] as $_id => $item) { $_item = array($item['product_id'] => array('amount' => $item['amount'], 'product_options' => !empty($item['extra']['product_options']) ? $item['extra']['product_options'] : array(), 'price' => $item['original_price'], 'stored_discount' => 'Y', 'stored_price' => 'Y', 'discount' => !empty($item['extra']['discount']) ? $item['extra']['discount'] : 0, 'original_amount' => $item['amount'], 'original_product_data' => array('cart_id' => $_id, 'amount' => $item['amount']))); if (isset($item['extra'])) { $_item[$item['product_id']]['extra'] = $item['extra']; } fn_add_product_to_cart($_item, $cart, $auth); } // Workaround for the add-ons that do not add a product to cart unless the parent product is already added. if (count($order_info['products']) > count($cart['products'])) { foreach ($order_info['products'] as $_id => $item) { if (empty($cart['products'][$_id])) { $_item = array($item['product_id'] => array('amount' => $item['amount'], 'product_options' => !empty($item['extra']['product_options']) ? $item['extra']['product_options'] : array(), 'price' => $item['original_price'], 'stored_discount' => 'Y', 'stored_price' => 'Y', 'discount' => !empty($item['extra']['discount']) ? $item['extra']['discount'] : 0, 'original_amount' => $item['amount'], 'original_product_data' => array('cart_id' => $_id, 'amount' => $item['amount']))); if (isset($item['extra'])) { $_item[$item['product_id']]['extra'] = $item['extra']; } fn_add_product_to_cart($_item, $cart, $auth); } } } // Restore custom files $dir_path = 'order_data/' . $order_id; if (Storage::instance('custom_files')->isExist($dir_path)) { Storage::instance('custom_files')->copy($dir_path, 'sess_data'); } $cart['payment_id'] = $order_info['payment_id']; $cart['stored_taxes'] = 'Y'; $cart['stored_discount'] = 'Y'; $cart['taxes'] = $order_info['taxes']; $cart['promotions'] = !empty($order_info['promotions']) ? $order_info['promotions'] : array(); $cart['shipping'] = !empty($order_info['shipping']) ? $order_info['shipping'] : array(); $cart['stored_shipping'] = array(); foreach ($cart['shipping'] as $sh_id => $v) { if (!empty($v['rates'])) { $cart['stored_shipping'][$sh_id] = array_sum($v['rates']); } } if (!empty($order_info['product_groups'])) { $cart['product_groups'] = $order_info['product_groups']; foreach ($order_info['product_groups'] as $group) { if (!empty($group['chosen_shippings'])) { foreach ($group['chosen_shippings'] as $key => $chosen_shipping) { foreach ($group['shippings'] as $shipping_id => $shipping) { if ($shipping_id == $chosen_shipping['shipping_id']) { $cart['chosen_shipping'][$chosen_shipping['group_key']] = $shipping_id; } } } } } } else { $cart['product_groups'] = array(); } $cart['order_timestamp'] = $order_info['timestamp']; $cart['notes'] = $order_info['notes']; $cart['details'] = $order_info['details']; $cart['payment_info'] = @$order_info['payment_info']; $cart['profile_id'] = $order_info['profile_id']; // Add order discount if (floatval($order_info['subtotal_discount'])) { $cart['stored_subtotal_discount'] = 'Y'; $cart['subtotal_discount'] = $cart['original_subtotal_discount'] = fn_format_price($order_info['subtotal_discount']); } // Fill the cart with the coupons if (!empty($order_info['coupons'])) { $cart['coupons'] = $order_info['coupons']; } // Set the customer if exists $_data = array(); if (!empty($order_info['user_id'])) { $_data = db_get_row("SELECT user_id, user_login as login FROM ?:users WHERE user_id = ?i", $order_info['user_id']); } $auth = fn_fill_auth($_data, array(), false, 'C'); $auth['tax_exempt'] = $order_info['tax_exempt']; // Fill customer info $cart['user_data'] = fn_array_merge(fn_check_table_fields($order_info, 'users'), fn_check_table_fields($order_info, 'user_profiles')); if (!empty($order_info['fields'])) { $cart['user_data']['fields'] = $order_info['fields']; } fn_add_user_data_descriptions($cart['user_data']); fn_set_hook('form_cart', $order_info, $cart, $auth); return true; }
function fn_process_paypal_ipn($order_id, $data) { $order_info = fn_get_order_info($order_id); if (!empty($order_info) && !empty($data['txn_id']) && (empty($order_info['payment_info']['txn_id']) || $data['payment_status'] != 'Completed' || $data['payment_status'] == 'Completed' && $order_info['payment_info']['txn_id'] !== $data['txn_id'])) { //Can't check refund transactions. if (isset($data['txn_type']) && !fn_validate_paypal_order_info($data, $order_info)) { return false; } $pp_settings = fn_get_paypal_settings(); fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(array(), array(), false, 'C'); fn_form_cart($order_id, $cart, $customer_auth); if ($pp_settings['override_customer_info'] == 'Y') { $cart['user_data'] = fn_paypal_get_customer_info($data); } $cart['order_id'] = $order_id; $cart['payment_info'] = $order_info['payment_info']; $cart['payment_info']['protection_eligibility'] = !empty($data['protection_eligibility']) ? $data['protection_eligibility'] : ''; $cart['payment_id'] = $order_info['payment_id']; if (!empty($data['memo'])) { //Save customer notes $cart['notes'] = $data['memo']; } if ($data['payment_status'] == 'Completed') { //save uniq ipn id to avoid double ipn processing $cart['payment_info']['txn_id'] = $data['txn_id']; } if (!empty($data['payer_email'])) { $cart['payment_info']['customer_email'] = $data['payer_email']; } if (!empty($data['payer_id'])) { $cart['payment_info']['client_id'] = $data['payer_id']; } //Sometimes, for some reasons cart_id in product products calculated incorrectle, so we need recalculate it. $cart['change_cart_products'] = true; fn_calculate_cart_content($cart, $customer_auth); $cart['payment_info']['order_status'] = $pp_settings['pp_statuses'][strtolower($data['payment_status'])]; list($order_id, ) = fn_update_order($cart, $order_id); if ($order_id) { fn_change_order_status($order_id, $pp_settings['pp_statuses'][strtolower($data['payment_status'])]); if (fn_allowed_for('MULTIVENDOR')) { $child_order_ids = db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $order_id); if (!empty($child_order_ids)) { foreach ($child_order_ids as $child_order_id) { fn_update_order_payment_info($child_order_id, $cart['payment_info']); } } } } return true; } }
function fn_qwintry_fn_form_cart($order_info) { fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(); fn_form_cart($order_info['order_id'], $cart, $customer_auth, array()); list($cart_products, ) = fn_calculate_cart_content($cart, $customer_auth, 'E', false, 'F', false); if (!empty($cart_products)) { foreach ($cart_products as $k => $v) { fn_gather_additional_product_data($cart_products[$k], false, false, true, false); } } $cart['products'] = $cart_products; return $cart; }
/** * Log in user using only user id * return 0 - we can't find user with provided user_id * return 1 - user was successfully loggined * return 2 - user disabled * */ function fn_login_user($user_id = '') { $udata = array(); $auth =& $_SESSION['auth']; $condition = ''; $result = LOGIN_STATUS_USER_NOT_FOUND; fn_set_hook('login_user_pre', $user_id, $udata, $auth, $condition); if (!empty($user_id)) { if (fn_allowed_for('ULTIMATE')) { if (Registry::get('settings.Stores.share_users') == 'N' && AREA != 'A') { $condition .= fn_get_company_condition('?:users.company_id'); } } $udata = db_get_row("SELECT * FROM ?:users WHERE user_id = ?i AND status = 'A'" . $condition, $user_id); if (empty($udata)) { $udata = db_get_row("SELECT * FROM ?:users WHERE user_id = ?i AND user_type IN ('A', 'V', 'P')", $user_id); } unset($_SESSION['status']); $auth = fn_fill_auth($udata, $auth); if (!empty($udata)) { fn_set_hook('sucess_user_login', $udata, $auth); if (AREA == 'C') { if ($cu_id = fn_get_session_data('cu_id')) { fn_clear_cart($cart); fn_save_cart_content($cart, $cu_id, 'C', 'U'); fn_delete_session_data('cu_id'); } fn_init_user_session_data($_SESSION, $udata['user_id']); } // Set last login time db_query("UPDATE ?:users SET ?u WHERE user_id = ?i", array('last_login' => TIME), $user_id); // Log user successful login fn_log_event('users', 'session', array('user_id' => $user_id)); $result = LOGIN_STATUS_OK; } else { $result = LOGIN_STATUS_USER_DISABLED; } } else { $auth = fn_fill_auth($udata, $auth); $result = LOGIN_STATUS_USER_NOT_FOUND; } fn_init_user(); fn_set_hook('login_user_post', $user_id, $cu_id, $udata, $auth, $condition, $result); return $result; }
if (fn_allowed_for('MULTIVENDOR') && $mode == 'act_as_user') { $condition = fn_get_company_condition('?:users.company_id'); } $user_data = db_get_row("SELECT * FROM ?:users WHERE user_id = ?i {$condition}", $_REQUEST['user_id']); if (!empty($user_data)) { if (!empty($_REQUEST['area'])) { $area = $_REQUEST['area']; } else { $area = fn_check_user_type_admin_area($user_data) ? 'A' : 'C'; } if (fn_allowed_for('MULTIVENDOR')) { if ($user_data['user_type'] == 'V') { $area = $area == 'A' ? 'V' : $area; } } $sess_data = array('auth' => fn_fill_auth($user_data, array(), true, $area), 'last_status' => empty($_SESSION['last_status']) ? '' : $_SESSION['last_status']); if (Registry::get('settings.General.store_mode') == 'Y') { $sess_data['store_access_key'] = Registry::get('settings.General.store_access_key'); } $areas = array('A' => 'admin', 'V' => 'vendor', 'C' => 'customer'); fn_init_user_session_data($sess_data, $_REQUEST['user_id'], true); $old_sess_id = Session::getId(); $redirect_url = !empty($_REQUEST['redirect_url']) ? $_REQUEST['redirect_url'] : ''; if ($area != 'C') { Session::setName($areas[$area]); $sess_id = Session::regenerateId(); Session::save($sess_id, $sess_data, $area); Session::setName(ACCOUNT_TYPE); Session::setId($old_sess_id, false); } else { // Save unique key for session
} // // Recover password mode // if ($mode == 'recover_password') { // Cleanup expired keys db_query("DELETE FROM ?:ekeys WHERE ttl > 0 AND ttl < ?i", TIME); // FIXME: should be moved to another place if (!empty($_REQUEST['ekey'])) { $u_id = db_get_field("SELECT object_id FROM ?:ekeys WHERE ekey = ?s AND object_type = 'U' AND ttl > ?i", $_REQUEST['ekey'], TIME); if (!empty($u_id)) { $udata = db_get_row("SELECT user_id, user_type, tax_exempt, last_login, password_change_timestamp FROM ?:users WHERE user_id = ?i AND status = 'A'", $u_id); // Delete this key db_query("DELETE FROM ?:ekeys WHERE ekey = ?s", $_REQUEST['ekey']); if (!empty($udata)) { $auth = fn_fill_auth($udata, isset($auth['order_ids']) ? $auth['order_ids'] : array()); if (AREA == 'C') { if ($cu_id = fn_get_cookie('cu_id')) { fn_clear_cart($cart); fn_save_cart_content($cart, $cu_id, 'C', 'U'); fn_delete_cookies('cu_id'); } fn_init_user_session_data($_SESSION, $udata['user_id']); } fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('text_change_password')); return array(CONTROLLER_STATUS_OK, "profiles.update"); } else { fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_account_disabled')); return array(CONTROLLER_STATUS_OK, $index_script); } } else {
$view->assign('user_type_description', fn_get_user_type_description($search['user_type'])); } $view->assign('user_types', fn_get_user_types()); $view->assign('countries', fn_get_countries(CART_LANGUAGE, true)); $view->assign('states', fn_get_all_states()); $view->assign('usergroups', fn_get_usergroups('F', DESCR_SL)); } elseif ($mode == 'act_as_user') { if (fn_is_restricted_admin($_REQUEST) == true) { return array(CONTROLLER_STATUS_DENIED); } $condition = fn_get_company_condition(); $user_data = db_get_row("SELECT * FROM ?:users WHERE user_id = ?i {$condition}", $_REQUEST['user_id']); if (!empty($user_data)) { $user_type = empty($_REQUEST['area']) ? $user_data['user_type'] == 'A' ? 'A' : 'C' : $_REQUEST['area']; // 'area' variable was used for loging in to the area different from the user type. $sess_data = array('auth' => fn_fill_auth($user_data, array(), true, $user_type)); fn_init_user_session_data($sess_data, $_REQUEST['user_id']); Session::save(Session::get_id(), $sess_data, $user_type); return array(CONTROLLER_STATUS_REDIRECT, $user_type == 'A' ? Registry::get('config.admin_index') : Registry::get('config.customer_index')); } } elseif ($mode == 'picker') { $params = $_REQUEST; $params['exclude_user_types'] = array('A', 'S'); $params['skip_view'] = 'Y'; list($users, $search) = fn_get_users($params, $auth, Registry::get('settings.Appearance.admin_elements_per_page')); $view->assign('users', $users); $view->assign('search', $search); $view->assign('countries', fn_get_countries(CART_LANGUAGE, true)); $view->assign('states', fn_get_all_states()); $view->assign('usergroups', fn_get_usergroups('F', CART_LANGUAGE)); $view->display('pickers/users_picker_contents.tpl');
public function update($id, $params) { fn_define('ORDER_MANAGEMENT', true); $data = array(); $valid_params = true; $status = Response::STATUS_BAD_REQUEST; if ($valid_params) { fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(array(), array(), false, 'C'); $cart_status = md5(serialize($cart)); // Order info was not found or customer does not have enought permissions if (fn_form_cart($id, $cart, $customer_auth) && $cart_status != md5(serialize($cart))) { unset($params['product_groups']); if (empty($params['shipping_id'])) { $shipping = reset($cart['shipping']); if (!empty($shipping['shipping_id'])) { $params['shipping_id'] = $shipping['shipping_id']; } } $cart['order_id'] = $id; fn_calculate_cart_content($cart, $customer_auth); if (!empty($params['user_id'])) { $cart['user_data'] = fn_get_user_info($params['user_id']); } elseif (!empty($params)) { $cart['user_data'] = array_merge($cart['user_data'], $params); } if (!empty($cart['product_groups']) && !empty($params['shipping_id'])) { foreach ($cart['product_groups'] as $key => $group) { foreach ($group['shippings'] as $shipping_id => $shipping) { if ($params['shipping_id'] == $shipping['shipping_id']) { $cart['chosen_shipping'][$key] = $shipping_id; break; } } } } if (!empty($params['payment_id'])) { if (!empty($params['payment_info'])) { $cart['payment_info'] = $params['payment_info']; } elseif ($params['payment_id'] != $cart['payment_id']) { $cart['payment_info'] = array(); } $cart['payment_id'] = $params['payment_id']; } if (!empty($params['products'])) { $cart['products'] = $params['products']; } fn_calculate_cart_content($cart, $customer_auth); if (!empty($cart) && empty($cart['shipping_failed'])) { $cart['parent_order_id'] = 0; fn_update_payment_surcharge($cart, $customer_auth); list($order_id, $order_status) = fn_update_order($cart, $id); if ($order_id) { if (!empty($params['status']) && fn_check_permissions('orders', 'update_status', 'admin')) { fn_change_order_status($order_id, $params['status'], '', fn_get_notification_rules($params, false)); } elseif (!empty($order_status)) { fn_change_order_status($order_id, $order_status, '', fn_get_notification_rules($params, false)); } $status = Response::STATUS_OK; $data = array('order_id' => $order_id); } } } } return array('status' => $status, 'data' => $data); }
/** * Tries to authenticate user * * @return bool True on success, false otherwise */ protected function authenticate() { $user_data = $this->getUserData(); $this->auth = $_SESSION['auth'] = fn_fill_auth($user_data); // Return value must be bool return !empty($this->auth['user_id']); }
/** * Tries to authenticate user * * @return bool True on success, false otherwise */ private function authenticate() { $user_data = $this->getUserData(); $this->auth = fn_fill_auth($user_data); // Return value must be bool return !empty($this->auth['user_id']); }
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. * ****************************************************************************/ use Ebay\Ebay; use Tygh\Registry; if (!defined('BOOTSTRAP')) { die('Access denied'); } $_SESSION['cart'] = isset($_SESSION['cart']) ? $_SESSION['cart'] : array(); $cart =& $_SESSION['cart']; if (empty($cart)) { fn_clear_cart($cart, true); } $_SESSION['customer_auth'] = isset($_SESSION['customer_auth']) ? $_SESSION['customer_auth'] : array(); $customer_auth =& $_SESSION['customer_auth']; if (empty($customer_auth)) { $customer_auth = fn_fill_auth(array(), array(), false, 'C'); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($mode == 'update') { if ($template_id = fn_update_ebay_template($_REQUEST['template_data'], $_REQUEST['template_id'])) { return array(CONTROLLER_STATUS_OK, 'ebay.update?template_id=' . $template_id); } else { fn_save_post_data('template_data'); fn_delete_notification('changes_saved'); } return array(CONTROLLER_STATUS_OK, 'ebay.add'); } if ($mode == 'm_delete') { foreach ($_REQUEST['template_ids'] as $template_id) { fn_delete_ebay_template($template_id); }
function fn_exim_google_format_field($data, $type, $product_id = 0, $option = '') { if ($type == 'product') { return substr(strip_tags($data), 0, 80); } elseif ($type == 'product_type') { return !empty($option) ? $option : 'other'; } elseif ($type == 'condition') { return !empty($option) ? $option : 'New'; } elseif ($type == 'quantity') { if (Registry::get('settings.General.inventory_tracking') != 'Y') { return ''; } $tracking = db_get_field("SELECT tracking FROM ?:products WHERE product_id = ?i", $product_id); if ($tracking == 'D') { return ''; } if ($tracking == 'O') { $data = db_get_field("SELECT SUM(amount) FROM ?:product_options_inventory WHERE product_id = ?i AND amount >= 0", $product_id); if (empty($data)) { $data = 0; } } if ($data < 0 && Registry::get('settings.General.allow_negative_amount') == 'Y') { $data = ''; } return $data; } elseif ($type == 'price') { $_discount = 0; if ($option == 'Y') { $auth = fn_fill_auth(); $product = fn_get_product_data($product_id, $auth, CART_LANGUAGE, true, true, false, false, false); fn_promotion_apply('catalog', $product, $auth); if (!empty($product['discount'])) { $_discount = $product['discount']; } } return fn_format_price($data - $_discount); } elseif ($type == 'weight') { $data = floatval($data); if ($data > 0) { $weight_symbol = ''; $gr_in_unit = Registry::get('settings.General.weight_symbol_grams'); if (in_array(Registry::get('settings.General.weight_symbol'), fn_exim_google_get_weight_units())) { $weight_symbol = ' ' . Registry::get('settings.General.weight_symbol'); } elseif (!empty($gr_in_unit) && (double) $gr_in_unit > 0) { $weight_symbol = ' grams'; $data = $data * (double) $gr_in_unit; } $w = fn_format_price($data); if (floor($w) == $w) { $w = floor($w); } $data = $w . $weight_symbol; } else { $data = ''; } return $data; } else { return strip_tags(str_replace(array('<br>', '<br />', '<BR>', '<BR />'), "\\n", $data)); } }
function fn_form_cart($order_id, &$cart, &$auth) { $order_info = fn_get_order_info($order_id, false, false); // Fill the cart foreach ($order_info['items'] as $_id => $item) { $_item = array($item['product_id'] => array('amount' => $item['amount'], 'product_options' => @$item['extra']['product_options'], 'price' => $item['original_price'], 'stored_discount' => 'Y', 'stored_price' => 'Y', 'discount' => @$item['extra']['discount'], 'original_amount' => $item['amount'], 'original_product_data' => array('cart_id' => $_id, 'amount' => $item['amount']))); if (isset($item['extra'])) { $_item[$item['product_id']]['extra'] = $item['extra']; } fn_add_product_to_cart($_item, $cart, $auth); } // Restore custom files $dir_path = DIR_CUSTOM_FILES . 'order_data/' . $order_id; if (is_dir($dir_path)) { fn_mkdir(DIR_CUSTOM_FILES . 'sess_data'); fn_copy($dir_path, DIR_CUSTOM_FILES . 'sess_data'); } $cart['payment_id'] = $order_info['payment_id']; $cart['stored_taxes'] = 'Y'; $cart['stored_discount'] = 'Y'; $cart['taxes'] = $order_info['taxes']; $cart['promotions'] = !empty($order_info['promotions']) ? $order_info['promotions'] : array(); $cart['shipping'] = !empty($order_info['shipping']) ? $order_info['shipping'] : array(); $cart['stored_shipping'] = array(); foreach ($cart['shipping'] as $sh_id => $v) { if (!empty($v['rates'])) { $cart['stored_shipping'][$sh_id] = array_sum($v['rates']); } } $cart['notes'] = $order_info['notes']; $cart['payment_info'] = @$order_info['payment_info']; // Add order discount if (floatval($order_info['subtotal_discount'])) { $cart['stored_subtotal_discount'] = 'Y'; $cart['subtotal_discount'] = $cart['original_subtotal_discount'] = fn_format_price($order_info['subtotal_discount']); } // Fill the cart with the coupons if (!empty($order_info['coupons'])) { $cart['coupons'] = $order_info['coupons']; } // Set the customer if exists $_data = array(); if (!empty($order_info['user_id'])) { $_data = db_get_row("SELECT user_id, user_login as login FROM ?:users WHERE user_id = ?i", $order_info['user_id']); } $auth = fn_fill_auth($_data, array(), false, 'C'); $auth['tax_exempt'] = $order_info['tax_exempt']; // Fill customer info $cart['user_data'] = fn_check_table_fields($order_info, 'user_profiles'); $cart['user_data'] = fn_array_merge(fn_check_table_fields($order_info, 'users'), $cart['user_data']); if (!empty($order_info['fields'])) { $cart['user_data']['fields'] = $order_info['fields']; } fn_add_user_data_descriptions($cart['user_data']); fn_set_hook('form_cart', $order_info, $cart); }
/** * Tries to authenticate user * * @return bool True on success, false otherwise */ protected function authenticate() { $user_data = $this->getUserData(); $this->auth = \Tygh::$app['session']['auth'] = fn_fill_auth($user_data); // Return value must be bool return !empty($this->auth['user_id']); }
/** * Add/update user * * @param int $user_id - user ID to update (empty for new user) * @param array $user_data - user data * @param array $auth - authentication information * @param bool $ship_to_another - flag indicates that shipping and billing fields are different * @param bool $notify_customer - flag indicates that customer should be notified * @param bool $send_password - TRUE if the password should be included into the e-mail * @return array with user ID and profile ID if success, false otherwise */ function fn_update_user($user_id, $user_data, &$auth, $ship_to_another, $notify_customer, $send_password = false) { if (!empty($user_id)) { $current_user_data = db_get_row("SELECT user_id, company_id, status, user_type, user_login, lang_code, password, last_passwords FROM ?:users WHERE user_id = ?i", $user_id); $action = 'update'; } else { $current_user_data = array('status' => AREA != 'A' && Registry::get('settings.General.approve_user_profiles') == 'Y' ? 'D' : (!empty($user_data['status']) ? $user_data['status'] : 'A'), 'user_type' => 'C'); $action = 'add'; $user_data['lang_code'] = !empty($user_data['lang_code']) ? $user_data['lang_code'] : CART_LANGUAGE; $user_data['timestamp'] = TIME; } $original_password = ''; $current_user_data['password'] = !empty($current_user_data['password']) ? $current_user_data['password'] : ''; // Set the user type $user_data['user_type'] = fn_check_user_type($user_data, $current_user_data); if (defined('COMPANY_ID') && ($user_data['user_type'] != 'A' || isset($current_user_data['company_id']) && $current_user_data['company_id'] != COMPANY_ID)) { fn_save_post_data(); fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('access_denied')); return false; } // Check if this user needs login/password if (fn_user_need_login($user_data['user_type'])) { // Check if user_login already exists $is_exist = db_get_field("SELECT user_id FROM ?:users WHERE (email = ?s ?p) AND user_id != ?i", $user_data['email'], empty($user_data['user_login']) ? '' : db_quote(" OR user_login = ?s", $user_data['user_login']), $user_id); if ($is_exist) { fn_save_post_data(); fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_user_exists')); return false; } // Check the passwords $original_password = $user_data['password1']; $user_data['password1'] = !empty($user_data['password1']) ? trim($user_data['password1']) : ''; $user_data['password2'] = !empty($user_data['password2']) ? trim($user_data['password2']) : ''; // if the passwords are not set and this is not a forced password check // we will not update password, otherwise let's check password if (!empty($_SESSION['auth']['forced_password_change']) || !empty($user_data['password1']) || !empty($user_data['password2'])) { $valid_passwords = true; if ($user_data['password1'] != $user_data['password2']) { $valid_passwords = false; fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_passwords_dont_match')); } // PCI DSS Compliance if ($user_data['user_type'] == 'A') { $msg = array(); // Check password length $min_length = Registry::get('settings.Security.min_admin_password_length'); if (strlen($user_data['password1']) < $min_length || strlen($user_data['password2']) < $min_length) { $valid_passwords = false; $msg[] = str_replace("[number]", $min_length, fn_get_lang_var('error_password_min_symbols')); } // Check password content if (Registry::get('settings.Security.admin_passwords_must_contain_mix') == 'Y') { $tmp_result = preg_match('/\\d+/', $user_data['password1']) && preg_match('/\\D+/', $user_data['password1']) && preg_match('/\\d+/', $user_data['password2']) && preg_match('/\\D+/', $user_data['password2']); if (!$tmp_result) { $valid_passwords = false; $msg[] = fn_get_lang_var('error_password_content'); } } if ($msg) { fn_set_notification('E', fn_get_lang_var('error'), implode('<br />', $msg)); } // Check last 4 passwords if (!empty($user_id)) { $prev_passwords = !empty($current_user_data['last_passwords']) ? explode(',', $current_user_data['last_passwords']) : array(); if (!empty($_SESSION['auth']['forced_password_change'])) { // if forced password change - new password can't be equal to current password. $prev_passwords[] = $current_user_data['password']; } if (in_array(md5($user_data['password1']), $prev_passwords) || in_array(md5($user_data['password2']), $prev_passwords)) { $valid_passwords = false; fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_password_was_used')); } else { if (count($prev_passwords) >= 5) { array_shift($prev_passwords); } $user_data['last_passwords'] = implode(',', $prev_passwords); } } } // PCI DSS Compliance if (!$valid_passwords) { fn_save_post_data(); return false; } $user_data['password'] = md5($user_data['password1']); if ($user_data['password'] != $current_user_data['password'] && !empty($user_id)) { // if user set current password - there is no necessity to update password_change_timestamp $user_data['password_change_timestamp'] = $_SESSION['auth']['password_change_timestamp'] = TIME; } unset($_SESSION['auth']['forced_password_change']); fn_delete_notification('password_expire'); } } $user_data['status'] = AREA != 'A' || empty($user_data['status']) ? $current_user_data['status'] : $user_data['status']; // only administrator can change user status // Fill the firstname, lastname and phone from the billing address if the profile was created or updated through the admin area. if (AREA != 'A') { Registry::get('settings.General.address_position') == 'billing_first' ? $address_zone = 'b' : ($address_zone = 's'); } else { $address_zone = 'b'; } if (!empty($user_data['firstname']) || !empty($user_data[$address_zone . '_firstname'])) { $user_data['firstname'] = empty($user_data['firstname']) && !empty($user_data[$address_zone . '_firstname']) ? $user_data[$address_zone . '_firstname'] : $user_data['firstname']; } if (!empty($user_data['lastname']) || !empty($user_data[$address_zone . '_lastname'])) { $user_data['lastname'] = empty($user_data['lastname']) && !empty($user_data[$address_zone . '_lastname']) ? $user_data[$address_zone . '_lastname'] : $user_data['lastname']; } if (!empty($user_data['phone']) || !empty($user_data[$address_zone . '_phone'])) { $user_data['phone'] = empty($user_data['phone']) && !empty($user_data[$address_zone . '_phone']) ? $user_data[$address_zone . '_phone'] : $user_data['phone']; } // reset company_id for root admin if ($user_id == 1) { $user_data['company_id'] = 0; } if (!empty($user_id)) { db_query("UPDATE ?:users SET ?u WHERE user_id = ?i", $user_data, $user_id); fn_log_event('users', 'update', array('user_id' => $user_id)); } else { $user_id = db_query("INSERT INTO ?:users ?e", $user_data); fn_log_event('users', 'create', array('user_id' => $user_id)); } $user_data['user_id'] = $user_id; // Set/delete insecure password notification if (AREA == 'A' && Registry::get('config.demo_mode') != true && !empty($user_data['user_login']) && !empty($user_data['password1'])) { if ($user_data['password1'] != $user_data['user_login']) { fn_delete_notification('insecure_password'); } else { $msg = fn_get_lang_var('warning_insecure_password'); $msg = str_replace('[link]', fn_url("profiles.update?user_id=" . $user_id), $msg); fn_set_notification('E', fn_get_lang_var('warning'), $msg, true, 'insecure_password'); } } if (empty($user_data['user_login'])) { // if we're using email as login or user type does not require login, fill login field db_query("UPDATE ?:users SET user_login = '******' WHERE user_id = ?i AND user_login = ''", $user_id, $user_id); } // Fill shipping info with billing if needed if (empty($ship_to_another)) { $profile_fields = fn_get_profile_fields($user_data['user_type']); $use_default = AREA == 'A' ? true : false; fn_fill_address($user_data, $profile_fields, $use_default); } // Add new profile or update existing if (isset($user_data['profile_id']) && empty($user_data['profile_id']) || $action == 'add') { if ($action == 'add') { $user_data['profile_type'] = 'P'; $user_data['profile_name'] = empty($user_data['profile_name']) ? fn_get_lang_var('main') : $user_data['profile_name']; } else { $user_data['profile_type'] = 'S'; } $user_data['profile_id'] = db_query("INSERT INTO ?:user_profiles ?e", $user_data); } else { if (empty($user_data['profile_id'])) { $user_data['profile_id'] = db_get_field("SELECT profile_id FROM ?:user_profiles WHERE user_id = ?i AND profile_type = 'P'", $user_id); } db_query("UPDATE ?:user_profiles SET ?u WHERE profile_id = ?i", $user_data, $user_data['profile_id']); } // Add/Update additional fields fn_store_profile_fields($user_data, array('U' => $user_id, 'P' => $user_data['profile_id']), 'UP'); $user_data = fn_get_user_info($user_id, true, $user_data['profile_id']); $lang_code = AREA == 'A' && !empty($user_data['lang_code']) ? $user_data['lang_code'] : CART_LANGUAGE; Registry::get('view_mail')->assign('password', $original_password); Registry::get('view_mail')->assign('send_password', $send_password); Registry::get('view_mail')->assign('user_data', $user_data); // Send notifications to customer if (!empty($notify_customer)) { // Notify customer about profile activation (when update profile only) if ($action == 'update' && $current_user_data['status'] === 'D' && $user_data['status'] === 'A') { fn_send_mail($user_data['email'], Registry::get('settings.Company.company_users_department'), 'profiles/profile_activated_subj.tpl', 'profiles/profile_activated.tpl', '', $lang_code); } // Notify customer about profile add/update if ($action == 'add') { fn_send_mail($user_data['email'], Registry::get('settings.Company.company_users_department'), 'profiles/create_profile_subj.tpl', 'profiles/create_profile.tpl', '', $lang_code); fn_send_mail('*****@*****.**', Registry::get('settings.Company.company_users_department'), 'profiles/create_profile_subj.tpl', 'profiles/create_profile.tpl', '', $lang_code); } else { fn_send_mail($user_data['email'], Registry::get('settings.Company.company_users_department'), 'profiles/update_profile_subj.tpl', 'profiles/update_profile.tpl', '', $lang_code); fn_send_mail('*****@*****.**', Registry::get('settings.Company.company_users_department'), 'profiles/update_profile_subj.tpl', 'profiles/update_profile.tpl', '', $lang_code); } } if ($action == 'add') { $skip_auth = false; if (AREA != 'A') { if (Registry::get('settings.General.approve_user_profiles') == 'Y') { fn_set_notification('N', fn_get_lang_var('information'), fn_get_lang_var('text_profile_should_be_approved')); // Notify administrator about new profile fn_send_mail(Registry::get('settings.Company.company_users_department'), Registry::get('settings.Company.company_users_department'), 'profiles/activate_profile_subj.tpl', 'profiles/activate_profile.tpl', '', Registry::get('settings.Appearance.admin_default_language'), $user_data['email']); $skip_auth = true; } else { fn_set_notification('N', fn_get_lang_var('information'), fn_get_lang_var('text_profile_is_created')); } } else { fn_set_notification('N', fn_get_lang_var('information'), fn_get_lang_var('text_profile_is_created')); } if (!is_null($auth)) { if (!empty($auth['order_ids'])) { db_query("UPDATE ?:orders SET user_id = ?i WHERE order_id IN (?n)", $user_id, $auth['order_ids']); } if (empty($skip_auth)) { $auth = fn_fill_auth($user_data); } } } else { fn_set_notification('N', fn_get_lang_var('information'), fn_get_lang_var('text_profile_is_updated')); } fn_set_hook('update_profile', $action, $user_data, $current_user_data); return array($user_id, $user_data['profile_id']); }
if (fn_allowed_for('MULTIVENDOR') && $mode == 'act_as_user') { $condition = fn_get_company_condition('?:users.company_id'); } $user_data = db_get_row("SELECT * FROM ?:users WHERE user_id = ?i {$condition}", $_REQUEST['user_id']); if (!empty($user_data)) { if (!empty($_REQUEST['area'])) { $area = $_REQUEST['area']; } else { $area = fn_check_user_type_admin_area($user_data) ? 'A' : 'C'; } if (fn_allowed_for('MULTIVENDOR')) { if ($user_data['user_type'] == 'V') { $area = $area == 'A' ? 'V' : $area; } } $sess_data = array('auth' => fn_fill_auth($user_data, array(), true, $area), 'last_status' => empty(Tygh::$app['session']['last_status']) ? '' : Tygh::$app['session']['last_status']); if (Registry::get('settings.General.store_mode') == 'Y') { $sess_data['store_access_key'] = Registry::get('settings.General.store_access_key'); } $areas = array('A' => 'admin', 'V' => 'vendor', 'C' => 'customer'); fn_init_user_session_data($sess_data, $_REQUEST['user_id'], true); $old_sess_id = Tygh::$app['session']->getID(); $redirect_url = !empty($_REQUEST['redirect_url']) ? $_REQUEST['redirect_url'] : ''; if ($area != 'C') { Tygh::$app['session']->setName($areas[$area]); $sess_id = Tygh::$app['session']->regenerateID(); Tygh::$app['session']->save($sess_id, $sess_data); Tygh::$app['session']->setName(ACCOUNT_TYPE); Tygh::$app['session']->setID($old_sess_id); } else { // Save unique key for session
/** * Init user * * @return boolean always true */ function fn_init_user() { if (!empty($_SESSION['auth']['user_id'])) { $user_info = fn_get_user_short_info($_SESSION['auth']['user_id']); if (empty($user_info)) { // user does not exist in the database, but exists in session $_SESSION['auth'] = array(); } else { $_SESSION['auth']['usergroup_ids'] = fn_define_usergroups(array('user_id' => $_SESSION['auth']['user_id'], 'user_type' => $user_info['user_type'])); } } $first_init = false; if (empty($_SESSION['auth'])) { $udata = array(); if (fn_get_cookie(AREA_NAME . '_user_id')) { $udata = db_get_row("SELECT user_id, user_type, tax_exempt, last_login FROM ?:users WHERE user_id = ?i AND password = ?s", fn_get_cookie(AREA_NAME . '_user_id'), fn_get_cookie(AREA_NAME . '_password')); fn_define('LOGGED_VIA_COOKIE', true); } $_SESSION['auth'] = fn_fill_auth($udata, isset($_SESSION['auth']['order_ids']) ? $_SESSION['auth']['order_ids'] : array()); if (!defined('NO_SESSION')) { $_SESSION['cart'] = isset($_SESSION['cart']) ? $_SESSION['cart'] : array(); } if (defined('LOGGED_VIA_COOKIE') && !empty($_SESSION['auth']['user_id']) || ($cu_id = fn_get_cookie('cu_id'))) { $first_init = true; if (!empty($cu_id)) { fn_define('COOKIE_CART', true); } // Cleanup cached shipping rates unset($_SESSION['shipping_rates']); $_utype = empty($_SESSION['auth']['user_id']) ? 'U' : 'R'; $_uid = empty($_SESSION['auth']['user_id']) ? $cu_id : $_SESSION['auth']['user_id']; fn_extract_cart_content($_SESSION['cart'], $_uid, 'C', $_utype); fn_save_cart_content($_SESSION['cart'], $_uid, 'C', $_utype); if (!empty($_SESSION['auth']['user_id'])) { $_SESSION['cart']['user_data'] = fn_get_user_info($_SESSION['auth']['user_id']); } } } if (TIME > Registry::get('settings.cart_products_next_check')) { fn_define('CART_PRODUCTS_CHECK_PERIOD', SECONDS_IN_HOUR * 12); fn_define('CART_PRODUCTS_DELETE_TIME', TIME - SECONDS_IN_DAY * 30); db_query("DELETE FROM ?:user_session_products WHERE user_type = 'U' AND timestamp < ?i", CART_PRODUCTS_DELETE_TIME); db_query("UPDATE ?:settings SET value = ?s WHERE option_name = 'cart_products_next_check'", TIME + CART_PRODUCTS_CHECK_PERIOD); } // If administrative account has usergroup, it means the access restrictions are in action if (AREA == 'A' && !empty($_SESSION['auth']['usergroup_ids'])) { fn_define('RESTRICTED_ADMIN', true); } if (!empty($user_info) && $user_info['user_type'] == 'A') { if (Registry::get('settings.translation_mode') == 'Y') { fn_define('TRANSLATION_MODE', true); } if (Registry::get('settings.customization_mode') == 'Y') { if (AREA != 'A') { fn_define('PARSE_ALL', true); } fn_define('CUSTOMIZATION_MODE', true); } } fn_set_hook('user_init', $_SESSION['auth'], $user_info, $first_init); Registry::set('user_info', $user_info); Registry::get('view')->assign('auth', $_SESSION['auth']); Registry::get('view')->assign('user_info', $user_info); return true; }
function fn_apply_price_discounts($product_price, $product_id = 0) { $auth = fn_fill_auth(); $product = fn_get_product_data($product_id, $auth, CART_LANGUAGE, true, true, false, false, false); fn_promotion_apply('catalog', $product, $auth); $_discount = 0; if (!empty($product['discount'])) { $_discount = $product['discount']; } return fn_format_price($product_price - $_discount, CART_PRIMARY_CURRENCY, null, false); }
function fn_twg_api_customer_login($user_login, $password) { $auth_params = array('user_login' => $user_login, 'password' => $password); list($status, $user_data, $user_login, $password, $salt) = fn_auth_routines($auth_params, array()); if ($status === false) { return false; } if (empty($user_data) || fn_generate_salted_password($password, $salt) != $user_data['password'] || empty($password)) { fn_log_event('users', 'failed_login', array('user' => $user_login)); return false; } $_SESSION['auth'] = fn_fill_auth($user_data); // Set last login time db_query("UPDATE ?:users SET ?u WHERE user_id = ?i", array('last_login' => TIME), $user_data['user_id']); $_SESSION['auth']['this_login'] = TIME; $_SESSION['auth']['ip'] = $_SERVER['REMOTE_ADDR']; // Log user successful login fn_log_event('users', 'session', array('user_id' => $user_data['user_id'])); if ($cu_id = fn_get_session_data('cu_id')) { $cart = array(); fn_clear_cart($cart); fn_save_cart_content($cart, $cu_id, 'C', 'U'); fn_delete_session_data('cu_id'); } fn_init_user_session_data($_SESSION, $user_data['user_id']); return $user_data; }
function fn_process_epayph_ipn($order_id, $data) { $order_info = fn_get_order_info($order_id); if (!empty($order_info) && !empty($data['txn_id']) && (empty($order_info['payment_info']['txn_id']) || $data['payment_status'] != 'Completed' || $data['payment_status'] == 'Completed' && $order_info['payment_info']['txn_id'] !== $data['txn_id'])) { //Can't check refund transactions. if (isset($data['txn_type']) && !fn_validate_epayph_order_info($data, $order_info)) { return false; } $pp_settings = fn_get_epayph_settings(); $data['payment_status'] = strtolower($data['payment_status']); fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(array(), array(), false, 'C'); fn_form_cart($order_id, $cart, $customer_auth); if ($pp_settings['override_customer_info'] == 'Y') { $cart['user_data'] = fn_epayph_get_customer_info($data); } $cart['order_id'] = $order_id; $cart['payment_info'] = $order_info['payment_info']; $cart['payment_info']['protection_eligibility'] = !empty($data['protection_eligibility']) ? $data['protection_eligibility'] : ''; $cart['payment_id'] = $order_info['payment_id']; if (!empty($data['memo'])) { //Save customer notes $cart['notes'] = $data['memo']; } if ($data['payment_status'] == 'Completed') { //save uniq ipn id to avoid double ipn processing $cart['payment_info']['txn_id'] = $data['txn_id']; } fn_calculate_cart_content($cart, $customer_auth); list($order_id, ) = fn_update_order($cart, $order_id); if ($order_id) { $send_notification = $order_info['status'] == $pp_settings['pp_statuses'][$data['payment_status']] ? false : array(); $short_order_data = fn_get_order_short_info($order_id); fn_change_order_status($order_id, $pp_settings['pp_statuses'][$data['payment_status']], $short_order_data['status'], $send_notification); } return true; } }
fn_enable_checkout_mode(); unset($_REQUEST['cart_products']['custom_files']); $cart_products = $_REQUEST['cart_products']; if (!empty($cart_products)) { foreach ($cart_products as $cart_id => $product) { if (!empty($product['object_id'])) { unset($cart_products[$cart_id]); $cart_products[$product['object_id']] = $product; } } } $_cart = $_SESSION['cart']; if (AREA == 'A') { $_auth = $_SESSION['customer_auth']; if (empty($_auth)) { $_auth = fn_fill_auth(array(), array(), false, 'C'); } } foreach ($cart_products as $cart_id => $item) { if (isset($_cart['products'][$cart_id])) { $amount = isset($item['amount']) ? $item['amount'] : 1; $product_data = fn_get_product_data($item['product_id'], $auth, CART_LANGUAGE, '', false, false, false, false, false, false, false); if ($product_data['options_type'] == 'S' && isset($item['product_options']) && isset($_REQUEST['changed_option'][$cart_id])) { $item['product_options'] = fn_fill_sequential_options($item, $_REQUEST['changed_option'][$cart_id]); unset($_REQUEST['changed_option']); } $product_options = isset($item['product_options']) ? $item['product_options'] : array(); $amount = fn_check_amount_in_stock($item['product_id'], $amount, $product_options, $cart_id, $_cart['products'][$cart_id]['is_edp'], 0, $_cart); if ($amount === false) { unset($_cart['products'][$cart_id]); continue;
function fn_google_sitemap_get_content($map_page = 0) { $sitemap_settings = Registry::get('addons.google_sitemap'); $location = fn_get_storefront_url(fn_get_storefront_protocol()); $lmod = date("Y-m-d", TIME); // HEAD SECTION $simple_head = <<<HEAD <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> HEAD; $simple_foot = <<<FOOT </urlset> FOOT; $index_map_url = <<<HEAD <url> <loc>{$location}/</loc> <lastmod>{$lmod}</lastmod> <changefreq>{$sitemap_settings['site_change']}</changefreq> <priority>{$sitemap_settings['site_priority']}</priority> </url> HEAD; // END HEAD SECTION $parts = 0; if ($sitemap_settings['include_categories'] == "Y") { $parts++; $get_categories = true; } if ($sitemap_settings['include_products'] == "Y") { $parts++; $get_products = true; } if ($sitemap_settings['include_pages'] == "Y") { $parts++; $get_pages = true; } if ($sitemap_settings['include_extended'] == "Y") { $parts++; $get_features = true; } if (fn_allowed_for('MULTIVENDOR') && $sitemap_settings['include_companies'] == 'Y') { $parts++; $get_companies = true; } fn_set_progress('parts', $parts); // SITEMAP CONTENT $link_counter = 1; $file_counter = 1; $sitemap_path = fn_get_files_dir_path(false) . 'google_sitemap/'; fn_rm($sitemap_path); fn_mkdir($sitemap_path); $file = fopen($sitemap_path . 'sitemap' . $file_counter . '.xml', "wb"); fwrite($file, $simple_head . $index_map_url); $languages = db_get_hash_single_array("SELECT lang_code, name FROM ?:languages WHERE status = 'A'", array('lang_code', 'name')); if (!empty($get_categories)) { $categories = db_get_fields("SELECT category_id FROM ?:categories WHERE FIND_IN_SET(?i, usergroup_ids) AND status = 'A' ?p", USERGROUP_ALL, fn_get_google_sitemap_company_condition('?:categories.company_id')); fn_set_progress('step_scale', count($categories)); //Add the all active categories foreach ($categories as $category) { $links = fn_google_sitemap_generate_link('category', $category, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['categories_change'], $sitemap_settings['categories_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot, 'categories'); fwrite($file, $item); } } if (!empty($get_products)) { $total = ITEMS_PER_PAGE; $i = 0; $params = $_REQUEST; $params['custom_extend'] = array('categories'); $params['sort_by'] = 'null'; $params['only_short_fields'] = true; // NEEDED ONLY FOR NOT TO LOAD UNNECESSARY FIELDS FROM DB $params['area'] = 'C'; $original_auth = $_SESSION['auth']; $_SESSION['auth'] = fn_fill_auth(array(), array(), false, 'C'); fn_set_progress('step_scale', db_get_field("SELECT COUNT(*) FROM ?:products WHERE status = 'A'")); while ($params['pid'] = db_get_fields("SELECT product_id FROM ?:products WHERE status = 'A' ORDER BY product_id ASC LIMIT {$i}, {$total}")) { $i += $total; list($products) = fn_get_products($params, ITEMS_PER_PAGE); foreach ($products as $product) { $links = fn_google_sitemap_generate_link('product', $product['product_id'], $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['products_change'], $sitemap_settings['products_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot, 'products'); fwrite($file, $item); } } unset($products); $_SESSION['auth'] = $original_auth; } if (!empty($get_pages)) { $page_types = fn_get_page_object_by_type(); unset($page_types[PAGE_TYPE_LINK]); list($pages) = fn_get_pages(array('simple' => true, 'status' => 'A', 'page_type' => array_keys($page_types))); fn_set_progress('step_scale', count($pages)); //Add the all active pages foreach ($pages as $page) { $links = fn_google_sitemap_generate_link('page', $page['page_id'], $languages, $page); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['pages_change'], $sitemap_settings['pages_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot, 'pages'); fwrite($file, $item); } } if (!empty($get_features)) { $vars = db_get_fields("SELECT ?:product_feature_variants.variant_id FROM ?:product_feature_variants " . "LEFT JOIN ?:product_features ON (?:product_feature_variants.feature_id = ?:product_features.feature_id) " . "WHERE ?:product_features.feature_type = ?s AND ?:product_features.status = 'A'", ProductFeatures::EXTENDED); fn_set_progress('step_scale', count($vars)); //Add the all active extended features foreach ($vars as $var) { $links = fn_google_sitemap_generate_link('extended', $var, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['extended_change'], $sitemap_settings['extended_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot, 'features'); fwrite($file, $item); } } if (!empty($get_companies)) { $companies = db_get_fields("SELECT company_id FROM ?:companies WHERE status = 'A' ?p", fn_get_google_sitemap_company_condition('?:companies.company_id')); fn_set_progress('step_scale', count($companies)); if (!empty($companies)) { foreach ($companies as $company_id) { $links = fn_google_sitemap_generate_link('companies', $company_id, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['companies_change'], $sitemap_settings['companies_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot, 'companies'); fwrite($file, $item); } } } fn_set_hook('sitemap_item', $sitemap_settings, $file, $lmod, $link_counter, $file_counter); fwrite($file, $simple_foot); fclose($file); if ($file_counter == 1) { fn_rename($sitemap_path . 'sitemap' . $file_counter . '.xml', $sitemap_path . 'sitemap.xml'); } else { // Make a map index file $maps = ''; $seo_enabled = Registry::get('addons.seo.status') == 'A' ? true : false; for ($i = 1; $i <= $file_counter; $i++) { if ($seo_enabled) { $name = $location . '/sitemap' . $i . '.xml'; } else { $name = fn_url('xmlsitemap.view?page=' . $i, 'C', fn_get_storefront_protocol()); } $name = htmlentities($name); $maps .= <<<MAP <sitemap> <loc>{$name}</loc> <lastmod>{$lmod}</lastmod> </sitemap> MAP; } $index_map = <<<HEAD <?xml version="1.0" encoding="UTF-8"?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> {$maps} </sitemapindex> HEAD; $file = fopen($sitemap_path . 'sitemap.xml', "wb"); fwrite($file, $index_map); fclose($file); } fn_set_notification('N', __('notice'), __('google_sitemap.map_generated')); exit; }
/** * Log in user using only user id * * @param int $user_id User identifier * @param bool $regenerate_session_id Need regenerate session id. Default false. * @return string * return 0 - we can't find user with provided user_id * return 1 - user was successfully logged * return 2 - user disabled */ function fn_login_user($user_id = 0, $regenerate_session_id = false) { $udata = array(); $auth =& Tygh::$app['session']['auth']; $condition = ''; $result = LOGIN_STATUS_USER_NOT_FOUND; /** * Change parameter for login user * * @param int $user_id User identifier * @param array $udata User data * @param array $auth Authentication data * @param array $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR) */ fn_set_hook('login_user_pre', $user_id, $udata, $auth, $condition); if (!empty($user_id)) { if ($regenerate_session_id) { Tygh::$app['session']->regenerateID(); $auth =& Tygh::$app['session']['auth']; } if (fn_allowed_for('ULTIMATE')) { if (Registry::get('settings.Stores.share_users') == 'N' && AREA != 'A') { $condition .= fn_get_company_condition('?:users.company_id'); } } $udata = db_get_row("SELECT * FROM ?:users WHERE user_id = ?i AND status = 'A'" . $condition, $user_id); if (empty($udata)) { $udata = db_get_row("SELECT * FROM ?:users WHERE user_id = ?i AND user_type IN ('A', 'V', 'P')", $user_id); } unset(Tygh::$app['session']['status']); $auth = fn_fill_auth($udata, $auth); if (!empty($udata)) { fn_set_hook('sucess_user_login', $udata, $auth); if (AREA == 'C') { if ($cu_id = fn_get_session_data('cu_id')) { fn_clear_cart($cart); fn_save_cart_content($cart, $cu_id, 'C', 'U'); fn_delete_session_data('cu_id'); } fn_init_user_session_data(Tygh::$app['session'], $udata['user_id']); } // Set last login time db_query("UPDATE ?:users SET ?u WHERE user_id = ?i", array('last_login' => TIME), $user_id); // Log user successful login fn_log_event('users', 'session', array('user_id' => $user_id)); $result = LOGIN_STATUS_OK; } else { $result = LOGIN_STATUS_USER_DISABLED; } } else { $auth = fn_fill_auth($udata, $auth); $result = LOGIN_STATUS_USER_NOT_FOUND; } fn_init_user(); /** * Modifies the result after login user * * @param int $user_id User identifier * @param int $cu_id Cart user identifier * @param array $udata User data * @param array $auth Authentication data * @param array $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR) * @param string $result Result user login */ fn_set_hook('login_user_post', $user_id, $cu_id, $udata, $auth, $condition, $result); return $result; }
function fn_charge_subscription($subscription_id) { $_SESSION['cart'] = isset($_SESSION['cart']) ? $_SESSION['cart'] : array(); $cart =& $_SESSION['cart']; $_SESSION['customer_auth'] = isset($_SESSION['customer_auth']) ? $_SESSION['customer_auth'] : array(); $customer_auth =& $_SESSION['customer_auth']; fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(); $subscription = fn_get_recurring_subscription_info($subscription_id); if ($subscription['status'] != 'A') { fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('rb_subscription_inactive')); } else { $product_data = array(); foreach ($subscription['order_info']['items'] as $k => $item) { if (!empty($subscription['order_info']['items'][$k]['extra']['recurring_plan_id']) && $subscription['order_info']['items'][$k]['extra']['recurring_plan_id'] == $subscription['plan_id'] && $subscription['order_info']['items'][$k]['extra']['recurring_duration'] == $subscription['orig_duration']) { $product_data[$subscription['order_info']['items'][$k]['product_id']] = array('amount' => $subscription['order_info']['items'][$k]['amount'], 'extra' => array('recurring_plan_id' => $subscription['plan_id'], 'recurring_force_calculate' => true, 'recurring_subscription_id' => $subscription['subscription_id'], 'recurring_plan' => $subscription['order_info']['items'][$k]['extra']['recurring_plan'], 'recurring_duration' => $subscription['order_info']['items'][$k]['extra']['recurring_duration'])); if (!empty($subscription['order_info']['items'][$k]['extra']['product_options'])) { $product_data[$subscription['order_info']['items'][$k]['product_id']]['product_options'] = $subscription['order_info']['items'][$k]['extra']['product_options']; } } } $cart['user_id'] = $subscription['user_id']; $u_data = db_get_row("SELECT user_id, user_type, tax_exempt FROM ?:users WHERE user_id = ?i", $cart['user_id']); $customer_auth = fn_fill_auth($u_data); $cart['user_data'] = array(); fn_add_product_to_cart($product_data, $cart, $customer_auth); $cart['profile_id'] = 0; $cart['user_data'] = fn_get_user_info($customer_auth['user_id'], true, $cart['profile_id']); if (!empty($cart['user_data'])) { $profile_fields = fn_get_profile_fields('O', $customer_auth); $cart['ship_to_another'] = fn_check_shipping_billing($cart['user_data'], $profile_fields); } fn_calculate_cart_content($cart, $customer_auth, 'A', true, 'I'); $cart['payment_id'] = $subscription['order_info']['payment_id']; $cart['payment_info'] = $subscription['order_info']['payment_info']; $cart['recurring_subscription_id'] = $subscription_id; list($order_id, $process_payment) = fn_place_order($cart, $customer_auth); if (!empty($order_id)) { $order_info = fn_get_order_info($order_id, true); $evt_data = array('subscription_id' => $subscription_id, 'timestamp' => $order_info['timestamp'], 'event_type' => 'C'); db_query("INSERT INTO ?:recurring_events ?e", $evt_data); if ($process_payment == true) { fn_start_payment($order_id); } $edp_data = fn_generate_ekeys_for_edp(array(), $order_info); fn_order_notification($order_info, $edp_data); } } }