function fn_restore_dump($files) { if (empty($files)) { return false; } fn_set_progress('parts', sizeof($files)); foreach ($files as $file) { $is_archive = false; $list = array($file); if (in_array(fn_get_file_ext($file), array('zip', 'tgz'))) { $is_archive = true; fn_decompress_files(Registry::get('config.dir.database') . $file, Registry::get('config.dir.database') . '_tmp'); $list = fn_get_dir_contents(Registry::get('config.dir.database') . '_tmp', false, true, 'sql', '_tmp/'); } foreach ($list as $_file) { db_import_sql_file(Registry::get('config.dir.database') . $_file); } if ($is_archive) { fn_rm(Registry::get('config.dir.database') . '_tmp'); } } // Log database restore fn_log_event('database', 'restore'); fn_set_hook('database_restore', $files); fn_clear_cache(); return true; }
if (defined('AJAX_REQUEST') && empty($auth)) { exit; } if (empty($auth['user_id'])) { return array(CONTROLLER_STATUS_REDIRECT, $index_script); } fn_add_breadcrumb(fn_get_lang_var('my_account')); $profile_id = 0; $user_data = fn_get_user_info($auth['user_id'], true, $profile_id); $view->assign('user_data', $user_data); $view->assign('view_mode', 'simple'); } elseif ($mode == 'change_login') { $auth = $_SESSION['auth']; if (!empty($auth['user_id'])) { // Log user logout fn_log_event('users', 'session', array('user_id' => $auth['user_id'], 'time' => TIME - $auth['this_login'], 'timeout' => false)); } unset($_SESSION['auth'], $_SESSION['cart']['user_data']); fn_delete_cookies(AREA_NAME . '_user_id', AREA_NAME . '_password'); return array(CONTROLLER_STATUS_OK, fn_url('checkout.checkout')); } function fn_auth_routines($request) { $status = true; $user_login = $_REQUEST['user_login']; $password = $_POST['password']; $field = Registry::get('settings.General.use_email_as_login') == 'Y' ? 'email' : 'user_login'; $user_data = db_get_row("SELECT * FROM ?:users WHERE {$field} = ?s", $user_login); if (!empty($user_data)) { $user_data['usergroups'] = fn_get_user_usergroups($user_data['user_id']); }
/** * Exports database to file * * @param string $file_name path to file will be created * @param array $dbdump_tables List of tables to be exported * @param bool $dbdump_schema Export database schema * @param bool $dbdump_data Export tatabase data * @param bool $log Log database export action * @param bool $show_progress Show or do not show process by printing ' .' * @param bool $move_progress_bar Move COMET progress bar or not on show progress * @param array $change_table_prefix Array with 2 keys (from, to) to change table prefix * @return bool false, if file is not accessible */ function db_export_to_file($file_name, $dbdump_tables, $dbdump_schema, $dbdump_data, $log = true, $show_progress = true, $move_progress_bar = true, $change_table_prefix = array()) { $fd = @fopen($file_name, 'w'); if (!$fd) { fn_set_notification('E', __('error'), __('dump_cant_create_file')); return false; } if ($log) { // Log database backup fn_log_event('database', 'backup'); } // set export format Database::query("SET @SQL_MODE = 'MYSQL323'"); $create_statements = array(); $insert_statements = array(); if ($show_progress && $move_progress_bar) { fn_set_progress('step_scale', sizeof($dbdump_tables) * ((int) $dbdump_schema + (int) $dbdump_data)); } // get status data $t_status = Database::getHash("SHOW TABLE STATUS", 'Name'); foreach ($dbdump_tables as $k => $table) { $_table = !empty($change_table_prefix) ? str_replace($change_table_prefix['from'], $change_table_prefix['to'], $table) : $table; if ($dbdump_schema) { if ($show_progress) { fn_set_progress('echo', '<br />' . __('backupping_schema') . ': <b>' . $table . '</b>', $move_progress_bar); } fwrite($fd, "\nDROP TABLE IF EXISTS " . $_table . ";\n"); $scheme = Database::getRow("SHOW CREATE TABLE {$table}"); $_scheme = array_pop($scheme); if ($change_table_prefix) { $_scheme = str_replace($change_table_prefix['from'], $change_table_prefix['to'], $_scheme); } fwrite($fd, $_scheme . ";\n\n"); } if ($dbdump_data) { if ($show_progress) { fn_set_progress('echo', '<br />' . __('backupping_data') . ': <b>' . $table . '</b> ', $move_progress_bar); } $total_rows = Database::getField("SELECT COUNT(*) FROM {$table}"); // Define iterator if (!empty($t_status[$table]) && $t_status[$table]['Avg_row_length'] < DB_MAX_ROW_SIZE) { $it = DB_ROWS_PER_PASS; } else { $it = 1; } for ($i = 0; $i < $total_rows; $i = $i + $it) { $table_data = Database::getArray("SELECT * FROM {$table} LIMIT {$i}, {$it}"); foreach ($table_data as $_tdata) { $_tdata = fn_add_slashes($_tdata, true); $values = array(); foreach ($_tdata as $v) { $values[] = $v !== null ? "'{$v}'" : 'NULL'; } fwrite($fd, "INSERT INTO {$_table} (`" . implode('`, `', array_keys($_tdata)) . "`) VALUES (" . implode(', ', $values) . ");\n"); } if ($show_progress) { fn_echo(' .'); } } } } fclose($fd); @chmod($file_name, DEFAULT_FILE_PERMISSIONS); return true; }
function fn_twg_api_customer_logout() { // copied from common/auth.php - logout mode $auth = $_SESSION['auth']; fn_save_cart_content($_SESSION['cart'], $auth['user_id']); if (!empty($auth['user_id'])) { // Log user logout fn_log_event('users', 'session', array('user_id' => $auth['user_id'], 'time' => TIME - $auth['this_login'], 'timeout' => false)); } unset($_SESSION['auth']); fn_clear_cart($_SESSION['cart'], false, true); fn_delete_session_data(fn_get_area_name() . '_user_id', fn_get_area_name() . '_password'); return true; }
/** * Restores backup file * * @param string $filename File to be restored * @param string $base_path Base folder path (default: dir.backups) * @return bool true if restored, error code if errors */ public static function restore($filename, $base_path = '') { $file_ext = fn_get_file_ext($filename); if (!in_array($file_ext, array('sql', 'tgz', 'zip'))) { return __(self::ERROR_UNSUPPORTED_FILE_TYPE); } if (empty($base_path)) { $base_path = Registry::get('config.dir.backups'); } $backup_path = $base_path . basename($filename); if (in_array($file_ext, array('zip', 'tgz'))) { $type = self::getArchiveType($backup_path); $extract_path = fn_get_cache_path(false) . 'tmp/backup/'; fn_rm($extract_path); fn_mkdir($extract_path); if ($type == 'database') { fn_decompress_files($backup_path, $extract_path); $list = fn_get_dir_contents($extract_path, false, true, 'sql'); foreach ($list as $sql_file) { db_import_sql_file($extract_path . $sql_file); } } else { $root_dir = Registry::get('config.dir.root') . '/'; $files_list = self::getCompressedFilesList($backup_path); // Check permissions on all files foreach ($files_list as $file) { if (!self::checkWritable($root_dir . $file)) { return __(self::ERROR_UNWRITABLE_FILE, array('[file]' => $root_dir . $file, '[url]' => fn_url('settings.manage?section_id=Upgrade_center'))); } fn_set_progress('echo', __('check_permissions') . ': ' . $file . '<br>', true); } // All files can be overrided. Restore backupped files fn_decompress_files($backup_path, $extract_path); $root_dir = Registry::get('config.dir.root') . '/'; foreach ($files_list as $file) { $ext = fn_get_file_ext($file); if ($ext == 'sql' && strpos($file, 'var/restore/') !== false) { // This is a DB dump. Restore it db_import_sql_file($extract_path . $file); continue; } fn_set_progress('echo', __('restore') . ': ' . $file . '<br>', true); self::restoreFile($extract_path . $file, $root_dir . $file); } fn_rm($extract_path); return true; } } else { db_import_sql_file($backup_path); } fn_log_event('database', 'restore'); fn_clear_cache(); return true; }
function fn_error($debug_data, $error = '', $is_db = true) { $auth =& $_SESSION['auth']; $debug_data = array_reverse($debug_data, true); if (file_exists(DIR_ROOT . '/bug_report.php')) { $bug_report = true; } if (!empty($bug_report)) { ob_start(); } if (!empty($error) && $is_db == true) { // Log database errors fn_log_event('database', 'error', array('error' => $error, 'backtrace' => $debug_data)); echo <<<EOT <p><b><span style='font-weight: bold; color: #000000; font-size: 13px; font-family: Courier;'>Database error:</span></b> {$error['message']}<br> <b><span style='font-weight: bold; color: #000000; font-size: 13px; font-family: Courier;'>Invalid query:</span></b> {$error['query']}</p> EOT; } elseif (!empty($error)) { echo <<<EOT <p><b><span style='font-weight: bold; color: #000000; font-size: 13px; font-family: Courier;'>Error:</span></b> {$error}<br> EOT; } echo <<<EOU <hr noshade width='100%'> <p><span style='font-weight: bold; color: #000000; font-size: 13px; font-family: Courier;'>Backtrace:</span> <table cellspacing='1'> EOU; $i = 0; if (!empty($debug_data)) { $func = ''; foreach (array_reverse($debug_data) as $v) { if (empty($v['file'])) { $func = $v['function']; continue; } elseif (!empty($func)) { $v['function'] = $func; $func = ''; } $i = $i == 0 ? 1 : 0; $color = $i == 0 ? "#DDDDDD" : "#EEEEEE"; echo "<tr bgcolor='{$color}'><td style='text-decoration: underline;'>File:</td><td>{$v['file']}</td></tr>"; echo "<tr bgcolor='{$color}'><td style='text-decoration: underline;'>Line:</td><td>{$v['line']}</td></tr>"; echo "<tr bgcolor='{$color}'><td style='text-decoration: underline;'>Function:</td><td>{$v['function']}</td></tr>"; } } echo '</table>'; if (!empty($bug_report)) { $debug = ob_get_clean(); include DIR_ROOT . '/bug_report.php'; } exit; }
/** * Add a record to the log if the user session is expired * * @param array $entry - session record * @return bool Always true */ function fn_log_user_logout($entry, $data) { if (!empty($data['auth']) && $data['auth']['user_id']) { $this_login = empty($data['auth']['this_login']) ? 0 : $data['auth']['this_login']; // Log user logout fn_log_event('users', 'session', array('user_id' => $data['auth']['user_id'], 'ip' => empty($data['auth']['ip']) ? '' : $data['auth']['ip'], 'time' => $entry['expiry'] - $this_login, 'timeout' => true, 'expiry' => $entry['expiry'])); } return true; }
/** * @param array $auth */ function fn_user_logout($auth) { // Regenerate session_id for security reasons fn_save_cart_content($_SESSION['cart'], $auth['user_id']); Session::regenerateId(); fn_init_user(); $auth = $_SESSION['auth']; if (!empty($auth['user_id'])) { // Log user logout fn_log_event('users', 'session', array('user_id' => $auth['user_id'], 'time' => TIME - $auth['this_login'], 'timeout' => false)); } unset($_SESSION['auth']); fn_clear_cart($_SESSION['cart'], false, true); fn_delete_session_data(AREA . '_user_id', AREA . '_password'); unset($_SESSION['product_notifications']); fn_login_user(); // need to fill $_SESSION['auth'] array for anonymous user }
/** * Add a record to the log if the user session is expired * * @param array $auth - user auth data * @param integer $expiry - expiration time * @return bool Always true */ function fn_log_user_logout($auth, $expiry = TIME) { if (!empty($auth) && $auth['user_id']) { $this_login = empty($auth['this_login']) ? 0 : $auth['this_login']; // Log user logout fn_log_event('users', 'session', array('user_id' => $auth['user_id'], 'ip' => empty($auth['ip']) ? '' : $auth['ip'], 'time' => $expiry - $this_login, 'timeout' => true, 'expiry' => $expiry)); } return true; }
/** * Function delete order * * @param int $order_id */ function fn_delete_order($order_id) { // Log order deletion fn_log_event('orders', 'delete', array('order_id' => $order_id)); fn_change_order_status($order_id, STATUS_INCOMPLETED_ORDER, '', fn_get_notification_rules(array(), false)); // incomplete to increase inventory fn_set_hook('delete_order', $order_id); db_query("DELETE FROM ?:new_orders WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:order_data WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:order_details WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:orders WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:product_file_ekeys WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:profile_fields_data WHERE object_id = ?i AND object_type='O'", $order_id); db_query("DELETE FROM ?:order_docs WHERE order_id = ?i", $order_id); }
public function generate($filepath = '') { @ignore_user_abort(1); @set_time_limit(0); register_shutdown_function(array($this, 'shutdownHandler')); if (!empty($filepath)) { $this->filepath_temp = $filepath; } fn_mkdir(dirname($this->filepath_temp)); $continue = false; if (file_exists($this->filepath_temp) && $this->offset > 0) { $continue = true; } if ($continue) { $this->log->write(Logs::INFO, '', 'Continue ' . date('d.m.Y H:i:s', time()) . '. Offset ' . $this->offset); } else { $status_generate = fn_get_storage_data('yml2_status_generate_' . $this->price_id); if ($status_generate == 'active' && file_exists($this->filepath_temp)) { fn_echo(__("yml_export.generation_was_started")); exit; } fn_rm($this->filepath_temp); $this->offset = 0; $this->log->write(Logs::INFO, '', 'Start ' . date('d.m.Y H:i:s', time())); fn_set_storage_data('yml2_export_start_time_' . $this->price_id, time()); } fn_set_storage_data('yml2_status_generate_' . $this->price_id, 'active'); $file = fopen($this->filepath_temp, 'ab'); if (!$continue) { $this->head($file); } $this->body($file); $this->bottom($file); fclose($file); $this->log->write(Logs::INFO, '', 'Finish ' . date('d.m.Y H:i:s', time())); $this->log->write(Logs::INFO, '', 'Product export ' . $this->yml2_product_export . '. Product skip ' . $this->yml2_product_skip); $data = array('[export]' => $this->yml2_product_export, '[skip]' => $this->yml2_product_skip, '[cron]' => defined('CONSOLE') ? 'Cron. ' : ''); fn_log_event('yml_export', 'export', array('message' => __('text_log_action_export', $data))); if ($this->options['detailed_generation'] == 'Y') { $path = $this->log->getTempLogFile(); if ($path) { $log = fopen($path, 'r'); $line = fgets($log); $info_line = true; while (!feof($log)) { $line = fgets($log); if (empty($line)) { continue; } $data = explode(';', $line); if ($data[0] == '[INFO]' && !$info_line) { fn_echo(NEW_LINE); } elseif ($data[0] != '[INFO]' && $info_line) { fn_echo(NEW_LINE); } $data[1] = isset($data[1]) ? $data[1] : ''; $data[2] = isset($data[2]) ? $data[2] : ''; fn_echo($data[0] . $data[1] . $data[2] . NEW_LINE); $info_line = $data[0] == '[INFO]'; } fclose($log); } } $this->log->rotate(); if (empty($filepath)) { $this->backupYml(); if (file_exists($this->filepath_temp)) { fn_rm($this->filepath); fn_rename($this->filepath_temp, $this->filepath); } } fn_set_storage_data('yml2_product_export_' . $this->price_id); fn_set_storage_data('yml2_product_skip_' . $this->price_id); fn_set_storage_data('yml2_export_start_time_' . $this->price_id); fn_set_storage_data('yml2_export_count_' . $this->price_id); fn_set_storage_data('yml2_export_offset_' . $this->price_id); fn_set_storage_data('yml2_export_time_' . $this->price_id, time()); fn_set_storage_data('yml2_status_generate_' . $this->price_id, 'finish'); }
/** * Set event to log * @param string $type * @param string $action * @param array $data */ protected static function logEvent($type, $action, array $data = array()) { fn_log_event($type, $action, $data); }
function fn_update_news($news_id, $news_data, $lang_code = CART_LANGUAGE) { // news title required if (empty($news_data['news'])) { return false; } $_data = $news_data; $_data['date'] = fn_parse_date($news_data['date']); if (isset($_data['localization'])) { $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']); } if (empty($news_id)) { $create = true; $news_id = $_data['news_id'] = db_query("REPLACE INTO ?:news ?e", $_data); if (empty($news_id)) { return false; } // Adding descriptions foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) { db_query("INSERT INTO ?:news_descriptions ?e", $_data); } } else { if (!empty($news_data['block_id'])) { fn_add_items_to_block($news_data['block_id'], $news_data['add_items'], $news_id, 'news'); } db_query("UPDATE ?:news SET ?u WHERE news_id = ?i", $_data, $news_id); // update news descriptions $_data = $news_data; db_query("UPDATE ?:news_descriptions SET ?u WHERE news_id = ?i AND lang_code = ?s", $_data, $news_id, $lang_code); } // Log news update/add fn_log_event('news', !empty($create) ? 'create' : 'update', array('news_id' => $news_id)); fn_set_hook('update_news', $news_data, $news_id, $lang_code); return $news_id; }
if (!empty($cart['failed_order_id'])) { $_msg = !empty($_payment_info['reason_text']) ? $_payment_info['reason_text'] : ''; $_msg .= empty($_msg) ? __('text_order_placed_error') : ''; fn_set_notification('O', '', $_msg); $cart['processed_order_id'] = $cart['failed_order_id']; unset($cart['failed_order_id']); } unset($_payment_info['card_number'], $_payment_info['cvv2']); $cart['payment_info'] = $_payment_info; if (!empty($cart['extra_payment_info'])) { $cart['payment_info'] = array_merge($cart['payment_info'], $cart['extra_payment_info']); } } } if ($mode == 'change_login') { $auth = $_SESSION['auth']; if (!empty($auth['user_id'])) { fn_log_event('users', 'session', array('user_id' => $auth['user_id'], 'time' => TIME - $auth['this_login'], 'timeout' => false, 'company_id' => fn_get_company_id('users', 'user_id', $auth['user_id']))); } unset($_SESSION['auth'], $_SESSION['cart']['user_data']); fn_delete_session_data(AREA . '_user_id', AREA . '_password'); return array(CONTROLLER_STATUS_OK, 'onestepcheckout.checkout'); } if (!empty($profile_fields)) { Registry::get('view')->assign('profile_fields', $profile_fields); } Registry::get('view')->assign('cart', $cart); Registry::get('view')->assign('continue_url', empty($_SESSION['continue_url']) ? '' : $_SESSION['continue_url']); Registry::get('view')->assign('mode', $mode); Registry::get('view')->assign('payment_methods', $payment_methods); $_SESSION['checkout_mode'] = $mode;
/** * Generates error notification * * @param string $action Action thae was happen * @param string $reason Reason, why the error notification must be showed * @param string $table Table name (optional) * @return bool Always true */ private function _generateError($action, $reason, $table = '') { $message = str_replace("[reason]", $reason, $action); if (!empty($table)) { $message = str_replace("[table]", $table, $message); } fn_log_event('settings', 'error', $message); if (Debugger::isActive() || fn_is_development()) { fn_set_notification('E', __('error'), $message); } return true; }
$suffix = ''; if ($mode == 'm_delete' && !empty($_REQUEST['order_ids'])) { foreach ($_REQUEST['order_ids'] as $v) { fn_delete_order($v); } } if ($mode == 'update_details') { fn_trusted_vars('update_order'); // Update customer's email if its changed in customer's account if (!empty($_REQUEST['update_customer_details']) && $_REQUEST['update_customer_details'] == 'Y') { $u_id = db_get_field("SELECT user_id FROM ?:orders WHERE order_id = ?i", $_REQUEST['order_id']); $current_email = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $u_id); db_query("UPDATE ?:orders SET email = ?s WHERE order_id = ?i", $current_email, $_REQUEST['order_id']); } // Log order update fn_log_event('orders', 'update', array('order_id' => $_REQUEST['order_id'])); db_query('UPDATE ?:orders SET ?u WHERE order_id = ?i', $_REQUEST['update_order'], $_REQUEST['order_id']); //Update shipping info if (!empty($_REQUEST['update_shipping'])) { foreach ($_REQUEST['update_shipping'] as $group_key => $shipment) { $shipment['shipment_data']['order_id'] = $_REQUEST['order_id']; $shipment_id = isset($shipment['shipment_id']) ? $shipment['shipment_id'] : 0; fn_update_shipment($shipment['shipment_data'], $shipment_id, $group_key, true); } } // Add new shipping info /*if (!empty($_REQUEST['add_shipping'])) { $shipping = db_get_field('SELECT shipping FROM ?:shipping_descriptions WHERE shipping_id = ?i', $_REQUEST['add_shipping']['shipping_id']); $shippings[$_REQUEST['add_shipping']['shipping_id']] = array( 'shipping' => $shipping, 'tracking_number' => $_REQUEST['add_shipping']['tracking_number'],
function fn_update_product($product_data, $product_id = 0, $lang_code = CART_LANGUAGE) { $_data = $product_data; if (!empty($product_data['timestamp'])) { $_data['timestamp'] = fn_parse_date($product_data['timestamp']); // Minimal data for product record } if (!empty($product_data['avail_since'])) { $_data['avail_since'] = fn_parse_date($product_data['avail_since']); } if (isset($product_data['tax_ids'])) { $_data['tax_ids'] = empty($product_data['tax_ids']) ? '' : fn_create_set($product_data['tax_ids']); } if (isset($product_data['localization'])) { $_data['localization'] = empty($product_data['localization']) ? '' : fn_implode_localizations($_data['localization']); } if (isset($product_data['usergroup_ids'])) { $_data['usergroup_ids'] = empty($product_data['usergroup_ids']) ? '' : implode(',', $_data['usergroup_ids']); } if (Registry::get('settings.General.allow_negative_amount') == 'N' && isset($_data['amount'])) { $_data['amount'] = abs($_data['amount']); } // add new product if (empty($product_id)) { $create = true; // product title can't be empty if (empty($product_data['product'])) { return false; } $product_id = db_query("INSERT INTO ?:products ?e", $_data); if (empty($product_id)) { return false; } // // Adding same product descriptions for all cart languages // $_data = $product_data; $_data['product_id'] = $product_id; $_data['product'] = trim($_data['product'], " -"); foreach ((array) Registry::get('languages') as $_data['lang_code'] => $_v) { db_query("INSERT INTO ?:product_descriptions ?e", $_data); } // update product } else { if (isset($product_data['product']) && empty($product_data['product'])) { unset($product_data['product']); } db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", $_data, $product_id); $_data = $product_data; if (!empty($_data['product'])) { $_data['product'] = trim($_data['product'], " -"); } db_query("UPDATE ?:product_descriptions SET ?u WHERE product_id = ?i AND lang_code = ?s", $_data, $product_id, $lang_code); } // Log product add/update fn_log_event('products', !empty($create) ? 'create' : 'update', array('product_id' => $product_id)); if (!empty($product_data['product_features'])) { $i_data = array('product_id' => $product_id, 'lang_code' => $lang_code); foreach ($product_data['product_features'] as $feature_id => $value) { // Check if feature is applicable for this product $id_paths = db_get_fields("SELECT ?:categories.id_path FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id WHERE product_id = ?i", $product_id); $_params = array('category_ids' => array_unique(explode('/', implode('/', $id_paths))), 'feature_id' => $feature_id); list($_feature) = fn_get_product_features($_params); if (empty($_feature)) { $_feature = db_get_field("SELECT description FROM ?:product_features_descriptions WHERE feature_id = ?i AND lang_code = ?s", $feature_id, CART_LANGUAGE); $_product = db_get_field("SELECT product FROM ?:product_descriptions WHERE product_id = ?i AND lang_code = ?s", $product_id, CART_LANGUAGE); fn_set_notification('E', fn_get_lang_var('error'), str_replace(array('[feature_name]', '[product_name]'), array($_feature, $_product), fn_get_lang_var('product_feature_cannot_assigned'))); continue; } $i_data['feature_id'] = $feature_id; unset($i_data['value']); unset($i_data['variant_id']); unset($i_data['value_int']); $feature_type = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $feature_id); // Delete variants in current language if ($feature_type == 'T') { db_query("DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id = ?i AND lang_code = ?s", $feature_id, $product_id, $lang_code); } else { db_query("DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id = ?i", $feature_id, $product_id); } if ($feature_type == 'D') { $i_data['value_int'] = fn_parse_date($value); } elseif ($feature_type == 'M') { if (!empty($product_data['add_new_variant'][$feature_id]['variant'])) { $value = empty($value) ? array() : $value; $value[] = fn_add_feature_variant($feature_id, $product_data['add_new_variant'][$feature_id]); } if (!empty($value)) { foreach ($value as $variant_id) { foreach (Registry::get('languages') as $i_data['lang_code'] => $_d) { // insert for all languages $i_data['variant_id'] = $variant_id; db_query("REPLACE INTO ?:product_features_values ?e", $i_data); } } } continue; } elseif (in_array($feature_type, array('S', 'N', 'E'))) { if (!empty($product_data['add_new_variant'][$feature_id]['variant'])) { $i_data['variant_id'] = fn_add_feature_variant($feature_id, $product_data['add_new_variant'][$feature_id]); } elseif (!empty($value) && $value != 'disable_select') { if ($feature_type == 'N') { $i_data['value_int'] = db_get_field("SELECT variant FROM ?:product_feature_variant_descriptions WHERE variant_id = ?i AND lang_code = ?s", $value, CART_LANGUAGE); } $i_data['variant_id'] = $value; } else { continue; } } else { if ($value == '') { continue; } if ($feature_type == 'O') { $i_data['value_int'] = $value; } else { $i_data['value'] = $value; } } if ($feature_type != 'T') { // feature values are common for all languages, except text (T) foreach (Registry::get('languages') as $i_data['lang_code'] => $_d) { db_query("REPLACE INTO ?:product_features_values ?e", $i_data); } } else { // for text feature, update current language only $i_data['lang_code'] = $lang_code; db_query("INSERT INTO ?:product_features_values ?e", $i_data); } } } // Update product prices if (isset($product_data['price'])) { if (!isset($product_data['prices'])) { $product_data['prices'] = array(); $skip_price_delete = true; } $_price = array('price' => abs($product_data['price']), 'lower_limit' => 1); array_unshift($product_data['prices'], $_price); } if (!empty($product_data['prices'])) { if (empty($skip_price_delete)) { db_query("DELETE FROM ?:product_prices WHERE product_id = ?i", $product_id); } foreach ($product_data['prices'] as $v) { if (!empty($v['lower_limit'])) { $v['product_id'] = $product_id; db_query("REPLACE INTO ?:product_prices ?e", $v); } } } if (!empty($product_data['popularity'])) { $_data = array('product_id' => $product_id, 'total' => intval($product_data['popularity'])); db_query("INSERT INTO ?:product_popularity ?e ON DUPLICATE KEY UPDATE total = ?i", $_data, $product_data['popularity']); } fn_set_hook('update_product', $product_data, $product_id, $lang_code); return $product_id; }
/** * Display database error * * @param resource $result result, returned by database server * @param string $query SQL query, passed to server * @return mixed false if no error, dies with error message otherwise */ private static function _error($result, $query) { if (!empty($result) || self::$_db->errorCode() == 0) { // it's ok } else { $error = array('message' => self::$_db->error() . ' <b>(' . self::$_db->errorCode() . ')</b>', 'query' => $query); if (Registry::get('runtime.database.skip_errors') == true) { Registry::push('runtime.database.errors', $error); } else { // Log database errors fn_log_event('database', 'error', array('error' => $error, 'backtrace' => debug_backtrace())); throw new DatabaseException($error['message'] . "<p>{$error['query']}</p>"); } } return false; }
/** * Function print notice that function $old_function is deprecated and must be replaced by $new_function * @param string $old_function Name of the old function * @param string $new_function Name of the new function */ function fn_generate_deprecated_function_notice($old_function, $new_function) { $message = __('function_deprecated', array('[old_function]' => $old_function, '[new_function]' => $new_function)); if (Debugger::isActive()) { fn_set_notification('E', __('error'), $message); } fn_log_event('general', 'deprecated', array('function' => $old_function, 'message' => $message, 'backtrace' => debug_backtrace())); }
function fn_delete_news($news_id) { // Log news deletion fn_log_event('news', 'delete', array('news_id' => $news_id)); fn_clean_block_items('news', $news_id); fn_clean_block_links('news', $news_id); db_query("DELETE FROM ?:news WHERE news_id = ?i", $news_id); db_query("DELETE FROM ?:news_descriptions WHERE news_id = ?i", $news_id); fn_set_hook('delete_news', $news_id); }
$redirect_url = $_REQUEST['return_url']; } unset($_REQUEST['redirect_url']); if (AREA == 'C') { fn_set_notification('N', __('notice'), __('successful_login')); } if (AREA == 'A' && Registry::get('runtime.unsupported_browser')) { $redirect_url = "upgrade_center.ie7notify"; } unset($_SESSION['cart']['edit_step']); } else { // // Login incorrect // // Log user failed login fn_log_event('users', 'failed_login', array('user' => $user_login)); $auth = array(); fn_set_notification('E', __('error'), __('error_incorrect_login')); fn_save_post_data('user_login'); return array(CONTROLLER_STATUS_REDIRECT, $redirect_url); } unset($_SESSION['edit_step']); } // // Recover password mode // if ($mode == 'recover_password') { $user_email = !empty($_REQUEST['user_email']) ? $_REQUEST['user_email'] : ''; $redirect_url = ''; if (!fn_recover_password_generate_key($user_email)) { $redirect_url = "auth.recover_password";
if (!$store_access_id || $store_access_id != $_REQUEST['access_id']) { fn_twg_throw_error_denied($response, 'twgadmin_auth_fail_access_id'); } } // Regenerate session_id for security reasons Session::regenerateId(); fn_login_user($user_data['user_id']); fn_set_session_data(AREA . '_user_id', $user_data['user_id'], COOKIE_ALIVE_TIME); fn_set_session_data(AREA . '_password', $user_data['password'], COOKIE_ALIVE_TIME); // 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']; $auth = $_SESSION['auth']; // Log user successful login fn_log_event('users', 'session', array('user_id' => $user_data['user_id'], 'company_id' => fn_get_company_id('users', 'user_id', $user_data['user_id']))); fn_init_company_id($_REQUEST); fn_init_company_data($_REQUEST); $response->setData(array('status' => 'ok')); $response->setData(array('settings' => fn_twg_get_admin_settings($auth))); $response->returnResponse(); } elseif ($action == 'get') { $object_name = ''; $condition = array(); $options = array('lang_code' => $lang_code); $result = array(); $is_paginate = false; $total_items = 0; $items_per_page = !empty($_REQUEST['items_per_page']) ? $_REQUEST['items_per_page'] : TWG_RESPONSE_ITEMS_LIMIT; if ($object == 'timeline') { list($logs, $pagination_params) = fn_twg_get_logs($_REQUEST);
/** * Executes request, if curl exists - via curl, if not - via socket * @param string $method request method * @param string $url request url * @param mixed $data request data * @param array $extra extra settings * @return mixed request response on success, false on failure */ private static function _request($method, $url, $data, $extra = array()) { list($url, $data) = self::_prepareData($method, $url, $data); if (self::_curlExists()) { $content = self::_curlRequest($method, $url, $data, $extra); } else { $content = self::_socketRequest($method, $url, $data, $extra); } if (self::$logging) { fn_log_event('requests', 'http', array('url' => $url, 'data' => var_export($data, true), 'response' => $content)); } return $content; }
/** * Function delete order * * @param int $order_id * @return int */ function fn_delete_order($order_id) { if (Registry::get('runtime.company_id') && !fn_allowed_for('ULTIMATE')) { fn_company_access_denied_notification(); return false; } // Log order deletion fn_log_event('orders', 'delete', array('order_id' => $order_id)); fn_change_order_status($order_id, STATUS_INCOMPLETED_ORDER, '', fn_get_notification_rules(array(), false)); // incomplete to increase inventory fn_set_hook('delete_order', $order_id); db_query("DELETE FROM ?:new_orders WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:order_data WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:order_details WHERE order_id = ?i", $order_id); $result = db_query("DELETE FROM ?:orders WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:product_file_ekeys WHERE order_id = ?i", $order_id); db_query("DELETE FROM ?:profile_fields_data WHERE object_id = ?i AND object_type='O'", $order_id); db_query("DELETE FROM ?:order_docs WHERE order_id = ?i", $order_id); // Delete shipments $shipment_ids = db_get_fields('SELECT shipment_id FROM ?:shipment_items WHERE order_id = ?i GROUP BY shipment_id', $order_id); if (!empty($shipment_ids)) { db_query('DELETE FROM ?:shipments WHERE shipment_id IN (?a)', $shipment_ids); db_query('DELETE FROM ?:shipment_items WHERE order_id = ?i', $order_id); } return $result; }
private function _errors($response, $id, $method) { if (empty($response)) { return false; } $errors = array(); $status = ''; $log_errors = array(); if ($response->Ack != 'Success') { $errors = $response->Errors; $status = !empty($response->Ack) ? (string) $response->Ack : __('error'); $extra = !empty(self::$errors[$id]) ? count(self::$errors[$id]) : 0; if (is_array($errors)) { for ($i = $extra; $i < count($errors) + $extra; $i++) { $log_errors[] = self::$errors[$id][$i] = (array) $errors[$i]; fn_set_notification('W', __('warning'), (string) $errors[$i]->LongMessage); } } else { $log_errors[] = self::$errors[$id][$extra] = (array) $errors; fn_set_notification('W', __('warning'), (string) $errors->LongMessage); } } fn_log_event('ebay_requests', 'all', array('method' => $method, 'status' => $status, 'errors' => $log_errors)); return true; }
/** * Adds or updates category * * @param array $category_data Category data * @param int $category_id Category identifier * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) * @return int New or updated category identifier */ function fn_update_category($category_data, $category_id = 0, $lang_code = CART_LANGUAGE) { /** * Update category data (running before fn_update_category() function) * * @param array $category_data Category data * @param int $category_id Category identifier * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('update_category_pre', $category_data, $category_id, $lang_code); // category title required if (empty($category_data['category'])) { //return false; // FIXME: management page doesn't have category name } if (isset($category_data['localization'])) { $category_data['localization'] = empty($category_data['localization']) ? '' : fn_implode_localizations($category_data['localization']); } if (isset($category_data['usergroup_ids'])) { $category_data['usergroup_ids'] = empty($category_data['usergroup_ids']) ? '0' : implode(',', $category_data['usergroup_ids']); } if (fn_allowed_for('ULTIMATE')) { fn_set_company_id($category_data); } $_data = $category_data; unset($_data['parent_id']); if (isset($category_data['timestamp'])) { $_data['timestamp'] = fn_parse_date($category_data['timestamp']); } if (isset($_data['position']) && empty($_data['position']) && $_data['position'] != '0' && isset($category_data['parent_id'])) { $_data['position'] = db_get_field("SELECT max(position) FROM ?:categories WHERE parent_id = ?i", $category_data['parent_id']); $_data['position'] = $_data['position'] + 10; } if (isset($_data['selected_layouts'])) { $_data['selected_layouts'] = serialize($_data['selected_layouts']); } if (isset($_data['use_custom_templates']) && $_data['use_custom_templates'] == 'N') { // Clear the layout settings if the category custom templates were disabled $_data['product_columns'] = $_data['selected_layouts'] = $_data['default_layout'] = ''; } // create new category if (empty($category_id)) { if (fn_allowed_for('ULTIMATE') && empty($_data['company_id'])) { fn_set_notification('E', __('error'), __('need_company_id')); return false; } $create = true; $category_id = db_query("INSERT INTO ?:categories ?e", $_data); $_data['category_id'] = $category_id; foreach (fn_get_translation_languages() as $_data['lang_code'] => $v) { db_query("INSERT INTO ?:category_descriptions ?e", $_data); } $category_data['parent_id'] = !empty($category_data['parent_id']) ? $category_data['parent_id'] : 0; // update existing category } else { $category_data['old_company_id'] = db_get_field("SELECT company_id FROM ?:categories WHERE category_id = ?i", $category_id); $arow = db_query("UPDATE ?:categories SET ?u WHERE category_id = ?i", $_data, $category_id); $arow_description = db_query("UPDATE ?:category_descriptions SET ?u WHERE category_id = ?i AND lang_code = ?s", $_data, $category_id, $lang_code); if ($arow === false && $arow_description === false) { fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('category'))), '', '404'); $category_id = false; } } if ($category_id) { // regenerate id_path for all child categories of the updated category if (isset($category_data['parent_id'])) { fn_change_category_parent($category_id, intval($category_data['parent_id'])); } // Log category add/update fn_log_event('categories', !empty($create) ? 'create' : 'update', array('category_id' => $category_id)); // Assign usergroup to all subcategories if (!empty($_data['usergroup_to_subcats']) && $_data['usergroup_to_subcats'] == 'Y') { $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id); db_query("UPDATE ?:categories SET usergroup_ids = ?s WHERE id_path LIKE ?l", $_data['usergroup_ids'], "{$id_path}/%"); } } /** * Update category data (running after fn_update_category() function) * * @param array $category_data Category data * @param int $category_id Category identifier * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('update_category_post', $category_data, $category_id, $lang_code); return $category_id; }
// Check if backups folder exists. If not - create it if (!is_dir(Registry::get('config.dir.backups'))) { fn_mkdir(Registry::get('config.dir.backups')); } if (fn_copy($dump['path'], Registry::get('config.dir.backups') . $dump['name'])) { fn_set_notification('N', __('notice'), __('done')); } else { fn_set_notification('E', __('error'), __('cant_create_backup_file')); } } else { fn_set_notification('E', __('error'), __('cant_upload_file')); } } if ($mode == 'optimize') { // Log database optimization fn_log_event('database', 'optimize'); $all_tables = db_get_fields("SHOW TABLES"); fn_set_progress('parts', sizeof($all_tables)); foreach ($all_tables as $table) { fn_set_progress('echo', __('optimizing_table') . " <b>{$table}</b>...<br />"); db_query("OPTIMIZE TABLE {$table}"); db_query("ANALYZE TABLE {$table}"); $fields = db_get_hash_array("SHOW COLUMNS FROM {$table}", 'Field'); if (!empty($fields['is_global'])) { // Sort table by is_global field fn_echo('.'); db_query("ALTER TABLE {$table} ORDER BY is_global DESC"); } elseif (!empty($fields['position'])) { // Sort table by position field fn_echo('.'); db_query("ALTER TABLE {$table} ORDER BY position");
/** * Deletes news by its ID * * @param int $news_id - News Identifier */ function fn_delete_news($news_id) { $news_deleted = false; if (!empty($news_id)) { if (fn_check_company_id('news', 'news_id', $news_id)) { // Log news deletion fn_log_event('news', 'delete', array('news_id' => $news_id)); Block::instance()->removeDynamicObjectData('news', $news_id); $affected_rows = db_query("DELETE FROM ?:news WHERE news_id = ?i", $news_id); db_query("DELETE FROM ?:news_descriptions WHERE news_id = ?i", $news_id); if ($affected_rows != 0) { $news_deleted = true; } else { fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('news'))), '', '404'); } fn_set_hook('delete_news', $news_id); } else { fn_company_access_denied_notification(); } } return $news_deleted; }
if (!empty($_POST['order-calculations-request'])) { $xml_response = $_POST['order-calculations-request']; } elseif (!empty($_POST['NotificationData'])) { $xml_response = $_POST['NotificationData']; } if (!empty($_POST['order-calculations-error'])) { // Process the Amazon callback error $xml_error = $_POST['order-calculations-error']; $xml = @simplexml_load_string($xml_error); if (empty($xml)) { $xml = @simplexml_load_string(stripslashes($xml_error)); } // Get error message $code = (string) $xml->OrderCalculationsErrorCode; $message = (string) $xml->OrderCalculationsErrorMessage; fn_log_event('requests', 'http', array('url' => 'amazon_callback', 'data' => '', 'response' => var_export(array($code, $message), true))); exit; } $xml = @simplexml_load_string($xml_response); if (empty($xml)) { $xml = @simplexml_load_string(stripslashes($xml_response)); } if (empty($xml)) { // ERROR: Failed to parse incoming XML data die; } else { $message_recognizer = $xml->getName(); } if ($message_recognizer == 'OrderCalculationsRequest') { list($amazon_sess_id, $payment_id) = explode(';', base64_decode((string) $xml->CallbackOrderCart->CartCustomData->ClientRequestId)); $processor_data = fn_get_payment_method_data($payment_id);
/** * Gets error message from shipping service server * * @param string $resonse Reponse from Shipping service server * @return string Text of error or false if no errors */ public function processErrors($result) { $err_message = strval($result->faultcode . ': ' . $result->faultstring); fn_log_event('general', 'runtime', array('function' => 'getQuotesByRequest', 'message' => __('temando_system') . ': ' . $err_message)); return $err_message; }