Source for file LC_Page_Admin_Basis_ZipInstall.php
Documentation is available at LC_Page_Admin_Basis_ZipInstall.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
require_once DATA_REALDIR . 'module/HTTP/Request.php';
define("ZIP_CSV_LINE_MAX", 8192);
define("ZIP_CSV_REALFILE", DATA_REALDIR . "downloads/KEN_ALL.CSV");
/** UTF-8 変換済みの郵便番号CSV ファイルのパス */
define("ZIP_CSV_UTF8_REALFILE", DATA_REALDIR . "downloads/KEN_ALL_utf-8.CSV");
* @author LOCKON CO.,LTD.
* @version $Id:LC_Page_Admin_Basis_ZipInstall.php 16741 2007-11-08 00:43:24Z adachi $
/** 日本郵便から取得した ZIP アーカイブファイルの保管パス */
$this->tpl_mainpage = 'basis/zip_install.tpl';
$this->tpl_subno = 'zip_install';
$this->tpl_maintitle = '基本情報管理';
$this->tpl_subtitle = '郵便番号DB登録';
$this->tpl_mainno = 'basis';
$this->exec = (boolean) $_GET['exec'];
$objFormParam = new SC_FormParam_Ex();
$objFormParam->setParam($_GET);
$this->arrErr = $objFormParam->checkError();
$this->arrForm = $objFormParam->getHashArray();
$this->tpl_zip_download_url_empty = !defined('ZIP_DOWNLOAD_URL') || strlen(ZIP_DOWNLOAD_URL) === 0 || ZIP_DOWNLOAD_URL === false;
$this->tpl_skip_update_csv = $this->tpl_zip_download_url_empty || $this->tpl_zip_function_not_exists;
if (!empty($this->arrErr)) {
SC_Utils_Ex::sfDispException();
// XXX PHP4 を切捨てたら、ダウンロードの必要性チェックなども行いたい
// $arrHeader = get_headers(ZIP_DOWNLOAD_URL, 1);
$objQuery = & SC_Query_Ex::getSingletonInstance();
if (!$this->tpl_skip_update_csv) {
* テーブルデータと UTF-8 変換済みの郵便番号 CSV を削除
$objQuery = & SC_Query_Ex::getSingletonInstance();
$objQuery->delete('mtb_zip');
if ($tpl_mode == 'manual') {
$objFormParam->addParam("開始行", 'startRowNum', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
$objQuery = & SC_Query_Ex::getSingletonInstance();
$img_path = USER_URL . USER_PACKAGE_DIR . "admin/img/basis/"; // 画像パスは admin 固定
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<meta http-equiv="Content-Type" content="text/html; charset= <?php echo CHAR_CODE ?>" />
<div style="background-color: #494E5F;">
// 一部のIEは256バイト以上受け取ってから表示を開始する。
SC_Utils_Ex::sfFlush(true);
echo '<img src="' . $img_path . 'zip_install_progress.gif"><br />';
echo '<img src="' . $img_path . 'space_w.gif">';
$safe_mode = (boolean) ini_get('safe_mode');
if (empty($arrCSV)) continue;
if ($cntCurrentLine >= $start) {
// $sqlval['code'] = $arrCSV[0];
// $sqlval['old_zipcode'] = $arrCSV[1];
$sqlval['zipcode'] = $arrCSV[2];
// $sqlval['state_kana'] = $arrCSV[3];
// $sqlval['city_kana'] = $arrCSV[4];
// $sqlval['town_kana'] = $arrCSV[5];
$sqlval['state'] = $arrCSV[6];
$sqlval['city'] = $arrCSV[7];
$sqlval['town'] = $arrCSV[8];
// $sqlval['flg1'] = $arrCSV[9];
// $sqlval['flg2'] = $arrCSV[10];
// $sqlval['flg3'] = $arrCSV[11];
// $sqlval['flg4'] = $arrCSV[12];
// $sqlval['flg5'] = $arrCSV[13];
// $sqlval['flg6'] = $arrCSV[14];
$objQuery->insert("mtb_zip", $sqlval);
if($cntCurrentLine % $disp_line == 0 && $img_cnt < IMAGE_MAX) {
echo '<img src="' . $img_path . 'graph_1_w.gif">';
// 暴走スレッドが残留する確率を軽減したタイムアウト防止のロジック
// TODO 動作が安定していれば、SC_Utils 辺りに移動したい。
echo '<img src="' . $img_path . 'space_w.gif">';
<script type="text/javascript" language="javascript">
document.open("text/html","replace");
document.write("<p>完了しました。<br />");
document.write(" <?php echo $cntInsert ?> 件を追加しました。</p>");
document.write("<p><a href='?' target='_top'>戻る</a></p>");
// コンテンツを削除するため、タイムアウトで呼び出し。
setTimeout("complete()", 0);
$objQuery = & SC_Query_Ex::getSingletonInstance();
return $objQuery->count('mtb_zip');
$tmp = fgetcsv($fp, ZIP_CSV_LINE_MAX);
if (empty($tmp)) continue;
* 日本郵便から郵便番号 CSV の ZIP アーカイブファイルを取得
// TODO Proxyの設定は「DATA_REALDIR . 'module/HTTP/Request.php'」内の「function HTTP_Request」へ記述する。いずれは、外部設定としたい。
$req = new HTTP_Request();
$req->setURL(ZIP_DOWNLOAD_URL);
$res = $req->sendRequest();
SC_Utils_Ex::sfDispException(ZIP_DOWNLOAD_URL . ' の取得に失敗しました。');
// 郵便番号CSV(zip file)を保存する。
$res = fwrite($fp, $req->getResponseBody());
* ZIP アーカイブファイルを展開して、郵便番号 CSV を上書き
} while ($entry && zip_entry_name($entry) != 'KEN_ALL.CSV');
$res = zip_entry_open($zip, $entry, 'rb');
$fp = fopen($tmp_csv_realfile, 'w');
SC_Utils_Ex::sfDispException($tmp_csv_realfile . ' を開けません。');
$res = fwrite($fp, zip_entry_read($entry, zip_entry_filesize($entry)));
SC_Utils_Ex::sfDispException($tmp_csv_realfile . ' の書き込みに失敗しました。');
SC_Utils_Ex::sfDispException('ファイル名を変更できません。: ' . $tmp_csv_realfile . ' -> ' . ZIP_CSV_REALFILE);
* @return string CSV の更新日時 (整形済みテキスト)
Documentation generated on Fri, 24 Feb 2012 14:01:07 +0900 by Seasoft
|