/**
  * テーブルを検索する.
  *
  * 引数に部分一致するテーブル名を配列で返す.
  *
  * @param string $expression 検索文字列
  * @return array テーブル名の配列
  */
 function findTableNames($expression = "")
 {
     $objQuery = new SC_Query();
     $sql = "SHOW TABLES LIKE ?";
     $arrColList = $objQuery->getAll($sql, array("%" . $expression . "%"));
     $arrColList = SC_Utils_Ex::sfswaparray($arrColList, false);
     return $arrColList[0];
 }
 /**
  * Page のプロセス(モバイル).
  *
  * FIXME 要リファクタリング
  *
  * @return void
  */
 function mobileProcess()
 {
     $objView = new SC_MobileView();
     $objCustomer = new SC_Customer();
     $objQuery = new SC_Query();
     $objDb = new SC_Helper_DB_Ex();
     // パラメータ管理クラス
     $this->objFormParam = new SC_FormParam();
     // パラメータ情報の初期化
     $this->lfInitParam();
     // POST値の取得
     $this->objFormParam->setParam($_POST);
     // ファイル管理クラス
     $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
     // ファイル情報の初期化
     $this->lfInitFile();
     if (!isset($_POST['mode'])) {
         $_POST['mode'] = "";
     }
     if (!empty($_POST['mode'])) {
         $tmp_id = $_POST['product_id'];
     } else {
         $tmp_id = $_GET['product_id'];
     }
     // 値の正当性チェック
     if (!SC_Utils_Ex::sfIsInt($tmp_id) || !$objDb->sfIsRecord("dtb_products", "product_id", $tmp_id, 'del_flg = 0 AND status = 1')) {
         SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
     }
     // ログイン判定
     if ($objCustomer->isLoginSuccess(true)) {
         //お気に入りボタン表示
         $this->tpl_login = true;
         /* 閲覧ログ機能は現在未使用
         
                        $table = "dtb_customer_reading";
                        $where = "customer_id = ? ";
                        $arrval[] = $objCustomer->getValue('customer_id');
                        //顧客の閲覧商品数
                        $rpcnt = $objQuery->count($table, $where, $arrval);
         
                        //閲覧数が設定数以下
                        if ($rpcnt < CUSTOMER_READING_MAX){
                        //閲覧履歴に新規追加
                        lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
                        } else {
                        //閲覧履歴の中で一番古いものを削除して新規追加
                        $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
                        $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
                        $where = "customer_id = ? AND update_date = ? ";
                        $arrval = array($objCustomer->getValue("customer_id"), $old);
                        //削除
                        $objQuery->delete($table, $where, $arrval);
                        //追加
                        lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
                        }
                     */
     }
     // 規格選択セレクトボックスの作成
     $this->lfMakeSelectMobile($this, $tmp_id);
     // 商品IDをFORM内に保持する。
     $this->tpl_product_id = $tmp_id;
     switch ($_POST['mode']) {
         case 'select':
             // 規格1が設定されている場合
             if ($this->tpl_classcat_find1) {
                 // templateの変更
                 $this->tpl_mainpage = "products/select_find1.tpl";
                 break;
             }
         case 'select2':
             $this->arrErr = $this->lfCheckError();
             // 規格1が設定されている場合
             if ($this->tpl_classcat_find1 and $this->arrErr['classcategory_id1']) {
                 // templateの変更
                 $this->tpl_mainpage = "products/select_find1.tpl";
                 break;
             }
             // 規格2が設定されている場合
             if ($this->tpl_classcat_find2) {
                 $this->arrErr = array();
                 $this->tpl_mainpage = "products/select_find2.tpl";
                 break;
             }
         case 'selectItem':
             $this->arrErr = $this->lfCheckError();
             // 規格1が設定されている場合
             if ($this->tpl_classcat_find2 and $this->arrErr['classcategory_id2']) {
                 // templateの変更
                 $this->tpl_mainpage = "products/select_find2.tpl";
                 break;
             }
             // 商品数の選択を行う
             $this->tpl_mainpage = "products/select_item.tpl";
             break;
         case 'cart':
             // 入力値の変換
             $this->objFormParam->convParam();
             $this->arrErr = $this->lfCheckError();
             if (count($this->arrErr) == 0) {
                 $objCartSess = new SC_CartSession();
                 $classcategory_id1 = $_POST['classcategory_id1'];
                 $classcategory_id2 = $_POST['classcategory_id2'];
                 // 規格1が設定されていない場合
                 if (!$this->tpl_classcat_find1) {
                     $classcategory_id1 = '0';
                 }
                 // 規格2が設定されていない場合
                 if (!$this->tpl_classcat_find2) {
                     $classcategory_id2 = '0';
                 }
                 $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
                 $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
                 $this->sendRedirect($this->getLocation(MOBILE_URL_CART_TOP), true);
                 exit;
             }
             break;
         default:
             break;
     }
     $objQuery = new SC_Query();
     // DBから商品情報を取得する。
     $arrRet = $objQuery->select("*", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($tmp_id));
     $this->arrProduct = $arrRet[0];
     // 商品コードの取得
     $code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code";
     $arrProductCode = $objQuery->getall($code_sql, array($tmp_id));
     $arrProductCode = SC_Utils_Ex::sfswaparray($arrProductCode);
     $this->arrProductCode = $arrProductCode["product_code"];
     // 購入制限数を取得
     if ($this->arrProduct['sale_unlimited'] == 1 || $this->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
         $this->tpl_sale_limit = SALE_LIMIT_MAX;
     } else {
         $this->tpl_sale_limit = $this->arrProduct['sale_limit'];
     }
     // サブタイトルを取得
     $arrFirstCat = $objDb->sfGetFirstCat($arrRet[0]['category_id']);
     $tpl_subtitle = $arrFirstCat['name'];
     $this->tpl_subtitle = $tpl_subtitle;
     // DBからのデータを引き継ぐ
     $this->objUpFile->setDBFileList($this->arrProduct);
     // ファイル表示用配列を渡す
     $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL, true);
     // 支払方法の取得
     $this->arrPayment = $this->lfGetPayment();
     // 入力情報を渡す
     $this->arrForm = $this->objFormParam->getFormParamList();
     //レビュー情報の取得
     $this->arrReview = $this->lfGetReviewData($tmp_id);
     // タイトルに商品名を入れる
     $this->tpl_title = "商品詳細 " . $this->arrProduct["name"];
     //オススメ商品情報表示
     $this->arrRecommend = $this->lfPreGetRecommendProducts($tmp_id);
     //この商品を買った人はこんな商品も買っています
     $this->arrRelateProducts = $this->lfGetRelateProducts($tmp_id);
     $objView->assignobj($this);
     $objView->display(SITE_FRAME);
 }
 /**
  * Page のプロセス.
  *
  * @return void
  */
 function process()
 {
     $objQuery = new SC_Query();
     $objView = new SC_SiteView();
     $objSiteInfo = new SC_SiteInfo();
     //店舗情報をセット
     $arrSiteInfo = $objSiteInfo->data;
     //商品IDを取得
     $product_id = $_GET['product_id'];
     $mode = $_GET['mode'];
     if ($product_id != "" and is_numeric($product_id) or $mode == "all") {
         //商品詳細を取得
         $mode == "all" ? $arrProduct = $this->lfGetProductsDetail($objQuery, $mode) : ($arrProduct = $this->lfGetProductsDetail($objQuery, $product_id));
         // 値のセットし直し
         foreach ($arrProduct as $key => $val) {
             //商品価格を税込みに編集
             $arrProduct[$key]["price02"] = SC_Utils_Ex::sfPreTax($arrProduct[$key]["price02"], $arrSiteInfo["tax"], $arrSiteInfo["tax_rule"]);
             // 画像ファイルのURLセット
             file_exists(IMAGE_SAVE_DIR . $arrProduct[$key]["main_list_image"]) ? $dir = IMAGE_SAVE_URL_RSS : ($dir = IMAGE_TEMP_URL_RSS);
             $arrProduct[$key]["main_list_image"] = $dir . $arrProduct[$key]["main_list_image"];
             file_exists(IMAGE_SAVE_DIR . $arrProduct[$key]["main_image"]) ? $dir = IMAGE_SAVE_URL_RSS : ($dir = IMAGE_TEMP_URL_RSS);
             $arrProduct[$key]["main_image"] = $dir . $arrProduct[$key]["main_image"];
             file_exists(IMAGE_SAVE_DIR . $arrProduct[$key]["main_large_image"]) ? $dir = IMAGE_SAVE_URL_RSS : ($dir = IMAGE_TEMP_URL_RSS);
             $arrProduct[$key]["main_large_image"] = $dir . $arrProduct[$key]["main_large_image"];
             // ポイント計算
             $arrProduct[$key]["point"] = SC_Utils_Ex::sfPrePoint($arrProduct[$key]["price02"], $arrProduct[$key]["point_rate"], POINT_RULE, $arrProduct[$key]["product_id"]);
             // 在庫無制限
             $arrProduct[$key]["stock_unlimited"] = $arrProduct[$key]["stock_unlimited"] == 1 ? "在庫無制限" : NULL;
         }
     } elseif ($mode == "list") {
         //商品一覧を取得
         $arrProduct = $objQuery->getall("SELECT product_id, name AS product_name FROM dtb_products");
     } else {
         $arrProduct = $this->lfGetProductsAllclass($objQuery);
         // 値のセットし直し
         foreach ($arrProduct as $key => $val) {
             //商品価格を税込みに編集
             $arrProduct[$key]["price01_max"] = SC_Utils_Ex::sfPreTax($arrProduct[$key]["price01_max"], $arrSiteInfo["tax"], $arrSiteInfo["tax_rule"]);
             $arrProduct[$key]["price01_min"] = SC_Utils_Ex::sfPreTax($arrProduct[$key]["price01_min"], $arrSiteInfo["tax"], $arrSiteInfo["tax_rule"]);
             $arrProduct[$key]["price02_max"] = SC_Utils_Ex::sfPreTax($arrProduct[$key]["price02_max"], $arrSiteInfo["tax"], $arrSiteInfo["tax_rule"]);
             $arrProduct[$key]["price02_min"] = SC_Utils_Ex::sfPreTax($arrProduct[$key]["price02_min"], $arrSiteInfo["tax"], $arrSiteInfo["tax_rule"]);
             // 画像ファイルのURLセット
             file_exists(IMAGE_SAVE_DIR . $arrProduct[$key]["main_list_image"]) ? $dir = IMAGE_SAVE_URL_RSS : ($dir = IMAGE_TEMP_URL_RSS);
             $arrProduct[$key]["main_list_image"] = $dir . $arrProduct[$key]["main_list_image"];
             file_exists(IMAGE_SAVE_DIR . $arrProduct[$key]["main_image"]) ? $dir = IMAGE_SAVE_URL_RSS : ($dir = IMAGE_TEMP_URL_RSS);
             $arrProduct[$key]["main_image"] = $dir . $arrProduct[$key]["main_image"];
             file_exists(IMAGE_SAVE_DIR . $arrProduct[$key]["main_large_image"]) ? $dir = IMAGE_SAVE_URL_RSS : ($dir = IMAGE_TEMP_URL_RSS);
             $arrProduct[$key]["main_large_image"] = $dir . $arrProduct[$key]["main_large_image"];
             // ポイント計算
             $arrProduct[$key]["point_max"] = SC_Utils_Ex::sfPrePoint($arrProduct[$key]["price02_max"], $arrProduct[$key]["point_rate"], POINT_RULE, $arrProduct[$key]["product_id"]);
             $arrProduct[$key]["point_min"] = SC_Utils_Ex::sfPrePoint($arrProduct[$key]["price02_min"], $arrProduct[$key]["point_rate"], POINT_RULE, $arrProduct[$key]["product_id"]);
         }
     }
     //商品情報をセット
     $this->arrProduct = $arrProduct;
     if (is_array(SC_Utils_Ex::sfswaparray($arrProduct))) {
         $this->arrProductKeys = array_keys(SC_Utils_Ex::sfswaparray($arrProduct));
     }
     //店舗情報をセット
     $this->arrSiteInfo = $arrSiteInfo;
     //セットしたデータをテンプレートファイルに出力
     $objView->assignobj($this);
     //キャッシュしない(念のため)
     header("Pragma: no-cache");
     //XMLテキスト(これがないと正常にRSSとして認識してくれないツールがあるため)
     header("Content-type: application/xml");
     DETAIL_P_HTML;
     //画面表示
     $objView->display($this->tpl_mainpage, true);
 }
 /**
  * テーブルを検索する.
  *
  * 引数に部分一致するテーブル名を配列で返す.
  *
  * @param string $expression 検索文字列
  * @return array テーブル名の配列
  */
 function findTableNames($expression = "")
 {
     $objQuery = new SC_Query();
     $sql = "   SELECT c.relname AS name, " . "     CASE c.relkind " . "     WHEN 'r' THEN 'table' " . "     WHEN 'v' THEN 'view' END AS type " . "     FROM pg_catalog.pg_class c " . "LEFT JOIN pg_catalog.pg_namespace n " . "       ON n.oid = c.relnamespace " . "    WHERE c.relkind IN ('r','v') " . "      AND n.nspname NOT IN ('pg_catalog', 'pg_toast') " . "      AND pg_catalog.pg_table_is_visible(c.oid) " . "      AND c.relname LIKE ?" . " ORDER BY 1,2;";
     $arrColList = $objQuery->getAll($sql, array("%" . $expression . "%"));
     $arrColList = SC_Utils_Ex::sfswaparray($arrColList, false);
     return $arrColList[0];
 }