| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 4 | * |
|---|
| 5 | * http://www.lockon.co.jp/ |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | /* [名称] SC_Customer |
|---|
| 9 | * [概要] 会員管理クラス |
|---|
| 10 | */ |
|---|
| 11 | class SC_Customer { |
|---|
| 12 | |
|---|
| 13 | var $conn; |
|---|
| 14 | var $email; |
|---|
| 15 | var $customer_data; // 会員情報 |
|---|
| 16 | |
|---|
| 17 | function SC_Customer( $conn = '', $email = '', $pass = '' ) { |
|---|
| 18 | // セッション開始 |
|---|
| 19 | /* startSessionから移動 2005/11/04 中川 */ |
|---|
| 20 | SC_Utils_Ex::sfDomainSessionStart(); |
|---|
| 21 | |
|---|
| 22 | // DB接続オブジェクト生成 |
|---|
| 23 | $DB_class_name = "SC_DbConn"; |
|---|
| 24 | if ( is_object($conn)){ |
|---|
| 25 | if ( is_a($conn, $DB_class_name)){ |
|---|
| 26 | // $connが$DB_class_nameのインスタンスである |
|---|
| 27 | $this->conn = $conn; |
|---|
| 28 | } |
|---|
| 29 | } else { |
|---|
| 30 | if (class_exists($DB_class_name)){ |
|---|
| 31 | //$DB_class_nameのインスタンスを作成する |
|---|
| 32 | $this->conn = new SC_DbConn(); |
|---|
| 33 | } |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | if ( is_object($this->conn) ) { |
|---|
| 37 | // 正常にDBに接続できる |
|---|
| 38 | if ( $email ){ |
|---|
| 39 | // emailから顧客情報を取得する |
|---|
| 40 | // $this->setCustomerDataFromEmail( $email ); |
|---|
| 41 | } |
|---|
| 42 | } else { |
|---|
| 43 | echo "DB接続オブジェクトの生成に失敗しています"; |
|---|
| 44 | exit; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | if ( strlen($email) > 0 && strlen($pass) > 0 ){ |
|---|
| 48 | $this->getCustomerDataFromEmailPass( $email, $pass ); |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | function getCustomerDataFromEmailPass( $pass, $email, $mobile = false ) { |
|---|
| 53 | // 小文字に変換 |
|---|
| 54 | $email = strtolower($email); |
|---|
| 55 | $sql_mobile = $mobile ? ' OR email_mobile = ?' : ''; |
|---|
| 56 | $arrValues = array($email); |
|---|
| 57 | if ($mobile) { |
|---|
| 58 | $arrValues[] = $email; |
|---|
| 59 | } |
|---|
| 60 | // 本登録された会員のみ |
|---|
| 61 | $sql = "SELECT * FROM dtb_customer WHERE (email = ?" . $sql_mobile . ") AND del_flg = 0 AND status = 2"; |
|---|
| 62 | $result = $this->conn->getAll($sql, $arrValues); |
|---|
| 63 | if (empty($result)) { |
|---|
| 64 | return false; |
|---|
| 65 | } else { |
|---|
| 66 | $data = $result[0]; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | // パスワードが合っていれば顧客情報をcustomer_dataにセットしてtrueを返す |
|---|
| 70 | if ( sha1($pass . ":" . AUTH_MAGIC) == $data['password'] ){ |
|---|
| 71 | $this->customer_data = $data; |
|---|
| 72 | $this->startSession(); |
|---|
| 73 | return true; |
|---|
| 74 | } |
|---|
| 75 | return false; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | * 携帯端末IDが一致する会員が存在するかどうかをチェックする。 |
|---|
| 80 | * |
|---|
| 81 | * @return boolean 該当する会員が存在する場合は true、それ以外の場合 |
|---|
| 82 | * は false を返す。 |
|---|
| 83 | */ |
|---|
| 84 | function checkMobilePhoneId() { |
|---|
| 85 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
|---|
| 86 | return false; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
|---|
| 90 | $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
|---|
| 91 | $result = $this->conn->getOne($sql, array($_SESSION['mobile']['phone_id'])); |
|---|
| 92 | return $result > 0; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | /** |
|---|
| 96 | * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。 |
|---|
| 97 | * パスワードが合っている場合は顧客情報を取得する。 |
|---|
| 98 | * |
|---|
| 99 | * @param string $pass パスワード |
|---|
| 100 | * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、 |
|---|
| 101 | * それ以外の場合は false を返す。 |
|---|
| 102 | */ |
|---|
| 103 | function getCustomerDataFromMobilePhoneIdPass($pass) { |
|---|
| 104 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
|---|
| 105 | return false; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
|---|
| 109 | $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
|---|
| 110 | @list($data) = $this->conn->getAll($sql, array($_SESSION['mobile']['phone_id'])); |
|---|
| 111 | |
|---|
| 112 | // パスワードが合っている場合は、顧客情報をcustomer_dataに格納してtrueを返す。 |
|---|
| 113 | if (sha1($pass . ':' . AUTH_MAGIC) == @$data['password']) { |
|---|
| 114 | $this->customer_data = $data; |
|---|
| 115 | $this->startSession(); |
|---|
| 116 | return true; |
|---|
| 117 | } |
|---|
| 118 | return false; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | /** |
|---|
| 122 | * 携帯端末IDを登録する。 |
|---|
| 123 | * |
|---|
| 124 | * @return void |
|---|
| 125 | */ |
|---|
| 126 | function updateMobilePhoneId() { |
|---|
| 127 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
|---|
| 128 | return; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) { |
|---|
| 132 | return; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | $objQuery = new SC_Query; |
|---|
| 136 | $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']); |
|---|
| 137 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
|---|
| 138 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
|---|
| 139 | |
|---|
| 140 | $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id']; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | /** |
|---|
| 144 | * email から email_mobile へ携帯のメールアドレスをコピーする。 |
|---|
| 145 | * |
|---|
| 146 | * @return void |
|---|
| 147 | */ |
|---|
| 148 | function updateEmailMobile() { |
|---|
| 149 | |
|---|
| 150 | $objMobile = new SC_Helper_Mobile_Ex(); |
|---|
| 151 | // すでに email_mobile に値が入っている場合は何もしない。 |
|---|
| 152 | if ($this->customer_data['email_mobile'] != '') { |
|---|
| 153 | return; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | // email が携帯のメールアドレスではない場合は何もしない。 |
|---|
| 157 | if (!$objMobile->gfIsMobileMailAddress($this->customer_data['email'])) { |
|---|
| 158 | return; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | // email から email_mobile へコピーする。 |
|---|
| 162 | $objQuery = new SC_Query; |
|---|
| 163 | $sqlval = array('email_mobile' => $this->customer_data['email']); |
|---|
| 164 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
|---|
| 165 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
|---|
| 166 | |
|---|
| 167 | $this->customer_data['email_mobile'] = $this->customer_data['email']; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | // パスワードを確認せずにログイン |
|---|
| 171 | function setLogin($email) { |
|---|
| 172 | // 本登録された会員のみ |
|---|
| 173 | $sql = "SELECT * FROM dtb_customer WHERE email = ? AND del_flg = 0 AND status = 2"; |
|---|
| 174 | $result = $this->conn->getAll($sql, array($email)); |
|---|
| 175 | $data = isset($result[0]) ? $result[0] : ""; |
|---|
| 176 | $this->customer_data = $data; |
|---|
| 177 | $this->startSession(); |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | // セッション情報を最新の情報に更新する |
|---|
| 181 | function updateSession() { |
|---|
| 182 | $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0"; |
|---|
| 183 | $customer_id = $this->getValue('customer_id'); |
|---|
| 184 | $arrRet = $this->conn->getAll($sql, array($customer_id)); |
|---|
| 185 | $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : ""; |
|---|
| 186 | $_SESSION['customer'] = $this->customer_data; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | // ログイン情報をセッションに登録し、ログに書き込む |
|---|
| 190 | function startSession() { |
|---|
| 191 | SC_Utils_Ex::sfDomainSessionStart(); |
|---|
| 192 | $_SESSION['customer'] = $this->customer_data; |
|---|
| 193 | // セッション情報の保存 |
|---|
| 194 | GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH ); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | // ログアウト $_SESSION['customer']を解放し、ログに書き込む |
|---|
| 198 | function EndSession() { |
|---|
| 199 | // $_SESSION['customer']の解放 |
|---|
| 200 | unset($_SESSION['customer']); |
|---|
| 201 | // ログに記録する |
|---|
| 202 | GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH ); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | // ログインに成功しているか判定する。 |
|---|
| 206 | function isLoginSuccess($dont_check_email_mobile = false) { |
|---|
| 207 | // ログイン時のメールアドレスとDBのメールアドレスが一致している場合 |
|---|
| 208 | if(isset($_SESSION['customer']['customer_id']) |
|---|
| 209 | && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) { |
|---|
| 210 | |
|---|
| 211 | $objQuery = new SC_Query(); |
|---|
| 212 | $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
|---|
| 213 | if($email == $_SESSION['customer']['email']) { |
|---|
| 214 | // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。 |
|---|
| 215 | // ただし $dont_check_email_mobile が true の場合はチェックしない。 |
|---|
| 216 | if (defined('MOBILE_SITE') && !$dont_check_email_mobile) { |
|---|
| 217 | $email_mobile = $objQuery->get("dtb_customer", "email_mobile", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
|---|
| 218 | return isset($email_mobile); |
|---|
| 219 | } |
|---|
| 220 | return true; |
|---|
| 221 | } |
|---|
| 222 | } |
|---|
| 223 | return false; |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | // パラメータの取得 |
|---|
| 227 | function getValue($keyname) { |
|---|
| 228 | return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : ""; |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | // パラメータのセット |
|---|
| 232 | function setValue($keyname, $val) { |
|---|
| 233 | $_SESSION['customer'][$keyname] = $val; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | // パラメータがNULLかどうかの判定 |
|---|
| 237 | function hasValue($keyname) { |
|---|
| 238 | return isset($_SESSION['customer'][$keyname]); |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | // 誕生日月であるかどうかの判定 |
|---|
| 242 | function isBirthMonth() { |
|---|
| 243 | if (isset($_SESSION['customer']['birth'])) { |
|---|
| 244 | $arrRet = split("[- :/]", $_SESSION['customer']['birth']); |
|---|
| 245 | $birth_month = intval($arrRet[1]); |
|---|
| 246 | $now_month = intval(date("m")); |
|---|
| 247 | |
|---|
| 248 | if($birth_month == $now_month) { |
|---|
| 249 | return true; |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | return false; |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | /** |
|---|
| 256 | * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す. |
|---|
| 257 | * |
|---|
| 258 | * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR'] |
|---|
| 259 | * を返す. |
|---|
| 260 | * |
|---|
| 261 | * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列 |
|---|
| 262 | */ |
|---|
| 263 | function getRemoteHost() { |
|---|
| 264 | |
|---|
| 265 | if (!empty($_SERVER['REMOTE_HOST'])) { |
|---|
| 266 | return $_SERVER['REMOTE_HOST']; |
|---|
| 267 | } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|---|
| 268 | return $_SERVER['REMOTE_ADDR']; |
|---|
| 269 | } else { |
|---|
| 270 | return ""; |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | ?> |
|---|