📄 import.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";
if ( $FILE_NAME == "" )
{
echo "<script Language=\"JavaScript\">\r\nfunction CheckForm()\r\n{\r\n if(document.form1.CSV_FILE.value==\"\")\r\n { 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 <table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" class=\"small\">\r\n <tr>\r\n <td class=\"Big\"><img src=\"/images/sys_config.gif\" align=\"absmiddle\"><span class=\"big3\"> 导入CSV通讯簿</span><br>\r\n </td>\r\n </tr>\r\n </table>\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 <br>\r\n <input type=\"button\" value=\"返回\" class=\"BigButton\" onclick=\"location='index.php'\">\r\n </div>\r\n";
exit( );
}
if ( strtolower( substr( $FILE_NAME, -3 ) ) != "csv" )
{
message( "错误", "只能导入CSV文件!" );
button_back( );
exit( );
}
$title = array( "姓名" => "PSN_NAME", "性别" => "SEX", "昵称" => "NICK_NAME", "电子邮件地址" => "EMAIL", "电子邮件" => "EMAIL", "住宅所在街道" => "ADD_HOME", "家庭所在街道" => "ADD_HOME", "手机" => "MOBIL_NO", "移动电话" => "MOBIL_NO", "小灵通" => "BP_NO", "传呼机" => "BP_NO", "QQ" => "OICQ_NO", "MSN" => "ICQ_NO", "生日" => "BIRTHDAY", "家庭所在地邮政编码" => "POST_NO_HOME", "住宅所在地的邮政编码" => "POST_NO_HOME", "家庭所在街道" => "ADD_HOME", "住宅所在街道" => "ADD_HOME", "家庭电话1" => "TEL_NO_HOME", "住宅电话" => "TEL_NO_HOME", "公司所在地邮政编码" => "POST_NO_DEPT", "公司所在地的邮政编码" => "POST_NO_DEPT", "公司所在街道" => "ADD_DEPT", "职位" => "MINISTRATION", "职务" => "MINISTRATION", "办公电话1" => "TEL_NO_DEPT", "业务电话" => "TEL_NO_DEPT", "公司传真" => "FAX_NO_DEPT", "业务传真" => "FAX_NO_DEPT", "配偶" => "MATE", "子女" => "CHILD", "公司" => "DEPT_NAME", "附注" => "NOTES" );
$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 ) )
{
++$ROW_COUNT;
$ID_STR = "";
$VALUE_STR = "";
reset( &$title );
foreach ( $title as $key )
{
if ( !find_id( $ID_STR, $key ) )
{
if ( $key == "SEX" )
{
if ( $DATA[$key] == "女" )
{
$DATA[$key] = "1";
}
else if ( $DATA[$key] == "男" )
{
$DATA[$key] = "0";
}
else
{
$DATA[$key] = "";
}
}
$ID_STR .= $key.",";
$VALUE_STR .= "'".$DATA[$key]."',";
}
}
$ID_STR = trim( $ID_STR, "," );
$VALUE_STR = trim( $VALUE_STR, "," );
$query = "insert into ADDRESS (USER_ID,GROUP_ID,".$ID_STR.( ") values ('".$LOGIN_USER_ID."',{$GROUP_ID}," ).$VALUE_STR.");";
exequery( $connection, $query );
}
if ( file_exists( $CSV_FILE ) )
{
@unlink( $CSV_FILE );
}
message( "", "共".$ROW_COUNT."条数据导入!" );
echo "<div align=\"center\">\r\n<input type=\"button\" value=\"返回\" class=\"BigButton\" onClick=\"location='index.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 + -