/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.servlet.mobile.imode;

import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jp.co.sint.basic.SICust;
import jp.co.sint.basic.SIMailTemp;
import jp.co.sint.basic.SIMaker;
import jp.co.sint.basic.SIMallShop;
import jp.co.sint.basic.SIPointMan;
import jp.co.sint.basic.SIUserInfo;
import jp.co.sint.basic.SIReserveCartManager;
import jp.co.sint.beans.front.UIRemainder;
import jp.co.sint.beans.front.UIUserEdit;
import jp.co.sint.beans.front.UIUserLogin;
import jp.co.sint.beans.mallmgr.UIRegCatalogCust;
import jp.co.sint.beans.mallmgr.UIRegCust;
import jp.co.sint.beans.mobile.imode.UIIBuyDetail;
import jp.co.sint.beans.mobile.imode.UIIBuyHist;
import jp.co.sint.beans.mobile.imode.UIICustAddress;
import jp.co.sint.beans.mobile.imode.UIIDeliveryList;
import jp.co.sint.beans.mobile.imode.UIIUserEdit;
import jp.co.sint.config.SIConfig;
import jp.co.sint.database.SIDBAccessException;
import jp.co.sint.database.SIDBUtil;
import jp.co.sint.database.SIDatabaseConnection;
import jp.co.sint.database.SIDuplicateKeyException;
import jp.co.sint.database.SIInsertRec;
import jp.co.sint.database.SIModifyRec; // 7.3.0 ST2025 追加
import jp.co.sint.mail.SIMail;
import jp.co.sint.mail.SISendMail; // 7.3.0 ST2026 追加
import jp.co.sint.servlet.SIServlet;
import jp.co.sint.servlet.front.SIAddrSrv;
import jp.co.sint.servlet.front.SICustomerSrv;
import jp.co.sint.servlet.front.SIOrderHistorySrv;
import jp.co.sint.servlet.mallmgr.SIRegCustSrv;
import jp.co.sint.tools.SICheckDataConf;
import jp.co.sint.tools.SICheckValid;
import jp.co.sint.tools.SICustomError;
import jp.co.sint.tools.SICustomErrors;
import jp.co.sint.tools.SIDateTime; // 7.3.0 ST2026 追加
import jp.co.sint.tools.SIErrorException;
import jp.co.sint.tools.SIErrorFactory;
import jp.co.sint.tools.SIFatalException; // 7.3.0 ST2026 追加
import jp.co.sint.tools.SIHTMLUtil;
import jp.co.sint.tools.SIURLMap;
import jp.co.sint.tools.SIUtil;

import org.apache.log4j.Category;
import jp.co.sint.tools.SIURLParameter;

// 7.1.1 ST0236 追加

/**
 * @version $Id: SIICustomerSrv.java,v 1.0 2003/12/25 Exp $
 * @author Jinwang Chen <br>
 * Description:
 * <p>
 * History
 * </p>
 * <p>
 * Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reason
 * </p>
 * ============&nbsp;&nbsp;&nbsp;==========&nbsp;&nbsp;===========================<br>
 * Jinwang Chen 2003/12/25 18:50:04 Original
 */
public class SIICustomerSrv extends SIServlet {
  // ログ用のインスタンスの生成
  private static Category log = Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  // 7.3.0 ST2026 追加 ここから
  // 顧客データ更新区分（1:追加 / 2:更新)
  private static final String LC_ADD = "1";
  private static final String LC_UPD = "2";
  
  // 7.3.0 ST2026 追加 ここまで
  
  /**
   * <b>doUpdate</b> HTTP リクエストの処理
   * 
   * @param request リクエスト
   * @param response
   * @return なし
   * @throws ServletException
   * @throws IOException
   */
  public void doUpdate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession(true);// セッションの取得
    SIDatabaseConnection databaseConnection = new SIDatabaseConnection();// DBへのコネクションの作成
    SIURLParameter urlParam = new SIURLParameter(request);// 7.1.1 ST0236 追加
    String strLoginDateTime = null; // 前回ログイン日時 退避用 //7.3.0 ST2029 追加
    SIUserInfo siUserInfo = null; // 7.3.0 ST2025 追加
    try {
      Connection dbConn = databaseConnection.getConnection();
      
      String actionName = this.getActionName(urlParam);// 画面からのアクション //7.1.1 ST0236 修正
      String editMode = this.getEditMode(urlParam);// DBへの編集モード //7.1.1 ST0236 修正
      
      if (this.getServletPath(request).equals("/mobile/i/cust")) {// ユーザー情報登録
        UIIUserEdit userEdit = new UIIUserEdit();
        
        if (SIUtil.isNull(actionName)) {// 初めて
          SIUserInfo lUserInfo = SIHTMLUtil.getUserInfo(request);
          if (lUserInfo.isNotLogin(request)) {// ログインしなければ、ログインへ
            String lUrl = SIURLMap.getUrl("webshop.servlet.front.imode.login") + "?nid=" + SIHTMLUtil.URLEncode(SIURLMap.getUrl("webshop.servlet.front.imode.customer"));
            redirectHttps(request, response, lUrl);
          } else {
            userEdit.setRegCust(lUserInfo.getCustCode());
            userEdit.reset(dbConn);
            userEdit.setEditModeTxt(SIConfig.SIEDIT_MODE_UPDATE);
            userEdit.setNextUrlTxt((String) urlParam.getParam("nid"));// 7.1.1 ST0236 修正
            session.setAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME, userEdit);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit1");
          }
        } else if (SIConfig.SIACTION_LOGIN.equals(actionName)) {// ログイン画面から新規登録
          // add by mikami
          session.removeAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME);
          forwardKey(request, response, "webshop.jsp.front.imode.member.main");
        } else if (SIConfig.SIACTION_CONFIRM.equals(actionName)) {// 確認画面:編集画面1の確認と編集画面2の確認
          userEdit = (UIIUserEdit) session.getAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME);
          if (userEdit == null) userEdit = new UIIUserEdit();
          userEdit.init(request, urlParam);// 7.1.1 ST0236 修正
          session.setAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME, userEdit);
          boolean lResult = userEdit.validate(request, dbConn);
          if (lResult && SIUtil.isNull(userEdit.getScrID())) {
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit2");
          } else if (lResult && SIUtil.isNotNull(userEdit.getScrID())) {
            forwardKey(request, response, "webshop.jsp.front.imode.customer.confirm");
          } else if (!lResult && SIUtil.isNull(userEdit.getScrID())) {
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit1");
          } else if (!lResult && SIUtil.isNotNull(userEdit.getScrID())) {
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit2");
          }
        } else if (SIConfig.SIACTION_REMODIFY.equals(actionName)) {// 再修正へ
          if (SIUtil.isNull((String) urlParam.getParam("scrID"))) {// 7.1.1 ST0236 修正
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit1");
          } else {
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit2");
          }
        } else if (SIConfig.SIACTION_REGIST.equals(actionName)) {// DBへの登録
          userEdit = (UIIUserEdit) session.getAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME);
          try {
            UIRegCust regCust = userEdit.getRegCust();
            if (userEdit.getEditModeTxt().equalsIgnoreCase(SIConfig.SIEDIT_MODE_UPDATE)) {// 更新
              SIRegCustSrv.custHobbyTableData(dbConn, regCust, SIConfig.SIEDIT_MODE_UPDATE);
              SIRegCustSrv.updateTableData(dbConn, regCust, request, null);// 7.3.0 ST2023 修正 引数追加
              this.writeCookie(response, regCust.getEmail(), regCust.getPassword());
              request.setAttribute(SIConfig.SIMESSAGE_ATTRIBUTE_RESULT_NAME, SIErrorFactory.getErrorMsg("manager.message.success.modify"));
              sendUserRegistMail(dbConn, regCust, LC_UPD); // 7.3.0 ST2026 追加
            } else if (userEdit.getEditModeTxt().equalsIgnoreCase(SIConfig.SIEDIT_MODE_INSERT)) {// 新規
              if (SIDBUtil.hasData(dbConn, "SELECT email FROM custtbl WHERE email=" + SIDBUtil.SQL2Str(regCust.getEmail()))) {
                throw new SIDuplicateKeyException();
              }
              regCust.setCustCode(SIDBUtil.getFirstData(dbConn, SIDBUtil.getNextVal("CUSTTBL_CUSTCD_SEQ")));
              SIRegCustSrv.custHobbyTableData(dbConn, regCust, SIConfig.SIEDIT_MODE_INSERT);
              SIRegCustSrv.insertTableData(dbConn, regCust, request, null);// 7.3.0 ST2029 修正 パラメータ追加 //7.3.0 ST2023 修正 引数追加
              request.setAttribute(SIConfig.SIMESSAGE_ATTRIBUTE_RESULT_NAME, SIErrorFactory.getErrorMsg("manager.message.success.insert"));
              sendUserRegistMail(dbConn, regCust, LC_ADD); // 7.3.0 ST2026 追加
            }
            // 会員アドレス帳の登録
            SICustomerSrv.updateCustAddressTableData(dbConn, regCust);
            SIUserInfo userLogin = new SIUserInfo();
            userLogin.setCustCode(regCust.getCustCode());
            // 7.3.0 ST2029 追加 ここから
            // セッションから前回最終ログイン日付を退避
            SIUserInfo backUserInfo = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            strLoginDateTime = new String();
            if (backUserInfo != null) {// 登録後初回ログイン時はセッション=null
              strLoginDateTime = backUserInfo.getLoginDateTime();
            }
            if (userEdit.getEditModeTxt().equalsIgnoreCase(SIConfig.SIEDIT_MODE_INSERT)) {
              strLoginDateTime = "";
            }
            // 7.3.0 ST2029 追加 ここまで
            userLogin.reset(dbConn);
            userLogin.setLoginDateTime(strLoginDateTime);// 退避した前回最終ログイン日付をセット //7.3.0 ST2029 追加
            session.setAttribute(SIConfig.SISESSION_USERINFO_NAME, userLogin);
            if (userEdit.getEditModeTxt().equalsIgnoreCase(SIConfig.SIEDIT_MODE_INSERT)&&SIUtil.isNotNull(regCust.getCatalogRequest())) {
              UIRegCatalogCust lUser = new UIRegCatalogCust();
              lUser.setCustName(regCust.getCustName());
              lUser.setCustPronName(regCust.getCustPronName());
              lUser.setPostCode1(regCust.getPostCode1());
              lUser.setPostCode2(regCust.getPostCode2());
              lUser.setAddress1(regCust.getAddress1());
              lUser.setAddress2(regCust.getAddress2());
              lUser.setAddress3(regCust.getAddress3());
              lUser.setCompanyName(regCust.getCompanyName());
              lUser.setCorporationName(regCust.getCorporationName());
              lUser.setStoreTel(regCust.getStoreTel());
              lUser.setFax(regCust.getFax());
              lUser.setEmail(regCust.getEmail());
              lUser.setJob(regCust.getJob());
              lUser.setCatalogRequest(regCust.getCatalogRequest());
              SICustomerSrv.sendCatalogMail(lUser,true);
            }
            try {
              dbConn.commit();
            } catch (SQLException ee) {}
            session.removeAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME);
            if (SIUtil.isNotNull(userEdit.getNextUrlTxt())) {
              redirectHttps(request, response, userEdit.getNextUrlTxt());
            } else {
              request.setAttribute("mode", userEdit.getEditModeTxt());
              request.setAttribute("sso", userEdit.getSsouserId());
              forwardKey(request, response, "webshop.jsp.front.imode.customer.result");
            }
          } catch (SIDuplicateKeyException e) {
            try {
              dbConn.rollback();
            } catch (SQLException ee) {}
            e.printStackTrace();
            log.debug(e.toString());
            SICustomErrors errors = new SICustomErrors();
            errors.addError(new SICustomError("database.insert.duplicate"));
            request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit1");
          } catch (SIDBAccessException e) {
            try {
              dbConn.rollback();
            } catch (SQLException ee) {}
            e.printStackTrace();
            log.debug(e.toString());
            SICustomErrors errors = new SICustomErrors();
            errors.addError(new SICustomError("database.execute.error"));
            request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit1");
          } catch (NullPointerException e) {
            e.printStackTrace();
            log.debug(e.toString());
            SICustomErrors errors = new SICustomErrors();
            errors.addError(new SICustomError("database.insert.duplicate"));
            request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.edit1");
          }
          // 7.3.0 ST2024 追加 ここから
        } else if (SIConfig.SIACTION_POLICY.equals(actionName)) { // 個人情報利用目的
          userEdit = (UIIUserEdit) session.getAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME);
          forwardKey(request, response, "webshop.jsp.front.imode.privacy.policy");
          session.setAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME, userEdit);
          // 7.3.0 ST2024 追加 ここまで
        }
      } else if (this.getServletPath(request).equals("/mobile/i/login")) {// ユーザーログイン
        UIUserLogin userLogin = new UIUserLogin();
        userLogin.init(request, urlParam);// 7.1.1 ST0236 修正
        if (actionName.equalsIgnoreCase(SIConfig.SIACTION_LOGIN)) {
          // if (SIUtil.isNull(userLogin.getEmailTxt())&&SIUtil.isNull(userLogin.getPasswordTxt())&&!"req".equals((String)urlParam.getParam("Mode"))){//両方が入力しなければ、7.3.0 ST2025 修正
          // forwardKey(request,response,"webshop.servlet.front.imode.customer");
          // }else if (userLogin.validate(request, response, dbConn)){//認証OK //7.2.0 ST0329 パラメータ追加
          if (userLogin.validate(request, response, dbConn)) {// 認証OK
            userLogin.updLoginDateTime(dbConn);// DB更新(最終ログイン日時) //7.3.0 ST2029 追加
            userLogin.initMobileUid(dbConn);// UID登録
            session = request.getSession(true);// 7.2.0 ST0329 追加
            // ポイント期限のチェックと更新
            SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            SIPointMan.clear(dbConn, lUserLogin.getCustCode());
            SIReserveCartManager.refresh(request, dbConn);
            this.writeCookie(response, userLogin.getEmailTxt(), userLogin.getPasswordTxt());
            session.removeAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME);
            if (SIUtil.isNotNull(userLogin.getNextUrlTxt())) {// 決済へ行く前に、カートの情報を設定
              if (userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtylist") || userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtydetail")) {
                String url = userLogin.getNextUrlTxt();
                url = url.replaceAll("/ctc=", "?ctc=");
                url = url.replaceAll("/shc=", "&shc=");
                url = url.replaceAll("/cmc=", "&cmc=");
                url = url.replaceAll("/inc=", "&inc=");
                // EDBTG003-00 nagayoshi add start
                url = url.replaceAll("/cmpt=", "&cmpt=");
                // EDBTG003-00 nagayoshi add end
                url = url.replaceAll("/a=", "&a=");
                url = url.replaceAll("/pageNumberTxt=", "&pageNumberTxt=");
                userLogin.setNextUrlTxt(url);
              }
              redirectHttps(request, response, userLogin.getNextUrlTxt());
            } else {
              // 8.1.6 ST2380 修正 ここから
              forwardKey(request, response, "webshop.jsp.front.imode.main");
              // redirectKey(request,response,"webshop.jsp.front.imode.main");
              // 8.1.6 ST2380 修正 ここまで
            }
          } else if (userLogin.isPreUser(dbConn)){
            // add by mikami
            UIIUserEdit userEdit = new UIIUserEdit();
            //userEdit.init(request, urlParam);
            userEdit.setSsouserId(userLogin.getSsouserId());
            userEdit.getRegCust().setPreCustInfo(dbConn, userLogin.getSsouserId());
            session.setAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME, userEdit);

            StringBuffer lUrlBuf = new StringBuffer(SIURLMap.getUrl("webshop.servlet.front.imode.member"));
            //lUrlBuf.append("?actionNameTxt=").append("policy");
            redirectHttps(request, response, lUrlBuf.toString());
          } else {
            session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
            forwardKey(request, response, "webshop.jsp.front.imode.login");
          }
        } else if (actionName.equalsIgnoreCase(SIConfig.SIACTION_LOGIN2)) {
          userLogin.initEasyLogin(request, urlParam, dbConn);
          if (userLogin.validate(request, response, dbConn, true)) {// 認証OK
            userLogin.updLoginDateTime(dbConn);// DB更新(最終ログイン日時)
            session = request.getSession(true);
            // ポイント期限のチェックと更新
            SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            SIPointMan.clear(dbConn, lUserLogin.getCustCode());
            SIReserveCartManager.refresh(request, dbConn);
            session.removeAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME);
            if (SIUtil.isNotNull(userLogin.getNextUrlTxt())) {// 決済へ行く前に、カートの情報を設定
              if (userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtylist") || userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtydetail")) {
                String url = userLogin.getNextUrlTxt();
                url = url.replaceAll("/ctc=", "?ctc=");
                url = url.replaceAll("/shc=", "&shc=");
                url = url.replaceAll("/cmc=", "&cmc=");
                url = url.replaceAll("/inc=", "&inc=");
                // EDBTG003-00 nagayoshi add start
                url = url.replaceAll("/cmpt=", "&cmpt=");
                // EDBTG003-00 nagayoshi add end
                url = url.replaceAll("/a=", "&a=");
                url = url.replaceAll("/pageNumberTxt=", "&pageNumberTxt=");
                userLogin.setNextUrlTxt(url);
              }
              redirectHttps(request, response, userLogin.getNextUrlTxt());
            } else {
              forwardKey(request, response, "webshop.jsp.front.imode.main");
            }
          } else {
            session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
            forwardKey(request, response, "webshop.jsp.front.imode.login");
          }
        } else {// 初期化
          session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
          forwardKey(request, response, "webshop.jsp.front.imode.login");
        }
        
      } else if (this.getServletPath(request).equals("/mobile/i/login2")) {// ユーザーログイン
        UIUserLogin userLogin = new UIUserLogin();
        userLogin.init(request, urlParam);
        if (actionName.equalsIgnoreCase(SIConfig.SIACTION_LOGIN)) {
          if (userLogin.validate(request, response, dbConn)) {// 認証OK
            userLogin.updLoginDateTime(dbConn);// DB更新(最終ログイン日時)
            userLogin.initMobileUid(dbConn);// UID登録
            session = request.getSession(true);
            // ポイント期限のチェックと更新
            SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            SIPointMan.clear(dbConn, lUserLogin.getCustCode());
            SIReserveCartManager.refresh(request, dbConn);
            this.writeCookie(response, userLogin.getEmailTxt(), userLogin.getPasswordTxt());
            session.removeAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME);
            if (SIUtil.isNotNull(userLogin.getNextUrlTxt())) {// 決済へ行く前に、カートの情報を設定
              if (userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtylist") || userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtydetail")) {
                String url = userLogin.getNextUrlTxt();
                url = url.replaceAll("/ctc=", "?ctc=");
                url = url.replaceAll("/shc=", "&shc=");
                url = url.replaceAll("/cmc=", "&cmc=");
                url = url.replaceAll("/inc=", "&inc=");
                // EDBTG003-00 nagayoshi add start
                url = url.replaceAll("/cmpt=", "&cmpt=");
                // EDBTG003-00 nagayoshi add end
                url = url.replaceAll("/a=", "&a=");
                url = url.replaceAll("/pageNumberTxt=", "&pageNumberTxt=");
                userLogin.setNextUrlTxt(url);
              }
              redirectHttps(request, response, userLogin.getNextUrlTxt());
            } else {
              forwardKey(request, response, "webshop.jsp.front.imode.main");
            }
          } else {
            session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
            forwardKey(request, response, "webshop.jsp.front.imode.login2");
          }
        } else if (actionName.equalsIgnoreCase(SIConfig.SIACTION_LOGIN2)) {
          userLogin.initEasyLogin(request, urlParam, dbConn);
          if (userLogin.validate(request, response, dbConn, true)) {// 認証OK
            userLogin.updLoginDateTime(dbConn);// DB更新(最終ログイン日時)
            session = request.getSession(true);
            // ポイント期限のチェックと更新
            SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            SIPointMan.clear(dbConn, lUserLogin.getCustCode());
            SIReserveCartManager.refresh(request, dbConn);
            session.removeAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME);
            if (SIUtil.isNotNull(userLogin.getNextUrlTxt())) {// 決済へ行く前に、カートの情報を設定
              if (userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtylist") || userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtydetail")) {
                String url = userLogin.getNextUrlTxt();
                url = url.replaceAll("/ctc=", "?ctc=");
                url = url.replaceAll("/shc=", "&shc=");
                url = url.replaceAll("/cmc=", "&cmc=");
                url = url.replaceAll("/inc=", "&inc=");
                // EDBTG003-00 nagayoshi add start
                url = url.replaceAll("/cmpt=", "&cmpt=");
                // EDBTG003-00 nagayoshi add end
                url = url.replaceAll("/a=", "&a=");
                url = url.replaceAll("/pageNumberTxt=", "&pageNumberTxt=");
                userLogin.setNextUrlTxt(url);
              }
              redirectHttps(request, response, userLogin.getNextUrlTxt());
            } else {
              forwardKey(request, response, "webshop.jsp.front.imode.main");
            }
          } else {
            session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
            forwardKey(request, response, "webshop.jsp.front.imode.login2");
          }
        } else {// 初期化
          session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
          forwardKey(request, response, "webshop.jsp.front.imode.login2");
        }
        
      } else if (this.getServletPath(request).equals("/mobile/i/login3")) {// ユーザーログイン
        UIUserLogin userLogin = new UIUserLogin();
        userLogin.init(request, urlParam);
        if (actionName.equalsIgnoreCase(SIConfig.SIACTION_LOGIN)) {
          if (userLogin.validate(request, response, dbConn)) {// 認証OK
            userLogin.updLoginDateTime(dbConn);// DB更新(最終ログイン日時)
            userLogin.initMobileUid(dbConn);// UID登録
            session = request.getSession(true);
            // ポイント期限のチェックと更新
            SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            SIPointMan.clear(dbConn, lUserLogin.getCustCode());
            SIReserveCartManager.refresh(request, dbConn);
            this.writeCookie(response, userLogin.getEmailTxt(), userLogin.getPasswordTxt());
            session.removeAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME);
            if (SIUtil.isNotNull(userLogin.getNextUrlTxt())) {// 決済へ行く前に、カートの情報を設定
              if (userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtylist") || userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtydetail")) {
                String url = userLogin.getNextUrlTxt();
                url = url.replaceAll("/ctc=", "?ctc=");
                url = url.replaceAll("/shc=", "&shc=");
                url = url.replaceAll("/cmc=", "&cmc=");
                url = url.replaceAll("/inc=", "&inc=");
                // EDBTG003-00 nagayoshi add start
                url = url.replaceAll("/cmpt=", "&cmpt=");
                // EDBTG003-00 nagayoshi add end
                url = url.replaceAll("/a=", "&a=");
                url = url.replaceAll("/pageNumberTxt=", "&pageNumberTxt=");
                userLogin.setNextUrlTxt(url);
              }
              redirectHttps(request, response, userLogin.getNextUrlTxt());
            } else {
              forwardKey(request, response, "webshop.jsp.front.imode.main");
            }
          } else {
            session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
            forwardKey(request, response, "webshop.jsp.front.imode.login3");
          }
        } else if (actionName.equalsIgnoreCase(SIConfig.SIACTION_LOGIN2)) {
          userLogin.initEasyLogin(request, urlParam, dbConn);
          if (userLogin.validate(request, response, dbConn)) {// 認証OK
            userLogin.updLoginDateTime(dbConn);// DB更新(最終ログイン日時)
            userLogin.initMobileUid(dbConn);// UID登録
            session = request.getSession(true);
            // ポイント期限のチェックと更新
            SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            SIPointMan.clear(dbConn, lUserLogin.getCustCode());
            SIReserveCartManager.refresh(request, dbConn);
            session.removeAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME);
            if (SIUtil.isNotNull(userLogin.getNextUrlTxt())) {// 決済へ行く前に、カートの情報を設定
              if (userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtylist") || userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtydetail")) {
                String url = userLogin.getNextUrlTxt();
                url = url.replaceAll("/ctc=", "?ctc=");
                url = url.replaceAll("/shc=", "&shc=");
                url = url.replaceAll("/cmc=", "&cmc=");
                url = url.replaceAll("/inc=", "&inc=");
                // EDBTG003-00 nagayoshi add start
                url = url.replaceAll("/cmpt=", "&cmpt=");
                // EDBTG003-00 nagayoshi add end
                url = url.replaceAll("/a=", "&a=");
                url = url.replaceAll("/pageNumberTxt=", "&pageNumberTxt=");
                userLogin.setNextUrlTxt(url);
              }
              redirectHttps(request, response, userLogin.getNextUrlTxt());
            } else {
              forwardKey(request, response, "webshop.jsp.front.imode.main");
            }
          } else {
            session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
            forwardKey(request, response, "webshop.jsp.front.imode.login3");
          }
        } else {// 初期化
          session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
          forwardKey(request, response, "webshop.jsp.front.imode.login3");
        }
        
      } else if (this.getServletPath(request).equals("/mobile/i/login4")) {// ユーザーログイン
        UIUserLogin userLogin = new UIUserLogin();
        userLogin.init(request, urlParam);
        if (actionName.equalsIgnoreCase(SIConfig.SIACTION_LOGIN)) {
          if (userLogin.validate(request, response, dbConn)) {// 認証OK
            userLogin.updLoginDateTime(dbConn);// DB更新(最終ログイン日時)
            userLogin.initMobileUid(dbConn);// UID登録
            session = request.getSession(true);
            // ポイント期限のチェックと更新
            SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            SIPointMan.clear(dbConn, lUserLogin.getCustCode());
            SIReserveCartManager.refresh(request, dbConn);
            this.writeCookie(response, userLogin.getEmailTxt(), userLogin.getPasswordTxt());
            session.removeAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME);
            if (SIUtil.isNotNull(userLogin.getNextUrlTxt())) {// 決済へ行く前に、カートの情報を設定
              if (userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtylist") || userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtydetail")) {
                String url = userLogin.getNextUrlTxt();
                url = url.replaceAll("/ctc=", "?ctc=");
                url = url.replaceAll("/shc=", "&shc=");
                url = url.replaceAll("/cmc=", "&cmc=");
                url = url.replaceAll("/inc=", "&inc=");
                // EDBTG003-00 nagayoshi add start
                url = url.replaceAll("/cmpt=", "&cmpt=");
                // EDBTG003-00 nagayoshi add end
                url = url.replaceAll("/a=", "&a=");
                url = url.replaceAll("/pageNumberTxt=", "&pageNumberTxt=");
                userLogin.setNextUrlTxt(url);
              }
              redirectHttps(request, response, userLogin.getNextUrlTxt());
            } else {
              forwardKey(request, response, "webshop.jsp.front.imode.main");
            }
          } else {
            session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
            forwardKey(request, response, "webshop.jsp.front.imode.login4");
          }
        } else if (actionName.equalsIgnoreCase(SIConfig.SIACTION_LOGIN2)) {
          userLogin.initEasyLogin(request, urlParam, dbConn);
          if (userLogin.validate(request, response, dbConn, true)) {// 認証OK
            userLogin.updLoginDateTime(dbConn);// DB更新(最終ログイン日時)
            session = request.getSession(true);
            // ポイント期限のチェックと更新
            SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
            SIPointMan.clear(dbConn, lUserLogin.getCustCode());
            SIReserveCartManager.refresh(request, dbConn);
            session.removeAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME);
            if ("0".equals(lUserLogin.getHairCosmeFlg())) {
              forwardKey(request, response, "webshop.jsp.front.imode.contract.haircosme.1");
            } else if ("2".equals(lUserLogin.getHairCosmeFlg())) {
              forwardKey(request, response, "webshop.jsp.front.imode.contract.haircosme.3");
            } else if (SIUtil.isNotNull(userLogin.getNextUrlTxt())) {// 決済へ行く前に、カートの情報を設定
              if (userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtylist") || userLogin.getNextUrlTxt().startsWith("/mobile/i/cmdtydetail")) {
                String url = userLogin.getNextUrlTxt();
                url = url.replaceAll("/ctc=", "?ctc=");
                url = url.replaceAll("/shc=", "&shc=");
                url = url.replaceAll("/cmc=", "&cmc=");
                url = url.replaceAll("/inc=", "&inc=");
                // EDBTG003-00 nagayoshi add start
                url = url.replaceAll("/cmpt=", "&cmpt=");
                // EDBTG003-00 nagayoshi add end
                url = url.replaceAll("/a=", "&a=");
                url = url.replaceAll("/pageNumberTxt=", "&pageNumberTxt=");
                userLogin.setNextUrlTxt(url);
              }
              redirectHttps(request, response, userLogin.getNextUrlTxt());
            } else {
              forwardKey(request, response, "webshop.jsp.front.imode.main");
            }
          } else {
            session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
            forwardKey(request, response, "webshop.jsp.front.imode.login4");
          }
        } else {// 初期化
          session.setAttribute(SIConfig.SISESSION_I_USER_LOGIN_NAME, userLogin);
          forwardKey(request, response, "webshop.jsp.front.imode.login4");
        }
      //20121023 add Nishikawa ログアウト機能
      } else if (this.getServletPath(request).equals("/mobile/i/logout")) { // ログアウト
        try {
          SIReserveCartManager.cancel(request, databaseConnection.getConnection());
          databaseConnection.getConnection().commit();
        } catch (Exception e) {
          log.debug(e);
          e.printStackTrace();
        }
        session.invalidate();
        // クッキーの取得
        Cookie[] cookies = request.getCookies();
        for (int i = 0; cookies != null && i < cookies.length; i++) {
          // クッキーの名前で判別
          if (cookies[i].getName().equals(SIConfig.SICOOKIE_LOGIN)) {
            // レコード削除
            SIModifyRec lRec = new SIModifyRec("LOGINSESSIONTBL");
            lRec.add("delflg", 1);
            lRec.addCondition("sessionid", cookies[i].getValue());
            try {
              lRec.execute(databaseConnection.getConnection());
              databaseConnection.getConnection().commit();
            } catch (SIDuplicateKeyException e) {
              log.debug(e);
              e.printStackTrace();
            } catch (SIDBAccessException e) {
              log.debug(e);
              e.printStackTrace();
            }
            cookies[i].setMaxAge(0);
            cookies[i].setDomain("." + SIConfig.BG_HOST_NAME);
            cookies[i].setPath("/");
            ((HttpServletResponse)response).addCookie(cookies[i]);
            break;
          }
        }
        forwardKey(request, response, "webshop.jsp.front.imode.logout");
      } else if (this.getServletPath(request).equals("/mobile/i/custmenu")) {// 顧客メニュー
        forwardKey(request, response, "webshop.jsp.front.imode.customer.menu");
      } else if (this.getServletPath(request).equals("/mobile/i/custdelivery")) {// アドレス帳
        if (SIUtil.isNull(actionName)) {// 一覧の初期表示
          UIIDeliveryList lDeliveryList = new UIIDeliveryList();
          SIUserInfo lUserInfo = SIHTMLUtil.getUserInfo(request);
          if (lUserInfo.isNotLogin(request)) {// ログインしなければ、ログインへ
            String lUrl = SIURLMap.getUrl("webshop.servlet.front.imode.login") + "?nid=" + SIHTMLUtil.URLEncode(SIURLMap.getUrl("webshop.servlet.front.imode.customer.delivery"));
            redirectHttps(request, response, lUrl);
          } else {
            session.setAttribute(SIConfig.SISESSION_I_DELIVERY_LIST_NAME, lDeliveryList);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery");
          }
        } else if (SIConfig.SIACTION_LIST.equals(actionName)) {// ページ遷移など
          UIIDeliveryList lDeliveryList = new UIIDeliveryList();
          lDeliveryList.init(request, urlParam);// 7.1.1 ST0236 修正
          session.setAttribute(SIConfig.SISESSION_I_DELIVERY_LIST_NAME, lDeliveryList);
          forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery");
        } else if (SIConfig.SIACTION_BACK.equals(actionName)) {// 編集画面から一覧
          forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery");
        } else if (SIConfig.SIACTION_NEW.equals(actionName) || SIConfig.SIACTION_MODIFY.equals(actionName)) {
          UIICustAddress regCust = new UIICustAddress();
          regCust.init(request, urlParam);// 7.1.1 ST0236 修正
          regCust.setCustCode(SIHTMLUtil.getUserInfo(request).getCustCode());// 7.2.0 ST0328 追加
          // 7.2.0 ST0328 修正 ここから
          if (SIConfig.SIEDIT_MODE_UPDATE.equals(editMode)) {
            regCust.reset(databaseConnection.getConnection());
          }
          // 7.2.0 ST0328 修正 ここまで
          session.setAttribute(SIConfig.SISESSION_I_ADDR_EDIT_NAME, regCust);
          forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.edit");
        } else if (SIConfig.SIACTION_REMODIFY.equals(actionName)) {// 再修正
          forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.edit");
        } else if (SIConfig.SIACTION_CONFIRM.equals(actionName)) {// 登録
          UIICustAddress regCust = (UIICustAddress) session.getAttribute(SIConfig.SISESSION_I_ADDR_EDIT_NAME);
          regCust.init(request, urlParam);// 7.1.1 ST0236 修正
          regCust.setCustCode(SIHTMLUtil.getUserInfo(request).getCustCode());// 7.2.0 ST0328 追加
          session.setAttribute(SIConfig.SISESSION_I_ADDR_EDIT_NAME, regCust);
          if (regCust.validate(request, dbConn)) {
            
            regCust = (UIICustAddress) session.getAttribute(SIConfig.SISESSION_I_ADDR_EDIT_NAME);
            try {
              if (SIConfig.SIEDIT_MODE_INSERT.equals(editMode)) {// 新規
                SIAddrSrv.insertTableData(dbConn, regCust);
                request.setAttribute(SIConfig.SIMESSAGE_ATTRIBUTE_RESULT_NAME, SIErrorFactory.getErrorMsg("manager.message.success.insert"));
              } else if (SIConfig.SIEDIT_MODE_UPDATE.equals(editMode)) {// 更新
                SIAddrSrv.updateTableData(dbConn, regCust);
                request.setAttribute(SIConfig.SIMESSAGE_ATTRIBUTE_RESULT_NAME, SIErrorFactory.getErrorMsg("manager.message.success.modify"));
              }
              try {
                dbConn.commit();
              } catch (SQLException ee) {}
              ;
              forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.result");
            } catch (SIDuplicateKeyException e) {
              try {
                dbConn.rollback();
              } catch (SQLException ee) {}
              e.printStackTrace();
              log.debug(e.toString());
              SICustomErrors errors = new SICustomErrors();
              errors.addError(new SICustomError("database.insert.duplicate"));
              request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
              forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.edit");
            } catch (SIDBAccessException e) {
              try {
                dbConn.rollback();
              } catch (SQLException ee) {}
              e.printStackTrace();
              log.debug(e.toString());
              SICustomErrors errors = new SICustomErrors();
              errors.addError(new SICustomError("database.execute.error"));
              request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
              forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.edit");
            }
          } else {
            forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.edit");
          }
        } else if (SIConfig.SIACTION_REGIST.equals(actionName)) {// 登録
          UIICustAddress regCust = (UIICustAddress) session.getAttribute(SIConfig.SISESSION_I_ADDR_EDIT_NAME);
          try {
            if (SIConfig.SIEDIT_MODE_INSERT.equals(editMode)) {// 新規
              SIAddrSrv.insertTableData(dbConn, regCust);
              request.setAttribute(SIConfig.SIMESSAGE_ATTRIBUTE_RESULT_NAME, SIErrorFactory.getErrorMsg("manager.message.success.insert"));
              
            } else if (SIConfig.SIEDIT_MODE_UPDATE.equals(editMode)) {// 更新
              SIAddrSrv.updateTableData(dbConn, regCust);
              request.setAttribute(SIConfig.SIMESSAGE_ATTRIBUTE_RESULT_NAME, SIErrorFactory.getErrorMsg("manager.message.success.modify"));
            }
            try {
              dbConn.commit();
            } catch (SQLException ee) {}
            ;
            forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.result");
          } catch (SIDuplicateKeyException e) {
            try {
              dbConn.rollback();
            } catch (SQLException ee) {}
            e.printStackTrace();
            log.debug(e.toString());
            SICustomErrors errors = new SICustomErrors();
            errors.addError(new SICustomError("database.insert.duplicate"));
            request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.edit");
          } catch (SIDBAccessException e) {
            try {
              dbConn.rollback();
            } catch (SQLException ee) {}
            e.printStackTrace();
            log.debug(e.toString());
            SICustomErrors errors = new SICustomErrors();
            errors.addError(new SICustomError("database.execute.error"));
            request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery.edit");
          }
        } else if (SIConfig.SIACTION_DELETE.equals(actionName)) {
          UIICustAddress regCust = new UIICustAddress();
          regCust.init(request, urlParam);// 7.1.1 ST0236 修正
          regCust.setCustCode(SIHTMLUtil.getUserInfo(request).getCustCode());// 7.2.0 ST0328 追加
          try {
            if (SIUtil.isNull(regCust.getCustCode()) || SIUtil.isNull(regCust.getAddressCode())) { throw new SIDBAccessException(); }
            SIAddrSrv.deleteTableData(databaseConnection.getConnection(), regCust);
            request.setAttribute(SIConfig.SIMESSAGE_ATTRIBUTE_RESULT_NAME, SIErrorFactory.getErrorMsg("manager.message.success.delete"));
            try {
              databaseConnection.getConnection().commit();
            } catch (SQLException sqle) {}
          } catch (SIDBAccessException e) {
            try {
              databaseConnection.getConnection().rollback();
            } catch (SQLException ee) {}
            SICustomErrors errors = new SICustomErrors();
            errors.addError(new SICustomError("database.execute.error"));
            request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
          }
          forwardKey(request, response, "webshop.jsp.front.imode.customer.delivery");
        }
      } else if (this.getServletPath(request).equals("/mobile/i/buyhist")) {// ご注文履歴
        if (SIUtil.isNull(actionName)) {// 一覧の初期表示
          UIIBuyHist lBuyHist = new UIIBuyHist();
          SIUserInfo lUserInfo = SIHTMLUtil.getUserInfo(request);
          if (lUserInfo.isNotLogin(request)) {// ログインしなければ、ログインへ
            String lUrl = SIURLMap.getUrl("webshop.servlet.front.imode.login") + "?nid=" + SIHTMLUtil.URLEncode(SIURLMap.getUrl("webshop.servlet.front.imode.customer.hist"));
            redirectHttps(request, response, lUrl);
          } else {
            lBuyHist.init(request, urlParam);// 7.1.1 ST0236 修正
            session.setAttribute(SIConfig.SISESSION_I_BUY_HIST_NAME, lBuyHist);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.hist");
          }
        } else if (SIConfig.SIACTION_BACK.equals(actionName)) {// 一覧に戻る
          forwardKey(request, response, "webshop.jsp.front.imode.customer.hist");
        } else if (SIConfig.SIACTION_DELETE.equals(actionName)) {// キャンセル
          UIIBuyHist lBuyHist = new UIIBuyHist();
          // 出荷日を設定するPKを設定
          lBuyHist.initCancel(request, urlParam);// 7.1.1 ST0236 修正
          // キャンセルするレコードの
          if (lBuyHist.validateCancel(request, databaseConnection.getConnection())) {// 問題がなければ
            try {
              (new SIOrderHistorySrv()).orderCancel(databaseConnection.getConnection(), lBuyHist.getCancelOrderCodeHid());
              request.setAttribute(SIConfig.SIMESSAGE_ATTRIBUTE_RESULT_NAME, "キャンセルしました。");
              try {
                databaseConnection.getConnection().commit();
              } catch (SQLException sqle) {}
            } catch (SIDBAccessException sqle) {
              try {
                databaseConnection.getConnection().rollback();
              } catch (SQLException ee) {}
              sqle.printStackTrace();
              SICustomErrors errors = new SICustomErrors();
              errors.addError(new SICustomError("database.execute.error"));
              request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            } catch (SIErrorException erre) {
              try {
                databaseConnection.getConnection().rollback();
              } catch (SQLException ee) {}
              erre.printStackTrace();
              SICustomErrors errors = new SICustomErrors();
              errors.addError(new SICustomError("manager.message.failure.cancel"));
              request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            }
          }
          forwardKey(request, response, "webshop.jsp.front.imode.customer.hist");
        } else if (SIConfig.SIACTION_DETAIL.equals(actionName)) {// ご注文履歴詳細
          UIIBuyDetail regOrder = new UIIBuyDetail();
          regOrder.init(request, urlParam);// 7.1.1 ST0236 修正
          regOrder.reset(request, databaseConnection.getConnection());
          session.setAttribute(SIConfig.SISESSION_I_BUY_DETAIL_NAME, regOrder);
          forwardKey(request, response, "webshop.jsp.front.imode.customer.detail");
        }
      } else if (this.getServletPath(request).equals("/mobile/i/custpoint")) {// ポイント残高
        if (SIUtil.isNull(actionName)) {// 表示
          SIUserInfo lUserInfo = SIHTMLUtil.getUserInfo(request);
          if (lUserInfo.isNotLogin(request)) {// ログインしなければ、ログインへ
            String lUrl = SIURLMap.getUrl("webshop.servlet.front.imode.login") + "?nid=" + SIHTMLUtil.URLEncode(SIURLMap.getUrl("webshop.servlet.front.imode.customer.point"));
            redirectHttps(request, response, lUrl);
          } else {
            forwardKey(request, response, "webshop.jsp.front.imode.customer.point");
          }
        }
        // 7.3.0 ST2025 追加 ここから お客様情報削除依頼
      } else if (this.getServletPath(request).equals("/mobile/i/custdelrequest")) { // お客様情報削除依頼
        if (SIUtil.isNull(actionName)) { // 削除依頼画面表示
          SIUserInfo lUserInfo = SIHTMLUtil.getUserInfo(request);
          if (lUserInfo.isNotLogin(request)) {// ログインしなければ、ログインへ
            String lUrl = SIURLMap.getUrl("webshop.servlet.front.imode.login") + "?nid=" + SIHTMLUtil.URLEncode(SIURLMap.getUrl("webshop.servlet.front.imode.customer.delrequest"));
            lUrl = lUrl + "&Mode=req"; // 7.3.0 ST2025 追加
            redirectHttps(request, response, lUrl);
          } else {
            forwardKey(request, response, "webshop.jsp.front.imode.customer.delrequest"); // 削除依頼画面表示
          }
        } else {
          // 削除依頼の発行
          siUserInfo = SIHTMLUtil.getUserInfo(request);
          siUserInfo.getCustCode();
          try {
            updDeleteRequest(databaseConnection.getConnection(), request, siUserInfo);
            siUserInfo.setDelFlg(Integer.parseInt(SIConfig.SIDEL_FLG_REQUEST));
            request.setAttribute(SIConfig.SISESSION_USERINFO_NAME, siUserInfo);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.delrequest");
          } catch (SIDuplicateKeyException e) {
            try {
              databaseConnection.getConnection().rollback();
            } catch (SQLException ee) {}
            e.printStackTrace();
            log.debug(e.toString());
            SICustomErrors errors = new SICustomErrors();
            errors.addError(new SICustomError("database.insert.duplicate"));
            request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.menu");
          } catch (SIDBAccessException e) {
            try {
              databaseConnection.getConnection().rollback();
            } catch (SQLException ee) {}
            e.printStackTrace();
            log.debug(e.toString());
            SICustomErrors errors = new SICustomErrors();
            errors.addError(new SICustomError("database.execute.error"));
            request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            forwardKey(request, response, "webshop.jsp.front.imode.customer.menu");
          }
        }
        // 7.3.0 ST2025 追加 ここまで
        // パスワードリマインダー画面
      } else if (this.getServletPath(request).equals("/mobile/i/remainder")) {
        if (SIUtil.isNull(actionName)) {// パスワード確認画面へ遷移
          UIRemainder remainder = new UIRemainder();
          remainder.init(request, urlParam);// 7.1.1 ST0236 修正
          session.setAttribute(SIConfig.SISESSION_I_USER_REMAINDER_NAME, remainder);
          forwardKey(request, response, "webshop.jsp.front.imode.remainder");
        } else if (actionName.equalsIgnoreCase(SIConfig.SIACTION_CONFIRM)) {
          UIRemainder remainder = (UIRemainder) session.getAttribute(SIConfig.SISESSION_I_USER_REMAINDER_NAME);
          remainder.init1(request, urlParam);// 7.1.1 ST0236 修正
          remainder.validate1(request, databaseConnection.getConnection());
          session.setAttribute(SIConfig.SISESSION_I_USER_REMAINDER_NAME, remainder);
          forwardKey(request, response, "webshop.jsp.front.imode.remainder");
        } else if (actionName.equalsIgnoreCase(SIConfig.SIACTION_MAIL)) {
          UIRemainder remainder = (UIRemainder) session.getAttribute(SIConfig.SISESSION_I_USER_REMAINDER_NAME);
          remainder.init2(request, urlParam);// 7.1.1 ST0236 修正
          if (remainder.validate2(request, databaseConnection.getConnection())) {
            this.sendRemainderMail(request, databaseConnection.getConnection(), remainder);
          }
          session.setAttribute(SIConfig.SISESSION_I_USER_REMAINDER_NAME, remainder);
          forwardKey(request, response, "webshop.jsp.front.imode.remainder");
        }
      } else if (this.getServletPath(request).equals("/mobile/i/member")) {
        UIIUserEdit userEdit = new UIIUserEdit();
        // add by mikami
        if(session.getAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME) != null){
          userEdit = (UIIUserEdit) session.getAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME);
        }else{
          userEdit = new UIIUserEdit();
        }
        // add end
        userEdit.setEditModeTxt(SIConfig.SIEDIT_MODE_INSERT);
        if (SIUtil.isNotNull((String) urlParam.getParam("nid")) && !((String) urlParam.getParam("nid")).equals(SIURLMap.getUrl("webshop.servlet.front.imode.customer"))) {
          userEdit.setNextUrlTxt((String) urlParam.getParam("nid"));// 7.1.1 ST0236 修正
        }
        session.setAttribute(SIConfig.SISESSION_I_USER_EDIT_NAME, userEdit);
        forwardKey(request, response, "webshop.jsp.front.imode.customer.edit1");
      } else if (this.getServletPath(request).equals("/mobile/i/contract_maker")) {
        if (SIUtil.isNull(actionName)) {
          session.setAttribute(SIConfig.SISESSION_MAN_MAKER_CONTRACT_CODE, (String)urlParam.getParam("contractMaker"));
          forwardKey(request, response, "webshop.jsp.front.imode.contract.peachpeau.1");
        } else if (SIConfig.SIACTION_CONFIRM.equals(actionName)) {
          forwardKey(request, response, "webshop.jsp.front.imode.contract.peachpeau.2");
        } else if (SIConfig.SIACTION_REGIST.equals(actionName)) {
          SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
          if (lUserLogin.isNotLogin(request)) forwardKey(request, response, "webshop.jsp.front.imode.main");
          String makerCode = (String)session.getAttribute(SIConfig.SISESSION_MAN_MAKER_CONTRACT_CODE);
          SIMaker maker = new SIMaker();
          maker.reset(databaseConnection.getConnection(), makerCode);
          if ("2".equals(maker.getContractFlg())){
            SICustomerSrv.contractMaker(lUserLogin,maker);
          }else if ("3".equals(maker.getContractFlg())){
            SICustomerSrv.contractMakerRegist(lUserLogin,maker);
            try{
              SIInsertRec lRec = new SIInsertRec("custmakertbl");
              lRec.add("custcode",lUserLogin.getCustCode());
              lRec.add("makercode",makerCode);
              lRec.execute(databaseConnection.getConnection());
              lUserLogin.reset(databaseConnection.getConnection());
            }catch(Exception e){
              e.printStackTrace();
            }
            try {databaseConnection.getConnection().commit();} catch (SQLException ee) {}// コミット処理
          }
          session.setAttribute(SIConfig.SISESSION_USERINFO_NAME, lUserLogin);
          forwardKey(request, response, "webshop.jsp.front.imode.contract.peachpeau.3");
        }
      } else if (this.getServletPath(request).equals("/mobile/i/contract_haircosme")) {
        if (SIUtil.isNull(actionName)) {
          forwardKey(request, response, "webshop.jsp.front.imode.contract.haircosme.1");
        } else if (SIConfig.SIACTION_REGIST.equals(actionName)) {
          SIUserInfo lUserLogin = (SIUserInfo) session.getAttribute(SIConfig.SISESSION_USERINFO_NAME);
          if (lUserLogin.isNotLogin(request)) forwardKey(request, response, "webshop.jsp.front.imode.main");
          if ("0".equals(lUserLogin.getHairCosmeFlg())) {
            request.removeAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY);
            SICustomErrors errors = new SICustomErrors();
            lUserLogin.setSalonUrl(request.getParameter("URL"));
            if (SICheckValid.checkValid(errors, "サロンホームページURL", lUserLogin.getSalonUrl(), SICheckDataConf.SICHECK_DATA_EMPTY_TYPE+SICheckDataConf.SICHECK_DATA_URL_TYPE)){
              SICustomerSrv.contractHairCosme3(request,lUserLogin, databaseConnection.getConnection());
              SIModifyRec lRec = new SIModifyRec("custtbl");
              lRec.addCondition("custcode",lUserLogin.getCustCode());
              lRec.add("salonUrl", lUserLogin.getSalonUrl());
              try {
                lRec.execute(databaseConnection.getConnection());
                databaseConnection.getConnection().commit();
                lUserLogin.reset(databaseConnection.getConnection());
              } catch (Exception e) {
                e.printStackTrace();
              }
            }else{
              request.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
            }
          }else if ("4".equals(lUserLogin.getHairCosmeFlg())) {
            SICustomerSrv.contractHairCosme2(lUserLogin, databaseConnection.getConnection());
            try {
              databaseConnection.getConnection().commit();
              lUserLogin.reset(databaseConnection.getConnection());
            } catch (SIDBAccessException e) {
              e.printStackTrace();
            }
          }
          session.setAttribute(SIConfig.SISESSION_USERINFO_NAME, lUserLogin);
          if(lUserLogin.getHairCosmeFlg().equals("0")){
            forwardKey(request, response, "webshop.jsp.front.imode.contract.haircosme.1");
          }else if(lUserLogin.getHairCosmeFlg().equals("2")){
            forwardKey(request, response, "webshop.jsp.front.imode.contract.haircosme.3");
          }else{
            forwardKey(request, response, "webshop.jsp.front.imode.cmdty.detail");
          }
        }
      }
    } catch (SQLException e) {
      e.printStackTrace();
      throw new ServletException();
    } catch (NamingException e) {
      e.printStackTrace();
      throw new ServletException();
    } finally {
      siUserInfo = null; // 7.3.0 ST2025 追加
      databaseConnection.close();
    }
  }
  
  // 7.3.0 ST2026 追加 ここから
  /**
   * sendUserRegistMail メールを送信する 顧客データが登録・修正された場合に使用する(フロントサイド) バックサイドとは「削除がない」「第２引数が違う」の差異があります。
   * 
   * @param Connection DBコネクション
   * @param UIRegCust 送信先に関するデータを納めるUIRegCustクラス
   * @param String 更新区分（1:新規 / 2:修正)
   */
  private void sendUserRegistMail(Connection connection, UIRegCust regCust, String strMode) {
    
    StringBuffer lMailBuf = null; // メール本文用StringBuffer
    SISendMail lSendMail = null; // メール送信クラス
    String lReserveChangeDateTime = null; // 現在日付
    String[] strMailAdr = new String[2]; // メール１通に対するメール送信先
    
    // メールを作成・送信
    lMailBuf = new StringBuffer();
    lSendMail = new SISendMail();
    
    try {
      lSendMail.setMailTemp(connection, "0", SIConfig.SIMAIL_TEMPLATE_USER_REGIST);
    } catch (SIFatalException e) {
      e.printStackTrace();
    }
    
    lReserveChangeDateTime = (new SIDateTime()).getFullDateTime();
    
    // メールの本文の作成
    if (LC_ADD.equals(strMode) == true) {
      lMailBuf.append("\n登録日時:" + lReserveChangeDateTime);
      lMailBuf.append("\n\nお客様情報 (登録通知) ");
    } else if (LC_UPD.equals(strMode) == true) {
      lMailBuf.append("\n更新日時:" + lReserveChangeDateTime);
      lMailBuf.append("\n\nお客様情報 (更新通知) ");
    }
    lMailBuf.append("\n=============");
    lMailBuf.append("\nお客様氏名:").append(regCust.getCustName());
    lMailBuf.append("\nお客様のメールアドレス:").append(regCust.getEmail());
    lMailBuf.append("\n=============");
    
    // メールの本文の作成(メールテンプレートの内容2)
    lMailBuf.append("\n");
    lSendMail.appendContent1(lMailBuf.toString());
    
    // メールの本文の作成(メールテンプレートの内容3)
    lMailBuf = new StringBuffer();
    lSendMail.appendContent2(lMailBuf.toString());
    
    // 送信開始
    try {
      // メールアドレスが修正されているときには修正前のアドレスも対象とする
      if (LC_UPD.equals(strMode) == true && regCust.getEmail().equals(regCust.getEMailOld()) == false) {
        strMailAdr[0] = regCust.getEMailOld();
        strMailAdr[1] = regCust.getEmail();
        lSendMail.setToMailAddress(strMailAdr);
        // その他
      } else {
        lSendMail.setToMailAddress(regCust.getEmail());
      }
      lSendMail.execute();
    } catch (SIFatalException e) {
      e.printStackTrace();
    }
    
    lMailBuf = null;
    lSendMail = null;
    lReserveChangeDateTime = null;
    strMailAdr = null;
  }
  
  // 7.3.0 ST2026 追加 ここまで
  // 7.3.0 ST2025 追加 ここから
  /**
   * updDeleteRequest 顧客テーブルの対象のレコードの削除依頼フラグを2（削除依頼）に更新する さらに更新が成功していればメールを顧客とモール（ショップ）管理者に送信する
   * 
   * @param Connection DBコネクション
   * @param HttpServletRequest リクエスト
   * @param SIUserInfo SIUserInfoクラス
   * @throws SIDuplicateKeyException
   * @throws SIDBAccessException
   */
  private void updDeleteRequest(Connection connection, HttpServletRequest request, SIUserInfo siUserInfo) throws SIDuplicateKeyException, SIDBAccessException {
    
    SIModifyRec lModRec = null;
    StringBuffer lMailBuf = null;
    SISendMail lSendMail = null;
    String lReserveChangeDateTime = null;
    
    try {
      lModRec = new SIModifyRec(SIConfig.SITABLE_CUST_NAME);
      // キー項目のセット
      lModRec.addCondition("custcode", siUserInfo.getCustCode());
      // 更新対象項目のセット
      lModRec.add("DelFlg", SIConfig.SIDEL_FLG_REQUEST); // 削除フラグ = 2(削除依頼)
      
      // 更新実行
      lModRec.execute(connection);
      // コミット
      connection.commit();
      
      // 削除依頼メールを作成・送信
      lMailBuf = new StringBuffer();
      lSendMail = new SISendMail();
      try {
        lSendMail.setMailTemp(connection, "0", SIConfig.SIMAIL_TEMPLATE_DELETE_REQUEST);
      } catch (SIFatalException e) {
        e.printStackTrace();
      }
      
      lReserveChangeDateTime = (new SIDateTime()).getFullDateTime();
      lMailBuf.append("\n依頼日時:" + lReserveChangeDateTime);
      
      // メールの本文の作成(削除依頼情報)
      lMailBuf.append("\n\nお客様情報 (削除依頼) ");
      lMailBuf.append("\n=============");
      lMailBuf.append("\nお客様氏名:").append(siUserInfo.getCustName());
      lMailBuf.append("\nお客様のメールアドレス:").append(siUserInfo.getEmail());
      lMailBuf.append("\n=============");
      
      // メールの本文の作成(メールテンプレートの内容2)
      lMailBuf.append("\n");
      lSendMail.appendContent1(lMailBuf.toString());
      
      // メールの本文の作成(メールテンプレートの内容3)
      lMailBuf = new StringBuffer();
      lSendMail.appendContent2(lMailBuf.toString());
      
      // 送信開始
      try {
        lSendMail.setToMailAddress(siUserInfo.getEmail());
        lSendMail.execute();
      } catch (SIFatalException e) {
        e.printStackTrace();
      }
      
    } catch (SQLException sqle) {
      
      throw new SIDBAccessException("delete data error.");
      
    } finally {
      
      lModRec = null;
      lMailBuf = null;
      lSendMail = null;
      lReserveChangeDateTime = null;
    }
  }
  
  // 7.3.0 ST2025 追加 ここまで
  private boolean sendRemainderMail(HttpServletRequest request, Connection connection, UIRemainder remainder) {
    SISendMail lSendMail = new SISendMail();
    
    // 送信先メールアドレス取得
    lSendMail.setToMailAddress(remainder.getEmailTxt());
    
    // 送信元メールアドレス取得
    SIMallShop mall = new SIMallShop();
    mall.resetMall(connection);
    
    // パスワード取得
    SICust cust = new SICust();
    cust.reset(connection, remainder.getEmailTxt());
    
    // メールのテンプレートをセットする
    SIMailTemp mailTemp = new SIMailTemp();
    mailTemp.setEncode(SIConfig.SIENCODE_NONE);
    mailTemp.setTitle("パスワード確認メールです。");
    mailTemp.setFromMail(mall.getEmail());
    mailTemp.setContent1("お客さまのパスワードは【" + cust.getPassword() + "】です。");
    lSendMail.setMailTemp(mailTemp);
    
    // メール送信
    try {
      return lSendMail.execute();
    } catch (SIFatalException e) {
      return false;
    }
  }

  /**
   * writeCookie メールアドレス、パスワードをクッキーに保存します。 保存期限は30日間です。
   * 
   * @param HttpServletResponse レスポンス
   * @param String 保存するメールアドレス
   * @param String 保存するパスワード
   * @throws IOException
   */
  private void writeCookie(HttpServletResponse response, String lEmailTxt, String lPasswdTxt) throws IOException {
    String value1 = URLEncoder.encode(lEmailTxt, "Shift_JIS");
    String value2 = URLEncoder.encode(lPasswdTxt, "Shift_JIS");
    Cookie mailCookie = new Cookie("ws_mailaddressBG", value1);
    Cookie passCookie = new Cookie("ws_passwordBG", value2);
    mailCookie.setMaxAge(60 * 60 * 24 * 30);
    passCookie.setMaxAge(60 * 60 * 24 * 30);
    response.addCookie(mailCookie);
    response.addCookie(passCookie);
  }
}
