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

Revision 17954, 5.6 KB checked in by Seasoft, 15 years ago (diff)

・ループ内で実行する必要が無い処理をループ外に移動
・システム設定の取得を行う関数を修正 (get_cfg_var → ini_get)

  • 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            $safe_mode = (boolean)ini_get('safe_mode');
105            $max_execution_time
106                = is_numeric(ini_get('max_execution_time'))
107                ? intval(ini_get('max_execution_time'))
108                : intval(get_cfg_var('max_execution_time'))
109            ;
110            while (!feof($fp)) {
111                $arrCSV = fgetcsv($fp, ZIP_CSV_LINE_MAX);
112                // $sqlval['code'] = $arrCSV[0];
113                // $sqlval['old_zipcode'] = $arrCSV[1];
114                $sqlval['zipcode'] = $arrCSV[2];
115                // $sqlval['state_kana'] = $arrCSV[3];
116                // $sqlval['city_kana'] = $arrCSV[4];
117                // $sqlval['town_kana'] = $arrCSV[5];
118                $sqlval['state'] = mb_convert_encoding($arrCSV[6], CHAR_CODE, 'sjis-win');
119                $sqlval['city'] = mb_convert_encoding($arrCSV[7], CHAR_CODE, 'sjis-win');
120                $sqlval['town'] = mb_convert_encoding($arrCSV[8], CHAR_CODE, 'sjis-win');
121                // $sqlval['flg1'] = $arrCSV[9];
122                // $sqlval['flg2'] = $arrCSV[10];
123                // $sqlval['flg3'] = $arrCSV[11];
124                // $sqlval['flg4'] = $arrCSV[12];
125                // $sqlval['flg5'] = $arrCSV[13];
126                // $sqlval['flg6'] = $arrCSV[14];
127                $objQuery->insert("mtb_zip", $sqlval);
128                $cnt++;
129                // $disp_line件ごとに進捗表示する
130                if($cnt % $disp_line == 0 && $img_cnt < IMAGE_MAX) {
131                    print("<img src='". $img_path ."install/graph_1_w.gif'>");
132                    SC_Utils_Ex::sfFlush();
133                    $img_cnt++;
134                }
135                // 暴走スレッドが残留する確率を軽減したタイムアウト防止のロジック
136                // TODO 動作が安定していれば、SC_Utils 辺りに移動したい。
137                if (!$safe_mode) {
138                    // タイムアウトをリセット
139                    set_time_limit($max_execution_time);
140                }
141            }
142            fclose($fp);
143            $objQuery->commit();
144
145            print("<img src='". $img_path ."install/space_w.gif'><br>\n");
146            print("<table width='700' height='50' border='0' cellpadding='0' cellspacing='0'>\n");
147            print("<tr>\n");
148            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");
149            print("</tr>\n");
150            print("</table>\n");
151        }
152    }
153
154    /**
155     * デストラクタ.
156     *
157     * @return void
158     */
159    function destroy() {
160        parent::destroy();
161    }
162}
163?>
Note: See TracBrowser for help on using the repository browser.