Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Admin_Mail.php

Documentation is available at LC_Page_Admin_Mail.php

  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
  25. require_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: LC_Page_Admin_Mail.php 21217 2011-08-24 03:58:36Z Seasoft $
  33.  */
  34. class 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_subno = 'index';
  49.         $this->tpl_pager = 'pager.tpl';
  50.         $this->tpl_maintitle = 'メルマガ管理';
  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->arrBirthYear = $objDate->getYear();
  65.         $this->arrRegistYear = $objDate->getYear();
  66.         $this->arrMonth = $objDate->getMonth();
  67.         $this->arrDay = $objDate->getDay();
  68.         $this->objDate = $objDate;
  69.  
  70.         // カテゴリ一覧設定
  71.         $objDb = new SC_Helper_DB_Ex();
  72.         $this->arrCatList = $objDb->sfGetCategoryList();
  73.  
  74.         // テンプレート一覧設定
  75.         $this->arrTemplate = $this->lfGetMailTemplateList(SC_Helper_Mail_Ex::sfGetMailmagaTemplate());
  76.  
  77.         $this->httpCacheControl('nocache');
  78.     }
  79.  
  80.     /**
  81.      * Page のプロセス.
  82.      *
  83.      * @return void 
  84.      */
  85.     function process() {
  86.         $this->action();
  87.         $this->sendResponse();
  88.     }
  89.  
  90.     /**
  91.      * Page のアクション.
  92.      *
  93.      * @return void 
  94.      */
  95.     function action() {
  96.  
  97.         // パラメーター管理クラス
  98.         $objFormParam = new SC_FormParam_Ex();
  99.         $this->lfInitParamSearchCustomer($objFormParam);
  100.         $objFormParam->setParam($_POST);
  101.  
  102.         // パラメーター読み込み
  103.         $this->arrHidden = $objFormParam->getSearchArray();
  104.  
  105.         // 入力パラメーターチェック
  106.         $this->arrErr = SC_Helper_Customer_Ex::sfCheckErrorSearchParam($objFormParam);
  107.         $this->arrForm = $objFormParam->getFormParamList();
  108.         if(!SC_Utils_Ex::isBlank($this->arrErr)) return;
  109.  
  110.         // モードによる処理切り替え
  111.         switch ($this->getMode()) {
  112.         // 配信先検索
  113.         case 'search':
  114.         case 'back':
  115.             list($this->tpl_linemax, $this->arrResults, $this->objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray());
  116.             $this->arrPagenavi = $this->objNavi->arrPagenavi;
  117.             break;
  118.         // input:検索結果画面「配信内容を設定する」押下後
  119.         case 'input':
  120.             $this->tpl_mainpage = 'mail/input.tpl';
  121.             break;
  122.         // template:テンプレート選択時
  123.         case 'template':
  124.         case 'regist_back':
  125.             $this->tpl_mainpage = 'mail/input.tpl';
  126.             if (SC_Utils_Ex::sfIsInt($_POST['template_id']) === true) {
  127.                 $this->lfAddParamSelectTemplate($objFormParam);
  128.                 $this->lfGetTemplateData($objFormParam, $_POST['template_id']);
  129.                 // regist_back時、subject,bodyにはテンプレートを読み込むのではなく、入力内容で上書き
  130.                 if($this->getMode()=='regist_back') $objFormParam->setParam($_POST);
  131.             }
  132.             break;
  133.         case 'regist_confirm':
  134.             $this->tpl_mainpage = 'mail/input.tpl';
  135.             $this->lfAddParamSelectTemplate($objFormParam);
  136.             $objFormParam->setParam($_POST);
  137.             $this->arrErr = $objFormParam->checkError();
  138.             if (SC_Utils_Ex::isBlank($this->arrErr)) $this->tpl_mainpage = 'mail/input_confirm.tpl';
  139.             break;
  140.         case 'regist_complete':
  141.             $this->tpl_mainpage = 'mail/input.tpl';
  142.             $this->lfAddParamSelectTemplate($objFormParam);
  143.             $objFormParam->setParam($_POST);
  144.             $this->arrErr = $objFormParam->checkError();
  145.             if (SC_Utils_Ex::isBlank($this->arrErr)){
  146.                 $this->tpl_mainpage = 'mail/index.tpl';
  147.                 SC_Helper_Mail_Ex::sfSendMailmagazine($this->lfRegisterData($objFormParam));  // DB登録・送信
  148.                 SC_Response_Ex::sendRedirect("./history.php");
  149.             }
  150.             break;
  151.         // query:配信履歴から「確認」
  152.         case 'query':
  153.             if (SC_Utils_Ex::sfIsInt($_GET["send_id"])) {
  154.                 $this->arrSearchData = $this->lfGetMailQuery();
  155.             }
  156.             $this->setTemplate('mail/query.tpl');
  157.             break;
  158.         // query:配信履歴から「再送信」
  159.         case 'retry':
  160.             if (SC_Utils_Ex::sfIsInt($_GET["send_id"])) {
  161.                 SC_Helper_Mail_Ex::sfSendMailmagazine($_GET['send_id']);  // DB登録・送信
  162.                 SC_Response_Ex::sendRedirect("./history.php");
  163.             } else {
  164.                 $this->tpl_onload = "window.alert('メール送信IDが正しくありません');";
  165.             }
  166.             break;
  167.         default:
  168.             break;
  169.         }
  170.         $this->arrForm = $objFormParam->getFormParamList();
  171.     }
  172.  
  173.     /**
  174.      * デストラクタ.
  175.      *
  176.      * @return void 
  177.      */
  178.     function destroy() {
  179.         parent::destroy();
  180.     }
  181.  
  182.     /**
  183.      * パラメーター情報の初期化(初期顧客検索時)
  184.      *
  185.      * @param array $objFormParam フォームパラメータークラス
  186.      * @return void 
  187.      */
  188.     function lfInitParamSearchCustomer(&$objFormParam) {
  189.         SC_Helper_Customer_Ex::sfSetSearchParam($objFormParam);
  190.         $objFormParam->addParam('配信形式', 'search_htmlmail', INT_LEN, 'n', array("NUM_CHECK","MAX_LENGTH_CHECK"));
  191.         $objFormParam->addParam('配信メールアドレス種別', 'search_mail_type', INT_LEN, 'n', array("NUM_CHECK","MAX_LENGTH_CHECK"));
  192.     }
  193.  
  194.     /**
  195.      * パラメーター情報の追加(テンプレート選択)
  196.      *
  197.      * @param array $objFormParam フォームパラメータークラス
  198.      * @return void 
  199.      */
  200.     function lfAddParamSelectTemplate(&$objFormParam) {
  201.         $objFormParam->addParam("メール形式", 'mail_method', INT_LEN, 'n', array("EXIST_CHECK","ALNUM_CHECK"));
  202.         $objFormParam->addParam('Subject', 'subject', STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
  203.         $objFormParam->addParam("本文", 'body', LLTEXT_LEN, 'KVCa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
  204.         $objFormParam->addParam("テンプレートID", "template_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
  205.     }
  206.  
  207.     /**
  208.      * メルマガテンプレート一覧情報の取得
  209.      *
  210.      * @param array $arrTemplate SC_Helper_Mail_Ex::sfGetMailmagaTemplate()の戻り値
  211.      * @return array key:template_id value:サブジェクト【配信形式】
  212.      */
  213.     function lfGetMailTemplateList($arrTemplate){
  214.         if ( is_array($arrTemplate) ){
  215.             foreach( $arrTemplate as $line ){
  216.                 $return[$line['template_id']] = "【" . $this->arrHtmlmail[$line['mail_method']] . "】" . $line['subject'];
  217.             }
  218.         }
  219.         return $return;
  220.     }
  221.  
  222.     /**
  223.      * テンプレートIDから情報の取得して$objFormParamにset_paramする
  224.      *
  225.      * @param array $objFormParam フォームパラメータークラス
  226.      * @param array $template_id テンプレートID
  227.      * @return void 
  228.      */
  229.     function lfGetTemplateData(&$objFormParam, $template_id){
  230.         $objQuery =& SC_Query_Ex::getSingletonInstance();
  231.         $objQuery->setOrder("template_id DESC");
  232.         $where = 'template_id = ?';
  233.         $arrResults = $objQuery->getRow('*', 'dtb_mailmaga_template', $where, array($template_id));
  234.         $objFormParam->setParam($arrResults);
  235.     }
  236.  
  237.     /**
  238.      * 配信内容と配信リストを書き込む
  239.      *
  240.      * @return integer 登録した行の dtb_send_history.send_id の値
  241.      */
  242.     function lfRegisterData(&$objFormParam){
  243.         $objQuery =& SC_Query_Ex::getSingletonInstance();
  244.  
  245.         list($linemax, $arrSendCustomer, $objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray(), 'All');
  246.         $send_customer_cnt = count($arrSendCustomer);
  247.  
  248.         $send_id = $objQuery->nextVal('dtb_send_history_send_id');
  249.         $dtb_send_history = array();
  250.         $dtb_send_history["mail_method"] = $objFormParam->getValue('mail_method');
  251.         $dtb_send_history['subject'] = $objFormParam->getValue('subject');
  252.         $dtb_send_history['body'] = $objFormParam->getValue('body');
  253.         $dtb_send_history["start_date"] = 'CURRENT_TIMESTAMP';
  254.         $dtb_send_history["creator_id"] = $_SESSION['member_id'];
  255.         $dtb_send_history["send_count"] = $send_customer_cnt;
  256.         $dtb_send_history["search_data"] = serialize($objFormParam->getSearchArray());
  257.         $dtb_send_history["update_date"] = 'CURRENT_TIMESTAMP';
  258.         $dtb_send_history["create_date"] = 'CURRENT_TIMESTAMP';
  259.         $dtb_send_history['send_id'] = $send_id;
  260.         $objQuery->insert("dtb_send_history", $dtb_send_history );
  261.         // 「配信メールアドレス種別」に携帯メールアドレスが指定されている場合は、携帯メールアドレスに配信
  262.         $emailtype="email";
  263.         $searchmailtype = $objFormParam->getValue('search_mail_type');
  264.         if($searchmailtype==2||$searchmailtype==4)$emailtype="email_mobile";
  265.         if ( is_array( $arrSendCustomer ) ){
  266.             foreach( $arrSendCustomer as $line ){
  267.                 $dtb_send_customer = array();
  268.                 $dtb_send_customer["customer_id"] = $line["customer_id"];
  269.                 $dtb_send_customer["send_id"] = $send_id;
  270.                 $dtb_send_customer['email'] = $line[$emailtype];
  271.                 $dtb_send_customer['name'] = $line["name01"] . " " . $line["name02"];
  272.                 $objQuery->insert("dtb_send_customer", $dtb_send_customer );
  273.             }
  274.         }
  275.         return $send_id;
  276.     }
  277.  
  278.     /**
  279.      * 配信履歴から条件を取得する
  280.      *
  281.      * @param integer $send_id 配信履歴番号 
  282.      * @return array 
  283.      */
  284.     function lfGetMailQuery($send_id){
  285.  
  286.         $objQuery =& SC_Query_Ex::getSingletonInstance();
  287.  
  288.         // 送信履歴より、送信条件確認画面
  289.         $sql = "SELECT search_data FROM dtb_send_history WHERE send_id = ?";
  290.         $searchData = $objQuery->getOne($sql, array($_GET["send_id"]));
  291.         return unserialize($searchData);
  292.     }
  293. }
  294. ?>

Documentation generated on Fri, 24 Feb 2012 14:01:21 +0900 by Seasoft