| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2007 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_PATH . "pages/LC_Page.php"); |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * メルマガ管理 のページクラス. |
|---|
| 29 | * |
|---|
| 30 | * @package Page |
|---|
| 31 | * @author LOCKON CO.,LTD. |
|---|
| 32 | * @version $Id$ |
|---|
| 33 | */ |
|---|
| 34 | class LC_Page_Admin_Mail extends LC_Page { |
|---|
| 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 = TEMPLATE_DIR . 'admin/pager.tpl'; |
|---|
| 51 | $this->tpl_subtitle = '配信内容設定'; |
|---|
| 52 | |
|---|
| 53 | $masterData = new SC_DB_MasterData_Ex(); |
|---|
| 54 | $this->arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank")); |
|---|
| 55 | $this->arrJob = $masterData->getMasterData("mtb_job"); |
|---|
| 56 | $this->arrJob["不明"] = "不明"; |
|---|
| 57 | $this->arrSex = $masterData->getMasterData("mtb_sex"); |
|---|
| 58 | $this->arrMailType = $masterData->getMasterData("mtb_mail_type"); |
|---|
| 59 | $this->arrPageRows = $masterData->getMasterData("mtb_page_rows"); |
|---|
| 60 | // ページナビ用 |
|---|
| 61 | $this->tpl_pageno = isset($_POST['search_pageno']) ? $_POST['search_pageno'] : ""; |
|---|
| 62 | $this->arrMAILMAGATYPE = $masterData->getMasterData("mtb_mail_magazine_type"); |
|---|
| 63 | $this->arrHtmlmail[''] = "すべて"; |
|---|
| 64 | $this->arrHtmlmail[1] = $this->arrMAILMAGATYPE[1]; |
|---|
| 65 | $this->arrHtmlmail[2] = $this->arrMAILMAGATYPE[2]; |
|---|
| 66 | $this->arrMagazineTypeAll = $masterData->getMasterData("mtb_magazine_type"); |
|---|
| 67 | |
|---|
| 68 | //---- 検索用項目配列 |
|---|
| 69 | $this->arrHtmlmail = array( "" => "両方", 1 => "HTML", 2 => "TEXT" ); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | //---- 配列内容専用項目の配列 |
|---|
| 73 | $this->arrRegistColumn = array( |
|---|
| 74 | array( "column" => "template_id", "convert" => "n" ), |
|---|
| 75 | array( "column" => "mail_method", "convert" => "n" ), |
|---|
| 76 | array( "column" => "send_year", "convert" => "n" ), |
|---|
| 77 | array( "column" => "send_month", "convert" => "n" ), |
|---|
| 78 | array( "column" => "send_day", "convert" => "n" ), |
|---|
| 79 | array( "column" => "send_hour", "convert" => "n" ), |
|---|
| 80 | array( "column" => "send_minutes", "convert" => "n" ), |
|---|
| 81 | array( "column" => "subject", "convert" => "aKV" ), |
|---|
| 82 | array( "column" => "body", "convert" => "KV" ) |
|---|
| 83 | ); |
|---|
| 84 | |
|---|
| 85 | //---- メルマガ会員種別 |
|---|
| 86 | $this->arrCustomerType = array(1 => "会員", |
|---|
| 87 | 2 => "非会員", |
|---|
| 88 | //3 => "CSV登録" |
|---|
| 89 | ); |
|---|
| 90 | |
|---|
| 91 | //---- 検索項目 |
|---|
| 92 | $this->arrSearchColumn = array( |
|---|
| 93 | array( "column" => "name", "convert" => "aKV"), |
|---|
| 94 | array( "column" => "pref", "convert" => "n" ), |
|---|
| 95 | array( "column" => "kana", "convert" => "CKV"), |
|---|
| 96 | array( "column" => "sex", "convert" => "" ), |
|---|
| 97 | array( "column" => "tel", "convert" => "n" ), |
|---|
| 98 | array( "column" => "job", "convert" => "" ), |
|---|
| 99 | array( "column" => "email", "convert" => "a" ), |
|---|
| 100 | array( "column" => "email_mobile", "convert" => "a" ), |
|---|
| 101 | array( "column" => "htmlmail", "convert" => "n" ), |
|---|
| 102 | array( "column" => "customer", "convert" => "" ), |
|---|
| 103 | array( "column" => "buy_total_from", "convert" => "n" ), |
|---|
| 104 | array( "column" => "buy_total_to", "convert" => "n" ), |
|---|
| 105 | array( "column" => "buy_times_from", "convert" => "n" ), |
|---|
| 106 | array( "column" => "buy_times_to", "convert" => "n" ), |
|---|
| 107 | array( "column" => "birth_month", "convert" => "n" ), |
|---|
| 108 | array( "column" => "b_start_year", "convert" => "n" ), |
|---|
| 109 | array( "column" => "b_start_month", "convert" => "n" ), |
|---|
| 110 | array( "column" => "b_start_day", "convert" => "n" ), |
|---|
| 111 | array( "column" => "b_end_year", "convert" => "n" ), |
|---|
| 112 | array( "column" => "b_end_month", "convert" => "n" ), |
|---|
| 113 | array( "column" => "b_end_day", "convert" => "n" ), |
|---|
| 114 | array( "column" => "start_year", "convert" => "n" ), |
|---|
| 115 | array( "column" => "start_month", "convert" => "n" ), |
|---|
| 116 | array( "column" => "start_day", "convert" => "n" ), |
|---|
| 117 | array( "column" => "end_year", "convert" => "n" ), |
|---|
| 118 | array( "column" => "end_month", "convert" => "n" ), |
|---|
| 119 | array( "column" => "end_day", "convert" => "n" ), |
|---|
| 120 | array( "column" => "buy_start_year", "convert" => "n" ), |
|---|
| 121 | array( "column" => "buy_start_month", "convert" => "n" ), |
|---|
| 122 | array( "column" => "buy_start_day", "convert" => "n" ), |
|---|
| 123 | array( "column" => "buy_end_year", "convert" => "n" ), |
|---|
| 124 | array( "column" => "buy_end_month", "convert" => "n" ), |
|---|
| 125 | array( "column" => "buy_end_day", "convert" => "n" ), |
|---|
| 126 | array( "column" => "buy_product_code", "convert" => "aKV" ), |
|---|
| 127 | array( "column" => "buy_product_name", "convert" => "aKV" ), |
|---|
| 128 | array( "column" => "category_id", "convert" => "" ), |
|---|
| 129 | array( "column" => "buy_total_from", "convert" => "n" ), |
|---|
| 130 | array( "column" => "buy_total_to", "convert" => "n" ), |
|---|
| 131 | array( "column" => "campaign_id", "convert" => "" ), |
|---|
| 132 | array( "column" => "mail_type", "convert" => "" ) |
|---|
| 133 | ); |
|---|
| 134 | |
|---|
| 135 | if (!isset($_POST['htmlmail'])) $_POST['htmlmail'] = ""; |
|---|
| 136 | if (!isset($_POST['mail_type'])) $_POST['mail_type'] = ""; |
|---|
| 137 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
|---|
| 138 | if (!isset($_POST['buy_product_code'])) $_POST['buy_product_code'] = ""; |
|---|
| 139 | if (!isset($_GET['mode'])) $_GET['mode'] = ""; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | /** |
|---|
| 143 | * Page のプロセス. |
|---|
| 144 | * |
|---|
| 145 | * @return void |
|---|
| 146 | */ |
|---|
| 147 | function process() { |
|---|
| 148 | |
|---|
| 149 | //---- ページ初期設定 |
|---|
| 150 | $conn = new SC_DBConn(); |
|---|
| 151 | $objView = new SC_AdminView(); |
|---|
| 152 | $objDate = new SC_Date(); |
|---|
| 153 | $objQuery = new SC_Query(); |
|---|
| 154 | $objDb = new SC_Helper_DB_Ex(); |
|---|
| 155 | $this->objDate = $objDate; |
|---|
| 156 | $this->arrTemplate = $this->getTemplateList($conn); |
|---|
| 157 | |
|---|
| 158 | $objSess = new SC_Session(); |
|---|
| 159 | |
|---|
| 160 | // 認証可否の判定 |
|---|
| 161 | SC_Utils_Ex::sfIsSuccess($objSess); |
|---|
| 162 | |
|---|
| 163 | /* |
|---|
| 164 | query:配信履歴「確認」 |
|---|
| 165 | */ |
|---|
| 166 | if ($_GET["mode"] == "query" && SC_Utils_Ex::sfCheckNumLength($_GET["send_id"])) { |
|---|
| 167 | // 送信履歴より、送信条件確認画面 |
|---|
| 168 | $sql = "SELECT search_data FROM dtb_send_history WHERE send_id = ?"; |
|---|
| 169 | $result = $conn->getOne($sql, array($_GET["send_id"])); |
|---|
| 170 | $tpl_path = "mail/query.tpl"; |
|---|
| 171 | |
|---|
| 172 | $list_data = unserialize($result); |
|---|
| 173 | |
|---|
| 174 | // 都道府県を変換 |
|---|
| 175 | $list_data['pref_disp'] = $this->arrPref[$list_data['pref']]; |
|---|
| 176 | |
|---|
| 177 | // 配信形式 |
|---|
| 178 | $list_data['htmlmail_disp'] = $this->arrHtmlmail[$list_data['htmlmail']]; |
|---|
| 179 | |
|---|
| 180 | // 性別の変換 |
|---|
| 181 | if (count($list_data['sex']) > 0) { |
|---|
| 182 | foreach($list_data['sex'] as $key => $val){ |
|---|
| 183 | $list_data['sex'][$key] = $this->arrSex[$val]; |
|---|
| 184 | $sex_disp .= $list_data['sex'][$key] . " "; |
|---|
| 185 | } |
|---|
| 186 | $list_data['sex_disp'] = $sex_disp; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | // 職業の変換 |
|---|
| 190 | if (count($list_data['job']) > 0) { |
|---|
| 191 | foreach($list_data['job'] as $key => $val){ |
|---|
| 192 | $list_data['job'][$key] = $this->arrJob[$val]; |
|---|
| 193 | $job_disp .= $list_data['job'][$key] . " "; |
|---|
| 194 | } |
|---|
| 195 | $list_data['job_disp'] = $job_disp; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | // カテゴリ変換 |
|---|
| 199 | $arrCatList = $objDb->sfGetCategoryList(); |
|---|
| 200 | $list_data['category_name'] = $arrCatList[$list_data['category_id']]; |
|---|
| 201 | |
|---|
| 202 | $this->list_data = $list_data; |
|---|
| 203 | $this->arrCampaignList = $this->lfGetCampaignList($objQuery); |
|---|
| 204 | |
|---|
| 205 | $objView->assignobj($this); |
|---|
| 206 | $objView->display($tpl_path); |
|---|
| 207 | exit; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | if($_POST['mode'] == 'delete') { |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | switch($_POST['mode']) { |
|---|
| 214 | /* |
|---|
| 215 | search:「検索」ボタン |
|---|
| 216 | back:検索結果画面「戻る」ボタン |
|---|
| 217 | */ |
|---|
| 218 | case 'delete': |
|---|
| 219 | case 'search': |
|---|
| 220 | case 'back': |
|---|
| 221 | //-- 入力値コンバート |
|---|
| 222 | $this->list_data = $this->lfConvertParam($_POST, $this->arrSearchColumn); |
|---|
| 223 | |
|---|
| 224 | //-- 入力エラーのチェック |
|---|
| 225 | $this->arrErr = $this->lfErrorCheck($this->list_data); |
|---|
| 226 | |
|---|
| 227 | //-- 検索開始 |
|---|
| 228 | if (!is_array($this->arrErr)) { |
|---|
| 229 | $this->list_data['name'] = isset($this->list_data['name']) |
|---|
| 230 | ? SC_Utils_Ex::sfManualEscape($this->list_data['name']) : ""; |
|---|
| 231 | // hidden要素作成 |
|---|
| 232 | $this->arrHidden = $this->lfGetHidden($this->list_data); |
|---|
| 233 | |
|---|
| 234 | //-- 検索データ取得 |
|---|
| 235 | $objSelect = new SC_CustomerList($this->list_data, "magazine"); |
|---|
| 236 | // 生成されたWHERE文を取得する |
|---|
| 237 | list($where, $arrval) = $objSelect->getWhere(); |
|---|
| 238 | |
|---|
| 239 | // 「WHERE」部分を削除する。 |
|---|
| 240 | $where = ereg_replace("^WHERE", "", $where); |
|---|
| 241 | |
|---|
| 242 | // 検索結果の取得 |
|---|
| 243 | $from = "dtb_customer"; |
|---|
| 244 | |
|---|
| 245 | // 行数の取得 |
|---|
| 246 | $linemax = $objQuery->count($from, $where, $arrval); |
|---|
| 247 | $this->tpl_linemax = $linemax; // 何件が該当しました。表示用 |
|---|
| 248 | |
|---|
| 249 | // ページ送りの取得 |
|---|
| 250 | $objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, SEARCH_PMAX, "fnResultPageNavi", NAVI_PMAX); |
|---|
| 251 | $this->arrPagenavi = $objNavi->arrPagenavi; |
|---|
| 252 | $startno = $objNavi->start_row; |
|---|
| 253 | |
|---|
| 254 | // 取得範囲の指定(開始行番号、行数のセット) |
|---|
| 255 | $objQuery->setlimitoffset(SEARCH_PMAX, $startno); |
|---|
| 256 | // 表示順序 |
|---|
| 257 | $objQuery->setorder("customer_id DESC"); |
|---|
| 258 | |
|---|
| 259 | // 検索結果の取得 |
|---|
| 260 | $col = $objSelect->getMailMagazineColumn($this->lfGetIsMobile($_POST['mail_type'])); |
|---|
| 261 | $this->arrResults = $objQuery->select($col, $from, $where, $arrval); |
|---|
| 262 | //現在時刻の取得 |
|---|
| 263 | $this->arrNowDate = $this->lfGetNowDate(); |
|---|
| 264 | } |
|---|
| 265 | break; |
|---|
| 266 | /* |
|---|
| 267 | input:検索結果画面「htmlmail内容設定」ボタン |
|---|
| 268 | */ |
|---|
| 269 | case 'input': |
|---|
| 270 | //-- 入力値コンバート |
|---|
| 271 | $this->list_data = $this->lfConvertParam($_POST, $this->arrSearchColumn); |
|---|
| 272 | //-- 入力エラーのチェック |
|---|
| 273 | $this->arrErr = $this->lfErrorCheck($this->list_data); |
|---|
| 274 | //-- エラーなし |
|---|
| 275 | if (!is_array($this->arrErr)) { |
|---|
| 276 | //-- 現在時刻の取得 |
|---|
| 277 | $this->arrNowDate = $this->lfGetNowDate(); |
|---|
| 278 | $this->arrHidden = $this->lfGetHidden($this->list_data); // hidden要素作成 |
|---|
| 279 | $this->tpl_mainpage = 'mail/input.tpl'; |
|---|
| 280 | } |
|---|
| 281 | break; |
|---|
| 282 | /* |
|---|
| 283 | template:テンプレート選択 |
|---|
| 284 | */ |
|---|
| 285 | case 'template': |
|---|
| 286 | //-- 入力値コンバート |
|---|
| 287 | $this->list_data = $this->lfConvertParam($_POST, $this->arrSearchColumn); |
|---|
| 288 | |
|---|
| 289 | //-- 時刻設定の取得 |
|---|
| 290 | $this->arrNowDate['year'] = isset($_POST['send_year']) ? $_POST['send_year'] : ""; |
|---|
| 291 | $this->arrNowDate['month'] = isset($_POST['send_month']) ? $_POST['send_month'] : ""; |
|---|
| 292 | $this->arrNowDate['day'] = isset($_POST['send_day']) ? $_POST['send_day'] : ""; |
|---|
| 293 | $this->arrNowDate['hour'] = isset($_POST['send_hour']) ? $_POST['send_hour'] : ""; |
|---|
| 294 | $this->arrNowDate['minutes'] = isset($_POST['send_minutes']) ? $_POST['send_minutes'] : ""; |
|---|
| 295 | |
|---|
| 296 | //-- 入力エラーのチェック |
|---|
| 297 | $this->arrErr = $this->lfErrorCheck($this->list_data); |
|---|
| 298 | |
|---|
| 299 | //-- 検索開始 |
|---|
| 300 | if ( ! is_array($this->arrErr)) { |
|---|
| 301 | $this->list_data['name'] = isset($this->list_data['name']) ? SC_Utils_Ex::sfManualEscape($this->list_data['name']) : ""; |
|---|
| 302 | $this->arrHidden = $this->lfGetHidden($this->list_data); // hidden要素作成 |
|---|
| 303 | |
|---|
| 304 | $this->tpl_mainpage = 'mail/input.tpl'; |
|---|
| 305 | $template_data = $this->getTemplateData($conn, $_POST['template_id']); |
|---|
| 306 | if ( $template_data ){ |
|---|
| 307 | foreach( $template_data as $key=>$val ){ |
|---|
| 308 | $this->list_data[$key] = $val; |
|---|
| 309 | } |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | //-- HTMLテンプレートを使用する場合は、HTMLソースを生成してBODYへ挿入 |
|---|
| 313 | if ( $this->list_data["mail_method"] == 3) { |
|---|
| 314 | $objTemplate = new LC_HTMLtemplate; |
|---|
| 315 | $objTemplate->list_data = lfGetHtmlTemplateData($_POST['template_id']); |
|---|
| 316 | $objSiteInfo = new SC_SiteInfo(); |
|---|
| 317 | $objTemplate->arrInfo = $objSiteInfo->data; |
|---|
| 318 | //メール担当写真の表示 |
|---|
| 319 | $objUpFile = new SC_UploadFile(IMAGE_TEMP_URL, IMAGE_SAVE_URL); |
|---|
| 320 | $objUpFile->addFile("メール担当写真", 'charge_image', array('jpg'), IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); |
|---|
| 321 | $objUpFile->setDBFileList($objTemplate->list_data); |
|---|
| 322 | $objTemplate->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL); |
|---|
| 323 | $objMakeTemplate = new SC_AdminView(); |
|---|
| 324 | $objMakeTemplate->assignobj($objTemplate); |
|---|
| 325 | $this->list_data["body"] = $objMakeTemplate->fetch("mail/html_template.tpl"); |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | break; |
|---|
| 329 | /* |
|---|
| 330 | regist_confirm:「入力内容を確認」 |
|---|
| 331 | regist_back:「テンプレート設定画面へ戻る」 |
|---|
| 332 | regist_complete:「登録」 |
|---|
| 333 | */ |
|---|
| 334 | case 'regist_confirm': |
|---|
| 335 | case 'regist_back': |
|---|
| 336 | case 'regist_complete': |
|---|
| 337 | //-- 入力値コンバート |
|---|
| 338 | $this->arrCheckColumn = array_merge( $this->arrSearchColumn, $this->arrRegistColumn ); |
|---|
| 339 | $this->list_data = $this->lfConvertParam($_POST, $this->arrCheckColumn); |
|---|
| 340 | |
|---|
| 341 | //現在時刻の取得 |
|---|
| 342 | $this->arrNowDate = $this->lfGetNowDate(); |
|---|
| 343 | |
|---|
| 344 | //-- 入力エラーのチェック |
|---|
| 345 | $this->arrErr = $this->lfErrorCheck($this->list_data, 1); |
|---|
| 346 | $this->tpl_mainpage = 'mail/input.tpl'; |
|---|
| 347 | $this->arrHidden = $this->lfGetHidden($this->list_data); // hidden要素作成 |
|---|
| 348 | |
|---|
| 349 | //-- 検索開始 |
|---|
| 350 | if ( ! is_array($this->arrErr)) { |
|---|
| 351 | $this->list_data['name'] = |
|---|
| 352 | isset($this->list_data['name']) |
|---|
| 353 | ? SC_Utils_Ex::sfManualEscape($this->list_data['name']) : ""; |
|---|
| 354 | |
|---|
| 355 | if ( $_POST['mode'] == 'regist_confirm'){ |
|---|
| 356 | $this->tpl_mainpage = 'mail/input_confirm.tpl'; |
|---|
| 357 | } else if( $_POST['mode'] == 'regist_complete' ){ |
|---|
| 358 | $this->lfRegistData($conn, $this->list_data); |
|---|
| 359 | if(MELMAGA_SEND == true) { |
|---|
| 360 | if(MELMAGA_BATCH_MODE) { |
|---|
| 361 | $this->sendRedirect($this->getLocation(URL_DIR . "admin/mail/history.php")); |
|---|
| 362 | } else { |
|---|
| 363 | $this->sendRedirect($this->getLocation(URL_DIR . "admin/mail/sendmail.php", array("mode" => "now"))); |
|---|
| 364 | } |
|---|
| 365 | exit; |
|---|
| 366 | } else { |
|---|
| 367 | SC_Utils_Ex::sfErrorHeader(">> 本サイトではメルマガ配信は行えません。"); |
|---|
| 368 | } |
|---|
| 369 | } |
|---|
| 370 | } |
|---|
| 371 | break; |
|---|
| 372 | default: |
|---|
| 373 | $this->list_data['mail_type'] = 1; |
|---|
| 374 | break; |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | // 配信時間の年を、「現在年~現在年+1」の範囲に設定 |
|---|
| 378 | for ($year=date("Y"); $year<=date("Y") + 1;$year++){ |
|---|
| 379 | $arrYear[$year] = $year; |
|---|
| 380 | } |
|---|
| 381 | $this->arrYear = $arrYear; |
|---|
| 382 | |
|---|
| 383 | $this->arrCustomerOrderId = $this->lfGetCustomerOrderId($_POST['buy_product_code']); |
|---|
| 384 | |
|---|
| 385 | $this->arrCatList = $objDb->sfGetCategoryList(); |
|---|
| 386 | |
|---|
| 387 | $this->arrCampaignList = $this->lfGetCampaignList($objQuery); |
|---|
| 388 | |
|---|
| 389 | //---- ページ表示 |
|---|
| 390 | $objView->assignobj($this); |
|---|
| 391 | $objView->display(MAIN_FRAME); |
|---|
| 392 | |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | /** |
|---|
| 396 | * デストラクタ. |
|---|
| 397 | * |
|---|
| 398 | * @return void |
|---|
| 399 | */ |
|---|
| 400 | function destroy() { |
|---|
| 401 | parent::destroy(); |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | // 商品コードで検索された場合にヒットした注文番号を取得する。 |
|---|
| 405 | function lfGetCustomerOrderId($keyword) { |
|---|
| 406 | $arrCustomerOrderId = null; |
|---|
| 407 | if($keyword != "") { |
|---|
| 408 | $col = "dtb_order.customer_id, dtb_order.order_id"; |
|---|
| 409 | $from = "dtb_order LEFT JOIN dtb_order_detail USING(order_id)"; |
|---|
| 410 | $where = "product_code LIKE ? AND del_flg = 0"; |
|---|
| 411 | $val = SC_Utils_Ex::sfManualEscape($keyword); |
|---|
| 412 | $arrVal[] = "%$val%"; |
|---|
| 413 | $objQuery = new SC_Query(); |
|---|
| 414 | $objQuery->setgroupby("customer_id, order_id"); |
|---|
| 415 | $arrRet = $objQuery->select($col, $from, $where, $arrVal); |
|---|
| 416 | $arrCustomerOrderId = SC_Utils_Ex::sfArrKeyValues($arrRet, "customer_id", "order_id"); |
|---|
| 417 | } |
|---|
| 418 | return $arrCustomerOrderId; |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | function lfMakeCsvData(&$conn, $send_id){ |
|---|
| 422 | $arrTitle = array( 'name01','email'); |
|---|
| 423 | |
|---|
| 424 | $sql = "SELECT name01,email FROM dtb_send_customer WHERE send_id = ? ORDER BY email"; |
|---|
| 425 | $result = $conn->getAll($sql, array($send_id) ); |
|---|
| 426 | |
|---|
| 427 | if ( $result ){ |
|---|
| 428 | $return = SC_Utils_Ex::getCSVData( $result, $arrTitle); |
|---|
| 429 | } |
|---|
| 430 | return $return; |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | //現在時刻の取得(配信時間デフォルト値) |
|---|
| 434 | function lfGetNowDate(){ |
|---|
| 435 | $nowdate = date("Y/n/j/G/i"); |
|---|
| 436 | list($year, $month, $day, $hour, $minute) = split("[/]", $nowdate); |
|---|
| 437 | $arrNowDate = array( 'year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minutes' => $minute); |
|---|
| 438 | foreach ($arrNowDate as $key => $val){ |
|---|
| 439 | switch ($key){ |
|---|
| 440 | case 'minutes': |
|---|
| 441 | $val = ereg_replace('^[0]','', $val); |
|---|
| 442 | if ($val < 30){ |
|---|
| 443 | $list_date[$key] = '30'; |
|---|
| 444 | }else{ |
|---|
| 445 | $list_date[$key] = '00'; |
|---|
| 446 | } |
|---|
| 447 | break; |
|---|
| 448 | case 'year': |
|---|
| 449 | case 'month': |
|---|
| 450 | case 'day': |
|---|
| 451 | $list_date[$key] = $val; |
|---|
| 452 | break; |
|---|
| 453 | } |
|---|
| 454 | } |
|---|
| 455 | if ($arrNowDate['minutes'] < 30){ |
|---|
| 456 | $list_date['hour'] = $hour; |
|---|
| 457 | }else{ |
|---|
| 458 | $list_date['hour'] = $hour + 1; |
|---|
| 459 | } |
|---|
| 460 | return $list_date; |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | // 配信内容と配信リストを書き込む |
|---|
| 464 | function lfRegistData(&$conn, $arrData){ |
|---|
| 465 | |
|---|
| 466 | $objQuery = new SC_Query(); |
|---|
| 467 | $objSelect = new SC_CustomerList($this->lfConvertParam($arrData, $this->arrSearchColumn), "magazine" ); |
|---|
| 468 | |
|---|
| 469 | $search_data = $conn->getAll($objSelect->getListMailMagazine($this->lfGetIsMobile($_POST['mail_type'])), $objSelect->arrVal); |
|---|
| 470 | $dataCnt = count($search_data); |
|---|
| 471 | |
|---|
| 472 | $dtb_send_history = array(); |
|---|
| 473 | if(DB_TYPE=='pgsql'){ |
|---|
| 474 | $dtb_send_history["send_id"] = $objQuery->nextval('dtb_send_history', 'send_id'); |
|---|
| 475 | } |
|---|
| 476 | $dtb_send_history["mail_method"] = $arrData['mail_method']; |
|---|
| 477 | $dtb_send_history["subject"] = $arrData['subject']; |
|---|
| 478 | $dtb_send_history["body"] = $arrData['body']; |
|---|
| 479 | if(MELMAGA_BATCH_MODE) { |
|---|
| 480 | $dtb_send_history["start_date"] = $arrData['send_year'] ."/".$arrData['send_month']."/".$arrData['send_day']." ".$arrData['send_hour'].":".$arrData['send_minutes']; |
|---|
| 481 | } else { |
|---|
| 482 | $dtb_send_history["start_date"] = "now()"; |
|---|
| 483 | } |
|---|
| 484 | $dtb_send_history["creator_id"] = $_SESSION['member_id']; |
|---|
| 485 | $dtb_send_history["send_count"] = $dataCnt; |
|---|
| 486 | $arrData['body'] = ""; |
|---|
| 487 | $dtb_send_history["search_data"] = serialize($arrData); |
|---|
| 488 | $dtb_send_history["update_date"] = "now()"; |
|---|
| 489 | $dtb_send_history["create_date"] = "now()"; |
|---|
| 490 | $objQuery->insert("dtb_send_history", $dtb_send_history ); |
|---|
| 491 | if(DB_TYPE == "mysql"){ |
|---|
| 492 | $dtb_send_history["send_id"] = $objQuery->nextval('dtb_send_history','send_id'); |
|---|
| 493 | } |
|---|
| 494 | if ( is_array( $search_data ) ){ |
|---|
| 495 | foreach( $search_data as $line ){ |
|---|
| 496 | $dtb_send_customer = array(); |
|---|
| 497 | $dtb_send_customer["customer_id"] = $line["customer_id"]; |
|---|
| 498 | $dtb_send_customer["send_id"] = $dtb_send_history["send_id"]; |
|---|
| 499 | $dtb_send_customer["email"] = $line["email"]; |
|---|
| 500 | |
|---|
| 501 | $dtb_send_customer["name"] = $line["name01"] . " " . $line["name02"]; |
|---|
| 502 | |
|---|
| 503 | $conn->autoExecute("dtb_send_customer", $dtb_send_customer ); |
|---|
| 504 | } |
|---|
| 505 | } |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | // キャンペーン一覧 |
|---|
| 509 | function lfGetCampaignList(&$objQuery) { |
|---|
| 510 | $arrCampaign = null; |
|---|
| 511 | $sql = "SELECT campaign_id, campaign_name FROM dtb_campaign ORDER BY update_date DESC"; |
|---|
| 512 | $arrResult = $objQuery->getall($sql); |
|---|
| 513 | |
|---|
| 514 | foreach($arrResult as $arrVal) { |
|---|
| 515 | $arrCampaign[$arrVal['campaign_id']] = $arrVal['campaign_name']; |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | return $arrCampaign; |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | function lfGetIsMobile($mail_type) { |
|---|
| 522 | // 検索結果の取得 |
|---|
| 523 | $is_mobile = false; |
|---|
| 524 | switch($mail_type) { |
|---|
| 525 | case 1: |
|---|
| 526 | $is_mobile = false; |
|---|
| 527 | break; |
|---|
| 528 | case 2: |
|---|
| 529 | $is_mobile = true; |
|---|
| 530 | break; |
|---|
| 531 | default: |
|---|
| 532 | $is_mobile = false; |
|---|
| 533 | break; |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | return $is_mobile; |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | //---- HTMLテンプレートを使用する場合、データを取得する。 |
|---|
| 541 | function lfGetHtmlTemplateData($id) { |
|---|
| 542 | |
|---|
| 543 | global $conn; |
|---|
| 544 | $sql = "SELECT * FROM dtb_mailmaga_template WHERE template_id = ?"; |
|---|
| 545 | $result = $conn->getAll($sql, array($id)); |
|---|
| 546 | $list_data = $result[0]; |
|---|
| 547 | |
|---|
| 548 | // メイン商品の情報取得 |
|---|
| 549 | $sql = "SELECT name, main_image, point_rate, deliv_fee, price01_min, price01_max, price02_min, price02_max FROM vw_products_allclass AS allcls WHERE product_id = ?"; |
|---|
| 550 | $main = $conn->getAll($sql, array($list_data["main_product_id"])); |
|---|
| 551 | $list_data["main"] = $main[0]; |
|---|
| 552 | |
|---|
| 553 | // サブ商品の情報取得 |
|---|
| 554 | $sql = "SELECT product_id, name, main_list_image, price01_min, price01_max, price02_min, price02_max FROM vw_products_allclass AS allcls WHERE product_id = ?"; |
|---|
| 555 | $k = 0; |
|---|
| 556 | $l = 0; |
|---|
| 557 | for ($i = 1; $i <= 12; $i ++) { |
|---|
| 558 | if ($l == 4) { |
|---|
| 559 | $l = 0; |
|---|
| 560 | $k ++; |
|---|
| 561 | } |
|---|
| 562 | $result = ""; |
|---|
| 563 | $j = sprintf("%02d", $i); |
|---|
| 564 | if ($i > 0 && $i < 5 ) $k = 0; |
|---|
| 565 | if ($i > 4 && $i < 9 ) $k = 1; |
|---|
| 566 | if ($i > 8 && $i < 13 ) $k = 2; |
|---|
| 567 | |
|---|
| 568 | if (is_numeric($list_data["sub_product_id" .$j])) { |
|---|
| 569 | $result = $conn->getAll($sql, array($list_data["sub_product_id" .$j])); |
|---|
| 570 | $list_data["sub"][$k][$l] = $result[0]; |
|---|
| 571 | $list_data["sub"][$k]["data_exists"] = "OK"; //当該段にデータが1つ以上存在するフラグ |
|---|
| 572 | } |
|---|
| 573 | $l ++; |
|---|
| 574 | } |
|---|
| 575 | return $list_data; |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | //--- テンプレートの種類を返す |
|---|
| 579 | function lfGetTemplateMethod($conn, $templata_id){ |
|---|
| 580 | |
|---|
| 581 | if ( SC_Utils_Ex::sfCheckNumLength($template_id) ){ |
|---|
| 582 | $sql = "SELECT mail_method FROM dtb_mailmaga_template WEHRE template_id = ?"; |
|---|
| 583 | } |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | //--- hidden要素出力用配列の作成 |
|---|
| 587 | function lfGetHidden( $array ){ |
|---|
| 588 | if ( is_array($array) ){ |
|---|
| 589 | foreach( $array as $key => $val ){ |
|---|
| 590 | if ( is_array( $val )){ |
|---|
| 591 | for ( $i=0; $i<count($val); $i++){ |
|---|
| 592 | $return[ $key.'['.$i.']'] = $val[$i]; |
|---|
| 593 | } |
|---|
| 594 | } else { |
|---|
| 595 | $return[$key] = $val; |
|---|
| 596 | } |
|---|
| 597 | } |
|---|
| 598 | } |
|---|
| 599 | return $return; |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | //---- 取得文字列の変換 |
|---|
| 603 | function lfConvertParam($array, $arrSearchColumn) { |
|---|
| 604 | |
|---|
| 605 | // 文字変換 |
|---|
| 606 | foreach ($arrSearchColumn as $data) { |
|---|
| 607 | $arrConvList[ $data["column"] ] = $data["convert"]; |
|---|
| 608 | } |
|---|
| 609 | |
|---|
| 610 | $new_array = array(); |
|---|
| 611 | foreach ($arrConvList as $key => $val) { |
|---|
| 612 | if (isset($array[$key]) && strlen($array[$key]) > 0 ){ // データのあるものだけ返す |
|---|
| 613 | $new_array[$key] = $array[$key]; |
|---|
| 614 | if( strlen($val) > 0) { |
|---|
| 615 | $new_array[$key] = mb_convert_kana($new_array[$key] ,$val); |
|---|
| 616 | } |
|---|
| 617 | } |
|---|
| 618 | } |
|---|
| 619 | return $new_array; |
|---|
| 620 | |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | //---- 入力エラーチェック |
|---|
| 625 | function lfErrorCheck($array, $flag = '') { |
|---|
| 626 | |
|---|
| 627 | // flag は登録時用 |
|---|
| 628 | |
|---|
| 629 | $objErr = new SC_CheckError($array); |
|---|
| 630 | |
|---|
| 631 | $objErr->doFunc(array("顧客コード", "customer_id", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 632 | $objErr->doFunc(array("都道府県", "pref", 2), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 633 | $objErr->doFunc(array("顧客名", "name", STEXT_LEN), array("MAX_LENGTH_CHECK")); |
|---|
| 634 | $objErr->doFunc(array("顧客名(カナ)", "kana", STEXT_LEN), array("KANA_CHECK", "MAX_LENGTH_CHECK")); |
|---|
| 635 | |
|---|
| 636 | $objErr->doFunc(array('メールアドレス', "email", STEXT_LEN) ,array("EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK")); |
|---|
| 637 | $objErr->doFunc(array("電話番号", "tel", TEL_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 638 | |
|---|
| 639 | $objErr->doFunc(array("購入回数(開始)", "buy_times_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 640 | $objErr->doFunc(array("購入回数(終了)", "buy_times_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 641 | if (!isset($array['buy_total_from'])) $array['buy_total_from'] = ""; |
|---|
| 642 | if (!isset($array['buy_total_to'])) $array['buy_total_to'] = ""; |
|---|
| 643 | if (!isset($array['buy_times_from'])) $array['buy_times_from'] = ""; |
|---|
| 644 | if (!isset($array['buy_times_from'])) $array['buy_times_from'] = ""; |
|---|
| 645 | if ((is_numeric($array["buy_total_from"]) && is_numeric($array["buy_total_to"]) ) && ($array["buy_times_from"] > $array["buy_times_to"]) ) $objErr->arrErr["buy_times_from"] .= "※ 購入回数の指定範囲が不正です。"; |
|---|
| 646 | |
|---|
| 647 | $objErr->doFunc(array("誕生月", "birth_month", 2), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 648 | |
|---|
| 649 | $objErr->doFunc(array("誕生日(開始日)", "b_start_year", "b_start_month", "b_start_day",), array("CHECK_DATE")); |
|---|
| 650 | $objErr->doFunc(array("誕生日(終了日)", "b_end_year", "b_end_month", "b_end_day"), array("CHECK_DATE")); |
|---|
| 651 | $objErr->doFunc(array("誕生日(開始日)","誕生日(終了日)", "b_start_year", "b_start_month", "b_start_day", "b_end_year", "b_end_month", "b_end_day"), array("CHECK_SET_TERM")); |
|---|
| 652 | |
|---|
| 653 | $objErr->doFunc(array("登録・更新日(開始日)", "start_year", "start_month", "start_day",), array("CHECK_DATE")); |
|---|
| 654 | $objErr->doFunc(array("登録・更新日(終了日)", "end_year", "end_month", "end_day"), array("CHECK_DATE")); |
|---|
| 655 | $objErr->doFunc(array("登録・更新日(開始日)","登録・更新日(終了日)", "start_year", "start_month", "start_day", "end_year", "end_month", "end_day"), array("CHECK_SET_TERM")); |
|---|
| 656 | |
|---|
| 657 | $objErr->doFunc(array("最終購入日(開始日)", "buy_start_year", "buy_start_month", "buy_start_day",), array("CHECK_DATE")); |
|---|
| 658 | $objErr->doFunc(array("最終購入(終了日)", "buy_end_year", "buy_end_month", "buy_end_day"), array("CHECK_DATE")); |
|---|
| 659 | $objErr->doFunc(array("最終購入日(開始日)","登録・更新日(終了日)", "buy_start_year", "buy_start_month", "buy_start_day", "buy_end_year", "buy_end_month", "buy_end_day"), array("CHECK_SET_TERM")); |
|---|
| 660 | |
|---|
| 661 | $objErr->doFunc(array("購入商品コード", "buy_product_code", STEXT_LEN), array("MAX_LENGTH_CHECK")); |
|---|
| 662 | |
|---|
| 663 | $objErr->doFunc(array("購入商品名", "buy_product_name", STEXT_LEN), array("MAX_LENGTH_CHECK")); |
|---|
| 664 | |
|---|
| 665 | $objErr->doFunc(array("購入金額(開始)", "buy_total_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 666 | $objErr->doFunc(array("購入金額(終了)", "buy_total_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 667 | |
|---|
| 668 | $objErr->doFunc(array("キャンペーン", "campaign_id", INT_LEN), array("NUM_CHECK")); |
|---|
| 669 | |
|---|
| 670 | //購入金額(from) > 購入金額(to) の場合はエラーとする |
|---|
| 671 | if ( (is_numeric($array["buy_total_from"]) && is_numeric($array["buy_total_to"]) ) && |
|---|
| 672 | ($array["buy_total_from"] > $array["buy_total_to"]) ) { |
|---|
| 673 | $objErr->arrErr["buy_total_from"] .= "※ 購入金額の指定範囲が不正です。"; |
|---|
| 674 | } |
|---|
| 675 | |
|---|
| 676 | if ( $flag ){ |
|---|
| 677 | $objErr->doFunc(array("テンプレート", "template_id"), array("EXIST_CHECK", "NUM_CHECK")); |
|---|
| 678 | $objErr->doFunc(array("メール送信法法", "mail_method"), array("EXIST_CHECK", "NUM_CHECK")); |
|---|
| 679 | |
|---|
| 680 | if(MELMAGA_BATCH_MODE) { |
|---|
| 681 | $objErr->doFunc(array("配信日(年)","send_year"), array("EXIST_CHECK", "NUM_CHECK")); |
|---|
| 682 | $objErr->doFunc(array("配信日(月)","send_month"), array("EXIST_CHECK", "NUM_CHECK")); |
|---|
| 683 | $objErr->doFunc(array("配信日(日)","send_day"), array("EXIST_CHECK", "NUM_CHECK")); |
|---|
| 684 | $objErr->doFunc(array("配信日(時)","send_hour"), array("EXIST_CHECK", "NUM_CHECK")); |
|---|
| 685 | $objErr->doFunc(array("配信日(分)","send_minutes"), array("EXIST_CHECK", "NUM_CHECK")); |
|---|
| 686 | $objErr->doFunc(array("配信日", "send_year", "send_month", "send_day"), array("CHECK_DATE")); |
|---|
| 687 | $objErr->doFunc(array("配信日", "send_year", "send_month", "send_day","send_hour", "send_minutes"), array("ALL_EXIST_CHECK")); |
|---|
| 688 | } |
|---|
| 689 | $objErr->doFunc(array("Subject", "subject", STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK")); |
|---|
| 690 | $objErr->doFunc(array("本文", 'body', LLTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK")); // HTMLテンプレートを使用しない場合 |
|---|
| 691 | } |
|---|
| 692 | |
|---|
| 693 | return $objErr->arrErr; |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | /* テンプレートIDとsubjectの配列を返す */ |
|---|
| 697 | function getTemplateList($conn){ |
|---|
| 698 | $return = ""; |
|---|
| 699 | $sql = "SELECT template_id, subject, mail_method FROM dtb_mailmaga_template WHERE del_flg = 0 "; |
|---|
| 700 | if ($_POST["htmlmail"] == 2 || $_POST['mail_type'] == 2) { |
|---|
| 701 | $sql .= " AND mail_method = 2 "; //TEXT希望者へのTESTメールテンプレートリスト |
|---|
| 702 | } |
|---|
| 703 | $sql .= " ORDER BY template_id DESC"; |
|---|
| 704 | $result = $conn->getAll($sql); |
|---|
| 705 | |
|---|
| 706 | if ( is_array($result) ){ |
|---|
| 707 | foreach( $result as $line ){ |
|---|
| 708 | $return[$line['template_id']] = "【" . $this->arrMagazineTypeAll[$line['mail_method']] . "】" . $line['subject']; |
|---|
| 709 | } |
|---|
| 710 | } |
|---|
| 711 | |
|---|
| 712 | return $return; |
|---|
| 713 | } |
|---|
| 714 | |
|---|
| 715 | /* テンプレートIDからテンプレートデータを取得 */ |
|---|
| 716 | function getTemplateData($conn, $id){ |
|---|
| 717 | |
|---|
| 718 | if ( SC_Utils_Ex::sfCheckNumLength($id) ){ |
|---|
| 719 | $sql = "SELECT * FROM dtb_mailmaga_template WHERE template_id = ? ORDER BY template_id DESC"; |
|---|
| 720 | $result = $conn->getAll( $sql, array($id) ); |
|---|
| 721 | if ( is_array($result) ) { |
|---|
| 722 | $return = $result[0]; |
|---|
| 723 | } |
|---|
| 724 | } |
|---|
| 725 | return $return; |
|---|
| 726 | } |
|---|
| 727 | |
|---|
| 728 | } |
|---|
| 729 | class LC_HTMLtemplate { |
|---|
| 730 | var $list_data; |
|---|
| 731 | } |
|---|
| 732 | |
|---|
| 733 | ?> |
|---|