Esempio n. 1
0
function newai_import_FilterXLS()
{
    global $_FILES, $_POST, $_GET, $db;
    global $showlistfieldlist, $showlistfieldfilter;
    global $common_html, $html_etc;
    global $return_sql_line, $db;
    global $columns;
    //print_R($columns);
    global $showlistfieldlist, $showlistfieldlist_key;
    global $foreignkey, $showFieldName, $tablename;
    if (is_uploaded_file($_FILES['uploadfileXLS']['tmp_name'])) {
        $uploadfile_self = $_FILES['uploadfileXLS']['tmp_name'];
        $uploadfile_name = $_FILES['uploadfileXLS']['name'];
        $checkFileType = substr($uploadfile_name, -3);
        if ($checkFileType != "xls") {
            print_nouploadfile("你上传的不是EXCEL格式的文件!");
            exit;
        }
        //print $checkFileType;exit;
        if (!is_dir("FileCache")) {
            mkdir("FileCache");
        }
        $uploadfile_name = "FileCache/" . $uploadfile_name;
        copy($_FILES['uploadfileXLS']['tmp_name'], $uploadfile_name);
        if (is_file("../../Framework/PHPExcelParser4/readExcel.php")) {
            require_once "../../Framework/PHPExcelParser4/readExcel.php";
        } else {
            require_once "../Framework/PHPExcelParser4/readExcel.php";
            require_once "../Framework/PHPExcelParser4/readExcel.php";
        }
        $a = new ReadExcel($uploadfile_name);
        $tmp = $a->read();
        //按列读取的数据,转换为按行读取的数据
        $MainData = $tmp[0];
        $ColumnNumber = sizeof(array_values($MainData));
        for ($i = 0; $i < $ColumnNumber; $i++) {
            $ColumnArray = $MainData[$i];
            //print_R($ColumnArray);
            for ($ii = 0; $ii < sizeof($ColumnArray); $ii++) {
                $ContentText[$ii][$i] = $ColumnArray[$ii];
            }
        }
        //重新生成文本
        $ColumnNumber = sizeof(array_keys($ContentText));
        for ($i = 0; $i < $ColumnNumber; $i++) {
            $ContentArray = $ContentText[$i];
            $ContentTextArray[] = join(',', $ContentArray);
            //print_R($ContentArray);
        }
        //print_r($ContentTextArray);
        //exit;
        //数据对接区
        $file = $ContentTextArray;
    }
    return $file;
}
Esempio n. 2
0
	if(is_uploaded_file($_FILES['ExcelFile']['tmp_name']))			{
			$uploadfile_self=$_FILES['ExcelFile']['tmp_name'];
			$uploadfile_name=$_FILES['ExcelFile']['name'];
			$checkFileType = substr($uploadfile_name,-3);
			if($checkFileType!="xls")	{
				print_nouploadfile("你上传的不是EXCEL格式的文件!");
				exit;
			}
			//print $checkFileType;exit;
			if(!is_dir("FileCache")) mkdir("FileCache");
			$uploadfile_name = "FileCache/".$uploadfile_name;
			copy($_FILES['ExcelFile']['tmp_name'],$uploadfile_name);

			require_once "../../PHPExcelParser4/readExcel.php";

			$a = new ReadExcel($uploadfile_name);
			$tmp = $a->read();
			//dump($tmp);exit;


			//按列读取的数据,转换为按行读取的数据
			$MainData = $tmp[0];
			$ColumnNumber = sizeof(array_values($MainData));
			for($i=0;$i<$ColumnNumber;$i++)			{
				$ColumnArray = $MainData[$i];
				//print_R($ColumnArray);
				for($ii=0;$ii<sizeof($ColumnArray);$ii++)			{
					$ContentText[$ii][$i] = $ColumnArray[$ii];
				}
			}
			//print_r($ContentText);exit;
Esempio n. 3
0
function ImportPlanDealData()				{
	global $_FILES,$_POST,$_GET,$db;
	global $showlistfieldlist,$showlistfieldfilter;
	global $common_html,$html_etc;
	global $return_sql_line,$db;
	global $columns;//print_R($columns);
	global $showlistfieldlist,$showlistfieldlist_key;
	global $foreignkey,$showFieldName,$tablename;

	$tablename = "edu_planexec";
	$专业代码 = $_GET['专业代码'];
	$NJ = $_SESSION['SYSTEM_CURRENT_NJ'];
	$学期 = $_SESSION['SYSTEM_CURRENT_XUEQI'];

		if(is_uploaded_file($_FILES['uploadfileXLS']['tmp_name']))			{
				$uploadfile_self=$_FILES['uploadfileXLS']['tmp_name'];
				$uploadfile_name=$_FILES['uploadfileXLS']['name'];
				$checkFileType = substr($uploadfile_name,-3);
				if($checkFileType!="xls")	{
					print_nouploadfile("你上传的不是EXCEL格式的文件!");
					exit;
				}
				//print $checkFileType;exit;
				if(!is_dir("FileCache")) mkdir("FileCache");
				$uploadfile_name = "FileCache/".$uploadfile_name;
				copy($_FILES['uploadfileXLS']['tmp_name'],$uploadfile_name);

				if(is_file("../../PHPExcelParser4/readExcel.php"))	{
					require_once "../../PHPExcelParser4/readExcel.php";
				}
				else	{
					require_once "../PHPExcelParser4/readExcel.php";
					require_once "../PHPExcelParser4/readExcel.php";
				}
				$a = new ReadExcel($uploadfile_name);
				$tmp = $a->read();

				//按列读取的数据,转换为按行读取的数据
				$MainData = $tmp[0];
				$ColumnNumber = sizeof(array_values($MainData));
				for($i=0;$i<$ColumnNumber;$i++)			{
					$ColumnArray = $MainData[$i];
					//print_R($ColumnArray);
					for($ii=0;$ii<sizeof($ColumnArray);$ii++)			{
						$ContentText[$ii][$i] = $ColumnArray[$ii];
					}
				}
				//重新生成文本
				$ColumnNumber = sizeof(array_keys($ContentText));
				for($i=0;$i<$ColumnNumber;$i++)			{
					$ContentArray = $ContentText[$i];
					$ContentTextArray[] = join(',',$ContentArray);
					//print_R($ContentArray);
				}

				//print_r($ContentTextArray);
				//exit;

				//数据对接区
				$file = $ContentTextArray;

				//#################################################################
				//以下为CSV格式处理区,共同使用代码区
				//#################################################################

				//处理原有数据
				//$delete_sql_text = "delete from $tablename where 级别='$NJ' and 专业代码='$专业代码' and 开课学期='$学期'";;
				//$rs=$db->Execute($delete_sql_text);
				//$rs_a = $rs->GetArray();

				global $db;
				$first_row=trim($file[0]);
				$first_row_array=explode(',',$first_row);//导入数据中字段列表
				$result = array();
				$html_etc_edu_planexec = @array_flip($html_etc['edu_planexec']);
				//列行检测
				//2012-07-10 加入对字段显示姓名出现在EXCEL头行时进行转换为字段名称的判断工作
				for($i=0;$i<sizeof($first_row_array);$i++)			{
					$字段名称	= TRIM($first_row_array[$i]);
					if($html_etc_edu_planexec[$字段名称]!=""&&$html_etc_edu_planexec[$字段名称]!=$字段名称."_remark")		{
						$字段名称	= TRIM($html_etc_edu_planexec[$字段名称]);
					}
					$result[$i] = TRIM($字段名称);
				}
				//print_R($result);exit;
				$交换键值后的列 = @array_flip($result);

				page_css('数据导入');
				//table_begin(500);
				//数据行检测
				$Insert_RIGHT = 0;
				$Insert_ERROR = 0;
				$Update_RIGHT = 0;
				$Update_ERROR = 0;
				for($i=1;$i<sizeof($file);$i++)			{

					$PRE	= substr($file[$i],1);
					$LAST	= substr($file[$i],-1);
					if($PRE=' '||$LASH=' ')  {
						$file[$i] = ereg_replace(' ','',$file[$i]);
					}

					$line_array=explode(',',trim($file[$i]));
					//教师用户名数据过滤
					$开课教师_INDEX		= $交换键值后的列['开课教师'];
					//$教师用户名_INDEX	= $交换键值后的列['教师用户名'];
					//$line_array[$教师用户名_INDEX] = returntablefield("user","USER_NAME",$line_array[$开课教师_INDEX],"USER_ID");
					//班级代码数据过滤
					$班级名称_INDEX		= $交换键值后的列['班级名称'];
					$班级代码_INDEX	= $交换键值后的列['班级代码'];
					$班级代码_text = returntablefield("edu_banji","班级名称",$line_array[$班级名称_INDEX],"班级代码");
					$line_array[$班级代码_INDEX] = $班级代码_text;
					//级别数据过滤
					$级别_INDEX		= $交换键值后的列['级别'];
					$入学年份_text = returntablefield("edu_banji","班级名称",$line_array[$班级名称_INDEX],"入学年份");
					$line_array[$级别_INDEX] = $入学年份_text;
					//专业代码数据过滤
					$专业名称_INDEX		= $交换键值后的列['专业名称'];
					$专业代码_INDEX	= $交换键值后的列['专业代码'];
					$专业代码_text = returntablefield("edu_zhuanye","专业名称",$line_array[$专业名称_INDEX],"专业代码");
					$line_array[$专业代码_INDEX] = $专业代码_text;

					//导入过滤错误提示
					$班级名称_text = returntablefield("edu_banji","班级名称",$line_array[$班级名称_INDEX],"班级名称");
					if($班级名称_text==""){
						print "<center>班级:<font color=red>".$line_array[$班级名称_INDEX]."</font>在班级表中查询不到,会造成跟此班级相关的数据无法导入成功,请核实。</center><br>";
						continue;
					}
					if($入学年份_text==""){
						print "<center>班级:<font color=red>".$line_array[$班级名称_INDEX]."</font>在班级表中查询不到对应的<font color=red>入学年份(也就是级别)</font>,会造成跟此班级级别相关的数据无法导入成功,请核实。</center><br>";
						continue;
					}
					$专业名称_text = returntablefield("edu_zhuanye","专业名称",$line_array[$专业名称_INDEX],"专业名称");
					if($专业名称_text==""){
						print "<center>专业:<font color=red>".$line_array[$专业名称_INDEX]."</font>在专业表中查询不到,会造成跟此专业相关的数据无法导入成功,请核实。</center><br>";
						continue;
					}
					if($专业代码_text==""){
						print "<center>专业:<font color=red>".$line_array[$专业名称_INDEX]."</font>在专业表中查询不到对应的<font color=red>专业代码</font>,会造成跟此专业相关的数据无法导入成功,请核实。</center><br>";
						continue;
					}


					//专业代码数据过滤
					//echo "班级名称:::".$line_array[$班级名称_INDEX]."<br>";
					//$级别_afff = returntablefield("edu_banji","班级名称",$line_array[$班级名称_INDEX],"入学年份");
					//echo "级别_afff::".$级别_afff."<br>";

					//print_R($line_array);
					//echo "<br>";

					$line_array_text = join("','",$line_array);
					$line_array_text = "'".$line_array_text."'";
					$result_text = join("`,`",$result);
					$result_text = "`".$result_text."`";

					//echo "line_array_text::".$line_array_text."<br>";
					//echo "result_text::".$result_text."<br>";

					//清理已经重复的数据
					$课程名称_INDEX		= $交换键值后的列['课程名称'];
					$sql = "
							delete from $tablename
							where 级别='$NJ'
							and 课程名称='".$line_array[$课程名称_INDEX]."'
							and 开课教师='".$line_array[$开课教师_INDEX]."'
							and 开课学期='$学期'
							and 班级名称='".$line_array[$班级名称_INDEX]."'
							";
					/*
					$sql = "
							delete from $tablename
							where 级别='$NJ'
							and 课程名称='".$line_array[$课程名称_INDEX]."'
							and 开课学期='$学期'
							and 班级名称='".$line_array[$班级名称_INDEX]."'
							";
						*/

					//echo "delete_sql::".$sql."<br>";;
					$rs  = $db->Execute($sql);



					$sql = "INSERT INTO `".$tablename."` (".$result_text.") VALUES (".$line_array_text.");";
					//echo "INSERT_sql::".$sql."<br>";;
					$rs  = $db->Execute($sql);
					$EOF = $rs->EOF;
					if($EOF)		{
						$Insert_RIGHT +=1;
					}
					else	{
						$Insert_ERROR += 1;
					}
					//print $sql."<BR>";
				}//exit;
				//导入数据结果较验
				$Insert_Text = "处理数据成功:{$Insert_RIGHT} 条 失败:{$Insert_ERROR} 条";
				//action=PlanDetail&专业代码=111&专业名称=计算机科学与技术&年级=2008&学期=2
				//print_R($_POST);
				//print_R($_GET);
				$专业代码 = $_GET['专业代码'];
				$专业名称 = $_GET['专业名称'];
				$NJ = $_SESSION['SYSTEM_CURRENT_NJ'];
				$学期 = $_SESSION['SYSTEM_CURRENT_XUEQI'];
				print "
				<style type='text/css'>.style1 {
				color: #FFFFFF;
				font-weight: bold;
				font-family: Arial, Helvetica, sans-serif;
				font-size: 14px;
				}
				</style>
				<BR><BR>
				<table width='450'  border='0' align='center' cellpadding='0' cellspacing='0' class='small' style='border:1px solid #006699;'>
				<tr><td height='110' align='middle' colspan=2  bgcolor='#E0F2FC'>
				<font color=red >".$common_html['common_html']['importsuccess']."<BR><BR>$Insert_Text<BR><BR><input type=button accesskey='c' name='cancel' value=' 点击返回 ' class=SmallButton onClick=\"location='edu_planexec.php?".base64_encode("XX=XX&NJ=$NJ")."'\" title='快捷键:ALT+c'></font>
				</td></tr><tr></table>";
				//print "<META HTTP-EQUIV=REFRESH CONTENT='$SYSTEM_SECOND;URL=?action=init_default'>\n";
				//print_infor($common_html['common_html']['importsuccess'],'trip',"location='?action=init_default'",'?action=init_default');
				优化数据表($tablename);
				unlink($uploadfile_name);exit;
				}
				else			{
					//print "ERROR!";
					print_nouploadfile();
				}
}