source: branches/version-2_5-dev/data/class/pages/admin/mail/LC_Page_Admin_Mail.php @ 20764

Revision 20764, 11.1 KB checked in by nanasess, 13 years ago (diff)

#601 (コピーライトの更新)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * メルマガ管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Mail extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'mail/index.tpl';
47        $this->tpl_mainno = 'mail';
48        $this->tpl_subnavi = 'mail/subnavi.tpl';
49        $this->tpl_subno = 'index';
50        $this->tpl_pager = 'pager.tpl';
51        $this->tpl_subtitle = '配信内容設定';
52
53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrPref = $masterData->getMasterData('mtb_pref');
55        $this->arrJob = $masterData->getMasterData("mtb_job");
56        $this->arrJob["不明"] = "不明";
57        $this->arrSex = $masterData->getMasterData("mtb_sex");
58        $this->arrPageRows = $masterData->getMasterData("mtb_page_max");
59        $this->arrHtmlmail = array( "" => "両方",  1 => 'HTML', 2 => 'TEXT' );
60        $this->arrMailType = $masterData->getMasterData("mtb_mail_type");
61
62        // 日付プルダウン設定
63        $objDate = new SC_Date_Ex(BIRTH_YEAR);
64        $this->arrYear = $objDate->getYear();   
65        $this->arrMonth = $objDate->getMonth();
66        $this->arrDay = $objDate->getDay();
67        $this->objDate = $objDate;
68
69        // カテゴリ一覧設定
70        $objDb = new SC_Helper_DB_Ex();
71        $this->arrCatList = $objDb->sfGetCategoryList();
72
73        // テンプレート一覧設定
74        $this->arrTemplate = $this->lfGetMailTemplateList(SC_Helper_Mail_Ex::sfGetMailmagaTemplate());
75
76        $this->httpCacheControl('nocache');
77    }
78
79    /**
80     * Page のプロセス.
81     *
82     * @return void
83     */
84    function process() {
85        $this->action();
86        $this->sendResponse();
87    }
88
89    /**
90     * Page のアクション.
91     *
92     * @return void
93     */
94    function action() {
95
96        // パラメータ管理クラス
97        $objFormParam = new SC_FormParam_Ex();
98        $this->lfInitParamSearchCustomer($objFormParam);
99        $objFormParam->setParam($_POST);
100
101        // パラメーター読み込み
102        $this->arrHidden = $objFormParam->getSearchArray();
103
104        // 入力パラメーターチェック
105        $this->arrErr = SC_Helper_Customer_Ex::sfCheckErrorSearchParam($objFormParam);
106        $this->arrForm = $objFormParam->getFormParamList();
107        if(!SC_Utils_Ex::isBlank($this->arrErr)) return;
108
109        // モードによる処理切り替え
110        switch ($this->getMode()) {
111        // 配信先検索
112        case 'search':
113        case 'back':
114            list($this->tpl_linemax, $this->arrResults, $this->objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray());
115            $this->arrPagenavi = $this->objNavi->arrPagenavi;
116            break;
117        // input:検索結果画面「配信内容を設定する」押下後
118        case 'input':
119            $this->tpl_mainpage = 'mail/input.tpl';
120            break;
121        // template:テンプレート選択時
122        case 'template':
123        case 'regist_back':
124            $this->tpl_mainpage = 'mail/input.tpl';
125            if (SC_Utils_Ex::sfIsInt($_POST['template_id']) === true) {
126                $this->lfAddParamSelectTemplate($objFormParam);
127                $this->lfGetTemplateData($objFormParam, $_POST['template_id']);
128                // regist_back時、subject,bodyにはテンプレートを読み込むのではなく、入力内容で上書き
129                if($this->getMode()=='regist_back') $objFormParam->setParam($_POST);
130            }
131            break;
132        case 'regist_confirm':
133            $this->tpl_mainpage = 'mail/input.tpl';
134            $this->lfAddParamSelectTemplate($objFormParam);
135            $objFormParam->setParam($_POST);
136            $this->arrErr = $objFormParam->checkError();
137            if (SC_Utils_Ex::isBlank($this->arrErr)) $this->tpl_mainpage = 'mail/input_confirm.tpl';
138            break;
139        case 'regist_complete':
140            $this->tpl_mainpage = 'mail/input.tpl';
141            $this->lfAddParamSelectTemplate($objFormParam);
142            $objFormParam->setParam($_POST);
143            $this->arrErr = $objFormParam->checkError();
144            if (SC_Utils_Ex::isBlank($this->arrErr)){
145                $this->tpl_mainpage = 'mail/index.tpl';
146                SC_Helper_Mail_Ex::sfSendMailmagazine($this->lfRegisterData($objFormParam));  // DB登録・送信
147                SC_Response_Ex::sendRedirect("./history.php");
148            }
149            break;
150        // query:配信履歴から「確認」
151        case 'query':
152            if (SC_Utils_Ex::sfIsInt($_GET["send_id"])) {
153                $this->arrSearchData = $this->lfGetMailQuery();
154            }
155            $this->setTemplate('mail/query.tpl');
156            break;
157        // query:配信履歴から「再送信」
158        case 'retry':
159            if (SC_Utils_Ex::sfIsInt($_GET["send_id"])) {
160                SC_Helper_Mail_Ex::sfSendMailmagazine($_GET['send_id']);  // DB登録・送信
161                SC_Response_Ex::sendRedirect("./history.php");
162            } else {
163                $this->tpl_onload = "window.alert('メール送信IDが正しくありません');";
164            }
165        default:
166            break;
167        }
168        $this->arrForm = $objFormParam->getFormParamList();
169    }
170
171    /**
172     * デストラクタ.
173     *
174     * @return void
175     */
176    function destroy() {
177        parent::destroy();
178    }
179
180    /**
181     * パラメーター情報の初期化(初期顧客検索時)
182     *
183     * @param array $objFormParam フォームパラメータークラス
184     * @return void
185     */
186    function lfInitParamSearchCustomer(&$objFormParam) {
187        SC_Helper_Customer_Ex::sfSetSearchParam($objFormParam);
188        $objFormParam->addParam('配信形式', 'search_htmlmail', INT_LEN, 'n', array("NUM_CHECK","MAX_LENGTH_CHECK"));
189        $objFormParam->addParam('配信メールアドレス種別', 'search_mail_type', INT_LEN, 'n', array("NUM_CHECK","MAX_LENGTH_CHECK"));
190    }
191
192    /**
193     * パラメーター情報の追加(テンプレート選択)
194     *
195     * @param array $objFormParam フォームパラメータークラス
196     * @return void
197     */
198    function lfAddParamSelectTemplate(&$objFormParam) {
199        $objFormParam->addParam("メール形式", 'mail_method', INT_LEN, 'n', array("EXIST_CHECK","ALNUM_CHECK"));
200        $objFormParam->addParam('Subject', 'subject', STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
201        $objFormParam->addParam("本文", 'body', LLTEXT_LEN, 'KVCa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
202        $objFormParam->addParam("テンプレートID", "template_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
203    }
204
205    /**
206     * メルマガテンプレート一覧情報の取得
207     *
208     * @param array $arrTemplate SC_Helper_Mail_Ex::sfGetMailmagaTemplate()の戻り値
209     * @return array key:template_id value:サブジェクト【配信形式】
210     */
211    function lfGetMailTemplateList($arrTemplate){
212        if ( is_array($arrTemplate) ){
213            foreach( $arrTemplate as $line ){
214                $return[$line['template_id']] = "【" . $this->arrHtmlmail[$line['mail_method']] . "】" . $line['subject'];
215            }
216        }
217        return $return;
218    }
219
220    /**
221     * テンプレートIDから情報の取得して$objFormParamにset_paramする
222     *
223     * @param array $objFormParam フォームパラメータークラス
224     * @param array $template_id テンプレートID
225     * @return void
226     */
227    function lfGetTemplateData(&$objFormParam, $template_id){
228        $objQuery =& SC_Query_Ex::getSingletonInstance();
229        $objQuery->setOrder("template_id DESC");
230        $where = 'template_id = ?';
231        $arrResults = $objQuery->getRow('*', 'dtb_mailmaga_template', $where, array($template_id));
232        $objFormParam->setParam($arrResults);
233    }
234
235    /**
236     * 配信内容と配信リストを書き込む
237     *
238     * @return integer 登録した行の dtb_send_history.send_id の値
239     */
240    function lfRegisterData(&$objFormParam){
241        $objQuery =& SC_Query_Ex::getSingletonInstance();
242
243        list($linemax, $arrSendCustomer, $objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray());
244        $send_customer_cnt = count($arrSendCustomer);
245
246        $send_id = $objQuery->nextVal('dtb_send_history_send_id');
247        $dtb_send_history = array();
248        $dtb_send_history["mail_method"] = $objFormParam->getValue('mail_method');
249        $dtb_send_history['subject'] = $objFormParam->getValue('subject');
250        $dtb_send_history['body'] = $objFormParam->getValue('body');
251        $dtb_send_history["start_date"] = "now()";
252        $dtb_send_history["creator_id"] = $_SESSION['member_id'];
253        $dtb_send_history["send_count"] = $send_customer_cnt;
254        $dtb_send_history["search_data"] = serialize($objFormParam->getSearchArray());
255        $dtb_send_history["update_date"] = "now()";
256        $dtb_send_history["create_date"] = "now()";
257        $dtb_send_history['send_id'] = $send_id;
258        $objQuery->insert("dtb_send_history", $dtb_send_history );
259
260        if ( is_array( $arrSendCustomer ) ){
261            foreach( $arrSendCustomer as $line ){
262                $dtb_send_customer = array();
263                $dtb_send_customer["customer_id"] = $line["customer_id"];
264                $dtb_send_customer["send_id"] = $send_id;
265                $dtb_send_customer['email'] = $line['email'];
266                $dtb_send_customer['name'] = $line["name01"] . " " . $line["name02"];
267                $objQuery->insert("dtb_send_customer", $dtb_send_customer );
268            }
269        }
270        return $send_id;
271    }
272
273    /**
274     * 配信履歴から条件を取得する
275     *
276     * @param integer $send_id 配信履歴番号
277     * @return array
278     */
279    function lfGetMailQuery($send_id){
280
281        $objQuery =& SC_Query_Ex::getSingletonInstance();
282
283        // 送信履歴より、送信条件確認画面
284        $sql = "SELECT search_data FROM dtb_send_history WHERE send_id = ?";
285        $searchData = $objQuery->getOne($sql, array($_GET["send_id"]));
286        return unserialize($searchData);
287    }
288}
289?>
Note: See TracBrowser for help on using the repository browser.