source: tmp/version-2_5-test/data/class/SC_Customer.php @ 18609

Revision 18609, 11.5 KB checked in by kajiwara, 14 years ago (diff)

正式版にナイトリービルド版をマージしてみるテスト

  • 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        //docomo用にデータを取り出す。
102        if(SC_MobileUserAgent::getCarrier() == 'docomo'){
103            if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0)
104                $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId();
105        }
106        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
107            return false;
108        }
109
110        // 携帯端末IDが一致し、本登録された会員を検索する。
111        $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
112        $result = $this->conn->getOne($sql, array($_SESSION['mobile']['phone_id']));
113        return $result > 0;
114    }
115
116    /**
117     * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。
118     * パスワードが合っている場合は顧客情報を取得する。
119     *
120     * @param string $pass パスワード
121     * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、
122     *                 それ以外の場合は false を返す。
123     */
124    function getCustomerDataFromMobilePhoneIdPass($pass) {
125        //docomo用にデータを取り出す。
126        if(SC_MobileUserAgent::getCarrier() == 'docomo'){
127            if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0)
128                $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId();
129        }
130        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
131            return false;
132        }
133
134        // 携帯端末IDが一致し、本登録された会員を検索する。
135        $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
136        @list($data) = $this->conn->getAll($sql, array($_SESSION['mobile']['phone_id']));
137
138        // パスワードが合っている場合は、顧客情報をcustomer_dataに格納してtrueを返す。
139        if (sha1($pass . ':' . AUTH_MAGIC) == @$data['password']) {
140            $this->customer_data = $data;
141            $this->startSession();
142            return true;
143        }
144        return false;
145    }
146
147    /**
148     * 携帯端末IDを登録する。
149     *
150     * @return void
151     */
152    function updateMobilePhoneId() {
153        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
154            return;
155        }
156
157        if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) {
158            return;
159        }
160
161        $objQuery = new SC_Query;
162        $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']);
163        $where = 'customer_id = ? AND del_flg = 0 AND status = 2';
164        $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id']));
165
166        $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id'];
167    }
168
169    /**
170     * email から email_mobile へ携帯のメールアドレスをコピーする。
171     *
172     * @return void
173     */
174    function updateEmailMobile() {
175
176        $objMobile = new SC_Helper_Mobile_Ex();
177        // すでに email_mobile に値が入っている場合は何もしない。
178        if ($this->customer_data['email_mobile'] != '') {
179            return;
180        }
181
182        // email が携帯のメールアドレスではない場合は何もしない。
183        if (!$objMobile->gfIsMobileMailAddress($this->customer_data['email'])) {
184            return;
185        }
186
187        // email から email_mobile へコピーする。
188        $objQuery = new SC_Query;
189        $sqlval = array('email_mobile' => $this->customer_data['email']);
190        $where = 'customer_id = ? AND del_flg = 0 AND status = 2';
191        $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id']));
192
193        $this->customer_data['email_mobile'] = $this->customer_data['email'];
194    }
195
196    // パスワードを確認せずにログイン
197    function setLogin($email) {
198        // 本登録された会員のみ
199        $sql = "SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2";
200        $result = $this->conn->getAll($sql, array($email, $email));
201        $data = isset($result[0]) ? $result[0] : "";
202        $this->customer_data = $data;
203        $this->startSession();
204    }
205
206    // セッション情報を最新の情報に更新する
207    function updateSession() {
208        $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
209        $customer_id = $this->getValue('customer_id');
210        $arrRet = $this->conn->getAll($sql, array($customer_id));
211        $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : "";
212        $_SESSION['customer'] = $this->customer_data;
213    }
214
215    // ログイン情報をセッションに登録し、ログに書き込む
216    function startSession() {
217        SC_Utils_Ex::sfDomainSessionStart();
218        $_SESSION['customer'] = $this->customer_data;
219        // セッション情報の保存
220        GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH );
221    }
222
223    // ログアウト $_SESSION['customer']を解放し、ログに書き込む
224    function EndSession() {
225        // $_SESSION['customer']の解放
226        unset($_SESSION['customer']);
227        $objSiteSess = new SC_SiteSession();
228        $objSiteSess->unsetUniqId();
229        // ログに記録する
230        GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH );
231    }
232
233    // ログインに成功しているか判定する。
234    function isLoginSuccess($dont_check_email_mobile = false) {
235        // ログイン時のメールアドレスとDBのメールアドレスが一致している場合
236        if(isset($_SESSION['customer']['customer_id'])
237            && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) {
238
239            $objQuery = new SC_Query();
240            $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id']));
241            if($email == $_SESSION['customer']['email']) {
242                // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。
243                // ただし $dont_check_email_mobile が true の場合はチェックしない。
244                if (defined('MOBILE_SITE') && !$dont_check_email_mobile) {
245                    $email_mobile = $objQuery->get("dtb_customer", "email_mobile", "customer_id = ?", array($_SESSION['customer']['customer_id']));
246                    return isset($email_mobile);
247                }
248                return true;
249            }
250        }
251        return false;
252    }
253
254    // パラメータの取得
255    function getValue($keyname) {
256        return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : "";
257    }
258
259    // パラメータのセット
260    function setValue($keyname, $val) {
261        $_SESSION['customer'][$keyname] = $val;
262    }
263
264    // パラメータがNULLかどうかの判定
265    function hasValue($keyname) {
266        return isset($_SESSION['customer'][$keyname]);
267    }
268
269    // 誕生日月であるかどうかの判定
270    function isBirthMonth() {
271        if (isset($_SESSION['customer']['birth'])) {
272            $arrRet = split("[- :/]", $_SESSION['customer']['birth']);
273            $birth_month = intval($arrRet[1]);
274            $now_month = intval(date("m"));
275
276            if($birth_month == $now_month) {
277                return true;
278            }
279        }
280        return false;
281    }
282
283    /**
284     * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す.
285     *
286     * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR']
287     * を返す.
288     *
289     * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列
290     */
291    function getRemoteHost() {
292
293        if (!empty($_SERVER['REMOTE_HOST'])) {
294            return $_SERVER['REMOTE_HOST'];
295        } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
296            return $_SERVER['REMOTE_ADDR'];
297        } else {
298            return "";
299        }
300    }
301}
302?>
Note: See TracBrowser for help on using the repository browser.