Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Admin_Basis_DeliveryInput.php

Documentation is available at LC_Page_Admin_Basis_DeliveryInput.php

  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.  
  24. // {{{ requires
  25. require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
  26.  
  27. /**
  28.  * 配送方法設定 のページクラス.
  29.  *
  30.  * @package Page
  31.  * @author LOCKON CO.,LTD.
  32.  * @version $Id: LC_Page_Admin_Basis_DeliveryInput.php 21289 2011-10-20 10:04:19Z shutta $
  33.  */
  34. class LC_Page_Admin_Basis_DeliveryInput extends LC_Page_Admin_Ex {
  35.     // }}}
  36.     // {{{ functions
  37.  
  38.     /**
  39.      * Page を初期化する.
  40.      *
  41.      * @return void 
  42.      */
  43.     function init() {
  44.         parent::init();
  45.         $this->tpl_mainpage = 'basis/delivery_input.tpl';
  46.         $this->tpl_subno = 'delivery';
  47.         $this->tpl_mainno = 'basis';
  48.         $masterData = new SC_DB_MasterData_Ex();
  49.         $this->arrPref = $masterData->getMasterData('mtb_pref');
  50.         $this->arrProductType = $masterData->getMasterData("mtb_product_type");
  51.         $this->arrPayments = SC_Helper_DB_Ex::sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
  52.         $this->tpl_maintitle = '基本情報管理';
  53.         $this->tpl_subtitle = '配送方法設定';
  54.         $this->mode = $this->getMode();
  55.     }
  56.  
  57.     /**
  58.      * Page のプロセス.
  59.      *
  60.      * @return void 
  61.      */
  62.     function process() {
  63.         $this->action();
  64.         $this->sendResponse();
  65.     }
  66.  
  67.     /**
  68.      * Page のアクション.
  69.      *
  70.      * @return void 
  71.      */
  72.     function action() {
  73.         $objFormParam = new SC_FormParam_Ex();
  74.         $this->lfInitParam($this->mode, $objFormParam);
  75.         $objFormParam->setParam($_POST);
  76.  
  77.         // 入力値の変換
  78.         $objFormParam->convParam();
  79.         $this->arrErr = $this->lfCheckError($objFormParam);
  80.  
  81.         switch ($this->mode) {
  82.             case 'edit':
  83.                 if (count($this->arrErr) == 0) {
  84.                     $objFormParam->setValue('deliv_id', $this->lfRegistData($objFormParam->getHashArray(), $_SESSION['member_id']));
  85.                     $this->tpl_onload = "window.alert('配送方法設定が完了しました。');";
  86.                 }
  87.                 break;
  88.             case 'pre_edit':
  89.                 if (count($this->arrErr) > 0) {
  90.                     SC_Utils_Ex::sfDispException();
  91.                 }
  92.                 $this->lfGetDelivData($objFormParam);
  93.                 break;
  94.             default:
  95.                 break;
  96.         }
  97.  
  98.         $this->arrForm = $objFormParam->getFormParamList();
  99.     }
  100.  
  101.     /**
  102.      * デストラクタ.
  103.      *
  104.      * @return void 
  105.      */
  106.     function destroy() {
  107.         parent::destroy();
  108.     }
  109.  
  110.     /* パラメーター情報の初期化 */
  111.     function lfInitParam($mode, &$objFormParam) {
  112.         $objFormParam->initParam();
  113.  
  114.         switch ($mode) {
  115.             case 'edit':
  116.                 $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
  117.                 $objFormParam->addParam("配送業者名", 'name', STEXT_LEN, 'KVa', array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
  118.                 $objFormParam->addParam("名称", "service_name", STEXT_LEN, 'KVa', array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
  119.                 $objFormParam->addParam("説明", 'remark', LLTEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK"));
  120.                 $objFormParam->addParam("伝票No.確認URL", "confirm_url", URL_LEN, 'n', array("URL_CHECK", "MAX_LENGTH_CHECK"), "http://");
  121.                 $objFormParam->addParam("取扱商品種別", "product_type_id", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
  122.                 $objFormParam->addParam("取扱支払方法", "payment_ids", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
  123.  
  124.                 for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
  125.                     $objFormParam->addParam("お届け時間$cnt", "deliv_time$cnt", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK"));
  126.                 }
  127.  
  128.                 if(INPUT_DELIV_FEE) {
  129.                     for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
  130.                         $objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
  131.                     }
  132.                 }
  133.                 break;
  134.  
  135.             case 'pre_edit':
  136.                 $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
  137.                 break;
  138.  
  139.             default:
  140.                 break;
  141.         }
  142.     }
  143.  
  144.     /**
  145.      * 配送情報を登録する
  146.      *
  147.      * @return $deliv_id 
  148.      */
  149.     function lfRegistData($arrRet, $member_id) {
  150.         $objQuery =& SC_Query_Ex::getSingletonInstance();
  151.         $objQuery->begin();
  152.  
  153.         // 入力データを渡す。
  154.         $sqlval['name'] = $arrRet['name'];
  155.         $sqlval['service_name'] = $arrRet['service_name'];
  156.         $sqlval['remark'] = $arrRet['remark'];
  157.         $sqlval['confirm_url'] = $arrRet['confirm_url'];
  158.         $sqlval['product_type_id'] = $arrRet['product_type_id'];
  159.         $sqlval['creator_id'] = $member_id;
  160.         $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
  161.  
  162.         // deliv_id が決まっていた場合
  163.         if($arrRet['deliv_id'] != "") {
  164.             $deliv_id = $arrRet['deliv_id'];
  165.             $where = "deliv_id = ?";
  166.             $objQuery->update("dtb_deliv", $sqlval, $where, array($deliv_id));
  167.  
  168.             // お届け時間の登録
  169.             $table = "dtb_delivtime";
  170.             $where = "deliv_id = ? AND time_id = ?";
  171.             for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
  172.                 $sqlval = array();
  173.                 $keyname = "deliv_time".$cnt;
  174.                 $arrval = array($deliv_id, $cnt);
  175.                 // 既存データの有無を確認
  176.                 $curData = $objQuery->select("*", $table, $where, $arrval);
  177.  
  178.                 if(strcmp($arrRet[$keyname], "") != 0) {
  179.                     $sqlval['deliv_time'] = $arrRet[$keyname];
  180.  
  181.                     // 入力が空ではなく、DBに情報があれば更新
  182.                     if(count($curData)) {
  183.                         $objQuery->update($table, $sqlval, $where, $arrval);
  184.                     }
  185.                     // DBに情報がなければ登録
  186.                     else {
  187.                         $sqlval['deliv_id'] = $deliv_id;
  188.                         $sqlval['time_id'] = $cnt;
  189.                         $objQuery->insert($table, $sqlval);
  190.                     }
  191.                 }
  192.                 // 入力が空で、DBに情報がある場合は削除
  193.                 else if(count($curData)) {
  194.                     $objQuery->delete($table, $where, $arrval);
  195.                 }
  196.             }
  197.  
  198.             // 配送料の登録
  199.             if(INPUT_DELIV_FEE) {
  200.                 for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
  201.                     $keyname = 'fee'.$cnt;
  202.                     if(strcmp($arrRet[$keyname], "") != 0) {
  203.                         $sqlval = array('fee' => $arrRet[$keyname]);
  204.                         $objQuery->update("dtb_delivfee", $sqlval, "deliv_id = ? AND fee_id = ?", array($deliv_id, $cnt));
  205.                     }
  206.                 }
  207.             }
  208.         }
  209.         else {
  210.             // 登録する配送業者IDの取得
  211.             $deliv_id = $objQuery->nextVal('dtb_deliv_deliv_id');
  212.             $sqlval['deliv_id'] = $deliv_id;
  213.             $sqlval['rank'] = $objQuery->max('rank', "dtb_deliv") + 1;
  214.             $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
  215.             // INSERTの実行
  216.             $objQuery->insert("dtb_deliv", $sqlval);
  217.  
  218.             $sqlval = array();
  219.             // お届け時間の設定
  220.             for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
  221.                 $keyname = "deliv_time$cnt";
  222.                 if($arrRet[$keyname] != "") {
  223.                     $sqlval['deliv_id'] = $deliv_id;
  224.                     $sqlval['time_id'] = $cnt;
  225.                     $sqlval['deliv_time'] = $arrRet[$keyname];
  226.                     // INSERTの実行
  227.                     $objQuery->insert("dtb_delivtime", $sqlval);
  228.                 }
  229.             }
  230.  
  231.             if(INPUT_DELIV_FEE) {
  232.                 $sqlval = array();
  233.                 // 配送料金の設定
  234.                 for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
  235.                     $keyname = "fee$cnt";
  236.                     if($arrRet[$keyname] != "") {
  237.                         $sqlval['deliv_id'] = $deliv_id;
  238.                         $sqlval['fee'] = $arrRet[$keyname];
  239.                         $sqlval['pref'] = $cnt;
  240.                         // INSERTの実行
  241.                         $sqlval['fee_id'] = $cnt;
  242.                         $objQuery->insert("dtb_delivfee", $sqlval);
  243.                     }
  244.                 }
  245.             }
  246.         }
  247.  
  248.         $objQuery->delete('dtb_payment_options', 'deliv_id = ?', array($arrRet['deliv_id']));
  249.         $sqlval = array();
  250.         $i = 1;
  251.         foreach ($arrRet['payment_ids'] as $val) {
  252.             $sqlval['deliv_id'] = $deliv_id;
  253.             $sqlval['payment_id'] = $val;
  254.             $sqlval['rank'] = $i;
  255.             $objQuery->insert('dtb_payment_options', $sqlval);
  256.             $i++;
  257.         }
  258.         $objQuery->commit();
  259.         return $deliv_id;
  260.     }
  261.  
  262.     /* 配送業者情報の取得 */
  263.     function lfGetDelivData(&$objFormParam) {
  264.         $objQuery =& SC_Query_Ex::getSingletonInstance();
  265.  
  266.         $deliv_id = $objFormParam->getValue('deliv_id');
  267.  
  268.         // パラメーター情報の初期化
  269.         $this->lfInitParam('edit', $objFormParam);
  270.  
  271.         // 配送業者一覧の取得
  272.         $col = "deliv_id, name, service_name, remark, confirm_url, product_type_id";
  273.         $where = "deliv_id = ?";
  274.         $table = "dtb_deliv";
  275.         $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
  276.         $objFormParam->setParam($arrRet[0]);
  277.         // お届け時間の取得
  278.         $col = "deliv_time";
  279.         $where = "deliv_id = ?  ORDER BY time_id";
  280.         $table = "dtb_delivtime";
  281.         $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
  282.         $objFormParam->setParamList($arrRet, 'deliv_time');
  283.         // 配送料金の取得
  284.         $col = 'fee';
  285.         $where = "deliv_id = ? ORDER BY pref";
  286.         $table = "dtb_delivfee";
  287.         $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
  288.         $objFormParam->setParamList($arrRet, 'fee');
  289.         // 支払方法
  290.         $col = 'payment_id';
  291.         $where = 'deliv_id = ? ORDER BY rank';
  292.         $table = 'dtb_payment_options';
  293.         $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
  294.         $arrPaymentIds = array();
  295.         foreach ($arrRet as $val) {
  296.             $arrPaymentIds[] = $val['payment_id'];
  297.         }
  298.         $objFormParam->setValue('payment_ids', $arrPaymentIds);
  299.     }
  300.  
  301.     /* 入力内容のチェック */
  302.     function lfCheckError(&$objFormParam) {
  303.         // 入力データを渡す。
  304.         $arrRet =  $objFormParam->getHashArray();
  305.         $objErr = new SC_CheckError_Ex($arrRet);
  306.         $objErr->arrErr = $objFormParam->checkError();
  307.  
  308.         if(!isset($objErr->arrErr['name']) && $arrRet['deliv_id'] == "") {
  309.             // 既存チェック
  310.             $objDb = new SC_Helper_DB_Ex();
  311.             $ret = $objDb->sfIsRecord("dtb_deliv", "service_name", array($arrRet['service_name']));
  312.             if ($ret) {
  313.                 $objErr->arrErr['name'] = "※ 同じ名称の組み合わせは登録できません。<br>";
  314.             }
  315.         }
  316.  
  317.         return $objErr->arrErr;
  318.     }
  319. }
  320. ?>

Documentation generated on Fri, 24 Feb 2012 14:01:02 +0900 by Seasoft