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 | /* [名称] SC_Customer |
---|
25 | * [概要] 会員管理クラス |
---|
26 | */ |
---|
27 | class SC_Customer { |
---|
28 | |
---|
29 | var $customer_data; // 会員情報 |
---|
30 | |
---|
31 | function SC_Customer() { |
---|
32 | } |
---|
33 | |
---|
34 | function getCustomerDataFromEmailPass( $pass, $email, $mobile = false ) { |
---|
35 | // 小文字に変換 |
---|
36 | $email = strtolower($email); |
---|
37 | $sql_mobile = $mobile ? ' OR email_mobile = ?' : ''; |
---|
38 | $arrValues = array($email); |
---|
39 | if ($mobile) { |
---|
40 | $arrValues[] = $email; |
---|
41 | } |
---|
42 | // 本登録された会員のみ |
---|
43 | $sql = "SELECT * FROM dtb_customer WHERE (email = ?" . $sql_mobile . ") AND del_flg = 0 AND status = 2"; |
---|
44 | $objQuery = new SC_Query(); |
---|
45 | $result = $objQuery->getAll($sql, $arrValues); |
---|
46 | if (empty($result)) { |
---|
47 | return false; |
---|
48 | } else { |
---|
49 | $data = $result[0]; |
---|
50 | } |
---|
51 | |
---|
52 | // パスワードが合っていれば顧客情報をcustomer_dataにセットしてtrueを返す |
---|
53 | if ( SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt']) ) { |
---|
54 | $this->customer_data = $data; |
---|
55 | $this->startSession(); |
---|
56 | return true; |
---|
57 | } |
---|
58 | return false; |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * 会員の登録住所を取得する. |
---|
63 | * |
---|
64 | * 配列の1番目に会員登録住所, 追加登録住所が存在する場合は2番目以降に |
---|
65 | * 設定される. |
---|
66 | * |
---|
67 | * @param integer $customer_id 会員ID |
---|
68 | * @return array 会員登録住所, 追加登録住所の配列 |
---|
69 | */ |
---|
70 | function getCustomerAddress($customer_id) { |
---|
71 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
72 | |
---|
73 | $from = <<< __EOS__ |
---|
74 | ( SELECT NULL AS other_deliv_id, |
---|
75 | customer_id, |
---|
76 | name01, name02, |
---|
77 | kana01, kana02, |
---|
78 | zip01, zip02, |
---|
79 | pref, |
---|
80 | addr01, addr02, |
---|
81 | email, email_mobile, |
---|
82 | tel01, tel02, tel03, |
---|
83 | fax01, fax02, fax03 |
---|
84 | FROM dtb_customer |
---|
85 | WHERE customer_id = ? |
---|
86 | UNION ALL |
---|
87 | SELECT other_deliv_id, |
---|
88 | customer_id, |
---|
89 | name01, name02, |
---|
90 | kana01, kana02, |
---|
91 | zip01, zip02, |
---|
92 | pref, |
---|
93 | addr01, addr02, |
---|
94 | NULL AS email, NULL AS email_mobile, |
---|
95 | tel01, tel02, tel03, |
---|
96 | NULL AS fax01, NULL AS fax02, NULL AS fax03 |
---|
97 | FROM dtb_other_deliv |
---|
98 | WHERE customer_id = ? |
---|
99 | ) AS addrs |
---|
100 | __EOS__; |
---|
101 | $objQuery->setOrder("other_deliv_id IS NULL DESC, other_deliv_id DESC"); |
---|
102 | return $objQuery->select("*", $from, "", array($customer_id, $customer_id)); |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * 携帯端末IDが一致する会員が存在するかどうかをチェックする。 |
---|
107 | * FIXME |
---|
108 | * @return boolean 該当する会員が存在する場合は true、それ以外の場合 |
---|
109 | * は false を返す。 |
---|
110 | */ |
---|
111 | function checkMobilePhoneId() { |
---|
112 | //docomo用にデータを取り出す。 |
---|
113 | if(SC_MobileUserAgent::getCarrier() == 'docomo'){ |
---|
114 | if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0) |
---|
115 | $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); |
---|
116 | } |
---|
117 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
118 | return false; |
---|
119 | } |
---|
120 | |
---|
121 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
---|
122 | $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
---|
123 | $objQuery = new SC_Query(); |
---|
124 | $result = $objQuery->count("dtb_customer", "mobile_phone_id = ? AND del_flg = 0 AND status = 2", array($_SESSION['mobile']['phone_id'])); |
---|
125 | return $result > 0; |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。 |
---|
130 | * パスワードが合っている場合は顧客情報を取得する。 |
---|
131 | * |
---|
132 | * @param string $pass パスワード |
---|
133 | * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、 |
---|
134 | * それ以外の場合は false を返す。 |
---|
135 | */ |
---|
136 | function getCustomerDataFromMobilePhoneIdPass($pass) { |
---|
137 | //docomo用にデータを取り出す。 |
---|
138 | if(SC_MobileUserAgent::getCarrier() == 'docomo'){ |
---|
139 | if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0) |
---|
140 | $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); |
---|
141 | } |
---|
142 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
143 | return false; |
---|
144 | } |
---|
145 | |
---|
146 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
---|
147 | $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
---|
148 | $objQuery = new SC_Query(); |
---|
149 | @list($data) = $objQuery->getAll($sql, array($_SESSION['mobile']['phone_id'])); |
---|
150 | |
---|
151 | // パスワードが合っている場合は、顧客情報をcustomer_dataに格納してtrueを返す。 |
---|
152 | if ( SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt']) ) { |
---|
153 | $this->customer_data = $data; |
---|
154 | $this->startSession(); |
---|
155 | return true; |
---|
156 | } |
---|
157 | return false; |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * 携帯端末IDを登録する。 |
---|
162 | * |
---|
163 | * @return void |
---|
164 | */ |
---|
165 | function updateMobilePhoneId() { |
---|
166 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
167 | return; |
---|
168 | } |
---|
169 | |
---|
170 | if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) { |
---|
171 | return; |
---|
172 | } |
---|
173 | |
---|
174 | $objQuery = new SC_Query; |
---|
175 | $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']); |
---|
176 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
---|
177 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
---|
178 | |
---|
179 | $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id']; |
---|
180 | } |
---|
181 | |
---|
182 | // パスワードを確認せずにログイン |
---|
183 | function setLogin($email) { |
---|
184 | // 本登録された会員のみ |
---|
185 | $sql = "SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2"; |
---|
186 | $objQuery = new SC_Query(); |
---|
187 | $result = $objQuery->getAll($sql, array($email, $email)); |
---|
188 | $data = isset($result[0]) ? $result[0] : ""; |
---|
189 | $this->customer_data = $data; |
---|
190 | $this->startSession(); |
---|
191 | } |
---|
192 | |
---|
193 | // セッション情報を最新の情報に更新する |
---|
194 | function updateSession() { |
---|
195 | $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0"; |
---|
196 | $customer_id = $this->getValue('customer_id'); |
---|
197 | $objQuery = new SC_Query(); |
---|
198 | $arrRet = $objQuery->getAll($sql, array($customer_id)); |
---|
199 | $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : ""; |
---|
200 | $_SESSION['customer'] = $this->customer_data; |
---|
201 | } |
---|
202 | |
---|
203 | // ログイン情報をセッションに登録し、ログに書き込む |
---|
204 | function startSession() { |
---|
205 | $_SESSION['customer'] = $this->customer_data; |
---|
206 | // セッション情報の保存 |
---|
207 | GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_REALFILE ); |
---|
208 | } |
---|
209 | |
---|
210 | // ログアウト $_SESSION['customer']を解放し、ログに書き込む |
---|
211 | function EndSession() { |
---|
212 | // $_SESSION['customer']の解放 |
---|
213 | unset($_SESSION['customer']); |
---|
214 | $objSiteSess = new SC_SiteSession(); |
---|
215 | $objSiteSess->unsetUniqId(); |
---|
216 | // ログに記録する |
---|
217 | GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_REALFILE ); |
---|
218 | } |
---|
219 | |
---|
220 | // ログインに成功しているか判定する。 |
---|
221 | function isLoginSuccess($dont_check_email_mobile = false) { |
---|
222 | // ログイン時のメールアドレスとDBのメールアドレスが一致している場合 |
---|
223 | if(isset($_SESSION['customer']['customer_id']) |
---|
224 | && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) { |
---|
225 | |
---|
226 | $objQuery = new SC_Query(); |
---|
227 | $email = $objQuery->get("email", "dtb_customer", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
---|
228 | if($email == $_SESSION['customer']['email']) { |
---|
229 | // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。 |
---|
230 | // ただし $dont_check_email_mobile が true の場合はチェックしない。 |
---|
231 | if (defined('MOBILE_SITE') && !$dont_check_email_mobile) { |
---|
232 | $email_mobile = $objQuery->get("email_mobile", "dtb_customer", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
---|
233 | return isset($email_mobile); |
---|
234 | } |
---|
235 | return true; |
---|
236 | } |
---|
237 | } |
---|
238 | return false; |
---|
239 | } |
---|
240 | |
---|
241 | // パラメータの取得 |
---|
242 | function getValue($keyname) { |
---|
243 | return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : ""; |
---|
244 | } |
---|
245 | |
---|
246 | // パラメータのセット |
---|
247 | function setValue($keyname, $val) { |
---|
248 | $_SESSION['customer'][$keyname] = $val; |
---|
249 | } |
---|
250 | |
---|
251 | // パラメータがNULLかどうかの判定 |
---|
252 | function hasValue($keyname) { |
---|
253 | return isset($_SESSION['customer'][$keyname]); |
---|
254 | } |
---|
255 | |
---|
256 | // 誕生日月であるかどうかの判定 |
---|
257 | function isBirthMonth() { |
---|
258 | if (isset($_SESSION['customer']['birth'])) { |
---|
259 | $arrRet = split("[- :/]", $_SESSION['customer']['birth']); |
---|
260 | $birth_month = intval($arrRet[1]); |
---|
261 | $now_month = intval(date("m")); |
---|
262 | |
---|
263 | if($birth_month == $now_month) { |
---|
264 | return true; |
---|
265 | } |
---|
266 | } |
---|
267 | return false; |
---|
268 | } |
---|
269 | |
---|
270 | /** |
---|
271 | * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す. |
---|
272 | * |
---|
273 | * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR'] |
---|
274 | * を返す. |
---|
275 | * |
---|
276 | * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列 |
---|
277 | */ |
---|
278 | function getRemoteHost() { |
---|
279 | |
---|
280 | if (!empty($_SERVER['REMOTE_HOST'])) { |
---|
281 | return $_SERVER['REMOTE_HOST']; |
---|
282 | } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
---|
283 | return $_SERVER['REMOTE_ADDR']; |
---|
284 | } else { |
---|
285 | return ""; |
---|
286 | } |
---|
287 | } |
---|
288 | } |
---|
289 | ?> |
---|