Index: branches/version-2_4/data/class/helper/SC_Helper_CSV.php
===================================================================
--- branches/version-2_4/data/class/helper/SC_Helper_CSV.php	(revision 18174)
+++ branches/version-2_4/data/class/helper/SC_Helper_CSV.php	(revision 18543)
@@ -99,52 +99,61 @@
     }
 
-
-    // CSV出力データを作成する。(商品)
-    function lfGetProductsCSV($where, $option, $arrval, $arrOutputCols) {
-        $objDb = new SC_Helper_DB_Ex();
-
-        $from = "vw_product_class AS prdcls";
-        $cols = SC_Utils_Ex::sfGetCommaList($arrOutputCols, true, array('category_id'));
-
-        $objQuery = new SC_Query();
-        $objQuery->setoption($option);
-
-        $list_data = $objQuery->select($cols, $from, $where, $arrval);
-        $max = count($list_data);
+    // CSVを送信する。(商品)
+    function sfDownloadProductsCsv($where, $arrval, $order) {
+
+        // CSV出力タイトル行の作成
+        $arrOutput = SC_Utils_Ex::sfSwapArray($this->sfgetCsvOutput(1, " WHERE csv_id = 1 AND status = 1"));
+        if (count($arrOutput) <= 0) return false; // 失敗終了
+        $arrOutputCols = $arrOutput['col'];
+
+        $objQuery = new SC_Query();
+        $objQuery->setorder($order);
+
+        $dataRows = $objQuery->select(
+             SC_Utils_Ex::sfGetCommaList($arrOutputCols, true, array('category_id'))
+            ,'vw_product_class AS prdcls'
+            ,$where
+            ,$arrval
+        );
 
         // 規格分類名一覧
         if (in_array('classcategory_id1', $arrOutputCols) || in_array('classcategory_id2', $arrOutputCols)) {
+            $objDb = new SC_Helper_DB_Ex();
             $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
         }
 
-        if (!isset($data)) $data = "";
-        for($i = 0; $i < $max; $i++) {
-            // 関連商品情報の付与
+        $outputArray = array();
+
+        // ヘッダ行
+        $outputArray[] = $arrOutput['disp_name'];
+
+        // データ行
+        foreach ($dataRows as $row) {
+            // 規格名1
             if (in_array('classcategory_id1', $arrOutputCols)) {
-                $list_data[$i]['classcategory_id1'] = $arrClassCatName[$list_data[$i]['classcategory_id1']];
-            }
+                $row['classcategory_id1'] = $arrClassCatName[$row['classcategory_id1']];
+            }
+
+            // 規格名2
             if (in_array('classcategory_id2', $arrOutputCols)) {
-                $list_data[$i]['classcategory_id2'] = $arrClassCatName[$list_data[$i]['classcategory_id2']];
-            }
-
+                $row['classcategory_id2'] = $arrClassCatName[$row['classcategory_id2']];
+            }
+
+            // カテゴリID
             if (in_array('category_id', $arrOutputCols)) {
-                $arrCategory_id = $objQuery->getCol("dtb_product_categories",
+                $row['category_id'] = $objQuery->getCol("dtb_product_categories",
                                   "category_id",
                                   "product_id = ?",
-                                  array($list_data[$i]['product_id']));
-
-                // カテゴリID 付与
-                for ($j = 0; $j < count($arrCategory_id); $j++) {
-                    $list_data[$i]['category_id'] .= $arrCategory_id[$j];
-                    if ($j < count($arrCategory_id) - 1) {
-                        $list_data[$i]['category_id'] .= "|";
-                    }
-                }
-            }
-
-            // 各項目をCSV出力用に変換する。
-            $data .= $this->lfMakeProductsCSV($list_data[$i]);
-        }
-        return $data;
+                                   array($row['product_id']));
+         }
+
+           $outputArray[] = $row;
+       }
+
+       // CSVを送信する。
+       $this->lfDownloadCsv($outputArray);
+
+       // 成功終了
+       return true;
     }
 
@@ -188,23 +197,36 @@
     }
 
-    // CSV出力データを作成する。(カテゴリ)
-    function lfGetCategoryCSV($where, $option, $arrval, $arrOutputCols) {
-        $objDb = new SC_Helper_DB_Ex();
-
-        $from = "dtb_category";
-        $cols = SC_Utils_Ex::sfGetCommaList($arrOutputCols);
-
-        $objQuery = new SC_Query();
-        $objQuery->setoption($option);
-
-        $list_data = $objQuery->select($cols, $from, $where, $arrval);
-        $max = count($list_data);
-
-        if (!isset($data)) $data = "";
-        for($i = 0; $i < $max; $i++) {
-            // 各項目をCSV出力用に変換する。
-            $data .= $this->lfMakeCSV($list_data[$i]);
-        }
-        return $data;
+    // CSVを送信する。(カテゴリ)
+    function sfDownloadCategoryCsv() {
+
+    // CSV出力タイトル行の作成
+    $arrOutput = SC_Utils_Ex::sfSwapArray($this->sfgetCsvOutput(5, " WHERE csv_id = 5 AND status = 1"));
+    if (count($arrOutput) <= 0) return false; // 失敗終了
+        $arrOutputCols = $arrOutput['col'];
+
+        $objQuery = new SC_Query();
+        $objQuery->setorder('rank DESC');
+
+        $dataRows = $objQuery->select(
+             SC_Utils_Ex::sfGetCommaList($arrOutputCols)
+            ,'dtb_category'
+            ,'del_flg = 0'
+        );
+
+        $outputArray = array();
+
+        // ヘッダ行
+        $outputArray[] = $arrOutput['disp_name'];
+
+        // データ行
+        foreach ($dataRows as $row) {
+            $outputArray[] = $row;
+        }
+
+        // CSVを送信する。
+        $this->lfDownloadCsv($outputArray, 'category');
+
+        // 成功終了
+        return true;
     }
 
@@ -231,12 +253,10 @@
     function lfMakeCSV($list) {
         $line = "";
-		
-		reset($list);
+
+        reset($list);
         while(list($key, $val) = each($list)){
             $tmp = "";
             switch($key) {
             case 'order_pref':
-                $tmp = $this->arrPref[$val];
-                break;
             case 'deliv_pref':
                 $tmp = $this->arrPref[$val];
@@ -255,37 +275,9 @@
     }
 
-    // 各項目をCSV出力用に変換する。(商品)
-    function lfMakeProductsCSV($list) {
-        $line = "";
-        if(is_array($list)) {
-			reset($list);
-        	while(list($key, $val) = each($list)){
-                $tmp = "";
-                switch($key) {
-                case 'point_rate':
-                    if($val == "") {
-                        $tmp = '0';
-                    } else {
-                        $tmp = $val;
-                    }
-                    break;
-                default:
-                    $tmp = $val;
-                    break;
-                }
-                $tmp = str_replace("\"", "\\\"", $tmp);
-                $line .= "\"".$tmp."\",";
-            }
-            // 文末の","を変換
-            $line = $this->replaceLineSuffix($line);
-        }
-        return $line;
-    }
-
     // 各項目をCSV出力用に変換する。(レビュー)
     function lfMakeReviewCSV($list) {
         $line = "";
-		reset($list);
-    	while(list($key, $val) = each($list)){
+        reset($list);
+        while(list($key, $val) = each($list)){
             $tmp = "";
             switch($key) {
@@ -316,6 +308,6 @@
     function lfMakeTrackbackCSV($list) {
         $line = "";
-		reset($list);
-    	while(list($key, $val) = each($list)){
+        reset($list);
+        while(list($key, $val) = each($list)){
             $tmp = "";
             switch($key) {
@@ -411,4 +403,67 @@
                                            );
     }
+
+
+    /**
+     * 1次元配列を1行のCSVとして返す
+     * 参考: http://jp.php.net/fputcsv
+     */
+    function sfArrayToCsv($fields, $delimiter = ',', $enclosure = '"', $arrayDelimiter = '|') {
+
+        if( strlen($delimiter) != 1 ) {
+            trigger_error('delimiter must be a single character', E_USER_WARNING);
+            return "";
+        }
+
+        if( strlen($enclosure) < 1 ) {
+            trigger_error('enclosure must be a single character', E_USER_WARNING);
+            return "";
+        }
+
+        foreach (array_keys($fields) as $key) {
+            $field =& $fields[$key];
+
+            // 配列を「|」区切りの文字列に変換する
+            if (is_array($field)) {
+                $field = implode($arrayDelimiter, $field);
+            }
+
+            /* enclose a field that contains a delimiter, an enclosure character, or a newline */
+            if (
+                   is_string($field)
+                && preg_match('/[' . preg_quote($delimiter) . preg_quote($enclosure) . '\\s]/', $field)
+            ) {
+                $field = $enclosure . preg_replace('/' . preg_quote($enclosure) . '/', $enclosure . $enclosure, $field) . $enclosure;
+            }
+        }
+
+        return implode($delimiter, $fields);
+    }
+
+    /**
+     * CSVを送信する。
+     */
+    function lfDownloadCsv($arrayData, $prefix = ""){
+
+        if($prefix == "") {
+            $dir_name = SC_Utils::sfUpDirName();
+            $file_name = $dir_name . date("ymdHis") .".csv";
+        } else {
+            $file_name = $prefix . date("ymdHis") .".csv";
+        }
+
+        /* HTTPヘッダの出力 */
+        Header("Content-disposition: attachment; filename=${file_name}");
+        Header("Content-type: application/octet-stream; name=${file_name}");
+        Header("Cache-Control: ");
+        Header("Pragma: ");
+
+        /* データを出力 */
+        foreach ($arrayData as $lineArray) {
+            $lineString = $this->sfArrayToCsv($lineArray);
+            $lineString = mb_convert_encoding($lineString, 'SJIS-Win');
+            echo $lineString . "\n";
+        }
+    }
 }
 ?>
Index: branches/version-2_4/data/class/pages/admin/products/LC_Page_Admin_Products_Category.php
===================================================================
--- branches/version-2_4/data/class/pages/admin/products/LC_Page_Admin_Products_Category.php	(revision 18262)
+++ branches/version-2_4/data/class/pages/admin/products/LC_Page_Admin_Products_Category.php	(revision 18543)
@@ -180,23 +180,8 @@
 
             $objCSV = new SC_Helper_CSV_Ex();
-            // オプションの指定
-            $option = "ORDER BY rank DESC";
-            // CSV出力タイトル行の作成
-            $arrOutput = SC_Utils_Ex::sfSwapArray($objCSV->sfgetCsvOutput(5, " WHERE csv_id = 5 AND status = 1"));
-
-            if (count($arrOutput) <= 0) break;
-
-            $arrOutputCols = $arrOutput['col'];
-            $arrOutputTitle = $arrOutput['disp_name'];
-
-            $head = SC_Utils_Ex::sfGetCSVList($arrOutputTitle);
-
-            $where = "del_flg = 0";
-            $arrval = array();
-            $data = $objCSV->lfGetCategoryCSV($where, $option, $arrval, $arrOutputCols);
-
-            // CSVを送信する。
-            SC_Utils_Ex::sfCSVDownload($head.$data, 'category');
-            exit;
+
+            // CSVを送信する。正常終了の場合、終了。
+            $objCSV->sfDownloadCategoryCsv() && exit;
+
             break;
         default:
Index: branches/version-2_4/data/class/pages/admin/products/LC_Page_Admin_Products.php
===================================================================
--- branches/version-2_4/data/class/pages/admin/products/LC_Page_Admin_Products.php	(revision 17823)
+++ branches/version-2_4/data/class/pages/admin/products/LC_Page_Admin_Products.php	(revision 18543)
@@ -164,5 +164,5 @@
 
                     switch ($key) {
-                        case 'search_product_id':	// 商品ID
+                        case 'search_product_id': // 商品ID
                             $where .= " AND product_id = ?";
                             $view_where .= " AND product_id = ?";
@@ -179,10 +179,10 @@
                             $view_where = $where;
                             break;
-                        case 'search_name':			// 商品名
+                        case 'search_name': // 商品名
                             $where .= " AND name ILIKE ?";
                             $view_where .= " AND name ILIKE ?";
                             $arrval[] = "%$val%";
                             break;
-                        case 'search_category_id':	// カテゴリー
+                        case 'search_category_id': // カテゴリー
                             list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($val);
                             if($tmp_where != "") {
@@ -192,15 +192,15 @@
                             }
                             break;
-                        case 'search_product_code':	// 商品コード
+                        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）
+                        case 'search_startyear': // 登録更新日（FROM）
                             $date = SC_Utils_Ex::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）
+                        case 'search_endyear': // 登録更新日（TO）
                             $date = SC_Utils_Ex::sfGetTimestamp($_POST['search_endyear'], $_POST['search_endmonth'], $_POST['search_endday']);
                             $date = date('Y/m/d', strtotime($date) + 86400);
@@ -208,5 +208,5 @@
                             $view_where.= " AND update_date < date('" . $date . "')";
                             break;
-                        case 'search_product_flag':	//種別
+                        case 'search_product_flag': //種別
                             global $arrSTATUS;
                             $search_product_flag = SC_Utils_Ex::sfSearchCheckBoxes($val);
@@ -217,5 +217,5 @@
                             }
                             break;
-                        case 'search_status':		// ステータス
+                        case 'search_status': // ステータス
                             $tmp_where = "";
                             foreach ($val as $element){
@@ -244,88 +244,67 @@
 
                 switch($_POST['mode']) {
-                case 'csv':
-
-                    require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
-
-                    $objCSV = new SC_Helper_CSV_Ex();
-                    // オプションの指定
-                    $option = "ORDER BY $order";
-                    // CSV出力タイトル行の作成
-                    $arrOutput = SC_Utils_Ex::sfSwapArray($objCSV->sfgetCsvOutput(1, " WHERE csv_id = 1 AND status = 1"));
-
-                    if (count($arrOutput) <= 0) break;
-
-                    $arrOutputCols = $arrOutput['col'];
-                    $arrOutputTitle = $arrOutput['disp_name'];
-
-                    $head = SC_Utils_Ex::sfGetCSVList($arrOutputTitle);
-
-                    $data = $objCSV->lfGetProductsCSV($where, $option, $arrval, $arrOutputCols);
-
-                    // CSVを送信する。
-                    SC_Utils_Ex::sfCSVDownload($head.$data);
-                    exit;
-                    break;
-                case 'delete_all':
-                    // 検索結果の取得
-                    $col = "product_id";
-                    $from = "vw_products_nonclass AS noncls ";
-                    $arrProducts = $objQuery->select($col, $from, $where, $arrval);
-                    // 検索結果をすべて削除
-                    $sqlval['del_flg'] = 1;
-                    $where = "product_id = ?";
-                    if (count($arrProducts) > 0) {
-                        foreach ($arrProducts as $key => $val) {
-                            $objQuery->update("dtb_products", $sqlval, $where, array($arrProducts[$key]["product_id"]));
+                    case 'csv':
+                        require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
+
+                        $objCSV = new SC_Helper_CSV_Ex();
+
+                        // CSVを送信する。正常終了の場合、終了。
+                        $objCSV->sfDownloadProductsCsv($where, $arrval, $order) && exit;
+
+                        break;
+                    case 'delete_all':
+                        // 検索結果をすべて削除
+                        $where = "product_id IN (SELECT product_id FROM vw_products_allclass_detail AS alldtl WHERE $where)";
+                        $sqlval['del_flg'] = 1;
+                        $objQuery->update("dtb_products", $sqlval, $where, $arrval);
+                        $objQuery->delete("dtb_customer_favorite_products", $where, $arrval);
+                        break;
+                    default:
+                        // 読み込む列とテーブルの指定
+                        $col = "product_id, name, main_list_image, status, product_code_min, product_code_max, price02_min, price02_max, stock_min, stock_max, stock_unlimited_min, stock_unlimited_max, update_date";
+                        $from = "vw_products_allclass_detail AS alldtl ";
+
+                        // 行数の取得
+                        $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;
                         }
-                    }
-                    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;
+
+                        // ページ送りの取得
+                        $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->setlimitoffset($page_max, $startno);
-                    // 表示順序
-                    $objQuery->setorder($order);
-
-                    // 検索結果の取得
-                    $this->arrProducts = $objQuery->select($col, $from, $where, $arrval);
-
-                    // 各商品ごとのカテゴリIDを取得
-                    if (count($this->arrProducts) > 0) {
-                        foreach ($this->arrProducts as $key => $val) {
-                            $this->arrProducts[$key]["categories"] = $objDb->sfGetCategoryId($val["product_id"]);
-                            $objDb->g_category_on = false;
+
+                        // 取得範囲の指定(開始行番号、行数のセット)
+                        //                    if(DB_TYPE != "mysql") $objQuery->setlimitoffset($page_max, $startno);
+                        $objQuery->setlimitoffset($page_max, $startno);
+                        // 表示順序
+                        $objQuery->setorder($order);
+
+                        // 検索結果の取得
+                        $this->arrProducts = $objQuery->select($col, $from, $where, $arrval);
+
+                        // 各商品ごとのカテゴリIDを取得
+                        if (count($this->arrProducts) > 0) {
+                            foreach ($this->arrProducts as $key => $val) {
+                                $this->arrProducts[$key]["categories"] = $objDb->sfGetCategoryId($val["product_id"]);
+                                $objDb->g_category_on = false;
+                            }
                         }
-                    }
                 }
             }
@@ -354,9 +333,9 @@
         global $objPage;
         /*
-         *	文字列の変換
-         *	K :  「半角(ﾊﾝｶｸ)片仮名」を「全角片仮名」に変換
-         *	C :  「全角ひら仮名」を「全角かた仮名」に変換
-         *	V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
-         *	n :  「全角」数字を「半角(ﾊﾝｶｸ)」に変換
+         * 文字列の変換
+         * K :  「半角(ﾊﾝｶｸ)片仮名」を「全角片仮名」に変換
+         * C :  「全角ひら仮名」を「全角かた仮名」に変換
+         * V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
+         * n :  「全角」数字を「半角(ﾊﾝｶｸ)」に変換
          */
         $arrConvList['search_name'] = "KVa";
