function parseDataType(&$data, $column, $field) { global $database; $dataval = $data[$column]; switch ($field['type']) { case 'int': if (is_numeric($dataval)) { return $dataval; } else { return 0; } break; case 'double': case 'float': if (is_float($dataval)) { return $dataval; } else { return 0; } break; case 'bool': if ($dataval == 1 or preg_match('/yes/i', $dataval)) { return 1; } else { return 0; } break; case 'date': //return toDbDate($dataval); return TimeDate::toDatabaseDate($dataval); break; case 'datetime': //return toDbDateTime($dataval); return TimeDate::toDatabaseDateTime($dataval); break; case 'time': //return toDbTime($dataval); return TimeDate::toDatabaseTime($dataval); break; case 'relate': //Locate an existing record matching the given data value //If nothing found create a skeleton record with the supplied data //Return key of supplied data in related table. $class = $field['related']; $obj = new $class($database); $related_fields = $field['related_fields']; if (count($related_fields) > 1) { $values = preg_split('/[\\s]+/', $dataval); } else { $values = array($dataval); } $max = min(count($values), count($related_fields)); $params = array(); for ($i = 0; $i < $max; $i++) { $params[$related_fields[$i]] = $values[$i]; } if (isset($field['dependency']) and !empty($field['dependency'])) { $params[$field['dependency']['key']] = getDependentField($field, $data, $_POST['importFields']); } //jTipsDebug($_POST); //jTipsDebug($dataval); //jTipsDebug($field); //jTipsDebug($params); //die(); $obj->loadByParams($params); $rel_key = $field['related_key']; if (isset($obj->{$rel_key}) and !empty($rel_key)) { return $obj->{$rel_key}; } else { if ($field['required']) { $obj->bind($params); $obj->save(); return $obj->{$rel_key}; } else { return $field['default']; } } break; case 'virtual': continue; break; case 'text': default: return mysql_real_escape_string($dataval); break; } }