/**
  * @author Max Milbers
  * @param
  */
 function check()
 {
     if (!empty($this->_slugAutoName)) {
         $slugAutoName = $this->_slugAutoName;
         $slugName = $this->_slugName;
         if (in_array($slugAutoName, $this->_translatableFields)) {
             $checkTable = $this->_tbl . '_' . VMLANG;
         } else {
             $checkTable = $this->_tbl;
         }
         if (empty($this->{$slugName})) {
             // 				vmdebug('table check use _slugAutoName '.$slugAutoName.' '.$slugName);
             if (!empty($this->{$slugAutoName})) {
                 $this->{$slugName} = $this->{$slugAutoName};
             } else {
                 vmError('VmTable ' . $checkTable . ' Check not passed. Neither slug nor obligatory value at ' . $slugAutoName . ' for auto slug creation is given');
                 return false;
             }
         }
         //if (!class_exists('VmMediaHandler')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'mediahandler.php');
         //vmdebug('check $slug before stringURLSafe',$this->$slugName);
         //$this->$slugName = vmFile::makeSafe( $this->$slugName );
         //$lang = JFactory::getLanguage();
         //$this->$slugName = $lang->transliterate($this->$slugName);
         $this->{$slugName} = JApplication::stringURLSafe($this->{$slugName});
         $valid = $this->checkCreateUnique($checkTable, $slugName);
         if (!$valid) {
             return false;
         }
     }
     foreach ($this->_obkeys as $obkeys => $error) {
         if (empty($this->{$obkeys})) {
             if (empty($error)) {
                 $error = 'Serious error cant save ' . $this->_tbl . ' without ' . $obkeys;
             } else {
                 //	$error = get_class($this).' '.JText::_($error);
                 $error = get_class($this) . ' ' . $error;
             }
             $this->setError($error);
             vmError($error);
             return false;
         }
     }
     if ($this->_unique) {
         if (empty($this->_db)) {
             $this->_db = JFactory::getDBO();
         }
         foreach ($this->_unique_name as $obkeys => $error) {
             if (empty($this->{$obkeys})) {
                 // 					vmError(JText::sprintf('COM_VIRTUEMART_NON_UNIQUE_KEY',$this->$obkeys));
                 $this->setError($error);
                 vmError('Non unique ' . $this->_unique_name . ' ' . $error);
                 return false;
             } else {
                 $valid = $this->checkCreateUnique($this->_tbl, $obkeys);
                 if (!$valid) {
                     return false;
                 }
             }
         }
     }
     if (isset($this->virtuemart_vendor_id)) {
         $multix = Vmconfig::get('multix', 'none');
         //Lets check if the user is admin or the mainvendor
         if (!class_exists('Permissions')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php';
         }
         $virtuemart_vendor_id = false;
         if ($multix == 'none' and get_class($this) !== 'TableVmusers') {
             $this->virtuemart_vendor_id = 1;
         } else {
             $loggedVendorId = Permissions::getInstance()->isSuperVendor();
             $admin = Permissions::getInstance()->check('admin');
             $tbl_key = $this->_tbl_key;
             if (get_class($this) !== 'TableVmusers') {
                 if ($this->{$tbl_key}) {
                     $q = 'SELECT `virtuemart_vendor_id` FROM `' . $this->_tbl . '` WHERE `' . $this->_tbl_key . '`="' . $this->{$tbl_key} . '" ';
                     if (!isset(self::$_query_cache[md5($q)])) {
                         $this->_db->setQuery($q);
                         $virtuemart_vendor_id = $this->_db->loadResult();
                     } else {
                         $virtuemart_vendor_id = self::$_query_cache[md5($q)];
                     }
                 } else {
                     $virtuemart_vendor_id = $loggedVendorId;
                 }
                 // insert new ;
             } else {
                 $q = 'SELECT `virtuemart_vendor_id`,`user_is_vendor` FROM `' . $this->_tbl . '` WHERE `' . $this->_tbl_key . '`="' . $this->{$tbl_key} . '" ';
                 if (!isset(self::$_query_cache[md5($q)])) {
                     $this->_db->setQuery($q);
                     $vmuser = $this->_db->loadRow();
                 } else {
                     $vmuser = self::$_query_cache[md5($q)];
                 }
                 if ($vmuser and count($vmuser) === 2) {
                     $virtuemart_vendor_id = $vmuser[0];
                     $user_is_vendor = $vmuser[1];
                     if ($multix == 'none') {
                         if (empty($user_is_vendor)) {
                             $this->virtuemart_vendor_id = 0;
                         } else {
                             $this->virtuemart_vendor_id = 1;
                         }
                         return true;
                     } else {
                         if (!$admin) {
                             $this->virtuemart_vendor_id = $loggedVendorId;
                             return true;
                         }
                     }
                 }
             }
             if (!$admin and !empty($virtuemart_vendor_id) and !empty($loggedVendorId) and $loggedVendorId != $virtuemart_vendor_id) {
                 //vmWarn('COM_VIRTUEMART_NOT_SAME_VENDOR',$loggedVendorId,$virtuemart_vendor_id
                 //vmWarn('Stop try to hack this store, you got logged');
                 vmdebug('Hacking attempt stopped, logged vendor ' . $loggedVendorId . ' but data belongs to ' . $virtuemart_vendor_id);
                 return false;
             } else {
                 if (!$admin) {
                     if ($virtuemart_vendor_id) {
                         $this->virtuemart_vendor_id = $virtuemart_vendor_id;
                         vmdebug('Non admin is storing using loaded vendor_id');
                     } else {
                         //No id is stored, even users are allowed to use for the storage and vendorId, no change
                     }
                 } else {
                     if (!empty($virtuemart_vendor_id) and $loggedVendorId != $virtuemart_vendor_id) {
                         // only display 1 time logged Vendor Msg
                         if (!self::$checkloggedVendorMsg) {
                             self::$checkloggedVendorMsg = true;
                             vmInfo('Admin vendor ' . $checkloggedVendorMsg . $loggedVendorId . ' has set vendor ' . $this->virtuemart_vendor_id . ' in recorded item');
                         }
                         $this->virtuemart_vendor_id = $virtuemart_vendor_id;
                     }
                 }
             }
         }
         //tables to consider for multivendor
         //if(get_class($this)!== 'TableOrders' and get_class($this)!== 'TableInvoices' and get_class($this)!== 'TableOrder_items'){
     }
     return true;
 }