/** * Init template engine * * @return boolean always true */ function fn_init_templater() { if (defined('TEMPLATER_STARTED')) { return true; } require_once DIR_CORE . 'class.templater.php'; // // Template objects for processing html templates // $view = new Templater(); $view_mail = new Templater(); fn_set_hook('init_templater', $view, $view_mail); $view->register_prefilter(array(&$view, 'prefilter_hook')); $view_mail->register_prefilter(array(&$view_mail, 'prefilter_hook')); if (AREA == 'A' && !empty($_SESSION['auth']['user_id'])) { $view->register_prefilter(array(&$view, 'prefilter_form_tooltip')); } if (Registry::get('settings.customization_mode') == 'Y' && AREA == 'C') { $view->register_prefilter(array(&$view, 'prefilter_template_wrapper')); $view->register_outputfilter(array(&$view, 'outputfilter_template_ids')); $view->customization = true; } else { // Inline prefilter if (Registry::get('config.tweaks.inline_compilation') == true) { $view->register_prefilter(array(&$view, 'prefilter_inline')); } } if (Registry::get('config.tweaks.anti_csfr') == true) { $view->register_prefilter(array(&$view, 'prefilter_security_hash')); } // Output bufferring postfilter $view->register_prefilter(array(&$view, 'prefilter_output_buffering')); // Translation postfilter $view->register_postfilter(array(&$view, 'postfilter_translation')); if (Registry::get('settings.translation_mode') == 'Y') { $view->register_outputfilter(array(&$view, 'outputfilter_translate_wrapper')); } // // Store all compiled templates to the single directory // $view->use_sub_dirs = false; $view->compile_check = Registry::get('config.tweaks.check_templates'); if (Registry::get('settings.General.debugging_console') == 'Y') { if (empty($_SESSION['debugging_console']) && !empty($_SESSION['auth']['user_id'])) { $user_type = db_get_field("SELECT user_type FROM ?:users WHERE user_id = ?i", $_SESSION['auth']['user_id']); if ($user_type == 'A') { $_SESSION['debugging_console'] = true; } } if (isset($_SESSION['debugging_console']) && $_SESSION['debugging_console'] == true) { error_reporting(0); $view->debugging = true; } } $skin_name = Registry::get('config.skin_name'); $view->template_dir = DIR_SKINS . $skin_name . '/' . AREA_NAME; $view->config_dir = DIR_SKINS . $skin_name . '/' . AREA_NAME; $view->secure_dir = DIR_SKINS . $skin_name . '/' . AREA_NAME; $view->assign('images_dir', Registry::get('config.current_path') . "/skins/{$skin_name}/" . AREA_NAME . "/images"); $view->compile_dir = DIR_COMPILED . AREA_NAME . (defined('SKINS_PANEL') ? $skin_name : ''); $view->cache_dir = DIR_CACHE; $view->assign('skin_area', AREA_NAME); // Get manifest $manifest = fn_get_manifest(AREA_NAME); $view->assign('manifest', $manifest); // Mail templates should be taken from the customer skin if (AREA != 'C') { $manifest = fn_get_manifest('customer'); } $view_mail->assign('manifest', $manifest); $view_mail->template_dir = DIR_SKINS . Registry::get('settings.skin_name_customer') . '/mail'; $view_mail->config_dir = DIR_SKINS . Registry::get('settings.skin_name_customer') . '/mail'; $view_mail->secure_dir = DIR_SKINS . Registry::get('settings.skin_name_customer') . '/mail'; $view_mail->assign('images_dir', Registry::get('config.current_path') . '/skins/' . Registry::get('settings.skin_name_customer') . '/mail/images'); $view_mail->compile_dir = DIR_COMPILED . 'mail'; $view_mail->assign('skin_area', 'mail'); if (!is_dir($view->compile_dir)) { fn_mkdir($view->compile_dir); } if (!is_dir($view->cache_dir)) { fn_mkdir($view->cache_dir); } if (!is_dir($view_mail->compile_dir)) { fn_mkdir($view_mail->compile_dir); } if (!is_writable($view->compile_dir) || !is_dir($view->compile_dir)) { fn_error(debug_backtrace(), "Can't write template cache in the directory: <b>" . $view->compile_dir . '</b>.<br>Please check if it exists, and has writable permissions.', false); } $view->assign('ldelim', '{'); $view->assign('rdelim', '}'); $avail_languages = array(); foreach (Registry::get('languages') as $k => $v) { if ($v['status'] == 'D') { continue; } $avail_languages[$k] = $v; } $view->assign('languages', $avail_languages); $view->setLanguage(CART_LANGUAGE); $view_mail->setLanguage(CART_LANGUAGE); $view->assign('localizations', fn_get_localizations(CART_LANGUAGE, true)); if (defined('CART_LOCALIZATION')) { $view->assign('localization', fn_get_localization_data(CART_LOCALIZATION)); } $view->assign('currencies', Registry::get('currencies'), false); $view->assign('primary_currency', CART_PRIMARY_CURRENCY, false); $view->assign('secondary_currency', CART_SECONDARY_CURRENCY, false); $view_mail->assign('currencies', Registry::get('currencies'), false); $view_mail->assign('primary_currency', CART_PRIMARY_CURRENCY, false); $view_mail->assign('secondary_currency', CART_SECONDARY_CURRENCY, false); $view->assign('s_companies', Registry::get('s_companies'), false); $view->assign('s_company', defined('COMPANY_ID') ? COMPANY_ID : 'all', false); $view_mail->assign('s_companies', Registry::get('s_companies'), false); $view_mail->assign('s_company', defined('COMPANY_ID') ? COMPANY_ID : 'all', false); Registry::set('view', $view); Registry::set('view_mail', $view_mail); define('TEMPLATER_STARTED', true); return true; }
if ($mode == 'm_delete') { if (!empty($_REQUEST['localization_ids'])) { fn_delete_localization($_REQUEST['localization_ids']); } $suffix = '.manage'; } if ($mode == 'delete') { if (!empty($_REQUEST['localization_id'])) { fn_delete_localization((array) $_REQUEST['localization_id']); } $suffix = '.manage'; } return array(CONTROLLER_STATUS_OK, 'localizations' . $suffix); } if ($mode == 'update') { $localizaton = fn_get_localization_data($_REQUEST['localization_id'], DESCR_SL, true); if (empty($localizaton)) { return array(CONTROLLER_STATUS_NO_PAGE); } Tygh::$app['view']->assign('localization', $localizaton); Tygh::$app['view']->assign('localization_countries', array_diff(fn_get_simple_countries(), $localizaton['countries'])); Tygh::$app['view']->assign('localization_currencies', array_diff(fn_get_simple_currencies(), $localizaton['currencies'])); Tygh::$app['view']->assign('localization_languages', array_diff(fn_get_simple_languages(true), $localizaton['languages'])); Tygh::$app['view']->assign('default_localization', fn_get_default_localization(DESCR_SL)); Registry::set('navigation.tabs', array('general' => array('title' => __('general'), 'js' => true), 'details' => array('title' => __('items_title'), 'js' => true))); } elseif ($mode == 'add') { Tygh::$app['view']->assign('localization_countries', fn_get_simple_countries()); Tygh::$app['view']->assign('localization_currencies', fn_get_simple_currencies()); Tygh::$app['view']->assign('localization_languages', fn_get_simple_languages(true)); Tygh::$app['view']->assign('default_localization', fn_get_default_localization(DESCR_SL)); Registry::set('navigation.tabs', array('general' => array('title' => __('general'), 'js' => true), 'details' => array('title' => __('items_title'), 'js' => true)));
/** * Init template engine * * @return boolean always true */ function fn_init_templater($area = AREA) { $auth = Tygh::$app['session']['auth']; $view = new SmartyCore(); \SmartyException::$escape = false; /** * Change templater pre-init parameters * * @param object $view Templater object */ fn_set_hook('init_templater', $view); $view->_dir_perms = DEFAULT_DIR_PERMISSIONS; $view->_file_perms = DEFAULT_FILE_PERMISSIONS; $view->registerResource('tygh', new Tygh\SmartyEngine\FileResource()); // resource for shared templates loaded from backend $view->registerResource('backend', new Tygh\SmartyEngine\BackendResource()); if ($area == 'A') { if (!empty($auth['user_id'])) { // Auto-tooltips for admin panel $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preFormTooltip')); if (fn_allowed_for('ULTIMATE')) { // Enable sharing for objects $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSharing')); } } $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preScript')); } if ($area == 'C') { $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preTemplateWrapper')); if (Registry::get('runtime.customization_mode.design')) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTemplateIds')); } if (Registry::get('runtime.customization_mode.live_editor')) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputLiveEditorWrapper')); } $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputScript')); } if (Embedded::isEnabled()) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputEmbeddedUrl')); } // CSRF form protection if (fn_is_csrf_protection_enabled($auth)) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSecurityHash')); } // Language variable retrieval optimization $view->registerFilter('post', array('Tygh\\SmartyEngine\\Filters', 'postTranslation')); $smarty_plugins_dir = $view->getPluginsDir(); $view->setPluginsDir(Registry::get('config.dir.functions') . 'smarty_plugins'); $view->addPluginsDir($smarty_plugins_dir); $view->error_reporting = E_ALL & ~E_NOTICE; $view->registerDefaultPluginHandler(array('Tygh\\SmartyEngine\\Filters', 'smartyDefaultHandler')); $view->setArea($area); $view->use_sub_dirs = false; $view->compile_check = Development::isEnabled('compile_check') || Debugger::isActive() || fn_is_development() ? true : false; $view->setLanguage(CART_LANGUAGE); $view->assign('ldelim', '{'); $view->assign('rdelim', '}'); $view->assign('currencies', Registry::get('currencies'), false); $view->assign('primary_currency', CART_PRIMARY_CURRENCY, false); $view->assign('secondary_currency', CART_SECONDARY_CURRENCY, false); $view->assign('languages', Registry::get('languages')); if ($area == 'A') { $view->assign('addon_permissions_text', fn_get_addon_permissions_text()); } if (!fn_allowed_for('ULTIMATE:FREE')) { $view->assign('localizations', fn_get_localizations(CART_LANGUAGE, true)); if (defined('CART_LOCALIZATION')) { $view->assign('localization', fn_get_localization_data(CART_LOCALIZATION)); } } if (defined('THEMES_PANEL')) { if (fn_allowed_for('ULTIMATE')) { $storefronts = db_get_array('SELECT storefront, company, company_id FROM ?:companies'); Registry::set('demo_theme.storefronts', $storefronts); } $view->assign('demo_theme', Registry::get('demo_theme')); } Tygh::$app['view'] = $view; /** * Change templater parameters * * @param object $view Templater object */ fn_set_hook('init_templater_post', $view); return array(INIT_STATUS_OK); }
/** * Change order status * * @param int $order_id Order identifier * @param string $status_to New order status (one char) * @param string $status_from Old order status (one char) * @param array $force_notification Array with notification rules * @param boolean $place_order True, if this function have been called inside of fn_place_order function. * @return boolean */ function fn_change_order_status($order_id, $status_to, $status_from = '', $force_notification = array(), $place_order = false) { $order_info = fn_get_order_info($order_id, true); if (!$order_info) { return false; } if (defined('CART_LOCALIZATION') && $order_info['localization_id'] && CART_LOCALIZATION != $order_info['localization_id']) { Registry::get('view')->assign('localization', fn_get_localization_data(CART_LOCALIZATION)); } $order_statuses = fn_get_statuses(STATUSES_ORDER, array(), true, false, $order_info['lang_code'] ? $order_info['lang_code'] : CART_LANGUAGE, $order_info['company_id']); if (empty($status_from)) { $status_from = $order_info['status']; } if (empty($order_info) || empty($status_to) || $status_from == $status_to) { return false; } if (fn_allowed_for('MULTIVENDOR')) { if ($order_info['is_parent_order'] == 'Y') { $child_ids = db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $order_id); $res = $_res = true; foreach ($child_ids as $child_order_id) { $_res = fn_change_order_status($child_order_id, $status_to, '', $force_notification, $place_order); } $res = $res && $_res; return $res; } } $_updated_ids = array(); $_error = false; foreach ($order_info['products'] as $k => $v) { // Generate ekey if EDP is ordered if (!empty($v['extra']['is_edp']) && $v['extra']['is_edp'] == 'Y') { continue; // don't track inventory } // Update product amount if inventory tracking is enabled if (Registry::get('settings.General.inventory_tracking') == 'Y') { if ($order_statuses[$status_to]['params']['inventory'] == 'D' && $order_statuses[$status_from]['params']['inventory'] == 'I') { // decrease amount if (fn_update_product_amount($v['product_id'], $v['amount'], @$v['extra']['product_options'], '-') == false) { $status_to = 'B'; //backorder $_error = true; fn_set_notification('W', __('warning'), __('low_stock_subj', array('[product]' => fn_get_product_name($v['product_id']) . ' #' . $v['product_id']))); break; } else { $_updated_ids[] = $k; } } elseif ($order_statuses[$status_to]['params']['inventory'] == 'I' && $order_statuses[$status_from]['params']['inventory'] == 'D') { // increase amount fn_update_product_amount($v['product_id'], $v['amount'], @$v['extra']['product_options'], '+'); } } } if ($_error) { if (!empty($_updated_ids)) { foreach ($_updated_ids as $id) { // increase amount fn_update_product_amount($order_info['products'][$id]['product_id'], $order_info['products'][$id]['amount'], @$order_info['products'][$id]['extra']['product_options'], '+'); } unset($_updated_ids); } if ($status_from == $status_to) { return false; } } fn_set_hook('change_order_status', $status_to, $status_from, $order_info, $force_notification, $order_statuses, $place_order); if ($status_from == $status_to) { if (!empty($_updated_ids)) { foreach ($_updated_ids as $id) { // increase amount fn_update_product_amount($order_info['products'][$id]['product_id'], $order_info['products'][$id]['amount'], @$order_info['products'][$id]['extra']['product_options'], '+'); } unset($_updated_ids); } return false; } fn_promotion_post_processing($status_to, $status_from, $order_info, $force_notification); // Log order status change fn_log_event('orders', 'status', array('order_id' => $order_id, 'status_from' => $status_from, 'status_to' => $status_to)); if (!empty($order_statuses[$status_to]['params']['appearance_type']) && ($order_statuses[$status_to]['params']['appearance_type'] == 'I' || $order_statuses[$status_to]['params']['appearance_type'] == 'C') && !db_get_field("SELECT doc_id FROM ?:order_docs WHERE type = ?s AND order_id = ?i", $order_statuses[$status_to]['params']['appearance_type'], $order_id)) { $_data = array('order_id' => $order_id, 'type' => $order_statuses[$status_to]['params']['appearance_type']); $order_info['doc_ids'][$order_statuses[$status_to]['params']['appearance_type']] = db_query("INSERT INTO ?:order_docs ?e", $_data); } // Check if we need to remove CC info if (!empty($order_statuses[$status_to]['params']['remove_cc_info']) && $order_statuses[$status_to]['params']['remove_cc_info'] == 'Y' && !empty($order_info['payment_info'])) { fn_cleanup_payment_info($order_id, $order_info['payment_info'], true); } $edp_data = fn_generate_ekeys_for_edp(array('status_from' => $status_from, 'status_to' => $status_to), $order_info); $order_info['status'] = $status_to; fn_order_notification($order_info, $edp_data, $force_notification); db_query("UPDATE ?:orders SET status = ?s WHERE order_id = ?i", $status_to, $order_id); return true; }
/** * Init template engine * * @return boolean always true */ function fn_init_templater($area = AREA) { $view = new SmartyCore(); \SmartyException::$escape = false; /** * Change templater pre-init parameters * * @param object $view Templater object */ fn_set_hook('init_templater', $view); $view->registerResource('tygh', new Tygh\SmartyEngine\FileResource()); if ($area == 'A' && !empty($_SESSION['auth']['user_id'])) { // Auto-tooltips for admin panel $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preFormTooltip')); } // Customization mode if ($area == 'C') { $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preTemplateWrapper')); if (Registry::get('runtime.customization_mode.design')) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTemplateIds')); } } if (Registry::get('config.tweaks.anti_csrf') == true) { // CSRF form protection $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSecurityHash')); } if (Embedded::isEnabled()) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputEmbeddedUrl')); } if (fn_allowed_for('ULTIMATE')) { // Enable sharing for objects $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSharing')); } // Language variable retrieval optimization $view->registerFilter('post', array('Tygh\\SmartyEngine\\Filters', 'postTranslation')); // Translation mode if (Registry::get('runtime.customization_mode.translation')) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTranslateWrapper')); } if (Registry::get('settings.General.debugging_console') == 'Y') { if (empty($_SESSION['debugging_console']) && !empty($_SESSION['auth']['user_id'])) { $user_type = db_get_field("SELECT user_type FROM ?:users WHERE user_id = ?i", $_SESSION['auth']['user_id']); if ($user_type == 'A') { $_SESSION['debugging_console'] = true; } } if (isset($_SESSION['debugging_console']) && $_SESSION['debugging_console'] == true) { error_reporting(0); $view->debugging = true; } } $smarty_plugins_dir = $view->getPluginsDir(); $view->setPluginsDir(Registry::get('config.dir.functions') . 'smarty_plugins'); $view->addPluginsDir($smarty_plugins_dir); $view->error_reporting = E_ALL & ~E_NOTICE; $view->registerDefaultPluginHandler(array('Tygh\\SmartyEngine\\Filters', 'smartyDefaultHandler')); $view->setArea($area); $view->use_sub_dirs = false; $view->compile_check = Development::isEnabled('compile_check') || Debugger::isActive() || defined('DEVELOPMENT') ? true : false; $view->setLanguage(CART_LANGUAGE); $view->assign('ldelim', '{'); $view->assign('rdelim', '}'); $view->assign('currencies', Registry::get('currencies'), false); $view->assign('primary_currency', CART_PRIMARY_CURRENCY, false); $view->assign('secondary_currency', CART_SECONDARY_CURRENCY, false); $view->assign('languages', Registry::get('languages')); if ($area == 'A') { $view->assign('addon_permissions_text', fn_get_addon_permissions_text()); } if (!fn_allowed_for('ULTIMATE:FREE')) { $view->assign('localizations', fn_get_localizations(CART_LANGUAGE, true)); if (defined('CART_LOCALIZATION')) { $view->assign('localization', fn_get_localization_data(CART_LOCALIZATION)); } } if (defined('THEMES_PANEL')) { if (fn_allowed_for('ULTIMATE')) { $storefronts = db_get_array('SELECT storefront, company, company_id FROM ?:companies'); Registry::set('demo_theme.storefronts', $storefronts); } $view->assign('demo_theme', Registry::get('demo_theme')); } Registry::set('view', $view); /** * Change templater parameters * * @param object $view Templater object */ fn_set_hook('init_templater_post', $view); return array(INIT_STATUS_OK); }