source: branches/comu-ver2/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSV.php @ 18701

Revision 18701, 22.9 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/**
28 * 商品登録CSVのページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id:LC_Page_Admin_Products_UploadCSV.php 15532 2007-08-31 14:39:46Z nanasess $
33 *
34 * FIXME 同一商品IDで商品規格違いを登録できない。(更新は可能)
35 */
36class LC_Page_Admin_Products_UploadCSV extends LC_Page {
37
38    // }}}
39    // {{{ functions
40
41    /** フォームパラメータ */
42    var $objFormParam;
43
44    /** SC_UploadFile インスタンス */
45    var $objUpfile;
46
47    /**
48     * Page を初期化する.
49     *
50     * @return void
51     */
52    function init() {
53        parent::init();
54        $this->tpl_mainpage = 'products/upload_csv.tpl';
55        $this->tpl_subnavi = 'products/subnavi.tpl';
56        $this->tpl_mainno = 'products';
57        $this->tpl_subno = 'upload_csv';
58        $this->tpl_subtitle = '商品登録CSV';
59    }
60
61    /**
62     * Page のプロセス.
63     *
64     * @return void
65     */
66    function process() {
67        $conn = new SC_DBConn();
68        $objView = new SC_AdminView();
69        $objSess = new SC_Session();
70        $objDb = new SC_Helper_DB_Ex();
71
72        // 認証可否の判定
73        SC_Utils_Ex::sfIsSuccess($objSess);
74
75        // ファイル管理クラス
76        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
77        // ファイル情報の初期化
78        $this->lfInitFile();
79        // パラメータ管理クラス
80        $this->objFormParam = new SC_FormParam();
81        // パラメータ情報の初期化
82        $this->lfInitParam();
83        $colmax = $this->objFormParam->getCount();
84        $this->objFormParam->setHtmlDispNameArray();
85        $this->arrTitle = $this->objFormParam->getHtmlDispNameArray();
86
87        if (!isset($_POST['mode'])) $_POST['mode'] = "";
88
89        switch($_POST['mode']) {
90        case 'csv_upload':
91            $err = false;
92            // エラーチェック
93            $arrErr['csv_file'] = $this->objUpFile->makeTempFile('csv_file');
94
95            if($arrErr['csv_file'] == "") {
96                $arrErr = $this->objUpFile->checkEXISTS();
97            }
98
99            $objView->assignobj($this);
100            $objView->display('admin_popup_header.tpl');
101
102            // 実行時間を制限しない
103            set_time_limit(0);
104
105            // 出力をバッファリングしない(==日本語自動変換もしない)
106            ob_end_flush();
107
108            // IEのために256バイト空文字出力
109            echo str_pad('',256);
110
111            if(empty($arrErr['csv_file'])) {
112                // 一時ファイル名の取得
113                $filepath = $this->objUpFile->getTempFilePath('csv_file');
114                // エンコード
115                $enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath,
116                                                          CHAR_CODE, CSV_TEMP_DIR);
117                $fp = fopen($enc_filepath, "r");
118
119                // 無効なファイルポインタが渡された場合はエラー表示
120                if ($fp === false) {
121                    SC_Utils_Ex::sfDispError("");
122                }
123
124                // レコード数を得る
125                $rec_count = $this->lfCSVRecordCount($fp);
126
127                $line = 0;      // 行数
128                $regist = 0;    // 登録数
129
130                $objQuery = new SC_Query();
131                $objQuery->begin();
132
133                echo "■ CSV登録進捗状況 <br/><br/>\n";
134
135                while(!feof($fp) && !$err) {
136                    $arrCSV = fgetcsv($fp, CSV_LINE_MAX);
137
138                    // 行カウント
139                    $line++;
140
141                    if($line <= 1) {
142                        continue;
143                    }
144
145                    // 項目数カウント
146                    $max = count($arrCSV);
147
148                    // 項目数が1以下の場合は無視する
149                    if($max <= 1) {
150                        continue;
151                    }
152
153                    // 項目数チェック
154                    if($max != $colmax) {
155                        echo "※ 項目数が" . $max . "個検出されました。項目数は" . $colmax . "個になります。</br>\n";
156                        $err = true;
157                    } else {
158                        // シーケンス配列を格納する。
159                        $this->objFormParam->setParam($arrCSV, true);
160                        $arrRet = $this->objFormParam->getHashArray();
161                        $this->objFormParam->setParam($arrRet);
162                        // 入力値の変換
163                        $this->objFormParam->convParam();
164                        // <br>なしでエラー取得する。
165                        $arrCSVErr = $this->lfCheckError();
166                    }
167
168                    // 入力エラーチェック
169                    if(count($arrCSVErr) > 0) {
170                        echo "<font color=\"red\">■" . $line . "行目でエラーが発生しました。</font></br>\n";
171                        foreach($arrCSVErr as $val) {
172                            $this->printError($val);
173                        }
174                        $err = true;
175                    }
176
177                    if(!$err) {
178                        $this->lfRegistProduct($objQuery, $line);
179                        $regist++;
180                    }
181                    $arrParam = $this->objFormParam->getHashArray();
182
183                    if(!$err) echo $line." / ".$rec_count. "行目 (商品ID:".$arrParam['product_id']." / 商品名:".$arrParam['name'].")\n<br />";
184                    flush();
185                }
186                fclose($fp);
187
188                if(!$err) {
189                    $objQuery->commit();
190                    echo "■" . $regist . "件のレコードを登録しました。";
191                    // 商品件数カウント関数の実行
192                    $objDb->sfCategory_Count($objQuery);
193                    $objDb->sfMaker_Count($objQuery);
194                } else {
195                    $objQuery->rollback();
196                }
197            } else {
198                foreach($arrErr as $val) {
199                    $this->printError($val);
200                }
201            }
202            echo "<br/><a href=\"javascript:window.close()\">→閉じる</a>";
203            flush();
204
205            $objView->assignobj($this);
206            $objView->display('admin_popup_footer.tpl');
207
208            exit;
209            break;
210        default:
211            break;
212        }
213
214        $objView->assignobj($this);
215        $objView->display(MAIN_FRAME);
216    }
217
218    /**
219     * デストラクタ.
220     *
221     * @return void
222     */
223    function destroy() {
224        parent::destroy();
225    }
226
227
228    /**
229     * ファイル情報の初期化を行う.
230     *
231     * @return void
232     */
233    function lfInitFile() {
234        $this->objUpFile->addFile("CSVファイル", 'csv_file', array('csv'),
235                                  CSV_SIZE, true, 0, 0, false);
236    }
237
238    /**
239     * 入力情報の初期化を行う.
240     *
241     * @return void
242     */
243    function lfInitParam() {
244       
245        // 商品ステータスの上限文字数の算出
246        $masterData = new SC_DB_MasterData_Ex();
247        $arrSTATUS = $masterData->getMasterData("mtb_status");
248        $product_flag_maxlen = max(array_keys($arrSTATUS));
249        unset($arrSTATUS);
250        unset($masterData);
251
252        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
253        $this->objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
254
255        $this->objFormParam->addParam("規格名1", "dummy1");
256        $this->objFormParam->addParam("規格名2", "dummy2");
257
258        $this->objFormParam->addParam("商品名", "name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
259        $this->objFormParam->addParam("公開フラグ(1:公開 2:非公開)", "status", INT_LEN, "n", array("EXIST_CHECK","MAX_LENGTH_CHECK","NUM_CHECK"));
260        $this->objFormParam->addParam("商品ステータス", "product_flag", $product_flag_maxlen, "n", array("EXIST_CHECK","MAX_LENGTH_CHECK","NUM_CHECK"));
261        $this->objFormParam->addParam("商品コード", "product_code", STEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
262        $this->objFormParam->addParam(NORMAL_PRICE_TITLE, "price01", PRICE_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
263        $this->objFormParam->addParam(SALE_PRICE_TITLE, "price02", PRICE_LEN, "n", array("EXIST_CHECK","MAX_LENGTH_CHECK","NUM_CHECK"));
264        $this->objFormParam->addParam("在庫数", "stock", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
265        $this->objFormParam->addParam("送料", "deliv_fee", PRICE_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
266        $this->objFormParam->addParam("ポイント付与率", "point_rate", PERCENTAGE_LEN, "n", array("EXIST_CHECK","MAX_LENGTH_CHECK","NUM_CHECK"));
267        $this->objFormParam->addParam("購入制限", "sale_limit", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
268        $this->objFormParam->addParam("メーカーURL", "comment1", URL_LEN, "KVa", array("SPTAB_CHECK","URL_CHECK","MAX_LENGTH_CHECK"));
269        $this->objFormParam->addParam("検索ワード", "comment3", LLTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
270        $this->objFormParam->addParam("備考欄(SHOP専用)", "note", LLTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
271        $this->objFormParam->addParam("一覧-メインコメント", "main_list_comment", MTEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
272        $this->objFormParam->addParam("一覧-メイン画像", "main_list_image", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
273        $this->objFormParam->addParam("メインコメント", "main_comment", LLTEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
274        $this->objFormParam->addParam("メイン画像", "main_image", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
275        $this->objFormParam->addParam("メイン拡大画像", "main_large_image", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
276        $this->objFormParam->addParam("カラー比較画像", "file1", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
277        $this->objFormParam->addParam("商品詳細ファイル", "file2", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
278        $this->objFormParam->addParam("詳細-サブタイトル(1)", "sub_title1", STEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
279        $this->objFormParam->addParam("詳細-サブコメント(1)", "sub_comment1", LLTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
280        $this->objFormParam->addParam("詳細-サブ画像(1)", "sub_image1", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
281        $this->objFormParam->addParam("詳細-サブ拡大画像(1)", "sub_large_image1", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
282
283        $this->objFormParam->addParam("詳細-サブタイトル(2)", "sub_title2", STEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
284        $this->objFormParam->addParam("詳細-サブコメント(2)", "sub_comment2", LLTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
285        $this->objFormParam->addParam("詳細-サブ画像(2)", "sub_image2", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
286        $this->objFormParam->addParam("詳細-サブ拡大画像(2)", "sub_large_image2", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
287
288        $this->objFormParam->addParam("詳細-サブタイトル(3)", "sub_title3", STEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
289        $this->objFormParam->addParam("詳細-サブコメント(3)", "sub_comment3", LLTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
290        $this->objFormParam->addParam("詳細-サブ画像(3)", "sub_image3", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
291        $this->objFormParam->addParam("詳細-サブ拡大画像(3)", "sub_large_image3", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
292
293        $this->objFormParam->addParam("詳細-サブタイトル(4)", "sub_title4", STEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
294        $this->objFormParam->addParam("詳細-サブコメント(4)", "sub_comment4", LLTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
295        $this->objFormParam->addParam("詳細-サブ画像(4)", "sub_image4", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
296        $this->objFormParam->addParam("詳細-サブ拡大画像(4)", "sub_large_image4", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
297
298        $this->objFormParam->addParam("詳細-サブタイトル(5)", "sub_title5", STEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
299        $this->objFormParam->addParam("詳細-サブコメント(5)", "sub_comment5", LLTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
300        $this->objFormParam->addParam("詳細-サブ画像(5)", "sub_image5", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
301        $this->objFormParam->addParam("詳細-サブ拡大画像(5)", "sub_large_image5", LTEXT_LEN, "KVa", array("FILE_EXISTS","SPTAB_CHECK","MAX_LENGTH_CHECK"));
302
303        $this->objFormParam->addParam("発送日目安", "deliv_date_id", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
304
305        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
306            $this->objFormParam->addParam("関連商品($cnt)", "recommend_product_id$cnt", INT_LEN, "n", array("MAX_LENGTH_CHECK","NUM_CHECK"));
307            $this->objFormParam->addParam("関連商品コメント($cnt)", "recommend_comment$cnt", LTEXT_LEN, "KVa", array("SPTAB_CHECK","MAX_LENGTH_CHECK"));
308        }
309
310        $this->objFormParam->addParam("商品カテゴリ", "category_id", STEXT_LEN, "n", array("EXIST_CHECK", "SPTAB_CHECK"));
311    }
312
313    /**
314     * 商品登録を行う.
315     *
316     * @param SC_Query $objQuery SC_Queryインスタンス
317     * @param string|integer $line 処理中の行数
318     * @return void
319     */
320    function lfRegistProduct($objQuery, $line = "") {
321
322        $objDb = new SC_Helper_DB_Ex();
323
324        $arrRet = $this->objFormParam->getHashArray();
325
326        // dtb_products以外に登録される値を除外する。
327        foreach($arrRet as $key => $val) {
328            switch($key) {
329            case 'product_code':
330            case 'price01':
331            case 'price02':
332            case 'stock':
333            case 'product_class_id':
334            case 'recommend_product_id1':
335            case 'recommend_product_id2':
336            case 'recommend_product_id3':
337            case 'recommend_product_id4':
338            case 'recommend_product_id5':
339            case 'recommend_product_id6':
340            case 'recommend_comment1':
341            case 'recommend_comment2':
342            case 'recommend_comment3':
343            case 'recommend_comment4':
344            case 'recommend_comment5':
345            case 'recommend_comment6':
346            case 'category_id':
347                break;
348            default:
349                if(!ereg("^dummy", $key)) {
350                    $sqlval[$key] = $val;
351                }
352                break;
353            }
354        }
355
356        // 登録時間を生成(DBのnow()だとcommitした際、すべて同一の時間になってしまう)
357        $time = date("Y-m-d H:i:s");
358        // 秒以下を生成
359        if($line != "") {
360            $microtime = sprintf("%06d", $line);
361            $time .= ".$microtime";
362        }
363        $sqlval['update_date'] = $time;
364        $sqlval['creator_id'] = $_SESSION['member_id'];
365
366        if($sqlval['status'] == "") {
367            $sqlval['status'] = 2;
368        }
369
370        if($sqlval['product_id'] != "") {
371
372            // UPDATEの実行
373            $where = "product_id = ?";
374            $objQuery->update("dtb_products", $sqlval, $where, array($sqlval['product_id']));
375           
376            $product_id = $sqlval['product_id'];
377        } else {
378            // 新規登録
379
380            unset($sqlval['product_id']);
381            $sqlval['create_date'] = $time;
382           
383            // INSERTの実行
384            $objQuery->insert("dtb_products", $sqlval);
385           
386            $product_id = $objQuery->currval("dtb_products","product_id");
387        }
388
389        // カテゴリ登録
390        $arrCategory_id = explode("|", $arrRet["category_id"]);
391        $objDb->updateProductCategories($arrCategory_id, $product_id);
392
393        // 規格登録
394        $this->lfRegistProductClass($objQuery, $arrRet, $product_id, $arrRet['product_class_id']);
395
396        // 関連商品登録
397        $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id));
398        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
399            $keyname = "recommend_product_id" . $i;
400            $comment_key = "recommend_comment" . $i;
401            if($arrRet[$keyname] != "") {
402                $arrProduct = $objQuery->select("product_id", "dtb_products", "product_id = ?", array($arrRet[$keyname]));
403                if($arrProduct[0]['product_id'] != "") {
404                    $arrval['product_id'] = $product_id;
405                    $arrval['recommend_product_id'] = $arrProduct[0]['product_id'];
406                    $arrval['comment'] = $arrRet[$comment_key];
407                    $arrval['update_date'] = "Now()";
408                    $arrval['create_date'] = "Now()";
409                    $arrval['creator_id'] = $_SESSION['member_id'];
410                    $arrval['rank'] = RECOMMEND_PRODUCT_MAX - $i + 1;
411                    $objQuery->insert("dtb_recommend_products", $arrval);
412                }
413            }
414        }
415    }
416
417    /**
418     * 商品規格登録を行う.
419     *
420     * @param SC_Query $objQuery SC_Queryインスタンス
421     * @param array $arrList 商品規格情報配列
422     * @param integer $product_id 商品ID
423     * @param integer $product_class_id 商品規格ID
424     * @return void
425     */
426    function lfRegistProductClass($objQuery, $arrList, $product_id, $product_class_id) {
427        $sqlval['product_code'] = $arrList["product_code"];
428        $sqlval['stock'] = $arrList["stock"];
429        if($sqlval['stock'] == "") {
430            $sqlval['stock_unlimited'] = '1';
431        } else {
432            $sqlval['stock_unlimited'] = '0';
433        }
434        $sqlval['price01'] = $arrList['price01'];
435        $sqlval['price02'] = $arrList['price02'];
436        $sqlval['creator_id'] = $_SESSION['member_id'];
437
438        // TODO $sqlval['member_id'] は何処から出てくる?
439        if($sqlval['member_id'] == "") {
440            $sqlval['creator_id'] = '0';
441        }
442
443        if($product_class_id == "") {
444            // 新規登録
445            $where = "product_id = ?";
446            // 念のために既存の規格を削除
447            $objQuery->delete("dtb_products_class", $where, array($product_id));
448            $sqlval['product_id'] = $product_id;
449            $sqlval['classcategory_id1'] = '0';
450            $sqlval['classcategory_id2'] = '0';
451            $sqlval['create_date'] = "now()";
452            $objQuery->insert("dtb_products_class", $sqlval);
453        } else {
454            // 既存編集
455            $where = "product_id = ? AND product_class_id = ?";
456            $objQuery->update("dtb_products_class", $sqlval, $where, array($product_id, $product_class_id));
457        }
458    }
459
460    /**
461     * 入力チェックを行う.
462     *
463     * @return void
464     */
465    function lfCheckError() {
466
467        // 入力データを渡す。
468        $arrRet =  $this->objFormParam->getHashArray();
469        $objErr = new SC_CheckError($arrRet);
470        $objErr->arrErr = $this->objFormParam->checkError(false);
471
472        if(count($objErr->arrErr) == 0) {
473            $objQuery = new SC_Query();
474            // 商品ID、規格IDの存在チェック
475            if($arrRet['product_id'] != "") {
476                $count = $objQuery->count("dtb_products", "product_id = ?", array($arrRet['product_id']));
477                if($count == 0) {
478                    $objErr->arrErr['product_id'] = "※ 指定の商品IDは、登録されていません。";
479                }
480            }
481
482            if($arrRet['product_class_id'] != "") {
483                $count = 0;
484                if($arrRet['product_id'] != "") {
485                    $count = $objQuery->count("dtb_products_class", "product_id = ? AND product_class_id = ?", array($arrRet['product_id'], $arrRet['product_class_id']));
486                }
487                if($count == 0) {
488                    $objErr->arrErr['product_class_id'] = "※ 指定の規格IDは、登録されていません。";
489                }
490            }
491
492            // 存在するカテゴリIDかチェック
493            $arrCategory_id = explode("|", $arrRet['category_id']);
494            foreach ($arrCategory_id as $category_id) {
495                $count = $objQuery->count("dtb_category", "category_id = ?", array($category_id));
496                if($count == 0) {
497                    $objErr->arrErr['product_id'] = "※ 指定のカテゴリIDは、登録されていません。";
498                }
499            }
500        }
501        return $objErr->arrErr;
502    }
503
504    /**
505     * CSVのカウント数を得る.
506     *
507     * @param resource $fp fopenを使用して作成したファイルポインタ
508     * @return integer CSV のカウント数
509     */
510    function lfCSVRecordCount($fp) {
511
512        $count = 0;
513        while(!feof($fp)) {
514            $arrCSV = fgetcsv($fp, CSV_LINE_MAX);
515            $count++;
516        }
517        // ファイルポインタを戻す
518        if (rewind($fp)) {
519            return $count-1;
520        } else {
521            SC_Utils_Ex::sfDispError("");
522        }
523    }
524
525    /**
526     * 引数の文字列をエラー出力する.
527     *
528     * 引数 $val の内容は, htmlspecialchars() によってサニタイズされる
529     *
530     * @param string $val 出力する文字列
531     * @return void
532     */
533    function printError($val) {
534         echo "<font color=\"red\">"
535             . htmlspecialchars($val, ENT_QUOTES)
536             . "</font></br>\n";
537    }
538}
539?>
Note: See TracBrowser for help on using the repository browser.