setUniqueName('name'); $this->setObligatoryKeys('title'); $this->setLoggable(); $this->setLockable(); $this->setConvertInt(array('maxlength', 'size', 'cols', 'rows')); $this->setOrderable('ordering',false); $this->_xParams = 'userfield_params'; } /** * Validates the userfields record fields. * * @return boolean True if the table buffer is contains valid data, false otherwise. */ function check() { if (preg_match('/[^a-z0-9\._\-]/i', $this->name) > 0) { vmError(vmText::_('COM_VIRTUEMART_NAME_OF_USERFIELD_CONTAINS_INVALID_CHARACTERS')); return false; } if($this->name !='virtuemart_country_id' and $this->name !='virtuemart_state_id'){ $reqValues = array('select', 'multiselect', 'radio', 'multicheckbox'); if (in_array($this->type, $reqValues) and $this->_nrOfValues == 0 ) { vmError(vmText::_('COM_VIRTUEMART_VALUES_ARE_REQUIRED_FOR_THIS_TYPE')); return false; } } return parent::check(); } /** * Format the field type * @param $_data array array with additional data written to other tables * @return string Field type in SQL syntax */ function formatFieldType(&$_data = array()) { $_fieldType = $this->type; switch($this->type) { case 'date': $_fieldType = 'DATE'; break; case 'editorta': case 'textarea': case 'multiselect': case 'multicheckbox': $_fieldType = 'MEDIUMTEXT'; break; case 'checkbox': $_fieldType = 'TINYINT'; break; case 'age_verification': //$this->params = 'minimum_age='.(int)$_data['minimum_age']."\n"; default: $_fieldType = 'VARCHAR(255)'; break; } return $_fieldType; } function checkAndDelete($table, $whereField = 0, $andWhere = ''){ $ok = 1; $k = $this->_tbl_key; if($whereField!==0){ $whereKey = $whereField; } else { $whereKey = $this->_pkey; } $query = 'SELECT `'.$this->_tbl_key.'` FROM `'.$table.'` WHERE '.$whereKey.' = "' .$this->{$k} . '"'; // stAn - it should be better to add this directly to the controller of the shopper fields // only additionally, controllers are not considered as safe. if (isset($this->name)) { $umodel = VmModel::getModel('userfields'); $arr = $umodel->getCoreFields(); if (in_array($this->name, $arr)) { vmError('Cannot delete core field! Use unpublish'); return false; } } $this->_db->setQuery( $query ); $list = $this->_db->loadColumn(); if($list){ foreach($list as $row){ $ok = $row; $query = 'DELETE FROM `'.$table.'` WHERE '.$this->_tbl_key.' = "'.$row.'"'; $this->_db->setQuery( $query ); try { $this->_db->execute(); } catch (Exception $e){ vmError('Table userfields checkAndDelete '.$e->getMessage()); $ok = 0; } } } return $ok; } } //No CLosing Tag