setObligatoryKeys('address_type'); $this->setObligatoryKeys('virtuemart_user_id'); $this->setLoggable(); $this->setLockable(); $this->setTableShortCut('ui'); } /** * Validates the user info record fields. * * @author RickG, RolandD, Max Milbers * @return boolean True if the table buffer is contains valid data, false otherwise. */ public function check(){ if($this->address_type=='BT' or $this->address_type=='ST' ){ if($this->address_type=='ST' and empty($this->address_type_name)){ $zip = empty($this->zip)? '': ' '.$this->zip; $city = empty($this->city)? '': ' '.$this->city; $address_1 = empty($this->address_1)? '': ' '.$this->address_1; $this->address_type_name = vmText::sprintf('COM_VM_DELIVERY_ADDR_AUTONAME',rand(1,9),$zip,$city,$address_1); vmdebug('Table userinfos check failed: address_type '.$this->address_type.' without name, autogenerated '.$this->address_type_name,'check failed: ST has no name, autogenerated '.$this->address_type_name); } } else { vmError('Table userinfos check failed: Unknown address_type '.$this->address_type,'check failed: Unknown address_type '); vmdebug('Table userinfos check failed: Unknown address_type '.$this->address_type.' virtuemart_user_id '.$this->virtuemart_user_id.' name '.$this->name); return false; } if (!empty($this->virtuemart_userinfo_id)) { $this->virtuemart_userinfo_id = (int)$this->virtuemart_userinfo_id; if(!vmAccess::manager('user.edit')){ $q = "SELECT virtuemart_user_id FROM #__virtuemart_userinfos WHERE virtuemart_userinfo_id = ".$this->virtuemart_userinfo_id; $this->_db->setQuery($q); $total = $this->_db->loadColumn(); if (count($total) > 0) { $userId = JFactory::getUser()->id; if($total[0]!=$userId){ vmError('Hacking attempt uid check, you got logged'); echo 'Hacking attempt uid check, you got logged'; return false; } } } //return parent::check(); } else { if(empty($this->address_type)) $this->address_type = 'BT'; /* Check if a record exists */ $q = "SELECT virtuemart_userinfo_id FROM #__virtuemart_userinfos WHERE virtuemart_user_id = ".$this->virtuemart_user_id." AND address_type = ".$this->_db->Quote($this->address_type); if($this->address_type!='BT'){ $q .= " AND address_type_name = ".$this->_db->Quote($this->address_type_name); } $this->_db->setQuery($q); $total = $this->_db->loadColumn(); if (count($total) > 0) { $this->virtuemart_userinfo_id = (int)$total[0]; } else { $this->virtuemart_userinfo_id = 0;//md5(uniqid($this->virtuemart_user_id)); } } if(empty($this->virtuemart_user_id)){ $user = JFactory::getUser(); if(!empty($user->id)){ $this->virtuemart_user_id = $user->id; } } $hash = 'SFL'.$this->_tbl.'00'; if (isset(self::$_cache[$hash])) { foreach(self::$_cache[$hash] as $field){ if( strpos( $field['Type'],'int')!==false and $this->{$field['Field']}!==null){ if( empty($this->{$field['Field']}) ){ //vmdebug(' int field to 0',$field['Field'],$this->{$field['Field']}); $this->{$field['Field']} = 0; } else { $this->{$field['Field']} = (int)$this->{$field['Field']}; } } } } return parent::check(); } /** * Overloaded delete() to delete a list of virtuemart_userinfo_id's based on the user id * @var mixed id * @return boolean True on success * @author Oscar van Eijk */ function delete( $id=null , $where = 0 ){ // TODO If $id is not numeric, assume it's a virtuemart_userinfo_id. Validate if this is safe enough if (!is_numeric($id)) { return (parent::delete($id)); } // Implicit else $this->_db->setQuery('DELETE from `#__virtuemart_userinfos` WHERE `virtuemart_user_id` = ' . $id); if ($this->_db->execute() === false) { vmError($this->_db->getError()); return false; } return true; } } // No Closing tag