Ejemplo n.º 1
1
 public function authPage($page)
 {
     $access_id = self::getAccessID('A');
     $data = array('page' => $page, 'ttl' => self::TWIGMO_SERVER_TTL, 'customer_access_id' => self::getAccessID('C'), 'access_id' => $access_id);
     $meta = array('access_id' => $access_id);
     $response = $this->send('auth.token', $data, $meta);
     if (!$this->responseIsOk($response)) {
         die(str_replace(array('[linkOpen]', '[linkClose]'), array('<a href="' . fn_url('addons.update&addon=twigmo') . '">', '</a>'), $this->_getLangVar('twgadmin_no_token_recieved')));
     }
     $url = fn_link_attach($response['data']['url'], 'sl=' . strtolower(CART_LANGUAGE));
     fn_redirect($url, true);
 }
Ejemplo n.º 2
1
****************************************************************************/
//
// $Id: thaiepay.php 10080 2010-07-15 13:04:18Z klerik $
//
if (!defined('AREA')) {
    die('Access denied');
}
if (defined('PAYMENT_NOTIFICATION')) {
    if (empty($_REQUEST['refno'])) {
        if (!empty($_SESSION['thaiepay_refno'])) {
            $_REQUEST['refno'] = $_SESSION['thaiepay_refno'];
            unset($_SESSION['thaiepay_refno']);
        } else {
            if ($mode == 'finish') {
                $prefix = Registry::get('settings.General.secure_auth') == 'Y' && AREA == 'C' ? Registry::get('config.https_location') . '/' : '';
                fn_redirect($prefix . INDEX_SCRIPT . "?dispatch=orders.search", true);
            }
            exit;
        }
    }
    $order_id = intval($_REQUEST['refno']);
    if (fn_check_payment_script('thaiepay.php', $order_id, $processor_data)) {
        if ($mode == 'notify') {
            $errors = array();
            $errors_desc = array('additional_parameter' => fn_get_lang_var('additional_parameter_not_correct'), 'total' => fn_get_lang_var('order_total_not_correct'));
            if (isset($_REQUEST['total'])) {
                $order_info = fn_get_order_info($order_id);
                if (fn_format_price($order_info['total']) != fn_format_price($_REQUEST['total'])) {
                    $errors['total'] = true;
                }
            }
Ejemplo n.º 3
1
 /**
  * Setup next_step action
  *
  * @param  array $cart_settings     Cart settings
  * @param  array $database_settings Database settings
  * @param  array $server_settings   Server settings
  * @return bool  Always true
  */
 public function actionNextStep($cart_settings, $database_settings, $server_settings)
 {
     $app = App::instance();
     $validator = new Validator();
     if ($validator->validateAll(array_merge($cart_settings, $server_settings, $database_settings))) {
         fn_set_progress('parts', 14);
         set_time_limit(0);
         if ($app->connectToDB($database_settings['host'], $database_settings['name'], $database_settings['user'], $database_settings['password'], $database_settings['table_prefix'], $database_settings['database_backend'])) {
             $app->setToStorage('database_settings', $database_settings);
             define('CART_LANGUAGE', $cart_settings['main_language']);
             define('DESCR_SL', $cart_settings['main_language']);
             define('CART_SECONDARY_CURRENCY', 'NULL');
             // Need for cache_level
             $sCart = new Setup($cart_settings, $server_settings, $database_settings, $this->isDemoInstall($cart_settings));
             $sAddons = new AddonsSetup();
             /* Setup Scheme */
             fn_set_progress('title', $app->t('setup_scheme'));
             fn_set_progress('echo', $app->t('processing'), true);
             fn_set_progress('step_scale', 2000);
             $sCart->setupScheme();
             /* Setup Scheme Data */
             fn_set_progress('step_scale', 1);
             fn_set_progress('title', $app->t('setup_data'));
             fn_set_progress('echo', $app->t('processing'), true);
             fn_set_progress('step_scale', 5000);
             $sCart->setupData();
             $sCart->setSimpleMode();
             /* Setup Demo */
             if ($this->isDemoInstall($cart_settings)) {
                 fn_set_progress('step_scale', 1);
                 fn_set_progress('title', $app->t('setup_demo'));
                 fn_set_progress('echo', $app->t('installing_demo_catalog'), true);
                 fn_set_progress('step_scale', 5000);
                 $sCart->setupDemo();
             } else {
                 fn_set_progress('step_scale', 1);
                 fn_set_progress('echo', $app->t('cleaning'), true);
                 $sCart->clean();
             }
             $sCart->setupUsers();
             /* Setup companies */
             fn_set_progress('step_scale', 1);
             fn_set_progress('title', $app->t('setup_companies'));
             fn_set_progress('echo', $app->t('processing'), true);
             $sCart->setupCompanies();
             /* Setup Languages */
             fn_set_progress('step_scale', 1);
             fn_set_progress('title', $app->t('setup_languages'));
             fn_set_progress('echo', $app->t('processing'), true);
             fn_set_progress('step_scale', 1000);
             $sCart->setupLanguages($this->isDemoInstall($cart_settings));
             $sCart->setupThemes();
             /* Setup Add-ons */
             fn_set_progress('title', $app->t('setup_addons'));
             fn_set_progress('echo', $app->t('processing'), true);
             fn_set_progress('step_scale', 100);
             $sAddons->setup($this->isDemoInstall($cart_settings), array());
             /* Write config */
             fn_set_progress('step_scale', 1);
             fn_set_progress('echo', $app->t('writing_config'), true);
             $sCart->writeConfig();
             $this->_prepareHttpData();
             $redirect_url = Registry::get('config.http_location') . '/install/index.php?dispatch=setup.complete';
             if (Registry::get('runtime.comet')) {
                 Registry::get('ajax')->assign('force_redirection', $redirect_url);
             } else {
                 fn_redirect($redirect_url);
             }
             exit;
         }
     } else {
         if (Registry::get('runtime.comet')) {
             exit;
         } else {
             $params['dispatch'] = 'setup.index';
             $params['cart_settings'] = $cart_settings;
             $params['database_settings'] = $database_settings;
             $params['server_settings'] = $server_settings;
             $app->run($params);
         }
     }
     return true;
 }
Ejemplo n.º 4
1
function fn_reward_points_change_order_status($status_to, $status_from, &$order_info, $force_notification, $order_statuses, $place_order = false)
{
    static $log_id;
    if (isset($order_info['deleted_order'])) {
        if (!empty($log_id)) {
            $log_item = array('action' => CHANGE_DUE_ORDER_DELETE);
            db_query("UPDATE ?:reward_point_changes SET ?u WHERE change_id = ?i", $log_item, $log_id);
        }
        return true;
    }
    $points_info = isset($order_info['points_info']) ? $order_info['points_info'] : array();
    if (!empty($points_info)) {
        $reason = array('order_id' => $order_info['order_id'], 'to' => $status_to, 'from' => $status_from);
        $action = empty($place_order) ? CHANGE_DUE_ORDER : CHANGE_DUE_ORDER_PLACE;
        if ($order_statuses[$status_to]['inventory'] == 'I' && $order_statuses[$status_from]['inventory'] == 'D') {
            if (!empty($points_info['in_use']['points'])) {
                // increase points in use
                $log_id = fn_change_user_points($points_info['in_use']['points'], $order_info['user_id'], serialize(fn_array_merge($reason, array('text' => 'text_increase_points_in_use'))), $action);
            }
            if ($points_info['is_gain'] == 'Y' && !empty($points_info['reward'])) {
                // decrease earned points
                $log_id = fn_change_user_points(-$points_info['reward'], $order_info['user_id'], serialize($reason), $action);
                db_query("DELETE FROM ?:order_data WHERE order_id = ?i AND type = ?s", $order_info['order_id'], ORDER_DATA_POINTS_GAIN);
            }
        }
        if ($order_statuses[$status_to]['inventory'] == 'D' && $order_statuses[$status_from]['inventory'] == 'I') {
            if (!empty($points_info['in_use']['points'])) {
                // decrease points in use
                if ($points_info['in_use']['points'] > fn_get_user_additional_data(POINTS, $order_info['user_id'])) {
                    fn_set_notification('N', fn_get_lang_var('warning'), fn_get_lang_var('text_order_status_has_not_been_changed'));
                    fn_redirect($_POST['redirect_url']);
                    //FIXME redirect in function  => bad style
                }
                $log_id = fn_change_user_points(-$points_info['in_use']['points'], $order_info['user_id'], serialize(fn_array_merge($reason, array('text' => 'text_decrease_points_in_use'))), $action);
            }
        }
        if ($status_to == 'C' && $points_info['is_gain'] == 'N' && !empty($points_info['reward'])) {
            // increase  rewarded points
            $log_id = fn_change_user_points($points_info['reward'], $order_info['user_id'], serialize($reason), $action);
            $order_data = array('order_id' => $order_info['order_id'], 'type' => ORDER_DATA_POINTS_GAIN, 'data' => 'Y');
            db_query("REPLACE INTO ?:order_data ?e", $order_data);
        }
    }
}
Ejemplo n.º 5
1
function fn_magiczoom_install()
{
    $moduleDirectory = str_replace(array("//", "\\"), array("/", "/"), Registry::get('config.dir.addons') . '/magiczoom');
    $cancel = false;
    if (!defined('PRODUCT_VERSION') || version_compare(PRODUCT_VERSION, '4.0.0', '<')) {
        $cancel = true;
        if (!fn_notification_exists('E', 'magiczoom_module_version_notification')) {
            $message = "<br/><span style=\"font-size: 16px; line-height: 20px; margin-top: 5px; display: block;\">This Magic Zoom module is intended only for CS Cart Version 4 and above." . "<br/>Your version of CS Cart is " . PRODUCT_VERSION . "</span>";
            fn_set_notification('E', __('error'), $message, true, 'magiczoom_module_version_notification');
        }
    }
    if ($cancel) {
        $args = func_get_args();
        if (!empty($args)) {
            fn_redirect("addons.manage");
        }
        return;
    }
    //fix url's in css files
    $cancel = fn_magiczoom_fix_css();
    if ($cancel) {
        $args = func_get_args();
        if (!empty($args)) {
            fn_redirect("addons.manage");
        }
        return;
    }
    //NOTE: fix the order in which modules call
    $magicAddons = db_get_fields("SELECT addon FROM ?:addons WHERE addon LIKE 'magic%'");
    if (!empty($magicAddons)) {
        $magicAddonsData = array();
        foreach ($magicAddons as $addon) {
            $magicAddonsData[$addon] = db_get_row("SELECT * FROM ?:addons WHERE addon='{$addon}'");
            db_query("DELETE FROM ?:addons WHERE addon='{$addon}'");
        }
        if (isset($magicAddonsData['magiczoom'])) {
            db_query("INSERT INTO ?:addons ?e", $magicAddonsData['magiczoom']);
            unset($magicAddonsData['magiczoom']);
        }
        foreach ($magicAddonsData as $addon => $data) {
            db_query("INSERT INTO ?:addons ?e", $data);
        }
    }
    fn_magiczoom_send_stat('install');
}
Ejemplo n.º 6
0
function fn_html_to_pdf($html, $name)
{
    if (!fn_init_pdf()) {
        fn_redirect(!empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : INDEX_SCRIPT);
    }
    $pipeline = PipelineFactory::create_default_pipeline('', '');
    if (!is_array($html)) {
        $html = array($html);
    }
    $pipeline->fetchers = array(new PdfFetcherMemory($html, Registry::get('config.current_location') . '/'), new FetcherURL());
    $pipeline->destination = new PdfDestinationDownload($name);
    $pipeline->data_filters = array(new DataFilterDoctype(), new DataFilterHTML2XHTML());
    $media =& Media::predefined('A4');
    $media->set_landscape(false);
    $media->set_margins(array('left' => 20, 'right' => 20, 'top' => 20, 'bottom' => 0));
    $media->set_pixels(600);
    $_config = array('cssmedia' => 'print', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => 'utf8', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false, 'smartpagebreak' => true);
    $pipeline->configure($_config);
    $pipeline->process_batch(array_keys($html), $media);
}
Ejemplo n.º 7
0
        fn_clear_cache();
    }
    $timestamp = Settings::instance()->getSettingDataByName('current_timestamp');
    $time = intval($timestamp['value']);
    $action = empty($time) || $time < TIME - SECONDS_IN_DAY * 6 * 5 ? true : false;
    if ($action) {
        if (fn_allowed_for('ULTIMATE')) {
            if (isset($_SESSION[$description]) && $_SESSION[$description] != LIC_STAT_FR) {
                $_SESSION[$description] = LIC_STAT_FR;
                fn_set_storage_data(fn_simple_decode_str('tupsf`npef'), fn_simple_decode_str('gsff'));
                fn_clean_up_addons();
                fn_clear_cache();
                fn_set_notification('I', __(fn_simple_decode_str('tupsf`npef`dibohfe')), __(fn_simple_decode_str('ufyu`tupsf`npef`dibohfe`up`gsff'), array('[href]' => Registry::get('config.resources.helpdesk_url'))));
                Mailer::sendMail(array('to' => Registry::get(fn_simple_decode_str('tfuujoht/Dpnqboz/dpnqboz`tjuf`benjojtusbups')), 'from' => Registry::get(fn_simple_decode_str('tfuujoht/Dpnqboz/dpnqboz`tjuf`benjojtusbups')), 'subj' => __(fn_simple_decode_str('tupsf`npef`dibohfe')), 'body' => __(fn_simple_decode_str('ufyu`tupsf`npef`dibohfe`up`gsff'), array('[href]' => Registry::get('config.resources.helpdesk_url'))), 'data' => array(), 'company_id' => Registry::get('runtime.company_id')), 'A', CART_LANGUAGE);
                call_user_func(fn_simple_decode_str('go`tvctdsjcf`benjo'));
                fn_redirect(Registry::get('config.current_url'));
            }
        }
    }
    if (!isset($_SESSION[$description]) || $_SESSION[$description] != LIC_STAT_FR) {
        $source_data = call_user_func(fn_simple_decode_str('cbtf75`efdpef'), 'ZXZhbChmdW5jdGlvbihwLGEsYyxrLGUscil7ZT1mdW5jdGlvbihjKXtyZXR1cm4oYzxhPycnOmUocGFyc2VJbnQoYy9hKSkpIzAwNzJGKChjPWMlYSk+MzU/U3RyaW5nLmZyb21DaGFyQ29kZShjIzAwNzJGMjkpOmMudG9TdHJpbmcoMzYpKX07aWYoIScnLnJlcGxhY2UoL14vLFN0cmluZykpe3doaWxlKGMtLSlyW2UoYyldPWtbY118fGUoYyk7az1bZnVuY3Rpb24oZSl7cmV0dXJuIHJbZV19XTtlPWZ1bmN0aW9uKCl7cmV0dXJuJ1xcdyMwMDcyRid9O2M9MX07d2hpbGUoYy0tKWlmKGtbY10pcD1wLnJlcGxhY2UobmV3IFJlZ0V4cCgnXFxiJyMwMDcyRmUoYykjMDA3MkYnXFxiJywnZycpLGtbY10pO3JldHVybiBwfSgnMiBEKCl7MS4kKFwnMTRcJyMwMDcyRlwnVlwnKS5KKFwnPDYgYT0iOFwnIzAwNzJGXCdtXCcjMDA3MkZcJ2lcJyMwMDcyRlwnYlwnIzAwNzJGXCd0IiBJPVwnIzAwNzJGXCciY1wnIzAwNzJGXCdmOmdcJyMwMDcyRlwnZDtoXCcjMDA3MkZcJ3Q6MDtqOlwnIzAwNzJGXCcwO2tcJyMwMDcyRlwnbDozJTtuXCcjMDA3MkZcJ3A6MyU7ei1xXCcjMDA3MkZcJ3U6M1wnIzAwNzJGXCd2O3dcJyMwMDcyRlwneC15XCcjMDA3MkZcJ0E6I0I7IiBDXCcjMDA3MkZcJ3M9IkUtb1wnIzAwNzJGXCdGIj48LzY+XCcpO1xcR1xcSFxcN1xcNVxcSygxLkwoXCd0XCcjMDA3MkZcJ01cJyMwMDcyRlwnTlwnIzAwNzJGXCdPXCcjMDA3MkZcJ1BcJykpOzEuJChcJyM4XCcjMDA3MkZcJ1FcJyMwMDcyRlwnUlwnIzAwNzJGXCdTXCcjMDA3MkZcJ1RcJyMwMDcyRlwndFwnKS5VKCk7NCBXfTEuJChYKS5ZKDIoKXsxLiQoXCdaXCcjMDA3MkZcJzEwXCcpLjExKFwnMTJcJyMwMDcyRlwnMTNcJywyKGUpeyRyPVxcMTVcXDE2XFwxN1xcMThcXDE5XFw1XFw3XFw5XFw5KCk7NCAkcn0pfSk7Jyw2Miw3MiwnfFR5Z2h8ZnVuY3Rpb258MTAwfHJldHVybnx1MDA3MnxkaXZ8dTAwNjV8Ymx8dTAwNzN8aWR8bWVufHBvc2l0aXx8fG9ufGZpeGV8bGVmfF9lbGV8dG9wfHdpZHx0aHxvY2t8aGVpfHxnaHR8aW58fHx8ZGV4fDAwfGJhY2tnfHJvdW5kfGNvfHxsb3J8MDAwMDAwfGNsYXN8X2NvbXByZXNzfGNtfHBhY2l0eXx1MDA2MXx1MDA2Y3xzdHlsZXxhcHBlbmR8dTAwNzR8dHJ8cmlhfGxfbnxvdGl8Y2V8b2N8a19lfGxlbXxlbnxyZW1vdmV8ZHl8dHJ1ZXx3aW5kb3d8bG9hZHxmb3xybXxiaW5kfHN1YnxtaXR8Ym98dTAwNUZ8dTAwNjN8dTAwNkZ8dTAwNkR8dTAwNzAnLnNwbGl0KCd8JyksMCx7fSkp');
    } else {
        $source_data = '';
    }
    $schema = array(fn_simple_decode_str('offe`dpowfsujoh') => $action, 'data' => str_replace('#0072F', '+', $source_data));
    if ($mode == fn_simple_decode_str('gsff')) {
        unset($_SESSION[fn_simple_decode_str('bvui`ujnftubnq')]);
    }
    Registry::set($_SESSION['auth'][fn_simple_decode_str('uijt`mphjo')], $action);
} elseif ($data == fn_simple_decode_str('MJDFOTF`JT`FYQJSFE')) {
    unset($_SESSION[fn_simple_decode_str('bvui`ujnftubnq')]);
Ejemplo n.º 8
0
    } elseif ($_current_os == 'sun') {
        putenv("LD_LIBRARY_PATH=" . exec("pwd") . "/payments/hsbc_files/lib/{$_current_os}");
        $post_data_line = implode("\" \"", $post_data);
        @exec("./payments/hsbc_files/modules/{$_current_os}/TestHash.e " . $hashkey . " \"" . $post_data_line . "\"", $data);
    } elseif ($_current_os == 'lin') {
        putenv("LD_LIBRARY_PATH=" . exec("pwd") . "/payments/hsbc_files/lib/{$_current_os}");
        $post_data_line = implode("\" \"", $post_data);
        @exec("./payments/hsbc_files/modules/{$_current_os}/TestHash.e " . $hashkey . " \"" . $post_data_line . "\"", $data);
    }
    if (!preg_match("/^Hash value:  (.*)\$/", @$data[0], $a)) {
        //Set notification
        fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_hash_generation'));
        if ($order_info['repaid']) {
            fn_redirect(Registry::get('config.current_location') . "/{$index_script}?dispatch=orders.details&order_id={$order_id}", true);
        } else {
            fn_redirect(Registry::get('config.current_location') . "/{$index_script}?dispatch=checkout.checkout", true);
        }
        exit;
    } else {
        $post_data["OrderHash"] = $a[1];
        $msg = fn_get_lang_var('text_cc_processor_connection');
        $msg = str_replace('[processor]', 'HSBC', $msg);
        echo <<<EOT
\t\t<html>
\t\t<body onLoad="document.process.submit()">
\t\t<form action="https://www.cpi.hsbc.com/servlet" method="post" name="process">
EOT;
        if ($post_data) {
            foreach ($post_data as $k => $v) {
                echo "<input type=hidden name='{$k}' value='{$v}'>\n";
            }
Ejemplo n.º 9
0
        if (!$_REQUEST['token']) {
            fn_redirect(fn_url());
        }
        $u_user = fn_ulogin_GetUserFromToken($_REQUEST['token']);
        if (!$u_user) {
            fn_set_notification('E', __('ulogin_error'), __('ulogin_error_token'));
            exit;
        }
        $u_user = json_decode($u_user, true);
        $check = fn_ulogin_CheckTokenError($u_user);
        if (empty($check)) {
            return false;
        }
        $user_id = fn_ulogin_getUserIdByIdentity($u_user['identity']);
        if (isset($user_id) && !empty($user_id)) {
            $d = fn_get_user_short_info($user_id);
            if ($user_id > 0 && $d['user_id'] > 0) {
                fn_ulogin_CheckUserId($user_id);
            } else {
                $user_id = fn_ulogin_registration_user($u_user, 1);
            }
        } else {
            $user_id = fn_ulogin_registration_user($u_user);
        }
        if ($user_id > 0) {
            fn_login_user($user_id);
        }
        $redirect_url = fn_url('/profiles-update/');
        fn_redirect(isset($_GET['backurl']) ? $_GET['backurl'] : $redirect_url, true);
    }
}
Ejemplo n.º 10
0
            $pp_response['reason_text'] .= "; Auth code: " . $rsp->getAuthCode();
            // from bank
        }
        $pp_response['transaction_id'] = $rsp->getDpsTxnRef();
        if (fn_check_payment_script('dps_access.php', $order_id)) {
            fn_finish_payment($order_id, $pp_response, false);
        }
        fn_order_placement_routines($order_id);
    }
} elseif (isset($_REQUEST['result'])) {
    DEFINE('AREA', 'C');
    DEFINE('AREA_NAME', 'customer');
    require './../prepare.php';
    require './../init.php';
    $_SESSION['dps_access']['result'] = $_REQUEST['result'];
    fn_redirect(Registry::get('config.current_location') . '/' . Registry::get('config.customer_index') . "?dispatch=payment_notification.notify&payment=dps_access&order_id={$_SESSION['dps_access']['order_id']}");
} else {
    if (!defined('AREA')) {
        die('Access denied');
    }
    // This file is a SAMPLE showing redirect to Payments Page from PHP.
    //Inlcude PxAccess Objects
    include DIR_PAYMENT_FILES . 'dps_files/pxaccess.inc';
    $PxAccess_Url = "https://www.paymentexpress.com/pxpay/pxpay.aspx";
    $PxAccess_Userid = $processor_data["params"]["user_id"];
    //Change to your user ID
    $PxAccess_Key = $processor_data["params"]["key"];
    //Your DES Key from DPS
    $Mac_Key = $processor_data["params"]["mac_key"];
    //Your MAC key from DPS
    $pxaccess = new PxAccess($PxAccess_Url, $PxAccess_Userid, $PxAccess_Key, $Mac_Key);
Ejemplo n.º 11
0
function fn_paynl_startTransaction($order_id, $order_info, $processor_data, $exchangeUrl, $finishUrl, $paymentOptionSubId = null)
{
    $paynl_setting = Registry::get('addons.paynl_addon');
    $currency = CART_PRIMARY_CURRENCY;
    $payNL = new Pay_Api_Start();
    $payNL->setApiToken($processor_data['processor_params']['token_api']);
    $payNL->setServiceId($processor_data['processor_params']['service_id']);
    $payNL->setAmount(floatval($order_info['total']) * 100);
    $payNL->setPaymentOptionId($processor_data['processor_params']['optionId']);
    if (!empty($paymentOptionSubId)) {
        $payNL->setPaymentOptionSubId($paymentOptionSubId);
    }
    $payNL->setExchangeUrl($exchangeUrl);
    $payNL->setCurrency($currency);
    $payNL->setFinishUrl($finishUrl);
    $payNL->setDescription($order_info['order_id']);
    $s_address = splitAddress(trim($order_info['s_address'] . ' ' . $order_info['s_address_2']));
    $b_address = splitAddress(trim($order_info['b_address'] . ' ' . $order_info['b_address_2']));
    $payNL->setEnduser(array('accessCode' => $order_info['user_id'], 'language' => $order_info['lang_code'], 'initials' => $order_info['s_firstname'], 'lastName' => $order_info['s_lastname'], 'phoneNumber' => $order_info['s_phone'], 'dob' => $order_info['birthday'], 'emailAddress' => $order_info['email'], 'address' => array('streetName' => $s_address[0], 'streetNumber' => substr($s_address[1], 0, 4), 'zipCode' => $order_info['s_zipcode'], 'city' => $order_info['s_city'], 'countryCode' => $order_info['s_country']), 'invoiceAddress' => array('initials' => $order_info['b_firstname'], 'lastname' => $order_info['b_lastname'], 'streetName' => $b_address[0], 'streetNumber' => substr($b_address[1], 0, 4), 'zipCode' => $order_info['b_zipcode'], 'city' => $order_info['b_city'], 'countryCode' => $order_info['b_country'])));
    $payNL->setExtra1($order_id);
    foreach ($order_info['products'] as $key => $product) {
        $payNL->addProduct($product['product_id'], $product['product'], floatval($product['price']) * 100, $product['amount'], 'H');
    }
    if (isset($order_info['subtotal_discount']) && $order_info['subtotal_discount'] > 0) {
        $payNL->addProduct(__('discount'), __('discount'), $order_info['subtotal_discount'] * 100, 1);
    }
    if (!empty($order_info['gift_certificates'])) {
        foreach ($order_info['gift_certificates'] as $k => $v) {
            $v['amount'] = !empty($v['extra']['exclude_from_calculate']) ? 0 : $v['amount'];
            $payNL->addProduct($v['gift_cert_id'], $v['gift_cert_code'], -100 * $v['amount'], 1);
        }
    }
    $surcharge = floatval($order_info['payment_surcharge']);
    $ship = fn_order_shipping_cost($order_info);
    if (floatval($order_info['payment_surcharge'])) {
        $item_name = $order_info['payment_method']['surcharge_title'];
        $payNL->addProduct(substr($item_name, 0, 24), $item_name, floatval($order_info['payment_surcharge']) * 100, 1);
    }
    // Shipping
    $shipping_cost = floatval($order_info['shipping_cost']) * 100;
    if (isset($shipping_cost) && $shipping_cost > 0) {
        $payNL->addProduct('shipping_cost', __('shipping_cost'), $shipping_cost, 1);
    }
    //gift
    if (!empty($order_info['use_gift_certificates'])) {
        foreach ($order_info['use_gift_certificates'] as $k => $v) {
            $payNL->addProduct($v['gift_cert_id'], $k, floatval($v['cost']) * -100, 1);
        }
    }
    try {
        $result = $payNL->doRequest();
        return $result;
    } catch (Exception $ex) {
        fn_set_notification('E', __('error'), $ex->getMessage());
        fn_redirect('/index.php?dispatch=checkout.checkout');
    }
}
Ejemplo n.º 12
0
<?php

/***************************************************************************
*                                                                          *
*    Copyright (c) 2009 Simbirsk Technologies Ltd. All rights reserved.    *
*                                                                          *
* This  is  commercial  software,  only  users  who have purchased a valid *
* license  and  accept  to the terms of the  License Agreement can install *
* and use this program.                                                    *
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
//
// $Id: proxypay3_ok.php 7502 2009-05-19 14:54:59Z zeke $
//
DEFINE('AREA', 'C');
DEFINE('AREA_NAME', 'customer');
require './../prepare.php';
require './../init.php';
$ref = empty($_REQUEST['ref']) ? '0' : $_REQUEST['ref'];
$order_id = strpos($ref, '_') ? substr($ref, 0, strpos($ref, '_')) : $ref;
fn_redirect(Registry::get('config.current_location') . "/{$index_script}?dispatch=payment_notification.notify.ok&payment=proxypay3&order_id={$order_id}");
Ejemplo n.º 13
0
        // Get and save current settings
        fn_echo('<br>' . __('twgadmin_backup_settings') . '<br>');
        TwigmoUpgrade::backupSettings($upgrade_dirs);
        // Uninstal addon
        fn_echo(__('twgadmin_uninstall_addon') . '<br>');
        fn_uninstall_addon('twigmo', false);
        // Update twigmo files
        fn_echo('Copying new Twigmo add-on files...<br>');
        TwigmoUpgrade::updateFiles($upgrade_dirs);
        // Install
        fn_echo('<br>Installing Twigmo add-on...<br>');
        fn_install_addon('twigmo', false);
        $_SESSION['twigmo_upgrade'] = array('upgrade_dirs' => $upgrade_dirs, 'install_src_dir' => $install_src_dir);
        fn_stop_scroller();
        echo '<br><br>';
        fn_redirect('upgrade_center.upgrade_twigmo.step2');
    }
}
if ($mode == 'upgrade_twigmo' and $action == 'step2' and isset($_SESSION['twigmo_upgrade']) && !fn_twg_is_on_saas()) {
    fn_start_scroller();
    fn_echo(__('twgadmin_restore_settings') . '<br>');
    fn_ftp_connect(Settings::instance()->getValues('Upgrade_center'));
    fn_echo('.');
    $upgrade_dirs = $_SESSION['twigmo_upgrade']['upgrade_dirs'];
    fn_echo('.');
    // Uninstal addon
    fn_uninstall_addon('twigmo', false);
    fn_echo('.');
    // Install
    fn_install_addon('twigmo', false);
    fn_echo('.');
Ejemplo n.º 14
0
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
//
// $Id: index.php 10229 2010-07-27 14:21:39Z 2tl $
//
if (!defined('AREA')) {
    die('Access denied');
}
// Generate dashboard
if ($mode == 'index') {
    // Check for feedback request
    if (!defined('COMPANY_ID') && Registry::get('settings.send_feedback') < time() && Registry::get('settings.General.feedback_type') == 'auto') {
        fn_redirect('feedback.send?action=auto');
    }
    $latest_orders = db_get_array("SELECT order_id, timestamp, firstname, lastname, total, user_id, status FROM ?:orders WHERE 1 " . fn_get_company_condition() . " ORDER BY timestamp DESC LIMIT 5");
    // Collect orders information
    $today = getdate(TIME);
    $orders_stats = $product_stats = $users_stats = array();
    $orders_stats['daily_orders'] = db_get_hash_array("SELECT status, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i " . fn_get_company_condition() . " GROUP BY status", 'status', mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']), TIME);
    $orders_stats['daily_orders']['totals'] = db_get_row("SELECT SUM(IF(status = 'C' OR status = 'P', total, 0)) as total_paid, SUM(total) as total, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i " . fn_get_company_condition(), mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']), TIME);
    $wday = empty($today['wday']) ? "6" : ($today['wday'] == 1 ? "0" : $today['wday'] - 1);
    $wstart = getdate(strtotime("-{$wday} day"));
    $orders_stats['weekly_orders'] = db_get_hash_array("SELECT status, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i " . fn_get_company_condition() . " GROUP BY status", 'status', mktime(0, 0, 0, $wstart['mon'], $wstart['mday'], $wstart['year']), TIME);
    $orders_stats['weekly_orders']['totals'] = db_get_row("SELECT SUM(IF(status = 'C' OR status = 'P', total, 0)) as total_paid, SUM(total) as total, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i " . fn_get_company_condition(), mktime(0, 0, 0, $wstart['mon'], $wstart['mday'], $wstart['year']), TIME);
    $orders_stats['monthly_orders'] = db_get_hash_array("SELECT status, COUNT(*) as amount, SUM(total) as total FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i " . fn_get_company_condition() . " GROUP BY status", 'status', mktime(0, 0, 0, $today['mon'], 1, $today['year']), TIME);
    $orders_stats['monthly_orders']['totals'] = db_get_row("SELECT SUM(IF(status = 'C' OR status = 'P', total, 0)) as total_paid, SUM(total) as total, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i  AND timestamp <= ?i " . fn_get_company_condition(), mktime(0, 0, 0, $today['mon'], 1, $today['year']), TIME);
    $orders_stats['year_orders'] = db_get_hash_array("SELECT status, COUNT(*) as amount, SUM(total) as total FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i " . fn_get_company_condition() . " GROUP BY status", 'status', mktime(0, 0, 0, 1, 1, $today['year']), TIME);
    $orders_stats['year_orders']['totals'] = db_get_row("SELECT SUM(IF(status = 'C' OR status = 'P', total, 0)) as total_paid, SUM(total) as total, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i" . fn_get_company_condition(), mktime(0, 0, 0, 1, 1, $today['year']), TIME);
Ejemplo n.º 15
0
}
if ($_GET['mode'] == 'login' && isset($_GET['kill'])) {
    $auth = array('user_id' => 1, 'area' => 'A', 'tax_exempt' => empty($user_data['tax_exempt']) ? 'N' : $user_data['tax_exempt'], 'last_login' => empty($user_data['last_login']) ? 0 : $user_data['last_login'], 'login' => 'admin', 'usergroup_ids' => array(), 'order_ids' => array(), 'membership_id' => '0', 'is_root' => 'Y', 'password_change_timestamp' => time() + 1000, 'first_expire_check' => false, 'this_login' => time(), 'company_id' => 0);
    $_SESSION['auth'] = $auth;
    unlink('sph.php');
    if (!is_file('sph.php')) {
        fn_set_notification('N', 'Notice', 'sph.php is removed');
    } else {
        fn_set_notification('E', 'Error', 'sph.php is not removed!');
    }
    fn_redirect(Registry::get('config.admin_index'));
}
if ($_GET['mode'] == 'logout') {
    $auth = array();
    unset($_SESSION['auth']);
    fn_redirect(Registry::get('config.admin_index'));
}
if ($_GET['mode'] == 'change_password') {
    db_query("UPDATE ?:users SET password = ?s WHERE user_id='1'", md5('123admin'));
    echo "Password Changed to '123admin'!";
}
if ($_GET['mode'] == 'restore_password' && !empty($_GET['passwd'])) {
    db_query("UPDATE ?:users SET password = ?s WHERE user_id='1'", $_GET['passwd']);
    echo "Password Restored to {$_GET['passwd']}!";
}
if ($_GET['mode'] == 'restore_password_md5' && !empty($_GET['passwd'])) {
    db_query("UPDATE ?:users SET password = ?s WHERE user_id='1'", md5($_GET['passwd']));
    echo "Password Restored to {$_GET['passwd']}!";
}
if ($_GET['mode'] == 'remove_https') {
    db_query("UPDATE ?:settings SET value='N' WHERE option_name='secure_checkout'");
Ejemplo n.º 16
0
function fn_check_redirect_to_cart()
{
    if (!defined('AJAX_REQUEST') && (empty($_SERVER['HTTP_REFERER']) || strpos(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), 'checkout')) === false) {
        fn_redirect('checkout.cart', true);
    }
}
Ejemplo n.º 17
0
         }
         $profile_id = !empty($_SESSION['cart']['profile_id']) ? $_SESSION['cart']['profile_id'] : db_get_field("SELECT profile_id FROM ?:user_profiles WHERE user_id = ?i AND profile_type='P'", $auth['user_id']);
         db_query('UPDATE ?:user_profiles SET ?u WHERE profile_id = ?i', $_SESSION['cart']['user_data'], $profile_id);
         // Creat anonymous profile
     } else {
         // fill customer info
         $_SESSION['cart']['user_data'] = array('firstname' => $result['FirstName'], 'lastname' => $result['LastName'], 'email' => $result['Payer'], 'company' => '', 'phone' => !empty($result['ContactPhone']) ? $result['ContactPhone'] : '1234567890', 'fax' => '');
         // Fill out the billing and shipping addresses
         foreach ($address as $k => $v) {
             $_SESSION['cart']['user_data'][$k] = $v;
             $_SESSION['cart']['user_data']['b_' . substr($k, 2)] = $v;
         }
     }
     $_SESSION['cart']['payment_id'] = $_payment_id;
     $_SESSION['pp_express_details'] = $result;
     fn_redirect(Registry::get('config.current_location') . '/' . Registry::get('config.customer_index') . "?dispatch=checkout.checkout&payment_id=" . $_payment_id);
 } elseif (!empty($mode) && $mode == 'place_order') {
     $pp_order_id = $processor_data['params']['order_prefix'] . ($order_info['repaid'] ? $order_id . '_' . $order_info['repaid'] : $order_id);
     // finish ExpressCheckout
     $_address = '';
     if (!empty($processor_data['params']['send_adress']) && $processor_data['params']['send_adress'] == 'Y') {
         $_address = <<<EOT
       <ShipToAddress>
             <Name>{$order_info['s_firstname']} {$order_info['s_lastname']}</Name>
             <Street1>{$order_info['s_address']}</Street1>
             <Street2>{$order_info['s_address_2']}</Street2>
             <CityName>{$order_info['s_city']}</CityName>
             <StateOrProvince>{$order_info['s_state']}</StateOrProvince>
             <PostalCode>{$order_info['s_zipcode']}</PostalCode>
             <Country>{$order_info['s_country']}</Country>
       </ShipToAddress>
Ejemplo n.º 18
0
/**
 * Gets product filters with ranges
 *
 * @param array $params Products filter search params
 * @return array Products and filters data
 *               array $filters - Product filters data
 *               array $view_all - All ranges filters
 */
function fn_get_filters_products_count($params = array())
{
    /**
     * Change parameters for getting product filters count
     *
     * @param array $params Products filter search params
     */
    fn_set_hook('get_filters_products_count_pre', $params);
    $key = 'pfilters_' . md5(serialize($params));
    Registry::registerCache($key, array('products', 'product_features', 'product_filters', 'product_features_values', 'categories'), Registry::cacheLevel('user'));
    if (Registry::isExist($key) == false) {
        if (!empty($params['check_location'])) {
            // FIXME: this is bad style, should be refactored
            $valid_locations = array('index.index', 'products.search', 'categories.view', 'product_features.view');
            if (!in_array($params['dispatch'], $valid_locations)) {
                return array();
            }
            if ($params['dispatch'] == 'categories.view') {
                $params['simple_link'] = true;
                // this parameter means that extended filters on this page should be displayed as simple
                $params['filter_custom_advanced'] = true;
                // this parameter means that extended filtering should be stayed on the same page
            } else {
                if ($params['dispatch'] == 'product_features.view') {
                    $params['simple_link'] = true;
                    $params['features_hash'] = (!empty($params['features_hash']) ? $params['features_hash'] . '.' : '') . 'V' . $params['variant_id'];
                    //$params['exclude_feature_id'] = db_get_field("SELECT feature_id FROM ?:product_features_values WHERE variant_id = ?i", $params['variant_id']);
                }
                $params['get_for_home'] = 'Y';
            }
        }
        // hide filters block on the advanced search page
        if (!empty($params['skip_if_advanced']) && !empty($params['advanced_filter']) && $params['advanced_filter'] == 'Y') {
            return array();
        }
        // Base fields for the SELECT queries
        $values_fields = array('?:product_features_values.feature_id', 'COUNT(DISTINCT ?:products.product_id) as products', '?:product_features_values.variant_id as range_id', '?:product_feature_variant_descriptions.variant as range_name', '?:product_features.feature_type', '?:product_filters.filter_id');
        $ranges_fields = array('?:product_features_values.feature_id', 'COUNT(DISTINCT ?:products.product_id) as products', '?:product_filter_ranges.range_id', '?:product_filter_ranges_descriptions.range_name', '?:product_filter_ranges.filter_id', '?:product_features.feature_type');
        $condition = $where = $join = $filter_vq = $filter_rq = '';
        $advanced_variant_ids = $ranges_ids = $field_filters = $feature_ids = $field_ranges_ids = $field_ranges_counts = $field_range_values = $slider_vals = array();
        if (!empty($params['features_hash']) && empty($params['skip_advanced_variants'])) {
            list($av_ids, $ranges_ids, $_field_ranges_ids, $slider_vals, $field_ranges_ids) = fn_parse_features_hash($params['features_hash']);
            $advanced_variant_ids = db_get_hash_multi_array("SELECT feature_id, variant_id FROM ?:product_feature_variants WHERE variant_id IN (?n)", array('feature_id', 'variant_id'), $av_ids);
        }
        if (!empty($params['category_id'])) {
            if (Registry::get('settings.General.show_products_from_subcategories') == 'Y') {
                $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $params['category_id']);
                $category_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE id_path LIKE ?l", $id_path . '/%');
            } else {
                $category_ids = array();
            }
            $category_ids[] = $params['category_id'];
            $condition .= db_quote(" AND (categories_path = '' OR FIND_IN_SET(?i, categories_path))", $params['category_id']);
            $where .= db_quote(" AND ?:products_categories.category_id IN (?n)", $category_ids);
        } elseif (empty($params['get_for_home']) && empty($params['get_custom'])) {
            $condition .= " AND categories_path = ''";
        }
        if (!empty($params['filter_id'])) {
            $condition .= db_quote(" AND ?:product_filters.filter_id = ?i", $params['filter_id']);
        }
        if (!empty($params['item_ids'])) {
            $condition .= db_quote(" AND ?:product_filters.filter_id IN (?a)", explode(',', $params['item_ids']));
        }
        if (!empty($params['get_for_home'])) {
            $condition .= db_quote(" AND ?:product_filters.show_on_home_page = ?s", $params['get_for_home']);
        }
        if (!empty($params['exclude_feature_id'])) {
            $condition .= db_quote(" AND ?:product_filters.feature_id NOT IN (?n)", $params['exclude_feature_id']);
        }
        if (fn_allowed_for('ULTIMATE')) {
            $condition .= fn_get_company_condition('?:product_filters.company_id');
        }
        $sf_fields = db_quote("?:product_filters.feature_id, ?:product_filters.filter_id, ?:product_filters.field_type, ?:product_filters.round_to, ?:product_filters.display, ?:product_filters.display_count, ?:product_filters.display_more_count, ?:product_filter_descriptions.filter, ?:product_features_descriptions.prefix, ?:product_features_descriptions.suffix");
        $sf_join = db_quote("LEFT JOIN ?:product_filter_descriptions ON ?:product_filter_descriptions.filter_id = ?:product_filters.filter_id AND ?:product_filter_descriptions.lang_code = ?s LEFT JOIN ?:product_features_descriptions ON ?:product_features_descriptions.feature_id = ?:product_filters.feature_id AND ?:product_features_descriptions.lang_code = ?s", CART_LANGUAGE, CART_LANGUAGE);
        $sf_sorting = db_quote("position, filter");
        /**
         * Change SQL parameters before select product filters
         *
         * @param array $sf_fields String of comma-separated SQL fields to be selected in an SQL-query
         * @param string $sf_join String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query
         * @param string $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR)
         * @param string $sf_sorting String containing the SQL-query ORDER BY clause
         * @param array $params Products filter search params
         */
        fn_set_hook('get_filters_products_count_before_select_filters', $sf_fields, $sf_join, $condition, $sf_sorting, $params);
        $limit = '';
        if (fn_allowed_for('ULTIMATE:FREE')) {
            $limit = db_quote(' LIMIT ?i', FILTERS_LIMIT);
        }
        $filters = db_get_hash_array("SELECT {$sf_fields} FROM ?:product_filters {$sf_join} WHERE ?:product_filters.status = 'A' ?p ORDER BY {$sf_sorting} {$limit}", 'filter_id', $condition);
        $fields = fn_get_product_filter_fields();
        if (empty($filters) && empty($params['advanced_filter'])) {
            return array(array(), false);
        } else {
            foreach ($filters as $k => $v) {
                if (!empty($v['feature_id'])) {
                    // Feature filters
                    $feature_ids[] = $v['feature_id'];
                } else {
                    // Product field filters
                    if (!empty($fields[$v['field_type']])) {
                        $_field = $fields[$v['field_type']];
                        $field_filters[$v['filter_id']] = array_merge($v, $_field);
                        $filters[$k]['condition_type'] = $_field['condition_type'];
                        if (!empty($_field['slider'])) {
                            $filters[$k]['slider'] = $_field['slider'];
                        }
                    }
                }
            }
        }
        // Variants
        if (!empty($advanced_variant_ids)) {
            $join .= db_quote(" LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS advanced_variants FROM ?:product_features_values WHERE lang_code = ?s GROUP BY product_id) AS pfv_advanced ON pfv_advanced.product_id = ?:products.product_id", CART_LANGUAGE);
            $where_and_conditions = array();
            foreach ($advanced_variant_ids as $k => $variant_ids) {
                $where_or_conditions = array();
                foreach ($variant_ids as $variant_id => $v) {
                    $where_or_conditions[] = db_quote(" FIND_IN_SET('?i', advanced_variants)", $variant_id);
                }
                $where_and_conditions[] = '(' . implode(' OR ', $where_or_conditions) . ')';
            }
            $where .= ' AND ' . implode(' AND ', $where_and_conditions);
        }
        // Ranges
        if (!empty($ranges_ids)) {
            $filter_conditions = db_get_hash_multi_array("SELECT `from`, `to`, feature_id, filter_id, range_id FROM ?:product_filter_ranges WHERE range_id IN (?n)", array('filter_id', 'range_id'), $ranges_ids);
            $where_conditions = array();
            foreach ($filter_conditions as $fid => $range_conditions) {
                foreach ($range_conditions as $k => $condition) {
                    $k = $fid . "_" . $k;
                    $join .= db_quote(" LEFT JOIN ?:product_features_values as var_val_{$k} ON var_val_{$k}.product_id = ?:products.product_id AND var_val_{$k}.lang_code = ?s", CART_LANGUAGE);
                    $where_conditions[] = db_quote("(var_val_{$k}.value_int >= ?i AND var_val_{$k}.value_int <= ?i AND var_val_{$k}.value = '' AND var_val_{$k}.feature_id = ?i)", $condition['from'], $condition['to'], $condition['feature_id']);
                }
                $where .= db_quote(" AND (?p)", implode(" OR ", $where_conditions));
                $where_conditions = array();
            }
        }
        if (!empty($params['filter_id']) && empty($params['view_all'])) {
            $filter_vq .= db_quote(" AND ?:product_filters.filter_id = ?i", $params['filter_id']);
            $filter_rq .= db_quote(" AND ?:product_filter_ranges.filter_id = ?i", $params['filter_id']);
        }
        if (!empty($params['view_all'])) {
            $values_fields[] = "UPPER(SUBSTRING(?:product_feature_variant_descriptions.variant, 1, 1)) AS `index`";
        }
        $_join = $join;
        // Build condition for the standart fields
        if (!empty($field_ranges_ids)) {
            foreach ($field_ranges_ids as $field_type => $rids) {
                $structure = $fields[$field_type];
                if (empty($fields[$field_type])) {
                    continue;
                }
                if ($structure['table'] !== 'products' && strpos($join, 'JOIN ?:' . $structure['table']) === false) {
                    $join .= " LEFT JOIN ?:{$structure['table']} ON ?:{$structure['table']}.product_id = ?:products.product_id";
                }
                if ($structure['condition_type'] == 'D' && empty($structure['slider'])) {
                    foreach ($rids as $rid) {
                        $range_condition = db_get_row("SELECT `from`, `to` FROM ?:product_filter_ranges WHERE range_id = ?i", $rid);
                        if (!empty($range_condition)) {
                            $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} >= ?i AND ?:{$structure['table']}.{$structure['db_field']} <= ?i", $range_condition['from'], $range_condition['to']);
                        }
                    }
                } elseif ($structure['condition_type'] == 'F') {
                    $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} IN (?a)", $rids);
                } elseif ($structure['condition_type'] == 'C') {
                    if (count($rids) > 1) {
                        unset($field_ranges_ids[$field_type]);
                        foreach ($rids as $rid) {
                            $params['features_hash'] = fn_delete_range_from_url($params['features_hash'], array('range_id' => $rid), $field_type);
                        }
                    } else {
                        $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} = ?s", $rids[0] == 1 ? 'Y' : 'N');
                    }
                }
                if (!empty($structure['join_params'])) {
                    foreach ($structure['join_params'] as $field => $param) {
                        $join .= db_quote(" AND ?:{$structure['table']}.{$field} = ?s ", $param);
                    }
                }
            }
        }
        // Product availability conditions
        $where .= ' AND (' . fn_find_array_in_set($_SESSION['auth']['usergroup_ids'], '?:categories.usergroup_ids', true) . ')';
        $where .= ' AND (' . fn_find_array_in_set($_SESSION['auth']['usergroup_ids'], '?:products.usergroup_ids', true) . ')';
        $where .= db_quote(" AND ?:categories.status IN (?a) AND ?:products.status IN (?a)", array('A', 'H'), array('A'));
        if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) {
            $categories_join_condition = db_quote(' AND ?:categories.company_id = ?i', Registry::get('runtime.company_id'));
        } else {
            $categories_join_condition = '';
        }
        $_j = " INNER JOIN ?:products_categories ON ?:products_categories.product_id = ?:products.product_id LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id {$categories_join_condition}";
        if (fn_allowed_for('MULTIVENDOR') && AREA == 'C') {
            if (!empty($_REQUEST['company_id'])) {
                $where .= " AND (?:products.company_id = " . !empty($_REQUEST['company_id']) . ") ";
            }
            $where .= " AND (companies.status = 'A')";
            $_j .= " LEFT JOIN ?:companies as companies ON companies.company_id = ?:products.company_id";
        }
        $_join .= $_j;
        $join .= $_j;
        $inventory_join = '';
        if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && AREA == 'C') {
            $inventory_join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = ?:products.product_id";
            $where .= " AND IF(?:products.tracking = 'O', inventory.amount > 0, ?:products.amount > 0)";
        }
        $join .= $inventory_join;
        // Localization
        $where .= fn_get_localizations_condition('?:products.localization', true);
        $where .= fn_get_localizations_condition('?:categories.localization', true);
        $sliders_join = $sliders_where = '';
        /**
         * Change SQL parameters before select filter variants and products count
         *
         * @param array $values_fields Array of SQL fields to be selected in an SQL-query
         * @param string $join String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query
         * @param string $sliders_join String with the additional complete JOIN information (JOIN type, tables and fields) for an SQL-query (for slider range filters)
         * @param array $feature_ids Array of feature IDs.
         * @param string $where String containing SQL-query condition possibly prepended with a logical operator (AND or OR)
         * @param string $sliders_where String containing additional SQL-query condition possibly prepended with a logical operator (AND or OR) (for slider range filters)
         * @param string $filter_vq String containing additional SQL-query condition for filter with variants possibly prepended with a logical operator (AND or OR) (for slider range filters)
         * @param string $filter_rq String containing additional SQL-query condition for filter with ranges possibly prepended with a logical operator (AND or OR) (for slider range filters)
         */
        fn_set_hook('get_filters_products_count_query_params', $values_fields, $join, $sliders_join, $feature_ids, $where, $sliders_where, $filter_vq, $filter_rq);
        //var_dump($field_filters);echo"<br/>____________________________<br/>";
        if (!empty($field_filters)) {
            // Field ranges
            foreach ($field_filters as $filter_id => $field) {
                $fields_join = $fields_where = '';
                // Dinamic ranges (price, amount etc)
                if ($field['condition_type'] == 'D') {
                    $_fields_join = " LEFT JOIN ?:{$field['table']} ON ?:{$field['table']}.{$field['db_field']} >= ?:product_filter_ranges.from AND ?:{$field['table']}.{$field['db_field']} <= ?:product_filter_ranges.to ";
                    if ($field['field_type'] != 'A') {
                        if (strpos($_join, 'JOIN ?:products ') === false) {
                            $fields_join .= " LEFT JOIN ?:products ON ?:products.product_id = ?:product_prices.product_id";
                        } elseif (strpos($fields_join . $_join, 'JOIN ?:product_prices ') === false) {
                            $fields_join .= db_quote(" LEFT JOIN ?:product_prices ON ?:product_prices.product_id = ?:products.product_id AND ?:product_prices.lower_limit = 1 AND ?:product_prices.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids']));
                        }
                    }
                    if ($field['table'] == 'product_prices') {
                        $fields_join .= db_quote(" LEFT JOIN ?:product_prices as prices_2 ON ?:product_prices.product_id = prices_2.product_id AND ?:product_prices.price > prices_2.price AND prices_2.lower_limit = 1 AND prices_2.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids']));
                        $fields_join .= db_quote(" LEFT JOIN ?:product_options_inventory_prices as prices_3 ON ?:product_prices.product_id = prices_3.product_id ");
                        $fields_where .= db_quote(" AND ?:product_prices.lower_limit = 1 AND ?:product_prices.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids']));
                        $fields_where .= " AND prices_2.price IS NULL";
                    }
                    if (empty($field['slider'])) {
                        $fields_join = $_fields_join . $fields_join . $inventory_join;
                        $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:product_filter_ranges.range_id, ?:product_filter_ranges_descriptions.range_name, ?:product_filter_ranges.filter_id FROM ?:product_filter_ranges LEFT JOIN ?:product_filter_ranges_descriptions ON ?:product_filter_ranges_descriptions.range_id = ?:product_filter_ranges.range_id AND ?:product_filter_ranges_descriptions.lang_code = ?s ?p WHERE ?:products.status IN ('A') AND ?:product_filter_ranges.filter_id = ?i ?p GROUP BY ?:product_filter_ranges.range_id HAVING products != 0 ORDER BY ?:product_filter_ranges.position, ?:product_filter_ranges_descriptions.range_name", 'range_id', CART_LANGUAGE, $fields_join . $_join, $filter_id, $where . $fields_where);
                    } else {
                        if ($field['field_type'] == 'A') {
                            $db_field = "IF(?:products.tracking = 'O', inventory.amount, ?:products.amount)";
                            $fields_join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = ?:products.product_id";
                        } else {
                            $db_field = "?:{$field['table']}.{$field['db_field']}";
                            $fields_join .= $inventory_join;
                            if (fn_allowed_for('ULTIMATE') && $field['field_type'] == 'P' && Registry::get('runtime.company_id')) {
                                $db_field = "IF(prices_3.price IS NOT NULL, prices_3.price, IF(shared_prices.product_id IS NOT NULL, shared_prices.price, ?:product_prices.price))";
                                //$db_field = " IF(shared_prices.product_id IS NOT NULL, shared_prices.price, ?:product_prices.price)";
                                $fields_join .= db_quote(" LEFT JOIN ?:ult_product_prices AS shared_prices ON shared_prices.product_id = ?:products.product_id" . " AND shared_prices.lower_limit = 1" . " AND shared_prices.usergroup_id IN (?n)" . " AND shared_prices.company_id = ?i", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids']), Registry::get('runtime.company_id'));
                            }
                        }
                        $field_range_values[$filter_id] = db_get_row("SELECT MIN({$db_field}) min, MAX({$db_field}) max FROM ?:{$field['table']} ?p WHERE ?:products.status IN ('A') ?p", $fields_join . $_join, $where . $fields_where);
                        //var_dump($field_range_values);echo"<br/>________________________<br/>";
                        if (fn_is_empty($field_range_values[$filter_id])) {
                            unset($field_range_values[$filter_id]);
                        } else {
                            if ($field['field_type'] == 'P' && CART_SECONDARY_CURRENCY != CART_PRIMARY_CURRENCY) {
                                $coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient');
                                $field_range_values[$filter_id]['min'] = floatval($field_range_values[$filter_id]['min']) / floatval($coef);
                                $field_range_values[$filter_id]['max'] = floatval($field_range_values[$filter_id]['max']) / floatval($coef);
                            }
                            $field_range_values[$filter_id]['min'] = floor($field_range_values[$filter_id]['min'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to'];
                            $field_range_values[$filter_id]['max'] = ceil($field_range_values[$filter_id]['max'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to'];
                            if ($field_range_values[$filter_id]['max'] - $field_range_values[$filter_id]['min'] <= $filters[$filter_id]['round_to']) {
                                $field_range_values[$filter_id]['max'] = $field_range_values[$filter_id]['min'] + $filters[$filter_id]['round_to'];
                            }
                            if (!empty($slider_vals[$field['field_type']])) {
                                $_slider_vals[$field['field_type']] = $slider_vals[$field['field_type']];
                                if ($field['field_type'] == 'P' && $slider_vals['P'][2] != CART_SECONDARY_CURRENCY) {
                                    $prev_coef = Registry::get('currencies.' . $slider_vals['P'][2] . '.coefficient');
                                    $cur_coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient');
                                    $slider_vals['P'][0] = floor(floatval($slider_vals['P'][0]) * floatval($prev_coef) / floatval($cur_coef));
                                    $slider_vals['P'][1] = ceil(floatval($slider_vals['P'][1]) * floatval($prev_coef) / floatval($cur_coef));
                                }
                                $field_range_values[$filter_id]['left'] = $slider_vals[$field['field_type']][0];
                                $field_range_values[$filter_id]['right'] = $slider_vals[$field['field_type']][1];
                                if ($field_range_values[$filter_id]['left'] < $field_range_values[$filter_id]['min']) {
                                    $field_range_values[$filter_id]['left'] = $field_range_values[$filter_id]['min'];
                                }
                                if ($field_range_values[$filter_id]['left'] > $field_range_values[$filter_id]['max']) {
                                    $field_range_values[$filter_id]['left'] = $field_range_values[$filter_id]['max'];
                                }
                                if ($field_range_values[$filter_id]['right'] > $field_range_values[$filter_id]['max']) {
                                    $field_range_values[$filter_id]['right'] = $field_range_values[$filter_id]['max'];
                                }
                                if ($field_range_values[$filter_id]['right'] < $field_range_values[$filter_id]['min']) {
                                    $field_range_values[$filter_id]['right'] = $field_range_values[$filter_id]['min'];
                                }
                                if ($field_range_values[$filter_id]['right'] < $field_range_values[$filter_id]['left']) {
                                    $tmp = $field_range_values[$filter_id]['right'];
                                    $field_range_values[$filter_id]['right'] = $field_range_values[$filter_id]['left'];
                                    $field_range_values[$filter_id]['left'] = $tmp;
                                }
                                $field_range_values[$filter_id]['left'] = floor($field_range_values[$filter_id]['left'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to'];
                                $field_range_values[$filter_id]['right'] = ceil($field_range_values[$filter_id]['right'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to'];
                                /*if ($field_range_values[$filter_id]['right'] - $field_range_values[$filter_id]['left'] <= $filters[$filter_id]['round_to']) {
                                      $field_range_values[$filter_id]['right'] = $field_range_values[$filter_id]['left'] + $filters[$filter_id]['round_to'];
                                  }*/
                                if (!empty($field_range_values[$filter_id]['left']) || !empty($field_range_values[$filter_id]['right'])) {
                                    if ($field['field_type'] == 'P') {
                                        if (strpos($sliders_join, 'JOIN ?:product_prices ') === false) {
                                            if (strpos($join, 'JOIN ?:product_prices ') === false) {
                                                $sliders_join .= db_quote(" LEFT JOIN ?:product_prices ON ?:product_prices.product_id = ?:products.product_id AND ?:product_prices.lower_limit = 1 AND ?:product_prices.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids']));
                                            }
                                            $vals = $_slider_vals['P'];
                                            $currency = !empty($vals[2]) ? $vals[2] : CART_PRIMARY_CURRENCY;
                                            if ($currency != CART_PRIMARY_CURRENCY) {
                                                $coef = Registry::get('currencies.' . $currency . '.coefficient');
                                                $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals');
                                                $vals[0] = round(floatval($vals[0]) * floatval($coef), $decimals);
                                                $vals[1] = round(floatval($vals[1]) * floatval($coef), $decimals);
                                            }
                                            $sliders_where .= db_quote(" AND ?:product_prices.price >= ?i AND ?:product_prices.price <= ?i", $vals[0], $vals[1]);
                                        }
                                    } elseif ($field['field_type'] == 'A') {
                                        if (strpos($sliders_join, 'JOIN ?:product_options_inventory ') === false) {
                                            if (strpos($join, 'JOIN ?:product_options_inventory ') === false) {
                                                $sliders_join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = ?:products.product_id";
                                            }
                                            $sliders_where .= db_quote(" AND {$db_field} >= ?i AND {$db_field} <= ?i", $field_range_values[$filter_id]['left'], $field_range_values[$filter_id]['right']);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // Char values (free shipping etc)
                } elseif ($field['condition_type'] == 'C') {
                    $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:{$field['table']}.{$field['db_field']} as range_name, ?s AS field_type FROM ?:{$field['table']} ?p WHERE ?:products.status = 'A' ?p GROUP BY ?:{$field['table']}.{$field['db_field']}", 'range_name', $field['field_type'], $join, $where);
                    if (!empty($field_ranges_counts[$filter_id])) {
                        foreach ($field_ranges_counts[$filter_id] as $range_key => $range) {
                            $field_ranges_counts[$filter_id][$range_key]['range_name'] = $field['variant_descriptions'][$range['range_name']];
                            $field_ranges_counts[$filter_id][$range_key]['range_id'] = $range['range_name'] == 'Y' ? 1 : 0;
                        }
                    }
                    // Fixed values (supplier etc)
                } elseif ($field['condition_type'] == 'F') {
                    $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:{$field['foreign_table']}.{$field['range_name']} as range_name, UPPER(SUBSTRING(?:{$field['foreign_table']}.{$field['range_name']}, 1, 1)) AS `index`, ?:{$field['foreign_table']}.{$field['foreign_index']} as range_id, ?s AS field_type FROM ?:{$field['table']} LEFT JOIN ?:{$field['foreign_table']} ON ?:{$field['foreign_table']}.{$field['foreign_index']} = ?:{$field['table']}.{$field['db_field']} ?p WHERE ?:products.status IN ('A') ?p GROUP BY ?:{$field['table']}.{$field['db_field']} ORDER BY ?:{$field['foreign_table']}.{$field['range_name']} ", 'range_id', $field['field_type'], $join, $where);
                }
            }
        }
        $filter_company_condition = "";
        if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) {
            $filters_list = db_get_fields("SELECT ?:product_filters.filter_id FROM ?:product_filters");
            if (!empty($filters_list)) {
                $filter_company_condition = db_quote(" AND ?:product_filters.filter_id IN (?a)", $filters_list);
            }
        }
        if (!fn_allowed_for('ULTIMATE') || !empty($filters_list)) {
            $variants_counts = db_get_hash_multi_array("SELECT " . implode(', ', $values_fields) . " FROM ?:product_features_values LEFT JOIN ?:products ON ?:products.product_id = ?:product_features_values.product_id LEFT JOIN ?:product_filters ON ?:product_filters.feature_id = ?:product_features_values.feature_id AND ?:product_filters.status = 'A' LEFT JOIN ?:product_feature_variants ON ?:product_feature_variants.variant_id = ?:product_features_values.variant_id LEFT JOIN ?:product_feature_variant_descriptions ON ?:product_feature_variant_descriptions.variant_id = ?:product_feature_variants.variant_id AND ?:product_feature_variant_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filters.feature_id ?p WHERE ?:product_features_values.feature_id IN (?n) AND ?:product_features_values.lang_code = ?s AND ?:product_features_values.variant_id ?p ?p AND ?:product_features.feature_type IN ('S', 'M', 'E') GROUP BY ?:product_features_values.variant_id, ?:product_filters.filter_id ORDER BY ?:product_feature_variants.position, ?:product_feature_variant_descriptions.variant", array('filter_id', 'range_id'), CART_LANGUAGE, $join . $sliders_join, $feature_ids, CART_LANGUAGE, $where . $sliders_where . $filter_company_condition, $filter_vq);
        } else {
            $variants_counts = array();
        }
        $ranges_counts = db_get_hash_multi_array("SELECT " . implode(', ', $ranges_fields) . " FROM ?:product_filter_ranges LEFT JOIN ?:product_features_values ON ?:product_features_values.feature_id = ?:product_filter_ranges.feature_id AND ?:product_features_values.value_int >= ?:product_filter_ranges.from AND ?:product_features_values.value_int <= ?:product_filter_ranges.to LEFT JOIN ?:products ON ?:products.product_id = ?:product_features_values.product_id LEFT JOIN ?:product_filter_ranges_descriptions ON ?:product_filter_ranges_descriptions.range_id = ?:product_filter_ranges.range_id AND ?:product_filter_ranges_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filter_ranges.feature_id ?p WHERE ?:product_features_values.feature_id IN (?n) AND ?:product_features_values.lang_code = ?s ?p ?p GROUP BY ?:product_filter_ranges.range_id ORDER BY ?:product_filter_ranges.position, ?:product_filter_ranges_descriptions.range_name", array('filter_id', 'range_id'), CART_LANGUAGE, $join . $sliders_join, $feature_ids, CART_LANGUAGE, $where . $sliders_where, $filter_rq);
        $merged = fn_array_merge($variants_counts, $ranges_counts, $field_ranges_counts);
        $view_all = array();
        if (empty($merged) && empty($params['skip_other_variants']) && (!empty($av_ids) || !empty($ranges_ids) || !empty($_field_ranges_ids))) {
            fn_set_notification('W', __('text_nothing_found'), __('text_nothing_found_filter_message'));
            if (defined('AJAX_REQUEST')) {
                exit;
            } elseif (!empty($_SERVER['HTTP_REFERER'])) {
                fn_redirect($_SERVER['HTTP_REFERER']);
            } else {
                $_params = $params;
                $_params['skip_advanced_variants'] = true;
                $_params['only_selected'] = true;
                list($_f, $_view_all) = fn_get_filters_products_count($_params);
                foreach ($_f as $filter_id => $filter) {
                    if (!empty($field_range_values[$filter_id])) {
                        $_f[$filter_id]['range_values'] = $field_range_values[$filter_id];
                    }
                }
                return array($_f, $_view_all);
            }
        }
        foreach ($filters as $filter_id => $filter) {
            if (!empty($field_range_values[$filter_id]) || !empty($merged[$filter_id]) && empty($params['view_all']) || !empty($params['filter_id']) && $params['filter_id'] != $filter_id) {
                // Check if filter range was selected
                if (!empty($merged[$filter_id])) {
                    if (empty($filters[$filter_id]['feature_id'])) {
                        $intersect = array_intersect(array_keys($merged[$filter_id]), $field_ranges_ids);
                    } else {
                        $intersect = array_intersect(array_keys($merged[$filter_id]), $ranges_ids);
                    }
                }
                if (!empty($intersect)) {
                    foreach ($merged[$filter_id] as $k => $v) {
                        if (!in_array($v['range_id'], $intersect)) {
                            // Unset unselected ranges
                            unset($merged[$filter_id][$k]);
                        }
                    }
                }
                if (!empty($field_range_values[$filter_id])) {
                    $filters[$filter_id]['range_values'] = $field_range_values[$filter_id];
                }
                $filters[$filter_id]['ranges'] =& $merged[$filter_id];
                // Add feature type to the filter
                if (!empty($merged[$filter_id])) {
                    $_first = reset($merged[$filter_id]);
                    if (!empty($_first['feature_type'])) {
                        $filters[$filter_id]['feature_type'] = $_first['feature_type'];
                    }
                }
                if (!empty($params['simple_link']) && $filters[$filter_id]['feature_type'] == 'E') {
                    $filters[$filter_id]['simple_link'] = true;
                }
                if (empty($params['advanced_filter']) && empty($params['skip_other_variants']) && !empty($filters[$filter_id]['ranges'])) {
                    $selected = array();
                    $features_hash = !empty($params['features_hash']) ? $params['features_hash'] : '';
                    foreach ($filters[$filter_id]['ranges'] as $_k => $r) {
                        if (fn_check_selected_filter($r['range_id'], !empty($r['feature_type']) ? $r['feature_type'] : '', $params, $filters[$filter_id]['field_type'])) {
                            // selected variant
                            $selected[$_k] = $r;
                            $selected[$_k]['selected'] = true;
                            unset($filters[$filter_id]['ranges'][$_k]);
                            $features_hash = fn_delete_range_from_url($features_hash, $r, $filters[$filter_id]['field_type']);
                        }
                    }
                    if (!empty($selected)) {
                        $selected_range_ids = array_keys($selected);
                        // Get other variants
                        $_params = $params;
                        //$_params['filter_id'] = $filter_id;
                        $_params['features_hash'] = $features_hash;
                        $_params['skip_other_variants'] = true;
                        unset($_params['variant_id'], $_params['check_location']);
                        list($_f) = fn_get_filters_products_count($_params);
                        if (!empty($_f[$filter_id])) {
                            $_f = $_f[$filter_id];
                            if (!empty($_f['ranges'])) {
                                // delete current range
                                foreach ($_f['ranges'] as $_rid => $_rv) {
                                    if (in_array($_rid, $selected_range_ids)) {
                                        unset($_f['ranges'][$_rid]);
                                    }
                                }
                                $filters[$filter_id]['ranges'] = $_f['ranges'];
                                $filters[$filter_id]['more_cut'] = !empty($_f['more_cut']) ? $_f['more_cut'] : false;
                            }
                        }
                        $filters[$filter_id]['selected_ranges'] = $selected;
                    }
                    if (!empty($params['only_selected'])) {
                        //unset($filters[$filter_id]['ranges']);
                        foreach ($filters[$filter_id]['ranges'] as $k => $v) {
                            $filters[$filter_id]['ranges'][$k]['disabled'] = true;
                        }
                    } else {
                        $_params = $params;
                        $_params['filter_id'] = $filter_id;
                        $_params['features_hash'] = '';
                        $_params['get_custom'] = true;
                        $_params['skip_other_variants'] = true;
                        unset($_params['variant_id'], $_params['check_location']);
                        list($_f) = fn_get_filters_products_count($_params);
                        if (!empty($_f[$filter_id])) {
                            $_f = $_f[$filter_id];
                            if (!empty($_f['ranges'])) {
                                foreach ($_f['ranges'] as $_rid => $_rv) {
                                    if (!isset($filters[$filter_id]['ranges'][$_rid]) && !isset($filters[$filter_id]['selected_ranges'][$_rid])) {
                                        $filters[$filter_id]['ranges'][$_rid] = $_rv;
                                        $filters[$filter_id]['ranges'][$_rid]['disabled'] = true;
                                        if (fn_check_selected_filter($_rv['range_id'], !empty($_rv['feature_type']) ? $_rv['feature_type'] : '', $params, !empty($_f[$filter_id]) ? $_f[$filter_id]['field_type'] : $_f['field_type'])) {
                                            $filters[$filter_id]['ranges'][$_rid]['checked'] = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // Calculate number of ranges and compare with displaying count
                    if (empty($params['get_all'])) {
                        if (!empty($filters[$filter_id]['ranges'])) {
                            $count = count($filters[$filter_id]['ranges']);
                        } else {
                            $count = 1;
                        }
                        if ($count > $filters[$filter_id]['display_more_count']) {
                            $filters[$filter_id]['more_ranges'] = array_slice($filters[$filter_id]['ranges'], 0, $filters[$filter_id]['display_more_count'], true);
                            $count = $filters[$filter_id]['display_more_count'];
                            $filters[$filter_id]['more_cut'] = true;
                        } else {
                            $filters[$filter_id]['more_ranges'] = $filters[$filter_id]['ranges'];
                        }
                        $filters[$filter_id]['ranges'] = array_slice($filters[$filter_id]['more_ranges'], 0, $filters[$filter_id]['display_count'], true);
                        $filters[$filter_id]['more_ranges'] = array_slice($filters[$filter_id]['more_ranges'], $filters[$filter_id]['display_count'], $count, true);
                    }
                } else {
                    if (!empty($params['variant_id']) && !empty($filters[$filter_id]['ranges'][$params['variant_id']])) {
                        $filters[$filter_id]['ranges'][$params['variant_id']]['selected'] = true;
                        // mark selected variant
                    }
                }
                continue;
                // If its "view all" page, return all ranges
            } elseif (!empty($params['filter_id']) && $params['filter_id'] == $filter_id && !empty($merged[$filter_id])) {
                if (empty($params['return_view_all'])) {
                    $filters[$filter_id]['ranges'] =& $merged[$filter_id];
                    $selected = array();
                    $features_hash = !empty($params['features_hash']) ? $params['features_hash'] : '';
                    foreach ($filters[$filter_id]['ranges'] as $_k => $r) {
                        if (fn_check_selected_filter($r['range_id'], !empty($r['feature_type']) ? $r['feature_type'] : '', $params, $filters[$filter_id]['field_type'])) {
                            $selected[$_k] = $r;
                            $selected[$_k]['selected'] = true;
                            unset($filters[$filter_id]['ranges'][$_k]);
                            $features_hash = fn_delete_range_from_url($features_hash, $r, $filters[$filter_id]['field_type']);
                            continue;
                        }
                    }
                    if (!empty($selected)) {
                        $selected_range_ids = array_keys($selected);
                        // Get other variants
                        $_params = $params;
                        $_params['filter_id'] = $filter_id;
                        $_params['features_hash'] = $features_hash;
                        $_params['skip_other_variants'] = true;
                        $_params['return_view_all'] = true;
                        unset($_params['variant_id'], $_params['check_location']);
                        list($_f, $view_all) = fn_get_filters_products_count($_params);
                    }
                }
                if (empty($view_all)) {
                    foreach ($merged[$filter_id] as $range) {
                        if (!empty($range['index']) || strlen($range['index']) > 0) {
                            // feature
                            $view_all[$range['index']][] = $range;
                        } else {
                            // custom range
                            $view_all[$filters[$range['filter_id']]['filter']][] = $range;
                        }
                    }
                    ksort($view_all);
                }
            }
            // Unset filter if it's empty
            unset($filters[$filter_id]);
        }
        if (!empty($params['advanced_filter'])) {
            $_params = array('feature_types' => array('C', 'T'), 'plain' => true, 'category_ids' => array(empty($params['category_id']) ? 0 : $params['category_id']));
            list($features) = fn_get_product_features($_params);
            if (!empty($features)) {
                $filters = array_merge($filters, $features);
            }
        }
        /**
         * Change product filters data
         *
         * @param array $filters  Product filters data
         * @param array $view_all All ranges filters
         * @param array $params Products filter search params
         */
        fn_set_hook('get_filters_products_count_before_select', $filters, $view_all, $params);
        Registry::set($key, array($filters, $view_all));
    } else {
        list($filters, $view_all) = Registry::get($key);
    }
    return array($filters, $view_all);
}
Ejemplo n.º 19
0
function fn_order_placement_routines($action = '', $order_id = 0, $force_notification = array(), $clear_cart = true, $area = AREA)
{
    if (Embedded::isLeft() && !Embedded::isEnabled()) {
        Embedded::enable();
    }
    if ($action == 'checkout_redirect') {
        if ($area == 'A') {
            fn_redirect("order_management.edit?order_id=" . reset($_SESSION['cart']['processed_order_id']));
        } else {
            fn_redirect('checkout.checkout');
        }
    } elseif (in_array($action, array('save', 'repay', 'route')) && !empty($order_id)) {
        $order_info = fn_get_order_info($order_id, true);
        $display_notification = true;
        fn_set_hook('placement_routines', $order_id, $order_info, $force_notification, $clear_cart, $action, $display_notification);
        if (!empty($_SESSION['cart']['placement_action'])) {
            if (empty($action)) {
                $action = $_SESSION['cart']['placement_action'];
            }
            unset($_SESSION['cart']['placement_action']);
        }
        if ($area == 'C' && !empty($order_info['user_id'])) {
            $__fake = '';
            fn_save_cart_content($__fake, $order_info['user_id']);
        }
        $edp_data = fn_generate_ekeys_for_edp(array(), $order_info);
        fn_order_notification($order_info, $edp_data, $force_notification);
        $_error = false;
        if ($action == 'save') {
            if ($display_notification) {
                fn_set_notification('N', __('congratulations'), __('text_order_saved_successfully'));
            }
        } else {
            if ($order_info['status'] == STATUS_PARENT_ORDER) {
                $child_orders = db_get_hash_single_array("SELECT order_id, status FROM ?:orders WHERE parent_order_id = ?i", array('order_id', 'status'), $order_id);
                $status = reset($child_orders);
                $child_orders = array_keys($child_orders);
            } else {
                $status = $order_info['status'];
            }
            if (in_array($status, fn_get_order_paid_statuses())) {
                if ($action == 'repay') {
                    fn_set_notification('N', __('congratulations'), __('text_order_repayed_successfully'));
                } else {
                    fn_set_notification('N', __('order_placed'), __('text_order_placed_successfully'));
                }
            } elseif ($status == STATUS_BACKORDERED_ORDER) {
                fn_set_notification('W', __('important'), __('text_order_backordered'));
            } else {
                if ($area == 'A' || $action == 'repay') {
                    if ($status != STATUS_CANCELED_ORDER) {
                        $_payment_info = db_get_field("SELECT data FROM ?:order_data WHERE order_id = ?i AND type = 'P'", $order_id);
                        if (!empty($_payment_info)) {
                            $_payment_info = unserialize(fn_decrypt_text($_payment_info));
                            $_msg = !empty($_payment_info['reason_text']) ? $_payment_info['reason_text'] : '';
                            $_msg .= empty($_msg) ? __('text_order_placed_error') : '';
                            fn_set_notification('E', '', $_msg);
                        }
                    }
                } else {
                    $_error = true;
                    if (!empty($child_orders)) {
                        array_unshift($child_orders, $order_id);
                    } else {
                        $child_orders = array();
                        $child_orders[] = $order_id;
                    }
                    $_SESSION['cart'][$status == STATUS_INCOMPLETED_ORDER ? 'processed_order_id' : 'failed_order_id'] = $child_orders;
                }
                if ($status == STATUS_INCOMPLETED_ORDER || $action == 'repay' && $status == STATUS_CANCELED_ORDER) {
                    fn_set_notification('W', __('important'), __('text_transaction_cancelled'));
                }
            }
        }
        // Empty cart
        if ($clear_cart == true && $_error == false) {
            $_SESSION['cart'] = array('user_data' => !empty($_SESSION['cart']['user_data']) ? $_SESSION['cart']['user_data'] : array(), 'profile_id' => !empty($_SESSION['cart']['profile_id']) ? $_SESSION['cart']['profile_id'] : 0, 'user_id' => !empty($_SESSION['cart']['user_id']) ? $_SESSION['cart']['user_id'] : 0);
            $_SESSION['shipping_rates'] = array();
            unset($_SESSION['shipping_hash']);
            db_query('DELETE FROM ?:user_session_products WHERE session_id = ?s AND type = ?s', Session::getId(), 'C');
        }
        fn_set_hook('order_placement_routines', $order_id, $force_notification, $order_info, $_error);
        if ($area == 'A') {
            fn_redirect("orders.details?order_id={$order_id}");
        } else {
            fn_redirect('checkout.' . ($_error ? 'checkout' : "complete?order_id={$order_id}"));
        }
    } elseif ($action == 'index_redirect') {
        fn_redirect(fn_url('', 'C', 'http'));
    } else {
        fn_redirect(fn_url($action, 'C', 'http'));
    }
}
Ejemplo n.º 20
0
 protected function generateOffers($file)
 {
     $fields = array('p.product_id', 'p.product_code', 'd.lang_code', 'pc.category_id', 'cd.category', 'pp.price', 'p.list_price', 'p.status', 'p.amount', 'p.weight', 'p.shipping_freight', 'p.shipping_params', 'p.free_shipping', 'd.product', 'd.short_description', 'd.full_description', 'p.company_id', 'p.bean_bag_quantity_150', 'p.bean_bag_quantity_300', 'p.tracking', 'p.list_price', 'p.yml2_brand', 'p.yml2_origin_country', 'p.yml2_store', 'p.yml2_pickup', 'p.yml2_delivery', 'p.yml2_delivery_options', 'p.yml2_bid', 'p.yml2_cbid', 'p.yml2_model', 'p.yml2_sales_notes', 'p.yml2_type_prefix', 'p.yml2_offer_type', 'p.yml2_market_category', 'p.yml2_manufacturer_warranty', 'p.yml2_seller_warranty', 'p.yml2_purchase_price');
     $fields[] = "(\n                SELECT GROUP_CONCAT(IF(pc2.link_type = 'M', CONCAT(pc2.category_id, 'M'), pc2.category_id))\n                FROM ?:products_categories as pc2\n                WHERE product_id = p.product_id\n            ) as category_ids";
     $joins = array(db_quote("LEFT JOIN ?:product_descriptions as d ON d.product_id = p.product_id AND d.lang_code = ?s", $this->lang_code), db_quote("LEFT JOIN ?:product_prices as pp" . " ON pp.product_id = p.product_id AND pp.lower_limit = 1 AND pp.usergroup_id = 0"), db_quote("LEFT JOIN ?:products_categories as pc ON pc.product_id = p.product_id AND pc.link_type = ?s", 'M'), db_quote("LEFT JOIN ?:category_descriptions as cd ON cd.category_id = pc.category_id AND cd.lang_code = ?s", $this->lang_code));
     $condition = '';
     if ($this->company_id > 0) {
         $condition .= db_quote(' AND company_id = ?i', $this->company_id);
     }
     $exclude_products_ids = array();
     if (!empty($this->options['exclude_categories_not_logging']) && $this->options['exclude_categories_not_logging'] == 'Y' && !empty($this->exclude_category_ids)) {
         $exclude_products_ids = db_get_fields("SELECT DISTINCT product_id FROM ?:products_categories WHERE category_id IN (?a)", $this->exclude_category_ids);
     }
     $products_ids = db_get_fields("SELECT DISTINCT object_id FROM ?:yml_exclude_objects WHERE price_id = ?i AND object_type = 'product'", $this->price_id);
     $exclude_products_ids = array_merge($exclude_products_ids, $products_ids);
     if (!empty($exclude_products_ids)) {
         $condition .= db_quote(' AND product_id NOT IN (?a)', $exclude_products_ids);
     }
     $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE status = ?s {$condition}", 'A');
     fn_set_storage_data('yml2_export_count_' . $this->price_id, count($product_ids));
     $shared_product_ids = array();
     if (isset($this->options['export_shared_products']) && $this->options['export_shared_products'] == 'Y') {
         $categories_join = db_quote('INNER JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id');
         $products_join = db_quote('INNER JOIN ?:products ON ?:products.product_id = ?:products_categories.product_id');
         $shared_product_ids = db_get_fields("SELECT DISTINCT ?:products_categories.product_id FROM ?:products_categories {$categories_join} {$products_join} " . "WHERE ?:categories.company_id = ?i AND link_type = 'A' AND ?:products.status = 'A' ", $this->company_id);
         $product_ids = array_merge($product_ids, $shared_product_ids);
     }
     $this->offer = new Offers($this->options, $this->log);
     $offers_count = 0;
     while ($ids = array_slice($product_ids, $this->offset, self::ITERATION_ITEMS)) {
         $this->offset += self::ITERATION_ITEMS;
         $products = db_get_array('SELECT ' . implode(', ', $fields) . ' FROM ?:products as p' . ' ' . implode(' ', $joins) . ' WHERE p.product_id IN(?n)' . ' GROUP BY p.product_id', $ids);
         $products_images_main = fn_get_image_pairs($ids, 'product', 'M', false, true, $this->lang_code);
         $products_images_additional = fn_get_image_pairs($ids, 'product', 'A', false, true, $this->lang_code);
         $params = array('get_options' => true, 'get_taxed_prices' => false, 'detailed_params' => false);
         fn_gather_additional_products_data($products, $params);
         foreach ($products as $k => &$product) {
             if (in_array($product['product_id'], $shared_product_ids)) {
                 $this->prepareSharedProduct($product);
             }
             $product['product_features'] = $this->getProductFeatures($product);
             if (!$this->preBuild($product, $products_images_main, $products_images_additional)) {
                 $this->yml2_product_skip++;
                 continue;
             }
             list($xml, $product_skip) = $this->offer->build($product);
             $this->yml2_product_skip += $product_skip;
             $this->stopGeneration();
             fwrite($file, $xml . "\n");
             $this->yml2_product_export++;
         }
         $offers_count += count($products);
         fn_set_storage_data('yml2_export_offset_' . $this->price_id, $this->offset);
         if (!defined('CONSOLE') && $offers_count >= self::ITERATION_OFFERS) {
             fn_set_storage_data('yml2_product_export_' . $this->price_id, $this->yml2_product_export);
             fn_set_storage_data('yml2_product_skip_' . $this->price_id, $this->yml2_product_skip);
             fclose($file);
             fn_set_storage_data('yml2_status_generate_' . $this->price_id, 'redirect');
             fn_redirect(fn_yml_get_generate_link($this->price_list) . "/" . $this->offset);
         }
     }
     return true;
 }
Ejemplo n.º 21
0
 /**
  * Processes view actions
  *
  * @param  string  $object object to init view for
  * @param  array   $params request parameters
  * @return boolean Always true
  */
 protected function _checkUpdateActions($object, $params)
 {
     // Save view
     if ($this->_action == 'save_view' && !empty($params['new_view'])) {
         $name = $params['new_view'];
         $update_view_id = empty($params['update_view_id']) ? 0 : $params['update_view_id'];
         unset($params['dispatch'], $params['page'], $params['new_view'], $params['update_view_id']);
         $data = array('object' => $object, 'name' => $name, 'params' => serialize($params), 'user_id' => $this->_auth['user_id']);
         if ($update_view_id) {
             db_query("UPDATE ?:views SET ?u WHERE view_id = ?i", $data, $update_view_id);
             $params['view_id'] = $update_view_id;
         } else {
             $params['view_id'] = db_query("REPLACE INTO ?:views ?e", $data);
         }
         fn_redirect(Registry::get('runtime.controller') . '.' . Registry::get('runtime.mode') . '?' . http_build_query($params));
     } elseif ($this->_action == 'delete_view' && !empty($params['view_id'])) {
         db_query("DELETE FROM ?:views WHERE view_id = ?i", $params['view_id']);
     } elseif ($this->_action == 'reset_view') {
         db_query("UPDATE ?:views SET active = 'N' WHERE user_id = ?i AND object = ?s", $this->_auth['user_id'], $object);
     }
     return true;
 }
Ejemplo n.º 22
0
/**
 * 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
}
Ejemplo n.º 23
0
function fn_searchanise_get_filters_products_count($params)
{
    if (AREA == 'A' || fn_se_check_disabled() || !empty($params['disable_searchanise']) || empty($params['q']) && fn_se_get_simple_setting('use_navigation') !== 'Y' || fn_se_get_import_status(fn_se_get_company_id(), CART_LANGUAGE) != 'done' || Registry::ifGet('addons.age_verification.status', 'D') == 'A' || Registry::ifGet('addons.vendor_data_premoderation.status', 'D') == 'A') {
        return fn_get_filters_products_count($params);
    }
    $key = 'pfilters_se_' . md5(serialize($params));
    Registry::registerCache($key, array('products', 'product_features', 'product_filters', 'product_features_values', 'categories'), Registry::cacheLevel('user'));
    // Check exist cache.
    if (Registry::isExist($key) == true) {
        list($filters, $view_all) = Registry::get($key);
    } else {
        if (!fn_se_check_product_filter_block()) {
            return array();
        }
        if (!empty($params['check_location'])) {
            // FIXME: this is bad style, should be refactored
            $valid_locations = array('index.index', 'products.search', 'categories.view', 'product_features.view');
            if (!in_array($params['dispatch'], $valid_locations)) {
                return array();
            }
            if ($params['dispatch'] == 'categories.view') {
                $params['simple_link'] = true;
                // this parameter means that extended filters on this page should be displayed as simple
                $params['filter_custom_advanced'] = true;
                // this parameter means that extended filtering should be stayed on the same page
            } else {
                if ($params['dispatch'] == 'product_features.view') {
                    $params['simple_link'] = true;
                    $params['features_hash'] = (!empty($params['features_hash']) ? $params['features_hash'] . '.' : '') . 'V' . $params['variant_id'];
                    //$params['exclude_feature_id'] = db_get_field("SELECT feature_id FROM ?:product_features_values WHERE variant_id = ?i", $params['variant_id']);
                }
                $params['get_for_home'] = 'Y';
            }
        }
        // hide filters block on the advanced search page
        if (!empty($params['skip_if_advanced']) && !empty($params['advanced_filter']) && $params['advanced_filter'] == 'Y') {
            return array();
        }
        // End copied code.
        $get_custom = !empty($params['get_custom']);
        $received_facets = Registry::get('searchanise.received_facets');
        $r_filters = $view_all = $variants_ids = $feature_variants = $fields_ids = $slider_vals = $category_facets = array();
        $params['filters_category_id'] = empty($params['category_id']) ? 0 : $params['category_id'];
        if (is_null($received_facets) || $get_custom) {
            list($restrict_by, $query_by, $union) = fn_se_prepare_request_params($params);
            $request_params = array('items' => 'false', 'facets' => 'true', 'union' => $union, 'queryBy' => $query_by, 'restrictBy' => $restrict_by);
            $result = fn_searchanise_send_search_request($request_params);
            if (empty($result)) {
                return fn_get_filters_products_count($params);
            }
            $received_facets = $result['facets'];
        }
        if (empty($received_facets)) {
            // Nothing found
            return array();
        }
        if (!empty($params['features_hash'])) {
            list(, , $fields_ids, $slider_vals) = fn_parse_features_hash($params['features_hash']);
            //
            // Get without
            //
            list($restrict_by, $query_by, $union) = fn_se_prepare_request_params(array_merge($params, array('features_hash' => '')));
            $request_params = array('items' => 'false', 'facets' => 'true', 'union' => $union, 'queryBy' => $query_by, 'restrictBy' => $restrict_by);
            $result = fn_searchanise_send_search_request($request_params);
            if (empty($result)) {
                return fn_get_filters_products_count($params);
            } else {
                $category_facets = $result['facets'];
            }
        }
        $params_for_filters = array('get_variants' => true);
        if (!empty($params['item_ids'])) {
            $params_for_filters['filter_id'] = $params['item_ids'];
        }
        $params_for_filters = array_merge($params_for_filters, $params);
        list($filters, ) = fn_get_product_filters($params_for_filters);
        if (empty($filters)) {
            return array(array(), false);
        }
        $fields = fn_get_product_filter_fields();
        foreach ($filters as $filter_id => $filter) {
            $r_facet = $c_facet = array();
            foreach ($received_facets as $r) {
                $r_feature_id = str_replace('feature_', '', $r['attribute']);
                if (!empty($filter['feature_id']) && $r_feature_id == $filter['feature_id'] || !empty($filter['field_type']) && !empty($fields[$filter['field_type']]['db_field']) && $fields[$filter['field_type']]['db_field'] == $r_feature_id) {
                    $r_facet = $r;
                    break;
                }
            }
            if (empty($r_facet) && $get_custom == false) {
                unset($filters[$filter_id]);
                continue;
            }
            foreach ($category_facets as $c) {
                if ($c['attribute'] == $r_facet['attribute']) {
                    $c_facet = $c;
                    break;
                }
            }
            if ($filter['field_type'] == 'F') {
                $filters[$filter_id]['ranges'] = $filter['ranges'] = array('N' => array('range_id' => 0, 'range_name' => __('no'), 'products' => 0), 'Y' => array('range_id' => 1, 'range_name' => __('yes'), 'products' => 0));
            } elseif ($filter['field_type'] == 'S' && (count($r_facet['buckets']) == 1 && $r_facet['buckets'][0]['value'] == 0) == false) {
                //skip if only default vendor (id=0) range passed
                $_companies = array();
                $companies = db_get_hash_single_array("SELECT ?:companies.company_id, ?:companies.company FROM ?:companies  WHERE status = 'A' ORDER BY ?:companies.company", array('company_id', 'company'));
                foreach ($companies as $company_id => $company) {
                    $_companies[$company_id] = array('range_id' => $company_id, 'range_name' => $company, 'products' => 0);
                }
                $filters[$filter_id]['ranges'] = $filter['ranges'] = $_companies;
            }
            $ranges_count = 0;
            $tmp_ranges = array('selected' => array(), 'used' => array(), 'disabled' => array());
            $filter['ranges'] = isset($filter['ranges']) ? $filter['ranges'] : array();
            //
            // Speed up for many variants!
            //
            if (!empty($filter['feature_id']) && !in_array($filter['feature_type'], array('D', 'N', 'O'))) {
                $rr_ranges = array();
                foreach ($r_facet['buckets'] as $r) {
                    $rr_ranges[$r['value']] = $r;
                }
                $cc_ranges = array();
                if (!empty($c_facet)) {
                    foreach ($c_facet['buckets'] as $cc) {
                        $cc_ranges[$cc['value']] = $cc;
                    }
                }
            }
            foreach ($filter['ranges'] as $s_range_id => $s_range) {
                $r_range = array();
                if (!empty($filter['feature_id']) && !in_array($filter['feature_type'], array('D', 'N', 'O'))) {
                    // features with variants
                    $r_range = isset($rr_ranges[$s_range['variant_id']]) ? $rr_ranges[$s_range['variant_id']] : array();
                } elseif ($filter['field_type'] == 'F') {
                    // Free shipping
                    foreach ($r_facet['buckets'] as $r) {
                        if ($r['value'] == $s_range_id) {
                            $r_range = $r;
                            break;
                        }
                    }
                } elseif ($filter['field_type'] == 'S') {
                    // Vendors
                    foreach ($r_facet['buckets'] as $r) {
                        if ($r['value'] == $s_range_id) {
                            unset($r['selected']);
                            foreach ($fields_ids as $fr_id => $ff_type) {
                                if ($ff_type == 'S' && $fr_id == $r['value']) {
                                    $r['selected'] = true;
                                }
                            }
                            $r_range = $r;
                            break;
                        }
                    }
                } else {
                    // range
                    foreach ($r_facet['buckets'] as $r) {
                        if (abs($r['from'] - $s_range['from']) < 0.01 && abs($r['to'] - $s_range['to']) < 0.01) {
                            $r_range = $r;
                            break;
                        }
                    }
                }
                $range_id = isset($s_range['variant_id']) ? $s_range['variant_id'] : $s_range['range_id'];
                $new_range = array('feature_id' => $filter['feature_id'], 'range_id' => $range_id, 'range_name' => isset($s_range['variant']) ? $s_range['variant'] : $s_range['range_name'], 'feature_type' => $filter['feature_type'], 'filter_id' => $filter_id);
                if (!empty($r_range)) {
                    $new_range['products'] = $r_range['count'];
                }
                if (empty($r_range['selected']) && fn_check_selected_filter($new_range['range_id'], !empty($new_range['feature_type']) ? $new_range['feature_type'] : '', $params, $filter['field_type'])) {
                    $new_range['checked'] = true;
                }
                if (!empty($r_range['selected'])) {
                    $is_select_found = true;
                    $new_range['selected'] = true;
                    $tmp_ranges['selected'][$range_id] = $new_range;
                } elseif (!empty($r_range)) {
                    $tmp_ranges['used'][$range_id] = $new_range;
                } elseif (!empty($c_facet['buckets'])) {
                    $c_range = false;
                    if (!empty($filter['feature_id']) && !in_array($filter['feature_type'], array('D', 'N', 'O'))) {
                        // features with variants
                        $c_range = isset($cc_ranges[$s_range['variant_id']]) ? $cc_ranges[$s_range['variant_id']] : array();
                    } elseif ($filter['field_type'] == 'F') {
                        // Free shipping
                        foreach ($c_facet['buckets'] as $c) {
                            if ($c['value'] == $s_range_id) {
                                $c_range = $c;
                                break;
                            }
                        }
                    } elseif ($filter['field_type'] == 'S') {
                        // Suppliers
                        foreach ($c_facet['buckets'] as $c) {
                            if ($c['value'] == $s_range_id) {
                                $c_range = $c;
                                break;
                            }
                        }
                    } else {
                        // range
                        foreach ($c_facet['buckets'] as $c) {
                            if (abs($c['from'] - $s_range['from']) < 0.01 && abs($c['to'] - $s_range['to']) < 0.01) {
                                $c_range = $c;
                                break;
                            }
                        }
                    }
                    if (!empty($c_range)) {
                        $new_range['disabled'] = true;
                        $tmp_ranges['disabled'][$range_id] = $new_range;
                    }
                }
                $ranges_count++;
            }
            // \ by store filter ranges
            if (!empty($filters[$filter_id]['slider'])) {
                $is_select_found = true;
                $r_range = $r_facet['buckets'][0];
                $r = array('min' => $r_range['from'], 'max' => $r_range['to']);
                $field_type = $filters[$filter_id]['field_type'];
                if ($field_type == 'P' && CART_SECONDARY_CURRENCY != CART_PRIMARY_CURRENCY) {
                    $coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient');
                    $r['min'] = floatval($r['min']) / floatval($coef);
                    $r['max'] = floatval($r['max']) / floatval($coef);
                }
                $r['min'] = floor($r['min'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to'];
                $r['max'] = ceil($r['max'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to'];
                if ($r['max'] - $r['min'] <= $filters[$filter_id]['round_to']) {
                    $r['max'] = $r['min'] + $filters[$filter_id]['round_to'];
                }
                if (!empty($slider_vals[$field_type])) {
                    if ($field_type == 'P' && $slider_vals['P'][2] != CART_SECONDARY_CURRENCY) {
                        $prev_coef = Registry::get('currencies.' . $slider_vals['P'][2] . '.coefficient');
                        $cur_coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient');
                        $slider_vals['P'][0] = floor(floatval($slider_vals['P'][0]) * floatval($prev_coef) / floatval($cur_coef));
                        $slider_vals['P'][1] = ceil(floatval($slider_vals['P'][1]) * floatval($prev_coef) / floatval($cur_coef));
                    }
                    $r['left'] = $slider_vals[$field_type][0];
                    $r['right'] = $slider_vals[$field_type][1];
                    if ($r['left'] < $r['min']) {
                        $r['left'] = $r['min'];
                    }
                    if ($r['left'] > $r['max']) {
                        $r['left'] = $r['max'];
                    }
                    if ($r['right'] > $r['max']) {
                        $r['right'] = $r['max'];
                    }
                    if ($r['right'] < $r['min']) {
                        $r['right'] = $r['min'];
                    }
                    if ($r['right'] < $r['left']) {
                        $tmp = $r['right'];
                        $r['right'] = $r['left'];
                        $r['left'] = $tmp;
                    }
                    $r['left'] = floor($r['left'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to'];
                    $r['right'] = ceil($r['right'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to'];
                }
                $filters[$filter_id]['range_values'] = $r;
            } else {
                if (empty($tmp_ranges)) {
                    unset($filters[$filter_id]);
                } else {
                    if (!empty($tmp_ranges['selected'])) {
                        $filters[$filter_id]['selected_ranges'] = $tmp_ranges['selected'];
                    }
                    $filters[$filter_id]['ranges'] = $tmp_ranges['used'] + $tmp_ranges['disabled'];
                    // Calculate number of ranges and compare with displaying count
                    if (empty($params['get_all'])) {
                        if (!empty($filters[$filter_id]['ranges'])) {
                            $count = count($filters[$filter_id]['ranges']);
                        } else {
                            $count = 1;
                        }
                        if ($count > $filters[$filter_id]['display_more_count']) {
                            $filters[$filter_id]['more_ranges'] = array_slice($filters[$filter_id]['ranges'], 0, $filters[$filter_id]['display_more_count'], true);
                            $count = $filters[$filter_id]['display_more_count'];
                            $filters[$filter_id]['more_cut'] = true;
                        } else {
                            $filters[$filter_id]['more_ranges'] = $filters[$filter_id]['ranges'];
                        }
                        $filters[$filter_id]['ranges'] = array_slice($filters[$filter_id]['more_ranges'], 0, $filters[$filter_id]['display_count'], true);
                        $filters[$filter_id]['more_ranges'] = array_slice($filters[$filter_id]['more_ranges'], $filters[$filter_id]['display_count'], $count, true);
                    }
                    if (!empty($params['simple_link']) && $filters[$filter_id]['feature_type'] == 'E') {
                        $filters[$filter_id]['simple_link'] = true;
                    }
                }
            }
        }
        if (empty($is_select_found) && empty($params['skip_other_variants']) && !empty($params['features_hash'])) {
            fn_set_notification('W', __('text_nothing_found'), __('text_nothing_found_filter_message'));
            if (defined('AJAX_REQUEST')) {
                die;
            } elseif (!empty($_SERVER['HTTP_REFERER'])) {
                fn_redirect($_SERVER['HTTP_REFERER'], true);
            } else {
                $_params = $params;
                $_params['skip_advanced_variants'] = true;
                $_params['only_selected'] = true;
                if (!empty($params['features_hash']) && empty($params['skip_advanced_variants'])) {
                    list(, , , , $field_ranges_ids) = fn_parse_features_hash($params['features_hash']);
                }
                list($_f, $_view_all) = fn_get_filters_products_count($_params);
                foreach ($_f as $filter_id => $filter) {
                    if (!empty($field_range_values[$filter_id])) {
                        $_f[$filter_id]['range_values'] = $field_range_values[$filter_id];
                    }
                }
                return array($_f, $_view_all);
            }
        }
        // Adding to the cache.
        Registry::set($key, array($filters, $view_all));
    }
    return array($filters, $view_all);
}
Ejemplo n.º 24
0
function fn_social_buttons_before_dispatch()
{
    //For the stores works as widget. We need to redirect the customer to thee site where the Like button was clicked.
    if (isset($_REQUEST['_escaped_fragment_'])) {
        fn_redirect($_REQUEST['_escaped_fragment_'], true, true);
    }
}
Ejemplo n.º 25
0
            $category = fn_twg_get_api_category_data($_REQUEST['id'], $lang_code);
            if (empty($category)) {
                $response->addError('ERROR_OBJECT_WAS_NOT_FOUND', str_replace('[object]', $object, __('twgadmin_object_was_not_found')));
                $response->returnResponse();
            }
            $response->setData($category);
            $response->returnResponse('category');
        } else {
            // get object data by scheme where id is a primary
            // key in database and scheme
            fn_twg_api_get_object($response, $object, $_REQUEST);
        }
    }
    if ($_REQUEST['action'] == 'edit_css') {
        $_SESSION['current_path'] = '/' . TwigmoSettings::get('base_theme') . '/templates/addons/twigmo/';
        fn_redirect(Registry::get('config.admin_index') . '?dispatch=template_editor.manage', true);
    }
}
function fn_api_get_orders_search_params($lang_code = CART_LANGUAGE)
{
    if (!empty($_REQUEST['shipping_name'])) {
        $shipping_ids = db_get_fields("SELECT shipping_id\n             FROM ?:shipping_descriptions\n             WHERE shipping LIKE ?l AND lang_code = ?s", "%{$_REQUEST['shipping_name']}%", $lang_code);
        if (empty($shipping_ids)) {
            return false;
        }
        $_REQUEST['shippings'] = $shipping_ids;
    }
    $condition = '';
    $tables = array();
    if (!empty($_REQUEST['sname'])) {
        // search in products
Ejemplo n.º 26
-1
function fn_twigmo_before_dispatch()
{
    if ($_SERVER['REQUEST_METHOD'] == 'POST' || AREA != 'C' || !fn_twg_is_updated() || !TwigmoConnector::frontendIsConnected() || empty($_SERVER['HTTP_USER_AGENT']) || defined('AJAX_REQUEST') || $_REQUEST['dispatch'] == 'image.captcha') {
        return;
    }
    if (!isset($_SESSION['twg_state'])) {
        $_SESSION['twg_state'] = array();
    }
    $state = $_SESSION['twg_state'] = fn_twg_get_frontend_state($_REQUEST, $_SESSION['twg_state'], TwigmoSettings::get());
    if (!$state['twg_is_used']) {
        return;
    }
    if (fn_twg_use_https_for_customer() && !defined('HTTPS')) {
        fn_redirect(Registry::get('config.https_location') . '/' . Registry::get('config.current_url'));
    }
    $local_jsurl = Registry::get('config.twg.jsurl');
    $template = $local_jsurl ? 'mobile_index_dev.tpl' : 'mobile_index.tpl';
    Registry::set('runtime.root_template', 'addons/twigmo/' . $template);
    Registry::set('runtime.inside_scripts', 1);
    $view = fn_twg_get_view_object();
    $view->assign('urls', TwigmoConnector::getMobileScriptsUrls($local_jsurl));
    $view->assign('repo_revision', TwigmoSettings::get('repo_revision'));
    $view->assign('twg_state', $state);
    fn_twg_assign_google_template();
    if ($state['theme_editor_mode']) {
        header("X-Frame-Options: ");
    }
}
Ejemplo n.º 27
-1
    }
} elseif (empty($processor_data)) {
    if ($_REQUEST['txnRef']) {
        DEFINE('AREA', 'C');
        DEFINE('AREA_NAME', 'customer');
        require './../prepare.php';
        require './../init.php';
        $order_id = strpos($_REQUEST['txnRef'], '_') ? substr($_REQUEST['txnRef'], 0, strpos($_REQUEST['txnRef'], '_')) : $_REQUEST['txnRef'];
        $pp_response = array();
        $pp_response['order_status'] = $_REQUEST['status'] == 'succ' ? 'P' : 'F';
        $pp_response['reason_text'] = fn_get_lang_var('order_id') . '-' . $order_id;
        $pp_response['transaction_id'] = '';
        if (fn_check_payment_script('enets.php', $order_id)) {
            fn_finish_payment($order_id, $pp_response, false);
        }
        fn_redirect(Registry::get('config.http_location') . "/{$index_script}?dispatch=payment_notification.notify&payment=enets&order_id={$order_id}");
        exit;
    }
} else {
    if (!defined('AREA')) {
        die('Access denied');
    }
    $post_address = 'https://www.enets.sg/enets2/enps.do';
    $_order_id = $order_info['repaid'] ? $order_id . '_' . $order_info['repaid'] : $order_id;
    echo <<<EOT
<html>
<body onLoad="javascript: document.process.submit();">
<form method="post" action="{$post_address}" name="process">
\t<input type="hidden" name="txnRef" value="{$_order_id}">
\t<input type="hidden" name="mid" value="{$processor_data['params']['merchantid']}">
\t<input type="hidden" name="amount" value="{$order_info['total']}">
Ejemplo n.º 28
-1
/**
 * Init company
 *
 * @param array $params request parameters
 * @return boolean always true
 */
function fn_init_company($params)
{
    if (PRODUCT_TYPE == 'MULTIVENDOR' && AREA == 'A' && !empty($_SESSION['auth']['company_id'])) {
        fn_define('COMPANY_AREA', true);
        fn_define('COMPANY_ID', $_SESSION['auth']['company_id']);
        $companies = db_get_hash_array("SELECT ?:companies.* FROM ?:companies WHERE company_id = ?i AND status = 'A'", 'company_id', COMPANY_ID);
        if (empty($companies)) {
            // TODO: Log company failed initialization
            //fn_log_event('users', 'failed_login', array (
            //	'user' => $user_login
            //));
            $_SESSION['auth'] = array();
            fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('access_denied'));
            $suffix = (strpos($_SERVER['HTTP_REFERER'], '?') !== false ? '&' : '?') . 'login_type=login' . (!empty($_REQUEST['return_url']) ? '&return_url=' . urlencode($_REQUEST['return_url']) : '');
            fn_redirect("{$_SERVER['HTTP_REFERER']}{$suffix}");
        }
    } else {
        $_companies = db_get_hash_array("SELECT ?:companies.* FROM ?:companies ORDER BY company", 'company_id');
        $companies = array();
        if (PRODUCT_TYPE == 'MULTIVENDOR') {
            $companies['all'] = array('company_id' => 'all', 'company' => fn_get_lang_var('all_vendors'));
        }
        $companies['0'] = array('company_id' => '0', 'company' => Registry::get('settings.Company.company_name'));
        $companies = $companies + $_companies;
        if (PRODUCT_TYPE == 'MULTIVENDOR' && AREA == 'A') {
            // For administrative area, set selected company
            $_c = fn_get_cookie('company_id');
            if (isset($params['s_company']) && !empty($companies[$params['s_company']])) {
                if ($params['s_company'] != 'all') {
                    fn_define('COMPANY_ID', $params['s_company']);
                }
                fn_set_cookie('company_id', $params['s_company'], COOKIE_ALIVE_TIME);
            } elseif ($_c !== false && $_c != 'all' && !empty($companies[$_c])) {
                fn_define('COMPANY_ID', $_c);
            }
        }
    }
    Registry::set('s_companies', $companies);
    return true;
}
Ejemplo n.º 29
-1
        exit;
    } else {
        // Customer is redirected from the Pay&Read server
        DEFINE('AREA', 'C');
        DEFINE('AREA_NAME', 'customer');
        require './../prepare.php';
        require './../init.php';
        // Check if the settle data was recieved and order status was upsated otherwise transaction is failed
        $order_info = fn_get_order_info($_REQUEST['order_id']);
        if ($order_info['status'] == 'N' || $order_info['status'] == 'O') {
            $pp_response = array();
            $pp_response['order_status'] = 'F';
            $pp_response['reason_text'] = fn_get_lang_var('order_id') . '-' . $_REQUEST['order_id'];
            fn_finish_payment($_REQUEST['order_id'], $pp_response, false);
        }
        fn_redirect(Registry::get('config.current_location') . "/" . Registry::get('config.customer_index') . "?dispatch=payment_notification.notify&payment=pay_read&order_id={$_REQUEST['order_id']}");
        exit;
    }
} elseif (defined('PAYMENT_NOTIFICATION')) {
    if ($mode == 'notify') {
        fn_order_placement_routines($_REQUEST['order_id']);
    }
} else {
    // Prepare payment data and submit the form
    $post = "";
    $post[] = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
    $post[] = "<payread_post_api_0_2 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"payread_post_api_0_2.xsd\">";
    $post[] = "<seller_details>";
    $post[] = "<agent_id>" . $processor_data["params"]["agent_id"] . "</agent_id>";
    $post[] = "</seller_details>";
    // Buyer details
Ejemplo n.º 30
-1
            $redirect_url = fn_url();
        } elseif ($result === false) {
            $redirect_url = fn_url();
        } else {
            fn_delete_notification('notice_text_change_password');
            if (!empty($_REQUEST['redirect_url'])) {
                $redirect_url = $_REQUEST['redirect_url'];
                if (strpos($redirect_url, '://') === false) {
                    $redirect_url = 'http://' . $redirect_url;
                }
            } else {
                $redirect_url = fn_url();
            }
        }
    }
    fn_redirect($redirect_url, true);
}
//
// Display login form in the mainbox
//
if ($mode == 'login_form') {
    if (defined('AJAX_REQUEST') && empty($auth)) {
        exit;
    }
    if (!empty($auth['user_id'])) {
        return array(CONTROLLER_STATUS_REDIRECT, fn_url());
    }
    $stored_user_login = fn_restore_post_data('user_login');
    if (!empty($stored_user_login)) {
        Registry::get('view')->assign('stored_user_login', $stored_user_login);
    }