Warning: Can't use blame annotator:
svn blame failed on branches/version-2_5-dev/data/class/SC_FormParam.php: バイナリファイル 'file:///home/svn/open/branches/version-2_5-dev/data/class/SC_FormParam.php' に対しては blame で各行の最終変更者を計算できません 195004

source: branches/version-2_5-dev/data/class/SC_FormParam.php @ 18777

Revision 18777, 13.7 KB checked in by eccuore, 14 years ago (diff)

#792(ダウンロード販売機能) 機能追加

  • 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
RevLine 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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/**
25 * パラメータ管理クラス
26 *
27 * :XXX: addParam と setParam で言う「パラメータ」が用語として競合しているように感じる。(2009/10/17 Seasoft 塚田)
28 *
29 * @package SC
30 * @author LOCKON CO.,LTD.
31 */
32class SC_FormParam {
33
34    var $param;
35    var $disp_name;
36    var $keyname;
37    var $length;
38    var $convert;
39    var $arrCheck;
40    var $default;   // 何も入力されていないときに表示する値
41    var $input_db;  // DBにそのまま挿入可能か否か
42    var $html_disp_name;
43
44    // コンストラクタ
45    function SC_FormParam() {
46        $this->check_dir = IMAGE_SAVE_DIR;
47        $this->initParam();
48    }
49
50    /**
51     * パラメータの初期化
52     *
53     * @return void
54     */
55    function initParam() {
56        $this->disp_name = array();
57        $this->keyname = array();
58        $this->length = array();
59        $this->convert = array();
60        $this->arrCheck = array();
61        $this->default = array();
62        $this->input_db = array();
63    }
64
65    // パラメータの追加
66    function addParam($disp_name, $keyname, $length="", $convert="", $arrCheck=array(), $default="", $input_db="true") {
67        $this->disp_name[] = $disp_name;
68        $this->keyname[] = $keyname;
69        $this->length[] = $length;
70        $this->convert[] = $convert;
71        $this->arrCheck[] = $arrCheck;
72        $this->default[] = $default;
73        $this->input_db[] = $input_db;
74    }
75
76    // パラメータの入力
77    // $arrVal  :$arrVal['keyname']・・の配列を一致したキーのインスタンスに格納する
78    // $seq     :trueの場合、$arrVal[0]~の配列を登録順にインスタンスに格納する
79    function setParam($arrVal, $seq = false) {
80        $cnt = 0;
81        if(!$seq){
82            foreach($this->keyname as $val) {
83                if(isset($arrVal[$val])) {
84                    $this->setValue($val, $arrVal[$val]);
85                }
86            }
87        } else {
88            foreach($this->keyname as $val) {
89                $this->param[$cnt] = $arrVal[$cnt];
90                $cnt++;
91            }
92        }
93    }
94
95    // 画面表示用タイトル生成
96    function setHtmlDispNameArray() {
97        $cnt = 0;
98        foreach($this->keyname as $val) {
99            $find = false;
100            foreach($this->arrCheck[$cnt] as $val) {
101                if($val == "EXIST_CHECK") {
102                    $find = true;
103                }
104            }
105
106            if($find) {
107                $this->html_disp_name[$cnt] = $this->disp_name[$cnt] . "<span class='red'>(※ 必須)</span>";
108            } else {
109                $this->html_disp_name[$cnt] = $this->disp_name[$cnt];
110            }
111            $cnt++;
112        }
113    }
114
115    // 画面表示用タイトル取得
116    function getHtmlDispNameArray() {
117        return $this->html_disp_name;
118    }
119
120    // 複数列パラメータの取得
121    function setParamList($arrVal, $keyname) {
122        // DBの件数を取得する。
123        $count = count($arrVal);
124        $no = 1;
125        for($cnt = 0; $cnt < $count; $cnt++) {
126            $key = $keyname.$no;
127            if($arrVal[$cnt][$keyname] != "") {
128                $this->setValue($key, $arrVal[$cnt][$keyname]);
129            }
130            $no++;
131        }
132    }
133
134    function setDBDate($db_date, $year_key = 'year', $month_key = 'month', $day_key = 'day') {
135
136        if (!empty($db_date)) {
137            list($y, $m, $d) = split("[- ]", $db_date);
138            $this->setValue($year_key, $y);
139            $this->setValue($month_key, $m);
140            $this->setValue($day_key, $d);
141        }
142    }
143
144    // キーに対応した値をセットする。
145    function setValue($key, $param) {
146        $cnt = 0;
147        foreach($this->keyname as $val) {
148            if($val == $key) {
149                $this->param[$cnt] = $param;
150                // 複数一致の場合もあるので break してはいけない。
151            }
152            $cnt++;
153        }
154    }
155
156    function toLower($key) {
157        $cnt = 0;
158        foreach($this->keyname as $val) {
159            if($val == $key) {
160                $this->param[$cnt] = strtolower($this->param[$cnt]);
161                // 複数一致の場合もあるので break してはいけない。
162            }
163            $cnt++;
164        }
165    }
166
167    // エラーチェック
168    function checkError($br = true, $keyname = "") {
169        // 連想配列の取得
170        $arrRet = $this->getHashArray($keyname);
171        $objErr = new SC_CheckError($arrRet);
172
173        $cnt = 0;
174        foreach($this->keyname as $val) {
175            foreach($this->arrCheck[$cnt] as $func) {
176                if (!isset($this->param[$cnt])) $this->param[$cnt] = "";
177                switch($func) {
178                case 'EXIST_CHECK':
179                case 'NUM_CHECK':
180                case 'EMAIL_CHECK':
181                case 'EMAIL_CHAR_CHECK':
182                case 'ALNUM_CHECK':
183                case 'GRAPH_CHECK':
184                case 'KANA_CHECK':
185                case 'URL_CHECK':
186                case 'SPTAB_CHECK':
187                case 'ZERO_CHECK':
188                case 'ALPHA_CHECK':
189                case 'ZERO_START':
190                case 'FIND_FILE':
191                case 'NO_SPTAB':
192                case 'DIR_CHECK':
193                case 'DOMAIN_CHECK':
194                case 'FILE_NAME_CHECK':
195                case 'MOBILE_EMAIL_CHECK':
196
197                    if(!is_array($this->param[$cnt])) {
198                        $objErr->doFunc(array($this->disp_name[$cnt], $val), array($func));
199                    } else {
200                        $max = count($this->param[$cnt]);
201                        for($i = 0; $i < $max; $i++) {
202                            $objSubErr = new SC_CheckError($this->param[$cnt]);
203                            $objSubErr->doFunc(array($this->disp_name[$cnt], $i), array($func));
204                            if(count($objSubErr->arrErr) > 0) {
205                                foreach($objSubErr->arrErr as $mess) {
206                                    if($mess != "") {
207                                        $objErr->arrErr[$val] = $mess;
208                                    }
209                                }
210                            }
211                        }
212                    }
213                    break;
214                case 'MAX_LENGTH_CHECK':
215                case 'MIN_LENGTH_CHECK':
216                case 'NUM_COUNT_CHECK':
217                    if(!is_array($this->param[$cnt])) {
218                        $objErr->doFunc(array($this->disp_name[$cnt], $val, $this->length[$cnt]), array($func));
219                    } else {
220                        $max = count($this->param[$cnt]);
221                        for($i = 0; $i < $max; $i++) {
222                            $objSubErr = new SC_CheckError($this->param[$cnt]);
223                            $objSubErr->doFunc(array($this->disp_name[$cnt], $i, $this->length[$cnt]), array($func));
224                            if(count($objSubErr->arrErr) > 0) {
225                                foreach($objSubErr->arrErr as $mess) {
226                                    if($mess != "") {
227                                        $objErr->arrErr[$val] = $mess;
228                                    }
229                                }
230                            }
231                        }
232                    }
233                    break;
234                // 小文字に変換
235                case 'CHANGE_LOWER':
236                    $this->param[$cnt] = strtolower($this->param[$cnt]);
237                    break;
238                // ファイルの存在チェック
239                case 'FILE_EXISTS':
240                    if($this->param[$cnt] != "" && !file_exists($this->check_dir . $this->param[$cnt])) {
241                        $objErr->arrErr[$val] = "※ " . $this->disp_name[$cnt] . "のファイルが存在しません。<br>";
242                    }
243                    break;
244                // ダウンロード用ファイルの存在チェック
245                case 'DOWN_FILE_EXISTS':
246                    if($this->param[$cnt] != "" && !file_exists(DOWN_SAVE_DIR . $this->param[$cnt])) {
247                        $objErr->arrErr[$val] = "※ " . $this->disp_name[$cnt] . "のファイルが存在しません。<br>";
248                    }
249                    break;
250                default:
251                    $objErr->arrErr[$val] = "※※ エラーチェック形式($func)には対応していません ※※ <br>";
252                    break;
253                }
254            }
255
256            if (isset($objErr->arrErr[$val]) && !$br) {
257                $objErr->arrErr[$val] = ereg_replace("<br>$", "", $objErr->arrErr[$val]);
258            }
259            $cnt++;
260        }
261        return $objErr->arrErr;
262    }
263
264    // 入力文字の変換
265    function convParam() {
266        /*
267         *  文字列の変換
268         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
269         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
270         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
271         *  n :  「全角」数字を「半角(ハンカク)」に変換
272         *  a :  「全角」英字を「半角」英字に変換
273         */
274        $cnt = 0;
275        foreach ($this->keyname as $val) {
276            if (!isset($this->param[$cnt])) $this->param[$cnt] = "";
277
278            if(!is_array($this->param[$cnt])) {
279                if($this->convert[$cnt] != "") {
280                    $this->param[$cnt] = mb_convert_kana($this->param[$cnt] ,$this->convert[$cnt]);
281                }
282            } else {
283                $max = count($this->param[$cnt]);
284                for($i = 0; $i < $max; $i++) {
285                    if($this->convert[$cnt] != "") {
286                        $this->param[$cnt][$i] = mb_convert_kana($this->param[$cnt][$i] ,$this->convert[$cnt]);
287                    }
288                }
289            }
290            $cnt++;
291        }
292    }
293
294    // 連想配列の作成
295    function getHashArray($keyname = "") {
296        $arrRet = array();
297        $cnt = 0;
298        foreach($this->keyname as $val) {
299            if($keyname == "" || $keyname == $val) {
300                $arrRet[$val] = isset($this->param[$cnt]) ? $this->param[$cnt] : "";
301                $cnt++;
302            }
303        }
304        return $arrRet;
305    }
306
307    // DB格納用配列の作成
308    function getDbArray() {
309        $cnt = 0;
310        foreach ($this->keyname as $val) {
311            if ($this->input_db[$cnt]) {
312                $arrRet[$val] = isset($this->param[$cnt]) ? $this->param[$cnt] : "";
313            }
314            $cnt++;
315        }
316        return $arrRet;
317    }
318
319    // 配列の縦横を入れ替えて返す
320    function getSwapArray($arrKey) {
321        foreach($arrKey as $keyname) {
322            $arrVal = $this->getValue($keyname);
323            $max = count($arrVal);
324            for($i = 0; $i < $max; $i++) {
325                $arrRet[$i][$keyname] = $arrVal[$i];
326            }
327        }
328        return $arrRet;
329    }
330
331    // 項目名一覧の取得
332    function getTitleArray() {
333        return $this->disp_name;
334    }
335
336    // 項目数を返す
337    function getCount() {
338        $count = count($this->keyname);
339        return $count;
340    }
341
342    // フォームに渡す用のパラメータを返す
343    function getFormParamList() {
344        $cnt = 0;
345        foreach($this->keyname as $val) {
346
347            // キー名
348            $arrRet[$val]['keyname'] = $this->keyname[$cnt];
349            // 文字数制限
350            $arrRet[$val]['length'] = $this->length[$cnt];
351            // 入力値
352            if (isset($this->param[$cnt])) {
353                $arrRet[$val]['value'] = $this->param[$cnt];
354            }
355
356            if (!isset($this->param[$cnt])) $this->param[$cnt] = "";
357
358            if($this->default[$cnt] != "" && $this->param[$cnt] == "") {
359                $arrRet[$val]['value'] = $this->default[$cnt];
360            }
361
362            $cnt++;
363        }
364        return $arrRet;
365    }
366
367    // キー名の一覧を返す
368    function getKeyList() {
369        foreach($this->keyname as $val) {
370            $arrRet[] = $val;
371        }
372        return $arrRet;
373    }
374
375    // キー名と一致した値を返す
376    function getValue($keyname) {
377        $cnt = 0;
378        foreach($this->keyname as $val) {
379            if($val == $keyname) {
380                $ret = isset($this->param[$cnt]) ? $this->param[$cnt] : "";
381                break;
382            }
383            $cnt++;
384        }
385        return $ret;
386    }
387
388    function splitCheckBoxes($keyname) {
389        $cnt = 0;
390        foreach($this->keyname as $val) {
391            if($val == $keyname) {
392                $this->param[$cnt] = sfSplitCheckBoxes($this->param[$cnt]);
393            }
394            $cnt++;
395        }
396    }
397
398    function splitParamCheckBoxes($keyname) {
399        $cnt = 0;
400        foreach($this->keyname as $val) {
401            if($val == $keyname) {
402                if(isset($this->param[$cnt]) && !is_array($this->param[$cnt])) {
403                    $this->param[$cnt] = split("-", $this->param[$cnt]);
404                }
405            }
406            $cnt++;
407        }
408    }
409}
410?>
Note: See TracBrowser for help on using the repository browser.