📄 import.php
字号:
<?
function match ($TITLE_NAME)
{
switch ($TITLE_NAME)
{
case '部门名称':
{
return 'DEPT_NAME';
}
case '部门排序号':
{
return 'DEPT_NO';
}
case '上级部门':
{
return 'DEPT_PARENT';
}
case '部门电话':
{
return 'TEL_NO';
}
case '部门传真':
{
return 'FAX_NO';
}
case '部门职能':
{
return 'DEPT_FUNC';
}
}
}
include_once 'inc/auth.php';
include_once 'inc/conn.php';
include_once 'inc/utility.php';
echo '<html>
<head>
<title>导入部门</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body class="bodycolor" topmargin="5">
';
if ($FILE_NAME == '')
{
echo '<script Language="JavaScript">
function CheckForm()
{
if(document.form1.CSV_FILE.value=="")
{ alert("请选择要导入的文件!");
return (false);
}
if (document.form1.CSV_FILE.value!="")
{
var file_temp=document.form1.CSV_FILE.value,file_name;
var Pos;
Pos=file_temp.lastIndexOf("\\\\");
file_name=file_temp.substring(Pos+1,file_temp.length);
document.form1.FILE_NAME.value=file_name;
}
return (true);
}
</script>
<table border="0" width="100%" cellspacing="0" cellpadding="3" class="small">
<tr>
<td class="Big"><img src="/images/sys_config.gif" align="absmiddle"><span class="big3"> 导入部门</span><br>
</td>
</tr>
</table>
<br>
<br>
<div align="center" class="Big1">
<b>请指定用于导入的CSV文件:</b>
<form name="form1" method="post" action="import.php" enctype="multipart/form-data" onsubmit="return CheckForm();">
<input type="file" name="CSV_FILE" class="BigInput" size="30">
<input type="hidden" name="FILE_NAME">
<input type="hidden" name="GROUP_ID" value="';
echo $GROUP_ID;
echo '">
<input type="submit" value="导入" class="BigButton">
</form>
<br>
</div>
';
exit ();
}
if (strtolower (substr ($FILE_NAME, -3)) != 'csv')
{
message ('错误', '只能导入CSV文件!');
button_back ();
exit ();
}
$ID_STR = 'DEPT_NAME,DEPT_NO,DEPT_PARENT,TEL_NO,FAX_NO,DEPT_FUNC';
$ROW_COUNT = 0;
$handle = fopen ($CSV_FILE, 'r');
$TITLE = fgetcsv ($handle, 1000, ',');
if (!(($handle AND $TITLE)))
{
message ('错误', '打开文件错误!');
button_back ();
exit ();
}
$TITLE_NUM = count ($TITLE);
while ($DATA = fgetcsv ($handle, 66000, ','))
{
$DATA_NUM = count ($DATA);
for ($I = 0; $I < $DATA_NUM; ++$I)
{
$ID = match ($TITLE[$I]);
if (find_id ($ID_STR, $ID))
{
$DEPT[$ID] = $DATA[$I];
continue;
}
}
$query = 'select * from DEPARTMENT where DEPT_NAME=\'' . $DEPT['DEPT_PARENT'] . '\'';
$cursor = exequery ($connection, $query);
if ($ROW = mysql_fetch_array ($cursor))
{
$DEPT['DEPT_PARENT'] = $ROW['DEPT_ID'];
}
else
{
$DEPT['DEPT_PARENT'] = 0;
}
$query = 'insert into DEPARTMENT (' . $ID_STR . ') values (\'' . $DEPT['DEPT_NAME'] . '\',\'' . $DEPT['DEPT_NO'] . '\',\'' . $DEPT['DEPT_PARENT'] . '\',\'' . $DEPT['TEL_NO'] . '\',\'' . $DEPT['FAX_NO'] . '\',\'' . $DEPT['DEPT_FUNC'] . '\');';
exequery ($connection, $query);
if (0 < mysql_affected_rows ())
{
++$ROW_COUNT;
continue;
}
}
fclose ($handle);
if (file_exists ($CSV_FILE))
{
unlink ($CSV_FILE);
}
message ('', '共' . $ROW_COUNT . '条数据导入!');
echo '<div align="center">
<input type="button" value="返回" class="BigButton" onClick="location=\'import.php\';" title="返回">
</div>
</body>
</html>
';
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -