source: branches/beta/html/admin/products/upload_csv.php @ 15120

Revision 15120, 16.0 KB checked in by adati, 13 years ago (diff)

1.4.2betaのマージ

Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7mb_language('Japanese');
8
9require_once("../require.php");
10
11class LC_Page {
12    var $arrSession;
13    var $arrCSVErr;
14    function LC_Page() {
15        $this->tpl_mainpage = 'products/upload_csv.tpl';
16        $this->tpl_subnavi = 'products/subnavi.tpl';
17        $this->tpl_mainno = 'products';
18        $this->tpl_subno = 'upload_csv';
19    }
20}
21
22$conn = new SC_DBConn();
23$objPage = new LC_Page();
24$objView = new SC_AdminView();
25$objSess = new SC_Session();
26
27// ǧ¾Ú²ÄÈݤÎȽÄê
28sfIsSuccess($objSess);
29
30// ¥Õ¥¡¥¤¥ë´ÉÍý¥¯¥é¥¹
31$objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
32// ¥Õ¥¡¥¤¥ë¾ðÊó¤Î½é´ü²½
33lfInitFile();
34// ¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹
35$objFormParam = new SC_FormParam();
36// ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
37lfInitParam();
38$colmax = $objFormParam->getCount();
39$objFormParam->setHtmlDispNameArray();
40$objPage->arrTitle = $objFormParam->getHtmlDispNameArray();
41
42switch($_POST['mode']) {
43case 'csv_upload':
44    $err = false;
45    // ¥¨¥é¡¼¥Á¥§¥Ã¥¯
46    $arrErr['csv_file'] = $objUpFile->makeTempFile('csv_file');
47   
48    if($arrErr['css_file'] == "") {
49        $arrErr = $objUpFile->checkEXISTS();
50    }
51
52    // ¼Â¹Ô»þ´Ö¤òÀ©¸Â¤·¤Ê¤¤
53    set_time_limit(0);
54   
55    // ½ÐÎϤò¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤·¤Ê¤¤(==ÆüËܸ켫ưÊÑ´¹¤â¤·¤Ê¤¤)
56    ob_end_clean();
57   
58    // IE¤Î¤¿¤á¤Ë256¥Ð¥¤¥È¶õʸ»ú½ÐÎÏ
59    echo str_pad('',256);
60       
61    if($arrErr['csv_file'] == "") {
62        // °ì»þ¥Õ¥¡¥¤¥ë̾¤Î¼èÆÀ
63        $filepath = $objUpFile->getTempFilePath('csv_file');
64        // ¥¨¥ó¥³¡¼¥É
65        $enc_filepath = sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_DIR);
66       
67        // ¥ì¥³¡¼¥É¿ô¤òÆÀ¤ë
68        $rec_count = lfCSVRecordCount($enc_filepath);       
69       
70        $fp = fopen($enc_filepath, "r");
71        $line = 0;      // ¹Ô¿ô
72        $regist = 0;    // ÅÐÏ¿¿ô
73       
74        $objQuery = new SC_Query();
75        $objQuery->begin();
76       
77        echo "¢£¡¡CSVÅÐÏ¿¿ÊĽ¾õ¶· <br/><br/>\n";               
78               
79        while(!feof($fp) && !$err) {
80            $arrCSV = fgetcsv($fp, CSV_LINE_MAX);
81                       
82            // ¹Ô¥«¥¦¥ó¥È
83            $line++;
84           
85            if($line <= 1) {
86                continue;
87            }           
88                               
89            // ¹àÌÜ¿ô¥«¥¦¥ó¥È
90            $max = count($arrCSV);
91           
92            // ¹àÌÜ¿ô¤¬1°Ê²¼¤Î¾ì¹ç¤Ï̵»ë¤¹¤ë
93            if($max <= 1) {
94                continue;           
95            }
96           
97            // ¹àÌÜ¿ô¥Á¥§¥Ã¥¯
98            if($max != $colmax) {
99                echo "¢¨ ¹àÌÜ¿ô¤¬" . $max . "¸Ä¸¡½Ð¤µ¤ì¤Þ¤·¤¿¡£¹àÌÜ¿ô¤Ï" . $colmax . "¸Ä¤Ë¤Ê¤ê¤Þ¤¹¡£</br>\n";
100                $err = true;
101            } else {
102                // ¥·¡¼¥±¥ó¥¹ÇÛÎó¤ò³ÊǼ¤¹¤ë¡£
103                $objFormParam->setParam($arrCSV, true);
104                $arrRet = $objFormParam->getHashArray();
105                $objFormParam->setParam($arrRet);
106                // ÆþÎÏÃͤÎÊÑ´¹
107                $objFormParam->convParam();
108                // <br>¤Ê¤·¤Ç¥¨¥é¡¼¼èÆÀ¤¹¤ë¡£
109                $arrCSVErr = lfCheckError();
110            }
111           
112            // ÆþÎÏ¥¨¥é¡¼¥Á¥§¥Ã¥¯
113            if(count($arrCSVErr) > 0) {
114                echo "<font color=\"red\">¢£" . $line . "¹ÔÌܤǥ¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿¡£</font></br>\n";
115                foreach($arrCSVErr as $val) {
116                    echo "<font color=\"red\">$val</font></br>\n"; 
117                }
118                $err = true;
119            }
120           
121            if(!$err) {
122                lfRegistProduct($objQuery, $line);
123                $regist++;
124            }
125            $arrParam = $objFormParam->getHashArray();
126 
127            if(!$err) echo $line." / ".$rec_count. "¹ÔÌÜ¡¡¡Ê¾¦ÉÊID¡§".$arrParam['product_id']." / ¾¦ÉÊ̾¡§".$arrParam['name'].")\n<br />";
128            flush();
129        }
130        fclose($fp);
131       
132        if(!$err) {
133            $objQuery->commit();
134            echo "¢£" . $regist . "·ï¤Î¥ì¥³¡¼¥É¤òÅÐÏ¿¤·¤Þ¤·¤¿¡£";
135            // ¾¦ÉÊ·ï¿ô¥«¥¦¥ó¥È´Ø¿ô¤Î¼Â¹Ô
136            sfCategory_Count($objQuery);
137        } else {
138            $objQuery->rollback();
139        }
140    } else {
141        foreach($arrErr as $val) {
142            echo "<font color=\"red\">$val</font></br>\n"; 
143        }
144    }
145    echo "<br/><a href=\"javascript:window.close()\">¢ªÊĤ¸¤ë</a>";
146    flush();
147    exit;   
148    break;
149default:
150    break;
151}
152
153$objView->assignobj($objPage);
154$objView->display(MAIN_FRAME);
155
156//--------------------------------------------------------------------------------------------------------------------------
157
158/*
159 * ´Ø¿ô̾¡§lfInitFile
160 * ÀâÌÀ¡¡¡§¥Õ¥¡¥¤¥ë¾ðÊó¤Î½é´ü²½
161 */function lfInitFile() {
162    global $objUpFile;
163    $objUpFile->addFile("CSV¥Õ¥¡¥¤¥ë", 'csv_file', array('csv'), CSV_SIZE, true, 0, 0, false);
164}
165
166/*
167 * ´Ø¿ô̾¡§lfInitParam
168 * ÀâÌÀ¡¡¡§ÆþÎϾðÊó¤Î½é´ü²½
169 */
170function lfInitParam() {
171    global $objFormParam;
172       
173    $objFormParam->addParam("¾¦ÉÊID", "product_id", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
174    $objFormParam->addParam("¾¦Éʵ¬³ÊID", "product_class_id", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
175   
176    $objFormParam->addParam("µ¬³Ê̾1", "dummy1");
177    $objFormParam->addParam("µ¬³Ê̾2", "dummy2");
178   
179    $objFormParam->addParam("¾¦ÉÊ̾", "name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
180    $objFormParam->addParam("¸ø³«¥Õ¥é¥°(1:¸ø³« 2:Èó¸ø³«)", "status", INT_LEN, "n", array("EXIST_CHECK","MAX_LENGTH_CHECK","NUM_CHECK"));
181    $objFormParam->addParam("¾¦ÉÊ¥¹¥Æ¡¼¥¿¥¹", "product_flag", INT_LEN, "n", array("EXIST_CHECK","MAX_LENGTH_CHECK","NUM_CHECK"));
182    $objFormParam->addParam("¾¦ÉÊ¥³¡¼¥É", "product_code", STEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
183    $objFormParam->addParam(NORMAL_PRICE_TITLE, "price01", PRICE_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
184    $objFormParam->addParam(SALE_PRICE_TITLE, "price02", PRICE_LEN, "n", array("EXIST_CHECK","MAX_LENGTH_CHECK","NUM_CHECK"));
185    $objFormParam->addParam("ºß¸Ë¿ô", "stock", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
186    $objFormParam->addParam("Á÷ÎÁ", "deliv_fee", PRICE_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
187    $objFormParam->addParam("¥Ý¥¤¥ó¥ÈÉÕͿΨ", "point_rate", PERCENTAGE_LEN, "n", array("EXIST_CHECK","MAX_LENGTH_CHECK","NUM_CHECK"));
188    $objFormParam->addParam("¹ØÆþÀ©¸Â", "sale_limit", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
189    $objFormParam->addParam("¥á¡¼¥«¡¼URL", "comment1", URL_LEN, "KVa", array("SPTAB_CHECK","URL_CHECK","MAX_LENGTH_CHECK"));
190    $objFormParam->addParam("¸¡º÷¥ï¡¼¥É", "comment3", LLTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
191    $objFormParam->addParam("°ìÍ÷-¥á¥¤¥ó¥³¥á¥ó¥È", "main_list_comment", LTEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
192    $objFormParam->addParam("°ìÍ÷-¥á¥¤¥ó²èÁü", "main_list_image", LTEXT_LEN, "KVa", array("EXIST_CHECK","FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
193    $objFormParam->addParam("¥á¥¤¥ó¥³¥á¥ó¥È", "main_comment", LTEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
194    $objFormParam->addParam("¥á¥¤¥ó²èÁü", "main_image", LTEXT_LEN, "KVa", array("EXIST_CHECK","FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
195    $objFormParam->addParam("¥á¥¤¥ó³ÈÂç²èÁü", "main_large_image", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
196    $objFormParam->addParam("¥«¥é¡¼Èæ³Ó²èÁü", "file1", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
197    $objFormParam->addParam("¾¦Éʾܺ٥ե¡¥¤¥ë", "file2", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
198    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥¿¥¤¥È¥ë(1)", "sub_title1", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
199    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(1)", "sub_comment1", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
200    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö²èÁü(1)", "sub_image1", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
201    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö³ÈÂç²èÁü(1)", "sub_large_image1", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
202   
203    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥¿¥¤¥È¥ë(2)", "sub_title2", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
204    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(2)", "sub_comment2", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
205    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö²èÁü(2)", "sub_image2", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
206    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö³ÈÂç²èÁü(2)", "sub_large_image2", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
207   
208    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥¿¥¤¥È¥ë(3)", "sub_title3", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
209    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(3)", "sub_comment3", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
210    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö²èÁü(3)", "sub_image3", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
211    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö³ÈÂç²èÁü(3)", "sub_large_image3", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
212       
213    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥¿¥¤¥È¥ë(4)", "sub_title4", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
214    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(4)", "sub_comment4", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
215    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö²èÁü(4)", "sub_image4", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
216    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö³ÈÂç²èÁü(4)", "sub_large_image4", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
217       
218    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥¿¥¤¥È¥ë(5)", "sub_title5", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
219    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(5)", "sub_comment5", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
220    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö²èÁü(5)", "sub_image5", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
221    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö³ÈÂç²èÁü(5)", "sub_large_image5", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
222   
223    $objFormParam->addParam("ȯÁ÷ÆüÌÜ°Â", "deliv_date_id", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
224   
225    for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
226        $objFormParam->addParam("¤ª¤¹¤¹¤á¾¦ÉÊ($cnt)", "recommend_product_id$cnt", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
227        $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È($cnt)", "recommend_comment$cnt", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
228    }
229   
230    $objFormParam->addParam("¾¦ÉÊ¥«¥Æ¥´¥ê", "category_id", STEXT_LEN, "n", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
231}
232
233/*
234 * ´Ø¿ô̾¡§lfRegistProduct
235 * °ú¿ô1 ¡§SC_Query¥ª¥Ö¥¸¥§¥¯¥È
236 * ÀâÌÀ¡¡¡§¾¦ÉÊÅÐÏ¿
237 */
238function lfRegistProduct($objQuery, $line = "") {
239    global $objFormParam;
240    $arrRet = $objFormParam->getHashArray();
241   
242    // dtb_products°Ê³°¤ËÅÐÏ¿¤µ¤ì¤ëÃͤò½ü³°¤¹¤ë¡£
243    foreach($arrRet as $key => $val) {
244        switch($key) {
245        case 'product_code':
246        case 'price01':
247        case 'price02':
248        case 'stock':
249        case 'product_class_id':
250        case 'recommend_product_id1':
251        case 'recommend_product_id2':
252        case 'recommend_product_id3':
253        case 'recommend_product_id4':
254        case 'recommend_product_id5':
255        case 'recommend_product_id6':
256        case 'recommend_comment1':
257        case 'recommend_comment2':
258        case 'recommend_comment3':
259        case 'recommend_comment4':
260        case 'recommend_comment5':
261        case 'recommend_comment6':
262            break;
263        default:
264            if(!ereg("^dummy", $key)) {
265                $sqlval[$key] = $val;
266            }
267            break;
268        }
269    }
270    // ÅÐÏ¿»þ´Ö¤òÀ¸À®(DB¤Înow()¤À¤Ècommit¤·¤¿ºÝ¡¢¤¹¤Ù¤ÆƱ°ì¤Î»þ´Ö¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦)
271    $time = date("Y-m-d H:i:s");
272    // Éðʲ¼¤òÀ¸À®
273    if($line != "") {
274        $microtime = sprintf("%06d", $line);
275        $time .= ".$microtime";
276    }   
277    $sqlval['update_date'] = $time;
278    $sqlval['creator_id'] = $_SESSION['member_id'];
279       
280    if($sqlval['sale_limit'] == "") {
281        $sqlval['sale_unlimited'] = '1';
282    } else {
283        $sqlval['sale_unlimited'] = '0';       
284    }
285   
286    if($sqlval['status'] == "") {
287        $sqlval['status'] = 2;
288    }
289
290    if($arrRet['product_id'] != "" && $arrRet['product_class_id'] != "") {
291        // ¥«¥Æ¥´¥êÆâ¥é¥ó¥¯¤ÎÄ´À°½èÍý
292        $old_catid = $objQuery->get("dtb_products", "category_id", "product_id = ?", array($arrRet['product_id']));
293        sfMoveCatRank($objQuery, "dtb_products", "product_id", "category_id", $old_catid, $arrRet['category_id'], $arrRet['product_id']);
294
295        // UPDATE¤Î¼Â¹Ô
296        $where = "product_id = ?";
297        $objQuery->update("dtb_products", $sqlval, $where, array($sqlval['product_id']));
298    } else {
299
300        // postgresql¤Èmysql¤È¤Ç½èÍý¤òʬ¤±¤ë
301        if (DB_TYPE == "pgsql") {
302            $product_id = $objQuery->nextval("dtb_products","product_id");
303        }elseif (DB_TYPE == "mysql") {
304            $product_id = $objQuery->get_auto_increment("dtb_products");
305        }
306        $sqlval['product_id'] = $product_id;
307        // ¿·µ¬ÅÐÏ¿
308        // postgresql¤Èmysql¤È¤Ç½èÍý¤òʬ¤±¤ë
309        if (DB_TYPE == "pgsql") {
310            $product_id = $objQuery->nextval("dtb_products","product_id");
311        }elseif (DB_TYPE == "mysql") {
312            $product_id = $objQuery->get_auto_increment("dtb_products");
313        }
314       
315        $sqlval['product_id'] = $product_id;
316        $sqlval['create_date'] = $time;
317       
318        // ¥«¥Æ¥´¥êÆâ¤ÇºÇÂç¤Î¥é¥ó¥¯¤ò³ä¤êÅö¤Æ¤ë
319        $sqlval['rank'] = $objQuery->max("dtb_products", "rank", "category_id = ?", array($arrRet['category_id'])) + 1;
320       
321        // INSERT¤Î¼Â¹Ô
322        $objQuery->insert("dtb_products", $sqlval);
323    }
324   
325    // µ¬³ÊÅÐÏ¿
326    lfRegistProductClass($objQuery, $arrRet, $sqlval['product_id'], $arrRet['product_class_id']);
327   
328    // ¤ª¤¹¤¹¤á¾¦ÉÊÅÐÏ¿
329    $objQuery->delete("dtb_recommend_products", "product_id = ?", array($sqlval['product_id']));
330    for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
331        $keyname = "recommend_product_id" . $i;
332        $comment_key = "recommend_comment" . $i;
333        if($arrRet[$keyname] != "") {
334            $arrProduct = $objQuery->select("product_id", "dtb_products", "product_id = ?", array($arrRet[$keyname]));
335            if($arrProduct[0]['product_id'] != "") {
336                $arrval['product_id'] = $sqlval['product_id'];
337                $arrval['recommend_product_id'] = $arrProduct[0]['product_id'];
338                $arrval['comment'] = $arrRet[$comment_key];
339                $arrval['update_date'] = "Now()";
340                $arrval['create_date'] = "Now()";
341                $arrval['creator_id'] = $_SESSION['member_id'];
342                $arrval['rank'] = RECOMMEND_PRODUCT_MAX - $i + 1;
343                $objQuery->insert("dtb_recommend_products", $arrval);
344            }
345        }
346    }
347}
348
349/*
350 * ´Ø¿ô̾¡§lfRegistProductClass
351 * °ú¿ô1 ¡§SC_Query¥ª¥Ö¥¸¥§¥¯¥È
352 * °ú¿ô2 ¡§¾¦Éʵ¬³Ê¾ðÊóÇÛÎó
353 * °ú¿ô3 ¡§¾¦ÉÊID
354 * °ú¿ô4 ¡§¾¦Éʵ¬³ÊID
355 * ÀâÌÀ¡¡¡§¾¦Éʵ¬³ÊÅÐÏ¿
356 */
357function lfRegistProductClass($objQuery, $arrList, $product_id, $product_class_id) {
358    $sqlval['product_code'] = $arrList["product_code"];
359    $sqlval['stock'] = $arrList["stock"];
360    if($sqlval['stock'] == "") {
361        $sqlval['stock_unlimited'] = '1';
362    } else {
363        $sqlval['stock_unlimited'] = '0';       
364    }
365    $sqlval['price01'] = $arrList['price01'];
366    $sqlval['price02'] = $arrList['price02'];
367    $sqlval['creator_id'] = $_SESSION['member_id'];
368    if($sqlval['member_id'] == "") {
369        $sqlval['creator_id'] = '0';
370    }
371       
372    if($product_class_id == "") {
373        // ¿·µ¬ÅÐÏ¿
374        $where = "product_id = ?";
375        // Ç°¤Î¤¿¤á¤Ë´û¸¤Îµ¬³Ê¤òºï½ü
376        $objQuery->delete("dtb_products_class", $where, array($product_id));
377        $sqlval['product_id'] = $product_id;
378        $sqlval['classcategory_id1'] = '0';
379        $sqlval['classcategory_id2'] = '0';
380        $sqlval['create_date'] = "now()";
381        $objQuery->insert("dtb_products_class", $sqlval);
382    } else {
383        // ´û¸ÊÔ½¸
384        $where = "product_id = ? AND product_class_id = ?";
385        $objQuery->update("dtb_products_class", $sqlval, $where, array($product_id, $product_class_id));   
386    }
387}
388
389/*
390 * ´Ø¿ô̾¡§lfCheckError
391 * ÀâÌÀ¡¡¡§ÆþÎÏ¥Á¥§¥Ã¥¯
392 */
393function lfCheckError() {
394    global $objFormParam;
395    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
396    $arrRet =  $objFormParam->getHashArray();
397    $objErr = new SC_CheckError($arrRet);
398    $objErr->arrErr = $objFormParam->checkError(false);
399   
400    if(count($objErr->arrErr) == 0) {
401        $objQuery = new SC_Query();
402        // ¾¦ÉÊID¡¢µ¬³ÊID¤Î¸ºß¥Á¥§¥Ã¥¯
403        if($arrRet['product_id'] != "") {
404            $count = $objQuery->count("dtb_products", "product_id = ?", array($arrRet['product_id']));
405            if($count == 0) {
406                $objErr->arrErr['product_id'] = "¢¨ »ØÄê¤Î¾¦ÉÊID¤Ï¡¢ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£";
407            }
408        }
409               
410        if($arrRet['product_class_id'] != "") {
411            $count = 0;
412            if($arrRet['product_id'] != "") {
413                $count = $objQuery->count("dtb_products_class", "product_id = ? AND product_class_id = ?", array($arrRet['product_id'], $arrRet['product_class_id']));
414            }
415            if($count == 0) {
416                $objErr->arrErr['product_class_id'] = "¢¨ »ØÄê¤Îµ¬³ÊID¤Ï¡¢ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£";
417            }
418        }
419       
420        // ¸ºß¤¹¤ë¥«¥Æ¥´¥êID¤«¥Á¥§¥Ã¥¯
421        $count = $objQuery->count("dtb_category", "category_id = ?", array($arrRet['category_id']));
422        if($count == 0) {
423            $objErr->arrErr['product_id'] = "¢¨ »ØÄê¤Î¥«¥Æ¥´¥êID¤Ï¡¢ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£";
424        }
425    }
426    return $objErr->arrErr;
427}
428
429/*
430 * ´Ø¿ô̾¡§lfCSVRecordCount
431 * ÀâÌÀ¡¡¡§CSV¤Î¥«¥¦¥ó¥È¿ô¤òÆÀ¤ë
432 * °ú¿ô1 ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹
433 */
434function lfCSVRecordCount($file_name) {
435   
436    $count = 0;
437    $fp = fopen($file_name, "r");
438    while(!feof($fp)) {
439        $arrCSV = fgetcsv($fp, CSV_LINE_MAX);
440        $count++;
441    }
442   
443    return $count-1;
444}
445?>
Note: See TracBrowser for help on using the repository browser.