function importTXTData($content, $tableName, $sType)
{
    $fieldConfigList = '';
    $splList = '';
    $listStr = '';
    $splStr = '';
    $splxx = '';
    $s = '';
    $sql = '';
    $nOK = '';
    $fieldName = '';
    $fieldType = '';
    $fieldValue = '';
    $addFieldList = '';
    $addValueList = '';
    $updateValueList = '';
    $fieldStr = '';
    $tableName = aspTrim(lCase($tableName));
    //表
    //这样做是为了从GitHub下载时它把vbcrlf转成 chr(10)  20160409
    if (inStr($content, vbCrlf()) == false) {
        $content = replace($content, chr(10), vbCrlf());
    }
    $fieldConfigList = lCase(getFieldConfigList($GLOBALS['db_PREFIX'] . $tableName));
    $splStr = aspSplit($fieldConfigList, ',');
    $splList = aspSplit($content, vbCrlf() . '-------------------------------');
    $nOK = 0;
    foreach ($splList as $key => $listStr) {
        $addFieldList = '';
        //添加字段列表清空
        $addValueList = '';
        //添加字段列表值
        $updateValueList = '';
        //修改字段列表
        $s = lCase(newGetStrCut($listStr, '#stop#'));
        if ($s != '1' && $s != 'true') {
            foreach ($splStr as $key => $fieldStr) {
                if ($fieldStr != '') {
                    $splxx = aspSplit($fieldStr, '|');
                    $fieldName = $splxx[0];
                    $fieldType = $splxx[1];
                    if (inStr($listStr, '【' . $fieldName . '】') > 0) {
                        $listStr = $listStr . vbCrlf();
                        //加个换行是为了让最后一个参数能添加进去 20160629
                        if ($addFieldList != '') {
                            $addFieldList = $addFieldList . ',';
                            $addValueList = $addValueList . ',';
                            $updateValueList = $updateValueList . ',';
                        }
                        $addFieldList = $addFieldList . $fieldName;
                        $fieldValue = newGetStrCut($listStr, $fieldName);
                        if ($fieldType == 'textarea') {
                            $fieldValue = contentTranscoding($fieldValue);
                        }
                        //call echo(tableName,fieldName)
                        //文章大类
                        if (($tableName == 'articledetail' || $tableName == 'webcolumn') && $fieldName == 'parentid') {
                            //call echo(tableName,fieldName)
                            //call echo("fieldValue",fieldValue)
                            $fieldValue = getColumnId($fieldValue);
                            //call echo("fieldValue",fieldValue)
                            //后台菜单
                        } else {
                            if ($tableName == 'listmenu' && $fieldName == 'parentid') {
                                $fieldValue = getListMenuId($fieldValue);
                            }
                        }
                        if ($fieldType == 'date' && $fieldValue == '') {
                            $fieldValue = aspDate();
                        } else {
                            if (($fieldType == 'time' || $fieldType == 'now') && $fieldValue == '') {
                                $fieldValue = now();
                            }
                        }
                        if ($fieldType != 'yesno' && $fieldType != 'numb') {
                            $fieldValue = '\'' . $fieldValue . '\'';
                            //默认数值类型为0
                        } else {
                            if ($fieldValue == '') {
                                $fieldValue = 0;
                            }
                        }
                        $addValueList = $addValueList . $fieldValue;
                        //添加值
                        $updateValueList = $updateValueList . $fieldName . '=' . $fieldValue;
                        //修改值
                    }
                }
            }
            //字段列表不为空
            if ($addFieldList != '') {
                if ($sType == '修改') {
                    $sql = 'update ' . $GLOBALS['db_PREFIX'] . '' . $tableName . ' set ' . $updateValueList;
                } else {
                    $sql = 'insert into ' . $GLOBALS['db_PREFIX'] . '' . $tableName . ' (' . $addFieldList . ') values(' . $addValueList . ')';
                }
                //检测SQL
                if (checkSql($sql) == false) {
                    eerr('出错提示', '<hr>sql=' . $sql . '<br>');
                }
                $nOK = $nOK + 1;
            } else {
                $nOK = batchImportColumnList($splStr, $listStr, $nOK, $tableName);
            }
        }
    }
    $importTXTData = $nOK;
    //call echo("sql",sql)
    //call echo("addFieldList",addFieldList)
    //call echo("updateValueList",updateValueList)
    return @$importTXTData;
}
Beispiel #2
0
function getPostSql($id, $tableName, $fieldNameList)
{
    $valueStr = '';
    $editValueStr = '';
    $sql = '';
    $splStr = '';
    $splxx = '';
    $s = '';
    $fieldList = '';
    $fieldName = '';
    $defaultFieldValue = '';
    //字段名称
    $fieldSetType = '';
    //字段设置类型
    $fieldValue = '';
    //字段值
    $systemFieldList = '';
    //表字段列表
    $systemFieldList = getHandleFieldList($GLOBALS['db_PREFIX'] . $tableName, '字段配置列表');
    $postFieldList = '';
    //post字段列表
    $splPost = '';
    $fieldContent = '';
    $fieldConfig = '';
    $postFieldList = getFormFieldList();
    //以后再把下面与上面这两种处理方法事成一种看看行不行
    $splPost = aspSplit($postFieldList, '|');
    foreach ($splPost as $key => $fieldName) {
        $fieldContent = @$_POST[$fieldName];
        if (inStr($systemFieldList, ',' . $fieldName . '|') > 0 && inStr(',' . $fieldList . ',', ',' . $fieldName . ',') == false) {
            //为自定义的
            if (inStr($fieldNameList, ',' . $fieldName . '|') > 0) {
                $fieldConfig = mid($fieldNameList, inStr($fieldNameList, ',' . $fieldName . '|') + 1, -1);
            } else {
                $fieldConfig = mid($systemFieldList, inStr($systemFieldList, ',' . $fieldName . '|') + 1, -1);
            }
            $fieldConfig = mid($fieldConfig, 1, inStr($fieldConfig, ',') - 1);
            //call echo("config",fieldConfig)
            //call echo(fieldName,fieldContent)
            //call echo("fieldConfig",fieldConfig)
            $splxx = aspSplit($fieldConfig . '|||', '|');
            $fieldName = $splxx[0];
            //字段名称
            $fieldSetType = $splxx[1];
            //字段设置类型
            $defaultFieldValue = $splxx[2];
            //默认字段值
            $fieldValue = ADSqlRf($fieldName);
            //代替上面,因为它处理了'符号
            //call echo("fieldValue",fieldValue)
            //排序密码不处理
            if ($fieldValue != '#NO******NO#') {
                //md5加密
                if ($fieldSetType == 'md5') {
                    $fieldValue = myMD5($fieldValue);
                }
                if ($fieldSetType == 'yesno') {
                    if ($fieldValue == '') {
                        $fieldValue = $defaultFieldValue;
                    }
                    //不为数字类型加单引号
                } else {
                    if ($fieldSetType == 'numb') {
                        if ($fieldValue == '') {
                            $fieldValue = $defaultFieldValue;
                        }
                    } else {
                        if ($fieldName == 'flags') {
                            //PHP里用法
                            if (EDITORTYPE == 'php') {
                                if ($fieldValue != '') {
                                    $fieldValue = '|' . arrayToString($fieldValue, '|');
                                }
                            } else {
                                $fieldValue = '|' . arrayToString(aspSplit($fieldValue, ', '), '|');
                            }
                            $fieldValue = '\'' . $fieldValue . '\'';
                            //为时间
                        } else {
                            if ($fieldSetType == 'time' || $fieldSetType == 'now') {
                                if ($fieldValue == '') {
                                    $fieldValue = now();
                                }
                                $fieldValue = '\'' . $fieldValue . '\'';
                                //为时期
                            } else {
                                if ($fieldSetType == 'date') {
                                    if ($fieldValue == '') {
                                        $fieldValue = aspDate();
                                    }
                                    $fieldValue = '\'' . $fieldValue . '\'';
                                } else {
                                    $fieldValue = '\'' . $fieldValue . '\'';
                                }
                            }
                        }
                    }
                }
                $fieldValue = unescape($fieldValue);
                //解码20160418
                if ($valueStr != '') {
                    $valueStr = $valueStr . ',';
                    $editValueStr = $editValueStr . ',';
                }
                $valueStr = $valueStr . $fieldValue;
                $editValueStr = $editValueStr . $fieldName . '=' . $fieldValue;
            }
            if ($fieldList != '') {
                $fieldList = $fieldList . ',';
            }
            $fieldList = $fieldList . $fieldName;
        }
    }
    //自定义字段是否需要写入默认值  有的
    $splStr = aspSplit($fieldNameList, ',');
    foreach ($splStr as $key => $s) {
        if (inStr($s, '|') > 0) {
            $splxx = aspSplit($s . '|||', '|');
            $fieldName = $splxx[0];
            //字段名称
            $fieldSetType = $splxx[1];
            //字段设置类型
            $fieldValue = $splxx[2];
            //默认字段值
            if (inStr($systemFieldList, ',' . $fieldName . '|') > 0 && inStr(',' . $fieldList . ',', ',' . $fieldName . ',') == false) {
                if ($fieldSetType == 'date' && $fieldValue == '') {
                    $fieldValue = aspDate();
                } else {
                    if (($fieldSetType == 'time' || $fieldSetType == 'now') && $fieldValue == '') {
                        $fieldValue = now();
                    }
                }
                if ($fieldSetType != 'yesno' && $fieldSetType != 'numb') {
                    $fieldValue = '\'' . $fieldValue . '\'';
                }
                if ($fieldList != '') {
                    $fieldList = $fieldList . ',';
                    $valueStr = $valueStr . ',';
                    $editValueStr = $editValueStr . ',';
                }
                $fieldList = $fieldList . $fieldName;
                $valueStr = $valueStr . $fieldValue;
                $editValueStr = $editValueStr . $fieldName . '=' . $fieldValue;
                //call echo(fieldName,fieldSetType)
            }
        }
    }
    if ($id == '') {
        $sql = 'insert into ' . $GLOBALS['db_PREFIX'] . '' . $tableName . ' (' . $fieldList . ',updatetime) values(' . $valueStr . ',\'' . now() . '\')';
    } else {
        $sql = 'update ' . $GLOBALS['db_PREFIX'] . '' . $tableName . ' set ' . $editValueStr . ',updatetime=\'' . now() . '\' where id=' . $id;
    }
    $getPostSql = $sql;
    return @$getPostSql;
}
Beispiel #3
0
function now()
{
    return aspDate() . ' ' . aspTime();
}