⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 import.php

📁 通达网络办公 - Office Anywhere 2008 增强版100%源码(3.4.081216) 内含 通达OA2008增強版接近完美破解补丁20081216集 及 最新通达OA2008ADV(
💻 PHP
字号:
<?php

include_once( "inc/auth.php" );
include_once( "inc/utility_all.php" );
echo "<html>\r\n<head>\r\n<title>导入固定资产</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\r\n</head>\r\n<body class=\"bodycolor\" topmargin=\"5\">\r\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" class=\"small\">\r\n  <tr>\r\n    <td class=\"Big\"><img src=\"/images/menu/asset.gif\" align=\"absmiddle\"><span class=\"big3\"> 导入固定资产</span><br></td>\r\n  </tr>\r\n</table>\r\n\r\n";
if ( $FILE_NAME == "" )
{
	echo "<script Language=\"JavaScript\">\r\nfunction CheckForm()\r\n{\r\n   if(document.form1.CSV_FILE.value==\"\")\r\n   {\r\n   \t  alert(\"请选择要导入的文件!\");\r\n      return (false);\r\n   }\r\n\r\n   if (document.form1.CSV_FILE.value!=\"\")\r\n   {\r\n     var file_temp=document.form1.CSV_FILE.value,file_name;\r\n     var Pos;\r\n     Pos=file_temp.lastIndexOf(\"\\\\\");\r\n     file_name=file_temp.substring(Pos+1,file_temp.length);\r\n     document.form1.FILE_NAME.value=file_name;\r\n   }\r\n\r\n   return (true);\r\n}\r\n</script>\r\n\r\n<br>\r\n<br>\r\n\r\n<div align=\"center\" class=\"Big1\">\r\n<b>请指定用于导入的CSV文件:</b>\r\n<form name=\"form1\" method=\"post\" action=\"import.php\" enctype=\"multipart/form-data\" onsubmit=\"return CheckForm();\">\r\n  <input type=\"file\" name=\"CSV_FILE\" class=\"BigInput\" size=\"30\">\r\n  <input type=\"hidden\" name=\"FILE_NAME\">\r\n  <input type=\"hidden\" name=\"GROUP_ID\" value=\"";
	echo $GROUP_ID;
	echo "\">\r\n  <input type=\"submit\" value=\"导入\" class=\"BigButton\">\r\n</form>\r\n</div>\r\n";
	exit( );
}
if ( strtolower( substr( $FILE_NAME, -3 ) ) != "csv" )
{
	message( "错误", "只能导入CSV文件!" );
	button_back( );
	exit( );
}
$title = array( "资产编号" => "CPTL_NO", "资产名称" => "CPTL_NAME", "资产类别" => "TYPE_ID", "所属部门" => "DEPT_ID", "资产原值" => "CPTL_VAL", "残值(率)" => "CPTL_BAL", "折旧年限" => "DPCT_YY", "累计折旧" => "SUM_DPCT", "月折旧额" => "MON_DPCT", "资产性质" => "CPTL_KIND", "折旧提足" => "FINISH_FLAG", "增加日期" => "CREATE_DATE", "增加类型" => "PRCS_ID", "启用日期" => "FROM_YYMM", "减少日期" => "DCR_DATE", "减少类型" => "DCR_PRCS_ID", "保管人" => "KEEPER", "备注" => "REMARK" );
$ROW_COUNT = 0;
$data = file_get_contents( $CSV_FILE );
if ( !$data )
{
	message( "错误", "打开文件错误!" );
	button_back( );
	exit( );
}
$lines = csv2array( $data, $title );
while ( list( $I, $DATA ) = each( &$lines ) )
{
	$query = "select * from CP_ASSET_TYPE  where TYPE_NAME='".$DATA['TYPE_ID']."'";
	$cursor = exequery( $connection, $query );
	if ( $ROW = mysql_fetch_array( $cursor ) )
	{
		$DATA['TYPE_ID'] = $ROW['TYPE_ID'];
	}
	else
	{
		$lines[$I]['MSG_ERROR'] = "导入失败,资产类别 ".$DATA['TYPE_ID']." 不存在";
		continue;
	}
	$query = "select * from DEPARTMENT  where DEPT_NAME='".$DATA['DEPT_ID']."'";
	$cursor = exequery( $connection, $query );
	if ( $ROW = mysql_fetch_array( $cursor ) )
	{
		$DATA['DEPT_ID'] = $ROW['DEPT_ID'];
	}
	else
	{
		$lines[$I]['MSG_ERROR'] = "导入失败,部门 ".$DATA['DEPT_ID']." 不存在";
		continue;
	}
	$query = "SELECT * from CP_PRCS_PROP where left(PRCS_CLASS,1)='A' and PRCS_LONG_DESC='".$DATA['PRCS_ID']."'";
	$cursor = exequery( $connection, $query );
	if ( $ROW = mysql_fetch_array( $cursor ) )
	{
		$DATA['PRCS_ID'] = $ROW['PRCS_ID'];
	}
	else
	{
		$lines[$I]['MSG_ERROR'] = "导入失败,增加类型 ".$DATA['PRCS_ID']." 不存在";
		continue;
	}
	if ( $DATA['DCR_PRCS_ID'] != "" )
	{
		$query = "SELECT * from CP_PRCS_PROP where left(PRCS_CLASS,1)='D' and PRCS_LONG_DESC='".$DATA['DCR_PRCS_ID']."'";
		$cursor = exequery( $connection, $query );
		if ( $ROW = mysql_fetch_array( $cursor ) )
		{
			$DATA['DCR_PRCS_ID'] = $ROW['PRCS_ID'];
			break;
		}
		else
		{
			$lines[$I]['MSG_ERROR'] = "导入失败,减少类型 ".$DATA['DCR_PRCS_ID']." 不存在";
		}
	}
	else
	{
		$DCR_PRCS_ID['DCR_PRCS_ID'] = "0";
		do
		{
		} while ( 0 );
		if ( $DATA['FINISH_FLAG'] == "提足" )
		{
			$DATA['FINISH_FLAG'] = "1";
		}
		if ( $DATA['FINISH_FLAG'] == "未提足" )
		{
			$DATA['FINISH_FLAG'] = "0";
		}
		if ( $DATA['CPTL_KIND'] == "资产" )
		{
			$DATA['CPTL_KIND'] = "01";
		}
		if ( $DATA['CPTL_KIND'] == "费用" )
		{
			$DATA['CPTL_KIND'] = "02";
		}
		$ID_STR = "";
		$VALUE_STR = "";
		reset( &$title );
		foreach ( $title as $key )
		{
			if ( !find_id( $ID_STR, $key ) )
			{
				$ID_STR .= $key.",";
				$VALUE_STR .= "'".$DATA[$key]."',";
			}
		}
		$ID_STR = trim( $ID_STR, "," );
		$VALUE_STR = trim( $VALUE_STR, "," );
		$query = "insert into CP_CPTL_INFO (".$ID_STR.") values (".$VALUE_STR.");";
		exequery( $connection, $query );
		if ( 0 < mysql_affected_rows( ) )
		{
			++$ROW_COUNT;
		}
		else
		{
			$lines[$I]['MSG_ERROR'] = "导入失败,资产已存在";
		}
	}
}
if ( file_exists( $CSV_FILE ) )
{
	@unlink( $CSV_FILE );
}
echo "<br>\r\n<table class=\"TableList\" salign=\"center\" width=\"100%\">\r\n  <thead class=\"TableHeader\">\r\n      <td nowrap align=\"center\">资产编号</td>\r\n      <td nowrap align=\"center\">资产名称</td>\r\n      <td nowrap align=\"center\">信息</td>\r\n  </thead>\r\n";
$I = 0;
for ( ;	$I < count( $lines );	++$I	)
{
	if ( $lines[$I]['MSG_ERROR'] != "" )
	{
		$TR_STYLE = "color:#FF0000";
	}
	else
	{
		$TR_STYLE = "";
		$lines[$I]['MSG_ERROR'] = "成功";
	}
	echo "  <tr class=\"TableData\" align=\"center\" style=\"";
	echo $TR_STYLE;
	echo "\">\r\n      <td>";
	echo $lines[$I]['CPTL_NO'];
	echo "</td>\r\n      <td>";
	echo $lines[$I]['CPTL_NAME'];
	echo "</td>\r\n      <td align=\"left\">";
	echo $lines[$I]['MSG_ERROR'];
	echo "</td>\r\n  </tr>\r\n";
}
echo "</table>\r\n";
message( "信息", "共".$ROW_COUNT."条数据导入!" );
echo "<br>\r\n<div align=\"center\">\r\n<input type=\"button\" value=\"返回\" class=\"BigButton\" onClick=\"location='import.php';\" title=\"返回\">\r\n</div>\r\n\r\n</body>\r\n</html>\r\n";
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -