/** * Encode plain text string * Example: $result = fn_simple_encode_str('test'); // returns "uftu" * * @param type $str * @return type */ function fn_simple_encode_str($str) { $encoded_str = ''; for ($i = 0; $i < fn_strlen($str); $i++) { $chr = ord($str[$i]); $encoded_str .= chr(++$chr); } return $encoded_str; }
/** * Smarty truncate modifier plugin * * Type: modifier<br> * Name: truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string or inserting $etc into the middle. * @link http://smarty.php.net/manual/en/language.modifier.truncate.php * truncate (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param string * @param integer * @param string * @param boolean * @param boolean * @return string */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { if ($length == 0) { return ''; } if (Registry::get('runtime.customization_mode.translation') && preg_match('/(\\[lang name\\=[\\w-]+?( [pre\\-ajx]*)?\\])(.*?)(\\[\\/lang\\])/is', $string, $matches)) { list(, $pre, , $string, $post) = $matches; } else { $pre = $post = ''; } if (fn_strlen($string) > $length) { $length -= min($length, fn_strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/u', '', fn_substr($string, 0, $length + 1)); } if (!$middle) { return fn_substr($string, 0, $length) . $etc; } else { return fn_substr($string, 0, $length / 2) . $etc . fn_substr($string, -$length / 2); } } else { return $string; } }
/** * Dispathes the execution control to correct controller * * @return nothing */ function fn_dispatch($controller = '', $mode = '', $action = '', $dispatch_extra = '', $area = AREA) { Debugger::checkpoint('After init'); $auth = $_SESSION['auth']; $controller = empty($controller) ? Registry::get('runtime.controller') : $controller; $mode = empty($mode) ? Registry::get('runtime.mode') : $mode; $action = empty($action) ? Registry::get('runtime.action') : $action; $dispatch_extra = empty($dispatch_extra) ? Registry::get('runtime.dispatch_extra') : $dispatch_extra; fn_set_hook('before_dispatch', $controller, $mode, $action, $dispatch_extra, $area); $view = Registry::get('view'); $run_controllers = true; $external = false; $status = CONTROLLER_STATUS_NO_PAGE; // CSRF protection if (fn_is_csrf_protection_enabled($auth) && !fn_csrf_validate_request(array('server' => $_SERVER, 'request' => $_REQUEST, 'session' => $_SESSION, 'controller' => $controller, 'mode' => $mode, 'action' => $action, 'dispatch_extra' => $dispatch_extra, 'area' => $area, 'auth' => $auth))) { fn_set_notification('E', __('error'), __('text_csrf_attack')); fn_redirect(fn_url()); } // If $config['http_host'] was different from the domain name, there was redirection to $config['http_host'] value. if (strtolower(Registry::get('config.current_host')) != strtolower(REAL_HOST) && $_SERVER['REQUEST_METHOD'] == 'GET' && !defined('CONSOLE')) { if (!empty($_SERVER['REDIRECT_URL'])) { $qstring = $_SERVER['REDIRECT_URL']; } else { if (!empty($_SERVER['REQUEST_URI'])) { $qstring = $_SERVER['REQUEST_URI']; } else { $qstring = Registry::get('config.current_url'); } } $curent_path = Registry::get('config.current_path'); if (!empty($curent_path) && strpos($qstring, $curent_path) === 0) { $qstring = substr_replace($qstring, '', 0, fn_strlen($curent_path)); } fn_redirect(Registry::get('config.current_location') . $qstring, false, true); } $upload_max_filesize = Bootstrap::getIniParam('upload_max_filesize'); $post_max_size = Bootstrap::getIniParam('post_max_size'); if (!defined('AJAX_REQUEST') && isset($_SERVER['CONTENT_LENGTH']) && ($_SERVER['CONTENT_LENGTH'] > fn_return_bytes($upload_max_filesize) || $_SERVER['CONTENT_LENGTH'] > fn_return_bytes($post_max_size))) { $max_size = fn_return_bytes($upload_max_filesize) < fn_return_bytes($post_max_size) ? $upload_max_filesize : $post_max_size; fn_set_notification('E', __('error'), __('text_forbidden_uploaded_file_size', array('[size]' => $max_size))); fn_redirect($_SERVER['HTTP_REFERER']); } // If URL contains session ID, remove it if (!defined('AJAX_REQUEST') && !empty($_REQUEST[Session::getName()]) && $_SERVER['REQUEST_METHOD'] == 'GET') { fn_redirect(fn_query_remove(Registry::get('config.current_url'), Session::getName())); } // If demo mode is enabled, check permissions FIX ME - why did we need one more user login check? if ($area == 'A') { if (Registry::get('config.demo_mode') == true) { $run_controllers = fn_check_permissions($controller, $mode, 'demo'); if ($run_controllers == false) { fn_set_notification('W', __('demo_mode'), __('demo_mode_content_text'), 'K', 'demo_mode'); if (defined('AJAX_REQUEST')) { exit; } fn_delete_notification('changes_saved'); $status = CONTROLLER_STATUS_REDIRECT; $_REQUEST['redirect_url'] = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : fn_url(''); } } else { $run_controllers = fn_check_permissions($controller, $mode, 'admin', '', $_REQUEST); if ($run_controllers == false) { if (defined('AJAX_REQUEST')) { $_info = Debugger::isActive() || fn_is_development() ? ' ' . $controller . '.' . $mode : ''; fn_set_notification('W', __('warning'), __('access_denied') . $_info); exit; } $status = CONTROLLER_STATUS_DENIED; } } } if ($_SERVER['REQUEST_METHOD'] != 'POST' && !defined('AJAX_REQUEST')) { if ($area == 'A' && empty($_REQUEST['keep_location']) && !defined('CONSOLE')) { if (!defined('HTTPS') && Registry::get('settings.Security.secure_admin') == 'Y') { fn_redirect(Registry::get('config.https_location') . '/' . Registry::get('config.current_url')); } elseif (defined('HTTPS') && Registry::get('settings.Security.secure_admin') != 'Y') { fn_redirect(Registry::get('config.http_location') . '/' . Registry::get('config.current_url')); } } elseif ($area == 'C') { $secure_controllers = fn_get_secure_controllers(); // if we are not on https but controller is secure, redirect to https if (!defined('HTTPS') && (Registry::get('settings.Security.secure_storefront') == 'full' || isset($secure_controllers[$controller]) && $secure_controllers[$controller] == 'active')) { fn_redirect(Registry::get('config.https_location') . '/' . Registry::get('config.current_url'), false, true); } // if we are on https and the controller is insecure, redirect to http if (defined('HTTPS') && Registry::get('settings.Security.secure_storefront') != 'full' && !isset($secure_controllers[$controller]) && Registry::get('settings.Security.keep_https') != 'Y') { fn_redirect(Registry::get('config.http_location') . '/' . Registry::get('config.current_url'), false, true); } } } LastView::instance()->prepare($_REQUEST); $controllers_cascade = array(); $controllers_list = array('init'); if ($run_controllers == true) { $controllers_list[] = $controller; $controllers_list = array_unique($controllers_list); } foreach ($controllers_list as $ctrl) { $core_controllers = fn_init_core_controllers($ctrl); list($addon_controllers) = fn_init_addon_controllers($ctrl); if (empty($core_controllers) && empty($addon_controllers)) { //$controllers_cascade = array(); // FIXME: controllers_cascade contains INIT. We should not clear initiation code. $status = CONTROLLER_STATUS_NO_PAGE; $run_controllers = false; break; } if (count($core_controllers) + count($addon_controllers) > 1) { throw new DeveloperException('Duplicate controller ' . $controller . var_export(array_merge($core_controllers, $addon_controllers), true)); } $core_pre_controllers = fn_init_core_controllers($ctrl, GET_PRE_CONTROLLERS); $core_post_controllers = fn_init_core_controllers($ctrl, GET_POST_CONTROLLERS); list($addon_pre_controllers) = fn_init_addon_controllers($ctrl, GET_PRE_CONTROLLERS); list($addon_post_controllers, $addons) = fn_init_addon_controllers($ctrl, GET_POST_CONTROLLERS); // we put addon post-controller to the top of post-controller cascade if current addon serves this request if (count($addon_controllers)) { $addon_post_controllers = fn_reorder_post_controllers($addon_post_controllers, $addon_controllers[0]); } $controllers_cascade = array_merge($controllers_cascade, $addon_pre_controllers, $core_pre_controllers, $core_controllers, $addon_controllers, $core_post_controllers, $addon_post_controllers); if (empty($controllers_cascade)) { throw new DeveloperException("No controllers for: {$ctrl}"); } } if ($mode == 'add') { $tpl = 'update.tpl'; } elseif (strpos($mode, 'add_') === 0) { $tpl = str_replace('add_', 'update_', $mode) . '.tpl'; } else { $tpl = $mode . '.tpl'; } $view = Registry::get('view'); if ($view->templateExists('views/' . $controller . '/' . $tpl)) { // try to find template in base views $view->assign('content_tpl', 'views/' . $controller . '/' . $tpl); } elseif (defined('LOADED_ADDON_PATH') && $view->templateExists('addons/' . LOADED_ADDON_PATH . '/views/' . $controller . '/' . $tpl)) { // try to find template in addon views $view->assign('content_tpl', 'addons/' . LOADED_ADDON_PATH . '/views/' . $controller . '/' . $tpl); } elseif (!empty($addons)) { // try to find template in addon views that extend base views foreach ($addons as $addon => $_v) { if ($view->templateExists('addons/' . $addon . '/views/' . $controller . '/' . $tpl)) { $view->assign('content_tpl', 'addons/' . $addon . '/views/' . $controller . '/' . $tpl); break; } } } /** * Performs actions after template assignment and before controller run * * @param string $controller controller name * @param string $mode controller mode name * @param string $area current working area * @param array $controllers_cascade list of controllers to run */ fn_set_hook('dispatch_assign_template', $controller, $mode, $area, $controllers_cascade); foreach ($controllers_cascade as $item) { $_res = fn_run_controller($item, $controller, $mode, $action, $dispatch_extra); // 0 - status, 1 - url $url = !empty($_res[1]) ? $_res[1] : ''; $external = !empty($_res[2]) ? $_res[2] : false; $permanent = !empty($_res[3]) ? $_res[3] : false; // Status could be changed only if we allow to run controllers despite of init controller if ($run_controllers == true) { $status = !empty($_res[0]) ? $_res[0] : CONTROLLER_STATUS_OK; } if ($status == CONTROLLER_STATUS_OK && !empty($url)) { $redirect_url = $url; } elseif ($status == CONTROLLER_STATUS_REDIRECT && !empty($url)) { $redirect_url = $url; break; } elseif ($status == CONTROLLER_STATUS_DENIED || $status == CONTROLLER_STATUS_NO_PAGE) { break; } } LastView::instance()->init($_REQUEST); // In console mode, just stop here if (defined('CONSOLE')) { $notifications = fn_get_notifications(); $exit_code = 0; foreach ($notifications as $n) { fn_echo('[' . $n['title'] . '] ' . $n['message'] . "\n"); if ($n['type'] == 'E') { $exit_code = 1; } } exit($exit_code); } if (!empty($auth['this_login']) && Registry::ifGet($auth['this_login'], 'N') === 'Y') { fn_set_notification('E', __('error'), __(ACCOUNT_TYPE . LOGIN_STATUS_USER_DISABLED)); $status = CONTROLLER_STATUS_DENIED; } // [Block manager] // block manager is disabled for vendors. if (!(fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id') || fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id'))) { if (fn_check_permissions('block_manager', 'manage', 'admin')) { $dynamic_object = SchemesManager::getDynamicObject($_REQUEST['dispatch'], $area, $_REQUEST); if (!empty($dynamic_object)) { if ($area == 'A' && Registry::get('runtime.mode') != 'add' && !empty($_REQUEST[$dynamic_object['key']])) { $object_id = $_REQUEST[$dynamic_object['key']]; $location = Location::instance()->get($dynamic_object['customer_dispatch'], $dynamic_object, CART_LANGUAGE); if (!empty($location) && $location['is_default'] != 1) { $params = array('dynamic_object' => array('object_type' => $dynamic_object['object_type'], 'object_id' => $object_id), $dynamic_object['key'] => $object_id, 'manage_url' => Registry::get('config.current_url')); Registry::set('navigation.tabs.blocks', array('title' => __('layouts'), 'href' => 'block_manager.manage_in_tab?' . http_build_query($params), 'ajax' => true)); } } } } } // [/Block manager] // Redirect if controller returned successful/redirect status only if (in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT)) && !empty($_REQUEST['redirect_url']) && !$external) { $redirect_url = $_REQUEST['redirect_url']; } // If controller returns "Redirect" status, check if redirect url exists if ($status == CONTROLLER_STATUS_REDIRECT && empty($redirect_url)) { $status = CONTROLLER_STATUS_NO_PAGE; } // In backend show "changes saved" notification if ($area == 'A' && $_SERVER['REQUEST_METHOD'] == 'POST' && in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT))) { if (strpos($mode, 'update') !== false && $mode != 'update_status' && $mode != 'update_mode' && !fn_notification_exists('extra', 'demo_mode') && !fn_notification_exists('type', 'E')) { fn_set_notification('N', __('notice'), __('text_changes_saved'), 'I', 'changes_saved'); } } // Attach params and redirect if needed if (in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT)) && !empty($redirect_url)) { if (!isset($_REQUEST['return_to_list'])) { $params = array('page', 'selected_section', 'active_tab'); $url_params = array(); foreach ($params as $param) { if (!empty($_REQUEST[$param])) { $url_params[$param] = $_REQUEST[$param]; } } if (!empty($url_params)) { $redirect_url = fn_link_attach($redirect_url, http_build_query($url_params)); } } if (!isset($external)) { $external = false; } if (!isset($permanent)) { $permanent = false; } fn_redirect($redirect_url, $external, $permanent); } if (!$view->getTemplateVars('content_tpl') && $status == CONTROLLER_STATUS_OK) { // FIXME $status = CONTROLLER_STATUS_NO_PAGE; } if ($status != CONTROLLER_STATUS_OK) { if ($status == CONTROLLER_STATUS_NO_PAGE) { if ($area == 'A' && empty($auth['user_id'])) { // If admin is not logged in redirect to login page from not found page fn_set_notification('W', __('page_not_found'), __('page_not_found_text')); fn_redirect("auth.login_form"); } header(' ', true, 404); } $view->assign('exception_status', $status); if ($area == 'A') { $view->assign('content_tpl', 'exception.tpl'); // for backend only } if ($status == CONTROLLER_STATUS_DENIED) { $view->assign('page_title', __('access_denied')); } elseif ($status == CONTROLLER_STATUS_NO_PAGE) { $view->assign('page_title', __('page_not_found')); } } fn_set_hook('dispatch_before_display'); Debugger::checkpoint('Before TPL'); // Pass current URL to ajax response only if we render whole page if (defined('AJAX_REQUEST') && Registry::get('runtime.root_template') == 'index.tpl') { Registry::get('ajax')->assign('current_url', fn_url(Registry::get('config.current_url'), $area, 'current')); } Registry::get('view')->display(Registry::get('runtime.root_template')); Debugger::checkpoint('After TPL'); Debugger::display(); fn_set_hook('complete'); if (defined('AJAX_REQUEST')) { // HHVM workaround. Destroy Ajax object manually if it has been created. $ajax = Registry::get('ajax'); $ajax = null; } exit; // stop execution }
function fn_basename($path, $suffix = '', $encoding = 'UTF-8') { $basename = explode("/", $path); $basename = end($basename); if (!empty($suffix) && fn_substr($basename, 0 - fn_strlen($suffix, $encoding), fn_strlen($basename, $encoding), $encoding) == $suffix) { $basename = fn_substr($basename, 0, 0 - fn_strlen($suffix, $encoding), $encoding); } /* Remove query params Original: http://somehost.com/images/test.jpg?12345678 Bad result: test.jpg?12345678 Correct result: test.jpg */ list($basename) = explode('?', $basename); return $basename; }
exit; } // gateway_fast_registration $post_data['firstname'] = $order_info['b_firstname']; $post_data['lastname'] = $order_info['b_lastname']; $post_data['pay_from_email'] = $order_info['email']; //$post_data['pay_from_email'] = rand(). "@" . rand() . ".com"; // uncomment to test hide login feature $post_data['address'] = $order_info['b_address']; $post_data['address2'] = $order_info['b_address_2']; $post_data['postal_code'] = $order_info['b_zipcode']; $post_data['city'] = $order_info['b_city']; $post_data['state'] = fn_get_state_name($order_info['b_state'], $order_info['b_country']); if (empty($post_data['state'])) { $post_data['state'] = $order_info['b_state']; } if (fn_strlen($post_data['state']) > 50) { $post_data['state'] = fn_substr($post_data['state'], 0, 47) . '...'; } $post_data['country'] = db_get_field('SELECT code_A3 FROM ?:countries WHERE code=?s', $order_info['b_country']); $post_data['phone_number'] = $order_info['phone']; if ($processor_data['processor_params']['quick_checkout'] == 'Y') { $post_data['payment_methods'] = !empty($processor_data['processor_params']['payment_methods']) ? '' : 'ACC'; $post_data['hide_login'] = '******'; } else { $post_data['payment_methods'] = 'WLT'; $post_data['hide_login'] = !empty($suffix) ? '1' : '0'; } // split_gateway if (!empty($processor_data['processor_params']['payment_methods'])) { $post_data['payment_methods'] .= (!empty($post_data['payment_methods']) ? ',' : '') . $processor_data['processor_params']['payment_methods']; }
function fn_sales_repors_format_description($value, $limit, $id) { if (strlen($value) > fn_strlen($value)) { $limit /= 2; } return fn_strlen($value) > $limit ? $id . fn_substr($value, 0, $limit) . "..." : $id . $value; }
function fn_format_long_string($str, $length) { if (fn_strlen($str) <= $length) { return $str; } $length = $length - 3; return fn_substr($str, 0, $length) . '...'; }
function fn_log_event($type, $action, $data = array()) { $object_primary_keys = array('users' => 'user_id', 'orders' => 'order_id', 'products' => 'product_id', 'categories' => 'category_id'); $update = false; $content = array(); $actions = Registry::get('settings.Logging.log_type_' . $type); $cut_log = Registry::ifGet('log_cut', false); Registry::del('log_cut'); $cut_data = Registry::ifGet('log_cut_data', false); Registry::del('log_cut_data'); if (empty($actions) || $action && !empty($actions) && empty($actions[$action]) || !empty($cut_log)) { return false; } if (!empty($_SESSION['auth']['user_id'])) { $user_id = $_SESSION['auth']['user_id']; } else { $user_id = 0; } if ($type == 'users' && $action == 'logout' && !empty($data['user_id'])) { $user_id = $data['user_id']; } if ($user_id) { $udata = db_get_row("SELECT firstname, lastname, email FROM ?:users WHERE user_id = ?i", $user_id); } $event_type = 'N'; // notice if (!empty($data['backtrace'])) { $_btrace = array(); $func = ''; foreach (array_reverse($data['backtrace']) as $v) { if (!empty($v['file'])) { $v['file'] = fn_get_rel_dir($v['file']); } if (empty($v['file'])) { $func = $v['function']; continue; } elseif (!empty($func)) { $v['function'] = $func; $func = ''; } $_btrace[] = array('file' => !empty($v['file']) ? $v['file'] : '', 'line' => !empty($v['line']) ? $v['line'] : '', 'function' => $v['function']); } $data['backtrace'] = serialize($_btrace); } else { $data['backtrace'] = ''; } if ($type == 'general') { if ($action == 'deprecated') { $content['deprecated_function'] = $data['function']; } $content['message'] = $data['message']; } elseif ($type == 'orders') { $order_status_descr = fn_get_simple_statuses(STATUSES_ORDER, true, true); $content = array('order' => '# ' . $data['order_id'], 'id' => $data['order_id']); if ($action == 'status') { $content['status'] = $order_status_descr[$data['status_from']] . ' -> ' . $order_status_descr[$data['status_to']]; } } elseif ($type == 'products') { $product = db_get_field("SELECT product FROM ?:product_descriptions WHERE product_id = ?i AND lang_code = ?s", $data['product_id'], Registry::get('settings.Appearance.backend_default_language')); $content = array('product' => $product . ' (#' . $data['product_id'] . ')', 'id' => $data['product_id']); if ($action == 'low_stock') { // log stock - warning $event_type = 'W'; } } elseif ($type == 'categories') { $category = db_get_field("SELECT category FROM ?:category_descriptions WHERE category_id = ?i AND lang_code = ?s", $data['category_id'], Registry::get('settings.Appearance.backend_default_language')); $content = array('category' => $category . ' (#' . $data['category_id'] . ')', 'id' => $data['category_id']); } elseif ($type == 'database') { if ($action == 'error') { $content = array('error' => $data['error']['message'], 'query' => $data['error']['query']); $event_type = 'E'; } } elseif ($type == 'requests') { if (!empty($cut_data)) { $data['data'] = preg_replace("/\\<(" . implode('|', $cut_data) . ")\\>(.*?)\\<\\/(" . implode('|', $cut_data) . ")\\>/s", '<${1}>******</${1}>', $data['data']); $data['data'] = preg_replace("/%3C(" . implode('|', $cut_data) . ")%3E(.*?)%3C%2F(" . implode('|', $cut_data) . ")%3E/s", '%3C${1}%3E******%3C%2F${1}%3E', $data['data']); $data['data'] = preg_replace("/(" . implode('|', $cut_data) . ")=(.*?)(&)/s", '${1}=******${3}', $data['data']); } $content = array('url' => $data['url'], 'request' => fn_strlen($data['data']) < LOG_MAX_DATA_LENGTH && preg_match('//u', $data['data']) ? $data['data'] : '', 'response' => fn_strlen($data['response']) < LOG_MAX_DATA_LENGTH && preg_match('//u', $data['response']) ? $data['response'] : ''); } elseif ($type == 'users') { if (!empty($data['time'])) { if (empty($_SESSION['log']['login_log_id'])) { return false; } $content = db_get_field('SELECT content FROM ?:logs WHERE log_id = ?i', $_SESSION['log']['login_log_id']); $content = unserialize($content); $minutes = ceil($data['time'] / 60); $hours = floor($minutes / 60); if ($hours) { $minutes -= $hours * 60; } if ($hours || $minutes) { $content['loggedin_time'] = ($hours ? $hours . ' |hours| ' : '') . ($minutes ? $minutes . ' |minutes|' : ''); } if (!empty($data['timeout']) && $data['timeout']) { $content['timeout'] = true; } $update = $_SESSION['log']['login_log_id']; } else { if (!empty($data['user_id'])) { $info = db_get_row("SELECT firstname, lastname, email FROM ?:users WHERE user_id = ?i", $data['user_id']); $content = array('user' => $info['firstname'] . ($info['firstname'] && $info['lastname'] ? ' ' : '') . $info['lastname'] . ($info['firstname'] || $info['lastname'] ? '; ' : '') . $info['email'] . ' (#' . $data['user_id'] . ')'); $content['id'] = $data['user_id']; } elseif (!empty($data['user'])) { $content = array('user' => $data['user']); } if (in_array($action, array('session', 'failed_login'))) { $ip = fn_get_ip(); $content['ip_address'] = empty($data['ip']) ? $ip['host'] : $data['ip']; } } if ($action == 'failed_login') { // failed login - warning $event_type = 'W'; } } fn_set_hook('save_log', $type, $action, $data, $user_id, $content, $event_type, $object_primary_keys); $content = serialize($content); if ($update) { db_query('UPDATE ?:logs SET content = ?s WHERE log_id = ?i', $content, $update); } else { if (Registry::get('runtime.company_id')) { $company_id = Registry::get('runtime.company_id'); } elseif (!empty($object_primary_keys[$type]) && !empty($data[$object_primary_keys[$type]])) { $company_id = fn_get_company_id($type, $object_primary_keys[$type], $data[$object_primary_keys[$type]]); } else { $company_id = 0; } $row = array('user_id' => $user_id, 'timestamp' => TIME, 'type' => $type, 'action' => $action, 'event_type' => $event_type, 'content' => $content, 'backtrace' => $data['backtrace'], 'company_id' => $company_id); $log_id = db_query("INSERT INTO ?:logs ?e", $row); if ($type == 'users' && $action == 'session') { $_SESSION['log']['login_log_id'] = $log_id; } } return true; }
/** * @param array $lang_data * @param string $lang_code * @param array $params * @return array List of updated lang_names */ public static function updateLangVar($lang_data, $lang_code = DESCR_SL, $params = array()) { $error_flag = false; $result = array(); fn_set_hook('update_lang_values', $lang_data, $lang_code, $error_flag, $params, $result); foreach ($lang_data as $k => $v) { if (!empty($v['name'])) { preg_match("/(^[a-zA-z0-9][a-zA-Z0-9_\\.]*)/", $v['name'], $matches); if (fn_strlen($matches[0]) == fn_strlen($v['name'])) { $v['lang_code'] = $lang_code; $res = db_query("REPLACE INTO ?:language_values ?e", $v); if ($res) { $result[] = $v['name']; } } elseif (!$error_flag) { fn_set_notification('E', __('warning'), __('warning_lanvar_incorrect_name')); $error_flag = true; } } } return $result; }
/** * substr() with full UTF-8 support * * @param string $string The input string. * @param integer $start If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. If start is negative, the returned string will start at the start 'th character from the end of string. * @param integer $length If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string ). If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes a position beyond this truncation, an empty string will be returned. * @param integer $encoding The encoding parameter is the character encoding. If it is omitted, UTF-8 character encoding value will be used. * @return mixed Returns the extracted part of string or false if string is less than or equal to start characters long */ function fn_substr($string, $start, $length = null, $encoding = 'UTF-8') { if (empty($encoding)) { $encoding = 'UTF-8'; } if ($length === null) { return fn_substr($string, $start, fn_strlen($string, $encoding), $encoding); } if (function_exists('iconv_substr')) { // there was strange bug in iconv_substr when use negative length parameter // so we recalculate start and length here if ($length < 0) { $length = ceil($length); $len = iconv_strlen($string, $encoding); if ($start < 0) { $start += $len; } $length += $len - $start; } return iconv_substr($string, $start, $length, $encoding); } elseif (function_exists('mb_substr')) { return mb_substr($string, $start, $length, $encoding); } else { preg_match_all('/./su', $string, $ar); return join('', array_slice($ar[0], $start, $length)); } }
function fn_searchanise_get_products_before_select(&$params, &$join, &$condition, &$u_condition, &$inventory_condition, &$sortings, &$total, &$items_per_page, &$lang_code, &$having) { // disable by core if (AREA == 'A' || fn_se_check_disabled() || !empty($params['having']) || !empty($params['disable_searchanise']) || empty($params['search_performed']) || !empty($params['block_data']) || empty($params['q']) && fn_se_get_simple_setting('use_navigation') !== 'Y' || fn_se_get_import_status(fn_se_get_company_id(), $lang_code) != 'done' || !empty($params['pid']) || !empty($params['b_id']) || !empty($params['item_ids']) || !empty($params['feature']) || !empty($params['downloadable']) || !empty($params['tracking']) || !empty($params['shipping_freight_from']) || !empty($params['shipping_freight_to']) || !empty($params['exclude_pid']) || !empty($params['get_query']) || !empty($params['only_short_fields']) || isset($params['supplier_id']) || isset($params['amount_to']) || isset($params['amount_from']) || isset($params['q']) && Registry::get('settings.General.search_objects') || isset($params['compact']) && $params['compact'] == 'Y' || !empty($_REQUEST['sort_by']) && !in_array($_REQUEST['sort_by'], fn_se_get_valid_sortings()) || !empty($params['force_get_by_ids']) && empty($params['pid']) && empty($params['product_id'])) { return; } // disable by addons if (!empty($params['rating']) || !empty($params['bestsellers']) || !empty($params['also_bought_for_product_id']) || !empty($params['for_required_product']) || !empty($params['ppcode']) && $params['ppcode'] == 'Y' || isset($params['tag']) && fn_string_not_empty($params['tag']) || Registry::ifGet('addons.age_verification.status', 'D') == 'A' || Registry::ifGet('addons.vendor_data_premoderation.status', 'D') == 'A' || !empty($params['picker_for']) && $params['picker_for'] == 'gift_certificates') { return; } list($restrict_by, $query_by, $union) = fn_se_prepare_request_params($params); // // Categories // if (!empty($params['cid'])) { $cids = is_array($params['cid']) ? $params['cid'] : array($params['cid']); $c_condition = ''; if (AREA == 'C') { $_c_statuses = array('A', 'H'); // Show enabled categories $cids = db_get_fields("SELECT a.category_id FROM ?:categories as a WHERE a.category_id IN (?n) AND a.status IN (?a)", $cids, $_c_statuses); $c_condition = db_quote('AND a.status IN (?a) AND (' . fn_find_array_in_set(Tygh::$app['session']['auth']['usergroup_ids'], 'a.usergroup_ids', true) . ')', $_c_statuses); } $sub_categories_ids = db_get_fields("SELECT a.category_id FROM ?:categories as a LEFT JOIN ?:categories as b ON b.category_id IN (?n) WHERE a.id_path LIKE CONCAT(b.id_path, '/%') ?p", $cids, $c_condition); $sub_categories_ids = fn_array_merge($cids, $sub_categories_ids, false); if (empty($sub_categories_ids)) { $params['force_get_by_ids'] = true; $params['pid'] = $params['product_id'] = 0; return; } if (!empty($params['subcats']) && $params['subcats'] == 'Y') { $restrict_by['category_id'] = join('|', $sub_categories_ids); } else { $restrict_by['category_id'] = join('|', $cids); } } // // Sortings // if (!empty($_REQUEST['search_performed']) && empty($_REQUEST['sort_by']) && SE_USE_RELEVANCE_AS_DEFAULT_SORTING == 'Y') { $params['sort_by'] = 'relevance'; $params['sort_order'] = 'asc'; } if (!empty($params['sort_by']) && !in_array($params['sort_by'], fn_se_get_valid_sortings())) { return; } if ($params['sort_by'] == 'product') { $sort_by = 'title'; } elseif ($params['sort_by'] == 'relevance') { $params['sort_order'] = 'asc'; $sort_by = 'relevance'; } else { $sort_by = $params['sort_by']; } $sort_order = $params['sort_order'] == 'asc' ? 'asc' : 'desc'; // // Items_per_page // $items_per_page = empty($params['items_per_page']) ? 10 : (int) $params['items_per_page']; if (!empty($params['limit'])) { $max_results = $params['limit']; } else { $max_results = $items_per_page; } $get_items = true; $get_facets = false; if (!fn_allowed_for('ULTIMATE:FREE') && AREA == 'C' && !empty($params['dispatch']) && in_array($params['dispatch'], fn_se_get_facet_valid_locations()) && fn_se_check_product_filter_block() == true) { $get_facets = true; } $request_params = array('sortBy' => $sort_by, 'sortOrder' => $sort_order, 'union' => $union, 'queryBy' => $query_by, 'restrictBy' => $restrict_by, 'items' => $get_items == true ? 'true' : 'false', 'facets' => $get_facets == true ? 'true' : 'false', 'maxResults' => $max_results, 'startIndex' => ($params['page'] - 1) * $items_per_page); if ($request_params['sortBy'] == 'null') { unset($request_params['sortBy']); } if (!empty($params['q']) && fn_strlen($params['q']) > 0) { $request_params['q'] = $params['q']; $request_params['suggestions'] = 'true'; $request_params['query_correction'] = 'false'; $request_params['suggestionsMaxResults'] = 1; } else { $request_params['q'] = ''; } $result = fn_searchanise_send_search_request($request_params, $lang_code); if ($result == false) { //revert to standart sorting if ($params['sort_by'] == 'relevance') { $params['sort_by'] = ''; } Registry::set('runtime.se_use_relevance_sorting', false); return; } if (!empty($result['suggestions']) && count($result['suggestions']) > 0) { $params['suggestion'] = reset($result['suggestions']); } if (!empty($result['items'])) { foreach ($result['items'] as $product) { $params['pid'][] = $product['product_id']; } if ($params['sort_by'] == 'relevance') { $sortings['relevance'] = "FIELD(products.product_id, '" . join("','", $params['pid']) . "')"; $params['sort_order'] = 'asc'; } } else { $products = array(); $params['force_get_by_ids'] = true; $params['pid'] = $params['product_id'] = 0; } if (isset($result['facets'])) { Registry::set('searchanise.received_facets', $result['facets']); } $total = $result['totalItems']; $params['limit'] = $items_per_page; // need to set it manually for proper pagination // reset condition with text search && filtering params - we are get all control under process of text search and filtering $condition = ''; $join = ''; return; }
/** * 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_user - flag indicates that user should be notified * @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_user) { /** * Actions before updating 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_user Flag indicates that user should be notified */ fn_set_hook('update_user_pre', $user_id, $user_data, $auth, $ship_to_another, $notify_user); array_walk($user_data, 'fn_trim_helper'); $register_at_checkout = isset($user_data['register_at_checkout']) && $user_data['register_at_checkout'] == 'Y' ? true : false; if (fn_allowed_for('ULTIMATE')) { if (AREA == 'A' && !empty($user_data['user_type']) && $user_data['user_type'] == 'C' && (empty($user_data['company_id']) || Registry::get('runtime.company_id') && $user_data['company_id'] != Registry::get('runtime.company_id'))) { fn_set_notification('W', __('warning'), __('access_denied')); return false; } } if (!empty($user_id)) { $current_user_data = db_get_row("SELECT user_id, company_id, is_root, status, user_type, email, user_login, lang_code, password, salt, last_passwords" . " FROM ?:users WHERE user_id = ?i", $user_id); if (empty($current_user_data)) { fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('user'))), '', '404'); return false; } if (!fn_check_editable_permissions($auth, $current_user_data)) { fn_set_notification('E', __('error'), __('access_denied')); return false; } if (!empty($user_data['profile_id']) && AREA != 'A') { $profile_ids = db_get_fields("SELECT profile_id FROM ?:user_profiles WHERE user_id = ?i", $user_id); if (!in_array($user_data['profile_id'], $profile_ids)) { fn_set_notification('W', __('warning'), __('access_denied')); return false; } } if ($current_user_data['user_type'] == 'A' && AREA != 'A') { if (isset($user_data['email']) && $user_data['email'] != $current_user_data['email'] || !empty($user_data['password1']) || !empty($user_data['password2'])) { fn_set_notification('E', __('error'), __('error_change_admin_data_in_frontend')); return false; } } if (fn_allowed_for('ULTIMATE')) { if (AREA != 'A' || empty($user_data['company_id'])) { //we should set company_id for the frontdend, in the backend company_id received from form if ($current_user_data['user_type'] == 'A') { if (!isset($user_data['company_id']) || AREA != 'A' || Registry::get('runtime.company_id')) { // reset administrator's company if it was not set to root $user_data['company_id'] = $current_user_data['company_id']; } } elseif (Registry::get('settings.Stores.share_users') == 'Y') { $user_data['company_id'] = $current_user_data['company_id']; } else { $user_data['company_id'] = Registry::ifGet('runtime.company_id', 1); } } } if (fn_allowed_for('MULTIVENDOR')) { if (AREA != 'A') { //we should set company_id for the frontend $user_data['company_id'] = $current_user_data['company_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'); if (fn_allowed_for('ULTIMATE')) { if (!empty($user_data['company_id']) || Registry::get('runtime.company_id') || AREA == 'A') { //company_id can be received when we create user account from the backend $company_id = !empty($user_data['company_id']) ? $user_data['company_id'] : Registry::get('runtime.company_id'); if (empty($company_id)) { $company_id = fn_check_user_type_admin_area($user_data['user_type']) ? $user_data['company_id'] : fn_get_default_company_id(); } $user_data['company_id'] = $current_user_data['company_id'] = $company_id; } else { fn_set_notification('W', __('warning'), __('access_denied')); return false; } } $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'] : ''; $current_user_data['salt'] = !empty($current_user_data['salt']) ? $current_user_data['salt'] : ''; // Set the user type $user_data['user_type'] = fn_check_user_type($user_data, $current_user_data); if (Registry::get('runtime.company_id') && !fn_allowed_for('ULTIMATE') && (!fn_check_user_type_admin_area($user_data['user_type']) || isset($current_user_data['company_id']) && $current_user_data['company_id'] != Registry::get('runtime.company_id'))) { fn_set_notification('W', __('warning'), __('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 // FIXME if (!isset($user_data['email'])) { $user_data['email'] = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $user_id); } $is_exist = fn_is_user_exists($user_id, $user_data); if ($is_exist) { fn_set_notification('E', __('error'), __('error_user_exists'), '', 'user_exist'); return false; } // Check the passwords if (!empty($user_data['password1']) || !empty($user_data['password2'])) { $original_password = trim($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(Tygh::$app['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', __('error'), __('error_passwords_dont_match')); } // PCI DSS Compliance if (fn_check_user_type_admin_area($user_data['user_type'])) { $msg = array(); // Check password length $min_length = Registry::get('settings.Security.min_admin_password_length'); if (fn_strlen($user_data['password1']) < $min_length || fn_strlen($user_data['password2']) < $min_length) { $valid_passwords = false; $msg[] = str_replace("[number]", $min_length, __('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[] = __('error_password_content'); } } if ($msg) { fn_set_notification('E', __('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(Tygh::$app['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(fn_generate_salted_password($user_data['password1'], $current_user_data['salt']), $prev_passwords)) { $valid_passwords = false; fn_set_notification('E', __('error'), __('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) { return false; } $user_data['salt'] = fn_generate_salt(); $user_data['password'] = fn_generate_salted_password($user_data['password1'], $user_data['salt']); 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'] = Tygh::$app['session']['auth']['password_change_timestamp'] = TIME; } unset(Tygh::$app['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.Checkout.address_position') == 'billing_first') { $main_address_zone = BILLING_ADDRESS_PREFIX; $alt_address_zone = SHIPPING_ADDRESS_PREFIX; } else { $main_address_zone = SHIPPING_ADDRESS_PREFIX; $alt_address_zone = BILLING_ADDRESS_PREFIX; } $user_data = fn_fill_contact_info_from_address($user_data, $main_address_zone, $alt_address_zone); if (!fn_allowed_for('ULTIMATE')) { //for ult company_id was set before fn_set_company_id($user_data); } if (!empty($current_user_data['is_root']) && $current_user_data['is_root'] == 'Y') { $user_data['is_root'] = 'Y'; } else { $user_data['is_root'] = 'N'; } // check if it is a root admin $is_root_admin_exists = db_get_field("SELECT user_id FROM ?:users WHERE company_id = ?i AND is_root = 'Y' AND user_id != ?i", $user_data['company_id'], !empty($user_id) ? $user_id : 0); $user_data['is_root'] = empty($is_root_admin_exists) && $user_data['user_type'] !== 'C' ? 'Y' : 'N'; unset($user_data['user_id']); if (!empty($user_id)) { db_query("UPDATE ?:users SET ?u WHERE user_id = ?i", $user_data, $user_id); fn_clean_usergroup_links($user_id, $current_user_data['user_type'], $user_data['user_type']); fn_log_event('users', 'update', array('user_id' => $user_id)); } else { if (!isset($user_data['password_change_timestamp'])) { $user_data['password_change_timestamp'] = 1; } $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['password1'])) { if (!fn_compare_login_password($user_data, $user_data['password1'])) { fn_delete_notification('insecure_password'); } else { $lang_var = 'warning_insecure_password_email'; fn_set_notification('E', __('warning'), __($lang_var, array('[link]' => fn_url("profiles.update?user_id=" . $user_id))), 'K', '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); } $user_data['profile_id'] = fn_update_user_profile($user_id, $user_data, $action); $user_data = fn_get_user_info($user_id, true, $user_data['profile_id']); if ($register_at_checkout) { $user_data['register_at_checkout'] = 'Y'; } $lang_code = AREA == 'A' && !empty($user_data['lang_code']) ? $user_data['lang_code'] : CART_LANGUAGE; if (!fn_allowed_for('ULTIMATE:FREE')) { $user_data['usergroups'] = db_get_hash_array("SELECT lnk.link_id, lnk.usergroup_id, lnk.status, a.type, b.usergroup" . " FROM ?:usergroup_links as lnk" . " INNER JOIN ?:usergroups as a ON a.usergroup_id = lnk.usergroup_id AND a.status != 'D'" . " LEFT JOIN ?:usergroup_descriptions as b ON b.usergroup_id = a.usergroup_id AND b.lang_code = ?s" . " WHERE a.status = 'A' AND lnk.user_id = ?i AND lnk.status != 'D' AND lnk.status != 'F'", 'usergroup_id', $lang_code, $user_id); } // Send notifications to customer if (!empty($notify_user)) { $from = 'company_users_department'; if (fn_allowed_for('MULTIVENDOR')) { // Vendor administrator's notification // is sent from root users department if ($user_data['user_type'] == 'V') { $from = 'default_company_users_department'; } } // Notify customer about profile activation (when update profile only) if ($action == 'update' && $current_user_data['status'] === 'D' && $user_data['status'] === 'A') { Mailer::sendMail(array('to' => $user_data['email'], 'from' => $from, 'data' => array('user_data' => $user_data), 'tpl' => 'profiles/profile_activated.tpl', 'company_id' => $user_data['company_id']), fn_check_user_type_admin_area($user_data['user_type']) ? 'A' : 'C', $lang_code); } // Notify customer about profile add/update $prefix = $action == 'add' ? 'create' : 'update'; // Send password to user only if it was created by admin or vendor if (AREA != 'C' && $auth['user_id'] != $user_id) { $password = $original_password; } else { $password = null; } Mailer::sendMail(array('to' => $user_data['email'], 'from' => $from, 'data' => array('password' => $password, 'user_data' => $user_data), 'tpl' => 'profiles/' . $prefix . '_profile.tpl', 'company_id' => $user_data['company_id']), fn_check_user_type_admin_area($user_data['user_type']) ? 'A' : 'C', $lang_code); } if ($action == 'add') { if (AREA != 'A') { if (Registry::get('settings.General.approve_user_profiles') == 'Y') { fn_set_notification('W', __('important'), __('text_profile_should_be_approved')); // Notify administrator about new profile Mailer::sendMail(array('to' => 'company_users_department', 'from' => 'company_users_department', 'reply_to' => $user_data['email'], 'data' => array('user_data' => $user_data), 'tpl' => 'profiles/activate_profile.tpl', 'company_id' => $user_data['company_id']), 'A', Registry::get('settings.Appearance.backend_default_language')); } else { fn_set_notification('N', __('information'), __('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']); } } } else { if (AREA == 'C') { fn_set_notification('N', __('information'), __('text_profile_is_updated')); } } fn_set_hook('update_profile', $action, $user_data, $current_user_data); return array($user_id, !empty($user_data['profile_id']) ? $user_data['profile_id'] : false); }
function fn_basename($path, $suffix = '', $encoding = 'UTF-8') { $basename = explode("/", $path); $basename = end($basename); if (!empty($suffix) && fn_substr($basename, 0 - fn_strlen($suffix, $encoding), fn_strlen($basename, $encoding), $encoding) == $suffix) { $basename = fn_substr($basename, 0, 0 - fn_strlen($suffix, $encoding), $encoding); } return $basename; }
function fn_sales_repors_format_description($value, $limit, $id) { return $limit !== null && fn_strlen($value) > $limit ? $id . fn_substr($value, 0, $limit) . "..." : $id . $value; }
function fn_ult_update_lang_values(&$lang_data, &$lang_code, &$error_flag, &$params, &$result) { if (Registry::get('runtime.company_id')) { foreach ($lang_data as $k => $v) { if (!empty($v['name'])) { preg_match("/(^[a-zA-z0-9][a-zA-Z0-9_]*)/", $v['name'], $matches); if (fn_strlen($matches[0]) == fn_strlen($v['name'])) { $v['lang_code'] = $lang_code; $v['company_id'] = Registry::get('runtime.company_id'); db_query("REPLACE INTO ?:ult_language_values ?e", $v); // Check if variable not exists in General language variables $exists = db_get_field('SELECT value FROM ?:language_values WHERE name = ?s AND lang_code = ?s', $v['name'], $lang_code); if (!isset($exists) || empty($exists)) { // Create language variable with empty content for other companies $lang_data[$k]['value'] = ''; } } elseif (!$error_flag) { fn_set_notification('E', __('warning'), __('warning_lanvar_incorrect_name')); $error_flag = true; } $result[] = $v['name']; } if (!isset($params['clear']) || $params['clear']) { unset($lang_data[$k]); } } } else { $overwrite = array(); foreach ($lang_data as $k => $v) { if (!empty($v['name']) && !empty($v['overwrite']) && $v['overwrite'] == 'Y') { $overwrite[] = $v['name']; } } if (!empty($overwrite)) { db_query('DELETE FROM ?:ult_language_values WHERE name IN (?a) AND lang_code = ?s', $overwrite, $lang_code); } } }