Exemplo n.º 1
0
function prepare_for_db($field, $value, $controltype = "", $postfilename = "", $table = "")
{
    global $strTableName;
    if ($table == "") {
        $table = $strTableName;
    }
    $pSet = new ProjectSettings($table);
    $filename = "";
    $type = $pSet->getFieldType($field);
    if (!$controltype || $controltype == "multiselect") {
        if (is_array($value)) {
            $value = combinevalues($value);
        }
        if (($value === "" || $value === FALSE) && !IsCharType($type)) {
            return "";
        }
        if (IsGuid($type)) {
            if (!IsGuidString($value)) {
                return "";
            }
        }
        return $value;
    } else {
        if ($controltype == "time") {
            if (!strlen($value)) {
                return "";
            }
            $time = localtime2db($value);
            if (IsDateFieldType($pSet->getFieldType($field))) {
                $time = "2000-01-01 " . $time;
            }
            return $time;
        } else {
            if (substr($controltype, 0, 4) == "date") {
                $dformat = substr($controltype, 4);
                if ($dformat == EDIT_DATE_SIMPLE || $dformat == EDIT_DATE_SIMPLE_DP) {
                    $time = localdatetime2db($value);
                    if ($time == "null") {
                        return "";
                    }
                    return $time;
                } else {
                    if ($dformat == EDIT_DATE_DD || $dformat == EDIT_DATE_DD_DP) {
                        $a = explode("-", $value);
                        if (count($a) < 3) {
                            return "";
                        } else {
                            $y = $a[0];
                            $m = $a[1];
                            $d = $a[2];
                        }
                        if ($y < 100) {
                            if ($y < 70) {
                                $y += 2000;
                            } else {
                                $y += 1900;
                            }
                        }
                        return mysprintf("%04d-%02d-%02d", array($y, $m, $d));
                    } else {
                        return "";
                    }
                }
            } else {
                if (substr($controltype, 0, 8) == "checkbox") {
                    if ($value == "on") {
                        $ret = 1;
                    } else {
                        if ($value == "none") {
                            return "";
                        } else {
                            $ret = 0;
                        }
                    }
                    return $ret;
                } else {
                    return false;
                }
            }
        }
    }
}
Exemplo n.º 2
0
        $strSQL = "SELECT DISTINCT st." . $_connection->addFieldWrappers($f) . " from (" . $strSQL . ") st";
    } else {
        $strSQL = SQLQuery::gSQLWhere_having($sqlHead, $fromClause, $gQuery->WhereToSql(), $gQuery->GroupByToSql(), $gQuery->Having()->toSql($gQuery), $where, $having);
    }
    if ($_connection->dbType == nDATABASE_MySQL || $_connection->dbType == nDATABASE_PostgreSQL) {
        $strSQL .= " LIMIT " . $numberOfSuggests;
    } elseif ($_connection->dbType == nDATABASE_MSSQLServer || $_connection->dbType == nDATABASE_Access) {
        $strSQL = "select top " . $numberOfSuggests . " * from (" . $strSQL . ") st";
    } elseif ($_connection->dbType == nDATABASE_Oracle) {
        $strSQL = AddRowNumber($strSQL, $numberOfSuggests);
    }
    $qResult = $_connection->query($strSQL);
    // fill $response array with the field's suggest value
    while (($row = $qResult->fetchNumeric()) && count($response) < $numberOfSuggests) {
        $val = $cipherer->DecryptField($f, $row[0]);
        if (IsGuid($fType)) {
            $val = substr($val, 1, -1);
        }
        // "_" is added to conver number type to string
        $fieldControl->suggestValue("_" . $val, $searchFor, $response, $row);
    }
}
$_connection->close();
ksort($response, SORT_STRING);
foreach ($response as $value => $realValue) {
    if (count($result) > $numberOfSuggests) {
        break;
    }
    $strValue = $value[0] == '_' ? substr($value, 1) : $value;
    // .net compatibility issue
    $strRealValue = $realValue[0] == '_' ? substr($realValue, 1) : $realValue;
Exemplo n.º 3
0
/**
 * @param String field
 * @param Mixed value
 * @param String controltype
 * @param String postfilename
 * @param String table			The datasource table name
 * @intellisense
 */
function prepare_for_db($field, $value, $controltype = "", $postfilename = "", $table = "")
{
    global $strTableName, $cman;
    if ($table == "") {
        $table = $strTableName;
    }
    $pSet = new ProjectSettings($table);
    $connection = $cman->byTable($table);
    $filename = "";
    $type = $pSet->getFieldType($field);
    if ((!$controltype || $controltype == "multiselect") && !IsTimeType($type)) {
        if (is_array($value)) {
            $value = combinevalues($value);
        }
        if (($value === "" || $value === FALSE) && !IsCharType($type)) {
            return "";
        }
        if (IsGuid($type)) {
            if (!IsGuidString($value)) {
                return "";
            }
        }
        if (IsFloatType($type)) {
            return makeFloat($value);
        }
        if (IsNumberType($type) && !is_int($value)) {
            $value = trim($value);
            if (!is_numeric(str_replace(",", ".", $value))) {
                $value = "";
            }
        }
        return $value;
    } else {
        if ($controltype == "time" || IsTimeType($type)) {
            if (!strlen($value)) {
                return "";
            }
            $time = localtime2db($value);
            if ($connection->dbType == nDATABASE_PostgreSQL) {
                $timeArr = explode(":", $time);
                if ($timeArr[0] > 24 || $timeArr[1] > 59 || $timeArr[2] > 59) {
                    return "";
                }
            }
            if (IsDateFieldType($type)) {
                $time = "2000-01-01 " . $time;
            }
            return $time;
        } else {
            if (substr($controltype, 0, 4) == "date") {
                $dformat = substr($controltype, 4);
                if ($dformat == EDIT_DATE_SIMPLE || $dformat == EDIT_DATE_SIMPLE_INLINE || $dformat == EDIT_DATE_SIMPLE_DP) {
                    $time = localdatetime2db($value);
                    if ($time == "null") {
                        return "";
                    }
                    return $time;
                } else {
                    if ($dformat == EDIT_DATE_DD || $dformat == EDIT_DATE_DD_INLINE || $dformat == EDIT_DATE_DD_DP) {
                        $a = explode("-", $value);
                        if (count($a) < 3) {
                            return "";
                        } else {
                            $y = $a[0];
                            $m = $a[1];
                            $d = $a[2];
                        }
                        if ($y < 100) {
                            if ($y < 70) {
                                $y += 2000;
                            } else {
                                $y += 1900;
                            }
                        }
                        return mysprintf("%04d-%02d-%02d", array($y, $m, $d));
                    } else {
                        return "";
                    }
                }
            } else {
                if (substr($controltype, 0, 8) == "checkbox") {
                    if ($value == "on") {
                        $ret = 1;
                    } else {
                        if ($value == "none") {
                            return "";
                        } else {
                            $ret = 0;
                        }
                    }
                    return $ret;
                } else {
                    return false;
                }
            }
        }
    }
}