Index: branches/version-2_12-dev/data/class_extends/helper_extends/SC_Helper_Mailtemplate_Ex.php
===================================================================
--- branches/version-2_12-dev/data/class_extends/helper_extends/SC_Helper_Mailtemplate_Ex.php	(revision 22584)
+++ branches/version-2_12-dev/data/class_extends/helper_extends/SC_Helper_Mailtemplate_Ex.php	(revision 22584)
@@ -0,0 +1,39 @@
+<?php
+/*
+ * This file is part of EC-CUBE
+ *
+ * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+// {{{ requires
+require_once CLASS_REALDIR . 'helper/SC_Helper_Mailtemplate.php';
+
+/**
+ * メールテンプレートを管理するヘルパークラス(拡張).
+ *
+ * LC_Helper_Mailtemplate をカスタマイズする場合はこのクラスを編集する.
+ *
+ * @package Helper
+ * @author pineray
+ * @version $Id:$
+ */
+class SC_Helper_Mailtemplate_Ex extends SC_Helper_Mailtemplate
+{
+    //put your code here
+}
Index: branches/version-2_12-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Mail.php
===================================================================
--- branches/version-2_12-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Mail.php	(revision 22567)
+++ branches/version-2_12-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Mail.php	(revision 22584)
@@ -227,6 +227,4 @@
     function changeData(&$objFormParam)
     {
-        $objQuery =& SC_Query_Ex::getSingletonInstance();
-
         $template_id = $objFormParam->getValue('template_id');
 
@@ -237,7 +235,6 @@
         // 有効選択時
         elseif (SC_Utils_Ex::sfIsInt($template_id)) {
-            $where = 'template_id = ?';
-            $arrWhereVal = array($template_id);
-            $mailTemplates = $objQuery->getRow('subject, header, footer', 'dtb_mailtemplate', $where, $arrWhereVal);
+            $objMailtemplate = new SC_Helper_Mailtemplate_Ex();
+            $mailTemplates = $objMailtemplate->get($template_id);
         }
         // 不正選択時
Index: branches/version-2_12-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_Mail.php
===================================================================
--- branches/version-2_12-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_Mail.php	(revision 22567)
+++ branches/version-2_12-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_Mail.php	(revision 22584)
@@ -73,4 +73,5 @@
 
         $masterData = new SC_DB_MasterData_Ex();
+        $objMailtemplate = new SC_Helper_Mailtemplate_Ex();
 
         $mode = $this->getMode();
@@ -90,7 +91,7 @@
         switch ($mode) {
             case 'id_set':
-                    $result = $this->lfGetMailTemplateByTemplateID($post['template_id']);
-                    if ($result) {
-                        $this->arrForm = $result[0];
+                    $mailtemplate = $objMailtemplate->get($post['template_id']);
+                    if ($mailtemplate) {
+                        $this->arrForm = $mailtemplate;
                     } else {
                         $this->arrForm['template_id'] = $post['template_id'];
@@ -106,5 +107,5 @@
                     } else {
                         // 正常
-                        $this->lfRegistMailTemplate($this->arrForm, $_SESSION['member_id']);
+                        $this->lfRegistMailTemplate($this->arrForm, $_SESSION['member_id'], $objMailtemplate);
 
                         // 完了メッセージ
@@ -129,28 +130,8 @@
     }
 
-    function lfGetMailTemplateByTemplateID($template_id)
+    function lfRegistMailTemplate($post, $member_id, SC_Helper_Mailtemplate_Ex $objMailtemplate)
     {
-        $objQuery =& SC_Query_Ex::getSingletonInstance();
-
-        $sql = 'SELECT * FROM dtb_mailtemplate WHERE template_id = ?';
-        return $objQuery->getAll($sql, array($template_id));
-    }
-
-    function lfRegistMailTemplate($post, $member_id)
-    {
-        $objQuery =& SC_Query_Ex::getSingletonInstance();
-
         $post['creator_id'] = $member_id;
-        $post['update_date'] = 'CURRENT_TIMESTAMP';
-
-        $sql = 'SELECT * FROM dtb_mailtemplate WHERE template_id = ?';
-        $template_data = $objQuery->getAll($sql, array($post['template_id']));
-        if ($template_data) {
-            $sql_where = 'template_id = ?';
-            $objQuery->update('dtb_mailtemplate', $post, $sql_where, array(addslashes($post['template_id'])));
-        } else {
-            $objQuery->insert('dtb_mailtemplate', $post);
-        }
-
+        $objMailtemplate->save($post);
     }
 
Index: branches/version-2_12-dev/data/class/helper/SC_Helper_Mailtemplate.php
===================================================================
--- branches/version-2_12-dev/data/class/helper/SC_Helper_Mailtemplate.php	(revision 22584)
+++ branches/version-2_12-dev/data/class/helper/SC_Helper_Mailtemplate.php	(revision 22584)
@@ -0,0 +1,102 @@
+<?php
+/*
+ * This file is part of EC-CUBE
+ *
+ * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * メールテンプレートを管理するヘルパークラス.
+ *
+ * @package Helper
+ * @author pineray
+ * @version $Id:$
+ */
+class SC_Helper_Mailtemplate
+{
+    /**
+     * メールテンプレートの情報を取得.
+     * 
+     * @param integer $template_id メールテンプレートID
+     * @param boolean $has_deleted 削除されたメールテンプレートも含む場合 true; 初期値 false
+     * @return array
+     */
+    public function get($template_id, $has_deleted = false)
+    {
+        $objQuery =& SC_Query_Ex::getSingletonInstance();
+        $col = '*';
+        $where = 'template_id = ?';
+        if (!$has_deleted) {
+            $where .= ' AND del_flg = 0';
+        }
+        $arrRet = $objQuery->select($col, 'dtb_mailtemplate', $where, array($template_id));
+        return $arrRet[0];
+    }
+
+    /**
+     * メールテンプレート一覧の取得.
+     *
+     * @param boolean $has_deleted 削除されたメールテンプレートも含む場合 true; 初期値 false
+     * @return array
+     */
+    public function getList($has_deleted = false)
+    {
+        $objQuery =& SC_Query_Ex::getSingletonInstance();
+        $col = '*';
+        $where = '';
+        if (!$has_deleted) {
+            $where .= 'del_flg = 0';
+        }
+        $table = 'dtb_mailtemplate';
+        $arrRet = $objQuery->select($col, $table, $where);
+        return $arrRet;
+    }
+
+    /**
+     * メールテンプレートの登録.
+     * 
+     * @param array $sqlval
+     * @return multiple 登録成功:メールテンプレートID, 失敗:FALSE
+     */
+    public function save($sqlval)
+    {
+        $objQuery =& SC_Query_Ex::getSingletonInstance();
+
+        $template_id = $sqlval['template_id'];
+        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
+        // 存在確認
+        $where = 'template_id = ?';
+        $exist = $objQuery->exists('dtb_mailtemplate', $where, array($template_id));
+        // 新規登録
+        if (!$exist) {
+            // INSERTの実行
+            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
+            if (!$sqlval['template_id']) {
+                $sqlval['template_id'] = $objQuery->nextVal('dtb_mailtemplate_template_id');
+            }
+            $ret = $objQuery->insert('dtb_mailtemplate', $sqlval);
+        // 既存編集
+        } else {
+            unset($sqlval['creator_id']);
+            unset($sqlval['create_date']);
+            $ret = $objQuery->update('dtb_mailtemplate', $sqlval, $where, array($template_id));
+        }
+        return ($ret) ? $sqlval['template_id'] : FALSE;
+    }
+}
Index: branches/version-2_12-dev/data/class/helper/SC_Helper_Mail.php
===================================================================
--- branches/version-2_12-dev/data/class/helper/SC_Helper_Mail.php	(revision 22567)
+++ branches/version-2_12-dev/data/class/helper/SC_Helper_Mail.php	(revision 22584)
@@ -76,11 +76,10 @@
     {
 
-        $objQuery =& SC_Query_Ex::getSingletonInstance();
         // メールテンプレート情報の取得
-        $where = 'template_id = ?';
-        $arrRet = $objQuery->select('subject, header, footer', 'dtb_mailtemplate', $where, array($template_id));
-        $objPage->tpl_header = $arrRet[0]['header'];
-        $objPage->tpl_footer = $arrRet[0]['footer'];
-        $tmp_subject = $arrRet[0]['subject'];
+        $objMailtemplate = new SC_Helper_Mailtemplate_Ex();
+        $mailtemplate = $objMailtemplate->get($template_id);
+        $objPage->tpl_header = $mailtemplate['header'];
+        $objPage->tpl_footer = $mailtemplate['footer'];
+        $tmp_subject = $mailtemplate['subject'];
 
         $arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
@@ -117,9 +116,9 @@
         if ($subject == '' && $header == '' && $footer == '') {
             // メールテンプレート情報の取得
-            $where = 'template_id = ?';
-            $arrRet = $objQuery->select('subject, header, footer', 'dtb_mailtemplate', $where, array($template_id));
-            $arrTplVar->tpl_header = $arrRet[0]['header'];
-            $arrTplVar->tpl_footer = $arrRet[0]['footer'];
-            $tmp_subject = $arrRet[0]['subject'];
+            $objMailtemplate = new SC_Helper_Mailtemplate_Ex();
+            $mailtemplate = $objMailtemplate->get($template_id);
+            $arrTplVar->tpl_header = $mailtemplate['header'];
+            $arrTplVar->tpl_footer = $mailtemplate['footer'];
+            $tmp_subject = $mailtemplate['subject'];
         } else {
             $arrTplVar->tpl_header = $header;
