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

Revision 14919, 16.2 KB checked in by uehara, 15 years ago (diff)

CSVアップロード改修
MySQLのauto_incrementバグに対応

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    $objFormParam->addParam("¤ª¤¹¤¹¤á¾¦ÉÊ(1)", "recommend_product_id1", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
226    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(1)", "recommend_comment1", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
227    $objFormParam->addParam("¤ª¤¹¤¹¤á¾¦ÉÊ(2)", "recommend_product_id2", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
228    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(2)", "recommend_comment2", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
229    $objFormParam->addParam("¤ª¤¹¤¹¤á¾¦ÉÊ(3)", "recommend_product_id3", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
230    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(3)", "recommend_comment3", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
231    $objFormParam->addParam("¤ª¤¹¤¹¤á¾¦ÉÊ(4)", "recommend_product_id4", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
232    $objFormParam->addParam("¾ÜºÙ-¥µ¥Ö¥³¥á¥ó¥È(4)", "recommend_comment4", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
233
234    $objFormParam->addParam("¾¦ÉÊ¥«¥Æ¥´¥ê", "category_id", STEXT_LEN, "n", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
235}
236
237/*
238 * ´Ø¿ô̾¡§lfRegistProduct
239 * °ú¿ô1 ¡§SC_Query¥ª¥Ö¥¸¥§¥¯¥È
240 * ÀâÌÀ¡¡¡§¾¦ÉÊÅÐÏ¿
241 */
242function lfRegistProduct($objQuery, $line = "") {
243    global $objFormParam;
244    $arrRet = $objFormParam->getHashArray();
245   
246    // dtb_products°Ê³°¤ËÅÐÏ¿¤µ¤ì¤ëÃͤò½ü³°¤¹¤ë¡£
247    foreach($arrRet as $key => $val) {
248        switch($key) {
249        case 'product_code':
250        case 'price01':
251        case 'price02':
252        case 'stock':
253        case 'product_class_id':
254        case 'recommend_product_id1':
255        case 'recommend_product_id2':
256        case 'recommend_product_id3':
257        case 'recommend_product_id4':
258        case 'recommend_product_id5':
259        case 'recommend_product_id6':
260        case 'recommend_comment1':
261        case 'recommend_comment2':
262        case 'recommend_comment3':
263        case 'recommend_comment4':
264        case 'recommend_comment5':
265        case 'recommend_comment6':
266            break;
267        default:
268            if(!ereg("^dummy", $key)) {
269                $sqlval[$key] = $val;
270            }
271            break;
272        }
273    }
274    // ÅÐÏ¿»þ´Ö¤òÀ¸À®(DB¤Înow()¤À¤Ècommit¤·¤¿ºÝ¡¢¤¹¤Ù¤ÆƱ°ì¤Î»þ´Ö¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦)
275    $time = date("Y-m-d H:i:s");
276    // Éðʲ¼¤òÀ¸À®
277    if($line != "") {
278        $microtime = sprintf("%06d", $line);
279        $time .= ".$microtime";
280    }   
281    $sqlval['update_date'] = $time;
282    $sqlval['creator_id'] = $_SESSION['member_id'];
283       
284    if($sqlval['sale_limit'] == "") {
285        $sqlval['sale_unlimited'] = '1';
286    } else {
287        $sqlval['sale_unlimited'] = '0';       
288    }
289   
290    if($sqlval['status'] == "") {
291        $sqlval['status'] = 2;
292    }
293
294    if($arrRet['product_id'] != "" && $arrRet['product_class_id'] != "") {
295        // ¥«¥Æ¥´¥êÆâ¥é¥ó¥¯¤ÎÄ´À°½èÍý
296        $old_catid = $objQuery->get("dtb_products", "category_id", "product_id = ?", array($arrRet['product_id']));
297        sfMoveCatRank($objQuery, "dtb_products", "product_id", "category_id", $old_catid, $arrRet['category_id'], $arrRet['product_id']);
298
299        // UPDATE¤Î¼Â¹Ô
300        $where = "product_id = ?";
301        $objQuery->update("dtb_products", $sqlval, $where, array($sqlval['product_id']));
302    } else {
303
304        // ¿·µ¬ÅÐÏ¿
305        $product_id = $objQuery->nextval("dtb_products", "product_id");
306        $sqlval['product_id'] = $product_id;
307        $sqlval['create_date'] = $time;
308       
309        // ¥«¥Æ¥´¥êÆâ¤ÇºÇÂç¤Î¥é¥ó¥¯¤ò³ä¤êÅö¤Æ¤ë
310        $sqlval['rank'] = $objQuery->max("dtb_products", "rank", "category_id = ?", array($arrRet['category_id'])) + 1;
311       
312        // INSERT¤Î¼Â¹Ô
313        $objQuery->insert("dtb_products", $sqlval);
314    }
315   
316    // µ¬³ÊÅÐÏ¿
317    lfRegistProductClass($objQuery, $arrRet, $sqlval['product_id'], $arrRet['product_class_id']);
318   
319    // ¤ª¤¹¤¹¤á¾¦ÉÊÅÐÏ¿
320    $objQuery->delete("dtb_recommend_products", "product_id = ?", array($sqlval['product_id']));
321    for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
322        $keyname = "recommend_product_id" . $i;
323        $comment_key = "recommend_comment" . $i;
324        if($arrRet[$keyname] != "") {
325            $arrProduct = $objQuery->select("product_id", "dtb_products", "product_id = ?", array($arrRet[$keyname]));
326            if($arrProduct[0]['product_id'] != "") {
327                $arrval['product_id'] = $sqlval['product_id'];
328                $arrval['recommend_product_id'] = $arrProduct[0]['product_id'];
329                $arrval['comment'] = $arrRet[$comment_key];
330                $arrval['update_date'] = "Now()";
331                $arrval['create_date'] = "Now()";
332                $arrval['creator_id'] = $_SESSION['member_id'];
333                $arrval['rank'] = RECOMMEND_PRODUCT_MAX - $i + 1;
334                $objQuery->insert("dtb_recommend_products", $arrval);
335            }
336        }
337    }
338}
339
340/*
341 * ´Ø¿ô̾¡§lfRegistProductClass
342 * °ú¿ô1 ¡§SC_Query¥ª¥Ö¥¸¥§¥¯¥È
343 * °ú¿ô2 ¡§¾¦Éʵ¬³Ê¾ðÊóÇÛÎó
344 * °ú¿ô3 ¡§¾¦ÉÊID
345 * °ú¿ô4 ¡§¾¦Éʵ¬³ÊID
346 * ÀâÌÀ¡¡¡§¾¦Éʵ¬³ÊÅÐÏ¿
347 */
348function lfRegistProductClass($objQuery, $arrList, $product_id, $product_class_id) {
349    $sqlval['product_code'] = $arrList["product_code"];
350    $sqlval['stock'] = $arrList["stock"];
351    if($sqlval['stock'] == "") {
352        $sqlval['stock_unlimited'] = '1';
353    } else {
354        $sqlval['stock_unlimited'] = '0';       
355    }
356    $sqlval['price01'] = $arrList['price01'];
357    $sqlval['price02'] = $arrList['price02'];
358    $sqlval['creator_id'] = $_SESSION['member_id'];
359    if($sqlval['member_id'] == "") {
360        $sqlval['creator_id'] = '0';
361    }
362       
363    if($product_class_id == "") {
364        // ¿·µ¬ÅÐÏ¿
365        $where = "product_id = ?";
366        // Ç°¤Î¤¿¤á¤Ë´û¸¤Îµ¬³Ê¤òºï½ü
367        $objQuery->delete("dtb_products_class", $where, array($product_id));
368        $sqlval['product_id'] = $product_id;
369        $sqlval['classcategory_id1'] = '0';
370        $sqlval['classcategory_id2'] = '0';
371        $sqlval['create_date'] = "now()";
372        $objQuery->insert("dtb_products_class", $sqlval);
373    } else {
374        // ´û¸ÊÔ½¸
375        $where = "product_id = ? AND product_class_id = ?";
376        $objQuery->update("dtb_products_class", $sqlval, $where, array($product_id, $product_class_id));   
377    }
378}
379
380/*
381 * ´Ø¿ô̾¡§lfCheckError
382 * ÀâÌÀ¡¡¡§ÆþÎÏ¥Á¥§¥Ã¥¯
383 */
384function lfCheckError() {
385    global $objFormParam;
386    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
387    $arrRet =  $objFormParam->getHashArray();
388    $objErr = new SC_CheckError($arrRet);
389    $objErr->arrErr = $objFormParam->checkError(false);
390   
391    if(count($objErr->arrErr) == 0) {
392        $objQuery = new SC_Query();
393        // ¾¦ÉÊID¡¢µ¬³ÊID¤Î¸ºß¥Á¥§¥Ã¥¯
394        if($arrRet['product_id'] != "") {
395            $count = $objQuery->count("dtb_products", "product_id = ?", array($arrRet['product_id']));
396            if($count == 0) {
397                $objErr->arrErr['product_id'] = "¢¨ »ØÄê¤Î¾¦ÉÊID¤Ï¡¢ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£";
398            }
399        }
400               
401        if($arrRet['product_class_id'] != "") {
402            $count = 0;
403            if($arrRet['product_id'] != "") {
404                $count = $objQuery->count("dtb_products_class", "product_id = ? AND product_class_id = ?", array($arrRet['product_id'], $arrRet['product_class_id']));
405            }
406            if($count == 0) {
407                $objErr->arrErr['product_class_id'] = "¢¨ »ØÄê¤Îµ¬³ÊID¤Ï¡¢ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£";
408            }
409        }
410       
411        // ¸ºß¤¹¤ë¥«¥Æ¥´¥êID¤«¥Á¥§¥Ã¥¯
412        $count = $objQuery->count("dtb_category", "category_id = ?", array($arrRet['category_id']));
413        if($count == 0) {
414            $objErr->arrErr['product_id'] = "¢¨ »ØÄê¤Î¥«¥Æ¥´¥êID¤Ï¡¢ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£";
415        }
416    }
417    return $objErr->arrErr;
418}
419
420/*
421 * ´Ø¿ô̾¡§lfCSVRecordCount
422 * ÀâÌÀ¡¡¡§CSV¤Î¥«¥¦¥ó¥È¿ô¤òÆÀ¤ë
423 * °ú¿ô1 ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹
424 */
425function lfCSVRecordCount($file_name) {
426   
427    $count = 0;
428    $fp = fopen($file_name, "r");
429    while(!feof($fp)) {
430        $arrCSV = fgetcsv($fp, CSV_LINE_MAX);
431        $count++;
432    }
433   
434    return $count-1;
435}
436?>
Note: See TracBrowser for help on using the repository browser.