source: branches/rel/html/admin/basis/delivery_input.php @ 12157

Revision 12157, 5.5 KB checked in by uehara, 16 years ago (diff)
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.