source: branches/feature-module-update/html/admin/basis/delivery_input.php @ 15080

Revision 15080, 5.7 KB checked in by nanasess, 17 years ago (diff)

svn properties 設定

  • svn:mime-type - application/x-httpd-php; charset=UTF-8
  • svn:keywords - Id
  • Property svn:keywords set to Id
  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../require.php");
8
9class LC_Page {
10    var $arrSession;
11    var $tpl_mode;
12    function LC_Page() {
13        $this->tpl_mainpage = 'basis/delivery_input.tpl';
14        $this->tpl_subnavi = 'basis/subnavi.tpl';
15        $this->tpl_subno = 'delivery';
16        $this->tpl_mainno = 'basis';
17        global $arrPref;
18        $this->arrPref = $arrPref;
19        $this->tpl_subtitle = '配送業者設定';
20    }
21}
22
23$conn = new SC_DBConn();
24$objPage = new LC_Page();
25$objView = new SC_AdminView();
26$objSess = new SC_Session();
27$objQuery = new SC_Query();
28
29// 認証可否の判定
30sfIsSuccess($objSess);
31
32// パラメータ管理クラス
33$objFormParam = new SC_FormParam();
34// パラメータ情報の初期化
35lfInitParam();
36// POST値の取得
37$objFormParam->setParam($_POST);
38
39switch($_POST['mode']) {
40case 'edit':
41    // 入力値の変換
42    $objFormParam->convParam();
43    $objPage->arrErr = lfCheckError();
44    if(count($objPage->arrErr) == 0) {
45        $objPage->tpl_deliv_id = lfRegistData();
46        $objPage->tpl_onload = "window.alert('配送業者設定が完了しました。');";
47    }
48    break;
49case 'pre_edit':
50    if($_POST['deliv_id'] != "") {
51        lfGetDelivData($_POST['deliv_id']);
52        $objPage->tpl_deliv_id = $_POST['deliv_id'];
53    }
54    break;
55default:
56    break;
57}
58
59$objPage->arrForm = $objFormParam->getFormParamList();
60$objView->assignobj($objPage);
61$objView->display(MAIN_FRAME);
62//--------------------------------------------------------------------------------------------------------------------------------------
63/* パラメータ情報の初期化 */
64function lfInitParam() {
65    global $objFormParam;
66    $objFormParam->addParam("配送業者名", "name", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
67    $objFormParam->addParam("名称", "service_name", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
68    $objFormParam->addParam("伝票No.確認URL", "confirm_url", STEXT_LEN, "n", array("URL_CHECK", "MAX_LENGTH_CHECK"), "http://");
69   
70    for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
71        $objFormParam->addParam("配送時間$cnt", "deliv_time$cnt", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
72    }
73   
74    if(INPUT_DELIV_FEE) {
75        for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
76            $objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
77        }
78    }
79}
80
81/* DBに登録する */
82function lfRegistData() {
83    global $objFormParam;
84    $arrRet = $objFormParam->getHashArray();
85    $objQuery = new SC_Query();
86    $objQuery->begin();
87
88    // 入力データを渡す。
89    $sqlval['name'] = $arrRet['name'];
90    $sqlval['service_name'] = $arrRet['service_name'];
91    $sqlval['confirm_url'] = $arrRet['confirm_url'];
92    $sqlval['creator_id'] = $_SESSION['member_id'];
93    $sqlval['update_date'] = 'Now()';
94   
95    if($_POST['deliv_id'] != "") {
96        $deliv_id = $_POST['deliv_id'];
97        $where = "deliv_id = ?";
98        $objQuery->update("dtb_deliv", $sqlval, $where, array($deliv_id));
99        $objQuery->delete("dtb_delivfee", $where, array($deliv_id));
100        $objQuery->delete("dtb_delivtime", $where, array($deliv_id));
101    } else {
102        // 登録する配送業者IDの取得
103
104        if (DB_TYPE == "pgsql") {
105            $deliv_id = $objQuery->nextval('dtb_deliv', 'deliv_id');
106            $sqlval['deliv_id'] = $deliv_id;
107        }
108       
109        $sqlval['rank'] = $objQuery->max("dtb_deliv", "rank") + 1;
110        $sqlval['create_date'] = 'Now()';
111        // INSERTの実行
112        $objQuery->insert("dtb_deliv", $sqlval);
113       
114        if (DB_TYPE == "mysql") {
115            $deliv_id = $objQuery->nextval('dtb_deliv', 'deliv_id');           
116        }
117    }
118   
119    $sqlval = array();
120    // 配送時間の設定
121    for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
122        $keyname = "deliv_time$cnt";
123        if($arrRet[$keyname] != "") {
124            $sqlval['deliv_id'] = $deliv_id;
125            $sqlval['deliv_time'] = $arrRet[$keyname];
126            // INSERTの実行
127            $objQuery->insert("dtb_delivtime", $sqlval);
128        }
129    }
130   
131    if(INPUT_DELIV_FEE) {
132        $sqlval = array();
133        // 配送料金の設定
134        for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
135            $keyname = "fee$cnt";
136            if($arrRet[$keyname] != "") {
137                $sqlval['deliv_id'] = $deliv_id;
138                $sqlval['fee'] = $arrRet[$keyname];
139                $sqlval['pref'] = $cnt;
140                // INSERTの実行
141                $objQuery->insert("dtb_delivfee", $sqlval);
142            }
143        }
144    }
145    $objQuery->commit();
146    return $deliv_id;
147}
148
149/* 配送業者情報の取得 */
150function lfGetDelivData($deliv_id) {
151    global $objFormParam;
152    $objQuery = new SC_Query();
153    // 配送業者一覧の取得
154    $col = "deliv_id, name, service_name, confirm_url";
155    $where = "deliv_id = ?";
156    $table = "dtb_deliv";
157    $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
158    $objFormParam->setParam($arrRet[0]);
159    // 配送時間の取得
160    $col = "deliv_time";
161    $where = "deliv_id = ?  ORDER BY time_id";
162    $table = "dtb_delivtime";
163    $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
164    $objFormParam->setParamList($arrRet, 'deliv_time');
165    // 配送料金の取得
166    $col = "fee";
167    $where = "deliv_id = ? ORDER BY pref";
168    $table = "dtb_delivfee";
169    $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
170    $objFormParam->setParamList($arrRet, 'fee');
171}
172
173/* 入力内容のチェック */
174function lfCheckError() {
175    global $objFormParam;
176    // 入力データを渡す。
177    $arrRet =  $objFormParam->getHashArray();
178    $objErr = new SC_CheckError($arrRet);
179    $objErr->arrErr = $objFormParam->checkError();
180   
181    if(!isset($objErr->arrErr['name']) && $_POST['deliv_id'] == "") {
182        // 既存チェック
183        $ret = sfIsRecord("dtb_deliv", "service_name", array($arrRet['service_name']));
184        if ($ret) {
185            $objErr->arrErr['name'] = "※ 同じ名称の組み合わせは登録できません。<br>";
186        }
187    }
188   
189    return $objErr->arrErr;
190}
Note: See TracBrowser for help on using the repository browser.