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 | 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 | $sql_mobile = $mobile ? ' OR email_mobile ILIKE ?' : ''; |
---|
54 | $arrValues = array($email); |
---|
55 | if ($mobile) { |
---|
56 | $arrValues[] = $email; |
---|
57 | } |
---|
58 | // 本登録された会員のみ |
---|
59 | $sql = "SELECT * FROM dtb_customer WHERE (email ILIKE ?" . $sql_mobile . ") AND del_flg = 0 AND status = 2"; |
---|
60 | $result = $this->conn->getAll($sql, $arrValues); |
---|
61 | $data = $result[0]; |
---|
62 | |
---|
63 | // パスワードが合っていれば顧客情報をcustomer_dataにセットしてtrueを返す |
---|
64 | if ( sha1($pass . ":" . AUTH_MAGIC) == $data['password'] ){ |
---|
65 | $this->customer_data = $data; |
---|
66 | $this->startSession(); |
---|
67 | return true; |
---|
68 | } |
---|
69 | return false; |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * 携帯端末IDが一致する会員が存在するかどうかをチェックする。 |
---|
74 | * |
---|
75 | * @return boolean 該当する会員が存在する場合は true、それ以外の場合 |
---|
76 | * は false を返す。 |
---|
77 | */ |
---|
78 | function checkMobilePhoneId() { |
---|
79 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
80 | return false; |
---|
81 | } |
---|
82 | |
---|
83 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
---|
84 | $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
---|
85 | $result = $this->conn->getOne($sql, array($_SESSION['mobile']['phone_id'])); |
---|
86 | return $result > 0; |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。 |
---|
91 | * パスワードが合っている場合は顧客情報を取得する。 |
---|
92 | * |
---|
93 | * @param string $pass パスワード |
---|
94 | * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、 |
---|
95 | * それ以外の場合は false を返す。 |
---|
96 | */ |
---|
97 | function getCustomerDataFromMobilePhoneIdPass($pass) { |
---|
98 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
99 | return false; |
---|
100 | } |
---|
101 | |
---|
102 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
---|
103 | $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
---|
104 | @list($data) = $this->conn->getAll($sql, array($_SESSION['mobile']['phone_id'])); |
---|
105 | |
---|
106 | // パスワードが合っている場合は、顧客情報をcustomer_dataに格納してtrueを返す。 |
---|
107 | if (sha1($pass . ':' . AUTH_MAGIC) == @$data['password']) { |
---|
108 | $this->customer_data = $data; |
---|
109 | $this->startSession(); |
---|
110 | return true; |
---|
111 | } |
---|
112 | return false; |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * 携帯端末IDを登録する。 |
---|
117 | * |
---|
118 | * @return void |
---|
119 | */ |
---|
120 | function updateMobilePhoneId() { |
---|
121 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
122 | return; |
---|
123 | } |
---|
124 | |
---|
125 | if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) { |
---|
126 | return; |
---|
127 | } |
---|
128 | |
---|
129 | $objQuery = new SC_Query; |
---|
130 | $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']); |
---|
131 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
---|
132 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
---|
133 | |
---|
134 | $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id']; |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * email から email_mobile へ携帯のメールアドレスをコピーする。 |
---|
139 | * |
---|
140 | * @return void |
---|
141 | */ |
---|
142 | function updateEmailMobile() { |
---|
143 | // すでに email_mobile に値が入っている場合は何もしない。 |
---|
144 | if ($this->customer_data['email_mobile'] != '') { |
---|
145 | return; |
---|
146 | } |
---|
147 | |
---|
148 | // email が携帯のメールアドレスではない場合は何もしない。 |
---|
149 | if (!gfIsMobileMailAddress($this->customer_data['email'])) { |
---|
150 | return; |
---|
151 | } |
---|
152 | |
---|
153 | // email から email_mobile へコピーする。 |
---|
154 | $objQuery = new SC_Query; |
---|
155 | $sqlval = array('email_mobile' => $this->customer_data['email']); |
---|
156 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
---|
157 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
---|
158 | |
---|
159 | $this->customer_data['email_mobile'] = $this->customer_data['email']; |
---|
160 | } |
---|
161 | |
---|
162 | // パスワードを確認せずにログイン |
---|
163 | function setLogin($email) { |
---|
164 | // 本登録された会員のみ |
---|
165 | $sql = "SELECT * FROM dtb_customer WHERE email ILIKE ? AND del_flg = 0 AND status = 2"; |
---|
166 | $result = $this->conn->getAll($sql, array($email)); |
---|
167 | $data = $result[0]; |
---|
168 | $this->customer_data = $data; |
---|
169 | $this->startSession(); |
---|
170 | } |
---|
171 | |
---|
172 | // セッション情報を最新の情報に更新する |
---|
173 | function updateSession() { |
---|
174 | $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0"; |
---|
175 | $customer_id = $this->getValue('customer_id'); |
---|
176 | $arrRet = $this->conn->getAll($sql, array($customer_id)); |
---|
177 | $this->customer_data = $arrRet[0]; |
---|
178 | $_SESSION['customer'] = $this->customer_data; |
---|
179 | } |
---|
180 | |
---|
181 | // ログイン情報をセッションに登録し、ログに書き込む |
---|
182 | function startSession() { |
---|
183 | sfDomainSessionStart(); |
---|
184 | $_SESSION['customer'] = $this->customer_data; |
---|
185 | // セッション情報の保存 |
---|
186 | gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $_SERVER['REMOTE_HOST'], CUSTOMER_LOG_PATH ); |
---|
187 | } |
---|
188 | |
---|
189 | // ログアウト $_SESSION['customer']を解放し、ログに書き込む |
---|
190 | function EndSession() { |
---|
191 | // $_SESSION['customer']の解放 |
---|
192 | unset($_SESSION['customer']); |
---|
193 | // ログに記録する |
---|
194 | gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $_SERVER['REMOTE_HOST'], CUSTOMER_LOG_PATH ); |
---|
195 | } |
---|
196 | |
---|
197 | // ログインに成功しているか判定する。 |
---|
198 | function isLoginSuccess($dont_check_email_mobile = false) { |
---|
199 | // ログイン時のメールアドレスとDBのメールアドレスが一致している場合 |
---|
200 | if(sfIsInt($_SESSION['customer']['customer_id'])) { |
---|
201 | $objQuery = new SC_Query(); |
---|
202 | $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
---|
203 | if($email == $_SESSION['customer']['email']) { |
---|
204 | // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。 |
---|
205 | // ただし $dont_check_email_mobile が true の場合はチェックしない。 |
---|
206 | if (defined('MOBILE_SITE') && !$dont_check_email_mobile) { |
---|
207 | $email_mobile = $objQuery->get("dtb_customer", "email_mobile", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
---|
208 | return isset($email_mobile); |
---|
209 | } |
---|
210 | return true; |
---|
211 | } |
---|
212 | } |
---|
213 | return false; |
---|
214 | } |
---|
215 | |
---|
216 | // パラメータの取得 |
---|
217 | function getValue($keyname) { |
---|
218 | return $_SESSION['customer'][$keyname]; |
---|
219 | } |
---|
220 | |
---|
221 | // パラメータのセット |
---|
222 | function setValue($keyname, $val) { |
---|
223 | $_SESSION['customer'][$keyname] = $val; |
---|
224 | } |
---|
225 | |
---|
226 | // パラメータがNULLかどうかの判定 |
---|
227 | function hasValue($keyname) { |
---|
228 | return isset($_SESSION['customer'][$keyname]); |
---|
229 | } |
---|
230 | |
---|
231 | // 誕生日月であるかどうかの判定 |
---|
232 | function isBirthMonth() { |
---|
233 | $arrRet = split("[- :/]", $_SESSION['customer']['birth']); |
---|
234 | $birth_month = intval($arrRet[1]); |
---|
235 | $now_month = intval(date("m")); |
---|
236 | |
---|
237 | if($birth_month == $now_month) { |
---|
238 | return true; |
---|
239 | } |
---|
240 | return false; |
---|
241 | } |
---|
242 | } |
---|
243 | ?> |
---|