Exemplo n.º 1
0
 /**
  * constructs a VmModel
  * setMainTable defines the maintable of the model
  * @author Max Milbers
  */
 function __construct()
 {
     parent::__construct('virtuemart_userfield_id');
     $this->setMainTable('userfields');
     $this->setToggleName('required');
     $this->setToggleName('cart');
     $this->setToggleName('shipment');
     $this->setToggleName('account');
     // Instantiate the Helper class
     self::$_cache_ordered = null;
     self::$_cache_named = array();
     $this->_selectedOrdering = 'ordering';
     $this->_selectedOrderingDir = 'ASC';
     VmConfig::loadJLang('com_virtuemart_shoppers', TRUE);
 }
Exemplo n.º 2
0
 /**
  * constructs a VmModel
  * setMainTable defines the maintable of the model
  * @author Max Milbers
  */
 function __construct()
 {
     parent::__construct('virtuemart_userfield_id');
     $this->setMainTable('userfields');
     $this->setToggleName('required');
     $this->setToggleName('registration');
     $this->setToggleName('shipment');
     $this->setToggleName('account');
     // Instantiate the Helper class
     $this->_params = new ParamHelper();
     self::$_cache_ordered = null;
     self::$_cache_named = array();
     // Form fields that must be translated to parameters
     $this->reqParam = array('age_verification' => 'minimum_age', 'euvatid' => 'virtuemart_shoppergroup_id', 'webaddress' => 'webaddresstype');
     $this->_selectedOrdering = 'ordering';
     $this->_selectedOrderingDir = 'ASC';
 }
Exemplo n.º 3
0
 public static function getRegistrationHhtml(&$obj, &$OPCloader)
 {
     // if (!empty($no_login_in_template)) return "";
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (!class_exists('VirtueMartCart')) {
         require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php';
     }
     if (!empty($obj->cart)) {
         $cart =& $obj->cart;
     } else {
         $cart = VirtueMartCart::getCart();
     }
     $type = 'BT';
     // for unlogged
     $virtuemart_userinfo_id = 0;
     $new = 1;
     $fieldtype = $type . 'address';
     /*
     if (method_exists($cart, 'prepareAddressDataInCart'))
     $cart->prepareAddressDataInCart($type, $new);
     */
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php';
     OPCUserFields::populateCart($cart, $type, true);
     /*
     if (method_exists($cart, 'prepareAddressFieldsInCart'))
     $cart->prepareAddressFieldsInCart();
     */
     OPCloader::setRegType();
     if (!class_exists('VirtuemartModelUserfields')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'userfields.php';
     }
     $corefields = VirtueMartModelUserfields::getCoreFields();
     $userFields = $cart->{$fieldtype};
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
     $layout = 'default';
     foreach ($userFields['fields'] as $key => $uf) {
         if (!in_array($key, $corefields) || $key == 'agreed') {
             unset($userFields['fields'][$key]);
             continue;
         }
         if (!empty($opc_email_in_bt) || $OPCloader->isNoLogin() || $OPCloader->isNoLogin()) {
             if ($userFields['fields'][$key]['name'] == 'email') {
                 unset($userFields['fields'][$key]);
                 continue;
             }
         }
         if ($key == 'email') {
             $user = JFactory::getUser();
             $uid = $user->get('id');
             // user is logged, but does not have a VM account
             if (!OPCloader::logged($cart) && !empty($uid)) {
                 // the user is logged in only in joomla, but does not have an account with virtuemart
                 $userFields['fields'][$key]['formcode'] = str_replace('/>', ' readonly="readonly" />', $userFields['fields'][$key]['formcode']);
             }
         }
     }
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php';
     OPCUserFields::getUserFields($userFields, $OPCloader, $cart);
     // lets move email to the top
     $copy = array();
     // we will reorder the fields, so the email is first when used as username
     $u = OPCLang::_('COM_VIRTUEMART_REGISTER_UNAME');
     //$e = OPCLang::_('COM_VIRTUEMART_USER_FORM_EMAIL');
     // disable when used for logged in
     if (!empty($userFields['fields'])) {
         /*
              if (empty($opc_email_in_bt) && (!empty($double_email)))
         {
           // email is in BT, let's check for double mail
         		
         		$email2 = $userFields['fields']['email'];
         		$email2['name'] = 'email2'; 
         		$title = OPCLang::_('COM_ONEPAGE_EMAIL2'); 
         		if ($title != 'COM_ONEPAGE_EMAIL2')
         		$email2['title'] = $title;
         		$email2['formcode'] = str_replace('"email', '"email2', $email2['formcode']); 
         		$email2['formcode'] = str_replace('id=', ' onblur="javascript: doublemail_checkMail();" id=', $email2['formcode']);
         		
         		$h = '<span style="display: none; position: relative; color: red; font-size: 10px; background: none; border: none; padding: 0; margin: 0;" id="email2_info" class="email2_class">';
         		$emailerr = OPCLang::_('COM_ONEPAGE_EMAIL_DONT_MATCH');
         		if ($emailerr != 'COM_ONEPAGE_EMAIL_DONT_MATCH')
         		$h .= $emailerr;
         		else $h .= "Emails don't match!";
         		$h .= '</span>';
         		$email2['formcode'] .= $h;
         }
         */
         /*
         	 if (!empty($opc_check_username))
         	 if ((!OPCloader::logged($cart)) && (empty($uid)))
         	 if (!empty($userFields['fields']['username']))
         {
          
            $un = $userFields['fields']['username']['formcode']; 
         		 $un = str_replace('id=', ' onblur="javascript: Onepage.username_check(this);" id=', $un);
         		 $un .=  '<span class="username_already_exist" style="display: none; position: relative; color: red; font-size: 10px; background: none; border: none; padding: 0; margin: 0;" id="username_already_exists">';
         		 $un .= OPCLang::sprintf('COM_VIRTUEMART_STRING_ERROR_NOT_UNIQUE_NAME', $u); 
         		 $un .= '</span>'; 
         		 $userFields['fields']['username']['formcode'] = $un; 
         }
         */
         /*
         if (!empty($opc_check_email))
         if ((!OPCloader::logged($cart)) && (empty($uid)))
         if (!empty($userFields['fields']['email']))
         {
         
            $un = $userFields['fields']['email']['formcode']; 
         		 $un = str_replace('id=', ' onblur="javascript: Onepage.email_check(this);" id=', $un);
         		 $un .=  '<span class="email_already_exist" style="display: none; position: relative; color: red; font-size: 10px; background: none; border: none; padding: 0; margin: 0;" id="email_already_exists">';
         		 $un .= OPCLang::sprintf('COM_ONEPAGE_EMAIL_ALREADY_EXISTS', OPCLang::_('COM_VIRTUEMART_USER_FORM_EMAIL')); 
         		 $un .= '</span>'; 
         		 $userFields['fields']['email']['formcode'] = $un; 
         }
         */
     }
     /*
     	$OPCloader->reorderFields($userFields); 
     */
     if (count($userFields['fields']) === 0) {
         // no fields found
         return '';
     }
     //if (empty($opc_email_in_bt) && (!empty($double_email)))
     //$OPCloader->insertAfter($userFields['fields'], 'email', $email2, 'email2');
     $vars = array('rowFields' => $userFields, 'cart' => $obj, 'is_registration' => true);
     $html = $OPCloader->fetch($OPCloader, 'list_user_fields.tpl', $vars);
     $html = str_replace("'password'", "'opc_password'", $html);
     $html = str_replace("password2", "opc_password2", $html);
     if (strpos($html, 'email_field') !== false) {
         $html .= '<input type="hidden" name="email_in_registration" value="1" id="email_in_registration" />';
     } else {
         $html .= '<input type="hidden" name="email_in_registration" value="0" id="email_in_registration" />';
     }
     return $html;
 }
 * @package	VirtueMart
 * @subpackage User
 * @author Oscar van Eijk
 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * 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.
 * @version $Id$
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
$typefields = array('corefield', 'billto');
$corefields = VirtueMartModelUserfields::getCoreFields();
foreach ($typefields as $typefield) {
    $_k = 0;
    $_set = false;
    $_table = false;
    $_hiddenFields = '';
    //             for ($_i = 0, $_n = count($this->userFields['fields']); $_i < $_n; $_i++) {
    for ($_i = 0, $_n = count($this->userFields['fields']); $_i < $_n; $_i++) {
        // Do this at the start of the loop, since we're using 'continue' below!
        if ($_i == 0) {
            $_field = current($this->userFields['fields']);
        } else {
            $_field = next($this->userFields['fields']);
        }
        if ($_field['hidden'] == true) {
            $_hiddenFields .= $_field['formcode'] . "\n";
Exemplo n.º 5
0
 function getBTfields(&$obj, $unlg = false, $no_wrapper = false)
 {
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     $default_shipping_country = OPCloader::getDefaultCountry($cart);
     // $default_shipping_country
     $islogged = OPCloader::logged($obj->cart);
     if ($islogged && empty($unlg)) {
         return $this->getUserInfoBT($obj);
     } else {
         if (!class_exists('VirtueMartCart')) {
             require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php';
         }
         if (!empty($obj->cart)) {
             $cart =& $obj->cart;
         } else {
             $cart = VirtueMartCart::getCart();
         }
         $type = 'BT';
         $this->address_type = 'BT';
         // for unlogged
         $virtuemart_userinfo_id = 0;
         $this->virtuemart_userinfo_id = 0;
         $new = 1;
         if (!empty($unlg)) {
             $new = false;
         }
         $fieldtype = $type . 'address';
         if (empty($cart->BT)) {
             $cart->BT = array();
         }
         $user = JFactory::getUser();
         $uid = $user->get('id');
         // PPL Express address:
         $moveBT = false;
         $count = 0;
         if (!empty($cart->savedST)) {
             if (!$islogged) {
                 foreach ($cart->savedST as $key => $val) {
                     if ($key == 'virtuemart_country_id') {
                         continue;
                     }
                     if ($key == 'virtuemart_state_id') {
                         continue;
                     }
                     if (substr($key, 0, 7) === 'shipto_') {
                         continue;
                     }
                     if (empty($cart->BT[$key]) && !empty($val)) {
                         $count++;
                     } else {
                         if (!empty($cart->BT[$key]) && $val != $cart->BT[$key]) {
                             $count--;
                         }
                     }
                 }
                 if ($count > 0) {
                     if ($cart->savedST['virtuemart_country_id'] != $cart->BT['virtuemart_country_id']) {
                         $cart->BT['virtuemart_state_id'] = 0;
                     }
                     foreach ($cart->savedST as $key => $val) {
                         if (!empty($val)) {
                             $cart->BT[$key] = $val;
                         }
                     }
                 }
             }
         }
         if (empty($cart->BT['virtuemart_country_id'])) {
             if (!empty($default_shipping_country) && is_numeric($default_shipping_country)) {
                 $cart->BT['virtuemart_country_id'] = $default_shipping_country;
             } else {
                 // let's set a default country
                 $vendor = $this->getVendorInfo($cart);
                 $cart->BT['virtuemart_country_id'] = $vendor['virtuemart_country_id'];
             }
         }
         /*
         if (!empty($cart->BT) && (count($cart->BT)>2)) $new = false;    
         if (empty($cart->BT)) $new = true; 
         */
         $type = 'BT';
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php';
         OPCUserFields::populateCart($cart, $type, true);
         OPCloader::setRegType();
         $op_disable_shipto = OPCloader::getShiptoEnabled($cart);
         if (!class_exists('VirtuemartModelUserfields')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'userfields.php';
         }
         $corefields = VirtueMartModelUserfields::getCoreFields();
         $userFields = $cart->{$fieldtype};
         if (isset($cart->BTaddress) && isset($cart->BTaddress['fields']) && isset($cart->BTaddress['fields']['virtuemart_country_id']) && !empty($cart->BTaddress['fields']['virtuemart_country_id']['value'])) {
             if (is_numeric($cart->BTaddress['fields']['virtuemart_country_id']['value'])) {
                 $cart->BT['virtuemart_country_id'] = $cart->BTaddress['fields']['virtuemart_country_id']['value'];
             }
         }
         // unset corefields
         $onlyf = array();
         if (empty($bt_fields_from)) {
             $q = 'select name from #__virtuemart_userfields where published=1 and registration = 1';
             $db = JFactory::getDBO();
             $db->setQuery($q);
             $onlyf2 = $db->loadAssocList();
             foreach ($onlyf2 as $k => $v) {
                 $onlyf[] = $v['name'];
             }
         }
         if (!empty($userFields['fields'])) {
             foreach ($userFields['fields'] as $key => $uf) {
                 // disable fields that are not marked for registration
                 if (!empty($onlyf)) {
                     if (!in_array($uf['name'], $onlyf)) {
                         unset($userFields['fields'][$key]);
                         continue;
                     }
                 }
                 $userFields['fields'][$key]['formcode'] = str_replace('vm-chzn-select', '', $userFields['fields'][$key]['formcode']);
                 OPCloader::$fields_names[$key] = $userFields['fields'][$key]['title'];
                 if ($userFields['fields'][$key]['type'] == 'delimiter') {
                     unset($userFields['fields'][$key]);
                     continue;
                 }
                 foreach ($corefields as $f) {
                     if ($f == $uf['name']) {
                         // will move the email to bt section
                         if (empty($no_login_in_template) || $unlg) {
                             if ($f == 'email') {
                                 if (empty($opc_email_in_bt)) {
                                     if (!$this->isNoLogin()) {
                                         unset($userFields['fields'][$key]);
                                     }
                                 }
                             } else {
                                 unset($userFields['fields'][$key]);
                             }
                             continue;
                         }
                     }
                 }
                 if (empty($custom_rendering_fields)) {
                     $custom_rendering_fields = array();
                 }
                 if (!empty($custom_rendering_fields)) {
                     if (in_array($uf['name'], $custom_rendering_fields)) {
                         unset($userFields['fields'][$key]);
                         continue;
                     }
                 }
                 if ($key == 'name') {
                     if (!empty($op_no_display_name)) {
                         if (!empty($userFields['fields']['name'])) {
                             unset($userFields['fields']['name']);
                         }
                     }
                 }
             }
         }
         // end of for each
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php';
         $skipreorder = array('email');
         OPCUserFields::getUserFields($userFields, $this, $cart, array(), array(), $skipreorder);
         // logic reversed, if email is not in BT, remove it
         if (!((!empty($opc_email_in_bt) || $this->isNoLogin()) && !empty($double_email))) {
             unset($userFields['fields']['email2']);
             // email is in BT, let's check for double mail
         }
         $skipreorder = array();
         if (!empty($opc_email_in_bt) || $this->isNoLogin()) {
             $skipreorder[] = 'email';
             if (!empty($opc_check_email)) {
                 if (!OPCloader::logged($cart) && empty($uid)) {
                     if (!empty($userFields['fields']['email'])) {
                         $un = $userFields['fields']['email']['formcode'];
                         if (stripos($un, 'id="email_already_exists"') === false) {
                             //if (!$double_email)
                             $un = str_replace('id=', ' onblur="javascript: Onepage.email_check(this);" id=', $un);
                             $un .= '<span class="email_already_exist" style="display: none; position: relative; color: red; font-size: 10px; background: none; border: none; padding: 0; margin: 0;" id="email_already_exists">';
                             $un .= OPCLang::sprintf('COM_ONEPAGE_EMAIL_ALREADY_EXISTS', OPCLang::_('COM_VIRTUEMART_USER_FORM_EMAIL'));
                             $un .= '</span>';
                             $userFields['fields']['email']['formcode'] = $un;
                         }
                     }
                 }
             }
         }
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php';
         OPCUserFields::reorderFields($userFields, $skipreorder);
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
         $this->_model = OPCmini::getModel('user');
         //new VirtuemartModelUser();
         $layout = 'default';
         $hidden = array();
         $hidden_html = '';
         if (!empty($userFields['fields'])) {
             foreach ($userFields['fields'] as $key => $val) {
                 if (!empty($val['hidden'])) {
                     $hidden[] = $val;
                     $hidden_html .= $val['formcode'];
                     unset($userFields['fields'][$key]);
                 }
             }
         }
         $vars = array('rowFields' => $userFields, 'cart' => $obj, 'is_logged' => $unlg);
         $html = $this->fetch($this, 'list_user_fields.tpl', $vars);
         $hidden_html = str_replace('"required"', '""', $hidden_html);
         $html .= $hidden_html;
         $html = $this->addListeners($html);
         if (empty($custom_rendering_fields)) {
             $custom_rendering_fields = array();
         }
         if (in_array('virtuemart_country_id', $custom_rendering_fields)) {
             $html .= '<input type="hidden" id="virtuemart_country_id" name="virtuemart_country_id" value="' . $default_shipping_country . '" />';
         }
         if (in_array('virtuemart_state_id', $custom_rendering_fields)) {
             $html .= '<input type="hidden" id="virtuemart_state_id" name="virtuemart_state_id" value="0" />';
         }
         return $html;
     }
 }
Exemplo n.º 6
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;
    }
Exemplo n.º 7
0
 /**
  * Save the user info. The saveData function dont use the userModel store function for anonymous shoppers, because it would register them.
  * We make this function private, so we can do the tests in the tasks.
  *
  * @author Max Milbers
  * @author Valérie Isaksen
  *
  * @param boolean Defaults to false, the param is for the userModel->store function, which needs it to determin how to handle the data.
  * @return String it gives back the messages.
  */
 private function saveData(&$cart = false, $register = false, $disable_duplicit = false, &$data)
 {
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     $mainframe = JFactory::getApplication();
     $currentUser = JFactory::getUser();
     $msg = '';
     //store email:
     $data['email'] = str_replace(array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $data['email']);
     $user_id = JFactory::getUser()->get('id');
     if (empty($user_id)) {
         JFactory::getUser()->set('email', $data['email']);
     }
     if (empty($data['shipto_address_type_name'])) {
         $data['shipto_address_type_name'] = OPCLang::_('COM_VIRTUEMART_ORDER_PRINT_SHIPPING_LBL');
     }
     if (empty($data['address_type'])) {
         $data['address_type'] = 'BT';
     }
     $at = JRequest::getWord('addrtype');
     if (!empty($at)) {
         $data['address_type'] = $at;
     }
     $r = JRequest::getVar('register_account', '');
     if (!empty($r) || VmConfig::get('oncheckout_only_registered', 0)) {
         $register = true;
     }
     //if ($data['address_type'] == 'ST') $register = false;
     $this->addModelPath(JPATH_VM_ADMINISTRATOR . DS . 'models');
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
     $userModel = OPCmini::getModel('user');
     if ($currentUser->id != 0 || $register) {
         $data['user_is_vendor'] = 0;
         //It should always be stored, stAn: it will, but not here
         if ($currentUser->id == 0 || empty($data['ship_to_info_id'])) {
             if (!empty($data['email'])) {
                 if (empty($data['shipto_email'])) {
                     $data['shipto_email'] = $data['email'];
                 }
             }
             // check for duplicit registration feature
             if ($allow_duplicit && empty($disable_duplicit)) {
                 // set the username if appropriate
                 if (empty($data['username'])) {
                     if (!empty($currentUser->id)) {
                         $data['username'] = $username = $currentUser->username;
                         JRequest::setVar('username', $username);
                         $data['email'] = $email = $this->getEmail();
                         JRequest::setVar('email', $email);
                     } else {
                         $username = $data['email'];
                         $email = $data['email'];
                     }
                 } else {
                     $username = $data['username'];
                     if (!empty($data['email'])) {
                         $email = $data['email'];
                     } else {
                         // support for 3rd party exts
                         if (strpos($username, '@') !== false) {
                             $email = $username;
                         }
                     }
                 }
                 $db = JFactory::getDBO();
                 $q = "select * from #__users where email LIKE '" . $this->getEscaped($db, $email) . "' limit 0,1";
                 //or username = '******' ";
                 $db->setQuery($q);
                 $res = $db->loadAssoc();
                 $is_dup = false;
                 if (!empty($res)) {
                     //ok, the customer already used the same email address
                     $is_dup = true;
                     $duid = $res['id'];
                     $GLOBALS['is_dup'] = $duid;
                     $GLOBALS['opc_new_user'] = $duid;
                     $data['address_type'] = 'BT';
                     $data['virtuemart_user_id'] = $duid;
                     $data['shipto_virtuemart_user_id'] = $duid;
                     $this->saveToCart($data, $cart);
                     // we will not save the user into the jos_virtuermart_userinfos
                     if ($currentUser->id != 0) {
                         // ok, we have a joomla registration + logged in users
                         // but the user might not be registered with virtuemart
                         if ($currentUser->id == $duid) {
                             // yes we are talking about the same user
                             // let's associate his data in the cart with his data in VM tables
                             $q = "select * from #__virtuemart_userinfos where virtuemart_user_id = " . $duid . " ";
                             $db->setQuery($q);
                             $res = $db->loadAssocList();
                             if (empty($res)) {
                                 foreach ($res as $row) {
                                     // ok, he has no BT address assigned
                                     if ($row['address_type'] == 'BT') {
                                         $forceregister = true;
                                     }
                                     if ($row['address_type'] == 'ST') {
                                         $forceregisterst = true;
                                     }
                                 }
                             } else {
                                 // he is already logged in and all we have to do is to store his data in the order details, not the userinfos
                                 return true;
                             }
                         }
                     } else {
                         return true;
                     }
                     // ok, we've got a duplict registration here
                     if (empty($currentUser->id)) {
                         if (!empty($data['password']) && !empty($data['username'])) {
                             // if we showed the password fields, let try to log him in
                             // we can try to log him in if he entered password
                             $credentials = array('username' => $username, 'password' => $data['password']);
                             // added by stAn, so we don't ge an error
                             $ret = false;
                             if (empty($op_never_log_in)) {
                                 $options = array('silent' => true);
                                 $mainframe = JFactory::getApplication();
                                 ob_start();
                                 $ret = $mainframe->login($credentials, $options);
                                 // test123
                                 /*
                                 if (false)
                                 {
                                 ob_start(); 
                                 	$options = array('silent' => true, 'skip_joomdlehooks'=>true );
                                 	$mainframe->logout($user->id, $options); 
                                 	ob_get_clean(); 
                                 	$return = $mainframe->login($credentials, $options);
                                 }
                                 */
                             }
                             // refresh user data:
                             // refresh user data:
                             // refresh user data:
                             /*
                             $session = JFactory::getSession(); 
                             $user = JFactory::getUser(); 
                             $id = (int)$user->id; 
                             $user = new JUser($id); 
                             $session->clear('user');
                             $user = new JUser($id); 	
                             */
                             // end of refresh
                             // end of refresh
                             // end of refresh
                             $xxy = ob_get_clean();
                             unset($xxy);
                             if ($ret === false) {
                                 // the login was not sucessfull
                             } else {
                                 // login was sucessfull
                                 $dontproceed = true;
                             }
                         }
                     }
                     // did he check: shipping address is different?
                     if (method_exists($cart, 'prepareAddressDataInCart')) {
                         $cart->prepareAddressDataInCart('BT', 1);
                     }
                     if (method_exists($cart, 'prepareAddressFieldsInCart')) {
                         $cart->prepareAddressFieldsInCart();
                     }
                     if (!class_exists('VirtuemartModelUserfields')) {
                         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'userfields.php';
                     }
                     $corefields = VirtueMartModelUserfields::getCoreFields();
                     $fieldtype = 'BTaddress';
                     $userFields = $cart->{$fieldtype};
                     if (method_exists($cart, 'prepareAddressDataInCart')) {
                         $cart->prepareAddressDataInCart('ST', 1);
                     }
                     if (method_exists($cart, 'prepareAddressFieldsInCart')) {
                         $cart->prepareAddressFieldsInCart();
                     }
                     $fieldtype = 'STaddress';
                     $userFieldsst = $cart->{$fieldtype};
                     if (!empty($data['sa']) && $data['sa'] == 'adresaina') {
                         // yes, his data are in the shipto_ fields
                         $address = array();
                         foreach ($data as $ksa => $vsa) {
                             if (strpos($ksa, 'shipto_') === 0) {
                                 $address[$ksa] = $vsa;
                             }
                         }
                     } else {
                         // load the proper BT address
                         $q = "select * from #__virtuemart_userinfos where virtuemart_user_id = '" . $duid . "' and address_type = 'BT' limit 0,1";
                         $db->setQuery($q);
                         $bta = $db->loadAssoc();
                         if (!empty($bta)) {
                             $address = array();
                             // no, his data are in the BT address and therefore we need to copy them and set a proper BT address
                             foreach ($userFieldsst['fields'] as $key => $uf) {
                                 $uf['name'] = str_replace('shipto_', '', $uf['name']);
                                 // POST['variable'] is prefered form userinfos.variable in db
                                 if (empty($bta[$uf['name']])) {
                                     $bta[$uf['name']] = '';
                                 }
                                 if (!isset($data[$uf['name']])) {
                                     $data[$uf['name']] = '';
                                 }
                                 if (empty($data['address_type_name'])) {
                                     $data['address_type_name'] = OPCLang::_('COM_VIRTUEMART_ORDER_PRINT_SHIPPING_LBL');
                                 }
                                 if (empty($data['shipto_address_type_name'])) {
                                     $data['shipto_address_type_name'] = OPCLang::_('COM_VIRTUEMART_ORDER_PRINT_SHIPPING_LBL');
                                 }
                                 if (empty($data['name'])) {
                                     $data['name'] = $bta[$uf['name']];
                                 }
                                 JRequest::setVar('shipto_' . $uf['name'], $data[$uf['name']], 'post');
                                 // this will set the new BT address in the cart later on and in the order details as well
                                 if (!empty($bta[$uf['name']])) {
                                     JRequest::setVar($uf['name'], $bta[$uf['name']], 'post');
                                 }
                                 $address['shipto_' . $uf['name']] = $data[$uf['name']];
                             }
                         }
                     }
                     // ok, we've got the ST addres here, let's check if there is anything similar
                     $q = "select * from #__virtuemart_userinfos where virtuemart_user_id = '" . $duid . "'";
                     $db->setQuery($q);
                     $res = $db->loadAssocList();
                     $ign = array('virtuemart_userinfo_id', 'virtuemart_user_id', 'address_type', 'address_type_name', 'name', 'agreed', '', 'created_on', 'created_by', 'modified_on', 'modified_by', 'locked_on', 'locked_by');
                     if (function_exists('mb_strtolower')) {
                         $cf = 'mb_strtolower';
                     } else {
                         $cf = 'strtolower';
                     }
                     $e = $db->getErrorMsg();
                     if (!empty($res)) {
                         // user is already registered, but we need to fill some of the system fields
                         foreach ($res as $k => $ad) {
                             $match = false;
                             foreach ($ad as $nn => $val) {
                                 if (!in_array($nn, $ign)) {
                                     if (!isset($address['shipto_' . $nn])) {
                                         $address['shipto_' . $nn] = '';
                                     }
                                     if ($cf($val) != $cf($address['shipto_' . $nn])) {
                                         $match = false;
                                         break;
                                     } else {
                                         $match = true;
                                         $lastuid = $ad['virtuemart_userinfo_id'];
                                         $lasttype = $ad['address_type'];
                                     }
                                 }
                             }
                             if (!empty($match)) {
                                 // we've got a ST address already registered
                                 if ($lasttype == 'BT') {
                                     // let's set STsameAsBT
                                     JRequest::setVar('sa', null);
                                     // we don't have to do anything as the same data will be saved
                                 } else {
                                     JRequest::setVar('shipto_virtuemart_userinfo_id', $lastuid);
                                     $new_shipto_virtuemart_userinfo_id = $lastuid;
                                 }
                                 break;
                             }
                         }
                         // the user is registered and logged in, but he wants to checkout with a new address. he might still be in the guest mode
                         if (empty($match) || !empty($new_shipto_virtuemart_userinfo_id)) {
                             // we need to store it as a new ST address
                             $address['address_type'] = 'ST';
                             $address['virtuemart_user_id'] = $duid;
                             $address['shipto_virtuemart_user_id'] = $duid;
                             if (empty($new_shipto_virtuemart_userinfo_id)) {
                                 $address['shipto_virtuemart_userinfo_id'] = 0;
                                 $address['shipto_virtuemart_userinfo_id'] = $this->OPCstoreAddress($cart, $address, $duid);
                                 // let's set ST address here
                             } else {
                                 $address['shipto_virtuemart_userinfo_id'] = $new_shipto_virtuemart_userinfo_id;
                             }
                             if (!isset($address['agreed'])) {
                                 $address['agreed'] = JRequest::getBool('agreed', 1);
                             }
                             // empty radios fix start
                             //Notice: Undefined index:  name in /srv/www/clients/client1/web90/web/svn/2072/virtuemart/components/com_virtuemart/helpers/cart.php on line 1030
                             //Notice: Undefined index:  agreed in /srv/www/clients/client1/web90/web/svn/2072/virtuemart/components/com_virtuemart/helpers/cart.php on line 1030
                             //Notice: Undefined index:  myradio in /srv/www/clients/client1/web90/web/svn/2072/virtuemart/components/com_virtuemart/helpers/cart.php on line 1030
                             //Notice: Undefined index:  testcheckbox in /srv/www/clients/client1/web90/web/svn/2072/virtuemart/components/com_virtuemart/helpers/cart.php on line 1030
                             require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
                             $userFieldsModel = OPCmini::getModel('userfields');
                             $prefix = '';
                             $prepareUserFieldsBT = $userFieldsModel->getUserFieldsFor('cart', 'BT');
                             $prepareUserFieldsBT = $userFieldsModel->getUserFieldsFor('cart', 'ST');
                             if (!empty($prepareUserFieldsBT)) {
                                 foreach ($prepareUserFieldsBT as $fldb) {
                                     $name = $fldb->name;
                                     if (!isset($btdata[$name])) {
                                         $btdata[$name] = '';
                                     }
                                 }
                             }
                             if (!empty($prepareUserFieldsST)) {
                                 foreach ($prepareUserFieldsST as $flda) {
                                     $name = $flda->name;
                                     // we need to add empty values for checkboxes and radios
                                     if (!isset($address['shipto_' . $name])) {
                                         $address['shipto_' . $name] = '';
                                     }
                                 }
                             }
                             // empty radios fix end
                             if (defined('VM_VERSION') && VM_VERSION >= 3) {
                                 $cart->saveAddressInCart($address, 'ST', true, 'shipto_');
                             } else {
                                 $cart->saveAddressInCart($address, 'ST', true);
                             }
                             //$cart->saveAddressInCart($address, 'ST');
                             $btdata = JRequest::get('post');
                             $btdata['virtuemart_user_id'] = $duid;
                             $btdata['address_type'] = 'BT';
                             if (!isset($btdata['agreed'])) {
                                 $btdata['agreed'] = JRequest::getBool('agreed', 1);
                             }
                             $cart->saveAddressInCart($btdata, 'BT');
                             return;
                         }
                     }
                 }
             }
             if (empty($dontproceed)) {
                 if (empty($currentUser->id)) {
                     if (empty($data['username'])) {
                         $data['username'] = $data['email'];
                     }
                     if (empty($data['password']) && !VmConfig::get('oncheckout_show_register', 0)) {
                         $data['password'] = $data['password2'] = uniqid();
                     }
                 }
                 if (!empty($data['first_name'])) {
                     $data['name'] = $data['first_name'] . ' ' . $data['last_name'];
                 } else {
                     if (!empty($data['last_name'])) {
                         $data['name'] = $data['last_name'];
                     } else {
                         $data['name'] = '   ';
                     }
                 }
                 if (!empty($data['shipto_first_name']) && !empty($data['shipto_last_name'])) {
                     $data['shipto_name'] = $data['shipto_first_name'] . ' ' . $data['shipto_last_name'];
                 } else {
                     if (!empty($data['shipto_last_name'])) {
                         $data['shipto_name'] = $data['shipto_last_name'];
                     } else {
                         $data['shipto_name'] = '   ';
                     }
                 }
                 if (empty($_POST['name'])) {
                     $_POST['name'] = $data['name'];
                 }
                 // Bind the post data to the JUser object and the VM tables, then saves it, also sends the registration email
                 if (empty($unlog_all_shoppers)) {
                     if (empty($currentUser->id)) {
                         $data['guest'] = 0;
                     }
                 }
                 $usersConfig = JComponentHelper::getParams('com_users');
                 // OPC can still register, but will unlog the shopper immidiately when no login is enabled
                 if ($usersConfig->get('allowUserRegistration') != '0') {
                     $ret = $this->userStore($data, $userModel);
                     // here virtuemart logs in the user, so we need to unlog him
                     /*
                     			 since opc 2.0.231 VM cannot login the customer, therefore we do not need to unlog him
                     			 if (!empty($op_never_log_in))
                     {
                     
                       $mainframe = JFactory::getApplication(); 
                     				  $options = array('silent' => true, 'skip_joomdlehooks'=>true );
                     				 $user = JFactory::getUser();
                     				 $mainframe->logout($user->id, $options); 
                     				 $unlog_all_shoppers = true; 
                     }
                     */
                 } else {
                     $ret['success'] = true;
                     $user = JFactory::getUser();
                     $unlog_all_shoppers = true;
                 }
                 $data['address_type'] = 'ST';
                 // this gives error on shipping address save
                 // this section is used purely for unlogged customers
                 if (!empty($data['sa']) && $data['sa'] == 'adresaina') {
                     $this->userStoreAddress($userModel, $data);
                 }
                 $user = $ret['user'];
                 $ok = $ret['success'];
                 $user = JFactory::getUser();
                 // we will not send this again
                 if (empty($unlog_all_shoppers)) {
                     if ($user->id == 0) {
                         $msg = is_array($ret) ? $ret['message'] : $ret;
                         $usersConfig = JComponentHelper::getParams('com_users');
                         $useractivation = $usersConfig->get('useractivation');
                         if (empty($op_never_log_in)) {
                             if (is_array($ret) && $ret['success'] && (empty($useractivation) || !empty($opc_no_activation))) {
                                 // Username and password must be passed in an array
                                 $credentials = array('username' => $ret['user']->username, 'password' => $ret['user']->password_clear);
                                 $options = array('silent' => true);
                                 $return = $mainframe->login($credentials, $options);
                                 //test123
                                 /*
                                 				   if (false)				
                                 {
                                 // this part of code fixes the _levels caching issue on joomla 1.7 to 2.5
                                 ob_start(); 
                                 $options = array('silent' => true, 'skip_joomdlehooks'=>true );
                                 $mainframe->logout($user->id, $options); 
                                 ob_get_clean(); 
                                 $return = $mainframe->login($credentials, $options);
                                 }
                                 */
                                 // refresh user data:
                                 // refresh user data:
                                 /*
                                 $session = JFactory::getSession(); 
                                 $user = JFactory::getUser(); 
                                 $id = (int)$user->id; 
                                 $user = new JUser($id); 
                                 $session->clear('user');
                                 $user = new JUser($id); 	
                                 */
                                 // end of refresh				// end of refresh
                             }
                         }
                     }
                 }
             }
         } else {
             // the user is logged in and we want to update his address
             $data['address_type'] = 'ST';
             // this gives error on shipping address save
             $new_shipto = JRequest::getVar('opc_st_changed_new', false);
             if (!empty($data['sa']) && $data['sa'] == 'adresaina' || $new_shipto) {
                 $data['address_type'] = 'ST';
                 //$data['shipto_virtuemart_userinfo_id'] = null;
                 if (empty($data['email']) && !empty($currentUser->email)) {
                     $data['email'] = $currentUser->email;
                     $data['shipto_email'] = $currentUser->email;
                 }
                 if ($data['shipto_address_type_name'] == OPCLang::_('COM_VIRTUEMART_ORDER_PRINT_SHIPPING_LBL')) {
                     $data['shipto_address_type_name'] .= '(' . @$data['first_name'] . ' ' . @$data['last_name'] . ' ' . @$data['address_1'] . ' ' . @$data['city'] . ')';
                 }
                 if (empty($data['name'])) {
                     $data['name'] = '';
                     if (!empty($data['first_name'])) {
                         $data['name'] .= $data['first_name'];
                     }
                     if (!empty($data['last_name'])) {
                         $data['name'] .= $data['last_name'];
                     }
                 }
                 if (empty($data['user_id'])) {
                     $data['user_id'] = $currentUser->id;
                     $data['virtuemart_user_id'] = $currentUser->id;
                 }
                 if (empty($data['username']) && !empty($currentUser->username)) {
                     $data['username'] = $currentUser->username;
                 }
                 // to create a new one:
                 $data['shipto_virtuemart_userinfo_id'] = 0;
                 $this->OPCstoreAddress($cart, $data);
             }
             $bt = JRequest::getVar('ship_to_info_id_bt', '');
             if (!empty($bt)) {
                 $changed = JRequest::getVar('opc_st_changed_' . $bt, '');
                 if (!empty($changed)) {
                     $data['address_type'] = 'BT';
                     $data['shipto_virtuemart_userinfo_id'] = null;
                     if (empty($data['email']) && !empty($currentUser->email)) {
                         $data['email'] = $currentUser->email;
                     }
                     if (empty($data['name'])) {
                         $data['name'] = '';
                         if (!empty($data['first_name'])) {
                             $data['name'] .= $data['first_name'];
                         }
                         if (!empty($data['last_name'])) {
                             $data['name'] .= $data['last_name'];
                         }
                     }
                     if (empty($data['user_id'])) {
                         $data['user_id'] = $currentUser->id;
                         $data['virtuemart_user_id'] = $currentUser->id;
                     }
                     if (empty($data['username']) && !empty($currentUser->username)) {
                         $data['username'] = $currentUser->username;
                     }
                     $this->userStoreAddress($userModel, $data);
                     //$userModel->storeAddress($data);
                 }
             }
         }
     }
     $data['address_type'] = 'BT';
     $this->saveToCart($data, $cart);
     return $msg;
 }