| 1 | <?php |
|---|
| 2 | /* [̾¾Î] SC_Customer |
|---|
| 3 | * [³µÍ×] ²ñ°÷´ÉÍý¥¯¥é¥¹ |
|---|
| 4 | */ |
|---|
| 5 | class SC_Customer { |
|---|
| 6 | |
|---|
| 7 | var $conn; |
|---|
| 8 | var $email; |
|---|
| 9 | var $customer_data; // ²ñ°÷¾ðÊó |
|---|
| 10 | |
|---|
| 11 | function SC_Customer( $conn = '', $email = '', $pass = '' ) { |
|---|
| 12 | // ¥»¥Ã¥·¥ç¥ó³«»Ï |
|---|
| 13 | /* startSession¤«¤é°Üư 2005/11/04 ÃæÀî */ |
|---|
| 14 | sfDomainSessionStart(); |
|---|
| 15 | |
|---|
| 16 | // DBÀܳ¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À® |
|---|
| 17 | $DB_class_name = "SC_DbConn"; |
|---|
| 18 | if ( is_object($conn)){ |
|---|
| 19 | if ( is_a($conn, $DB_class_name)){ |
|---|
| 20 | // $conn¤¬$DB_class_name¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤Ç¤¢¤ë |
|---|
| 21 | $this->conn = $conn; |
|---|
| 22 | } |
|---|
| 23 | } else { |
|---|
| 24 | if (class_exists($DB_class_name)){ |
|---|
| 25 | //$DB_class_name¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¤¹¤ë |
|---|
| 26 | $this->conn = new SC_DbConn(); |
|---|
| 27 | } |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | if ( is_object($this->conn) ) { |
|---|
| 31 | // Àµ¾ï¤ËDB¤ËÀܳ¤Ç¤¤ë |
|---|
| 32 | if ( $email ){ |
|---|
| 33 | // email¤«¤é¸ÜµÒ¾ðÊó¤ò¼èÆÀ¤¹¤ë |
|---|
| 34 | // $this->setCustomerDataFromEmail( $email ); |
|---|
| 35 | } |
|---|
| 36 | } else { |
|---|
| 37 | echo "DBÀܳ¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¤¤¤Þ¤¹"; |
|---|
| 38 | exit; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | if ( strlen($email) > 0 && strlen($pass) > 0 ){ |
|---|
| 42 | $this->getCustomerDataFromEmailPass( $email, $pass ); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | function getCustomerDataFromEmailPass( $pass, $email ) { |
|---|
| 47 | // ËÜÅÐÏ¿¤µ¤ì¤¿²ñ°÷¤Î¤ß |
|---|
| 48 | $sql = "SELECT * FROM dtb_customer WHERE email ILIKE ? AND delete = 0 AND status = 2"; |
|---|
| 49 | $result = $this->conn->getAll($sql, array($email)); |
|---|
| 50 | $data = $result[0]; |
|---|
| 51 | |
|---|
| 52 | // ¥Ñ¥¹¥ï¡¼¥É¤¬¹ç¤Ã¤Æ¤¤¤ì¤Ð¸ÜµÒ¾ðÊó¤òcustomer_data¤Ë¥»¥Ã¥È¤·¤Ætrue¤òÊÖ¤¹ |
|---|
| 53 | if ( crypt($pass,$data['password'] ) == $data['password'] ){ |
|---|
| 54 | $this->customer_data = $data; |
|---|
| 55 | $this->startSession(); |
|---|
| 56 | return true; |
|---|
| 57 | } |
|---|
| 58 | return false; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | // ¥Ñ¥¹¥ï¡¼¥É¤ò³Îǧ¤»¤º¤Ë¥í¥°¥¤¥ó |
|---|
| 62 | function setLogin($email) { |
|---|
| 63 | // ËÜÅÐÏ¿¤µ¤ì¤¿²ñ°÷¤Î¤ß |
|---|
| 64 | $sql = "SELECT * FROM dtb_customer WHERE email ILIKE ? AND delete = 0 AND status = 2"; |
|---|
| 65 | $result = $this->conn->getAll($sql, array($email)); |
|---|
| 66 | $data = $result[0]; |
|---|
| 67 | $this->customer_data = $data; |
|---|
| 68 | $this->startSession(); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | // ¥»¥Ã¥·¥ç¥ó¾ðÊó¤òºÇ¿·¤Î¾ðÊó¤Ë¹¹¿·¤¹¤ë |
|---|
| 72 | function updateSession() { |
|---|
| 73 | $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND delete = 0"; |
|---|
| 74 | $customer_id = $this->getValue('customer_id'); |
|---|
| 75 | $arrRet = $this->conn->getAll($sql, array($customer_id)); |
|---|
| 76 | $this->customer_data = $arrRet[0]; |
|---|
| 77 | $_SESSION['customer'] = $this->customer_data; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | // ¥í¥°¥¤¥ó¾ðÊó¤ò¥»¥Ã¥·¥ç¥ó¤ËÅÐÏ¿¤·¡¢¥í¥°¤Ë½ñ¤¹þ¤à |
|---|
| 81 | function startSession() { |
|---|
| 82 | sfDomainSessionStart(); |
|---|
| 83 | $_SESSION['customer'] = $this->customer_data; |
|---|
| 84 | // ¥»¥Ã¥·¥ç¥ó¾ðÊó¤ÎÊݸ |
|---|
| 85 | gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $_SERVER['REMOTE_HOST'], CUSTOMER_LOG_PATH ); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | // ¥í¥°¥¢¥¦¥È¡¡$_SESSION['customer']¤ò²òÊü¤·¡¢¥í¥°¤Ë½ñ¤¹þ¤à |
|---|
| 89 | function EndSession() { |
|---|
| 90 | // $_SESSION['customer']¤Î²òÊü |
|---|
| 91 | unset($_SESSION['customer']); |
|---|
| 92 | // ¥í¥°¤ËµÏ¿¤¹¤ë |
|---|
| 93 | gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $_SERVER['REMOTE_HOST'], CUSTOMER_LOG_PATH ); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | // ¥í¥°¥¤¥ó¤ËÀ®¸ù¤·¤Æ¤¤¤ë¤«È½Äꤹ¤ë¡£ |
|---|
| 97 | function isLoginSuccess() { |
|---|
| 98 | // ¥í¥°¥¤¥ó»þ¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤ÈDB¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤¬°ìÃפ·¤Æ¤¤¤ë¾ì¹ç |
|---|
| 99 | if(sfIsInt($_SESSION['customer']['customer_id'])) { |
|---|
| 100 | $objQuery = new SC_Query(); |
|---|
| 101 | $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
|---|
| 102 | if($email == $_SESSION['customer']['email']) { |
|---|
| 103 | return true; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | return false; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | // ¥Ñ¥é¥á¡¼¥¿¤Î¼èÆÀ |
|---|
| 110 | function getValue($keyname) { |
|---|
| 111 | return $_SESSION['customer'][$keyname]; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | // ¥Ñ¥é¥á¡¼¥¿¤Î¥»¥Ã¥È |
|---|
| 115 | function setValue($keyname, $val) { |
|---|
| 116 | $_SESSION['customer'][$keyname] = $val; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | // ÃÂÀ¸Æü·î¤Ç¤¢¤ë¤«¤É¤¦¤«¤ÎȽÄê |
|---|
| 120 | function isBirthMonth() { |
|---|
| 121 | $arrRet = split("[- :/]", $_SESSION['customer']['birth']); |
|---|
| 122 | $birth_month = intval($arrRet[1]); |
|---|
| 123 | $now_month = intval(date("m")); |
|---|
| 124 | |
|---|
| 125 | if($birth_month == $now_month) { |
|---|
| 126 | return true; |
|---|
| 127 | } |
|---|
| 128 | return false; |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | ?> |
|---|