Example #1
0
 /**
  * Test userdata if valid
  *
  * @author Max Milbers
  * @param String if BT or ST
  * @param Object If given, an object with data address data that must be formatted to an array
  * @return redirectMsg, if there is a redirectMsg, the redirect should be executed after
  */
 public function validateUserData($type = 'BT', $data = null)
 {
     if (!class_exists('VirtueMartModelUserfields')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'userfields.php';
     }
     $userFieldsModel = VmModel::getModel('userfields');
     if ($type == 'BT') {
         $fieldtype = 'account';
     } else {
         $fieldtype = 'shipment';
     }
     $neededFields = $userFieldsModel->getUserFields($fieldtype, array('required' => true, 'delimiters' => true, 'captcha' => true, 'system' => false), array('delimiter_userinfo', 'name', 'username', 'password', 'password2', 'address_type_name', 'address_type', 'user_is_vendor', 'agreed'));
     $app = JFactory::getApplication();
     if ($app->isSite()) {
         if (!class_exists('VirtueMartCart')) {
             require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php';
         }
         $cart = VirtueMartCart::getCart();
     }
     $i = 0;
     $return = true;
     foreach ($neededFields as $field) {
         if ($field->required && empty($data[$field->name]) && $field->name != 'virtuemart_state_id') {
             //more than four fields missing, this is not a normal error (should be catche by js anyway, so show the address again.
             if ($i > 3 && $type == 'BT') {
                 vmInfo('COM_VIRTUEMART_CHECKOUT_PLEASE_ENTER_ADDRESS');
                 return false;
             } else {
                 vmInfo(JText::sprintf('COM_VIRTUEMART_MISSING_VALUE_FOR_FIELD', JText::_($field->title)));
                 $i++;
                 $return = false;
             }
         } else {
             if ($field->required and $field->name == 'virtuemart_state_id') {
                 if (!empty($data['virtuemart_country_id']) && !empty($data['virtuemart_state_id'])) {
                     if (!class_exists('VirtueMartModelState')) {
                         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'state.php';
                     }
                     if (!($msg = VirtueMartModelState::testStateCountry($data['virtuemart_country_id'], $data['virtuemart_state_id']))) {
                         $i++;
                         vmInfo(JText::sprintf('COM_VIRTUEMART_MISSING_VALUE_FOR_FIELD', JText::_($field->title)));
                         $return = false;
                     }
                 }
             }
         }
     }
     return $return;
 }
Example #2
0
 /**
  * Test userdata if valid
  *
  * @author Max Milbers
  * @param String if BT or ST
  * @param Object If given, an object with data address data that must be formatted to an array
  * @return redirectMsg, if there is a redirectMsg, the redirect should be executed after
  */
 public function validateUserData(&$data, $type = 'BT', $showInfo = false)
 {
     if (!class_exists('VirtueMartModelUserfields')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'userfields.php';
     }
     $userFieldsModel = VmModel::getModel('userfields');
     if ($type == 'BT') {
         $fieldtype = 'account';
     } else {
         if ($type == 'cartfields') {
             $fieldtype = 'cart';
         } else {
             $fieldtype = 'shipment';
         }
     }
     $neededFields = $userFieldsModel->getUserFields($fieldtype, array('required' => true, 'delimiters' => true, 'captcha' => true, 'system' => false), array('delimiter_userinfo', 'name', 'username', 'password', 'password2', 'address_type_name', 'address_type', 'user_is_vendor', 'agreed'));
     $i = 0;
     $return = true;
     $required = 0;
     $missingFields = array();
     $lang = JFactory::getLanguage();
     foreach ($neededFields as $field) {
         //This is a special test for the virtuemart_state_id. There is the speciality that the virtuemart_state_id could be 0 but is valid.
         if ($field->name == 'virtuemart_state_id') {
             if (!class_exists('VirtueMartModelState')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'state.php';
             }
             if (!empty($data['virtuemart_country_id'])) {
                 if (!isset($data['virtuemart_state_id'])) {
                     $data['virtuemart_state_id'] = 0;
                 }
                 if (!($msg = VirtueMartModelState::testStateCountry($data['virtuemart_country_id'], $data['virtuemart_state_id']))) {
                     //The state is invalid, so we set the state 0 here.
                     $data['virtuemart_state_id'] = 0;
                     vmdebug('State was not fitting to country, set virtuemart_state_id to 0');
                 } else {
                     if (empty($data['virtuemart_state_id'])) {
                         vmdebug('virtuemart_state_id is empty, but valid (country has not states, set to unrequired');
                         $field->required = false;
                     } else {
                         //vmdebug('validateUserData my country '.$data['virtuemart_country_id'].' my state '.$data['virtuemart_state_id']);
                     }
                 }
             }
         }
         if ($field->required) {
             $required++;
             if (empty($data[$field->name])) {
                 if ($lang->hasKey('COM_VIRTUEMART_MISSING_' . $field->name)) {
                     $missingFields[] = vmText::_('COM_VIRTUEMART_MISSING_' . $field->name);
                 } else {
                     //vmdebug('my field titel',$field->title);
                     $missingFields[] = vmText::sprintf('COM_VIRTUEMART_MISSING_VALUE_FOR_FIELD', $field->title);
                 }
                 $i++;
                 $return = false;
             } else {
                 if ($data[$field->name] == $field->default) {
                     $i++;
                 } else {
                 }
             }
         }
     }
     if (empty($required)) {
         vmdebug('Nothing to require');
         $return = true;
     } else {
         if ($i == $required) {
             $return = -1;
         }
     }
     //vmdebug('my i '.$i.' my data size '.$required,$return,$showInfo);
     if (!$return or $showInfo) {
         foreach ($missingFields as $fieldname) {
             vmInfo($fieldname);
         }
     }
     return $return;
 }
Example #3
0
 /**
  * Test userdata if valid
  *
  * @author Max Milbers
  * @param String if BT or ST
  * @param Object If given, an object with data address data that must be formatted to an array
  * @return redirectMsg, if there is a redirectMsg, the redirect should be executed after
  */
 function validateUserData($type = 'BT', $obj = null, $cart = null)
 {
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     // we disable validation for ST address, because it is still missing at the front-end and shall be added as an optional feature
     if ($type == 'ST') {
         return false;
     }
     require_once JPATH_OPC . DS . 'helpers' . DS . 'loader.php';
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php';
     $userFieldsModel = OPCmini::getModel('userfields');
     if ($type == 'BT') {
         $fieldtype = 'account';
     } else {
         $fieldtype = 'shipment';
     }
     if ($type == 'BT') {
         if (empty($bt_fields_from)) {
             $fieldtype = 'registration';
         } else {
             if ($bt_fields_from === 1) {
                 $fieldtype = 'account';
             } else {
                 $fieldtype = 'cart';
             }
         }
     }
     $neededFields = $userFieldsModel->getUserFields($fieldtype, array('required' => true, 'delimiters' => true, 'captcha' => true, 'system' => false), array('delimiter_userinfo', 'name', 'username', 'password', 'password2', 'address_type_name', 'address_type', 'user_is_vendor', 'agreed'));
     $redirectMsg = false;
     $i = 0;
     $missing = '';
     foreach ($neededFields as $field) {
         $is_business = JRequest::getVar('opc_is_business', 0);
         // we need to alter shopper group for business when set to:
         $is_business = JRequest::getVar('opc_is_business', 0);
         if (!empty($business_fields)) {
             if (!$is_business) {
                 // do not check if filled
                 if (in_array($field->name, $business_fields)) {
                     continue;
                 }
             }
         }
         if ($type == 'ST') {
             if (!empty($shipping_obligatory_fields)) {
                 if (!in_array($field->name, $shipping_obligatory_fields)) {
                     continue;
                 }
             }
         }
         // manage required business fields when not business selected:
         //foreach ($business_fields as $fn)
         if ($field->required && empty($cart->{$type}[$field->name]) && $field->name != 'virtuemart_state_id') {
             $redirectMsg = JText::sprintf('COM_VIRTUEMART_MISSING_VALUE_FOR_FIELD', JText::_($field->title));
             $i++;
             //more than four fields missing, this is not a normal error (should be catche by js anyway, so show the address again.
             if ($i > 2 && $type == 'BT') {
                 $missing .= JText::_($field->title);
                 $redirectMsg = JText::_('COM_VIRTUEMART_CHECKOUT_PLEASE_ENTER_ADDRESS');
             }
         }
         if ($obj !== null && is_array($cart->{$type})) {
             $cart->{$type}[$field->name] = $obj->{$field->name};
         }
         //This is a special test for the virtuemart_state_id. There is the speciality that the virtuemart_state_id could be 0 but is valid.
         if ($field->name == 'virtuemart_state_id') {
             if (!class_exists('VirtueMartModelState')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'state.php';
             }
             if (!empty($cart->{$type}['virtuemart_country_id']) && !empty($cart->{$type}['virtuemart_state_id'])) {
                 if (!($msg = VirtueMartModelState::testStateCountry($cart->{$type}['virtuemart_country_id'], $cart->{$type}['virtuemart_state_id']))) {
                     $redirectMsg = $msg;
                 }
             }
         }
     }
     if (empty($redirectMsg)) {
         return false;
     }
     $redirectMsg .= ' ' . $missing;
     return $redirectMsg;
 }