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

📄 import.php

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

if ( $KEY != 2007 )
{
	include_once( "inc/auth.php" );
}
include_once( "inc/utility_all.php" );
include_once( "inc/utility_org.php" );
echo "<html>\n<head>\n<title>导入部门</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n</head>\n<body class=\"bodycolor\" topmargin=\"5\">\n";
if ( $FILE_NAME == "" )
{
	echo "<script Language=\"JavaScript\">\nfunction CheckForm()\n{\n   if(document.form1.CSV_FILE.value==\"\")\n   { alert(\"请选择要导入的文件!\");\n     return (false);\n   }\n\n   if (document.form1.CSV_FILE.value!=\"\")\n   {\n     var file_temp=document.form1.CSV_FILE.value,file_name;\n     var Pos;\n     Pos=file_temp.lastIndexOf(\"\\\\\");\n     file_name=file_temp.substring(Pos+1,file_temp.length);\n     document.form1.FILE_NAME.value=file_name;\n   }\n\n   return (true);\n}\n</script>\n\n  <table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" class=\"small\">\n    <tr>\n      <td class=\"Big\"><img src=\"/images/sys_config.gif\" align=\"absmiddle\"><span class=\"big3\"> 导入部门</span><br>\n      </td>\n    </tr>\n  </table>\n\n  <br>\n  <br>\n\n  <div align=\"center\" class=\"Big1\">\n  <b>请指定用于导入的CSV文件:</b>\n  <form name=\"form1\" method=\"post\" action=\"import.php\" enctype=\"multipart/form-data\" onsubmit=\"return CheckForm();\">\n    <input type=\"file\" name=\"CSV_FILE\" class=\"BigInput\" size=\"30\">\n    <input type=\"hidden\" name=\"FILE_NAME\">\n    <input type=\"hidden\" name=\"GROUP_ID\" value=\"";
	echo $GROUP_ID;
	echo "\">\n    <input type=\"submit\" value=\"导入\" class=\"BigButton\">\n  </form>\n  <br>\n  </div>\n";
	if ( $KEY == 2007 )
	{
		echo "中&国&兵&器&工&业&信&息&中&心& 版-权-所-有:tongda2000.com";
	}
	exit( );
}
if ( strtolower( substr( $FILE_NAME, -3 ) ) != "csv" )
{
	message( "错误", "只能导入CSV文件!" );
	button_back( );
	exit( );
}
$title = array( "部门名称" => "DEPT_NAME", "部门排序号" => "DEPT_NO", "上级部门" => "DEPT_PARENT", "部门电话" => "TEL_NO", "部门传真" => "FAX_NO", "部门职能" => "DEPT_FUNC" );
setlocale( LC_ALL, ".936" );
$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 ) )
{
	if ( $DATA['DEPT_NAME'] == "" )
	{
		$lines[$I]['MSG_ERROR'] = "导入失败,部门名称为空";
	}
	else
	{
		$query = "select * from DEPARTMENT where DEPT_NAME='".$DATA['DEPT_NAME']."'";
		$cursor = exequery( $connection, $query );
		if ( 0 < mysql_num_rows( $cursor ) )
		{
			$lines[$I]['MSG_ERROR'] = "导入失败,部门 ".$DATA['DEPT_NAME']." 已经存在";
		}
		else
		{
			$query = "select * from DEPARTMENT where DEPT_NAME='".$DATA['DEPT_PARENT']."'";
			$cursor = exequery( $connection, $query );
			if ( $ROW = mysql_fetch_array( $cursor ) )
			{
				$DATA['DEPT_PARENT'] = $ROW['DEPT_ID'];
			}
			else
			{
				$DATA['DEPT_PARENT'] = 0;
			}
			$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 DEPARTMENT (".$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>\n<table class=\"TableList\" width=\"100%\" align=\"center\">\n  <thead class=\"TableHeader\">\n      <td nowrap align=\"center\">部门名称</td>\n      <td nowrap align=\"center\">排序号</td>\n      <td nowrap align=\"center\">上级部门</td>\n      <td nowrap align=\"center\">信息</td>\n  </thead>\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 "\">\n      <td>";
	echo $lines[$I]['DEPT_NAME'];
	echo "</td>\n      <td>";
	echo $lines[$I]['DEPT_NO'];
	echo "</td>\n      <td>";
	echo $lines[$I]['DEPT_PARENT'];
	echo "</td>\n      <td align=\"left\">";
	echo $lines[$I]['MSG_ERROR'];
	echo "</td>\n  </tr>\n";
}
echo "</table>\n";
message( "", "共".$ROW_COUNT."条数据导入!" );
cache_department( );
echo "<div align=\"center\">\n<input type=\"button\" value=\"返回\" class=\"BigButton\" onClick=\"location='import.php';\" title=\"返回\">\n</div>\n\n</body>\n</html>\n";
?>

⌨️ 快捷键说明

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