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

📄 import.php

📁 通达OA官方提供的30源代码,感觉很实在
💻 PHP
字号:
<?
include_once("inc/auth.php");
include_once("fun_allcompute.php");
include_once("inc/utility_all.php");
?>
<html>
<head>
<title>导入数据</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body class="bodycolor" topmargin="5">
<?
if($FILE_NAME=="")
{
 $operate="0";
 $query = "SELECT count(*) from SAL_DATA where FLOW_ID='$FLOW_ID'";
 $cursor= exequery($connection,$query);
 if($ROW=mysql_fetch_array($cursor))
 {
   $ROW_COUNT=$ROW[0];

 }

?>
<script Language="JavaScript">
 function chk(input)
  {
    for(var i=0;i<document.form1.c1.length;i++)
    {
      document.form1.c1[i].checked = false;
    }

    input.checked = true;
    return true;
  }
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>
<?
   if ($ROW_COUNT!=0)
    {
?>
      <td class="Big"><img src="/images/sys_config.gif" align="absmiddle"><span class="big3"> 导入CSV工资数据(该流程已录入过数据)</span><br>
      </td>
<?
    }
    else
    {
?>
      <td class="Big"><img src="/images/sys_config.gif" align="absmiddle"><span class="big3"> 导入CSV工资数据</span><br>
      </td>
<?
    }
?>
    </tr>
  </table>

  <br>
  <br>

  <div align="center" class="Big1">
  <b>请指定用于导入的CSV文件:</b>
  <form name="form1" method="post" action="import.php?FLOW_ID=<?=$FLOW_ID?>" 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="<?=$GROUP_ID?>">
    <input type="submit" value="导入" class="BigButton">
    <br><br>
<?
     if ($ROW_COUNT!=0)
    {
?>
     <input type="checkbox" name="c1" id="Id_c1" value="1" onClick="return chk(this);" checked><label for="Id_c1">插入新数据</label>&nbsp;&nbsp;
     <input type="checkbox" name="c1" id="Id_c2" value="2" onClick="return chk(this);" ><label for="Id_c2">更新已有的数据</label>&nbsp;&nbsp;
<?
    }
?>
   <br><br>
   <input type="checkbox" name="compute" id="Id_compute" value="1" ><label for="Id_compute">导入的同时计算所有的计算项</label>
  </form>

  <br>
  <input type="button" value="返回" class="BigButton" onClick="location='index.php'">
  <?
  if($FILE_NAME=="")
  Message("说明","1)EXECL的工资报表的列顺序为姓名、工资项目,将部门、职务等列删除;<BR>2)将改好的EXECL工资报表另存为CSV格式的文件;");
  ?>

  </div>
<?
   exit;
}

if(strtolower(substr($FILE_NAME,-3))!="csv")
{
   Message("错误","只能导入CSV文件!");
   Button_Back();
   exit;
}

$query = "SELECT ITEM_ID ,ITEM_NAME from SAL_ITEM";
$cursor= exequery($connection,$query);
$title=array();
while($ROW=mysql_fetch_array($cursor))
{
   $ITEM_NAME=$ROW["ITEM_NAME"];
   $ITEM_ID="S".$ROW["ITEM_ID"];
   $title[$ITEM_NAME]=$ITEM_ID;
}

$title+=array("姓名"=>"USER_NAME");

$ROW_COUNT = 0;
$data=file_get_contents($CSV_FILE);
$lines=CSV2Array($data,$title,",");

if(!$data)
{
   Message("错误","打开文件错误!");
   Button_Back();
   exit;
}

//echo $c1;

$operate="0";

if($c1=="2")
{
   $operate="1";
}
else
{
   $query = "delete from SAL_DATA where FLOW_ID='$FLOW_ID'";
   exequery($connection,$query);
}

if($operate=="0")
{
    foreach($lines as $line)
    {
       $STR_VALUE="";
       $STR_KEY="";
   
       foreach ($line as $key => $value) 
       {
          if ($key!="USER_NAME")
          {
		     $STR_KEY.=$key.",";
		     $STR_VALUE.="'$value'".",";
           }
	      else
	      {
	         $USER_NAME=$value;
	       }
        }
 
      if (substr($STR_KEY,-1)==",")
        $STR_KEY=substr($STR_KEY,0,-1);
      if (substr($STR_VALUE,-1)==",")
        $STR_VALUE=substr($STR_VALUE,0,-1);
	  
      $query="insert into SAL_DATA(FLOW_ID,USER_ID,";
      $query1 = "SELECT USER_ID from USER where USER_NAME='$USER_NAME'";
      $cursor1= exequery($connection,$query1);
      if(!$ROW=mysql_fetch_array($cursor1))
      {
         echo "<font color=#FF6633><b>员工".$USER_NAME."尚未在OA系统中注册!!</b></font><br>";
        continue;
       }
   
       $query.=$STR_KEY.") values ('$FLOW_ID','$ROW[0]',".$STR_VALUE.")";
       exequery($connection,$query);
       echo "员工".$USER_NAME."的工资导入完成!!<br>";
       $ROW_COUNT++;
    }
}
else
{
    foreach($lines as $line)
    {
       $STR_UPDATE="";
       
	   $query="update SAL_DATA set ";
       foreach ($line as $key => $value) 
       {
          if ($key!="USER_NAME")
          {
		     $STR_UPDATE.=$key."='".$value."',";
           }
	      else
	      {
	         $USER_NAME=$value;
	       }
        }
 
      if (substr($STR_UPDATE,-1)==",")
        $STR_UPDATE=substr($STR_UPDATE,0,-1);
      
      $query.=$STR_UPDATE;
      $query1 = "SELECT USER_ID from USER where USER_NAME='$USER_NAME'";
      $cursor1= exequery($connection,$query1);
      if(!$ROW=mysql_fetch_array($cursor1))
      {
         echo "<font color=#FF6633><b>员工".$USER_NAME."尚未在OA系统中注册!!</b></font><br>";
         continue;
      }
	  else
	  {
	     $query.=" where FLOW_ID=$FLOW_ID and USER_ID='$ROW[0]'";
	  }
   
      exequery($connection,$query);
	  echo "员工".$USER_NAME."的工资修改完成!!<br>";
      $ROW_COUNT++;
    }
}
if(file_exists($CSV_FILE))
   @unlink($CSV_FILE);

if($compute=="1") comput_allitem($FLOW_ID);
Message("","共".$ROW_COUNT."条数据导入!");

?>
<div align="center">
<input type="button" value="返回" class="BigButton" onClick="location='index.php';" title="返回">
</div>
</body>
</html>

⌨️ 快捷键说明

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