1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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 | * FIXME dtb_customer_mail なんて無いよ... |
---|
31 | * |
---|
32 | * @package Page |
---|
33 | * @author LOCKON CO.,LTD. |
---|
34 | * @version $Id$ |
---|
35 | */ |
---|
36 | class LC_Page_Magazine_Confirm extends LC_Page { |
---|
37 | |
---|
38 | // }}} |
---|
39 | // {{{ functions |
---|
40 | |
---|
41 | /** |
---|
42 | * Page を初期化する. |
---|
43 | * |
---|
44 | * @return void |
---|
45 | */ |
---|
46 | function init() { |
---|
47 | parent::init(); |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * Page のプロセス. |
---|
52 | * |
---|
53 | * @return void |
---|
54 | */ |
---|
55 | function process() { |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * モバイルページを初期化する. |
---|
60 | * |
---|
61 | * @return void |
---|
62 | */ |
---|
63 | function mobileInit() { |
---|
64 | $this->tpl_mainpage = 'magazine/confirm.tpl'; // メインテンプレート |
---|
65 | $this->tpl_title .= 'メルマガ確認'; |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * Page のプロセス(モバイル). |
---|
70 | * |
---|
71 | * @return void |
---|
72 | */ |
---|
73 | function mobileProcess() { |
---|
74 | $objConn = new SC_DbConn(); |
---|
75 | $this->arrForm = $_POST; |
---|
76 | |
---|
77 | // 登録 |
---|
78 | if (isset($_REQUEST['btnRegist'])) { |
---|
79 | $this->arrErr = $this->lfMailErrorCheck($this->arrForm, "regist", $objConn); |
---|
80 | |
---|
81 | // エラーがなければ |
---|
82 | if (count($this->arrErr) == 0) { |
---|
83 | // 確認 |
---|
84 | $this->arrForm['kind'] = 'メルマガ登録'; |
---|
85 | $this->arrForm['type'] = 'regist'; |
---|
86 | $this->arrForm['mail'] = $this->arrForm['regist']; |
---|
87 | } else { |
---|
88 | $this->tpl_mainpage = 'magazine/index.tpl'; |
---|
89 | $this->tpl_title = 'メルマガ登録・解除'; |
---|
90 | } |
---|
91 | // 解除 |
---|
92 | } elseif (isset($_REQUEST['btnCancel'])) { |
---|
93 | $this->arrErr = $this->lfMailErrorCheck($this->arrForm, "cancel", $objConn); |
---|
94 | |
---|
95 | // エラーがなければ |
---|
96 | if (count($this->arrErr) == 0) { |
---|
97 | // 確認 |
---|
98 | $this->arrForm['kind'] = 'メルマガ解除'; |
---|
99 | $this->arrForm['type'] = 'cancel'; |
---|
100 | $this->arrForm['mail'] = $this->arrForm['cancel']; |
---|
101 | } else { |
---|
102 | $this->tpl_mainpage = 'magazine/index.tpl'; |
---|
103 | $this->tpl_title = 'メルマガ登録・解除'; |
---|
104 | } |
---|
105 | // 完了 |
---|
106 | } elseif ($_REQUEST['mode'] == 'regist' or $_REQUEST['mode'] == 'cancel') { |
---|
107 | $objMailText = new SC_MobileView(); |
---|
108 | $helperMail = new SC_Helper_Mail_Ex(); |
---|
109 | $objQuery = new SC_Query(); |
---|
110 | // 登録 |
---|
111 | if ($_REQUEST['mode'] == 'regist') { |
---|
112 | $uniqId = $this->lfRegistData($_POST["email"], $objConn); |
---|
113 | |
---|
114 | $subject = $helperMail->fMakesubject($objQuery, $objMailText, $this, 'メルマガ登録のご確認'); |
---|
115 | // 解除 |
---|
116 | } elseif ($_REQUEST['mode'] == 'cancel') { |
---|
117 | $uniqId = $this->lfGetSecretKey($_POST["email"], $objConn); |
---|
118 | $subject = $helperMail->sfMakesubject('メルマガ解除のご確認'); |
---|
119 | } |
---|
120 | $objDb = new SC_Helper_DB_Ex(); |
---|
121 | $CONF = $objDb->sf_getBasisData(); |
---|
122 | $this->CONF = $CONF; |
---|
123 | $this->tpl_url = SC_Utils_Ex::gfAddSessionId(MOBILE_SSL_URL . "magazine/" . $_REQUEST['mode'] . ".php?id=" . $uniqId); |
---|
124 | |
---|
125 | |
---|
126 | $objMailText->assignobj($this); |
---|
127 | $toCustomerMail = $objMailText->fetch("mail_templates/mailmagazine_" . $_REQUEST['mode'] . ".tpl"); |
---|
128 | $objMail = new SC_SendMail(); |
---|
129 | $objMail->setItem( |
---|
130 | '' // 宛先 |
---|
131 | , $subject // サブジェクト |
---|
132 | , $toCustomerMail // 本文 |
---|
133 | , $CONF["email03"] // 配送元アドレス |
---|
134 | , $CONF["shop_name"] // 配送元 名前 |
---|
135 | , $CONF["email03"] // reply_to |
---|
136 | , $CONF["email04"] // return_path |
---|
137 | , $CONF["email04"] // Errors_to |
---|
138 | , $CONF["email01"] // Bcc |
---|
139 | ); |
---|
140 | // 宛先の設定 |
---|
141 | $objMail->setTo($_POST["email"], $_POST["email"]); |
---|
142 | $objMail->sendMail(); |
---|
143 | |
---|
144 | // 完了ページに移動させる。 |
---|
145 | $this->objDisplay->redirect($this->getLocation("./complete.php", |
---|
146 | array(session_name() => session_id()))); |
---|
147 | exit; |
---|
148 | } else { |
---|
149 | SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR); |
---|
150 | } |
---|
151 | |
---|
152 | $objView = new SC_MobileView(); |
---|
153 | // レイアウトデザインを取得 |
---|
154 | $objLayout = new SC_Helper_PageLayout_Ex(); |
---|
155 | $objLayout->sfGetPageLayout($this, false, DEF_LAYOUT); |
---|
156 | $objView->assignobj($this); |
---|
157 | $objView->display(SITE_FRAME); |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * デストラクタ. |
---|
162 | * |
---|
163 | * @return void |
---|
164 | */ |
---|
165 | function destroy() { |
---|
166 | parent::destroy(); |
---|
167 | } |
---|
168 | |
---|
169 | //---- 入力エラーチェック |
---|
170 | function lfMailErrorCheck($array, $dataName, &$objConn) { |
---|
171 | $objErr = new SC_CheckError($array); |
---|
172 | $objErr->doFunc( |
---|
173 | array('メールアドレス', $dataName, MTEXT_LEN) , |
---|
174 | array("NO_SPTAB", "EXIST_CHECK", "EMAIL_CHECK", |
---|
175 | "SPTAB_CHECK" ,"EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK", "EMAIL_CHECK", "MOBILE_EMAIL_CHECK")); |
---|
176 | |
---|
177 | // 入力エラーがなければ |
---|
178 | if (count($objErr->arrErr) == 0) { |
---|
179 | // メルマガの登録有無 |
---|
180 | $flg = $this->lfIsRegistData($array[$dataName], $objConn); |
---|
181 | |
---|
182 | // 登録の時 |
---|
183 | if ($dataName == 'regist' and $flg == true) { |
---|
184 | $objErr->arrErr[$dataName] = "既に登録されています。<br>"; |
---|
185 | // 解除の時 |
---|
186 | } elseif ($dataName == 'cancel' and $flg == false) { |
---|
187 | $objErr->arrErr[$dataName] = "メルマガ登録がされていません。<br>"; |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | return $objErr->arrErr; |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | //---- メルマガ登録 |
---|
196 | function lfRegistData ($email, &$objConn) { |
---|
197 | |
---|
198 | $count = 1; |
---|
199 | while ($count != 0) { |
---|
200 | $uniqid = SC_Utils_Ex::sfGetUniqRandomId("t"); |
---|
201 | $count = $objConn->getOne("SELECT COUNT(*) FROM dtb_customer_mail WHERE secret_key = ?", array($uniqid)); |
---|
202 | } |
---|
203 | |
---|
204 | $arrRegist["email"] = $email; // メールアドレス |
---|
205 | $arrRegist["mail_flag"] = 5; // 登録状態 |
---|
206 | $arrRegist["secret_key"] = $uniqid; // ID発行 |
---|
207 | $arrRegist["create_date"] = "now()"; // 作成日 |
---|
208 | $arrRegist["update_date"] = "now()"; // 更新日 |
---|
209 | |
---|
210 | //-- 仮登録実行 |
---|
211 | $objConn->query("BEGIN"); |
---|
212 | |
---|
213 | $objQuery = new SC_Query(); |
---|
214 | |
---|
215 | //-- 既にメルマガ登録しているかの判定 |
---|
216 | $sql = "SELECT count(*) FROM dtb_customer_mail WHERE email = ?"; |
---|
217 | $mailResult = $objConn->getOne($sql, array($arrRegist["email"])); |
---|
218 | |
---|
219 | if ($mailResult == 1) { |
---|
220 | $objQuery->update("dtb_customer_mail", $arrRegist, "email = " . SC_Utils_Ex::sfQuoteSmart($arrRegist["email"])); |
---|
221 | } else { |
---|
222 | $objQuery->insert("dtb_customer_mail", $arrRegist); |
---|
223 | } |
---|
224 | $objConn->query("COMMIT"); |
---|
225 | |
---|
226 | return $uniqid; |
---|
227 | } |
---|
228 | |
---|
229 | // 登録されているキーの取得 |
---|
230 | function lfGetSecretKey ($email, &$objConn) { |
---|
231 | $sql = "SELECT secret_key FROM dtb_customer_mail WHERE email = ?"; |
---|
232 | $uniqid = $objConn->getOne($sql, array($email)); |
---|
233 | |
---|
234 | if ($uniqid == '') { |
---|
235 | $count = 1; |
---|
236 | while ($count != 0) { |
---|
237 | $uniqid = SC_Utils_Ex::sfGetUniqRandomId("t"); |
---|
238 | $count = $objConn->getOne("SELECT COUNT(*) FROM dtb_customer_mail WHERE secret_key = ?", array($uniqid)); |
---|
239 | } |
---|
240 | |
---|
241 | $objQuery = new SC_Query(); |
---|
242 | $objQuery->update("dtb_customer_mail", array('secret_key' => $uniqid), "email = " . SC_Utils_Ex::sfQuoteSmart($email)); |
---|
243 | } |
---|
244 | |
---|
245 | return $uniqid; |
---|
246 | } |
---|
247 | |
---|
248 | // 既に登録されているかどうか |
---|
249 | function lfIsRegistData ($email, &$objConn) { |
---|
250 | $sql = "SELECT email, mailmaga_flg FROM dtb_customer_mail WHERE email = ?"; |
---|
251 | $mailResult = $objConn->getRow($sql, array($email)); |
---|
252 | |
---|
253 | // NULLも購読とみなす |
---|
254 | if (count($mailResult) == 0 or ($mailResult['mailmaga_flg'] != null and $mailResult['mailmaga_flg'] != 2 )) { |
---|
255 | return false; |
---|
256 | } else { |
---|
257 | return true; |
---|
258 | } |
---|
259 | } |
---|
260 | } |
---|
261 | ?> |
---|