source: branches/feature-module-update/data/class/SC_Customer.php @ 16741

Revision 16741, 10.9 KB checked in by adachi, 16 years ago (diff)

set eol-style:LF

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