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

Revision 16188, 9.5 KB checked in by nanasess, 19 years ago (diff)

未定義変数の修正

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
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 */
11class 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        // すでに email_mobile に値が入っている場合は何もしない。
150        if ($this->customer_data['email_mobile'] != '') {
151            return;
152        }
153
154        // email が携帯のメールアドレスではない場合は何もしない。
155        if (!gfIsMobileMailAddress($this->customer_data['email'])) {
156            return;
157        }
158
159        // email から email_mobile へコピーする。
160        $objQuery = new SC_Query;
161        $sqlval = array('email_mobile' => $this->customer_data['email']);
162        $where = 'customer_id = ? AND del_flg = 0 AND status = 2';
163        $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id']));
164
165        $this->customer_data['email_mobile'] = $this->customer_data['email'];
166    }
167
168    // パスワードを確認せずにログイン
169    function setLogin($email) {
170        // 本登録された会員のみ
171        $sql = "SELECT * FROM dtb_customer WHERE email ILIKE ? AND del_flg = 0 AND status = 2";
172        $result = $this->conn->getAll($sql, array($email));
173        $data = isset($result[0]) ? $result[0] : "";
174        $this->customer_data = $data;
175        $this->startSession();
176    }
177
178    // セッション情報を最新の情報に更新する
179    function updateSession() {
180        $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
181        $customer_id = $this->getValue('customer_id');
182        $arrRet = $this->conn->getAll($sql, array($customer_id));
183        $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : "";
184        $_SESSION['customer'] = $this->customer_data;
185    }
186
187    // ログイン情報をセッションに登録し、ログに書き込む
188    function startSession() {
189        SC_Utils_Ex::sfDomainSessionStart();
190        $_SESSION['customer'] = $this->customer_data;
191        // セッション情報の保存
192        GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $_SERVER['REMOTE_HOST'], CUSTOMER_LOG_PATH );
193    }
194
195    // ログアウト $_SESSION['customer']を解放し、ログに書き込む
196    function EndSession() {
197        // $_SESSION['customer']の解放
198        unset($_SESSION['customer']);
199        // ログに記録する
200        GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $_SERVER['REMOTE_HOST'], CUSTOMER_LOG_PATH );
201    }
202
203    // ログインに成功しているか判定する。
204    function isLoginSuccess($dont_check_email_mobile = false) {
205        // ログイン時のメールアドレスとDBのメールアドレスが一致している場合
206        if(isset($_SESSION['customer']['customer_id'])
207            && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) {
208
209            $objQuery = new SC_Query();
210            $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id']));
211            if($email == $_SESSION['customer']['email']) {
212                // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。
213                // ただし $dont_check_email_mobile が true の場合はチェックしない。
214                if (defined('MOBILE_SITE') && !$dont_check_email_mobile) {
215                    $email_mobile = $objQuery->get("dtb_customer", "email_mobile", "customer_id = ?", array($_SESSION['customer']['customer_id']));
216                    return isset($email_mobile);
217                }
218                return true;
219            }
220        }
221        return false;
222    }
223
224    // パラメータの取得
225    function getValue($keyname) {
226        return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : "";
227    }
228
229    // パラメータのセット
230    function setValue($keyname, $val) {
231        $_SESSION['customer'][$keyname] = $val;
232    }
233
234    // パラメータがNULLかどうかの判定
235    function hasValue($keyname) {
236        return isset($_SESSION['customer'][$keyname]);
237    }
238
239    // 誕生日月であるかどうかの判定
240    function isBirthMonth() {
241        if (isset($_SESSION['customer']['birth'])) {
242            $arrRet = split("[- :/]", $_SESSION['customer']['birth']);
243            $birth_month = intval($arrRet[1]);
244            $now_month = intval(date("m"));
245
246            if($birth_month == $now_month) {
247                return true;
248            }
249        }
250        return false;
251    }
252}
253?>
Note: See TracBrowser for help on using the repository browser.