init(); function Unescape($str) // UnescapeFunc는 아래에 정의되어 있음 { return urldecode(preg_replace_callback('/%u([[:alnum:]]{4})/', 'UnescapeFunc', $str)); } function UnescapeFunc($str) { return iconv('UTF-16LE', 'UTF-8', chr(hexdec(substr($str[1], 2, 2))).chr(hexdec(substr($str[1],0,2)))); } function getHttpContents( $sUrl, $iTimeout = 5, $bHeader = false ) { $hCurl = curl_init(); curl_setopt( $hCurl, CURLOPT_URL, $sUrl ); curl_setopt( $hCurl, CURLOPT_TIMEOUT, $iTimeout ); curl_setopt( $hCurl, CURLOPT_RETURNTRANSFER, 1 ); if ( $bHeader == true ) { curl_setopt( $hCurl, CURLOPT_HEADER, 1 ); } $sResult = curl_exec( $hCurl ); curl_close( $hCurl ); return $sResult; } //XML 파서 (외부 API에서 반환하는 xml 콜백데이터를 배열로 반환합니다.) function XMLObjectToArray2( &$objSource, $arrMultiKey = array(), $bUTF8 = false ) { if ( is_object( $objSource ) ) { $array = array(); if ( is_object( $objSource->attributes() ) ) { foreach( $objSource->attributes() as $k => $v ) { $array[ '_attributes' ][ $k ] = ( $bUTF8 == false ) ? iconv( 'UTF-8', 'EUC-KR', (string)$v ) : (string)$v; } } foreach ( $objSource as $key => $value ) { if ( (is_object($value) ) && ( count( $value ) > 0 ) ) { if ( in_array( $key, $arrMultiKey ) ) { $array[ $key ][] = XMLObjectToArray2( $value, $arrMultiKey, $bUTF8 ); } else { $array[ $key ] = XMLObjectToArray2( $value, $arrMultiKey, $bUTF8 ); } } else if ( is_object($value) ) { # 맨 마지막 Depth의 Element는 항상 한개씩 빼온다. $sValue = ( $bUTF8 == false ) ? iconv( 'UTF-8', 'EUC-KR', ( string )$value[ 0 ] ) : ( string )$value[ 0 ]; if ( in_array( $key, $arrMultiKey ) ) { $array[$key][] = $sValue; } else { $array[ $key ] = $sValue; } } else { if ( is_array( $value ) ) { $array[ $key ] = $value; } else { $array[ $key ] = ( $bUTF8 == false ) ? iconv( 'UTF-8', 'EUC-KR', ( string )$value ) : ( string )$value; } } } return $array; } return $objSource; } function XML_add_DB($fidx,$Member){ $MemberNameS = explode("|", iconv('EUC-KR', 'UTF-8',$Member)); for( $i = 0; $i0) {//중복 있을때 mysql_query("update relay_persons_2016 set amount=$MemberAmount WHERE f_idx = '$fidx' and relay_persons='$MemberName' and m_code='$MemberCode' and ord='2'"); //echo "중복"; }else{//중복없을떄 mysql_query("INSERT INTO relay_persons_2016(f_idx, relay_persons, amount, ord, m_code) VALUES('$fidx','$MemberName','$MemberAmount','2','$MemberCode')"); //echo "INSERT INTO relay_persons(f_idx, relay_persons, amount, ord) VALUES('$fidx','$MemberName','$MemberAmount','2')" . "----" .$Member."\n"; } } } $qry = "SELECT * FROM relay_person where relay_year='2016'"; $result = mysql_query( $qry ) or die( mysql_error() . "
" . $qry ); for( $i = 0; $row = mysql_fetch_array($result); $i++ ) { /* $Idx[] = $row[Idx]; $vcMemberID[] = $row[vcMemberID]; $vcUserName[] = $row[vcUserName]; $vcMail[] = $row[vcMail]; $vcType[] = $row[vcType]; $vcRegDate[] = zdate($row[vcRegDate], 'y-m-d H:i:s'); */ if ($row[relay_year]=='2012'){ $thisRelayCode = "1248"; }else if($row[relay_year]=='2013'){ $thisRelayCode = "1266"; }else if($row[relay_year]=='2014'){ $thisRelayCode = "1279";//2014년도 코드 필요 }else if($row[relay_year]=='2015'){ $thisRelayCode = "1280";//2015년도 코드 필요 }else if($row[relay_year]=='2016'){ $thisRelayCode = "1284";//2016년도 코드 필요 } $sUrl = "http://websvc2.hsit.co.kr/pages/RelaySponsors.aspx?param1=NkVUu1Q31GsMhku9iE/jvA==¶m2=".trim($row[mrm_code])."¶m3=".$thisRelayCode."¶m4=".trim($row[relay_year]); $NodeAry=array("index","txt"); //반환되는 xml의 노드값을 배열로써 받기 위해 받고자 하는 노드의 TagName을 배열로 만든다. $sHttpContents = getHttpContents( $sUrl ); $objDom = simplexml_load_string( $sHttpContents ); $arrData = XMLObjectToArray2( $objDom, $NodeAry ); if ($arrData[ResultCode]=="000"){ $err_code = "0"; $err_msg = "데이터 로딩 성공"; }else{ $err_code = "1"; $err_msg = "데이터 로딩 ERR"; } $MemberNameS_2 = explode("|", iconv('EUC-KR', 'UTF-8',$arrData[MemberName])); if ($arrData[MemberName]!=""){ XML_add_DB($row[idx],$arrData[MemberName]); } $sql = "select * from relay_persons_2016 where f_idx='$row[idx]' "; //echo $sql; $result2 = mysql_query( $sql ); $result2_dt = mysql_fetch_array($result2); $mem_1_cnt = mysql_affected_rows(); $personal_goal = $row[personal_goal]; if ( $mem_1_cnt < 1){ $err_code = "1"; $err_msg = "주자가 존재하지 않음"; } if ($mem_1_cnt > 29){ $total_juja = mysql_query("SELECT ifnull(endrun_date,'') as endrun_date FROM relay_person WHERE idx = '$row[idx]' "); //echo "SELECT ifnull(endrun_date,'') as endrun_date FROM relay_person WHERE idx = '$c_var' "; $total_juja_value = mysql_fetch_array($total_juja); if($total_juja_value[endrun_date]=="") {//등록이 안되어있을때 mysql_query("update relay_person set endrun_date=now() WHERE idx = '$row[idx]' "); } } if ($mem_1_cnt > $personal_goal){ $total_juja = mysql_query("SELECT ifnull(personal_date,'') as personal_date FROM relay_person WHERE idx = '$row[idx]' "); //echo "SELECT ifnull(personal_date,'') as personal_date FROM relay_person WHERE idx = '$c_var' "; $total_juja_value = mysql_fetch_array($total_juja); if($total_juja_value[personal_date]=="") {//등록이 안되어있을때 mysql_query("update relay_person set personal_date=now() WHERE idx = '$row[idx]' "); } } } echo "MRM data recieved.
Click here to mainpage."; ?>