source: branches/version-2_13-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Pdf.php @ 22926

Revision 22926, 8.5 KB checked in by Seasoft, 11 years ago (diff)

#2287 (環境によりデストラクタが正しく動作しないケースがある)
#2288 (リクエスト単位で実行されるべきログ出力がブロックにも適用されている)
#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 不明確な仕様にコメントを残した。
  • 親デストラクタを呼ぶだけの記述は可読性が悪くなると考え削除した。(上述のチケットで OS の仕様に依存したデストラクタとなるため、敢えてアプリケーション側で記述しておく意義は薄れたという認識のもと。)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * 帳票出力 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Order_Pdf extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'order/pdf_input.tpl';
44        $this->tpl_mainno = 'order';
45        $this->tpl_subno = 'pdf';
46        $this->tpl_maintitle = '受注管理';
47        $this->tpl_subtitle = '帳票出力';
48
49        $this->SHORTTEXT_MAX = STEXT_LEN;
50        $this->MIDDLETEXT_MAX = MTEXT_LEN;
51        $this->LONGTEXT_MAX = LTEXT_LEN;
52
53        $this->arrType[0]  = '納品書';
54
55        $this->arrDownload[0] = 'ブラウザに開く';
56        $this->arrDownload[1] = 'ファイルに保存';
57    }
58
59    /**
60     * Page のプロセス.
61     *
62     * @return void
63     */
64    function process()
65    {
66        $this->action();
67        $this->sendResponse();
68    }
69
70    /**
71     * Page のアクション.
72     *
73     * @return void
74     */
75    function action()
76    {
77        $objDb = new SC_Helper_DB_Ex();
78        $objDate = new SC_Date_Ex(1901);
79        $objDate->setStartYear(RELEASE_YEAR);
80        $this->arrYear = $objDate->getYear();
81        $this->arrMonth = $objDate->getMonth();
82        $this->arrDay = $objDate->getDay();
83
84        // パラメーター管理クラス
85        $this->objFormParam = new SC_FormParam_Ex();
86        // パラメーター情報の初期化
87        $this->lfInitParam($this->objFormParam);
88        $this->objFormParam->setParam($_POST);
89        // 入力値の変換
90        $this->objFormParam->convParam();
91
92        // どんな状態の時に isset($arrRet) == trueになるんだ? これ以前に$arrRet無いが、、、、
93        if (!isset($arrRet)) $arrRet = array();
94        switch ($this->getMode()) {
95            case 'confirm':
96
97                $status = $this->createPdf($this->objFormParam);
98                if ($status === true) {
99                    SC_Response_Ex::actionExit();
100                } else {
101                    $this->arrErr = $status;
102                }
103                break;
104            default:
105                $this->arrForm = $this->createFromValues($_GET['order_id'],$_POST['pdf_order_id']);
106                break;
107        }
108        $this->setTemplate($this->tpl_mainpage);
109    }
110
111    /**
112     *
113     * PDF作成フォームのデフォルト値の生成
114     */
115    function createFromValues($order_id,$pdf_order_id)
116    {
117        // ここが$arrFormの初登場ということを明示するため宣言する。
118        $arrForm = array();
119        // タイトルをセット
120        $arrForm['title'] = 'お買上げ明細書(納品書)';
121
122        // 今日の日付をセット
123        $arrForm['year']  = date('Y');
124        $arrForm['month'] = date('m');
125        $arrForm['day']   = date('d');
126
127        // メッセージ
128        $arrForm['msg1'] = 'このたびはお買上げいただきありがとうございます。';
129        $arrForm['msg2'] = '下記の内容にて納品させていただきます。';
130        $arrForm['msg3'] = 'ご確認くださいますよう、お願いいたします。';
131
132        // 注文番号があったら、セットする
133        if (SC_Utils_Ex::sfIsInt($order_id)) {
134            $arrForm['order_id'][0] = $order_id;
135        } elseif (is_array($pdf_order_id)) {
136            sort($pdf_order_id);
137            foreach ($pdf_order_id AS $key=>$val) {
138                $arrForm['order_id'][] = $val;
139            }
140        }
141
142        return $arrForm;
143    }
144
145    /**
146     *
147     * PDFの作成
148     * @param SC_FormParam $objFormParam
149     */
150    function createPdf(&$objFormParam)
151    {
152        $arrErr = $this->lfCheckError($objFormParam);
153        $arrRet = $objFormParam->getHashArray();
154
155    //タイトルが入力されていなければ、デフォルトのタイトルを表示
156    if($arrRet['title'] == '') $arrRet['title'] = 'お買上げ明細書(納品書)';
157
158        $this->arrForm = $arrRet;
159        // エラー入力なし
160        if (count($arrErr) == 0) {
161            $objFpdf = new SC_Fpdf_Ex($arrRet['download'], $arrRet['title']);
162            foreach ($arrRet['order_id'] AS $key => $val) {
163                $arrPdfData = $arrRet;
164                $arrPdfData['order_id'] = $val;
165                $objFpdf->setData($arrPdfData);
166            }
167            $objFpdf->createPdf();
168            return true;
169        } else {
170            return $arrErr;
171        }
172    }
173
174    /**
175     *  パラメーター情報の初期化
176     *  @param SC_FormParam
177     */
178    function lfInitParam(&$objFormParam)
179    {
180        $objFormParam->addParam('注文番号', 'order_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
181        $objFormParam->addParam('注文番号', 'pdf_order_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
182        $objFormParam->addParam('発行日', 'year', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
183        $objFormParam->addParam('発行日', 'month', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
184        $objFormParam->addParam('発行日', 'day', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
185        $objFormParam->addParam('帳票の種類', 'type', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
186        $objFormParam->addParam('ダウンロード方法', 'download', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
187        $objFormParam->addParam('帳票タイトル', 'title', STEXT_LEN, 'KVa', array ('MAX_LENGTH_CHECK'));
188        $objFormParam->addParam('帳票メッセージ1行目', 'msg1', STEXT_LEN*3/5, 'KVa', array('MAX_LENGTH_CHECK'));
189        $objFormParam->addParam('帳票メッセージ2行目', 'msg2', STEXT_LEN*3/5, 'KVa', array('MAX_LENGTH_CHECK'));
190        $objFormParam->addParam('帳票メッセージ3行目', 'msg3', STEXT_LEN*3/5, 'KVa', array('MAX_LENGTH_CHECK'));
191        $objFormParam->addParam('備考1行目', 'etc1', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
192        $objFormParam->addParam('備考2行目', 'etc2', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
193        $objFormParam->addParam('備考3行目', 'etc3', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
194        $objFormParam->addParam('ポイント表記', 'disp_point', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
195    }
196
197    /**
198     *  入力内容のチェック
199     *  @var SC_FormParam
200     */
201
202    function lfCheckError(&$objFormParam)
203    {
204        // 入力データを渡す。
205        $arrParams = $objFormParam->getHashArray();
206        $arrErr = $objFormParam->checkError();
207        $objError = new SC_CheckError_Ex($arrParams);
208
209        $year = $objFormParam->getValue('year');
210        if (!is_numeric($year)) {
211            $arrErr['year'] = '発行年は数値で入力してください。';
212        }
213
214        $month = $objFormParam->getValue('month');
215        if (!is_numeric($month)) {
216            $arrErr['month'] = '発行月は数値で入力してください。';
217        } else if (0 >= $month && 12 < $month) {
218            $arrErr['month'] = '発行月は1〜12の間で入力してください。';
219        }
220
221        $day = $objFormParam->getValue('day');
222        if (!is_numeric($day)) {
223            $arrErr['day'] = '発行日は数値で入力してください。';
224        } else if (0 >= $day && 31 < $day) {
225            $arrErr['day'] = '発行日は1〜31の間で入力してください。';
226        }
227
228        $objError->doFunc(array('発行日', 'year', 'month', 'day'), array('CHECK_DATE'));
229        $arrErr = array_merge($arrErr, $objError->arrErr);
230
231        return $arrErr;
232    }
233}
Note: See TracBrowser for help on using the repository browser.