/PhpOnAzure.Web/data/class/SC_Customer.php
PHP | 310 lines | 192 code | 30 blank | 88 comment | 41 complexity | e9e8fae82c4ec2d27a3c37fb6f4d4804 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
- <?php
- /*
- * This file is part of EC-CUBE
- *
- * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
- *
- * http://www.lockon.co.jp/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /* [??] SC_Customer
- * [??] ???????
- */
- class SC_Customer {
- /** ???? */
- var $customer_data;
- function SC_Customer() {
- }
- function getCustomerDataFromEmailPass( $pass, $email, $mobile = false ) {
- // ??????
- $email = strtolower($email);
- $sql_mobile = $mobile ? ' OR email_mobile = ?' : '';
- $arrValues = array($email);
- if ($mobile) {
- $arrValues[] = $email;
- }
- // ??????????
- $sql = "SELECT * FROM dtb_customer WHERE (email = ?" . $sql_mobile . ") AND del_flg = 0 AND status = 2";
- $objQuery = new SC_Query_Ex();
- $result = $objQuery->getAll($sql, $arrValues);
- if (empty($result)) {
- return false;
- } else {
- $data = $result[0];
- }
- // ?????????????????customer_data??????true???
- if ( SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt']) ) {
- $this->customer_data = $data;
- $this->startSession();
- return true;
- }
- return false;
- }
- /**
- * ????????????.
- *
- * ???1?????????, ??????????????2?????
- * ?????.
- *
- * @param integer $customer_id ??ID
- * @return array ??????, ?????????
- */
- function getCustomerAddress($customer_id) {
- $objQuery =& SC_Query_Ex::getSingletonInstance();
- $from = <<< __EOS__
- ( SELECT NULL AS other_deliv_id,
- customer_id,
- name01, name02,
- kana01, kana02,
- zip01, zip02,
- pref,
- addr01, addr02,
- email, email_mobile,
- tel01, tel02, tel03,
- fax01, fax02, fax03
- FROM dtb_customer
- WHERE customer_id = ?
- UNION ALL
- SELECT other_deliv_id,
- customer_id,
- name01, name02,
- kana01, kana02,
- zip01, zip02,
- pref,
- addr01, addr02,
- NULL AS email, NULL AS email_mobile,
- tel01, tel02, tel03,
- NULL AS fax01, NULL AS fax02, NULL AS fax03
- FROM dtb_other_deliv
- WHERE customer_id = ?
- ) AS addrs
- __EOS__;
- $objQuery->setOrder("CASE WHEN other_deliv_id is null THEN -1 ELSE 0 END, other_deliv_id DESC");
- return $objQuery->select("*", $from, "", array($customer_id, $customer_id));
- }
- /**
- * ????ID????????????????????????
- * FIXME
- * @return boolean ?????????????? true????????
- * ? false ????
- */
- function checkMobilePhoneId() {
- //docomo???????????
- if(SC_MobileUserAgent_Ex::getCarrier() == 'docomo'){
- if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0)
- $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent_Ex::getId();
- }
- if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
- return false;
- }
- // ????ID???????????????????
- $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
- $objQuery = new SC_Query_Ex();
- $result = $objQuery->count("dtb_customer", "mobile_phone_id = ? AND del_flg = 0 AND status = 2", array($_SESSION['mobile']['phone_id']));
- return $result > 0;
- }
- /**
- * ????ID????????????????????????
- * ????????????????????????
- *
- * @param string $pass ?????
- * @return boolean ????????????????????????? true?
- * ???????? false ????
- */
- function getCustomerDataFromMobilePhoneIdPass($pass) {
- //docomo???????????
- if(SC_MobileUserAgent_Ex::getCarrier() == 'docomo'){
- if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0)
- $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent_Ex::getId();
- }
- if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
- return false;
- }
- // ????ID???????????????????
- $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
- $objQuery = new SC_Query_Ex();
- @list($data) = $objQuery->getAll($sql, array($_SESSION['mobile']['phone_id']));
- // ????????????????????customer_data?????true????
- if ( SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt']) ) {
- $this->customer_data = $data;
- $this->startSession();
- return true;
- }
- return false;
- }
- /**
- * ????ID??????
- *
- * @return void
- */
- function updateMobilePhoneId() {
- if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
- return;
- }
- if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) {
- return;
- }
- $objQuery = new SC_Query_Ex();
- $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']);
- $where = 'customer_id = ? AND del_flg = 0 AND status = 2';
- $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id']));
- $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id'];
- }
- // ???????????????
- function setLogin($email) {
- // ??????????
- $sql = "SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2";
- $objQuery = new SC_Query_Ex();
- $result = $objQuery->getAll($sql, array($email, $email));
- $data = isset($result[0]) ? $result[0] : "";
- $this->customer_data = $data;
- $this->startSession();
- }
- // ??????????????????
- function updateSession() {
- $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
- $customer_id = $this->getValue('customer_id');
- $objQuery = new SC_Query_Ex();
- $arrRet = $objQuery->getAll($sql, array($customer_id));
- $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : "";
- $_SESSION['customer'] = $this->customer_data;
- }
- // ????????????????????????
- function startSession() {
- $_SESSION['customer'] = $this->customer_data;
- // ??????????
- GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_REALFILE );
- }
- // ??????$_SESSION['customer']????????????
- function EndSession() {
- // $_SESSION['customer']???
- unset($_SESSION['customer']);
- // ???????????????
- SC_Helper_Session_Ex::destroyToken();
- $objSiteSess = new SC_SiteSession_Ex();
- $objSiteSess->unsetUniqId();
- // ???????
- GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_REALFILE );
- }
- // ?????????????????
- function isLoginSuccess($dont_check_email_mobile = false) {
- // ??????????????DB?????????????????
- if(isset($_SESSION['customer']['customer_id'])
- && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) {
- $objQuery = new SC_Query_Ex();
- $email = $objQuery->get('email', "dtb_customer", "customer_id = ?", array($_SESSION['customer']['customer_id']));
- if($email == $_SESSION['customer']['email']) {
- // ???????????????????????????????????????
- // ??? $dont_check_email_mobile ? true ????????????
- if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE && !$dont_check_email_mobile) {
- $email_mobile = $objQuery->get("email_mobile", "dtb_customer", "customer_id = ?", array($_SESSION['customer']['customer_id']));
- return isset($email_mobile);
- }
- return true;
- }
- }
- return false;
- }
- // ?????????
- function getValue($keyname) {
- // ?????????????
- if ($keyname == 'point') {
- $objQuery =& SC_Query_Ex::getSingletonInstance();
- $point = $objQuery->get('point', 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
- $_SESSION['customer']['point'] = $point;
- return $point;
- } else {
- return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : "";
- }
- }
- // ??????????
- function setValue($keyname, $val) {
- $_SESSION['customer'][$keyname] = $val;
- }
- // ???????NULL???????
- function hasValue($keyname) {
- if (isset($_SESSION['customer'][$keyname])) {
- return !SC_Utils_Ex::isBlank($_SESSION['customer'][$keyname]);
- }
- return false;
- }
- // ??????????????
- function isBirthMonth() {
- if (isset($_SESSION['customer']['birth'])) {
- $arrRet = preg_split("|[- :/]|", $_SESSION['customer']['birth']);
- $birth_month = intval($arrRet[1]);
- $now_month = intval(date('m'));
- if($birth_month == $now_month) {
- return true;
- }
- }
- return false;
- }
- /**
- * $_SERVER['REMOTE_HOST'] ??? $_SERVER['REMOTE_ADDR'] ???.
- *
- * $_SERVER['REMOTE_HOST'] ?????????? $_SERVER['REMOTE_ADDR']
- * ???.
- *
- * @return string $_SERVER['REMOTE_HOST'] ?? $_SERVER['REMOTE_ADDR']????
- */
- function getRemoteHost() {
- if (!empty($_SERVER['REMOTE_HOST'])) {
- return $_SERVER['REMOTE_HOST'];
- } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
- return $_SERVER['REMOTE_ADDR'];
- } else {
- return "";
- }
- }
-
- //????????????
- function updateOrderSummary($customer_id){
- $objQuery = new SC_Query_Ex();
- $arrOrderSummary = $objQuery->getRow("SUM( payment_total ) as buy_total, COUNT(order_id) as buy_times,MAX( create_date ) as last_buy_date, MIN(create_date) as first_buy_date","dtb_order","customer_id = ? AND del_flg = 0 AND status <> ?",array($customer_id,ORDER_CANCEL));
- $objQuery->update("dtb_customer",$arrOrderSummary,"customer_id = ?",array($customer_id));
- }
- }
- ?>