MINI SHELL

Server : Apache/2.2.2 (Fedora)
System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686
User : apache ( 48)
PHP Version : 5.2.9
Disable Function : NONE
Directory :  /home/pathumthani_integration/integration/application/import_export/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/pathumthani_integration/integration/application/import_export/import.php
<?php
	session_start();
	require_once('../../common/classXML/xml2array.inc.php');
	require_once('../../config/config_epm.inc.php');
	require_once '../../common/classExcel/xls_reader/reader.php';
		require_once '../industry/function/function.inc.php';
	$complete=0;
	$noncom=0;
	$profile_id=$ProfileID;
    
    function getRealIpAddr(){
		if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
		{
		  $ip=$_SERVER['HTTP_CLIENT_IP'];
		}
		elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
		{
		  $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
		}
		else
		{
		  $ip=$_SERVER['REMOTE_ADDR'];
		}
		return $ip;
	}
	
	function excel2xml($filename_xml,$key){
    $irow=0;
	  $data = new Spreadsheet_Excel_Reader();
		$data->setOutputEncoding('UTF-8');		
		$data->read($filename_xml);
		$str_xml="<$key>\n";
        $icount=0;
		for ($i = 1 ; $i <= $data->sheets[0]['numRows'] ; $i++) {   //rows 
        $icount++;
		$strdata="";
		   for ($f = 1 ; $f <= $data->sheets[0]['numCols'] ; $f++) {   //rows     
				if($i==1){//cloumn
					$arr_column[$f]=$data->sheets[0]['cells'][$i][$f] ;	
				}else{//data
			    	$xkey=$arr_column[$f];
					$values=$data->sheets[0]['cells'][$i][$f] ;	
				    $strdata.="<$xkey>$values</$xkey>\n";
				}
			
		   }
		if($icount>1){//cloumn	
				 $str_xml.="<rec>$strdata</rec>\n";
				
			}
            
         if($icount==60){              
           $arr_xml[$irow]="<?xml version=\"1.0\" encoding=\"TIS-620\"?>".$str_xml."</$key>\n"; 
           $str_xml="<$key>\n"; 
           $irow++; 
           $icount=0;
         }   
            
		}
        if($icount>0){              
           $arr_xml[$irow]="<?xml version=\"1.0\" encoding=\"TIS-620\"?>".$str_xml."</$key>\n"; 
           $str_xml="<$key>\n"; 

         }   
        
		return $arr_xml;
        
		
	}
    
    
    
	function getSql($profile_id, $arr_xml, $pid='0',$import_sql='',$main_element='') {
		global $Conn;
		global $arr_sql_return; 		
		if ( count($arr_xml) >= 1 ) {

			foreach ( $arr_xml as $key => $arr ){ # foreach 1
				foreach ( $arr_xml[$key] as $element => $val){ # foreach 2
                    
					if ( $element != 'closetag' and $element != 'elements' and $element != 'text' ) {
						$sql = "SELECT * FROM tbl_xmldata WHERE PROFILE_ID='$profile_id' AND ELEMENT='$val' ";
						$result = mysql_query($sql);
						while($o=mysql_fetch_object($result)){
							if ( trim($o->IMPORT_SQL_STRING) != "" ) {              
								$import_sql_send =  $o->IMPORT_SQL_STRING;
								$main_element_send = $val;
							} else{
								$import_sql_send = '';
								$main_element_send = '';
							}
						}
					}else if($element == 'text'){
                      //  $val=str_replace("/","-",$val) ;
                       if($val!=""){
                          $val=iconv('UTF-8','TIS-620',$val);  
                       }
                       // echo $val; 
                         
						$import_sql = str_replace($main_element."::".$arr_xml[$key][name],$val,$import_sql);
					}else if($element == 'elements'){
						getSql($profile_id, $val, $pid,$import_sql_send,$main_element_send);
					}
				} # foreach 2
			} # foreach 1

			if ( $import_sql ) $arr_sql_return[] = $import_sql;
		} else {
			return -1;
		}
	} # end function
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<link href="../..//styles/styles.css" rel="stylesheet" type="text/css" />
<title><?=$title_name?></title>
<script language="JavaScript" type="text/javascript">
		function showStatus($total,$value){
			//alert($value);
			//alert(document.getElementById('show_1'));
			document.getElementById('show_1').innerHTML="["+$value+"/"+$total+"]";
		}
</script>
<table width="99%" border="0" cellspacing="0" cellpadding="0">
      <tr>
            <td>
            		<span id="show_1"></span>
            </td>                                      
            <td>&nbsp;</td>
            <td>&nbsp;</td>
      </tr>
</table>
<?	
	# ส่วนสั่งการ import และการแสดงผล
	if ( $_GET['ProfileID'] && $_GET['xmlfile'] ) {	
	
	
		$xml_file_name = $_GET['xmlfile'];
		$file_target = "file_temp/";
	 	$furl = $file_target . $xml_file_name;
		$XMLstrSQL = "SELECT ELEMENT FROM tbl_xmldata WHERE PROFILE_ID='".$_GET['ProfileID']."' AND PID='0' LIMIT 1";
		$XMLrsConn = mysql_query($XMLstrSQL);
		$XMLResult = mysql_fetch_object($XMLrsConn);		
		$table_name = $XMLResult->ELEMENT;
		if($im_type=="xml"){
			 $xml_data = implode("",file($furl));
		 }else{
            // echo"$furl:$table_name";
		      $xml_data=excel2xml($furl,$table_name);
		 }	

    
     $arr=array();
     $arr_xml =array();
     foreach($xml_data as $in =>$xml){
       $arr=xml2array($xml); # shwArray($arr_xml);  
           
      array_push($arr_xml,$arr[0])  ;
     }
	
       //print_r($arr_xml); 
      // echo"<hr>";
	
        
		$arr_sql_return = array(); 
		getSql($_GET['ProfileID'], $arr_xml);
		$numTotal=count($arr_sql_return);
		$numValue=0;

		foreach( $arr_sql_return as $key => $val ){
			$val = str_replace("\\", "",$val);
			$arr_val=explode(';',$val);// multi query;
			foreach($arr_val as $index=>$values_sql){
				//echo "$values_sql<br>";
				if(trim($values_sql)!=""){
					$rs = mysql_query($values_sql)or die(mysql_error());	
					}
						
			}  		
			//$errNo = mysql_errno($Conn);
			//$errComplain = mysql_error($Conn);
			$numValue++;
			/*print"<script language='JavaScript'> showStatus($numTotal,$numValue); </script> ";*/
			if($rs){
				//echo "&nbsp;<font color=blue><strong>Query Success</strong> :: $val</font><br>";	
				$complete++;		
			}else{
				//echo "&nbsp;<font color=red><strong>Query False</strong> :: $val [$errNo : $errComplain]</font><br>";	
				$noncom++;
			}
		}
		
		#Add Log
		$sql_insert_log ="INSERT INTO tbl_xmlimport_log 
									SET profile_id='".$_GET['ProfileID']."', 
									ip='".getRealIpAddr()."' ,
									user_id='".$_SESSION['session_staffid']."', 
									filename='".$_GET['xmlfile']."', 
									filetype='".$_GET['im_type']."',
									import_complete='".$complete."', 
									import_no_complete='".$noncom."',
									import_sum='".($noncom+$complete)."',
									update_date=NOW(),
									create_date=NOW()
									 ";
			mysql_query($sql_insert_log)or die(mysql_error());	
		
	}


  ?>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#B4B4B4">
		<table width="100%" border="0" cellpadding="5" cellspacing="1">
      <tr>
        <td bgcolor="#FFFFFF" align="center">
        
        <table width="50%" border="0" cellpadding="3" cellspacing="1" bgcolor="#0066CC">
        		<tr bgcolor="#FFFFFF">
                		<td width="200"><strong>ผู้นำเข้าข้อมูล</strong></td>
                        <td align="center"><?=$_SESSION[session_fullname]?></td>
                </tr>
                <tr bgcolor="#FFFFFF">
                		<td width="200"><strong>วันเวลาการนำเข้าข้อมูล</strong></td>
                        <td align="center">
						<?
						echo dateFormat(date("Y-m-d"),'thaidot');
						echo ' เวลา '.date("H:i:s");
						/*$sqlTime="	SELECT update_time FROM industry		";
						$rsTime=mysql_db_query($dbname,$sqlTime);
						$resTime=mysql_fetch_assoc($rsTime);
						echo $resTime['update_time'];*/
						?></td>
                </tr>
        		<tr bgcolor="#4774b5">
                		<td width="200"><strong></strong></td>
                        <td align="center"><strong>จำนวน(แถว)</strong></td>
                </tr>
        		<tr bgcolor="#FFFFFF">
                		<td width="200"><strong>import ข้อมูลได้</strong></td>
                        <td align="center"><?=$complete?></td>
                </tr>
                <tr bgcolor="#FFFFFF">
                		<td><strong>ไม่สามารถ import ข้อมูลได้</strong></td>
                        <td align="center"><?=$noncom?></td>
                </tr>
                <tr bgcolor="#FFFFFF">
                		<td><strong>รวม</strong></td>
                        <td align="center"><?=($noncom+$complete)?></td>
                </tr>
        </table>

</td></tr></table></td></tr></table>
<?


?>

Anon7 - 2021