示例#1
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";
示例#3
0
 function getUserFieldsLists(&$corefields)
 {
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'version.php';
     $ver = vmVersion::$RELEASE;
     $ok = false;
     if (version_compare($ver, '2.0.6', 'ge')) {
         $ok = true;
     }
     if ($ver == '${PHING.VM.RELEASE}') {
         $ok = true;
     }
     if (!$ok) {
         return false;
     }
     $jlang = JFactory::getLanguage();
     $jlang->load('com_virtuemart', JPATH_SITE, 'en-GB', true);
     $jlang->load('com_virtuemart', JPATH_SITE, $jlang->getDefault(), true);
     $jlang->load('com_virtuemart', JPATH_SITE, null, true);
     if (!class_exists('VirtueMartModelUserfields')) {
         require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'models' . DS . 'userfields.php';
     }
     $modelu = new VirtueMartModelUserfields();
     $corefields = $modelu->getCoreFields();
     $corefields[] = 'register_account';
     $modelu->setState('limitstart', 0);
     $modelu->setState('limit', 99999);
     $modelu->_noLimit = true;
     $uf = $modelu->getUserfieldsList();
     if (empty($uf)) {
         return array();
     }
     $last = array('virtuemart_userfield_id' => '0', 'virtuemart_vendor_id' => '1', 'userfield_jplugin_id' => '0', 'name' => 'register_account', 'title' => 'COM_VIRTUEMART_ORDER_REGISTER', 'description' => '', 'type' => 'checkbox', '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' => '101', 'shared' => '0', 'published' => '1', 'created_on' => '2014-04-01 16:43:17', 'created_by' => '42', 'modified_on' => '2014-04-01 16:43:17', 'modified_by' => '42', 'locked_on' => '0000-00-00 00:00:00', 'locked_by' => '0');
     $last = (object) $last;
     $last->name = 'register_account';
     $last->title = 'COM_VIRTUEMART_ORDER_REGISTER';
     $last->type = 'checkbox';
     $uf[] = $last;
     $uf = array_reverse($uf);
     return $uf;
 }
示例#4
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;
     }
 }
示例#5
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;
 }