source: branches/comu-ver2/data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php @ 17934

Revision 17934, 5.4 KB checked in by Seasoft, 15 years ago (diff)

郵便番号DB登録に関する改善。
・日本郵便のCSV(SJISファイル)に対応
・日本郵便のCSVを最新版(2009/2/27)に入れ替え
・更新できない不具合を修正(DELETE INSERT で対応)
・未使用項目をコメントアウト
・Flush 処理を改善。(IE6, FireFox?3 にて動作確認)
・タイムアウト防止のロジックを改訂(暴走スレッドが残留する確率を軽減する試み)

  • 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-2007 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/** CSV ファイルの最大行数 */
28define("ZIP_CSV_LINE_MAX", 8192);
29
30/** 画像の表示数量 */
31define("IMAGE_MAX", 680);
32
33/** 郵便番号CSV ファイルのパス */
34define("ZIP_CSV_FILE_PATH", DATA_PATH . "downloads/KEN_ALL.CSV");
35
36/**
37 * 郵便番号DB登録 のページクラス.
38 *
39 * @package Page
40 * @author LOCKON CO.,LTD.
41 * @version $Id:LC_Page_Admin_Basis_ZipInstall.php 16741 2007-11-08 00:43:24Z adachi $
42 */
43class LC_Page_Admin_Basis_ZipInstall extends LC_Page {
44
45    // }}}
46    // {{{ functions
47
48    /**
49     * Page を初期化する.
50     *
51     * @return void
52     */
53    function init() {
54        parent::init();
55    }
56
57    /**
58     * Page のプロセス.
59     *
60     * @return void
61     */
62    function process() {
63        $objQuery = new SC_Query();
64        $objSess = new SC_Session();
65
66        // 認証可否の判定
67        SC_Utils_Ex::sfIsSuccess($objSess);
68
69        $fp = fopen(ZIP_CSV_FILE_PATH, "r");
70        $img_path = USER_URL . "packages/" . TEMPLATE_NAME . "/img/";
71
72        echo ('<html>');
73        echo ('<body bgcolor="#494E5F">');
74        // 一部のIEは256バイト以上受け取ってから表示を開始する。
75        SC_Utils_Ex::sfFlush(true);
76
77#('http://www.post.japanpost.jp/zipcode/dl/kogaki/lzh/ken_all.lzh')
78        if(!$fp) {
79            SC_Utils_Ex::sfErrorHeader(">> " . ZIP_CSV_FILE_PATH . "の取得に失敗しました。");
80        } else {
81            print("<img src='". $img_path . "install/main_w.jpg'><br>");
82            SC_Utils_Ex::sfFlush();
83
84            // CSVの件数を数える
85            $line = 0;
86            while(!feof($fp)) {
87                fgets($fp, ZIP_CSV_LINE_MAX);
88                $line++;
89            }
90
91            print("<img src='". $img_path ."install/space_w.gif'>");
92            SC_Utils_Ex::sfFlush();
93
94            // ファイルポインタを戻す
95            fseek($fp, 0);
96
97            // 画像を一個表示する件数を求める。
98            $disp_line = intval($line / IMAGE_MAX);
99
100            $objQuery->begin();
101            $objQuery->delete('mtb_zip');
102            $cnt = 1;
103            $img_cnt = 0;
104            while (!feof($fp)) {
105                $arrCSV = fgetcsv($fp, ZIP_CSV_LINE_MAX);
106                // $sqlval['code'] = $arrCSV[0];
107                // $sqlval['old_zipcode'] = $arrCSV[1];
108                $sqlval['zipcode'] = $arrCSV[2];
109                // $sqlval['state_kana'] = $arrCSV[3];
110                // $sqlval['city_kana'] = $arrCSV[4];
111                // $sqlval['town_kana'] = $arrCSV[5];
112                $sqlval['state'] = mb_convert_encoding($arrCSV[6], CHAR_CODE, 'sjis-win');
113                $sqlval['city'] = mb_convert_encoding($arrCSV[7], CHAR_CODE, 'sjis-win');
114                $sqlval['town'] = mb_convert_encoding($arrCSV[8], CHAR_CODE, 'sjis-win');
115                // $sqlval['flg1'] = $arrCSV[9];
116                // $sqlval['flg2'] = $arrCSV[10];
117                // $sqlval['flg3'] = $arrCSV[11];
118                // $sqlval['flg4'] = $arrCSV[12];
119                // $sqlval['flg5'] = $arrCSV[13];
120                // $sqlval['flg6'] = $arrCSV[14];
121                $objQuery->insert("mtb_zip", $sqlval);
122                $cnt++;
123                // $disp_line件ごとに進捗表示する
124                if($cnt % $disp_line == 0 && $img_cnt < IMAGE_MAX) {
125                    print("<img src='". $img_path ."install/graph_1_w.gif'>");
126                    SC_Utils_Ex::sfFlush();
127                    $img_cnt++;
128                }
129                // 暴走スレッドが残留する確率を軽減したタイムアウト防止のロジック
130                // TODO 動作が安定していれば、SC_Utils 辺りに移動したい。
131                if (!get_cfg_var('safe_mode')) {
132                    // タイムアウトをリセット
133                    set_time_limit((int)get_cfg_var('max_execution_time'));
134                }
135            }
136            fclose($fp);
137            $objQuery->commit();
138
139            print("<img src='". $img_path ."install/space_w.gif'><br>\n");
140            print("<table width='700' height='50' border='0' cellpadding='0' cellspacing='0'>\n");
141            print("<tr>\n");
142            print("<td align='center'><a href='javascript:window.close()'><img src='". $img_path ."install/close.gif' alt='CLOSE' width='85' height='22' border='0' /></a></td>\n");
143            print("</tr>\n");
144            print("</table>\n");
145        }
146    }
147
148    /**
149     * デストラクタ.
150     *
151     * @return void
152     */
153    function destroy() {
154        parent::destroy();
155    }
156}
157?>
Note: See TracBrowser for help on using the repository browser.