PageRenderTime 37ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/PhpOnAzure.Web/data/class/SC_Customer.php

http://eccubeonwaz.codeplex.com
PHP | 310 lines | 192 code | 30 blank | 88 comment | 41 complexity | e9e8fae82c4ec2d27a3c37fb6f4d4804 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * This file is part of EC-CUBE
  4. *
  5. * Copyright(c) 2000-2011 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. /* [??] SC_Customer
  24. * [??] ???????
  25. */
  26. class SC_Customer {
  27. /** ???? */
  28. var $customer_data;
  29. function SC_Customer() {
  30. }
  31. function getCustomerDataFromEmailPass( $pass, $email, $mobile = false ) {
  32. // ??????
  33. $email = strtolower($email);
  34. $sql_mobile = $mobile ? ' OR email_mobile = ?' : '';
  35. $arrValues = array($email);
  36. if ($mobile) {
  37. $arrValues[] = $email;
  38. }
  39. // ??????????
  40. $sql = "SELECT * FROM dtb_customer WHERE (email = ?" . $sql_mobile . ") AND del_flg = 0 AND status = 2";
  41. $objQuery = new SC_Query_Ex();
  42. $result = $objQuery->getAll($sql, $arrValues);
  43. if (empty($result)) {
  44. return false;
  45. } else {
  46. $data = $result[0];
  47. }
  48. // ?????????????????customer_data??????true???
  49. if ( SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt']) ) {
  50. $this->customer_data = $data;
  51. $this->startSession();
  52. return true;
  53. }
  54. return false;
  55. }
  56. /**
  57. * ????????????.
  58. *
  59. * ???1?????????, ??????????????2?????
  60. * ?????.
  61. *
  62. * @param integer $customer_id ??ID
  63. * @return array ??????, ?????????
  64. */
  65. function getCustomerAddress($customer_id) {
  66. $objQuery =& SC_Query_Ex::getSingletonInstance();
  67. $from = <<< __EOS__
  68. ( SELECT NULL AS other_deliv_id,
  69. customer_id,
  70. name01, name02,
  71. kana01, kana02,
  72. zip01, zip02,
  73. pref,
  74. addr01, addr02,
  75. email, email_mobile,
  76. tel01, tel02, tel03,
  77. fax01, fax02, fax03
  78. FROM dtb_customer
  79. WHERE customer_id = ?
  80. UNION ALL
  81. SELECT other_deliv_id,
  82. customer_id,
  83. name01, name02,
  84. kana01, kana02,
  85. zip01, zip02,
  86. pref,
  87. addr01, addr02,
  88. NULL AS email, NULL AS email_mobile,
  89. tel01, tel02, tel03,
  90. NULL AS fax01, NULL AS fax02, NULL AS fax03
  91. FROM dtb_other_deliv
  92. WHERE customer_id = ?
  93. ) AS addrs
  94. __EOS__;
  95. $objQuery->setOrder("CASE WHEN other_deliv_id is null THEN -1 ELSE 0 END, other_deliv_id DESC");
  96. return $objQuery->select("*", $from, "", array($customer_id, $customer_id));
  97. }
  98. /**
  99. * ????ID????????????????????????
  100. * FIXME
  101. * @return boolean ?????????????? true????????
  102. * ? false ????
  103. */
  104. function checkMobilePhoneId() {
  105. //docomo???????????
  106. if(SC_MobileUserAgent_Ex::getCarrier() == 'docomo'){
  107. if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0)
  108. $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent_Ex::getId();
  109. }
  110. if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
  111. return false;
  112. }
  113. // ????ID???????????????????
  114. $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
  115. $objQuery = new SC_Query_Ex();
  116. $result = $objQuery->count("dtb_customer", "mobile_phone_id = ? AND del_flg = 0 AND status = 2", array($_SESSION['mobile']['phone_id']));
  117. return $result > 0;
  118. }
  119. /**
  120. * ????ID????????????????????????
  121. * ????????????????????????
  122. *
  123. * @param string $pass ?????
  124. * @return boolean ????????????????????????? true?
  125. * ???????? false ????
  126. */
  127. function getCustomerDataFromMobilePhoneIdPass($pass) {
  128. //docomo???????????
  129. if(SC_MobileUserAgent_Ex::getCarrier() == 'docomo'){
  130. if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0)
  131. $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent_Ex::getId();
  132. }
  133. if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
  134. return false;
  135. }
  136. // ????ID???????????????????
  137. $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
  138. $objQuery = new SC_Query_Ex();
  139. @list($data) = $objQuery->getAll($sql, array($_SESSION['mobile']['phone_id']));
  140. // ????????????????????customer_data?????true????
  141. if ( SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt']) ) {
  142. $this->customer_data = $data;
  143. $this->startSession();
  144. return true;
  145. }
  146. return false;
  147. }
  148. /**
  149. * ????ID??????
  150. *
  151. * @return void
  152. */
  153. function updateMobilePhoneId() {
  154. if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
  155. return;
  156. }
  157. if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) {
  158. return;
  159. }
  160. $objQuery = new SC_Query_Ex();
  161. $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']);
  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. $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id'];
  165. }
  166. // ???????????????
  167. function setLogin($email) {
  168. // ??????????
  169. $sql = "SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2";
  170. $objQuery = new SC_Query_Ex();
  171. $result = $objQuery->getAll($sql, array($email, $email));
  172. $data = isset($result[0]) ? $result[0] : "";
  173. $this->customer_data = $data;
  174. $this->startSession();
  175. }
  176. // ??????????????????
  177. function updateSession() {
  178. $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
  179. $customer_id = $this->getValue('customer_id');
  180. $objQuery = new SC_Query_Ex();
  181. $arrRet = $objQuery->getAll($sql, array($customer_id));
  182. $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : "";
  183. $_SESSION['customer'] = $this->customer_data;
  184. }
  185. // ????????????????????????
  186. function startSession() {
  187. $_SESSION['customer'] = $this->customer_data;
  188. // ??????????
  189. GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_REALFILE );
  190. }
  191. // ??????$_SESSION['customer']????????????
  192. function EndSession() {
  193. // $_SESSION['customer']???
  194. unset($_SESSION['customer']);
  195. // ???????????????
  196. SC_Helper_Session_Ex::destroyToken();
  197. $objSiteSess = new SC_SiteSession_Ex();
  198. $objSiteSess->unsetUniqId();
  199. // ???????
  200. GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_REALFILE );
  201. }
  202. // ?????????????????
  203. function isLoginSuccess($dont_check_email_mobile = false) {
  204. // ??????????????DB?????????????????
  205. if(isset($_SESSION['customer']['customer_id'])
  206. && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) {
  207. $objQuery = new SC_Query_Ex();
  208. $email = $objQuery->get('email', "dtb_customer", "customer_id = ?", array($_SESSION['customer']['customer_id']));
  209. if($email == $_SESSION['customer']['email']) {
  210. // ???????????????????????????????????????
  211. // ??? $dont_check_email_mobile ? true ????????????
  212. if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE && !$dont_check_email_mobile) {
  213. $email_mobile = $objQuery->get("email_mobile", "dtb_customer", "customer_id = ?", array($_SESSION['customer']['customer_id']));
  214. return isset($email_mobile);
  215. }
  216. return true;
  217. }
  218. }
  219. return false;
  220. }
  221. // ?????????
  222. function getValue($keyname) {
  223. // ?????????????
  224. if ($keyname == 'point') {
  225. $objQuery =& SC_Query_Ex::getSingletonInstance();
  226. $point = $objQuery->get('point', 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
  227. $_SESSION['customer']['point'] = $point;
  228. return $point;
  229. } else {
  230. return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : "";
  231. }
  232. }
  233. // ??????????
  234. function setValue($keyname, $val) {
  235. $_SESSION['customer'][$keyname] = $val;
  236. }
  237. // ???????NULL???????
  238. function hasValue($keyname) {
  239. if (isset($_SESSION['customer'][$keyname])) {
  240. return !SC_Utils_Ex::isBlank($_SESSION['customer'][$keyname]);
  241. }
  242. return false;
  243. }
  244. // ??????????????
  245. function isBirthMonth() {
  246. if (isset($_SESSION['customer']['birth'])) {
  247. $arrRet = preg_split("|[- :/]|", $_SESSION['customer']['birth']);
  248. $birth_month = intval($arrRet[1]);
  249. $now_month = intval(date('m'));
  250. if($birth_month == $now_month) {
  251. return true;
  252. }
  253. }
  254. return false;
  255. }
  256. /**
  257. * $_SERVER['REMOTE_HOST'] ??? $_SERVER['REMOTE_ADDR'] ???.
  258. *
  259. * $_SERVER['REMOTE_HOST'] ?????????? $_SERVER['REMOTE_ADDR']
  260. * ???.
  261. *
  262. * @return string $_SERVER['REMOTE_HOST'] ?? $_SERVER['REMOTE_ADDR']????
  263. */
  264. function getRemoteHost() {
  265. if (!empty($_SERVER['REMOTE_HOST'])) {
  266. return $_SERVER['REMOTE_HOST'];
  267. } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
  268. return $_SERVER['REMOTE_ADDR'];
  269. } else {
  270. return "";
  271. }
  272. }
  273. //????????????
  274. function updateOrderSummary($customer_id){
  275. $objQuery = new SC_Query_Ex();
  276. $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));
  277. $objQuery->update("dtb_customer",$arrOrderSummary,"customer_id = ?",array($customer_id));
  278. }
  279. }
  280. ?>