#180 상품 엑셀 일괄등록 기능 추가

This commit is contained in:
chicpro
2013-05-29 16:44:15 +09:00
parent 64212a5c8d
commit fdb4a4cc57
6 changed files with 1574 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
$sub_menu = '400300';
include_once('./_common.php');
auth_check($auth[$sub_menu], "w");
$g4['titile'] = '상품 엑셀일괄등록';
include_once(G4_PATH.'/head.sub.php');
?>
<p>
엑셀파일을 이용하여 상품을 일괄등록할 수 있습니다. 상품일괄등록용 엑셀파일을 다운로드 후 상품 정보를 입력합니다.
수정이 완료된 엑셀파일을 업로드하시면 상품이 일괄등록됩니다. 엑셀파일을 저장하실 때는 Excel 97 - 2003 통합문서 (*.xls) 로 저장하셔야 합니다.
</p>
<p>
<a href="<?php echo G4_URL; ?>/<?php echo G4_LIB_DIR; ?>/Excel/itemexcel.xls">엑세파일 다운로드</a>
</p>
<form name="fitemexcel" method="post" action="./itemexcelupdate.php" enctype="MULTIPART/FORM-DATA" autocomplete="off">
<table>
<tr>
<td>파일선택</td>
<td><input type="file" name="excelfile"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="상품등록">
<button type="button" onclick="window.close();">닫기</button>
</td>
</tr>
</table>
</form>
<?php
include_once(G4_PATH.'/tail.sub.php');
?>

View File

@ -0,0 +1,176 @@
<?php
$sub_menu = '400300';
include_once('./_common.php');
auth_check($auth[$sub_menu], "w");
if($_FILES['excelfile']['tmp_name']) {
$file = $_FILES['excelfile']['tmp_name'];
include_once(G4_LIB_PATH.'/Excel/reader.php');
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$data->setOutputEncoding('UTF-8');
/***
* if you want you can change 'iconv' to mb_convert_encoding:
* $data->setUTFEncoder('mb');
*
**/
/***
* By default rows & cols indeces start with 1
* For change initial index use:
* $data->setRowColOffset(0);
*
**/
/***
* Some function for formatting output.
* $data->setDefaultFormat('%.2f');
* setDefaultFormat - set format for columns with unknown formatting
*
* $data->setColumnFormat(4, '%.3f');
* setColumnFormat - set format for column (apply only to number fields)
*
**/
$data->read($file);
/*
$data->sheets[0]['numRows'] - count rows
$data->sheets[0]['numCols'] - count columns
$data->sheets[0]['cells'][$i][$j] - data from $i-row $j-column
$data->sheets[0]['cellsInfo'][$i][$j] - extended info about cell
$data->sheets[0]['cellsInfo'][$i][$j]['type'] = "date" | "number" | "unknown"
if 'type' == "unknown" - use 'raw' value, because cell contain value with format '0.00';
$data->sheets[0]['cellsInfo'][$i][$j]['raw'] = value if cell without format
$data->sheets[0]['cellsInfo'][$i][$j]['colspan']
$data->sheets[0]['cellsInfo'][$i][$j]['rowspan']
*/
error_reporting(E_ALL ^ E_NOTICE);
$dup_it_id = array();
$dup_count = 0;
$total_count = 0;
$fail_count = 0;
$succ_count = 0;
$comma = '';
$sql = " INSERT INTO {$g4['shop_item_table']}
( it_id, ca_id, ca_id2, ca_id3, it_name, it_gallery, it_maker, it_origin, it_brand, it_model, it_type1, it_type2, it_type3, it_type4, it_type5, it_basic, it_explan, it_mobile_explan, it_explan_html, it_cust_price, it_price, it_point, it_sell_email, it_use, it_stock_qty, it_time, it_ip, it_order, it_tel_inq, it_img1, it_img2, it_img3, it_img4, it_img5, it_img6, it_img7, it_img8, it_img9, it_img10 )
VALUES ";
for ($i = 3; $i <= $data->sheets[0]['numRows']; $i++) {
$total_count++;
$it_id = addslashes($data->sheets[0]['cells'][$i][1]);
$ca_id = addslashes($data->sheets[0]['cells'][$i][2]);
$ca_id2 = addslashes($data->sheets[0]['cells'][$i][3]);
$ca_id3 = addslashes($data->sheets[0]['cells'][$i][4]);
$it_name = addslashes($data->sheets[0]['cells'][$i][5]);
$it_gallery = addslashes($data->sheets[0]['cells'][$i][6]);
$it_maker = addslashes($data->sheets[0]['cells'][$i][7]);
$it_origin = addslashes($data->sheets[0]['cells'][$i][8]);
$it_brand = addslashes($data->sheets[0]['cells'][$i][9]);
$it_model = addslashes($data->sheets[0]['cells'][$i][10]);
$it_type1 = addslashes($data->sheets[0]['cells'][$i][11]);
$it_type2 = addslashes($data->sheets[0]['cells'][$i][12]);
$it_type3 = addslashes($data->sheets[0]['cells'][$i][13]);
$it_type4 = addslashes($data->sheets[0]['cells'][$i][14]);
$it_type5 = addslashes($data->sheets[0]['cells'][$i][15]);
$it_basic = addslashes($data->sheets[0]['cells'][$i][16]);
$it_explan = addslashes($data->sheets[0]['cells'][$i][17]);
$it_mobile_explan = addslashes($data->sheets[0]['cells'][$i][18]);
$it_cust_price = addslashes($data->sheets[0]['cells'][$i][19]);
$it_price = addslashes($data->sheets[0]['cells'][$i][20]);
$it_tel_inq = addslashes($data->sheets[0]['cells'][$i][21]);
$it_point = addslashes($data->sheets[0]['cells'][$i][22]);
$it_sell_email = addslashes($data->sheets[0]['cells'][$i][23]);
$it_use = addslashes($data->sheets[0]['cells'][$i][24]);
$it_stock_qty = addslashes($data->sheets[0]['cells'][$i][25]);
$it_order = addslashes($data->sheets[0]['cells'][$i][26]);
$it_img1 = addslashes($data->sheets[0]['cells'][$i][27]);
$it_img2 = addslashes($data->sheets[0]['cells'][$i][28]);
$it_img3 = addslashes($data->sheets[0]['cells'][$i][29]);
$it_img4 = addslashes($data->sheets[0]['cells'][$i][30]);
$it_img5 = addslashes($data->sheets[0]['cells'][$i][31]);
$it_img6 = addslashes($data->sheets[0]['cells'][$i][32]);
$it_img7 = addslashes($data->sheets[0]['cells'][$i][33]);
$it_img8 = addslashes($data->sheets[0]['cells'][$i][34]);
$it_img9 = addslashes($data->sheets[0]['cells'][$i][35]);
$it_img10 = addslashes($data->sheets[0]['cells'][$i][36]);
if(!$it_id || !$ca_id || !$it_name) {
$fail_count++;
continue;
}
// it_id 중복체크
$sql2 = " select count(*) as cnt from {$g4['shop_item_table']} where it_id = '$it_id' ";
$row2 = sql_fetch($sql2);
if($row2['cnt']) {
$dup_it_id[] = $it_id;
$dup_count++;
$fail_count++;
continue;
}
// 기본분류체크
$sql2 = " select count(*) as cnt from {$g4['shop_category_table']} where ca_id = '$ca_id' ";
$row2 = sql_fetch($sql2);
if(!$row2['cnt']) {
$fail_count++;
continue;
}
$sql .= $comma." ( '$it_id', '$ca_id', '$ca_id2', '$ca_id3', '$it_name', '$it_gallery', '$it_maker', '$it_origin', '$it_brand', '$it_model', '$it_type1', '$it_type2', '$it_type3', '$it_type4', '$it_type5', '$it_basic', '$it_explan', '$it_mobile_explan', '1', '$it_cust_price', '$it_price', '$it_point', '$it_sell_email', '$it_use', '$it_stock_qty', '".G4_TIME_YMDHIS."', '".$_SERVER['REMOTE_ADDR']."', '$it_order', '$it_tel_inq', '$it_img1', '$it_img2', '$it_img3', '$it_img4', '$it_img5', '$it_img6', '$it_img7', '$it_img8', '$it_img9', '$it_img10' ) ";
$comma = ' , ';
$succ_count++;
}
if($succ_count > 0)
sql_query($sql);
}
$g4['title'] = '상품 엑셀일괄등록';
include_once(G4_PATH.'/head.sub.php');
?>
<p>
상품등록을 완료했습니다.
</p>
<p>
총상품수 : <?php echo number_format($total_count); ?>
</p>
<p>
완료건수 : <?php echo number_format($succ_count); ?>
</p>
<p>
실패건수 : <?php echo number_format($fail_count); ?>
</p>
<?php if($dup_count > 0) { ?>
<p>
상품코드중복건수 : <?php echo number_format($dup_count); ?>
</p>
<p>
중복상품코드 : <?php echo implode(', ', $dup_it_id); ?>
</p>
<p>
<button type="button" onclick="window.close();">닫기</button>
</p>
<?php } ?>
<?php
include_once(G4_PATH.'/tail.sub.php');
?>

View File

@ -131,6 +131,7 @@ if ($sfl || $stx) // 검색렬일 때만 처음 버튼을 보여줌
<div id="btn_add">
<a href="./itemform.php">상품등록</a>
<a href="./itemexcel.php" onclick="return excelform(this.href);" target="_blank">상품일괄등록</a>
<a href="./itemsellrank.php" class="btn_add_optional">상품판매순위</a>
</div>
@ -222,6 +223,13 @@ $(function() {
return false;
});
});
function excelform(url)
{
var opt = "width=600,height=450,left=10,top=10";
window.open(url, "win_excel", opt);
return false;
}
</script>
<?php

BIN
lib/Excel/itemexcel.xls Normal file

Binary file not shown.

271
lib/Excel/oleread.inc Normal file
View File

@ -0,0 +1,271 @@
<?php
define('NUM_BIG_BLOCK_DEPOT_BLOCKS_POS', 0x2c);
define('SMALL_BLOCK_DEPOT_BLOCK_POS', 0x3c);
define('ROOT_START_BLOCK_POS', 0x30);
define('BIG_BLOCK_SIZE', 0x200);
define('SMALL_BLOCK_SIZE', 0x40);
define('EXTENSION_BLOCK_POS', 0x44);
define('NUM_EXTENSION_BLOCK_POS', 0x48);
define('PROPERTY_STORAGE_BLOCK_SIZE', 0x80);
define('BIG_BLOCK_DEPOT_BLOCKS_POS', 0x4c);
define('SMALL_BLOCK_THRESHOLD', 0x1000);
// property storage offsets
define('SIZE_OF_NAME_POS', 0x40);
define('TYPE_POS', 0x42);
define('START_BLOCK_POS', 0x74);
define('SIZE_POS', 0x78);
define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
//echo 'ROOT_START_BLOCK_POS = '.ROOT_START_BLOCK_POS."\n";
//echo bin2hex($data[ROOT_START_BLOCK_POS])."\n";
//echo "a=";
//echo $data[ROOT_START_BLOCK_POS];
//function log
function GetInt4d($data, $pos)
{
$value = ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24);
if ($value>=4294967294)
{
$value=-2;
}
return $value;
}
class OLERead {
var $data = '';
function OLERead(){
}
function read($sFileName){
// check if file exist and is readable (Darko Miljanovic)
if(!is_readable($sFileName)) {
$this->error = 1;
return false;
}
$this->data = @file_get_contents($sFileName);
if (!$this->data) {
$this->error = 1;
return false;
}
//echo IDENTIFIER_OLE;
//echo 'start';
if (substr($this->data, 0, 8) != IDENTIFIER_OLE) {
$this->error = 1;
return false;
}
$this->numBigBlockDepotBlocks = GetInt4d($this->data, NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
$this->sbdStartBlock = GetInt4d($this->data, SMALL_BLOCK_DEPOT_BLOCK_POS);
$this->rootStartBlock = GetInt4d($this->data, ROOT_START_BLOCK_POS);
$this->extensionBlock = GetInt4d($this->data, EXTENSION_BLOCK_POS);
$this->numExtensionBlocks = GetInt4d($this->data, NUM_EXTENSION_BLOCK_POS);
/*
echo $this->numBigBlockDepotBlocks." ";
echo $this->sbdStartBlock." ";
echo $this->rootStartBlock." ";
echo $this->extensionBlock." ";
echo $this->numExtensionBlocks." ";
*/
//echo "sbdStartBlock = $this->sbdStartBlock\n";
$bigBlockDepotBlocks = array();
$pos = BIG_BLOCK_DEPOT_BLOCKS_POS;
// echo "pos = $pos";
$bbdBlocks = $this->numBigBlockDepotBlocks;
if ($this->numExtensionBlocks != 0) {
$bbdBlocks = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS)/4;
}
for ($i = 0; $i < $bbdBlocks; $i++) {
$bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);
$pos += 4;
}
for ($j = 0; $j < $this->numExtensionBlocks; $j++) {
$pos = ($this->extensionBlock + 1) * BIG_BLOCK_SIZE;
$blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, BIG_BLOCK_SIZE / 4 - 1);
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; $i++) {
$bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);
$pos += 4;
}
$bbdBlocks += $blocksToRead;
if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
$this->extensionBlock = GetInt4d($this->data, $pos);
}
}
// var_dump($bigBlockDepotBlocks);
// readBigBlockDepot
$pos = 0;
$index = 0;
$this->bigBlockChain = array();
for ($i = 0; $i < $this->numBigBlockDepotBlocks; $i++) {
$pos = ($bigBlockDepotBlocks[$i] + 1) * BIG_BLOCK_SIZE;
//echo "pos = $pos";
for ($j = 0 ; $j < BIG_BLOCK_SIZE / 4; $j++) {
$this->bigBlockChain[$index] = GetInt4d($this->data, $pos);
$pos += 4 ;
$index++;
}
}
//var_dump($this->bigBlockChain);
//echo '=====2';
// readSmallBlockDepot();
$pos = 0;
$index = 0;
$sbdBlock = $this->sbdStartBlock;
$this->smallBlockChain = array();
while ($sbdBlock != -2) {
$pos = ($sbdBlock + 1) * BIG_BLOCK_SIZE;
for ($j = 0; $j < BIG_BLOCK_SIZE / 4; $j++) {
$this->smallBlockChain[$index] = GetInt4d($this->data, $pos);
$pos += 4;
$index++;
}
$sbdBlock = $this->bigBlockChain[$sbdBlock];
}
// readData(rootStartBlock)
$block = $this->rootStartBlock;
$pos = 0;
$this->entry = $this->__readData($block);
/*
while ($block != -2) {
$pos = ($block + 1) * BIG_BLOCK_SIZE;
$this->entry = $this->entry.substr($this->data, $pos, BIG_BLOCK_SIZE);
$block = $this->bigBlockChain[$block];
}
*/
//echo '==='.$this->entry."===";
$this->__readPropertySets();
}
function __readData($bl) {
$block = $bl;
$pos = 0;
$data = '';
while ($block != -2) {
$pos = ($block + 1) * BIG_BLOCK_SIZE;
$data = $data.substr($this->data, $pos, BIG_BLOCK_SIZE);
//echo "pos = $pos data=$data\n";
$block = $this->bigBlockChain[$block];
}
return $data;
}
function __readPropertySets(){
$offset = 0;
//var_dump($this->entry);
while ($offset < strlen($this->entry)) {
$d = substr($this->entry, $offset, PROPERTY_STORAGE_BLOCK_SIZE);
$nameSize = ord($d[SIZE_OF_NAME_POS]) | (ord($d[SIZE_OF_NAME_POS+1]) << 8);
$type = ord($d[TYPE_POS]);
//$maxBlock = strlen($d) / BIG_BLOCK_SIZE - 1;
$startBlock = GetInt4d($d, START_BLOCK_POS);
$size = GetInt4d($d, SIZE_POS);
$name = '';
for ($i = 0; $i < $nameSize ; $i++) {
$name .= $d[$i];
}
$name = str_replace("\x00", "", $name);
$this->props[] = array (
'name' => $name,
'type' => $type,
'startBlock' => $startBlock,
'size' => $size);
if (($name == "Workbook") || ($name == "Book")) {
$this->wrkbook = count($this->props) - 1;
}
if ($name == "Root Entry") {
$this->rootentry = count($this->props) - 1;
}
//echo "name ==$name=\n";
$offset += PROPERTY_STORAGE_BLOCK_SIZE;
}
}
function getWorkBook(){
if ($this->props[$this->wrkbook]['size'] < SMALL_BLOCK_THRESHOLD){
// getSmallBlockStream(PropertyStorage ps)
$rootdata = $this->__readData($this->props[$this->rootentry]['startBlock']);
$streamData = '';
$block = $this->props[$this->wrkbook]['startBlock'];
//$count = 0;
$pos = 0;
while ($block != -2) {
$pos = $block * SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, SMALL_BLOCK_SIZE);
$block = $this->smallBlockChain[$block];
}
return $streamData;
}else{
$numBlocks = $this->props[$this->wrkbook]['size'] / BIG_BLOCK_SIZE;
if ($this->props[$this->wrkbook]['size'] % BIG_BLOCK_SIZE != 0) {
$numBlocks++;
}
if ($numBlocks == 0) return '';
//echo "numBlocks = $numBlocks\n";
//byte[] streamData = new byte[numBlocks * BIG_BLOCK_SIZE];
//print_r($this->wrkbook);
$streamData = '';
$block = $this->props[$this->wrkbook]['startBlock'];
//$count = 0;
$pos = 0;
//echo "block = $block";
while ($block != -2) {
$pos = ($block + 1) * BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, BIG_BLOCK_SIZE);
$block = $this->bigBlockChain[$block];
}
//echo 'stream'.$streamData;
return $streamData;
}
}
}
?>

1084
lib/Excel/reader.php Normal file

File diff suppressed because it is too large Load Diff