Index: /branches/feature-module-update/html/admin/products/product.php
===================================================================
--- /branches/feature-module-update/html/admin/products/product.php	(revision 15080)
+++ /branches/feature-module-update/html/admin/products/product.php	(revision 15342)
@@ -5,597 +5,15 @@
  * http://www.lockon.co.jp/
  */
+
+// {{{ requires
 require_once("../require.php");
+require_once(CLASS_PATH . "page_extends/admin/products/LC_Page_Admin_Products_Product_Ex.php");
 
-class LC_Page {
-	var $arrCatList;
-	var $arrSRANK;
-	var $arrForm;
-	var $arrSubList;
-	var $arrHidden;
-	var $arrTempImage;
-	var $arrSaveImage;
-	var $tpl_mode;
-	function LC_Page() {
-		$this->tpl_mainpage = 'products/product.tpl';
-		$this->tpl_subnavi = 'products/subnavi.tpl';
-		$this->tpl_mainno = 'products';		
-		$this->tpl_subno = 'product';
-		$this->tpl_subtitle = '商品登録';
-		global $arrSRANK;
-		$this->arrSRANK = $arrSRANK;
-		global $arrDISP;
-		$this->arrDISP = $arrDISP;
-		global $arrCLASS;
-		$this->arrCLASS = $arrCLASS;
-		global $arrSTATUS;
-		$this->arrSTATUS = $arrSTATUS;
-		global $arrSTATUS_VALUE;
-		$this->arrSTATUS_VALUE = $arrSTATUS_VALUE;
-		global $arrSTATUS_IMAGE;
-		$this->arrSTATUS_IMAGE = $arrSTATUS_IMAGE;
-		global $arrDELIVERYDATE;
-		$this->arrDELIVERYDATE = $arrDELIVERYDATE;
-		$this->tpl_nonclass = true;
-	}
-}
+// }}}
+// {{{ generate page
 
-$objPage = new LC_Page();
-$objView = new SC_AdminView();
-$objSiteInfo = new SC_SiteInfo();
-$objQuery = new SC_Query();
-
-// 認証可否の判定
-$objSess = new SC_Session();
-sfIsSuccess($objSess);
-
-// ファイル管理クラス
-$objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
-
-// ファイル情報の初期化
-lfInitFile();
-// Hiddenからのデータを引き継ぐ
-$objUpFile->setHiddenFileList($_POST);
-
-// 検索パラメータの引き継ぎ
-foreach ($_POST as $key => $val) {
-	if (ereg("^search_", $key)) {
-		$objPage->arrSearchHidden[$key] = $val;	
-	}
-}
-
-// FORMデータの引き継ぎ
-$objPage->arrForm = $_POST;
-
-switch($_POST['mode']) {
-// 検索画面からの編集
-case 'pre_edit':
-case 'copy' :
-	// 編集時
-	if(sfIsInt($_POST['product_id'])){
-		// DBから商品情報の読込
-		$arrForm = lfGetProduct($_POST['product_id']);
-		// DBデータから画像ファイル名の読込
-		$objUpFile->setDBFileList($arrForm);
-		
-		if($_POST['mode'] == "copy"){
-			$arrForm["copy_product_id"] = $arrForm["product_id"];
-			$arrForm["product_id"] = "";
-			// 画像ファイルのコピー
-			$arrKey = $objUpFile->keyname;
-			$arrSaveFile = $objUpFile->save_file;
-			
-			foreach($arrSaveFile as $key => $val){
-				lfMakeScaleImage($arrKey[$key], $arrKey[$key], true); 
-			}
-		}
-		$objPage->arrForm = $arrForm;
-		
-		// 商品ステータスの変換
-		$arrRet = sfSplitCBValue($objPage->arrForm['product_flag'], "product_flag");
-		$objPage->arrForm = array_merge($objPage->arrForm, $arrRet);
-		// DBからおすすめ商品の読み込み
-		$objPage->arrRecommend = lfPreGetRecommendProducts($_POST['product_id']);
-		
-		// 規格登録ありなし判定
-		$objPage->tpl_nonclass = lfCheckNonClass($_POST['product_id']);
-		lfProductPage();		// 商品登録ページ
-	}
-	break;
-// 商品登録・編集
-case 'edit':
-	// 規格登録ありなし判定
-	$tpl_nonclass = lfCheckNonClass($_POST['product_id']);
-	
-	if($_POST['product_id'] == "" and sfIsInt($_POST['copy_product_id'])){
-		$tpl_nonclass = lfCheckNonClass($_POST['copy_product_id']);
-	}
-	$objPage->tpl_nonclass = $tpl_nonclass;
-	
-	// 入力値の変換
-	$objPage->arrForm = lfConvertParam($objPage->arrForm);
-	// エラーチェック
-	$objPage->arrErr = lfErrorCheck($objPage->arrForm);
-	// ファイル存在チェック
-	$objPage->arrErr = array_merge((array)$objPage->arrErr, (array)$objUpFile->checkEXISTS());
-	// エラーなしの場合
-	if(count($objPage->arrErr) == 0) {
-		lfProductConfirmPage(); // 確認ページ
-	} else {
-		lfProductPage();		// 商品登録ページ
-	}
-	break;
-// 確認ページから完了ページへ
-case 'complete':
-	$objPage->tpl_mainpage = 'products/complete.tpl';
-	
-	$objPage->tpl_product_id = lfRegistProduct($_POST);		// データ登録
-	
-	$objQuery = new SC_Query();
-	// 件数カウントバッチ実行
-	sfCategory_Count($objQuery);
-	// 一時ファイルを本番ディレクトリに移動する
-	$objUpFile->moveTempFile();
-
-	break;
-// 画像のアップロード
-case 'upload_image':
-	// ファイル存在チェック
-	$objPage->arrErr = array_merge((array)$objPage->arrErr, (array)$objUpFile->checkEXISTS($_POST['image_key']));
-	// 画像保存処理
-	$objPage->arrErr[$_POST['image_key']] = $objUpFile->makeTempFile($_POST['image_key']);
-
-	// 中、小画像生成
-	lfSetScaleImage();
-
-	lfProductPage(); // 商品登録ページ
-	break;
-// 画像の削除
-case 'delete_image':
-	$objUpFile->deleteFile($_POST['image_key']);
-	lfProductPage(); // 商品登録ページ
-	break;
-// 確認ページからの戻り
-case 'confirm_return':
-	// 規格登録ありなし判定
-	$objPage->tpl_nonclass = lfCheckNonClass($_POST['product_id']);
-	lfProductPage();		// 商品登録ページ
-	break;
-// おすすめ商品選択
-case 'recommend_select' :
-	lfProductPage();		// 商品登録ページ
-	break;
-default:
-	// 公開・非公開のデフォルト値
-	$objPage->arrForm['status'] = DEFAULT_PRODUCT_DISP;
-	lfProductPage();		// 商品登録ページ
-	break;
-}
-
-if($_POST['mode'] != 'pre_edit') {
-	// おすすめ商品の読み込み
-	$objPage->arrRecommend = lfGetRecommendProducts();
-}
-
-// 基本情報を渡す
-$objPage->arrInfo = $objSiteInfo->data;
-
-// サブ情報の入力があるかどうかチェックする
-$sub_find = false;
-for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
-	if(	$objPage->arrForm['sub_title'.$cnt] != "" || 
-		$objPage->arrForm['sub_comment'.$cnt] != "" || 
-		$objPage->arrForm['sub_image'.$cnt] != "" || 
-		$objPage->arrForm['sub_large_image'.$cnt] != ""	|| 
-		is_array($objPage->arrFile['sub_image'.$cnt]) || 
-		is_array($objPage->arrFile['sub_large_image'.$cnt])) {
-		$sub_find = true;
-		break;
-	}
-}
-// サブ情報表示・非表示のチェックに使用する。
-$objPage->sub_find = $sub_find;
-
-$objView->assignobj($objPage);
-$objView->display(MAIN_FRAME);
-//-----------------------------------------------------------------------------------------------------------------------------
-
-/* おすすめ商品の読み込み */
-function lfGetRecommendProducts() {
-	global $objPage;
-	$objQuery = new SC_Query();
-	
-	for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
-		$keyname = "recommend_id" . $i;
-		$delkey = "recommend_delete" . $i;
-		$commentkey = "recommend_comment" . $i;
-
-		if($_POST[$keyname] != "" && $_POST[$delkey] != 1) {
-			$arrRet = $objQuery->select("main_list_image, product_code_min, name", "vw_products_allclass AS allcls", "product_id = ?", array($_POST[$keyname])); 
-			$arrRecommend[$i] = $arrRet[0];
-			$arrRecommend[$i]['product_id'] = $_POST[$keyname];
-			$arrRecommend[$i]['comment'] = $objPage->arrForm[$commentkey];
-		}
-	}
-	return $arrRecommend;
-}
-
-/* おすすめ商品の登録 */
-function lfInsertRecommendProducts($objQuery, $arrList, $product_id) {
-	// 一旦オススメ商品をすべて削除する
-	$objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id));
-	$sqlval['product_id'] = $product_id;
-	$rank = RECOMMEND_PRODUCT_MAX;
-	for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
-		$keyname = "recommend_id" . $i;
-		$commentkey = "recommend_comment" . $i;
-		$deletekey = "recommend_delete" . $i;
-		if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') {
-			$sqlval['recommend_product_id'] = $arrList[$keyname];
-			$sqlval['comment'] = $arrList[$commentkey];
-			$sqlval['rank'] = $rank;
-			$sqlval['creator_id'] = $_SESSION['member_id'];
-			$sqlval['create_date'] = "now()";
-			$sqlval['update_date'] = "now()";
-			$objQuery->insert("dtb_recommend_products", $sqlval);
-			$rank--;
-		}
-	}
-}
-
-/* 登録済みおすすめ商品の読み込み */
-function lfPreGetRecommendProducts($product_id) {
-	$objQuery = new SC_Query();
-	$objQuery->setorder("rank DESC");
-	$arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
-	$max = count($arrRet);
-	$no = 1;
-	
-	for($i = 0; $i < $max; $i++) {
-		$arrProductInfo = $objQuery->select("main_list_image, product_code_min, name", "vw_products_allclass AS allcls", "product_id = ?", array($arrRet[$i]['recommend_product_id'])); 
-		$arrRecommend[$no] = $arrProductInfo[0];
-		$arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id'];
-		$arrRecommend[$no]['comment'] = $arrRet[$i]['comment'];
-		$no++;
-	}
-	return $arrRecommend;
-}
-
-/* 商品情報の読み込み */
-function lfGetProduct($product_id) {
-	$objQuery = new SC_Query();
-	$col = "*";
-	$table = "vw_products_nonclass AS noncls ";
-	$where = "product_id = ?";
-	
-	// viewも絞込み(mysql対応)
-	sfViewWhere("&&noncls_where&&", $where, array($product_id));
-	
-	$arrRet = $objQuery->select($col, $table, $where, array($product_id));
-		
-	return $arrRet[0];
-}
-
-/* 商品登録ページ表示用 */
-function lfProductPage() {
-	global $objPage;
-	global $objUpFile;
-	
-	// カテゴリの読込
-	list($objPage->arrCatVal, $objPage->arrCatOut) = sfGetLevelCatList(false);
-
-	if($objPage->arrForm['status'] == "") {
-		$objPage->arrForm['status'] = 1;
-	}
-	
-	if(!is_array($objPage->arrForm['product_flag'])) {
-		// 商品ステータスの分割読込
-		$objPage->arrForm['product_flag'] = sfSplitCheckBoxes($objPage->arrForm['product_flag']);
-	}
-	
-	// HIDDEN用に配列を渡す。
-	$objPage->arrHidden = array_merge((array)$objPage->arrHidden, (array)$objUpFile->getHiddenFileList());
-	// Form用配列を渡す。
-	$objPage->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
-	
-	
-	// アンカーを設定
-	if($_POST['image_key'] != ""){
-		$anchor_hash = "location.hash='#" . $_POST['image_key'] . "'";
-	}elseif($_POST['anchor_key'] != ""){
-		$anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
-	}
-		
-	$objPage->tpl_onload = "fnCheckSaleLimit('" . DISABLED_RGB . "'); fnCheckStockLimit('" . DISABLED_RGB . "'); " . $anchor_hash;
-}
-
-/* ファイル情報の初期化 */
-function lfInitFile() {
-	global $objUpFile;
-	$objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
-	$objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
-	$objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT);
-	for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
-		$objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT);	
-		$objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT);
-	}
-	$objUpFile->addFile("商品比較画像", 'file1', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, OTHER_IMAGE1_WIDTH, OTHER_IMAGE1_HEIGHT);
-	$objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false);
-}
-
-/* 商品の登録 */
-function lfRegistProduct($arrList) {
-	global $objUpFile;
-	global $arrSTATUS;
-	$objQuery = new SC_Query();
-	$objQuery->begin();
-	
-	// INSERTする値を作成する。
-	$sqlval['name'] = $arrList['name'];
-	$sqlval['category_id'] = $arrList['category_id'];
-	$sqlval['status'] = $arrList['status'];
-	$sqlval['product_flag'] = $arrList['product_flag'];
-	$sqlval['main_list_comment'] = $arrList['main_list_comment'];
-	$sqlval['main_comment'] = $arrList['main_comment'];
-	$sqlval['point_rate'] = $arrList['point_rate'];	
-	$sqlval['deliv_fee'] = $arrList['deliv_fee'];
-	$sqlval['comment1'] = $arrList['comment1'];
-	$sqlval['comment2'] = $arrList['comment2'];
-	$sqlval['comment3'] = $arrList['comment3'];
-	$sqlval['comment4'] = $arrList['comment4'];
-	$sqlval['comment5'] = $arrList['comment5'];
-	$sqlval['comment6'] = $arrList['comment6'];
-	$sqlval['main_list_comment'] = $arrList['main_list_comment'];
-	$sqlval['sale_limit'] = $arrList['sale_limit'];
-	$sqlval['sale_unlimited'] = $arrList['sale_unlimited'];
-	$sqlval['deliv_date_id'] = $arrList['deliv_date_id'];
-	$sqlval['update_date'] = "Now()";
-	$sqlval['creator_id'] = $_SESSION['member_id'];
-	$arrRet = $objUpFile->getDBFileList();
-	$sqlval = array_merge($sqlval, $arrRet);
-		
-	for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
-		$sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt];
-		$sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt];
-	}
-
-	if($arrList['product_id'] == "") {
-		if (DB_TYPE == "pgsql") {
-			$product_id = $objQuery->nextval("dtb_products", "product_id");
-			$sqlval['product_id'] = $product_id;
-		}
-		// カテゴリ内で最大のランクを割り当てる
-		$sqlval['rank'] = $objQuery->max("dtb_products", "rank", "category_id = ?", array($arrList['category_id'])) + 1;
-		// INSERTの実行
-		$sqlval['create_date'] = "Now()";
-		$objQuery->insert("dtb_products", $sqlval);
-
-		if (DB_TYPE == "mysql") {
-			$product_id = $objQuery->nextval("dtb_products", "product_id");
-			$sqlval['product_id'] = $product_id;
-		}
-		
-		// コピー商品の場合には規格もコピーする
-		if($_POST["copy_product_id"] != "" and sfIsInt($_POST["copy_product_id"])){
-			// dtb_products_class のカラムを取得
-			$arrColList = sfGetColumnList("dtb_products_class", $objQuery);
-			$arrColList_tmp = array_flip($arrColList);
-
-			// コピーしない列
-			unset($arrColList[$arrColList_tmp["product_class_id"]]);	 //規格ID
-			unset($arrColList[$arrColList_tmp["product_id"]]);			 //商品ID
-
-			$col = sfGetCommaList($arrColList);
-
-			$objQuery->query("INSERT INTO dtb_products_class (product_id, ". $col .") SELECT ?, " . $col. " FROM dtb_products_class WHERE product_id = ? ORDER BY product_class_id", array($product_id, $_POST["copy_product_id"]));
-			
-		}
-
-	} else {
-		$product_id = $arrList['product_id'];
-		// 削除要求のあった既存ファイルの削除
-		$arrRet = lfGetProduct($arrList['product_id']);
-		$objUpFile->deleteDBFile($arrRet);
-		
-		// カテゴリ内ランクの調整処理
-		$old_catid = $objQuery->get("dtb_products", "category_id", "product_id = ?", array($arrList['product_id']));
-		sfMoveCatRank($objQuery, "dtb_products", "product_id", "category_id", $old_catid, $arrList['category_id'], $arrList['product_id']);
-		
-		// UPDATEの実行
-		$where = "product_id = ?";
-		$objQuery->update("dtb_products", $sqlval, $where, array($arrList['product_id']));
-	}
-	
-	// 規格登録
-	sfInsertProductClass($objQuery, $arrList, $product_id);
-	
-	// おすすめ商品登録
-	lfInsertRecommendProducts($objQuery, $arrList, $product_id);
-	
-	$objQuery->commit();
-	return $product_id;
-}
-
-
-/* 取得文字列の変換 */
-function lfConvertParam($array) {
-	/*
-	 *	文字列の変換
-	 *	K :  「半角(ﾊﾝｶｸ)片仮名」を「全角片仮名」に変換
-	 *	C :  「全角ひら仮名」を「全角かた仮名」に変換
-	 *	V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します	
-	 *	n :  「全角」数字を「半角(ﾊﾝｶｸ)」に変換
-	 */
-	// 人物基本情報
-	
-	// スポット商品
-	$arrConvList['name'] = "KVa";
-	$arrConvList['main_list_comment'] = "KVa";
-	$arrConvList['main_comment'] = "KVa";
-	$arrConvList['price01'] = "n";
-	$arrConvList['price02'] = "n";
-	$arrConvList['stock'] = "n";
-	$arrConvList['sale_limit'] = "n";
-	$arrConvList['point_rate'] = "n";
-	$arrConvList['product_code'] = "KVna";
-	$arrConvList['comment1'] = "a";
-	//ホネケーキ:送料の指定なし
-	$arrConvList['deliv_fee'] = "n";
-	
-	// 詳細-サブ
-	for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
-		$arrConvList["sub_title$cnt"] = "KVa";
-	}
-	for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
-		$arrConvList["sub_comment$cnt"] = "KVa";
-	}
-	
-	// おすすめ商品
-	for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
-		$arrConvList["recommend_comment$cnt"] = "KVa";
-	}
-
-	// 文字変換
-	foreach ($arrConvList as $key => $val) {
-		// POSTされてきた値のみ変換する。
-		if(isset($array[$key])) {
-			$array[$key] = mb_convert_kana($array[$key] ,$val);
-		}
-	}
-	
-	global $arrSTATUS;
-	$array['product_flag'] = sfMergeCheckBoxes($array['product_flag'], count($arrSTATUS));
-	
-	return $array;
-}
-
-// 入力エラーチェック
-function lfErrorCheck($array) {
-	global $objPage;
-	global $arrAllowedTag;
-	
-	$objErr = new SC_CheckError($array);
-	$objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-	$objErr->doFunc(array("商品カテゴリ", "category_id", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-	$objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-	$objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-	$objErr->doFunc(array("詳細-メインコメント", "main_comment", $arrAllowedTag), array("HTML_TAG_CHECK"));
-	$objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-	$objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-	$objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-	$objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK"));
-	$objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK"));
-	
-	if($objPage->tpl_nonclass) {
-		$objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK","MAX_LENGTH_CHECK"));
-		$objErr->doFunc(array("通常価格", "price01", PRICE_LEN), array("ZERO_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
-		$objErr->doFunc(array("商品価格", "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "ZERO_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-			
-		if($array['stock_unlimited'] != "1") {
-			$objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
-		}
-	}
-	
-	if($array['sale_unlimited'] != "1") {	
-		$objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
-	}
-	
-	if(isset($objErr->arrErr['category_id'])) {
-		// 自動選択を防ぐためにダミー文字を入れておく
-		$objPage->arrForm['category_id'] = "#";
-	}
-	
-	for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
-		$objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-		$objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-		$objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $arrAllowedTag),  array("HTML_TAG_CHECK"));	
-	}
-	
-	for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
-		if($_POST["recommend_id$cnt"] != "" && $_POST["recommend_delete$cnt"] != 1) {
-			$objErr->doFunc(array("おすすめ商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-		}
-	}
-	
-	return $objErr->arrErr;
-}
-
-/* 確認ページ表示用 */
-function lfProductConfirmPage() {
-	global $objPage;
-	global $objUpFile;
-	$objPage->tpl_mainpage = 'products/confirm.tpl';
-	$objPage->arrForm['mode'] = 'complete';
-	// カテゴリの読込
-	$objPage->arrCatList = sfGetCategoryList();
-	// Form用配列を渡す。
-	$objPage->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
-}
-
-/* 規格あり判定用(規格が登録されていない場合:TRUE) */
-function lfCheckNonClass($product_id) {
-	if(sfIsInt($product_id)) {
-		$objQuery  = new SC_Query();
-		$where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0";
-		$count = $objQuery->count("dtb_products_class", $where, array($product_id));
-		if($count > 0) {
-			return false;
-		}
-	}
-	return true;
-}
-
-// 縮小した画像をセットする
-function lfSetScaleImage(){
-	
-	$subno = str_replace("sub_large_image", "", $_POST['image_key']);
-	switch ($_POST['image_key']){
-		case "main_large_image":
-			// 詳細メイン画像
-			lfMakeScaleImage($_POST['image_key'], "main_image");
-		case "main_image":
-			// 一覧メイン画像
-			lfMakeScaleImage($_POST['image_key'], "main_list_image");
-			break;
-		case "sub_large_image" . $subno:
-			// サブメイン画像
-			lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno);
-			break;
-		default:
-			break;
-	}
-}
-
-// 縮小画像生成
-function lfMakeScaleImage($from_key, $to_key, $forced = false){
-	global $objUpFile;
-	$arrImageKey = array_flip($objUpFile->keyname);
-	
-	if($objUpFile->temp_file[$arrImageKey[$from_key]]){
-		$from_path = $objUpFile->temp_dir . $objUpFile->temp_file[$arrImageKey[$from_key]];
-	}elseif($objUpFile->save_file[$arrImageKey[$from_key]]){
-		$from_path = $objUpFile->save_dir . $objUpFile->save_file[$arrImageKey[$from_key]];
-	}else{
-		return "";
-	}
-	
-	if(file_exists($from_path)){
-		// 元画像サイズを取得
-		list($from_w, $from_h) = getimagesize($from_path);
-		
-		// 生成先の画像サイズを取得
-		$to_w = $objUpFile->width[$arrImageKey[$to_key]];
-		$to_h = $objUpFile->height[$arrImageKey[$to_key]];
-		
-		
-		if($forced) $objUpFile->save_file[$arrImageKey[$to_key]] = "";
-		
-		if(($objUpFile->temp_file[$arrImageKey[$to_key]] == "" and $objUpFile->save_file[$arrImageKey[$to_key]] == "")){
-			$path = $objUpFile->makeThumb($from_path, $to_w, $to_h);
-			$objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path);
-		}
-	}else{
-		return "";
-	}
-}
-
+$objPage = new LC_Page_Admin_Products_Product_Ex();
+$objPage->init();
+$objPage->process();
+register_shutdown_function(array($objPage, "destroy"));
 ?>
Index: /branches/feature-module-update/html/admin/products/index.php
===================================================================
--- /branches/feature-module-update/html/admin/products/index.php	(revision 15080)
+++ /branches/feature-module-update/html/admin/products/index.php	(revision 15342)
@@ -5,357 +5,16 @@
  * http://www.lockon.co.jp/
  */
+
+// {{{ requires
 require_once("../require.php");
 require_once("./index_csv.php");
+require_once(CLASS_PATH . "page_extends/admin/products/LC_Page_Admin_Products_Ex.php");
 
-class LC_Page {
-	var $arrForm;
-	var $arrHidden;
-	var $arrProducts;
-	var $arrPageMax;
-	function LC_Page() {
-		$this->tpl_mainpage = 'products/index.tpl';
-		$this->tpl_mainno = 'products';
-		$this->tpl_subnavi = 'products/subnavi.tpl';
-		$this->tpl_subno = 'index';
-		$this->tpl_pager = DATA_PATH . 'Smarty/templates/admin/pager.tpl';
-		$this->tpl_subtitle = '商品マスタ';
+// }}}
+// {{{ generate page
 
-		global $arrPageMax;
-		$this->arrPageMax = $arrPageMax;
-		global $arrDISP;
-		$this->arrDISP = $arrDISP;
-		global $arrSTATUS;
-		$this->arrSTATUS = $arrSTATUS;
-		global $arrPRODUCTSTATUS_COLOR;
-		$this->arrPRODUCTSTATUS_COLOR = $arrPRODUCTSTATUS_COLOR;
-		/*
-		 session_start時のno-cacheヘッダーを抑制することで
-		 「戻る」ボタン使用時の有効期限切れ表示を抑制する。
-		 private-no-expire:クライアントのキャッシュを許可する。
-		*/
-		session_cache_limiter('private-no-expire');		
-	}
-}
-
-//$conn = new SC_DBConn();
-$objPage = new LC_Page();
-$objView = new SC_AdminView();
-
-$objDate = new SC_Date();
-
-// 登録・更新検索開始年
-$objDate->setStartYear(RELEASE_YEAR);
-$objDate->setEndYear(DATE("Y"));
-$objPage->arrStartYear = $objDate->getYear();
-$objPage->arrStartMonth = $objDate->getMonth();
-$objPage->arrStartDay = $objDate->getDay();
-// 登録・更新検索終了年
-$objDate->setStartYear(RELEASE_YEAR);
-$objDate->setEndYear(DATE("Y"));
-$objPage->arrEndYear = $objDate->getYear();
-$objPage->arrEndMonth = $objDate->getMonth();
-$objPage->arrEndDay = $objDate->getDay();
-
-// 認証可否の判定
-$objSess = new SC_Session();
-sfIsSuccess($objSess);
-
-//キャンペーンの編集時
-if(sfIsInt($_POST['campaign_id']) && $_POST['mode'] == "camp_search") {
-	$objQuery = new SC_Query();
-	$search_data = $objQuery->get("dtb_campaign", "search_condition", "campaign_id = ? ", array($_POST['campaign_id']));
-	$arrSearch = unserialize($search_data);
-	foreach ($arrSearch as $key => $val) {
-		$_POST[$key] = $val;
-	}
-}
-
-// POST値の引き継ぎ
-$objPage->arrForm = $_POST;
-
-// 検索ワードの引き継ぎ
-foreach ($_POST as $key => $val) {
-	if (ereg("^search_", $key) || ereg("^campaign_", $key)) {
-		switch($key) {
-			case 'search_product_flag':
-			case 'search_status':
-				$objPage->arrHidden[$key] = sfMergeParamCheckBoxes($val);
-				if(!is_array($val)) {
-					$objPage->arrForm[$key] = split("-", $val);
-				}
-				break;
-			default:
-				$objPage->arrHidden[$key] = $val;
-				break;
-		}
-	}
-}
-
-// ページ送り用
-$objPage->arrHidden['search_pageno'] = $_POST['search_pageno'];
-
-// 商品削除
-if ($_POST['mode'] == "delete") {
-	
-	if($_POST['category_id'] != "") {
-		// ランク付きレコードの削除
-		$where = "category_id = " . addslashes($_POST['category_id']);
-		sfDeleteRankRecord("dtb_products", "product_id", $_POST['product_id'], $where);
-	} else {
-		sfDeleteRankRecord("dtb_products", "product_id", $_POST['product_id']);
-	}
-	// 子テーブル(商品規格)の削除
-	$objQuery = new SC_Query();
-	$objQuery->delete("dtb_products_class", "product_id = ?", array($_POST['product_id']));
-	
-	// 件数カウントバッチ実行
-	sfCategory_Count($objQuery);	
-}
-
-
-if ($_POST['mode'] == "search" || $_POST['mode'] == "csv"  || $_POST['mode'] == "delete" || $_POST['mode'] == "delete_all" || $_POST['mode'] == "camp_search") {
-	// 入力文字の強制変換
-	lfConvertParam();
-	// エラーチェック
-	$objPage->arrErr = lfCheckError();
-
-	$where = "del_flg = 0";
-	$view_where = "del_flg = 0";
-	
-	// 入力エラーなし
-	if (count($objPage->arrErr) == 0) {
-
-		$arrval = array();
-		foreach ($objPage->arrForm as $key => $val) {
-			$val = sfManualEscape($val);
-			
-			if($val == "") {
-				continue;
-			}
-			
-			switch ($key) {
-				case 'search_product_id':	// 商品ID
-					$where .= " AND product_id = ?";
-					$view_where .= " AND product_id = ?";
-					$arrval[] = $val;
-					break;
-				case 'search_product_class_name': //規格名称
-					$where_in = " (SELECT classcategory_id FROM dtb_classcategory WHERE class_id IN (SELECT class_id FROM dtb_class WHERE name LIKE ?)) ";
-					$where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " . $where_in;
-					$where .= " OR classcategory_id2 IN" . $where_in . ")";
-					$view_where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " . $where_in;
-					$view_where .= " OR classcategory_id2 IN" . $where_in . ")";
-					$arrval[] = "%$val%";
-					$arrval[] = "%$val%";
-					$view_where = $where;
-					break;
-				case 'search_name':			// 商品名
-					$where .= " AND name ILIKE ?";
-					$view_where .= " AND name ILIKE ?";
-					$arrval[] = "%$val%";
-					break;
-				case 'search_category_id':	// カテゴリー
-					list($tmp_where, $tmp_arrval) = sfGetCatWhere($val);
-					if($tmp_where != "") {
-						$where.= " AND $tmp_where";
-						$view_where.= " AND $tmp_where";
-						$arrval = array_merge((array)$arrval, (array)$tmp_arrval);
-					}
-					break;
-				case 'search_product_code':	// 商品コード
-					$where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)";
-					$view_where .= " AND EXISTS (SELECT product_id FROM dtb_products_class as cls WHERE cls.product_code ILIKE ? AND dtb_products.product_id = cls.product_id GROUP BY cls.product_id )";
-					$arrval[] = "%$val%";
-					break;
-				case 'search_startyear':	// 登録更新日（FROM）
-					$date = sfGetTimestamp($_POST['search_startyear'], $_POST['search_startmonth'], $_POST['search_startday']);
-					$where.= " AND update_date >= '" . $_POST['search_startyear'] . "/" . $_POST['search_startmonth']. "/" .$_POST['search_startday'] . "'";
-					$view_where.= " AND update_date >= '" . $_POST['search_startyear'] . "/" . $_POST['search_startmonth']. "/" .$_POST['search_startday'] . "'";
-					break;
-				case 'search_endyear':		// 登録更新日（TO）
-					$date = sfGetTimestamp($_POST['search_endyear'], $_POST['search_endmonth'], $_POST['search_endday']);
-					$date = date('Y/m/d', strtotime($date) + 86400);
-					$where.= " AND update_date < date('" . $date . "')";
-					$view_where.= " AND update_date < date('" . $date . "')";
-					break;
-				case 'search_product_flag':	//種別
-					global $arrSTATUS;
-					$search_product_flag = sfSearchCheckBoxes($val);
-					if($search_product_flag != "") {
-						$where.= " AND product_flag LIKE ?";
-						$view_where.= " AND product_flag LIKE ?";
-						$arrval[] = $search_product_flag;					
-					}
-					break;
-				case 'search_status':		// ステータス
-					$tmp_where = "";
-					foreach ($val as $element){
-						if ($element != ""){
-							if ($tmp_where == ""){
-								$tmp_where.="AND (status LIKE ? ";
-							}else{
-								$tmp_where.="OR status LIKE ? ";
-							}
-							$arrval[]=$element;
-						}
-					}
-					if ($tmp_where != ""){
-						$tmp_where.=")";
-						$where.= " $tmp_where";
-						$view_where.= " $tmp_where";
-					}
-					break;
-				default:
-					break;
-			}
-		}
-
-		$order = "update_date DESC, product_id DESC";
-		$objQuery = new SC_Query();
-		
-		switch($_POST['mode']) {
-		case 'csv':
-			// オプションの指定
-			$option = "ORDER BY $order";
-			// CSV出力タイトル行の作成
-			$arrOutput = sfSwapArray(sfgetCsvOutput(1, " WHERE csv_id = 1 AND status = 1"));
-			
-			if (count($arrOutput) <= 0) break;
-			
-			$arrOutputCols = $arrOutput['col'];
-			$arrOutputTitle = $arrOutput['disp_name'];
-			
-			$head = sfGetCSVList($arrOutputTitle);
-			
-			$data = lfGetProductsCSV($where, $option, $arrval, $arrOutputCols);
-
-			// CSVを送信する。
-			sfCSVDownload($head.$data);
-			exit;
-			break;
-		case 'delete_all':
-			// 検索結果をすべて削除
-			$where = "product_id IN (SELECT product_id FROM vw_products_nonclass AS noncls  WHERE $where)";
-			$sqlval['del_flg'] = 1;
-			$objQuery->update("dtb_products", $sqlval, $where, $arrval);
-			break;
-		default:
-			// 読み込む列とテーブルの指定
-			$col = "product_id, name, category_id, main_list_image, status, product_code, price01, price02, stock, stock_unlimited";
-			$from = "vw_products_nonclass AS noncls ";
-
-			// 行数の取得
-			$linemax = $objQuery->count("dtb_products", $view_where, $arrval);
-			$objPage->tpl_linemax = $linemax;				// 何件が該当しました。表示用
-
-			// ページ送りの処理
-			if(is_numeric($_POST['search_page_max'])) {	
-				$page_max = $_POST['search_page_max'];
-			} else {
-				$page_max = SEARCH_PMAX;
-			}
-
-			// ページ送りの取得
-			$objNavi = new SC_PageNavi($_POST['search_pageno'], $linemax, $page_max, "fnNaviSearchPage", NAVI_PMAX);
-			$startno = $objNavi->start_row;
-			$objPage->arrPagenavi = $objNavi->arrPagenavi;
-			
-			//キャンペーン商品検索時は、全結果の商品IDを変数に格納する
-			if($_POST['search_mode'] == 'campaign') {
-				$arrRet = $objQuery->select($col, $from, $where, $arrval);
-				if(count($arrRet) > 0) {
-					$arrRet = sfSwapArray($arrRet);
-					$pid = implode("-", $arrRet['product_id']);
-					$objPage->arrHidden['campaign_product_id'] = $pid;
-				}
-			}
-
-			// 取得範囲の指定(開始行番号、行数のセット)
-			if(DB_TYPE != "mysql") $objQuery->setlimitoffset($page_max, $startno);
-			// 表示順序
-			$objQuery->setorder($order);
-			
-			// viewも絞込みをかける(mysql用)
-			sfViewWhere("&&noncls_where&&", $view_where, $arrval, $objQuery->order . " " .  $objQuery->setlimitoffset($page_max, $startno, true));
-
-			// 検索結果の取得
-			$objPage->arrProducts = $objQuery->select($col, $from, $where, $arrval);
-			
-			break;
-		}
-	}
-}
-	
-// カテゴリの読込
-$objPage->arrCatList = sfGetCategoryList();
-$objPage->arrCatIDName = lfGetIDName($objPage->arrCatList);
-
-// 画面の表示
-$objView->assignobj($objPage);
-$objView->display(MAIN_FRAME);
-
-//---------------------------------------------------------------------------------------------------------------------------------------------------------
-
-// 取得文字列の変換 
-function lfConvertParam() {
-	global $objPage;
-	/*
-	 *	文字列の変換
-	 *	K :  「半角(ﾊﾝｶｸ)片仮名」を「全角片仮名」に変換
-	 *	C :  「全角ひら仮名」を「全角かた仮名」に変換
-	 *	V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します	
-	 *	n :  「全角」数字を「半角(ﾊﾝｶｸ)」に変換
-	 */
-	$arrConvList['search_name'] = "KVa";
-	$arrConvList['search_product_code'] = "KVa";
-	
-	// 文字変換
-	foreach ($arrConvList as $key => $val) {
-		// POSTされてきた値のみ変換する。
-		if(isset($objPage->arrForm[$key])) {
-			$objPage->arrForm[$key] = mb_convert_kana($objPage->arrForm[$key] ,$val);
-		}
-	}
-}
-
-// エラーチェック 
-// 入力エラーチェック
-function lfCheckError() {
-	$objErr = new SC_CheckError();
-	$objErr->doFunc(array("商品ID", "search_product_id"), array("NUM_CHECK"));
-	$objErr->doFunc(array("開始日", "search_startyear", "search_startmonth", "search_startday"), array("CHECK_DATE"));
-	$objErr->doFunc(array("終了日", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_DATE"));
-	$objErr->doFunc(array("開始日", "終了日", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM"));
-	return $objErr->arrErr;
-}
-
-// チェックボックス用WHERE文作成
-function lfGetCBWhere($key, $max) {
-	$str = "";
-	$find = false;
-	for ($cnt = 1; $cnt <= $max; $cnt++) {
-		if ($_POST[$key . $cnt] == "1") {
-			$str.= "1";
-			$find = true;
-		} else {
-			$str.= "_";
-		}
-	}
-	if (!$find) {
-		$str = "";
-	}
-	return $str;
-}
-
-// カテゴリIDをキー、カテゴリ名を値にする配列を返す。
-function lfGetIDName($arrCatList) {
-	$max = count($arrCatList);
-	for ($cnt = 0; $cnt < $max; $cnt++ ) {
-		$key = $arrCatList[$cnt]['category_id'];
-		$val = $arrCatList[$cnt]['category_name'];
-		$arrRet[$key] = $val;	
-	}
-	return $arrRet;
-}
-
+$objPage = new LC_Page_Admin_Products_Ex();
+$objPage->init();
+$objPage->process();
+register_shutdown_function(array($objPage, "destroy"));
 ?>
Index: /branches/feature-module-update/data/class/page_extends/admin/products/LC_Page_Admin_Products_Ex.php
===================================================================
--- /branches/feature-module-update/data/class/page_extends/admin/products/LC_Page_Admin_Products_Ex.php	(revision 15342)
+++ /branches/feature-module-update/data/class/page_extends/admin/products/LC_Page_Admin_Products_Ex.php	(revision 15342)
@@ -0,0 +1,52 @@
+<?php
+/*
+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+
+// {{{ requires
+require_once(CLASS_PATH . "pages/admin/products/LC_Page_Admin_Products.php");
+
+/**
+ * 商品管理 のページクラス(拡張).
+ *
+ * LC_Page_Admin_Products をカスタマイズする場合はこのクラスを編集する.
+ *
+ * @package Page
+ * @author LOCKON CO.,LTD.
+ * @version $Id$
+ */
+class LC_Page_Admin_Products_Ex extends LC_Page_Admin_Products {
+
+    // }}}
+    // {{{ functions
+
+    /**
+     * Page を初期化する.
+     *
+     * @return void
+     */
+    function init() {
+        parent::init();
+    }
+
+    /**
+     * Page のプロセス.
+     *
+     * @return void
+     */
+    function process() {
+        parent::process();
+    }
+
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
+}
+?>
Index: /branches/feature-module-update/data/class/page_extends/admin/products/LC_Page_Admin_Products_Product_Ex.php
===================================================================
--- /branches/feature-module-update/data/class/page_extends/admin/products/LC_Page_Admin_Products_Product_Ex.php	(revision 15342)
+++ /branches/feature-module-update/data/class/page_extends/admin/products/LC_Page_Admin_Products_Product_Ex.php	(revision 15342)
@@ -0,0 +1,52 @@
+<?php
+/*
+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+
+// {{{ requires
+require_once(CLASS_PATH . "pages/admin/products/LC_Page_Admin_Products_Product.php");
+
+/**
+ * 商品登録 のページクラス(拡張).
+ *
+ * LC_Page_Admin_Products_Product をカスタマイズする場合はこのクラスを編集する.
+ *
+ * @package Page
+ * @author LOCKON CO.,LTD.
+ * @version $Id$
+ */
+class LC_Page_Admin_Products_Product_Ex extends LC_Page_Admin_Products_Product {
+
+    // }}}
+    // {{{ functions
+
+    /**
+     * Page を初期化する.
+     *
+     * @return void
+     */
+    function init() {
+        parent::init();
+    }
+
+    /**
+     * Page のプロセス.
+     *
+     * @return void
+     */
+    function process() {
+        parent::process();
+    }
+
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
+}
+?>
Index: /branches/feature-module-update/data/class/pages/admin/products/LC_Page_Admin_Products.php
===================================================================
--- /branches/feature-module-update/data/class/pages/admin/products/LC_Page_Admin_Products.php	(revision 15342)
+++ /branches/feature-module-update/data/class/pages/admin/products/LC_Page_Admin_Products.php	(revision 15342)
@@ -0,0 +1,382 @@
+<?php
+/*
+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+
+// {{{ requires
+require_once(CLASS_PATH . "pages/LC_Page.php");
+
+/**
+ * 商品管理 のページクラス.
+ *
+ * @package Page
+ * @author LOCKON CO.,LTD.
+ * @version $Id$
+ */
+class LC_Page_Admin_Products extends LC_Page {
+
+    // }}}
+    // {{{ functions
+
+    /**
+     * Page を初期化する.
+     *
+     * @return void
+     */
+    function init() {
+        parent::init();
+        $this->tpl_mainpage = 'products/index.tpl';
+        $this->tpl_mainno = 'products';
+        $this->tpl_subnavi = 'products/subnavi.tpl';
+        $this->tpl_subno = 'index';
+        $this->tpl_pager = DATA_PATH . 'Smarty/templates/admin/pager.tpl';
+        $this->tpl_subtitle = '商品マスタ';
+
+        $masterData = new SC_DB_MasterData_Ex();
+        $this->arrPageMax = $masterData->getMasterData("mtb_page_max");
+        $this->arrDISP = $masterData->getMasterData("mtb_disp");
+        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
+        $this->arrPRODUCTSTATUS_COLOR = $masterData->getMasterData("mtb_product_status_color");
+
+        $this->allowClientCache();
+    }
+
+    /**
+     * Page のプロセス.
+     *
+     * @return void
+     */
+    function process() {
+        $objView = new SC_AdminView();
+
+        $objDate = new SC_Date();
+
+        // 登録・更新検索開始年
+        $objDate->setStartYear(RELEASE_YEAR);
+        $objDate->setEndYear(DATE("Y"));
+        $this->arrStartYear = $objDate->getYear();
+        $this->arrStartMonth = $objDate->getMonth();
+        $this->arrStartDay = $objDate->getDay();
+        // 登録・更新検索終了年
+        $objDate->setStartYear(RELEASE_YEAR);
+        $objDate->setEndYear(DATE("Y"));
+        $this->arrEndYear = $objDate->getYear();
+        $this->arrEndMonth = $objDate->getMonth();
+        $this->arrEndDay = $objDate->getDay();
+
+        // 認証可否の判定
+        $objSess = new SC_Session();
+        SC_Utils_Ex::sfIsSuccess($objSess);
+
+        if (!isset($_POST['mode'])) $_POST['mode'] = "";
+
+        //キャンペーンの編集時
+        if(isset($_POST['campaign_id']) && SC_Utils_Ex::sfIsInt($_POST['campaign_id'])
+                && $_POST['mode'] == "camp_search") {
+            $objQuery = new SC_Query();
+            $search_data = $objQuery->get("dtb_campaign", "search_condition", "campaign_id = ? ", array($_POST['campaign_id']));
+            $arrSearch = unserialize($search_data);
+            foreach ($arrSearch as $key => $val) {
+                $_POST[$key] = $val;
+            }
+        }
+
+        // POST値の引き継ぎ
+        $this->arrForm = $_POST;
+
+        // 検索ワードの引き継ぎ
+        foreach ($_POST as $key => $val) {
+            if (ereg("^search_", $key) || ereg("^campaign_", $key)) {
+                switch($key) {
+                    case 'search_product_flag':
+                    case 'search_status':
+                        $this->arrHidden[$key] = sfMergeParamCheckBoxes($val);
+                        if(!is_array($val)) {
+                            $this->arrForm[$key] = split("-", $val);
+                        }
+                        break;
+                    default:
+                        $this->arrHidden[$key] = $val;
+                        break;
+                }
+            }
+        }
+
+        // ページ送り用
+        $this->arrHidden['search_pageno'] = isset($_POST['search_pageno']) ? $_POST['search_pageno'] : "";
+
+        // 商品削除
+        if ($_POST['mode'] == "delete") {
+
+            if($_POST['category_id'] != "") {
+                // ランク付きレコードの削除
+                $where = "category_id = " . addslashes($_POST['category_id']);
+                sfDeleteRankRecord("dtb_products", "product_id", $_POST['product_id'], $where);
+            } else {
+                sfDeleteRankRecord("dtb_products", "product_id", $_POST['product_id']);
+            }
+            // 子テーブル(商品規格)の削除
+            $objQuery = new SC_Query();
+            $objQuery->delete("dtb_products_class", "product_id = ?", array($_POST['product_id']));
+
+            // 件数カウントバッチ実行
+            SC_Utils_Ex::sfCategory_Count($objQuery);
+        }
+
+
+        if ($_POST['mode'] == "search" || $_POST['mode'] == "csv"  || $_POST['mode'] == "delete" || $_POST['mode'] == "delete_all" || $_POST['mode'] == "camp_search") {
+            // 入力文字の強制変換
+            $this->lfConvertParam();
+            // エラーチェック
+            $this->arrErr = $this->lfCheckError();
+
+            $where = "del_flg = 0";
+            $view_where = "del_flg = 0";
+
+            // 入力エラーなし
+            if (count($this->arrErr) == 0) {
+
+                $arrval = array();
+                foreach ($this->arrForm as $key => $val) {
+                    $val = SC_Utils_Ex::sfManualEscape($val);
+
+                    if($val == "") {
+                        continue;
+                    }
+
+                    switch ($key) {
+                        case 'search_product_id':	// 商品ID
+                            $where .= " AND product_id = ?";
+                            $view_where .= " AND product_id = ?";
+                            $arrval[] = $val;
+                            break;
+                        case 'search_product_class_name': //規格名称
+                            $where_in = " (SELECT classcategory_id FROM dtb_classcategory WHERE class_id IN (SELECT class_id FROM dtb_class WHERE name LIKE ?)) ";
+                            $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " . $where_in;
+                            $where .= " OR classcategory_id2 IN" . $where_in . ")";
+                            $view_where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " . $where_in;
+                            $view_where .= " OR classcategory_id2 IN" . $where_in . ")";
+                            $arrval[] = "%$val%";
+                            $arrval[] = "%$val%";
+                            $view_where = $where;
+                            break;
+                        case 'search_name':			// 商品名
+                            $where .= " AND name ILIKE ?";
+                            $view_where .= " AND name ILIKE ?";
+                            $arrval[] = "%$val%";
+                            break;
+                        case 'search_category_id':	// カテゴリー
+                            list($tmp_where, $tmp_arrval) = SC_Utils_Ex::sfGetCatWhere($val);
+                            if($tmp_where != "") {
+                                $where.= " AND $tmp_where";
+                                $view_where.= " AND $tmp_where";
+                                $arrval = array_merge((array)$arrval, (array)$tmp_arrval);
+                            }
+                            break;
+                        case 'search_product_code':	// 商品コード
+                            $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)";
+                            $view_where .= " AND EXISTS (SELECT product_id FROM dtb_products_class as cls WHERE cls.product_code ILIKE ? AND dtb_products.product_id = cls.product_id GROUP BY cls.product_id )";
+                            $arrval[] = "%$val%";
+                            break;
+                        case 'search_startyear':	// 登録更新日（FROM）
+                            $date = sfGetTimestamp($_POST['search_startyear'], $_POST['search_startmonth'], $_POST['search_startday']);
+                            $where.= " AND update_date >= '" . $_POST['search_startyear'] . "/" . $_POST['search_startmonth']. "/" .$_POST['search_startday'] . "'";
+                            $view_where.= " AND update_date >= '" . $_POST['search_startyear'] . "/" . $_POST['search_startmonth']. "/" .$_POST['search_startday'] . "'";
+                            break;
+                        case 'search_endyear':		// 登録更新日（TO）
+                            $date = sfGetTimestamp($_POST['search_endyear'], $_POST['search_endmonth'], $_POST['search_endday']);
+                            $date = date('Y/m/d', strtotime($date) + 86400);
+                            $where.= " AND update_date < date('" . $date . "')";
+                            $view_where.= " AND update_date < date('" . $date . "')";
+                            break;
+                        case 'search_product_flag':	//種別
+                            global $arrSTATUS;
+                            $search_product_flag = sfSearchCheckBoxes($val);
+                            if($search_product_flag != "") {
+                                $where.= " AND product_flag LIKE ?";
+                                $view_where.= " AND product_flag LIKE ?";
+                                $arrval[] = $search_product_flag;
+                            }
+                            break;
+                        case 'search_status':		// ステータス
+                            $tmp_where = "";
+                            foreach ($val as $element){
+                                if ($element != ""){
+                                    if ($tmp_where == ""){
+                                        $tmp_where.="AND (status LIKE ? ";
+                                    }else{
+                                        $tmp_where.="OR status LIKE ? ";
+                                    }
+                                    $arrval[]=$element;
+                                }
+                            }
+                            if ($tmp_where != ""){
+                                $tmp_where.=")";
+                                $where.= " $tmp_where";
+                                $view_where.= " $tmp_where";
+                            }
+                            break;
+                        default:
+                            break;
+                    }
+                }
+
+                $order = "update_date DESC, product_id DESC";
+                $objQuery = new SC_Query();
+
+                switch($_POST['mode']) {
+                case 'csv':
+                    // オプションの指定
+                    $option = "ORDER BY $order";
+                    // CSV出力タイトル行の作成
+                    $arrOutput = sfSwapArray(sfgetCsvOutput(1, " WHERE csv_id = 1 AND status = 1"));
+
+                    if (count($arrOutput) <= 0) break;
+
+                    $arrOutputCols = $arrOutput['col'];
+                    $arrOutputTitle = $arrOutput['disp_name'];
+
+                    $head = sfGetCSVList($arrOutputTitle);
+
+                    $data = lfGetProductsCSV($where, $option, $arrval, $arrOutputCols);
+
+                    // CSVを送信する。
+                    sfCSVDownload($head.$data);
+                    exit;
+                    break;
+                case 'delete_all':
+                    // 検索結果をすべて削除
+                    $where = "product_id IN (SELECT product_id FROM vw_products_nonclass AS noncls  WHERE $where)";
+                    $sqlval['del_flg'] = 1;
+                    $objQuery->update("dtb_products", $sqlval, $where, $arrval);
+                    break;
+                default:
+                    // 読み込む列とテーブルの指定
+                    $col = "product_id, name, category_id, main_list_image, status, product_code, price01, price02, stock, stock_unlimited";
+                    $from = "vw_products_nonclass AS noncls ";
+
+                    // 行数の取得
+                    $linemax = $objQuery->count("dtb_products", $view_where, $arrval);
+                    $this->tpl_linemax = $linemax;				// 何件が該当しました。表示用
+
+                    // ページ送りの処理
+                    if(is_numeric($_POST['search_page_max'])) {
+                        $page_max = $_POST['search_page_max'];
+                    } else {
+                        $page_max = SEARCH_PMAX;
+                    }
+
+                    // ページ送りの取得
+                    $objNavi = new SC_PageNavi($this->arrHidden['search_pageno'], $linemax, $page_max, "fnNaviSearchPage", NAVI_PMAX);
+                    $startno = $objNavi->start_row;
+                    $this->arrPagenavi = $objNavi->arrPagenavi;
+
+                    //キャンペーン商品検索時は、全結果の商品IDを変数に格納する
+                    if(isset($_POST['search_mode']) && $_POST['search_mode'] == 'campaign') {
+                        $arrRet = $objQuery->select($col, $from, $where, $arrval);
+                        if(count($arrRet) > 0) {
+                            $arrRet = sfSwapArray($arrRet);
+                            $pid = implode("-", $arrRet['product_id']);
+                            $this->arrHidden['campaign_product_id'] = $pid;
+                        }
+                    }
+
+                    // 取得範囲の指定(開始行番号、行数のセット)
+                    if(DB_TYPE != "mysql") $objQuery->setlimitoffset($page_max, $startno);
+                    // 表示順序
+                    $objQuery->setorder($order);
+//
+//                    // viewも絞込みをかける(mysql用)
+//                    sfViewWhere("&&noncls_where&&", $view_where, $arrval, $objQuery->order . " " .  $objQuery->setlimitoffset($page_max, $startno, true));
+//
+                    // 検索結果の取得
+                    $this->arrProducts = $objQuery->select($col, $from, $where, $arrval);
+
+                    break;
+                }
+            }
+        }
+
+        // カテゴリの読込
+        $this->arrCatList = SC_Utils_Ex::sfGetCategoryList();
+        $this->arrCatIDName = $this->lfGetIDName($this->arrCatList);
+
+        // 画面の表示
+        $objView->assignobj($this);
+        $objView->display(MAIN_FRAME);
+    }
+
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
+
+    // 取得文字列の変換
+    function lfConvertParam() {
+        global $objPage;
+        /*
+         *	文字列の変換
+         *	K :  「半角(ﾊﾝｶｸ)片仮名」を「全角片仮名」に変換
+         *	C :  「全角ひら仮名」を「全角かた仮名」に変換
+         *	V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
+         *	n :  「全角」数字を「半角(ﾊﾝｶｸ)」に変換
+         */
+        $arrConvList['search_name'] = "KVa";
+        $arrConvList['search_product_code'] = "KVa";
+
+        // 文字変換
+        foreach ($arrConvList as $key => $val) {
+            // POSTされてきた値のみ変換する。
+            if(isset($objPage->arrForm[$key])) {
+                $objPage->arrForm[$key] = mb_convert_kana($objPage->arrForm[$key] ,$val);
+            }
+        }
+    }
+
+    // エラーチェック
+    // 入力エラーチェック
+    function lfCheckError() {
+        $objErr = new SC_CheckError();
+        $objErr->doFunc(array("商品ID", "search_product_id"), array("NUM_CHECK"));
+        $objErr->doFunc(array("開始日", "search_startyear", "search_startmonth", "search_startday"), array("CHECK_DATE"));
+        $objErr->doFunc(array("終了日", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_DATE"));
+        $objErr->doFunc(array("開始日", "終了日", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM"));
+        return $objErr->arrErr;
+    }
+
+    // チェックボックス用WHERE文作成
+    function lfGetCBWhere($key, $max) {
+        $str = "";
+        $find = false;
+        for ($cnt = 1; $cnt <= $max; $cnt++) {
+            if ($_POST[$key . $cnt] == "1") {
+                $str.= "1";
+                $find = true;
+            } else {
+                $str.= "_";
+            }
+        }
+        if (!$find) {
+            $str = "";
+        }
+        return $str;
+    }
+
+    // カテゴリIDをキー、カテゴリ名を値にする配列を返す。
+    function lfGetIDName($arrCatList) {
+        $max = count($arrCatList);
+        for ($cnt = 0; $cnt < $max; $cnt++ ) {
+            $key = isset($arrCatList[$cnt]['category_id']) ? $arrCatList[$cnt]['category_id'] : "";
+            $val = isset($arrCatList[$cnt]['category_name']) ? $arrCatList[$cnt]['category_name'] : "";
+            $arrRet[$key] = $val;
+        }
+        return $arrRet;
+    }
+}
+?>
Index: /branches/feature-module-update/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php
===================================================================
--- /branches/feature-module-update/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php	(revision 15342)
+++ /branches/feature-module-update/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php	(revision 15342)
@@ -0,0 +1,647 @@
+<?php
+/*
+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+
+// {{{ requires
+require_once(CLASS_PATH . "pages/LC_Page.php");
+
+/**
+ * 商品登録 のページクラス.
+ *
+ * @package Page
+ * @author LOCKON CO.,LTD.
+ * @version $Id$
+ */
+class LC_Page_Admin_Products_Product extends LC_Page {
+
+    // {{{ properties
+
+    /** ファイル管理クラスのインスタンス */
+    var $objUpFile;
+
+    /** hidden 項目の配列 */
+    var $arrHidden;
+
+    /** エラー情報 */
+    var $arrErr;
+
+    // }}}
+    // {{{ functions
+
+    /**
+     * Page を初期化する.
+     *
+     * @return void
+     */
+    function init() {
+        parent::init();
+        $this->tpl_mainpage = 'products/product.tpl';
+        $this->tpl_subnavi = 'products/subnavi.tpl';
+        $this->tpl_mainno = 'products';
+        $this->tpl_subno = 'product';
+        $this->tpl_subtitle = '商品登録';
+        $this->arrErr = array();
+
+        $masterData = new SC_DB_MasterData_Ex();
+        $this->arrSRANK = $masterData->getMasterData("mtb_srank");
+        $this->arrDISP = $masterData->getMasterData("mtb_disp");
+        $this->arrCLASS = $masterData->getMasterData("mtb_class");
+        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
+        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
+        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
+        $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag");
+        $this->tpl_nonclass = true;
+    }
+
+    /**
+     * Page のプロセス.
+     *
+     * @return void
+     */
+    function process() {
+        $objView = new SC_AdminView();
+        $objSiteInfo = new SC_SiteInfo();
+        $objQuery = new SC_Query();
+        $objDb = new SC_Helper_DB_Ex();
+
+        // 認証可否の判定
+        $objSess = new SC_Session();
+        SC_Utils_Ex::sfIsSuccess($objSess);
+
+        // ファイル管理クラス
+        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
+
+        // ファイル情報の初期化
+        $this->lfInitFile();
+        // Hiddenからのデータを引き継ぐ
+        $this->objUpFile->setHiddenFileList($_POST);
+
+        // 検索パラメータの引き継ぎ
+        foreach ($_POST as $key => $val) {
+            if (ereg("^search_", $key)) {
+                $this->arrSearchHidden[$key] = $val;
+            }
+        }
+
+        // FORMデータの引き継ぎ
+        $this->arrForm = $_POST;
+
+        if (!isset($_POST['mode'])) $_POST['mode'] = "";
+
+        switch($_POST['mode']) {
+        // 検索画面からの編集
+        case 'pre_edit':
+        case 'copy' :
+            // 編集時
+            if(SC_Utils_Ex::sfIsInt($_POST['product_id'])){
+                // DBから商品情報の読込
+                $arrForm = $this->lfGetProduct($_POST['product_id']);
+                // DBデータから画像ファイル名の読込
+                $this->objUpFile->setDBFileList($arrForm);
+
+                if($_POST['mode'] == "copy"){
+                    $arrForm["copy_product_id"] = $arrForm["product_id"];
+                    $arrForm["product_id"] = "";
+                    // 画像ファイルのコピー
+                    $arrKey = $this->objUpFile->keyname;
+                    $arrSaveFile = $this->objUpFile->save_file;
+
+                    foreach($arrSaveFile as $key => $val){
+                        $this->lfMakeScaleImage($arrKey[$key], $arrKey[$key], true);
+                    }
+                }
+                $this->arrForm = $arrForm;
+
+                // 商品ステータスの変換
+                $arrRet = SC_Utils_Ex::sfSplitCBValue($this->arrForm['product_flag'], "product_flag");
+                $this->arrForm = array_merge($this->arrForm, $arrRet);
+                // DBからおすすめ商品の読み込み
+                $this->arrRecommend = $this->lfPreGetRecommendProducts($_POST['product_id']);
+
+                // 規格登録ありなし判定
+                $this->tpl_nonclass = $this->lfCheckNonClass($_POST['product_id']);
+                $this->lfProductPage();		// 商品登録ページ
+            }
+            break;
+        // 商品登録・編集
+        case 'edit':
+            // 規格登録ありなし判定
+            $tpl_nonclass = $this->lfCheckNonClass($_POST['product_id']);
+
+            if($_POST['product_id'] == "" and SC_Utils_Ex::sfIsInt($_POST['copy_product_id'])){
+                $tpl_nonclass = $this->lfCheckNonClass($_POST['copy_product_id']);
+            }
+            $this->tpl_nonclass = $tpl_nonclass;
+
+            // 入力値の変換
+            $this->arrForm = $this->lfConvertParam($this->arrForm);
+            // エラーチェック
+            $this->arrErr = $this->lfErrorCheck($this->arrForm);
+            // ファイル存在チェック
+            $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS());
+            // エラーなしの場合
+            if(count($this->arrErr) == 0) {
+                $this->lfProductConfirmPage(); // 確認ページ
+            } else {
+                $this->lfProductPage();		// 商品登録ページ
+            }
+            break;
+        // 確認ページから完了ページへ
+        case 'complete':
+            $this->tpl_mainpage = 'products/complete.tpl';
+
+            $this->tpl_product_id = $this->lfRegistProduct($_POST);		// データ登録
+
+            // 件数カウントバッチ実行
+            $objDb->sfCategory_Count($objQuery);
+            // 一時ファイルを本番ディレクトリに移動する
+            $this->objUpFile->moveTempFile();
+
+            break;
+        // 画像のアップロード
+        case 'upload_image':
+            // ファイル存在チェック
+            $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS($_POST['image_key']));
+            // 画像保存処理
+            $this->arrErr[$_POST['image_key']] = $this->objUpFile->makeTempFile($_POST['image_key']);
+
+            // 中、小画像生成
+            $this->lfSetScaleImage();
+
+            $this->lfProductPage(); // 商品登録ページ
+            break;
+        // 画像の削除
+        case 'delete_image':
+            $this->objUpFile->deleteFile($_POST['image_key']);
+            $this->lfProductPage(); // 商品登録ページ
+            break;
+        // 確認ページからの戻り
+        case 'confirm_return':
+            // 規格登録ありなし判定
+            $this->tpl_nonclass = lfCheckNonClass($_POST['product_id']);
+            $this->lfProductPage();		// 商品登録ページ
+            break;
+        // おすすめ商品選択
+        case 'recommend_select' :
+            $this->lfProductPage();		// 商品登録ページ
+            break;
+        default:
+            // 公開・非公開のデフォルト値
+            $this->arrForm['status'] = DEFAULT_PRODUCT_DISP;
+            $this->lfProductPage();		// 商品登録ページ
+            break;
+        }
+
+        if($_POST['mode'] != 'pre_edit') {
+            // おすすめ商品の読み込み
+            $this->arrRecommend = $this->lfGetRecommendProducts();
+        }
+
+        // 基本情報を渡す
+        $this->arrInfo = $objSiteInfo->data;
+
+        // サブ情報の入力があるかどうかチェックする
+        $sub_find = false;
+        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
+            if(	(isset($this->arrForm['sub_title'.$cnt])
+                 && !empty($this->arrForm['sub_title'.$cnt])) ||
+                (isset($this->arrForm['sub_comment'.$cnt])
+                 && !empty($this->arrForm['sub_comment'.$cnt])) ||
+                (isset($this->arrForm['sub_image'.$cnt])
+                 && !empty($this->arrForm['sub_image'.$cnt])) ||
+                (isset($this->arrForm['sub_large_image'.$cnt])
+                 && !empty($this->arrForm['sub_large_image'.$cnt])) ||
+                (isset($this->arrForm['sub_image'.$cnt])
+                 && is_array($this->arrFile['sub_image'.$cnt])) ||
+                (isset($this->arrForm['sub_large_image'.$cnt])
+                 && is_array($this->arrFile['sub_large_image'.$cnt]))) {
+                $sub_find = true;
+                break;
+            }
+        }
+        // サブ情報表示・非表示のチェックに使用する。
+        $this->sub_find = $sub_find;
+
+        $objView->assignobj($this);
+        $objView->display(MAIN_FRAME);
+    }
+
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
+
+    /* おすすめ商品の読み込み */
+    function lfGetRecommendProducts() {
+        $objQuery = new SC_Query();
+        $arrRecommend = array();
+        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
+            $keyname = "recommend_id" . $i;
+            $delkey = "recommend_delete" . $i;
+            $commentkey = "recommend_comment" . $i;
+
+            if((isset($_POST[$keyname]) && !empty($_POST[$keyname])) && $_POST[$delkey] != 1) {
+                $arrRet = $objQuery->select("main_list_image, product_code_min, name", "vw_products_allclass AS allcls", "product_id = ?", array($_POST[$keyname]));
+                $arrRecommend[$i] = $arrRet[0];
+                $arrRecommend[$i]['product_id'] = $_POST[$keyname];
+                $arrRecommend[$i]['comment'] = $this->arrForm[$commentkey];
+            }
+        }
+        return $arrRecommend;
+    }
+
+    /* おすすめ商品の登録 */
+    function lfInsertRecommendProducts($objQuery, $arrList, $product_id) {
+        // 一旦オススメ商品をすべて削除する
+        $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id));
+        $sqlval['product_id'] = $product_id;
+        $rank = RECOMMEND_PRODUCT_MAX;
+        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
+            $keyname = "recommend_id" . $i;
+            $commentkey = "recommend_comment" . $i;
+            $deletekey = "recommend_delete" . $i;
+            if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') {
+                $sqlval['recommend_product_id'] = $arrList[$keyname];
+                $sqlval['comment'] = $arrList[$commentkey];
+                $sqlval['rank'] = $rank;
+                $sqlval['creator_id'] = $_SESSION['member_id'];
+                $sqlval['create_date'] = "now()";
+                $sqlval['update_date'] = "now()";
+                $objQuery->insert("dtb_recommend_products", $sqlval);
+                $rank--;
+            }
+        }
+    }
+
+    /* 登録済みおすすめ商品の読み込み */
+    function lfPreGetRecommendProducts($product_id) {
+        $objQuery = new SC_Query();
+        $objQuery->setorder("rank DESC");
+        $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
+        $max = count($arrRet);
+        $no = 1;
+
+        for($i = 0; $i < $max; $i++) {
+            $arrProductInfo = $objQuery->select("main_list_image, product_code_min, name", "vw_products_allclass AS allcls", "product_id = ?", array($arrRet[$i]['recommend_product_id']));
+            $arrRecommend[$no] = $arrProductInfo[0];
+            $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id'];
+            $arrRecommend[$no]['comment'] = $arrRet[$i]['comment'];
+            $no++;
+        }
+        return $arrRecommend;
+    }
+
+    /* 商品情報の読み込み */
+    function lfGetProduct($product_id) {
+        $objQuery = new SC_Query();
+        $col = "*";
+        $table = "vw_products_nonclass AS noncls ";
+        $where = "product_id = ?";
+
+        // viewも絞込み(mysql対応) TODO
+        //sfViewWhere("&&noncls_where&&", $where, array($product_id));
+
+        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
+
+        return $arrRet[0];
+    }
+
+    /* 商品登録ページ表示用 */
+    function lfProductPage() {
+        $objDb = new SC_Helper_DB_Ex();
+
+        // カテゴリの読込
+        list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false);
+
+        if($this->arrForm['status'] == "") {
+            $this->arrForm['status'] = 1;
+        }
+
+        if(isset($this->arrForm['product_flag']) && !is_array($this->arrForm['product_flag'])) {
+            // 商品ステータスの分割読込
+            $this->arrForm['product_flag'] = SC_Utils_Ex::sfSplitCheckBoxes($this->arrForm['product_flag']);
+        }
+
+        // HIDDEN用に配列を渡す。
+        $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList());
+        // Form用配列を渡す。
+        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
+
+
+        // アンカーを設定
+        if (isset($_POST['image_key']) && !empty($_POST['image_key'])) {
+            $anchor_hash = "location.hash='#" . $_POST['image_key'] . "'";
+        } elseif (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
+            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
+        } else {
+            $anchor_hash = "";
+        }
+
+        $this->tpl_onload = "fnCheckSaleLimit('" . DISABLED_RGB . "'); fnCheckStockLimit('" . DISABLED_RGB . "'); " . $anchor_hash;
+    }
+
+    /* ファイル情報の初期化 */
+    function lfInitFile() {
+        $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
+        $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
+        $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT);
+        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
+            $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT);
+            $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT);
+        }
+        $this->objUpFile->addFile("商品比較画像", 'file1', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, OTHER_IMAGE1_WIDTH, OTHER_IMAGE1_HEIGHT);
+        $this->objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false);
+    }
+
+    /* 商品の登録 */
+    function lfRegistProduct($arrList) {
+        $objQuery = new SC_Query();
+        $objDb = new SC_Helper_DB_Ex();
+        $objQuery->begin();
+
+        // 配列の添字を定義
+        $checkArray = array("name", "category_id", "status", "product_flag",
+                            "main_list_comment", "main_comment", "point_rate",
+                            "deliv_fee", "comment1", "comment2", "comment3",
+                            "comment4", "comment5", "comment6", "main_list_comment",
+                            "sale_limit", "sale_unlimited", "deliv_date_id");
+        $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray);
+
+        // INSERTする値を作成する。
+        $sqlval['name'] = $arrList['name'];
+        $sqlval['category_id'] = $arrList['category_id'];
+        $sqlval['status'] = $arrList['status'];
+        $sqlval['product_flag'] = $arrList['product_flag'];
+        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
+        $sqlval['main_comment'] = $arrList['main_comment'];
+        $sqlval['point_rate'] = $arrList['point_rate'];
+        $sqlval['deliv_fee'] = $arrList['deliv_fee'];
+        $sqlval['comment1'] = $arrList['comment1'];
+        $sqlval['comment2'] = $arrList['comment2'];
+        $sqlval['comment3'] = $arrList['comment3'];
+        $sqlval['comment4'] = $arrList['comment4'];
+        $sqlval['comment5'] = $arrList['comment5'];
+        $sqlval['comment6'] = $arrList['comment6'];
+        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
+        $sqlval['sale_limit'] = $arrList['sale_limit'];
+        $sqlval['sale_unlimited'] = $arrList['sale_unlimited'];
+        $sqlval['deliv_date_id'] = $arrList['deliv_date_id'];
+        $sqlval['update_date'] = "Now()";
+        $sqlval['creator_id'] = $_SESSION['member_id'];
+        $arrRet = $this->objUpFile->getDBFileList();
+        $sqlval = array_merge($sqlval, $arrRet);
+
+        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
+            $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt];
+            $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt];
+        }
+
+        if($arrList['product_id'] == "") {
+            if (DB_TYPE == "pgsql") {
+                $product_id = $objQuery->nextval("dtb_products", "product_id");
+                $sqlval['product_id'] = $product_id;
+            }
+            // カテゴリ内で最大のランクを割り当てる
+            $sqlval['rank'] = $objQuery->max("dtb_products", "rank", "category_id = ?", array($arrList['category_id'])) + 1;
+            // INSERTの実行
+            $sqlval['create_date'] = "Now()";
+            $objQuery->insert("dtb_products", $sqlval);
+
+            if (DB_TYPE == "mysql") {
+                $product_id = $objQuery->nextval("dtb_products", "product_id");
+                $sqlval['product_id'] = $product_id;
+            }
+
+            // コピー商品の場合には規格もコピーする
+            if($_POST["copy_product_id"] != "" and sfIsInt($_POST["copy_product_id"])){
+                // dtb_products_class のカラムを取得
+                $dbFactory = SC_DB_DBFactory::getInstance();
+                $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery);
+                $arrColList_tmp = array_flip($arrColList);
+
+                // コピーしない列
+                unset($arrColList[$arrColList_tmp["product_class_id"]]);	 //規格ID
+                unset($arrColList[$arrColList_tmp["product_id"]]);			 //商品ID
+
+                $col = SC_Utils_Ex::sfGetCommaList($arrColList);
+
+                $objQuery->query("INSERT INTO dtb_products_class (product_id, ". $col .") SELECT ?, " . $col. " FROM dtb_products_class WHERE product_id = ? ORDER BY product_class_id", array($product_id, $_POST["copy_product_id"]));
+
+            }
+
+        } else {
+            $product_id = $arrList['product_id'];
+            // 削除要求のあった既存ファイルの削除
+            $arrRet = lfGetProduct($arrList['product_id']);
+            $this->objUpFile->deleteDBFile($arrRet);
+
+            // カテゴリ内ランクの調整処理
+            $old_catid = $objQuery->get("dtb_products", "category_id", "product_id = ?", array($arrList['product_id']));
+            sfMoveCatRank($objQuery, "dtb_products", "product_id", "category_id", $old_catid, $arrList['category_id'], $arrList['product_id']);
+
+            // UPDATEの実行
+            $where = "product_id = ?";
+            $objQuery->update("dtb_products", $sqlval, $where, array($arrList['product_id']));
+        }
+
+        // 規格登録
+        SC_Utils_Ex::sfInsertProductClass($objQuery, $arrList, $product_id);
+
+        // おすすめ商品登録
+        $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
+
+        $objQuery->commit();
+        return $product_id;
+    }
+
+
+    /* 取得文字列の変換 */
+    function lfConvertParam($array) {
+        /*
+         *	文字列の変換
+         *	K :  「半角(ﾊﾝｶｸ)片仮名」を「全角片仮名」に変換
+         *	C :  「全角ひら仮名」を「全角かた仮名」に変換
+         *	V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
+         *	n :  「全角」数字を「半角(ﾊﾝｶｸ)」に変換
+         */
+        // 人物基本情報
+
+        // スポット商品
+        $arrConvList['name'] = "KVa";
+        $arrConvList['main_list_comment'] = "KVa";
+        $arrConvList['main_comment'] = "KVa";
+        $arrConvList['price01'] = "n";
+        $arrConvList['price02'] = "n";
+        $arrConvList['stock'] = "n";
+        $arrConvList['sale_limit'] = "n";
+        $arrConvList['point_rate'] = "n";
+        $arrConvList['product_code'] = "KVna";
+        $arrConvList['comment1'] = "a";
+        //ホネケーキ:送料の指定なし
+        $arrConvList['deliv_fee'] = "n";
+
+        // 詳細-サブ
+        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
+            $arrConvList["sub_title$cnt"] = "KVa";
+        }
+        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
+            $arrConvList["sub_comment$cnt"] = "KVa";
+        }
+
+        // おすすめ商品
+        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
+            $arrConvList["recommend_comment$cnt"] = "KVa";
+        }
+
+        // 文字変換
+        foreach ($arrConvList as $key => $val) {
+            // POSTされてきた値のみ変換する。
+            if(isset($array[$key])) {
+                $array[$key] = mb_convert_kana($array[$key] ,$val);
+            }
+        }
+
+        if (!isset($array['product_flag'])) $array['product_flag'] = "";
+        $array['product_flag'] = SC_Utils_Ex::sfMergeCheckBoxes($array['product_flag'], count($this->arrSTATUS));
+
+        return $array;
+    }
+
+    // 入力エラーチェック
+    function lfErrorCheck($array) {
+
+        $objErr = new SC_CheckError($array);
+        $objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $objErr->doFunc(array("商品カテゴリ", "category_id", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK"));
+        $objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK"));
+        $objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK"));
+
+        if($this->tpl_nonclass) {
+            $objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK","MAX_LENGTH_CHECK"));
+            $objErr->doFunc(array("通常価格", "price01", PRICE_LEN), array("ZERO_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
+            $objErr->doFunc(array("商品価格", "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "ZERO_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+
+            if(isset($array['stock_unlinited']) && $array['stock_unlimited'] != "1") {
+                $objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
+            }
+        }
+
+        if(isset($array['sale_unlimited']) && $array['sale_unlimited'] != "1") {
+            $objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
+        }
+
+        if(isset($objErr->arrErr['category_id'])) {
+            // 自動選択を防ぐためにダミー文字を入れておく
+            $this->arrForm['category_id'] = "#";
+        }
+
+        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
+            $objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $this->arrAllowedTag),  array("HTML_TAG_CHECK"));
+        }
+
+        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
+            if($_POST["recommend_id$cnt"] != "" && $_POST["recommend_delete$cnt"] != 1) {
+                $objErr->doFunc(array("おすすめ商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+            }
+        }
+
+        return $objErr->arrErr;
+    }
+
+    /* 確認ページ表示用 */
+    function lfProductConfirmPage() {
+        $this->tpl_mainpage = 'products/confirm.tpl';
+        $this->arrForm['mode'] = 'complete';
+        $objDb = new SC_Helper_DB_Ex();
+        // カテゴリの読込
+        $this->arrCatList = $objDb->sfGetCategoryList();
+        // Form用配列を渡す。
+        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
+    }
+
+    /* 規格あり判定用(規格が登録されていない場合:TRUE) */
+    function lfCheckNonClass($product_id) {
+        if(SC_Utils_Ex::sfIsInt($product_id)) {
+            $objQuery  = new SC_Query();
+            $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0";
+            $count = $objQuery->count("dtb_products_class", $where, array($product_id));
+            if($count > 0) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    // 縮小した画像をセットする
+    function lfSetScaleImage(){
+
+        $subno = str_replace("sub_large_image", "", $_POST['image_key']);
+        switch ($_POST['image_key']){
+            case "main_large_image":
+                // 詳細メイン画像
+                $this->lfMakeScaleImage($_POST['image_key'], "main_image");
+            case "main_image":
+                // 一覧メイン画像
+                $this->lfMakeScaleImage($_POST['image_key'], "main_list_image");
+                break;
+            case "sub_large_image" . $subno:
+                // サブメイン画像
+                $this->lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno);
+                break;
+            default:
+                break;
+        }
+    }
+
+    // 縮小画像生成
+    function lfMakeScaleImage($from_key, $to_key, $forced = false){
+        $arrImageKey = array_flip($this->objUpFile->keyname);
+
+        if($this->objUpFile->temp_file[$arrImageKey[$from_key]]){
+            $from_path = $this->objUpFile->temp_dir . $this->objUpFile->temp_file[$arrImageKey[$from_key]];
+        }elseif($this->objUpFile->save_file[$arrImageKey[$from_key]]){
+            $from_path = $this->objUpFile->save_dir . $this->objUpFile->save_file[$arrImageKey[$from_key]];
+        }else{
+            return "";
+        }
+
+        if(file_exists($from_path)){
+            // 元画像サイズを取得
+            list($from_w, $from_h) = getimagesize($from_path);
+
+            // 生成先の画像サイズを取得
+            $to_w = $this->objUpFile->width[$arrImageKey[$to_key]];
+            $to_h = $this->objUpFile->height[$arrImageKey[$to_key]];
+
+
+            if($forced) $this->objUpFile->save_file[$arrImageKey[$to_key]] = "";
+
+            if((isset($this->objUpFile->temp_file[$arrImageKey[$to_key]])
+                   && $this->objUpFile->temp_file[$arrImageKey[$to_key]] == ""
+                and isset($this->objUpFile->save_file[$arrImageKey[$to_key]])
+                       && $this->objUpFile->save_file[$arrImageKey[$to_key]] == "")) {
+
+                $path = $this->objUpFile->makeThumb($from_path, $to_w, $to_h);
+                $this->objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path);
+            }
+        }else{
+            return "";
+        }
+    }
+}
+?>
