source: branches/beta/data/class/SC_Customer.php @ 15120

Revision 15120, 7.3 KB checked in by adati, 17 years ago (diff)

1.4.2betaのマージ

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        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( $pass, $email);
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?>
Note: See TracBrowser for help on using the repository browser.