Example #1
0
    function store()
    {
        require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'language.php';
        require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'config.php';
        // load basic stuff:
        OPCLang::loadLang();
        $this->removeCache();
        $this->loadVmConfig();
        $user = JFactory::getUser();
        $this->storeRegistration();
        $opc_load_jquery = JRequest::getVar('opc_load_jquery', false);
        if (!empty($opc_load_jquery)) {
            $opc_load_jquery = true;
        }
        OPCConfig::store('opc_load_jquery', '', 0, $opc_load_jquery);
        if (!class_exists('JFile')) {
            require JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'joomla' . DIRECTORY_SEPARATOR . 'filesystem' . DIRECTORY_SEPARATOR . 'file.php';
        }
        if (!class_exists('JFolder')) {
            require JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'joomla' . DIRECTORY_SEPARATOR . 'filesystem' . DIRECTORY_SEPARATOR . 'folder.php';
        }
        $msg = '';
        $rename = JRequest::getVar('rename_to_custom', false);
        if ($rename) {
            $msg .= $this->renameTheme();
        }
        $db = JFactory::getDBO();
        $data = JRequest::get('post');
        $this->storeTY($data);
        $cfg = urldecode('%3C%3Fphp') . '
if( !defined( \'_VALID_MOS\' ) && !defined( \'_JEXEC\' ) ) die( \'Direct Access to \'.basename(__FILE__).\' is not allowed.\' );
/*
*      One Page Checkout configuration file
*      Copyright RuposTel s.r.o. under GPL license
*      Version 2 of date 31.March 2012
*      Feel free to modify this file according to your needs
*
*
*     @copyright Copyright (C) 2007 - 2012 RuposTel - All rights reserved.
*     @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*     One Page checkout is free software released under GNU/GPL and uses code from VirtueMart
*     VirtueMart is free software. This version may have been modified pursuant
*     to the GNU General Public License, and as distributed it includes or
*     is derivative of works licensed under the GNU General Public License or
*     other free or open source software licenses.
* 
*/




';
        $cfg .= '
		  if (!class_exists(\'VmConfig\'))
		  require(JPATH_ADMINISTRATOR.DS.\'components\'.DS.\'com_virtuemart\'.DS.\'helpers\'.DS.\'config.php\'); 
		  VmConfig::loadConfig(); 

';
        if (!empty($data['delete_ht'])) {
            if (JFile::delete(JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'assets' . DS . 'js' . DS . '.htaccess') === false) {
                $msg .= JText::sprintf('COM_VIRTUEMART_STRING_DELETED_ERROR', JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'assets' . DS . 'js' . DS . '.htaccess');
            }
        }
        if (!empty($data['opc_cr_type'])) {
            $cfg .= ' $opc_cr_type = \'' . $data['opc_cr_type'] . '\'; ';
        }
        $data['do_not_show_opcregistration'] = (int) $data['do_not_show_opcregistration'];
        if (!empty($data['do_not_show_opcregistration'])) {
            $cfg .= ' $do_not_show_opcregistration = 1; ';
        }
        if (isset($data['bt_fields_from'])) {
            $cfg .= ' $bt_fields_from = \'' . $data['bt_fields_from'] . '\'; ';
        }
        if (isset($data['op_default_shipping_search'])) {
            $cfg .= ' $op_default_shipping_search = array(); ';
            if (is_array($data['op_default_shipping_search'])) {
                $i = 0;
                foreach ($data['op_default_shipping_search'] as $key => $val) {
                    if (empty($val)) {
                        continue;
                    }
                    $cfg .= ' $op_default_shipping_search[' . $i . '] = "' . str_replace('"', '\\"', $val) . '"; ';
                    $i++;
                }
            } else {
                $cfg .= ' $op_default_shipping_search[0] = "' . str_replace('"', '\\"', $val) . '"; ';
            }
        }
        if (!empty($data['home_vat_countries'])) {
            $home = str_replace('"', '', $data['home_vat_countries']);
            $cfg .= ' $home_vat_countries = "' . $home . '"; ';
        }
        if (isset($data['opc_payment_refresh'])) {
            $cfg .= '$opc_payment_refresh = true;
    ';
        }
        if (isset($data['use_original_basket'])) {
            $cfg .= '$use_original_basket = true;
    ';
        } else {
            $cfg .= '$use_original_basket = false; 
    ';
        }
        //opc_php_js
        //theme_fix1
        if (isset($data['theme_fix1'])) {
            $cfg .= '$theme_fix1 = true;
    ';
        } else {
            $cfg .= '$theme_fix1 = false; 
    ';
        }
        if (isset($data['opc_override_registration'])) {
            $cfg .= '$opc_override_registration = true; 
    ';
            $this->enableOpcRegistration(true);
        } else {
            $this->enableOpcRegistration(false);
        }
        if (isset($data['opc_euvat'])) {
            $cfg .= '$opc_euvat = true;
    ';
            $coref = array();
            $ulist = $this->getUserFieldsLists($coref);
            $found = false;
            $published = 1;
            $datau = array();
            $datau2 = array();
            foreach ($ulist as $key => $val) {
                if ($val->name == 'opc_vat') {
                    $published = $val->published;
                    $found = true;
                    if (empty($published)) {
                        foreach ($val as $key2 => $v) {
                            $datau[$key2] = $v;
                        }
                    }
                }
                if ($val->name == 'opc_vat_info') {
                    $published2 = $val->published;
                    $found = true;
                    if (empty($published2)) {
                        foreach ($val as $key2 => $v) {
                            $datau2[$key2] = $v;
                        }
                    }
                }
            }
            if (!$found || (empty($published) || empty($published2))) {
                $modelu = new VirtueMartModelUserfields();
                if (empty($datau)) {
                    $datau = array('virtuemart_userfield_id' => '0', 'virtuemart_vendor_id' => '0', 'userfield_jplugin_id' => '0', 'name' => 'opc_vat', 'title' => 'COM_ONEPAGE_EUVAT_FIELD', 'description' => '', 'type' => 'text', 'maxlength' => '25', 'size' => '30', 'required' => '0', 'cols' => '0', 'rows' => '0', 'value' => '', 'default' => NULL, 'registration' => '1', 'shipment' => '0', 'account' => '1', 'readonly' => '0', 'calculated' => '0', 'sys' => '0', 'params' => '', 'ordering' => '99', 'shared' => '0', 'published' => '1', 'created_on' => '0000-00-00 00:00:00', 'created_by' => '0', 'modified_on' => '0000-00-00 00:00:00', 'modified_by' => '0', 'locked_on' => '0000-00-00 00:00:00', 'locked_by' => '0');
                } else {
                    $datau['published'] = 1;
                }
                if (empty($datau2)) {
                    $datau2 = array('virtuemart_userfield_id' => '0', 'virtuemart_vendor_id' => '0', 'userfield_jplugin_id' => '0', 'name' => 'opc_vat_info', 'title' => 'COM_ONEPAGE_EUVAT_FIELD_INFO', 'description' => '', 'type' => 'hidden', 'maxlength' => '1000', 'size' => NULL, 'required' => '0', 'cols' => '0', 'rows' => '0', 'value' => '', 'default' => NULL, 'registration' => '1', 'shipment' => '0', 'account' => '1', 'readonly' => '0', 'calculated' => '0', 'sys' => '0', 'params' => '', 'ordering' => '99', 'shared' => '0', 'published' => '1', 'created_on' => '0000-00-00 00:00:00', 'created_by' => '0', 'modified_on' => '0000-00-00 00:00:00', 'modified_by' => '0', 'locked_on' => '0000-00-00 00:00:00', 'locked_by' => '0');
                } else {
                    $datau2['published'] = 1;
                }
                $modelu->store($datau);
                $modelu->store($datau2);
            }
        } else {
            $q = 'update #__virtuemart_userfields set published = 0 where name LIKE "opc_vat" or name LIKE "opc_vat_info"';
            $db = JFactory::getDBO();
            $db->setQuery($q);
            $db->query();
        }
        if (isset($data['opc_euvat_button'])) {
            $cfg .= '$opc_euvat_button = true;
    ';
        }
        if (isset($data['opc_euvat_contrymatch'])) {
            $cfg .= '$opc_euvat_contrymatch = true;
    ';
        }
        //disable_check
        if (isset($data['opc_no_activation'])) {
            $cfg .= '$opc_no_activation = true;
    ';
        } else {
            $cfg .= '$opc_no_activation = false; 
    ';
        }
        //disable_check
        if (isset($data['disable_check'])) {
            $cfg .= '$disable_check = true;
    ';
        } else {
            $cfg .= '$disable_check = false; 
    ';
        }
        if (isset($data['opc_php_js2'])) {
            $cfg .= '$opc_php_js2 = true;
    ';
        } else {
            $cfg .= '$opc_php_js2 = false; 
    ';
        }
        //only_one_shipping_address_hidden
        if (isset($data['only_one_shipping_address_hidden'])) {
            $cfg .= '$only_one_shipping_address_hidden = true;
    ';
        } else {
            $cfg .= '$only_one_shipping_address_hidden = false; 
    ';
        }
        if (isset($data['opc_only_parent_links'])) {
            $cfg .= '$opc_only_parent_links = true;
    ';
        } else {
            $cfg .= '$opc_only_parent_links = false; 
    ';
        }
        //opc_show_weight
        if (isset($data['opc_show_weight'])) {
            $cfg .= '$opc_show_weight = true;
    ';
        } else {
            $cfg .= '$opc_show_weight = false; 
    ';
        }
        if (isset($data['opc_dynamic_lines'])) {
            $cfg .= '$opc_dynamic_lines = true;
    ';
        } else {
            $cfg .= '$opc_dynamic_lines = false; 
    ';
        }
        if (isset($data['opc_editable_attributes'])) {
            $cfg .= '$opc_editable_attributes = true;
    ';
        } else {
            $cfg .= '$opc_editable_attributes = false; 
    ';
        }
        if (isset($data['op_customer_shipping'])) {
            $cfg .= '$op_customer_shipping = true;
    ';
        } else {
            $cfg .= '$op_customer_shipping = false; 
    ';
        }
        //allow_sg_update
        if (isset($data['allow_sg_update'])) {
            $cfg .= '$allow_sg_update = true;
    ';
        } else {
            $cfg .= '$allow_sg_update = false; 
    ';
        }
        if (isset($data['allow_sg_update_logged'])) {
            $cfg .= '$allow_sg_update_logged = true;
    ';
        } else {
            $cfg .= '$allow_sg_update_logged = false; 
    ';
        }
        if (isset($data['do_not_allow_gift_deletion'])) {
            $cfg .= '$do_not_allow_gift_deletion = true;
    ';
        } else {
            $cfg .= '$do_not_allow_gift_deletion = false; 
    ';
        }
        $gift_order_statuses = JRequest::getVar('gift_order_statuses', array());
        if (empty($gift_order_statuses)) {
            $cfg .= ' $gift_order_statuses = array(); ';
        } else {
            $str = var_export($gift_order_statuses, true);
            $cfg .= "\n" . ' $gift_order_statuses = ' . $str . ';' . "\n";
        }
        //opc_async
        if (isset($data['opc_async'])) {
            $cfg .= '$opc_async = true;
    ';
        } else {
            $cfg .= '$opc_async = false; 
    ';
        }
        if (isset($data['use_free_text'])) {
            $cfg .= '$use_free_text = true;
    ';
        } else {
            $cfg .= '$use_free_text = false; 
    ';
        }
        if (isset($data['disable_op'])) {
            $cfg .= '$disable_onepage = true;
    ';
        } else {
            $cfg .= '$disable_onepage = false; 
    ';
        }
        if (isset($data['opc_italian_checkbox'])) {
            $cfg .= '$opc_italian_checkbox = true;
    ';
        } else {
            $cfg .= '$opc_italian_checkbox = false; 
    ';
        }
        if (isset($data['opc_acymailing_checkbox'])) {
            $cfg .= '$opc_acymailing_checkbox = true;
    ';
        } else {
            $cfg .= '$opc_acymailing_checkbox = false; 
    ';
        }
        $data['opc_acy_id'] = (int) $data['opc_acy_id'];
        $cfg .= ' $opc_acy_id = (int)"' . $data['opc_acy_id'] . '"; ';
        //opc_do_not_alter_registration
        if (isset($data['opc_do_not_alter_registration'])) {
            $cfg .= '$opc_do_not_alter_registration = true;
    ';
        } else {
            $cfg .= '$opc_do_not_alter_registration = false; 
    ';
        }
        if (isset($data['opc_debug'])) {
            $cfg .= '$opc_debug = true;
    ';
        } else {
            $cfg .= '$opc_debug = false; 
    ';
        }
        if (isset($data['opc_debug2'])) {
            $cfg .= '$opc_debug2 = true;
    ';
        }
        if (!empty($data['blank_screens_email'])) {
            $cfg .= ' $blank_screens_email = \'' . addslashes($data['blank_screens_email']) . '\'; ';
        }
        if (isset($data['opc_memory'])) {
            $cfg .= ' $opc_memory = \'' . addslashes($data['opc_memory']) . '\'; ';
        }
        if (isset($data['rupostel_email'])) {
            $cfg .= ' $rupostel_email = \'' . addslashes($data['rupostel_email']) . '\'; ';
        }
        if (isset($data['opc_plugin_order']) && is_numeric($data['opc_plugin_order'])) {
            $cfg .= '$opc_plugin_order = \'' . $data['opc_plugin_order'] . '\';
    ';
        } else {
            $cfg .= '$opc_plugin_order = -9999; 
    ';
        }
        //
        if (isset($data['opc_disable_for_mobiles'])) {
            $cfg .= '$opc_disable_for_mobiles = true;
    ';
        } else {
            $cfg .= '$opc_disable_for_mobiles = false; 
    ';
        }
        if (isset($data['opc_request_cache'])) {
            $cfg .= '$opc_request_cache = true;
    ';
        } else {
            $cfg .= '$opc_request_cache = false; 
    ';
        }
        if (isset($data['opc_check_username'])) {
            $cfg .= '$opc_check_username = true;';
        } else {
            $cfg .= '$opc_check_username = false;';
        }
        if (isset($data['opc_rtl'])) {
            $cfg .= '$opc_rtl = true;';
        } else {
            $cfg .= '$opc_rtl = false;';
        }
        if (!empty($data['opc_no_duplicit_username']) && empty($data['op_usernameisemail'])) {
            $cfg .= '$opc_no_duplicit_username = true;
    ';
            $cfg .= '$opc_check_username = true;';
        } else {
            $cfg .= '$opc_no_duplicit_username = false; 
    ';
        }
        if (isset($data['klarna_se_get_address'])) {
            $cfg .= '$klarna_se_get_address = true;';
        } else {
            $cfg .= '$klarna_se_get_address = false;';
        }
        if (isset($data['ajaxify_cart'])) {
            $cfg .= '$ajaxify_cart = true;';
        } else {
            $cfg .= '$ajaxify_cart = false;';
        }
        if (isset($data['opc_check_email'])) {
            $cfg .= '$opc_check_email = true;';
        } else {
            $cfg .= '$opc_check_email = false;';
        }
        if (!empty($data['opc_no_duplicit_email'])) {
            $cfg .= '$opc_no_duplicit_email = true;
    ';
            $cfg .= '$opc_check_email = true;';
            $cfg .= '$allow_duplicit = false;';
        } else {
            $cfg .= '$opc_no_duplicit_email = false; 
    ';
        }
        //show_single_tax
        if (!empty($data['show_single_tax'])) {
            $cfg .= '$show_single_tax = true;
    ';
        } else {
            $cfg .= '$show_single_tax = false; 
    ';
        }
        if (!empty($data['opc_calc_cache'])) {
            $cfg .= '$opc_calc_cache = true;
    ';
        } else {
            $cfg .= '$opc_calc_cache = false; 
    ';
        }
        if (!empty($data['visitor_shopper_group'])) {
            $cfg .= '$visitor_shopper_group = "' . $data['visitor_shopper_group'] . '";
    ';
        } else {
            $cfg .= '$visitor_shopper_group = 0; 
    ';
        }
        if (!empty($data['no_coupon_ajax'])) {
            $cfg .= '$no_coupon_ajax = true;
    ';
        } else {
            $cfg .= '$no_coupon_ajax = false; 
    ';
        }
        if (!empty($data['business_shopper_group'])) {
            $cfg .= '$business_shopper_group = "' . $data['business_shopper_group'] . '";
    ';
        } else {
            $cfg .= '$business_shopper_group = 0; 
    ';
        }
        if (!empty($data['zero_total_status'])) {
            $cfg .= '$zero_total_status = "' . $data['zero_total_status'] . '";
    ';
        } else {
            $cfg .= '$zero_total_status = "C"; 
    ';
        }
        //op_never_log_in
        //option_sgroup
        if (!empty($data['option_sgroup'])) {
            $cfg .= '$option_sgroup = ' . (int) $data['option_sgroup'] . ';;
    ';
        } else {
            $cfg .= '$option_sgroup = false; 
    ';
        }
        if (!empty($data['op_never_log_in'])) {
            $cfg .= '$op_never_log_in = true;
    ';
        } else {
            $cfg .= '$op_never_log_in = false; 
    ';
        }
        //no_alerts
        if (!empty($data['no_alerts'])) {
            $cfg .= '$no_alerts = true;
    ';
        } else {
            $cfg .= '$no_alerts = false; 
    ';
        }
        if (!empty($data['disable_ship_to_on_zero_weight'])) {
            $cfg .= '$disable_ship_to_on_zero_weight = true;
    ';
        } else {
            $cfg .= '$disable_ship_to_on_zero_weight = false; 
    ';
        }
        //
        if (!empty($data['op_use_geolocator'])) {
            $cfg .= '$op_use_geolocator = true;
    ';
        } else {
            $cfg .= '$op_use_geolocator = false; 
    ';
        }
        if (!empty($data['append_details'])) {
            $cfg .= '$append_details = true;
    ';
        } else {
            $cfg .= '$append_details = false; 
    ';
        }
        if (!empty($data['op_redirect_joomla_to_vm'])) {
            $cfg .= '$op_redirect_joomla_to_vm = true;
    ';
        } else {
            $cfg .= '$op_redirect_joomla_to_vm = false; 
    ';
        }
        if (!empty($data['password_clear_text'])) {
            $cfg .= '$password_clear_text = true;
    ';
        } else {
            $cfg .= '$password_clear_text = false; 
    ';
        }
        $cfg .= ' $dpps_search = array(); $dpps_disable = array(); $dpps_default=array(); ' . "\n";
        if (!empty($data['disable_payment_per_shipping'])) {
            $search = JRequest::getVar('dpps_search');
            $cfg .= ' $disable_payment_per_shipping = true; ';
            foreach ($search as $i => $v) {
                if (!empty($data['dpps_disable'][$i]) && !empty($v)) {
                    $val = urlencode($v);
                    $val = str_replace("'", "\\'", $val);
                    $cfg .= ' $dpps_search[' . $i . '] = ' . "'" . $val . "';\n";
                    $cfg .= ' $dpps_disable[' . $i . '] = ' . "'" . $data['dpps_disable'][$i] . "';\n";
                    if ($data['dpps_default'][$i] != $data['dpps_disable'][$i]) {
                        $cfg .= ' $dpps_default[' . $i . '] = ' . "'" . $data['dpps_default'][$i] . "';\n";
                    } else {
                        $cfg .= ' $dpps_default[' . $i . '] = \'\'; ';
                    }
                }
            }
        } else {
            $cfg .= ' $disable_payment_per_shipping = false; ';
        }
        if (!empty($data['euvat_shopper_group'])) {
            $cfg .= '$euvat_shopper_group = "' . $data['euvat_shopper_group'] . '";
    ';
        } else {
            $cfg .= '$euvat_shopper_group = 0; 
    ';
        }
        if (!empty($data['payment_discount_before'])) {
            $cfg .= '$payment_discount_before = true;
    ';
        } else {
            $cfg .= '$payment_discount_before = false; 
    ';
        }
        if (!empty($data['only_one_shipping_address'])) {
            $cfg .= '$only_one_shipping_address = true;
    ';
        } else {
            $cfg .= '$only_one_shipping_address = false; 
    ';
        }
        if (isset($data['no_extra_product_info'])) {
            $cfg .= '$no_extra_product_info = true;
    ';
        } else {
            $cfg .= '$no_extra_product_info = false; 
    ';
        }
        if (isset($data['enable_captcha_unlogged'])) {
            $cfg .= '$enable_captcha_unlogged = true;
    ';
        } else {
            $cfg .= '$enable_captcha_unlogged = false; 
    ';
        }
        if (isset($data['send_pending_mail'])) {
            $cfg .= '$send_pending_mail = true;
    ';
        } else {
            $cfg .= '$send_pending_mail = false; 
    ';
        }
        if (isset($data['enable_captcha_logged'])) {
            $cfg .= '$enable_captcha_logged = true;
    ';
        } else {
            $cfg .= '$enable_captcha_logged = false; 
    ';
        }
        if (isset($data['hide_advertise'])) {
            $cfg .= '$hide_advertise = true;
    ';
        } else {
            $cfg .= '$hide_advertise = false; 
    ';
        }
        if (isset($data['hide_payment_if_one'])) {
            $cfg .= '$hide_payment_if_one = true;
    ';
        } else {
            $cfg .= '$hide_payment_if_one = false; 
    ';
        }
        if (!empty($data['disable_op'])) {
            if (version_compare(JVERSION, '1.7.0', 'ge') || version_compare(JVERSION, '1.6.0', 'ge') || version_compare(JVERSION, '2.5.0', 'ge')) {
                $q = "update #__extensions set enabled = 0 where element = 'opc' and type = 'plugin' limit 2 ";
            } else {
                $q = "update #__plugins set published = 0 where element = 'opc'  limit 2 ";
            }
            $db = JFactory::getDBO();
            $db->setQuery($q);
            $db->query();
            $e = $db->getErrorMsg();
            if (!empty($e)) {
                echo $msg .= $e;
            }
        } else {
            if (version_compare(JVERSION, '1.7.0', 'ge') || version_compare(JVERSION, '1.6.0', 'ge') || version_compare(JVERSION, '2.5.0', 'ge')) {
                $q = "update #__extensions set enabled = 1 where element = 'opc' and type = 'plugin' and folder = 'system' limit 2 ";
                // disable other opc solutions:
                $q2 = "update #__extensions set enabled = 0 where element = 'onestepcheckout' and type = 'plugin' and folder = 'system' ";
                $q3 = "update #__extensions set enabled = 0 where element = 'vponepagecheckout' and type = 'plugin' and folder = 'system' ";
            } else {
                $q = "update #__plugins set published = 1 where element = 'opc' and folder = 'system'  limit 2 ";
                $q2 = "update #__plugins set published = 0 where element = 'onestepcheckout' and folder = 'system' ";
                $q3 = "update #__plugins set published = 0 where element = 'vponepagecheckout' and folder = 'system' ";
            }
            $db = JFactory::getDBO();
            $db->setQuery($q);
            $db->query();
            $e = $db->getErrorMsg();
            if (!empty($e)) {
                echo $msg .= $e;
            }
            $db = JFactory::getDBO();
            $db->setQuery($q2);
            $db->query();
            $db = JFactory::getDBO();
            $db->setQuery($q3);
            $db->query();
        }
        $cfg .= "\n/* If user in Optional, normal, silent registration sets email which already exists and is registered \n* and you set this to true\n* his order details will be saved but he will not be added to joomla registration and checkout can continue\n* if registration type allows username and password which is already registered but his new password is not the same as in DB then checkout will return error\n*/\n";
        if (isset($data['email_after'])) {
            $cfg .= '$email_after = true;
      ';
        } else {
            $cfg .= '$email_after = false;
      ';
        }
        if (empty($data['opc_link_type'])) {
            $cfg .= '$opc_link_type = 0;
      ';
        } else {
            $cfg .= '$opc_link_type = ' . $data['opc_link_type'] . '; 
      ';
        }
        if (!empty($data['business_fields'])) {
            foreach ($data['business_fields'] as $k => $line) {
                $data['business_fields'][$k] = "'" . $line . "'";
            }
            // special cases
            if (in_array('password', $data['business_fields'])) {
                $data['business_fields'][] = 'opc_password';
            }
            if (in_array('username', $data['business_fields'])) {
                $data['business_fields'][] = 'opc_username';
            }
            $newa = implode(',', $data['business_fields']);
            $cfg .= ' $business_fields = array(' . $newa . '); ';
        } else {
            $cfg .= ' $business_fields = array(); ';
        }
        if (!empty($data['custom_rendering_fields'])) {
            foreach ($data['custom_rendering_fields'] as $k => $line) {
                $data['custom_rendering_fields'][$k] = "'" . $line . "'";
            }
            $newa = implode(',', $data['custom_rendering_fields']);
            $cfg .= ' $custom_rendering_fields = array(' . $newa . '); ';
        } else {
            $cfg .= ' $custom_rendering_fields = array(); ';
        }
        if (!empty($data['shipping_obligatory_fields'])) {
            foreach ($data['shipping_obligatory_fields'] as $k => $line) {
                $data['shipping_obligatory_fields'][$k] = "'" . $line . "'";
            }
            $newa = implode(',', $data['shipping_obligatory_fields']);
            $cfg .= ' $shipping_obligatory_fields = array(' . $newa . '); ';
        } else {
            $cfg .= ' $shipping_obligatory_fields = array(); ';
        }
        if (!empty($data['op_disable_shipping'])) {
            $cfg .= '$op_disable_shipping = true;
      ';
        } else {
            $cfg .= '$op_disable_shipping = false;
      ';
        }
        if (!empty($data['op_disable_shipto'])) {
            $cfg .= '$op_disable_shipto = true;
      ';
        } else {
            $cfg .= '$op_disable_shipto = false;
      ';
        }
        if (!empty($data['op_no_display_name'])) {
            $cfg .= '$op_no_display_name = true;
      ';
        } else {
            $cfg .= '$op_no_display_name = false;
      ';
        }
        if (!empty($data['op_create_account_unchecked'])) {
            $cfg .= '$op_create_account_unchecked = true;
      ';
        } else {
            $cfg .= '$op_create_account_unchecked = false;
      ';
        }
        /*	  
          	  if (!empty($data['tos_itemid']))
            $cfg .= ' $tos_itemid = "'.$data['tos_itemid'].'"; '; 
        */
        if (!empty($data['product_price_display'])) {
            $cfg .= ' $product_price_display = "' . $data['product_price_display'] . '";' . "\n";
        }
        if (!empty($data['subtotal_price_display'])) {
            $cfg .= ' $subtotal_price_display = "' . $data['subtotal_price_display'] . '";' . "\n";
        }
        if (!empty($data['opc_usmode'])) {
            $cfg .= ' $opc_usmode = true; ';
        } else {
            $cfg .= ' $opc_usmode = false; ';
        }
        if (!empty($data['full_tos_logged'])) {
            $cfg .= ' $full_tos_logged = true; ';
        } else {
            $cfg .= ' $full_tos_logged = false; ';
        }
        if (!empty($data['tos_scrollable'])) {
            $cfg .= ' $tos_scrollable = true; ';
        } else {
            $cfg .= ' $tos_scrollable = false; ';
        }
        $legal_info = VmConfig::get('oncheckout_show_legal_info', '1');
        if (!empty($data['full_tos_unlogged'])) {
            $cfg .= ' $full_tos_unlogged = true; ';
        } else {
            $cfg .= ' $full_tos_unlogged = false; ';
        }
        $tosx = VmConfig::get('agree_to_tos_onorder', '1');
        if (!empty($data['tos_logged'])) {
            $cfg .= ' $tos_logged = true; ';
        } else {
            $cfg .= ' $tos_logged = false; ';
        }
        if (!empty($data['tos_unlogged'])) {
            $cfg .= ' $tos_unlogged = true; ';
        } else {
            $cfg .= ' $tos_unlogged = false; ';
        }
        if (!empty($data['opc_email_in_bt'])) {
            $cfg .= ' $opc_email_in_bt = true; ';
        } else {
            $cfg .= ' $opc_email_in_bt = false; ';
        }
        if (!empty($data['double_email'])) {
            $cfg .= ' $double_email = true; ';
        } else {
            $cfg .= ' $double_email = false; ';
        }
        if (!empty($data['coupon_price_display'])) {
            $cfg .= ' $coupon_price_display = "' . $data['coupon_price_display'] . '";' . "\n";
        }
        if (!empty($data['other_discount_display'])) {
            $cfg .= ' $other_discount_display = "' . $data['other_discount_display'] . '";' . "\n";
        }
        if (isset($data['agreed_notchecked'])) {
            $cfg .= '$agreed_notchecked = true;
      ';
        } else {
            $cfg .= '$agreed_notchecked = false;
      ';
        }
        if ((int) $data['opc_default_shipping'] === 1) {
            $cfg .= '
	  $opc_default_shipping = 1; 
	  $op_default_shipping_zero = true;
	  $shipping_inside_choose = false; 
      ';
        } else {
            if ((int) $data['opc_default_shipping'] === 3) {
                $cfg .= ' $shipping_inside_choose = true; 
	    $opc_default_shipping = 3; 
	   ';
            } else {
                $cfg .= '
	   $op_default_shipping_zero = false;
	   $opc_default_shipping = ' . (int) $data['opc_default_shipping'] . ';
       $shipping_inside_choose = false;
	  ';
            }
        }
        if (!empty($data['never_count_tax_on_shipping'])) {
            $cfg .= '$never_count_tax_on_shipping = true;
      ';
        } else {
            $cfg .= '$never_count_tax_on_shipping = false;
      ';
        }
        if (!empty($data['save_shipping_with_tax'])) {
            $cfg .= '$save_shipping_with_tax = true;
      ';
        } else {
            $cfg .= '$save_shipping_with_tax = false;
      ';
        }
        if (isset($data['op_no_basket'])) {
            $cfg .= '$op_no_basket = true;
      ';
        } else {
            $cfg .= '$op_no_basket = false;
      ';
        }
        if (!empty($data['utm_payment'])) {
            $utm_p = (array) $data['utm_payment'];
        } else {
            $utm_p = array();
        }
        $utm_p2 = array();
        if (!empty($utm_p)) {
            foreach ($utm_p as $ku => $vu) {
                $utm_p2[(int) $ku] = (int) $vu;
            }
        }
        //$utm_p = OPCConfig::getValue('opc_config', 'utm_payments', 0, $default, false, false);
        OPCconfig::store('opc_config', 'utm_payments', 0, $utm_p2);
        if (isset($data['shipping_template'])) {
            $cfg .= '$shipping_template = true;
      ';
        } else {
            $cfg .= '$shipping_template = false;
      ';
        }
        $opclang = JRequest::getVar('opc_lang_orig', '');
        require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'config.php';
        $currency_config = JRequest::getVar('country_currency', array());
        $aset = array();
        OPCconfig::clearConfig('currency_config');
        if (!empty($currency_config)) {
            foreach ($currency_config as $cid => $arr) {
                if (!empty($arr)) {
                    foreach ($arr as $country_id) {
                        if (!empty($aset[$country_id])) {
                            continue;
                        }
                        $aset[$country_id] = $country_id;
                        $q = 'select country_2_code from #__virtuemart_countries where virtuemart_country_id = ' . (int) $country_id . ' limit 0,1';
                        $db = JFactory::getDBO();
                        $db->setQuery($q);
                        $c2c = $db->loadResult();
                        if (!empty($c2c)) {
                            OPCconfig::store('currency_config', $c2c, 0, (int) $cid);
                        }
                    }
                }
            }
        }
        if (!empty($data['currency_plg_can_change'])) {
            OPCconfig::store('currency_config', 'can_change', 0, true);
        } else {
            OPCconfig::store('currency_config', 'can_change', 0, false);
        }
        if (!empty($data['currency_plg'])) {
            $this->setPluginEnabled('opc_currency', 'system', true);
        } else {
            $this->setPluginEnabled('opc_currency', 'system', false);
        }
        OPCconfig::store('opc_config', 'op_articleid' . $opclang, 0, $data['op_articleid']);
        OPCconfig::store('opc_config', 'adc_op_articleid' . $opclang, 0, $data['adc_op_articleid']);
        OPCconfig::store('opc_config', 'tos_itemid' . $opclang, 0, $data['tos_itemid']);
        OPCconfig::store('opc_config', 'newitemid' . $opclang, 0, $data['newitemid']);
        OPCconfig::store('opc_config', 'op_customitemidty' . $opclang, 0, $data['op_customitemidty']);
        /*
        	  if (!empty($data['op_customitemidty']))
         {
          $cfg .= '$op_customitemidty = "'.(int)trim($data['op_customitemidty']).'";
              ';
         }
        */
        /* 
        if (!empty($data['newitemid']))
         $cfg .= '$newitemid = "'.trim($data['newitemid']).'";
              ';
              else $cfg .= '$newitemid = "";
              ';
        */
        //
        /*
        	  if (!empty($data['op_articleid']))
         $cfg .= '$op_articleid = "'.$data['op_articleid'].'";
        	  ';
        	  else $cfg .= '$op_articleid = "";
        	  ';
        	  
        
        	  	  if (!empty($data['adc_op_articleid']))
         $cfg .= '$adc_op_articleid = "'.$data['adc_op_articleid'].'";
        	  ';
        	  else $cfg .= '$adc_op_articleid = "";
        	  ';
        */
        if (isset($data['op_sum_tax'])) {
            $cfg .= '$op_sum_tax = true;
      ';
        } else {
            $cfg .= '$op_sum_tax = false;
      ';
        }
        if (isset($data['op_last_field'])) {
            $cfg .= '$op_last_field = true;
      ';
        } else {
            $cfg .= '$op_last_field = false;
      ';
        }
        if (!empty($data['op_default_zip'])) {
            $cfg .= '$op_default_zip = "' . urlencode($data['op_default_zip']) . '"; 
	';
        } else {
            if ($data['op_default_zip'] === '0' || $data['op_default_zip'] === 0) {
                $cfg .= '$op_default_zip = 0; ';
            } else {
                $cfg .= '$op_default_zip = "99999";
	';
            }
        }
        if (!empty($data['op_numrelated']) && is_numeric($data['op_numrelated'])) {
            $cfg .= '$op_numrelated = "' . $data['op_numrelated'] . '"; 
      ';
        } else {
            $cfg .= '$op_numrelated = false;
      ';
        }
        $cfg .= '
// auto config by template
$cut_login = false;
      ';
        if (isset($data['op_delay_ship'])) {
            $cfg .= '$op_delay_ship = true;
      ';
        } else {
            $cfg .= '$op_delay_ship = false;
      ';
        }
        if (isset($data['op_loader'])) {
            $cfg .= '$op_loader = true;
      ';
        } else {
            $cfg .= '$op_loader = false;
      ';
        }
        if (isset($data['op_usernameisemail'])) {
            $cfg .= '$op_usernameisemail = true;
      ';
        } else {
            $cfg .= '$op_usernameisemail = false;
      ';
        }
        if (isset($data['no_continue_link_bottom'])) {
            $cfg .= '$no_continue_link_bottom = true;
      ';
        } else {
            $cfg .= '$no_continue_link_bottom = false;
      ';
        }
        if (isset($data['op_default_state'])) {
            $cfg .= '$op_default_state = true;
      ';
        } else {
            $cfg .= '$op_default_state = false;
      ';
        }
        if (isset($data['list_userfields_override'])) {
            $cfg .= '$list_userfields_override = true;
      ';
        } else {
            $cfg .= '$list_userfields_override = false;
      ';
        }
        if (isset($data['no_jscheck'])) {
            $cfg .= '$no_jscheck = true;
      ';
        } else {
            $cfg .= '$no_jscheck = true;
      ';
        }
        if (isset($data['op_dontloadajax'])) {
            $cfg .= '$op_dontloadajax = true;
      		   $no_jscheck = true;
      ';
        } else {
            $cfg .= '$op_dontloadajax = false;
      ';
        }
        if (isset($data['shipping_error_override'])) {
            $serr = urlencode($data['shipping_error_override']);
            $cfg .= '$shipping_error_override = "' . $serr . '";
      ';
        } else {
            $cfg .= '$shipping_error_override = "";
      ';
        }
        if (isset($data['op_zero_weight_override'])) {
            $cfg .= '$op_zero_weight_override = true;
      ';
        } else {
            $cfg .= '$op_zero_weight_override = false;
      ';
        }
        if (isset($data['email_after'])) {
            $cfg .= '$email_after = true;
      ';
        } else {
            $cfg .= '$email_after = false;
      ';
        }
        if (isset($data['override_basket'])) {
            $cfg .= '$override_basket = true;
      ';
        } else {
            $cfg .= '$override_basket = false;
      ';
        }
        if ($data['selected_template'] != 'default') {
            $data['selected_template'] = JFile::makeSafe($data['selected_template']);
            $cfg .= '$selected_template = "' . $data['selected_template'] . '";
	    if (empty($is_admin))
		{
		$selected_template_override = JRequest::getVar(\'opc_theme\', \'\'); 
		if (!empty($selected_template_override))
		{
		$test = str_replace(\'_\', \'\', $selected_template_override); 
		if (ctype_alnum($test))
		 {
		   $selected_template = $selected_template_override; 
		 }
		}
		}
		
      ';
        } else {
            $cfg .= '$selected_template = ""; 
       ';
        }
        if (!empty($data['mobile_template'])) {
            $data['mobile_template'] = JFile::makeSafe($data['mobile_template']);
            $cfg .= ' 
  $is_mobile = false; 
  $mobile_template = "' . $data['mobile_template'] . '";
  if (empty($is_admin))
  if (empty($selected_template_override))
  {
$app = JFactory::getApplication(); 
$jtouch = $app->getUserStateFromRequest(\'jtpl\', \'jtpl\', -1, \'int\');
if (($jtouch > 0) || (defined(\'OPC_DETECTED_DEVICE\') && ((constant(\'OPC_DETECTED_DEVICE\')==\'MOBILE\') || ((constant(\'OPC_DETECTED_DEVICE\')==\'TABLET\')))))
 {
   $is_mobile = true; 
   $selected_template = $mobile_template; 
 }
 
 
 }
  
  ';
        }
        if (!isset($data['adwords_timeout'])) {
            $data['adwords_timeout'] = 4;
        }
        $op_timeout = (int) $data['adwords_timeout'];
        $cfg .= ' $adwords_timeout = ' . $op_timeout . '; ';
        if (isset($data['dont_show_inclship'])) {
            $cfg .= '$dont_show_inclship = true;
      ';
        } else {
            $cfg .= '$dont_show_inclship = false;
      ';
        }
        if (isset($data['no_continue_link'])) {
            $cfg .= '$no_continue_link = true;
      ';
        } else {
            $cfg .= '$no_continue_link = false;
      ';
        }
        require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_onepage' . DS . 'models' . DS . 'tracking.php';
        $modelT = new JModelTracking();
        $modelT->setEnabled();
        // removed in 2.0.207
        /*
        	 if (false)
        if (isset($data['adwords_enabled_0']) && (!empty($_POST['adwords_code_0'])))
        {
          jimport('joomla.filesystem.folder');
          jimport('joomla.filesystem.file');
        	
         $code = JRequest::getVar('adwords_code_0', '', 'post', 'string', JREQUEST_ALLOWRAW); // $_POST['adwords_code_0']; $code = $_POST['adwords_code_0'];
          if (JFile::write(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'trackers'.DS.'body.html', $code) === false)
          {
               $msg .= 'Cannot write to: '.JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'trackers'.DS.'body.html<br />';
          }
          else
          {
          $cfg .= '
          $adwords_name = array(); $adwords_code = array(); $adwords_amount = array();
        	$adwords_name[0] = "body.html";
        	
              
         		$adwords_amount[0] = "'.$data['adwords_amount_0'].'";
              $adwords_enabled[0] = true;
         	';
        }
        }
        else
        {
         $cfg .= '
         	$adwords_name = array(); $adwords_code = array(); $adwords_amount = array();
         	$adwords_name[0] = "body.html";
         	$adwords_amount[0] = "'.$data['adwords_amount_0'].'";
         	';
        	
        	jimport('joomla.filesystem.file');
        	$code = ""; 
        	if (JFile::write(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'trackers'.DS.'body.html', $code) === false)
          {
               $msg .= 'Cannot write to: '.JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'trackers'.DS.'body.html';
          }
        	
        }
        */
        if (isset($data['no_login_in_template'])) {
            $cfg .= '$no_login_in_template = true;
      ';
        } else {
            $cfg .= '$no_login_in_template = false;
      ';
        }
        $cfg . '


/* Following variables are to change shipping or payment to select boxes
*/
';
        if (isset($data['shipping_inside'])) {
            $cfg .= '$shipping_inside = true;
      ';
        } else {
            $cfg .= '$shipping_inside = false;
      ';
        }
        if (isset($data['payment_inside'])) {
            $cfg .= '$payment_inside = true;
      ';
        } else {
            $cfg .= '$payment_inside = false;
      ';
        }
        if (isset($data['payment_saveccv'])) {
            $cfg .= '$payment_saveccv = true;
      ';
        } else {
            $cfg .= '$payment_saveccv = false;
      ';
        }
        if (isset($data['payment_advanced'])) {
            $cfg .= '$payment_advanced = true;
      ';
        } else {
            $cfg .= '$payment_advanced = false;
      ';
        }
        if (isset($data['fix_encoding'])) {
            $cfg .= '$fix_encoding = true;
      ';
        } else {
            $cfg .= '$fix_encoding = false;
      ';
        }
        if (isset($data['fix_encoding_utf8'])) {
            $cfg .= '$fix_encoding_utf8 = true;
$fix_encoding = false;
      ';
        } else {
            $cfg .= '$fix_encoding_utf8 = false;
      ';
        }
        if (isset($data['shipping_inside_basket'])) {
            $cfg .= '$shipping_inside_basket = true;
      ';
        } else {
            $cfg .= '$shipping_inside_basket = false;
      ';
        }
        if (isset($data['payment_inside_basket'])) {
            $cfg .= '$payment_inside_basket = true;
      ';
        } else {
            $cfg .= '$payment_inside_basket = false;
      ';
        }
        if (isset($data['email_only_pok'])) {
            $cfg .= '$email_only_pok = true;
      ';
        } else {
            $cfg .= '$email_only_pok = false;
      ';
        }
        if (!empty($data['no_taxes_show'])) {
            $cfg .= '$no_taxes_show = true;
      ';
        } else {
            $cfg .= '$no_taxes_show = false;
      ';
        }
        if (!empty($data['use_order_tax'])) {
            $cfg .= '$use_order_tax = true;
      ';
        } else {
            $cfg .= '$use_order_tax = false;
      ';
        }
        if (isset($data['no_taxes'])) {
            $cfg .= '$no_taxes = true;
      ';
        } else {
            $cfg .= '$no_taxes = false;
      ';
        }
        if (isset($data['never_show_total'])) {
            $cfg .= '$never_show_total = true;
      ';
        } else {
            $cfg .= '$never_show_total = false;
      ';
        }
        if (isset($data['email_dontoverride'])) {
            $cfg .= '$email_dontoverride = true;
      ';
        } else {
            $cfg .= '$email_dontoverride = false;
      ';
        }
        if (isset($data['allow_duplicit'])) {
            $cfg .= '$allow_duplicit = true;
      ';
        } else {
            $cfg .= '$allow_duplicit = false;
      ';
        }
        if (isset($data['show_only_total'])) {
            $cfg .= '$show_only_total = true;
      ';
        } else {
            $cfg .= '$show_only_total = false;
      ';
        }
        if (isset($data['show_andrea_view'])) {
            $cfg .= '$show_andrea_view = true;
      ';
        } else {
            $cfg .= '$show_andrea_view = false;
      ';
        }
        if (isset($data['always_show_tax'])) {
            $cfg .= '$always_show_tax = true;
';
        } else {
            $cfg .= '$always_show_tax = false;
';
        }
        if (isset($data['always_show_all'])) {
            $cfg .= '$always_show_all = true;
';
        } else {
            $cfg .= '$always_show_all = false;
';
        }
        if (isset($data['add_tax'])) {
            $cfg .= '$add_tax = true;
      ';
        } else {
            $cfg .= '$add_tax = false;
      ';
        }
        if (isset($data['add_tax_to_shipping_problem'])) {
            $cfg .= '$add_tax_to_shipping_problem = true;
      ';
        } else {
            $cfg .= '$add_tax_to_shipping_problem = false;
      ';
        }
        if (isset($data['add_tax_to_shipping'])) {
            $cfg .= '$add_tax_to_shipping = true;
      ';
        } else {
            $cfg .= '$add_tax_to_shipping = false;
      ';
        }
        if (isset($data['custom_tax_rate'])) {
            $cfg .= '$custom_tax_rate = "' . addslashes($data['custom_tax_rate']) . '"; 
      ';
        } else {
            $cfg .= '$custom_tax_rate = 0;
      ';
        }
        if (isset($data['opc_auto_coupon'])) {
            $cfg .= '$opc_auto_coupon = "' . addslashes($data['opc_auto_coupon']) . '"; 
      ';
        } else {
            $cfg .= '$opc_auto_coupon = \'\';
      ';
        }
        if (isset($data['no_decimals'])) {
            $cfg .= '$no_decimals = true;';
        } else {
            $cfg .= '$no_decimals = false;';
        }
        if (isset($data['curr_after'])) {
            $cfg .= '$curr_after = true;';
        } else {
            $cfg .= '$curr_after = false;';
        }
        //
        if (isset($data['load_min_bootstrap'])) {
            $cfg .= '$load_min_bootstrap = true;';
        } else {
            $cfg .= '$load_min_bootstrap = false;';
        }
        $cfg .= "\n/*\nSet this to true to unlog (from Joomla) all shoppers after purchase\n*/\n";
        if (isset($data['unlog_all_shoppers'])) {
            $cfg .= '$unlog_all_shoppers = true;
		$no_login_in_template = true; 
';
        } else {
            $cfg .= '$unlog_all_shoppers = false;
';
        }
        // vat_input_id, eu_vat_always_zero, move_vat_shopper_group, zerotax_shopper_group
        if (!empty($data['vat_input_id'])) {
            $cfg .= '$vat_input_id = "' . $data['vat_input_id'] . '"; ';
        } else {
            $cfg .= '$vat_input_id = ""; ';
        }
        if (!empty($data['eu_vat_always_zero'])) {
            $cfg .= '$eu_vat_always_zero = "' . $data['eu_vat_always_zero'] . '"; ';
        } else {
            $cfg .= '$eu_vat_always_zero = ""; ';
        }
        if (empty($data['vat_except'])) {
            $data['vat_except'] = '';
        }
        $te = strtoupper($data['vat_except']);
        $eu = array('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK');
        if (!empty($data['vat_except'])) {
            if (!in_array($te, $eu)) {
                $msg .= 'Country code is not valid for EU ! Code used:' . $data['vat_except'] . '<br />';
                $msg .= "These are valid codes : 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' without apostrophies <br />";
            }
            $cfg .= '$vat_except = "' . $data['vat_except'] . '"; ';
        } else {
            $cfg .= '$vat_except = ""; ';
        }
        if (!empty($data['move_vat_shopper_group'])) {
            $cfg .= '$move_vat_shopper_group = "' . $data['move_vat_shopper_group'] . '"; ';
        } else {
            $cfg .= '$move_vat_shopper_group = ""; ';
        }
        if (!empty($data['zerotax_shopper_group'])) {
            $str = '';
            foreach ($data['zerotax_shopper_group'] as $g) {
                if (!empty($str)) {
                    $str .= ',' . $g . '';
                } else {
                    $str = "" . $g . "";
                }
            }
            $cfg .= ' $zerotax_shopper_group = array(' . $str . '); ';
        } else {
            $cfg .= ' $zerotax_shopper_group = array(); ';
        }
        $cfg .= " \n/* set this to true if you don't accept other than valid EU VAT id */\n";
        if (!empty($data['must_have_valid_vat'])) {
            $cfg .= '$must_have_valid_vat = true; ';
        } else {
            $cfg .= '$must_have_valid_vat = false; ';
        }
        $cfg .= "\n/*\n* Set this to true to unlog (from Joomla) all shoppers after purchase\n*/\n";
        if (isset($data['unlog_all_shoppers'])) {
            $cfg .= ' $unlog_all_shoppers = true;
      ';
        } else {
            $cfg .= ' $unlog_all_shoppers = false;
     ';
        }
        $cfg .= "\n/* This will disable positive messages on Thank You page in system info box */\n\n";
        $cfg .= "\n/* please check your source code of your country list in your checkout and get exact virtuemart code for your country\n* all incompatible shipping methods will be hiddin until customer choses other country\n* this will also be preselected in registration and shipping forms\n* Your shipping method cannot have 0 index ! Otherwise it will not be set as default\n*/     \n";
        if (isset($data['default_country'])) {
            $cfg .= ' $default_shipping_country = "' . $data['default_country'] . '";
      ';
        } else {
            $cfg .= ' $default_shipping_country = "";
     ';
        }
        /*
        $cfg .= '
        if (!defined("DEFAULT_COUNTRY"))
        {
         if (file_exists(JPATH_SITE.DS."administrator".DS."components".DS."com_geolocator".DS."assets".DS."helper.php"))
         {
          require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_geolocator".DS."assets".DS."helper.php"); 
          if (class_exists("geoHelper"))
           {
             $country_2_code = geoHelper::getCountry2Code(""); 
        	 if (!empty($country_2_code))
        	 {
        	 $db= JFactory::getDBO(); 
        	 $db->setQuery("select virtuemart_country_id from #__virtuemart_countries where country_2_code = \'".$country_2_code."\' "); 
        	 $r = $db->loadResult(); 
        	 if (!empty($r)) 
        	 $default_shipping_country = $r; 
        	 }
             //$default_shipping_country = 
           }
         }
          define("DEFAULT_COUNTRY", $default_shipping_country); 
         }
         else
         {
          $default_shipping_country = DEFAULT_COUNTRY; 
         
         }
        ';  
        */
        $cfg .= "\n/* since VM 1.1.5 there is paypal new api which can be clicked on image instead of using checkout process\n* therefore we can hide it from payments\n* These payments will be hidden all the time\n* example:  " . '$payments_to_hide = "4,3,5,2";
*/
';
        $cfg .= "\n/* default payment option id\n* leave commented or 0 to let VM decide\n*/\n";
        $pd = $data['default_payment'];
        if (!isset($data['default_payment']) || $pd == 'default') {
            $pd = '""';
        }
        $cfg .= '$payment_default = \'' . $pd . '\';
	';
        $cfg .= "\n/* turns on google analytics tracking, set to false if you don't use it */\n";
        /*
        	if ($data['g_analytics']=='1')
        	{
        	  $cfg .= ' $g_analytics = true;
        ';
        	}
        	else 
        	  $cfg .= ' $g_analytics = false;
        ';
        */
        $cfg .= "\n/* set this to false if you don't want to show full TOS\n* if you set show_full_tos, set this variable to one of theses:\n* use one of these values:\n* 'shop.tos' to read tos from your VirtueMart configuration\n* '25' if set to number it will search for article with this ID, extra lines will be removed automatically\n* both will be shown without any formatting\n*/\n";
        /* disabled, now differenciated between logged and unlogged within the loader file which is further sent to the template
         	if (isset($data['show_full_tos']))
         	{
         	  $cfg .= ' $show_full_tos = true; 
        ';
         	} else  	  $cfg .= ' $show_full_tos = false; 
        ';
        */
        //tos_config
        $opclang = JRequest::getVar('opc_lang_orig', '');
        require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'config.php';
        OPCconfig::store('opc_config', 'tos_config' . $opclang, 0, $data['tos_config']);
        /*
        $t = $data['tos_config'];
        $t = trim(strtolower($t));
        $cfg .= ' $tos_config = "'.$t.'"; 
        ';
        */
        /*
         	if (isset($data['op_show_others']))
         	{
         	  $cfg .= ' $op_show_others = true; 
        ';
         	} else  	  $cfg .= ' $op_show_others = false; 
        
        
        
        ';
        */
        if (isset($data['op_fix_payment_vat'])) {
            $cfg .= ' $op_fix_payment_vat = true; 
';
        } else {
            $cfg .= ' $op_fix_payment_vat = false; 
';
        }
        if (isset($data['op_free_shipping'])) {
            $cfg .= ' $op_free_shipping = true; 
';
        } else {
            $cfg .= ' $op_free_shipping = false; 
';
        }
        $cfg .= "\n/* change this variable to your real css path of '>> Proceed to Checkout'\n* let's hide 'Proceed to checkout' by CSS\n* if it doesn't work, change css path accordingly, i recommend Firefox Firebug to get the path\n* but this works for most templates, but if you see 'Proceed to checkout' link, contact me at stan@rupostel.sk\n* for rt_mynxx_j15 template use '.cart-checkout-bar {display: none; }'\n*/\n";
        $cfg .= '
$payment_info = array();
$payment_button = array();
$default_country_array = array();
';
        $cfg .= "\n" . ' /* URLs fetched after checkout encoded by base64_encode */' . "\n";
        $cfg .= ' $curl_url = array(';
        $arr = array();
        foreach ($data as $key => $val) {
            if (strpos($key, 'curl_url_') !== false) {
                if (!empty($val)) {
                    $arr[] = "'" . base64_encode($val) . "'";
                }
            }
        }
        $arrt = implode(',', $arr);
        if (empty($arr)) {
            $arrt = '';
        }
        $cfg .= $arrt . ');' . "\n";
        $payment_info = array();
        $payment_button = array();
        // needs update:
        $langs = array();
        foreach ($langs as $l) {
            $langcfg[$l] = "";
        }
        $exts = $this->getExt();
        if (!class_exists('JFile')) {
            require JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'joomla' . DIRECTORY_SEPARATOR . 'filesystem' . DIRECTORY_SEPARATOR . 'file.php';
        }
        if (!class_exists('JFolder')) {
            require JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'joomla' . DIRECTORY_SEPARATOR . 'filesystem' . DIRECTORY_SEPARATOR . 'folder.php';
        }
        /*
        if (!empty($exts))
        foreach($exts as $ext)
        {
           if (isset($data['opext_'.$ext['name']]))
           {
             //if (!JFile::write($ext['path'].DS.'enabled.html')) 
               if (JFile::write($ext['path'].DS.'enabled.html', ' ')===false)
               {
                 $msg .= 'Cannot write to: '.$ext['path'].DS.'<br />';
               }
             
           }
           else 
            {
            if (file_exists($ext['path'].DS.'enabled.html'))
            {
              if (JFile::delete($ext['path'].DS.'enabled.html')===false)
              {
               $msg .= 'Delete file \'enabled.html\' manually: '.$ext['path'].DS.'enabled.html<br />';
              }
            }
            //else $msg .= 'Cannot find: '.$ext['path'].DS.'enabled.';
            }
           
        }
        */
        if (!class_exists('JFile')) {
            require JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'joomla' . DIRECTORY_SEPARATOR . 'filesystem' . DIRECTORY_SEPARATOR . 'file.php';
        }
        if (!class_exists('JFolder')) {
            require JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'joomla' . DIRECTORY_SEPARATOR . 'filesystem' . DIRECTORY_SEPARATOR . 'folder.php';
        }
        foreach ($data as $k => $d) {
            /*
             if (strpos($k, 'payment_contentid_')!==false)
             {
               $pid = str_replace('payment_contentid_', '', $k); 
               $ofolder = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'classes'.DS.'payment'.DS.'onepage';
               $filename = $ofolder.DS.$pid.'.part.html';
               if (is_numeric($pid))
               {
                $dt = JRequest::getVar('payment_content_'.$pid, '', 'post', 'string', JREQUEST_ALLOWRAW);
                $dt = str_replace('<p>', '', $dt); 
                $dt = str_replace('</p>', '<br />', $dt);
                if (!empty($dt))
                if (JFile::write($filename, $dt)===false)
                {
                 $msg .= 'Cannot save payment content to: '.$filename.'<br />';
                }
               }
             }
            */
            // ok we will add a default country for a lang
            if (strpos($k, 'op_lang_code_') !== false) {
                $id = str_replace('op_lang_code_', '', $k);
                if (!empty($data[$k]) && !empty($data['op_selc_' . $id])) {
                    $cfg .= '
$default_country_array["' . $data[$k] . '"] = "' . $data['op_selc_' . $id] . '"; 
';
                }
            }
            if (strpos($k, 'op_group_') !== false) {
                $id = str_replace('op_group_', '', $k);
                if (!empty($data[$k]) && !empty($data['op_group_' . $id])) {
                    if (!empty($data['op_lang_code2_' . $id])) {
                        $cfg .= '
$lang_shopper_group["' . $data['op_lang_code2_' . $id] . '"] = "' . $data['op_group_' . $id] . '"; 
';
                    }
                }
            }
            if (strpos($k, 'op_selc2_') !== false) {
                $id = str_replace('op_selc2_', '', $k);
                if (isset($data[$k]) && !empty($data['op_group_ip_' . $id])) {
                    if (isset($data['op_selc2_' . $id])) {
                        $cfg .= '
$lang_shopper_group_ip["' . $data['op_selc2_' . $id] . '"] = "' . $data['op_group_ip_' . $id] . '"; 
';
                    }
                }
            }
            if (strpos($k, 'hidepsid_') !== false) {
                $ida = explode('_', $k, 2);
                $ida = $ida[1];
                $id = $data[$k];
                //$id = $d;
                if ($id != 'del' && count($data["hidep_" . $ida]) > 0) {
                    $def = $data["hidepdef_" . $ida];
                    $cfg .= ' $hidep["' . $id . '"] = "';
                    if (isset($data["hidep_" . $ida])) {
                        foreach ($data["hidep_" . $ida] as $h) {
                            $cfg .= $h . '/' . $def . ',';
                        }
                    } else {
                    }
                    $cfg .= '";
';
                }
            }
            if (strpos($k, 'ONEPAGE_PAYMENT_EXTRA_INFO') !== false) {
                $arr = explode('_', $k);
                $lang = $arr[1];
                $id = $arr[count($arr) - 1];
                if (!isset($payment_info[$id])) {
                    $payment_info[$id] = $id;
                    $cfg .= '$payment_info["' . $id . '"] = JText::_("COM_ONEPAGE_PAYMENT_EXTRA_INFO_' . $id . '"); 
';
                }
            }
            if (strpos($k, 'ONEPAGE_PAYMENT_EXTRA_INFO_BUTTON') !== false) {
                $arr = explode('_', $k);
                $lang = $arr[1];
                $id = $arr[count($arr) - 1];
                if (!isset($payment_button[$id])) {
                    $payment_button[$id] = $id;
                    $cfg .= '$payment_button["' . $id . '"] = JText::_("COM_ONEPAGE_PAYMENT_EXTRA_INFO_BUTTON_' . $id . '"); 
';
                }
            }
            if (strpos($k, 'tid_') !== false && strpos($k, 'payment_contentid') === false) {
                /* we have a standard variable:
                	  tid_special_, tid_ai_, tid_num_, tid_back_,  tid_forward_
                	  tid_nummax_, tid_itemmax_
                	  tid_type_
                	  */
                if (!defined($k)) {
                    $this->setTemplateSetting($k, $data[$k]);
                    //echo 'template setting: '.$k.'value: '.$data[$k];
                    define($k, $data[$k]);
                }
                $a = explode('_', $k);
                if (count($a) == 3) {
                    $tid = $a[2];
                    $checkboxes = array('tid_special_', 'tid_ai_', 'tid_num_', 'tid_forward_', 'tid_back_', 'tid_enabled_', 'tid_foreign_', 'tid_email_', 'tid_autocreate_');
                    foreach ($checkboxes as $ch) {
                        if (!isset($data[$ch . $tid]) && !defined($ch . $tid)) {
                            $this->setTemplateSetting($ch . $tid, 0);
                            define($ch . $tid, '0');
                            //echo ':'.$ch.$tid.' val: 0';
                        }
                    }
                }
            }
        }
        $cfg .= '
if (defined(\'OPC_THEME_OVERRIDE\') && (constant(\'OPC_THEME_OVERRIDE\'))) include(OPC_THEME_OVERRIDE); 
else
if (!empty($selected_template) && (file_exists(JPATH_ROOT.DS."components".DS."com_onepage".DS."themes".DS.$selected_template.DS."overrides".DS."onepage.cfg.php")))
{
  define(\'OPC_THEME_OVERRIDE\', JPATH_ROOT.DS."components".DS."com_onepage".DS."themes".DS.$selected_template.DS."overrides".DS."onepage.cfg.php"); 
  include(JPATH_ROOT.DS."components".DS."com_onepage".DS."themes".DS.$selected_template.DS."overrides".DS."onepage.cfg.php");
 
}
else
if (!defined(\'OPC_THEME_OVERRIDE\'))
define(\'OPC_THEME_OVERRIDE\', false); 


';
        $conf_file = JPATH_ROOT . DS . "components" . DS . "com_onepage" . DS . "config" . DS . "onepage.cfg.php";
        $ret = true;
        if (!class_exists('JFile')) {
            require JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'joomla' . DIRECTORY_SEPARATOR . 'filesystem' . DIRECTORY_SEPARATOR . 'file.php';
        }
        if (!class_exists('JFolder')) {
            require JPATH_LIBRARIES . DIRECTORY_SEPARATOR . 'joomla' . DIRECTORY_SEPARATOR . 'filesystem' . DIRECTORY_SEPARATOR . 'folder.php';
        }
        if (JFile::write($conf_file, $cfg) === false) {
            $msg .= JText::_('COM_ONEPAGE_ACCESS_DENIED_CONFIG') . ' ' . $conf_file . '<br />';
            $ret = false;
            // lets test if it is php valid
        } else {
            //unset($disable_onepage);
            if (eval('?>' . file_get_contents($conf_file)) === false) {
                $msg .= JText::_('COM_ONEPAGE_CONFIG_VALIDATION_ERROR') . ' <br />';
                $ret = false;
                // we have a big problem here, generated file is not valid
                if (!JFile::copy(JPATH_ROOT . DS . "components" . DS . "com_onepage" . DS . "config" . DS . "onepage.cfg.php", JPATH_ROOT . DS . "components" . DS . "com_onepage" . DS . "config" . DS . "onepage.invalid.cfg.php")) {
                }
                if (!JFile::copy(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_onepage' . DS . 'default' . DS . 'onepage.cfg.php', JPATH_ROOT . DS . "components" . DS . "com_onepage" . DS . "config" . DS . "onepage.cfg.php")) {
                    $msg .= 'Copying of default onepage.cfg.php was not successfull <br />';
                }
            }
        }
        if (VmConfig::get('oncheckout_only_registered', 0)) {
            if (VmConfig::get('oncheckout_show_register', 0)) {
                define('VM_REGISTRATION_TYPE', 'NORMAL_REGISTRATION');
            } else {
                define('VM_REGISTRATION_TYPE', 'SILENT_REGISTRATION');
            }
        } else {
            if (VmConfig::get('oncheckout_show_register', 0)) {
                define('VM_REGISTRATION_TYPE', 'OPTIONAL_REGISTRATION');
            } else {
                define('VM_REGISTRATION_TYPE', 'NO_REGISTRATION');
            }
        }
        $reg_type = $data['opc_registraton_type'];
        $set = array();
        switch ($reg_type) {
            case 'NO_REGISTRATION':
                $set['oncheckout_only_registered'] = 0;
                $set['oncheckout_show_register'] = 0;
                break;
            case 'OPTIONAL_REGISTRATION':
                $set['oncheckout_only_registered'] = 0;
                $set['oncheckout_show_register'] = 1;
                break;
            case 'SILENT_REGISTRATION':
                $set['oncheckout_only_registered'] = 1;
                $set['oncheckout_show_register'] = 0;
                break;
            default:
                $set['oncheckout_only_registered'] = 1;
                $set['oncheckout_show_register'] = 1;
                break;
        }
        if (!empty($data['use_ssl'])) {
            $set['useSSL'] = 1;
        } else {
            $set['useSSL'] = 0;
        }
        if (!empty($data['full_tos_unlogged'])) {
            $set['oncheckout_show_legal_info'] = 1;
        } else {
            $set['oncheckout_show_legal_info'] = 0;
        }
        if (!empty($data['tos_logged']) && !empty($data['tos_unlogged'])) {
            $set['agree_to_tos_onorder'] = 1;
        } else {
            $set['agree_to_tos_onorder'] = 0;
        }
        if (!empty($data['op_disable_shipping'])) {
            $set['automatic_shipment'] = 0;
        }
        $this->updateVmConfig($set);
        /*
        require_once(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'helpers'.DS.'mini.php'); 
        
        $configm = OPCmini::getModel('Config'); 
        
            $c = VmConfig::get('coupons_enable', true); 
        VmConfig::set('coupons_enable', 10); 
        
        
        
        $test = VmConfig::get('coupons_enable'); 
        VmConfig::set('coupons_enable', $c); 
        
        
        if ($test != 10)
         {
           $isadmin =false; 
         }
         else $isadmin = true; 
         
         if ((method_exists('VmConfig', 'isAtLeastVersion')) || (!$isadmin))
         {
           $msg .= 'Notice: You are running an old version of Virtuemart or you are not logged in as shop Administrator. Some Virtuemart settings cannot be updated with OPC. Please update TOS, registration type, SSL in your virtuemart configuration. (oncheckout_show_register, oncheckout_only_registered, agree_to_tos_onorder, automatic_shipment, oncheckout_show_legal_info, useSSL)  '; 
           
           $isadmin = false; 
         }
        if ($isadmin)
        if (!$configm->store($set))
        {
        	//$msg .= 'Error saving virtuemart configuration'; 
        }
        
        VmConfig::loadConfig(true); 
        */
        if (empty($_SESSION['onepage_err'])) {
            $_SESSION['onepage_err'] = serialize($msg);
        } else {
            $_SESSION['onepage_err'] = serialize($msg . unserialize($_SESSION['onepage_err']));
        }
        return $ret;
    }
Example #2
0
 function confirmedOrder()
 {
     $cart =& self::$current_cart;
     $payment_id = $cart->virtuemart_paymentmethod_id;
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     //Just to prevent direct call
     if ($cart->_dataValidated && $cart->_confirmDone) {
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
         $orderModel = OPCmini::getModel('Orders');
         $this->getModifiedData($cart);
         if (!empty($delivery_date)) {
             $cart->delivery_date = $delivery_date;
         }
         $orderID = $orderModel->createOrderFromCart($cart);
         $this->getModifiedData($cart, true);
         $msgq1 = JFactory::getApplication()->get('messageQueue', array());
         $msgq2 = JFactory::getApplication()->get('_messageQueue', array());
         $op_disable_shipping = OPCloader::getShippingEnabled($cart);
         if ($op_disable_shipping) {
             //$q = 'update #__virtuemart_orders set
         }
         if (empty($orderID)) {
             $mainframe = JFactory::getApplication();
             $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)));
         }
         $cart->virtuemart_order_id = $orderID;
         $order = $orderModel->getOrder($orderID);
         self::$new_order =& $order;
         $this->getModifiedOrder($order, $cart);
         // $GLOBALS['is_dup']
         if (!empty($orderID)) {
             if (!empty($GLOBALS['is_dup']) && is_numeric($GLOBALS['is_dup'])) {
                 $dbj = JFactory::getDBO();
                 $q = "update #__virtuemart_orders SET virtuemart_user_id = '" . $this->getEscaped($dbj, $GLOBALS['is_dup']) . "' where virtuemart_order_id = '" . $this->getEscaped($dbj, $orderID) . "' limit 1";
                 $dbj->setQuery($q);
                 $dbj->query();
                 $dbj = JFactory::getDBO();
                 $q = "update #__virtuemart_order_userinfos SET virtuemart_user_id = '" . $this->getEscaped($dbj, $GLOBALS['is_dup']) . "' where virtuemart_order_id = '" . $this->getEscaped($dbj, $orderID) . "' limit 2";
                 $dbj->setQuery($q);
                 $dbj->query();
                 $e = $dbj->getErrorMsg();
             } else {
                 if (!empty($GLOBALS['opc_new_user']) && is_numeric($GLOBALS['opc_new_user'])) {
                     $dbj = JFactory::getDBO();
                     $q = "update #__virtuemart_orders SET virtuemart_user_id = '" . $this->getEscaped($dbj, $GLOBALS['opc_new_user']) . "' where virtuemart_order_id = '" . $this->getEscaped($dbj, $orderID) . "' limit 1";
                     $dbj->setQuery($q);
                     $dbj->query();
                     $dbj = JFactory::getDBO();
                     $q = "update #__virtuemart_order_userinfos SET virtuemart_user_id = '" . $this->getEscaped($dbj, $GLOBALS['opc_new_user']) . "' where virtuemart_order_id = '" . $this->getEscaped($dbj, $orderID) . "' limit 2";
                     $dbj->setQuery($q);
                     $dbj->query();
                     $e = $dbj->getErrorMsg();
                 }
             }
         }
         //opc_new_user
         if (empty($order['details']['ST']->email) && !empty($order['details']['BT']->email)) {
             $order['details']['ST']->email = $order['details']['BT']->email;
         }
         // 			$cart = $this->getCart();
         if (isset($order['details']['BT'])) {
             $this->doCurl($order['details']['BT']);
         }
         $dispatcher = JDispatcher::getInstance();
         // 			$html="";
         if ($order['details']['BT']->order_total <= 0) {
             $no_payment = true;
         } else {
             $no_payment = false;
         }
         if (empty($op_disable_shipping)) {
             JPluginHelper::importPlugin('vmshipment');
         }
         JPluginHelper::importPlugin('vmcustom');
         if (empty($no_payment)) {
             JPluginHelper::importPlugin('vmpayment');
         }
         JPluginHelper::importPlugin('vmcustom');
         JPluginHelper::importPlugin('vmcalculation');
         $session = JFactory::getSession();
         $return_context = $session->getId();
         //end OPC email mod
         ob_start();
         $order = $orderModel->getOrder($orderID);
         if ($order['details']['BT']->order_status != $zero_total_status) {
             if ($order['details']['BT']->order_total <= 0) {
                 require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
                 $modelOrder = OPCmini::getModel('orders');
                 $order['order_status'] = $zero_total_status;
                 $order['customer_notified'] = 1;
                 $order['comments'] = '';
                 $modelOrder->updateStatusForOneOrder($orderID, $order, true);
                 //$order['paymentName']= $dbValues['payment_name'];
                 //We delete the old stuff
                 $cart->emptyCart();
             }
         }
         $output = ob_get_clean();
         //$returnValues = $dispatcher->trigger('plgVmConfirmedOrder', array($cart, $order));
         // pairs the cookie with the database
         $returnValues = $dispatcher->trigger('plgOpcOrderCreated', array($cart, $order));
         // runs shipping confirm as first and payment as last
         $returnValues = $dispatcher->trigger('plgVmConfirmedOrderOPC', array('shipment', $cart, $order));
         $returnValues = $dispatcher->trigger('plgVmConfirmedOrderOPC', array('calculation', $cart, $order));
         $returnValues = $dispatcher->trigger('plgVmConfirmedOrderOPC', array('custom', $cart, $order));
         $except = array('shipment', 'custom', 'calculation');
         $returnValues = $dispatcher->trigger('plgVmConfirmedOrderOPCExcept', array($except, $cart, $order));
         //OPC: maybe we want to send emil before a redirect:
         if (!empty($send_pending_mail)) {
             if (!class_exists('shopFunctionsF')) {
                 require JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
             }
             //Important, the data of the order update mails, payments and invoice should
             //always be in the database, so using getOrder is the right method
             require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
             $orderModel = OPCmini::getModel('orders');
             //$order = $orderModel->getOrder($orderID);
             $payment_name = $shipment_name = '';
             $op_disable_shipping = OPCloader::getShippingEnabled($cart);
             $msgqx1 = JFactory::getApplication()->get('messageQueue', array());
             $msgqx2 = JFactory::getApplication()->get('_messageQueue', array());
             $msgqx3 = JFactory::getApplication()->getMessageQueue();
             if (!class_exists('vmPSPlugin')) {
                 require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
             }
             if (empty($op_disable_shipping)) {
                 JPluginHelper::importPlugin('vmshipment');
             }
             if (empty($no_payment)) {
                 JPluginHelper::importPlugin('vmpayment');
             }
             $dispatcher = JDispatcher::getInstance();
             if (empty($op_disable_shipping)) {
                 $returnValues = $dispatcher->trigger('plgVmonShowOrderPrintShipment', array($order['details']['BT']->virtuemart_order_id, $order['details']['BT']->virtuemart_shipmentmethod_id, &$shipment_name));
             }
             if (empty($no_payment)) {
                 $returnValues = $dispatcher->trigger('plgVmonShowOrderPrintPayment', array($order['details']['BT']->virtuemart_order_id, $order['details']['BT']->virtuemart_paymentmethod_id, &$payment_name));
             }
             $order['shipmentName'] = $shipment_name;
             if (empty($no_payment)) {
                 $order['paymentName'] = $payment_name;
             } else {
                 $order['paymentName'] = '';
             }
             $vars['orderDetails'] = $order;
             if (!isset($vars['newOrderData'])) {
                 $vars['newOrderData'] = array();
             }
             $vars['newOrderData']['customer_notified'] = 1;
             $vars['url'] = 'url';
             $vars['doVendor'] = false;
             if (!empty($order['details']['BT']->virtuemart_vendor_id)) {
                 $virtuemart_vendor_id = $order['details']['BT']->virtuemart_vendor_id;
             } else {
                 $virtuemart_vendor_id = 1;
             }
             require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
             $vendorModel = OPCmini::getModel('vendor');
             $vendor = $vendorModel->getVendor($virtuemart_vendor_id);
             $vars['vendor'] = $vendor;
             $vendorEmail = $vendorModel->getVendorEmail($virtuemart_vendor_id);
             if (empty($vendorEmail)) {
                 $db = JFactory::getDBO();
                 $query = 'SELECT * FROM `#__virtuemart_vmusers`';
                 $db->setQuery($query);
                 $res = $db->loadAssocList();
                 $query = 'SELECT ju.email FROM `#__virtuemart_vmusers` as vmu, `#__users` as ju WHERE `virtuemart_vendor_id`=' . (int) $virtuemart_vendor_id . ' and ju.id = vmu.virtuemart_user_id and vmu.user_is_vendor = 1 limit 0,1';
                 $db->setQuery($query);
                 $vendorEmail = $db->loadResult();
             }
             $vars['vendorEmail'] = $vendorEmail;
             // Send the email
             if (file_exists(JPATH_VM_SITE . DS . 'views' . DS . 'invoice' . DS . 'view.html.php')) {
                 if (OPCcheckout::renderMail('invoice', $vendorEmail, $vars, null, true, false)) {
                     //ok
                 }
                 $x = JFactory::getApplication()->set('messageQueue', $msgqx1);
                 $x = JFactory::getApplication()->set('_messageQueue', $msgqx2);
                 if (OPCJ3) {
                     if (class_exists('ReflectionClass')) {
                         $a = JFactory::getApplication();
                         $reflectionClass = new ReflectionClass($a);
                         $property = $reflectionClass->getProperty('_messageQueue');
                         $property->setAccessible(true);
                         $property->setValue($a, $msgqx3);
                         $x = JFactory::getApplication()->getMessageQueue();
                     }
                 }
             }
         }
         /*
         jimport( 'joomla.plugin.helper' );
         $plugin = JPluginHelper::getPlugin('vmpayment', 'opctracking');
         if (!empty($plugin))
         {
            $opctracking = true; 
         }
         else 
         {
            $opctracking = false; 
         }
         */
         //$html = JRequest::getVar('html', JText::_('COM_VIRTUEMART_ORDER_PROCESSED'), null, 'string', JREQUEST_ALLOWRAW);
         $html = JRequest::getVar('html', JText::_('COM_VIRTUEMART_ORDER_PROCESSED'), 'default', 'STRING', JREQUEST_ALLOWRAW);
         $app = JFactory::getApplication();
         require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'config.php';
         $utm_p_load = false;
         $default = array();
         $utm_p = OPCConfig::getValue('opc_config', 'utm_payments', 0, $default, false, false);
         if (!empty($payment_id)) {
             if (in_array($payment_id, $utm_p)) {
                 $utm_p_load = true;
             }
         }
         if (method_exists($app, 'input')) {
             $html2 = $app->input->get('html', JText::_('COM_VIRTUEMART_ORDER_PROCESSED'), 'RAW');
             if ($utm_p_load) {
                 $html2 = str_replace('&amp;view=', '&amp;utm_nooverride=1&view=', $html2);
                 $html2 = str_replace('&view=', '&utm_nooverride=1&view=', $html2);
                 $app->input->set('html', $html2);
             }
         } else {
             $html2 = JRequest::getVar('html', JText::_('COM_VIRTUEMART_ORDER_PROCESSED'), 'default', 'STRING', JREQUEST_ALLOWRAW);
             if ($utm_p_load) {
                 $html2 = str_replace('&view=pluginresponse', '&utm_nooverride=1&view=pluginresponse', $html2);
                 $html2 = str_replace('&amp;view=pluginresponse', '&amp;utm_nooverride=1&amp;view=pluginresponse', $html2);
                 JRequest::setVar('html', $html2);
             }
         }
         if ($html != $html2) {
             $output .= $html2;
         }
         $output .= $html;
         ob_start();
         if ($order['details']['BT']->order_total <= 0) {
             $cart->emptyCart();
         }
         $output .= ob_get_clean();
         $x = JFactory::getApplication()->set('messageQueue', $msgq1);
         $x = JFactory::getApplication()->set('_messageQueue', $msgq2);
         if (!empty($output)) {
             return $output;
         }
         // may be redirect is done by the payment plugin (eg: paypal)
         // if payment plugin echos a form, false = nothing happen, true= echo form ,
         // 1 = cart should be emptied, 0 cart should not be emptied
     }
 }
Example #3
0
 function checkout()
 {
     /*
     $savedGET = $_GET; 
     $savedPOST = $_POST; 
     $savedREQUEST = $_REQUEST; 
     */
     // before we do anything, let's check captcha:
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (!class_exists('OPCLang')) {
         require JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_onepage' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'language.php';
     }
     OPCLang::loadLang();
     //mobile handling:
     if (!defined('OPC_DETECTED_DEVICE')) {
         if (class_exists('OPCplugin')) {
             OPCplugin::detectMobile();
         }
     }
     if (!isset($opc_memory)) {
         $opc_memory = '128M';
     }
     ini_set('memory_limit', $opc_memory);
     ini_set('error_reporting', 0);
     // disable error reporting for ajax:
     error_reporting(0);
     $logged = false;
     if (JFactory::getUser()->guest) {
     } else {
         $logged = true;
     }
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (!empty($enable_captcha_logged) && $logged || !empty($enable_captcha_unlogged) && !$logged) {
         $this->checkOPCCaptcha();
     }
     if (!class_exists('VmConfig')) {
         require JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php';
     }
     VmConfig::loadConfig();
     // since vm2.0.21a we need to load the language files here
     OPCLang::loadLang();
     $this->prepareFields();
     // fedex multibox fix:
     // register user first:
     $reg = JRequest::getVar('register_account');
     if (empty($reg)) {
         $reg = false;
     } else {
         $reg = true;
     }
     // ENABLE ONLY BUSINESS REGISTRATION WHEN REGISTER_ACCOUNT IS SET AS BUSINESS FIELD
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
     $is_business = JRequest::getVar('opc_is_business', 0);
     // we need to alter shopper group for business when set to:
     $is_business = JRequest::getVar('opc_is_business', 0);
     if (!empty($business_fields)) {
         if (!$is_business) {
             // manage required business fields when not business selected:
             foreach ($business_fields as $fn) {
                 /*
                 	$x1 = JRequest::getVar($fn); 
                 	if (empty($x1))
                 	JRequest::setVar($fn, '_'); 
                 
                 	$x1 = JRequest::getVar('shipto_'.$fn); 
                 	if (empty($x1))
                 	JRequest::setVar('shipto_'.$fn, '_'); 
                 */
             }
         }
     }
     if ($reg) {
         if (!empty($business_fields)) {
             if (in_array('register_account', $business_fields)) {
                 if (empty($is_business)) {
                     $reg = false;
                 }
             }
         }
     }
     //if (!class_exists('VirtueMartControllerUser'))
     //require_once(JPATH_SITE.DS.'components'.DS.'com_virtuemart'.DS.'controllers'.DS.'user.php');
     //$userC = new VirtueMartControllerUser();
     $cart = VirtueMartCart::getCart(false);
     $mainframe = Jfactory::getApplication();
     $virtuemart_currency_id = $mainframe->getUserStateFromRequest("virtuemart_currency_id", 'virtuemart_currency_id', JRequest::getInt('virtuemart_currency_id'));
     $cart->paymentCurrency = $virtuemart_currency_id;
     require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'shoppergroups.php';
     OPCShopperGroups::setShopperGroupsController($cart);
     if (method_exists($cart, 'prepareCartData')) {
         $cart->prepareCartData(false);
     }
     if (!isset($cart->vendorId)) {
         $cart->vendorId = 1;
     }
     $payment_id = $cart->virtuemart_paymentmethod_id = JRequest::getInt('virtuemart_paymentmethod_id', '');
     $cart->virtuemart_shipmentmethod_id = JRequest::getInt('virtuemart_shipmentmethod_id', '');
     $coupon = JRequest::getVar('opc_coupon_code_returned', '');
     if (!empty($coupon) && empty($cart->couponCode)) {
         $cart->couponCode = $coupon;
     }
     $this->runExt($cart);
     if (method_exists($cart, 'prepareCartProducts')) {
         $cart->prepareCartProducts();
     }
     $this->setCartAddress($cart);
     $this->setExtAddress($cart, false);
     $order_language = JFactory::getLanguage()->getTag();
     JRequest::setVar('order_language', $order_language);
     // k2 mod with recaptcha enabled
     $session = JFactory::getSession();
     $orig = $session->get('socialConnectData');
     $session->set('socialConnectData', true);
     // end p1 k2 mod with recaptcha enabled
     //$this->setShopperGroups($cart);
     $data = JRequest::get('post');
     $data['quite'] = true;
     //suppress messages from thsi function
     $this->saveData($cart, $reg, false, $data);
     if (!empty($allow_sg_update)) {
         $this->storeShopperGroup($data, true);
     }
     $userModel = OPCmini::getModel('user');
     if (method_exists($userModel, 'getCurrentUser')) {
         $user = $userModel->getCurrentUser();
         self::$shopper_groups = $user->shopper_groups;
     }
     // k2 mod with recaptcha enabled
     if (empty($orig)) {
         $session->clear('socialConnectData');
     } else {
         $session->set('socialConnectData', $orig);
     }
     // end p2 k2 mod with recaptcha enabled
     if (!class_exists('VirtueMartControllerCartOpc')) {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'overrides' . DS . 'cartcontroller.php';
     }
     $cartcontroller = new VirtueMartControllerCartOpc();
     $po = JRequest::getVar('socialNumber', '');
     if (method_exists($cartcontroller, 'setshipment')) {
         $cartcontroller->setshipment($cart);
     }
     // fix fedex multibox
     $saved_bt = $cart->BT;
     if (isset($_SESSION['load_fedex_prices_from_session'])) {
         unset($_SESSION['load_fedex_prices_from_session']);
     }
     if (method_exists($cartcontroller, 'setpayment')) {
         $cartcontroller->setpayment($cart);
     }
     if ($cart->BT != $saved_bt) {
         if (empty($cart->ST) || $cart->STsameAsBT) {
             $cart->STsameAsBT = 0;
             $cart->ST = $saved_bt;
             $text = JText::_('COM_ONEPAGE_USER_ENTERED_ADDRESS');
             if ($text == 'COM_ONEPAGE_USER_ENTERED_ADDRESS') {
                 $text = 'User Entered Address (Ship To)';
             }
             $cart->ST['address_type_name'] = $text;
             $cart->BT['address_type_name'] = JText::_('COM_ONEPAGE_ADDRESS_HAD_CHANGED_NAME');
             //$cart->BT = $saved_bt;
         } else {
             if ($cart->ST != $saved_bt) {
                 $address_changed = JText::_('COM_ONEPAGE_ADDRESS_HAD_CHANGED');
                 $mainframe = JFactory::getApplication();
                 $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart'), OPCLang::_('COM_ONEPAGE_ADDRESS_HAD_CHANGED'));
                 return;
             } else {
                 // $cart->BT = $saved_bt;
             }
         }
     }
     // security:
     JRequest::setVar('html', '');
     $post = JRequest::get('post');
     if (empty($cart->BT)) {
     }
     // fix the customer comment
     // $cart->customer_comment = JRequest::getVar('customer_comment', $cart->customer_comment);
     $cc = JRequest::getVar('customer_comment', '');
     $cc2 = JRequest::getVar('customer_note', '');
     if (empty($cart->customer_comment)) {
         $cart->customer_comment = $cc2 . $cc;
     } else {
         $cart->customer_comment = $cc2 . $cc;
     }
     JRequest::setVar('customer_comment', $cart->customer_comment);
     JRequest::setVar('customer_note', $cart->customer_comment);
     if (defined('VM_VERSION') && VM_VERSION >= 3) {
         $cart->BT['customer_note'] = $cart->customer_comment;
     }
     $OPCcheckout = new OPCcheckout($cart);
     $loader = new OPCloader();
     OPCcheckout::$current_cart =& $cart;
     $OPCcheckout->checkoutData(false);
     if ($cart->_dataValidated) {
         $cart->_confirmDone = true;
         $order = null;
         $output = $OPCcheckout->confirmedOrder();
         //$cart, $this, $order);
         /*
         jimport( 'joomla.plugin.helper' );
         $plugin = JPluginHelper::getPlugin('vmpayment', 'opctracking');
         if (!empty($plugin))
         {
            $opctracking = true; 
         }
         else 
         {
            $opctracking = false; 
         }
         */
         require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'config.php';
         $utm_p_load = false;
         $default = array();
         $utm_p = OPCConfig::getValue('opc_config', 'utm_payments', 0, $default, false, false);
         if (!empty($payment_id)) {
             if (in_array($payment_id, $utm_p)) {
                 $utm_p_load = true;
             }
         }
         if ($utm_p_load) {
             $output = str_replace('&view=pluginresponse', '&utm_nooverride=1&view=pluginresponse', $output);
             $output = str_replace('&amp;view=pluginresponse', '&amp;utm_nooverride=1&amp;view=pluginresponse', $output);
         }
         require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'removemsgs.php';
         OPCremoveMsgs::removeMsgs($cart);
         $order =& OPCcheckout::$new_order;
         $session = JFactory::getSession();
         if (!empty($order)) {
             if ($order['details']['BT']->order_total <= 0) {
                 $dispatcher = JDispatcher::getInstance();
                 $returnValues = $dispatcher->trigger('registerOrderAttempt', array(&$order));
                 $cart->emptyCart();
             }
         }
     } else {
         $mainframe = JFactory::getApplication();
         $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart'), 'Captcha: ' . OPCLang::_('COM_VIRTUEMART_CART_CHECKOUT_DATA_NOT_VALID'));
     }
     // some extensions somehow reset the language, and we need to set it to the proper one:
     $lang = JFactory::getLanguage();
     $tag = $lang->getTag();
     $filename = 'com_virtuemart';
     $lang->load($filename, JPATH_ADMINISTRATOR, $tag, true);
     $lang->load($filename, JPATH_SITE, $tag, true);
     //$post = JRequest::get('post');
     $mainframe = JFactory::getApplication();
     $pathway = $mainframe->getPathway();
     $document = JFactory::getDocument();
     //  $html = JRequest::getVar('html', OPCLang::_('COM_VIRTUEMART_ORDER_PROCESSED'), 'post', 'STRING', JREQUEST_ALLOWRAW);
     $document->setTitle(OPCLang::_('COM_VIRTUEMART_CART_THANKYOU'));
     $cart->setCartIntoSession();
     // now the plugins should have already loaded the redirect html
     // we can safely
     $virtuemart_order_id = $cart->virtuemart_order_id;
     JRequest::setVar('view', 'cart');
     $_REQUEST['view'] = 'cart';
     $_POST['view'] = 'cart';
     $_GET['view'] = 'cart';
     $view = $this->getView('cart', 'html');
     $currencyDisplay = CurrencyDisplay::getInstance($cart->pricesCurrency);
     $view->currencyDisplay = $currencyDisplay;
     $view->addTemplatePath(JPATH_VM_SITE . DS . 'views' . DS . 'cart' . DS . 'tmpl' . DS);
     $view->cart = $cart;
     $display_title = JRequest::getVar('display_title', true);
     $view->display_title = $display_title;
     $view->setLayout('order_done');
     $view->assignRef('html', $output);
     // commented for 2.0.22a
     //JRequest::setVar('html', $output);
     //$view->html = $output;
     // Display it all
     ob_start();
     $view->display();
     $html1 = ob_get_clean();
     $items = $pathway->getPathwayNames();
     $skipp = false;
     foreach ($items as $i) {
         if ($i == OPCLang::_('COM_VIRTUEMART_CART_THANKYOU')) {
             $skipp = true;
         }
     }
     if (!$skipp) {
         $pathway->addItem(OPCLang::_('COM_VIRTUEMART_CART_THANKYOU'));
     }
     if (empty($html1)) {
         $html1 = $output;
     }
     JRequest::setVar('view', 'opccart');
     JRequest::setVar('contoller', 'opccart');
     $html2 = '';
     if (!empty($append_details)) {
         // ok, lets try to alter it with the order details
         JRequest::setVar('order_pass', $order['details']['BT']->order_pass);
         JRequest::setVar('order_number', $order['details']['BT']->order_number);
         JRequest::setVar('virtuemart_order_id', $order['details']['BT']->virtuemart_order_id);
         //JRequest::setVar('tmpl', 'component');
         $html2 = $this->getVMView('orders', array(), 'orders', 'details', 'html');
     }
     $allhtml = $html1 . $html2;
     $this->runExtAfter($allhtml);
     echo $allhtml;
     JRequest::setVar('html', '');
     JRequest::setVar('html', $allhtml);
     JRequest::setVar('view', 'cart');
     $_REQUEST['view'] = 'cart';
     $_POST['view'] = 'cart';
     $_GET['view'] = 'cart';
     if (!empty($theme_fix1)) {
         JRequest::setVar('layout', 'order_done');
     }
     /*
     	  	$_GET = $savedGET; 
     	    $_POST = $savedPOST; 
     	    $_REQUEST = $savedREQUEST; 
     */
     return;
 }
Example #4
0
	<tr>
	    <td class="key">
	     <label for="utm_payment" ><?php 
    echo JText::_('COM_ONEPAGE_UTM_PAYMENT_LABEL');
    ?>
</label>
	    </td>
	    <td colspan="1" >
		<select id="utm_payment" name="utm_payment[]" class="vm-chzn-select" multiple="multiple" data-placeholder="<?php 
    echo JText::_('COM_VIRTUEMART_PAYMENTMETHOD_S');
    ?>
"  style="min-width: 150px; ">
		
		<?php 
    $default = array();
    $utm_p = OPCConfig::getValue('opc_config', 'utm_payments', 0, $default, false, false);
    foreach ($this->pms as $p) {
        ?>
		 <option value=<?php 
        echo '"' . $p['payment_method_id'] . '" ';
        if (in_array($p['payment_method_id'], $utm_p)) {
            echo 'selected="selected" ';
        }
        ?>
><?php 
        echo $p['payment_method_name'];
        ?>
</option>
		 <?php 
    }
    ?>