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