Пример #1
0
    /**
     * DB登録
     *
     * @return void
     */
    public function insertMtbZip($start = 1)
    {
        $objQuery = Application::alias('eccube.query');
        $img_path = USER_URL . USER_PACKAGE_DIR . 'admin/img/basis/';
        // 画像パスは admin 固定
        ?>
        <html xmlns='http://www.w3.org/1999/xhtml' lang='ja' xml:lang='ja'>
        <head>
            <meta http-equiv='Content-Type' content='text/html; charset=<?php 
        echo CHAR_CODE;
        ?>
' />
        </head>
        <body>
        <p>DB 登録進捗状況</p>
        <div style='background-color: #494E5F;'>
        <?php 
        // 一部のIEは256バイト以上受け取ってから表示を開始する。
        Utils::sfFlush(true);
        echo '<img src="' . $img_path . 'zip_install_progress.gif"><br />';
        echo '<img src="' . $img_path . 'space_w.gif">';
        Utils::sfFlush();
        // 画像を一個表示する件数を求める。
        $line_all = $this->countZipCsv();
        $disp_line = intval($line_all / IMAGE_MAX);
        /** 現在行(CSV形式。空行は除く。) */
        $cntCurrentLine = 0;
        /** 挿入した行数 */
        $cntInsert = 0;
        $img_cnt = 0;
        $fp = $this->openZipCsv();
        while (!feof($fp)) {
            $arrCSV = fgetcsv($fp, ZIP_CSV_LINE_MAX);
            if (empty($arrCSV)) {
                continue;
            }
            $cntCurrentLine++;
            if ($cntCurrentLine >= $start) {
                $sqlval = array();
                $sqlval['zip_id'] = $cntCurrentLine;
                $sqlval['zipcode'] = $arrCSV[2];
                $sqlval['state'] = $arrCSV[6];
                $sqlval['city'] = $arrCSV[7];
                $sqlval['town'] = $arrCSV[8];
                $objQuery->insert('mtb_zip', $sqlval);
                $cntInsert++;
            }
            // $disp_line件ごとに進捗表示する
            if ($cntCurrentLine % $disp_line == 0 && $img_cnt < IMAGE_MAX) {
                echo '<img src="' . $img_path . 'graph_1_w.gif">';
                Utils::sfFlush();
                $img_cnt++;
            }
            Utils::extendTimeOut();
        }
        fclose($fp);
        echo '<img src="' . $img_path . 'space_w.gif">';
        ?>
        </div>
        <script type='text/javascript' language='javascript'>
            <!--
                // 完了画面
                function complete()
                {
                    document.open('text/html','replace');
                    document.clear();
                    document.write('<p>完了しました。<br />');
                    document.write("<?php 
        echo $cntInsert;
        ?>
 件を追加しました。</p>");
                    document.write("<p><a href='?' target='_top'>戻る</a></p>");
                    document.close();
                }
                // コンテンツを削除するため、タイムアウトで呼び出し。
                setTimeout('complete()', 0);
            // -->
        </script>
        </body>
        </html>
        <?php 
    }
Пример #2
0
 /**
  * CSVファイルを読み込んで、保存処理を行う
  *
  * @param $objFormParam
  * @param $fp CSVファイルポインタ
  * @param $objQuery 保存を行うためのクエリ(指定がない場合、テストのみを行う)
  * @return boolean errFlag. 読み込みに失敗した場合true
  */
 public function lfReadCSVFile(&$objFormParam, &$fp, $objQuery = null)
 {
     $dry_run = $objQuery === null ? true : false;
     // 登録対象の列数
     $col_max_count = $objFormParam->getCount();
     // 行数
     $line_count = 0;
     // 処理に失敗した場合にtrue
     $errFlag = false;
     while (!feof($fp)) {
         $arrCSV = fgetcsv($fp, CSV_LINE_MAX);
         // 行カウント
         $line_count++;
         // ヘッダ行はスキップ
         if ($line_count == 1) {
             continue;
         }
         // 空行はスキップ
         if (empty($arrCSV)) {
             continue;
         }
         // 列数が多すぎる場合はエラー、列数が少ない場合は未設定として配列を補う
         $col_count = count($arrCSV);
         if ($col_count > $col_max_count) {
             $this->addRowErr($line_count, '※ 項目数が' . $col_count . '個検出されました。項目数は' . $col_max_count . '個になります。');
             $errFlag = true;
             break;
         } elseif ($col_count < $col_max_count) {
             $arrCSV = array_pad($arrCSV, $col_max_count, "");
             if (!$dry_run) {
                 $this->addRowResult($line_count, $col_count + 1 . "項目以降を空欄として読み込みました");
             }
         }
         // シーケンス配列を格納する。
         $objFormParam->setParam($arrCSV, true);
         // 入力値の変換
         $objFormParam->convParam();
         // 商品IDが設定されており、規格IDが設定されていなければ、既存の規格ID取得を試みる(product_class_idは必須入力項目ではない)
         $product_id = $objFormParam->getValue('product_id');
         $product_class_id = $objFormParam->getValue('product_class_id');
         if ($product_class_id == '' && $product_id != '') {
             $product_class_id = Utils::sfGetProductClassId($product_id, $objFormParam->getValue('classcategory_id1'), $objFormParam->getValue('classcategory_id2'));
             $objFormParam->setValue('product_class_id', $product_class_id);
         }
         // <br>なしでエラー取得する。
         $arrCSVErr = $this->lfCheckError($objFormParam);
         if (count($arrCSVErr) > 0) {
             foreach ($arrCSVErr as $err) {
                 $this->addRowErr($line_count, $err);
             }
             $errFlag = true;
             break;
         }
         if (!$dry_run) {
             $this->lfRegistProduct($objQuery, $line_count, $objFormParam);
             $arrParam = $objFormParam->getHashArray();
             $this->addRowResult($line_count, '商品ID:' . $arrParam['product_id'] . ' / 商品名:' . $arrParam['name']);
         }
         Utils::extendTimeOut();
     }
     return $errFlag;
 }
Пример #3
0
 /**
  * CSVファイルからインサート実行.
  *
  * @param  Query $objQuery
  * @param  string $dir
  * @param  string $mode
  * @return boolean
  */
 public function lfExeInsertSQL(&$objQuery, $dir, $mode)
 {
     $tbl_flg = false;
     $col_flg = false;
     $ret = true;
     $pagelayout_flg = false;
     $arrVal = array();
     $arrCol = array();
     $arrAllTableList = $objQuery->listTables();
     $objDir = dir($dir);
     while (false !== ($file_name = $objDir->read())) {
         if (!preg_match('/^((dtb|mtb|plg)_(\\w+))\\.csv$/', $file_name, $matches)) {
             continue;
         }
         $file_path = $dir . $file_name;
         $table = $matches[1];
         // テーブル存在チェック
         if (!in_array($table, $arrAllTableList)) {
             if ($mode === 'restore_config') {
                 continue;
             }
             return false;
         }
         // csvファイルからデータの取得
         $fp = fopen($file_path, 'r');
         if ($fp === false) {
             trigger_error($file_name . ' のファイルオープンに失敗しました。', E_USER_ERROR);
         }
         GcUtils::gfPrintLog('リストア実行: ' . $table);
         $objQuery->delete($table);
         $line = 0;
         $arrColName = array();
         while (!feof($fp)) {
             $line++;
             $arrCsvLine = fgetcsv($fp, 1024 * 1024);
             // 1行目: 列名
             if ($line === 1) {
                 $arrColName = $arrCsvLine;
                 continue;
             }
             // 空行を無視
             // false との比較は PHP 5.2.x Windows バグ対応
             // 参考: http://www.php.net/manual/ja/function.fgetcsv.php#98502
             if ($arrCsvLine === array(null) || $arrCsvLine === false) {
                 continue;
             }
             $arrVal = array_combine($arrColName, $arrCsvLine);
             $objQuery->insert($table, $arrVal);
             Utils::extendTimeOut();
         }
         fclose($fp);
     }
     return $ret;
 }
Пример #4
0
 /**
  * CSV作成 テンポラリファイル出力 コールバック関数
  *
  * @param  mixed   $data 出力データ
  * @return boolean true (true:固定 false:中断)
  */
 public function cbOutputCSV($data)
 {
     // 1行目のみヘッダーを出力する
     if ($this->output_header) {
         fputcsv($this->fpOutput, array_keys($data));
         $this->output_header = false;
     }
     fputcsv($this->fpOutput, $data);
     Utils::extendTimeOut();
     return true;
 }
Пример #5
0
 /**
  * 商品カテゴリを更新する.
  *
  * @param  array   $arrCategory_id 登録するカテゴリIDの配列
  * @param  integer $product_id     プロダクトID
  * @return void
  */
 public function updateProductCategories($arrCategory_id, $product_id)
 {
     /* @var $objQuery Query */
     $objQuery = Application::alias('eccube.query');
     // 現在のカテゴリ情報を取得
     $arrCurrentCat = $objQuery->getCol('category_id', 'dtb_product_categories', 'product_id = ?', array($product_id));
     // 登録するカテゴリ情報と比較
     foreach ($arrCurrentCat as $category_id) {
         // 登録しないカテゴリを削除
         if (!in_array($category_id, $arrCategory_id)) {
             $this->removeProductByCategories($category_id, $product_id);
         }
     }
     // カテゴリを登録
     foreach ($arrCategory_id as $category_id) {
         $this->addProductBeforCategories($category_id, $product_id);
         Utils::extendTimeOut();
     }
 }
Пример #6
0
 public function makeTempDownFile($keyname = 'down_file')
 {
     /* @var $objErr CheckError */
     $objErr = Application::alias('eccube.check_error');
     $cnt = 0;
     $check = $this->checkUploadError($keyname, $objErr);
     if ($check) {
         foreach ($this->keyname as $val) {
             // 一致したキーのファイルに情報を保存する。
             if ($val == $keyname) {
                 // 拡張子チェック
                 $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->arrExt[$cnt]), array('FILE_EXT_CHECK'));
                 // ファイルサイズチェック
                 $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->size[$cnt]), array('FILE_SIZE_CHECK'));
                 // エラーがない場合
                 if (!isset($objErr->arrErr[$keyname])) {
                     // 一意なファイル名を作成する。
                     $uniqname = date('mdHi') . '_' . uniqid('') . '.';
                     $this->temp_file[$cnt] = preg_replace("/^.*\\./", $uniqname, $_FILES[$keyname]['name']);
                     $result = copy($_FILES[$keyname]['tmp_name'], $this->temp_dir . $this->temp_file[$cnt]);
                     GcUtils::gfPrintLog($result . ' -> ' . $this->temp_dir . $this->temp_file[$cnt]);
                     Utils::extendTimeOut();
                 }
             }
             $cnt++;
         }
     }
     return $objErr->arrErr[$keyname];
 }
Пример #7
0
 /**
  * モバイル端末以外ダウンロード処理
  *
  * @param string $realpath       ダウンロードファイルパス
  * @param string $sdown_filename ダウンロード時の指定ファイル名
  */
 public function lfDownload($realpath, $sdown_filename)
 {
     // 拡張子を取得
     $extension = pathinfo($realpath, PATHINFO_EXTENSION);
     $contentType = $this->defaultContentType;
     // 拡張ContentType判定(拡張子をキーに拡張ContentType対象か判断)
     if (isset($this->arrContentType[$extension])) {
         // 拡張ContentType対象の場合は、ContentTypeを変更
         $contentType = $this->arrContentType[$extension];
     }
     header('Content-Type: ' . $contentType);
     //ファイル名指定
     header('Content-Disposition: attachment; filename="' . $sdown_filename . '"');
     header('Content-Transfer-Encoding: binary');
     //キャッシュ無効化
     header('Expires: Mon, 26 Nov 1962 00:00:00 GMT');
     header('Last-Modified: ' . gmdate('D,d M Y H:i:s') . ' GMT');
     //IE6+SSL環境下は、キャッシュ無しでダウンロードできない
     header('Cache-Control: private');
     header('Pragma: private');
     //ファイルサイズ指定
     $zv_filesize = filesize($realpath);
     header('Content-Length: ' . $zv_filesize);
     //ファイル読み込み
     $handle = fopen($realpath, 'rb');
     if ($handle === false) {
         Utils::sfDispSiteError(DOWNFILE_NOT_FOUND, '', true);
         Application::alias('eccube.response')->actionExit();
     }
     while (!feof($handle)) {
         echo fread($handle, DOWNLOAD_BLOCK * 1024);
         Utils::sfFlush();
         Utils::extendTimeOut();
     }
     fclose($handle);
 }