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

Revision 19854, 14.0 KB checked in by tao, 13 years ago (diff)

#841 インストール画面に管理画面のディレクトリ、SSL制限、IP制限を追加。管理画面でのアクセス制限も追加

  • 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-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_REALDIR;
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            if($this->default[$cnt] != "") {
112                $this->html_disp_name[$cnt] .= ' [省略時初期値: ' . $this->default[$cnt] . ']';
113            }
114            if($this->input_db[$cnt] == false) {
115                $this->html_disp_name[$cnt] .= ' [登録・更新不可] ';
116            }
117            $cnt++;
118        }
119    }
120
121    // 画面表示用タイトル取得
122    function getHtmlDispNameArray() {
123        return $this->html_disp_name;
124    }
125
126    // 複数列パラメータの取得
127    function setParamList($arrVal, $keyname) {
128        // DBの件数を取得する。
129        $count = count($arrVal);
130        $no = 1;
131        for($cnt = 0; $cnt < $count; $cnt++) {
132            $key = $keyname.$no;
133            if($arrVal[$cnt][$keyname] != "") {
134                $this->setValue($key, $arrVal[$cnt][$keyname]);
135            }
136            $no++;
137        }
138    }
139
140    function setDBDate($db_date, $year_key = 'year', $month_key = 'month', $day_key = 'day') {
141
142        if (!empty($db_date)) {
143            list($y, $m, $d) = split("[- ]", $db_date);
144            $this->setValue($year_key, $y);
145            $this->setValue($month_key, $m);
146            $this->setValue($day_key, $d);
147        }
148    }
149
150    // キーに対応した値をセットする。
151    function setValue($key, $param) {
152        $cnt = 0;
153        foreach($this->keyname as $val) {
154            if($val == $key) {
155                $this->param[$cnt] = $param;
156                // 複数一致の場合もあるので break してはいけない。
157            }
158            $cnt++;
159        }
160    }
161
162    function toLower($key) {
163        $cnt = 0;
164        foreach($this->keyname as $val) {
165            if($val == $key) {
166                $this->param[$cnt] = strtolower($this->param[$cnt]);
167                // 複数一致の場合もあるので break してはいけない。
168            }
169            $cnt++;
170        }
171    }
172
173    // エラーチェック
174    function checkError($br = true, $keyname = "") {
175        // 連想配列の取得
176        $arrRet = $this->getHashArray($keyname);
177        $objErr = new SC_CheckError($arrRet);
178
179        $cnt = 0;
180        foreach($this->keyname as $val) {
181            foreach($this->arrCheck[$cnt] as $func) {
182                if (!isset($this->param[$cnt])) $this->param[$cnt] = "";
183                switch($func) {
184                case 'EXIST_CHECK':
185                case 'NUM_CHECK':
186                case 'EMAIL_CHECK':
187                case 'EMAIL_CHAR_CHECK':
188                case 'ALNUM_CHECK':
189                case 'GRAPH_CHECK':
190                case 'KANA_CHECK':
191                case 'URL_CHECK':
192                case 'IP_CHECK':
193                case 'SPTAB_CHECK':
194                case 'ZERO_CHECK':
195                case 'ALPHA_CHECK':
196                case 'ZERO_START':
197                case 'FIND_FILE':
198                case 'NO_SPTAB':
199                case 'DIR_CHECK':
200                case 'DOMAIN_CHECK':
201                case 'FILE_NAME_CHECK':
202                case 'MOBILE_EMAIL_CHECK':
203
204                    if(!is_array($this->param[$cnt])) {
205                        $objErr->doFunc(array($this->disp_name[$cnt], $val), array($func));
206                    } else {
207                        $max = count($this->param[$cnt]);
208                        for($i = 0; $i < $max; $i++) {
209                            $objSubErr = new SC_CheckError($this->param[$cnt]);
210                            $objSubErr->doFunc(array($this->disp_name[$cnt], $i), array($func));
211                            if(count($objSubErr->arrErr) > 0) {
212                                foreach($objSubErr->arrErr as $mess) {
213                                    if($mess != "") {
214                                        $objErr->arrErr[$val] = $mess;
215                                    }
216                                }
217                            }
218                        }
219                    }
220                    break;
221                case 'MAX_LENGTH_CHECK':
222                case 'MIN_LENGTH_CHECK':
223                case 'NUM_COUNT_CHECK':
224                    if(!is_array($this->param[$cnt])) {
225                        $objErr->doFunc(array($this->disp_name[$cnt], $val, $this->length[$cnt]), array($func));
226                    } else {
227                        $max = count($this->param[$cnt]);
228                        for($i = 0; $i < $max; $i++) {
229                            $objSubErr = new SC_CheckError($this->param[$cnt]);
230                            $objSubErr->doFunc(array($this->disp_name[$cnt], $i, $this->length[$cnt]), array($func));
231                            if(count($objSubErr->arrErr) > 0) {
232                                foreach($objSubErr->arrErr as $mess) {
233                                    if($mess != "") {
234                                        $objErr->arrErr[$val] = $mess;
235                                    }
236                                }
237                            }
238                        }
239                    }
240                    break;
241                // 小文字に変換
242                case 'CHANGE_LOWER':
243                    $this->param[$cnt] = strtolower($this->param[$cnt]);
244                    break;
245                // ファイルの存在チェック
246                case 'FILE_EXISTS':
247                    if($this->param[$cnt] != "" && !file_exists($this->check_dir . $this->param[$cnt])) {
248                        $objErr->arrErr[$val] = "※ " . $this->disp_name[$cnt] . "のファイルが存在しません。<br>";
249                    }
250                    break;
251                // ダウンロード用ファイルの存在チェック
252                case 'DOWN_FILE_EXISTS':
253                    if($this->param[$cnt] != "" && !file_exists(DOWN_SAVE_REALDIR . $this->param[$cnt])) {
254                        $objErr->arrErr[$val] = "※ " . $this->disp_name[$cnt] . "のファイルが存在しません。<br>";
255                    }
256                    break;
257                default:
258                    $objErr->arrErr[$val] = "※※ エラーチェック形式($func)には対応していません ※※ <br>";
259                    break;
260                }
261            }
262
263            if (isset($objErr->arrErr[$val]) && !$br) {
264                $objErr->arrErr[$val] = ereg_replace("<br>$", "", $objErr->arrErr[$val]);
265            }
266            $cnt++;
267        }
268        return $objErr->arrErr;
269    }
270
271    // 入力文字の変換
272    function convParam() {
273        /*
274         *  文字列の変換
275         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
276         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
277         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
278         *  n :  「全角」数字を「半角(ハンカク)」に変換
279         *  a :  「全角」英字を「半角」英字に変換
280         */
281        $cnt = 0;
282        foreach ($this->keyname as $val) {
283            if (!isset($this->param[$cnt])) $this->param[$cnt] = "";
284
285            if(!is_array($this->param[$cnt])) {
286                if($this->convert[$cnt] != "") {
287                    $this->param[$cnt] = mb_convert_kana($this->param[$cnt] ,$this->convert[$cnt]);
288                }
289            } else {
290                $max = count($this->param[$cnt]);
291                for($i = 0; $i < $max; $i++) {
292                    if($this->convert[$cnt] != "") {
293                        $this->param[$cnt][$i] = mb_convert_kana($this->param[$cnt][$i] ,$this->convert[$cnt]);
294                    }
295                }
296            }
297            $cnt++;
298        }
299    }
300
301    // 連想配列の作成
302    function getHashArray($keyname = "") {
303        $arrRet = array();
304        $cnt = 0;
305        foreach($this->keyname as $val) {
306            if($keyname == "" || $keyname == $val) {
307                $arrRet[$val] = isset($this->param[$cnt]) ? $this->param[$cnt] : "";
308                $cnt++;
309            }
310        }
311        return $arrRet;
312    }
313
314    // DB格納用配列の作成
315    function getDbArray() {
316        $cnt = 0;
317        foreach ($this->keyname as $val) {
318            if ($this->input_db[$cnt]) {
319                $arrRet[$val] = isset($this->param[$cnt]) ? $this->param[$cnt] : "";
320            }
321            $cnt++;
322        }
323        return $arrRet;
324    }
325
326    // 配列の縦横を入れ替えて返す
327    function getSwapArray($arrKey) {
328        foreach($arrKey as $keyname) {
329            $arrVal = $this->getValue($keyname);
330            $max = count($arrVal);
331            for($i = 0; $i < $max; $i++) {
332                $arrRet[$i][$keyname] = $arrVal[$i];
333            }
334        }
335        return $arrRet;
336    }
337
338    // 項目名一覧の取得
339    function getTitleArray() {
340        return $this->disp_name;
341    }
342
343    // 項目数を返す
344    function getCount() {
345        $count = count($this->keyname);
346        return $count;
347    }
348
349    // フォームに渡す用のパラメータを返す
350    function getFormParamList() {
351        $cnt = 0;
352        foreach($this->keyname as $val) {
353
354            // キー名
355            $arrRet[$val]['keyname'] = $this->keyname[$cnt];
356            // 文字数制限
357            $arrRet[$val]['length'] = $this->length[$cnt];
358            // 入力値
359            if (isset($this->param[$cnt])) {
360                $arrRet[$val]['value'] = $this->param[$cnt];
361            }
362
363            if (!isset($this->param[$cnt])) $this->param[$cnt] = "";
364
365            if($this->default[$cnt] != "" && $this->param[$cnt] == "") {
366                $arrRet[$val]['value'] = $this->default[$cnt];
367            }
368
369            $cnt++;
370        }
371        return $arrRet;
372    }
373
374    // キー名の一覧を返す
375    function getKeyList() {
376        foreach($this->keyname as $val) {
377            $arrRet[] = $val;
378        }
379        return $arrRet;
380    }
381
382    // キー名と一致した値を返す
383    function getValue($keyname) {
384        $cnt = 0;
385        foreach($this->keyname as $val) {
386            if($val == $keyname) {
387                $ret = isset($this->param[$cnt]) ? $this->param[$cnt] : "";
388                break;
389            }
390            $cnt++;
391        }
392        return $ret;
393    }
394
395    function splitCheckBoxes($keyname) {
396        $cnt = 0;
397        foreach($this->keyname as $val) {
398            if($val == $keyname) {
399                $this->param[$cnt] = sfSplitCheckBoxes($this->param[$cnt]);
400            }
401            $cnt++;
402        }
403    }
404
405    function splitParamCheckBoxes($keyname) {
406        $cnt = 0;
407        foreach($this->keyname as $val) {
408            if($val == $keyname) {
409                if(isset($this->param[$cnt]) && !is_array($this->param[$cnt])) {
410                    $this->param[$cnt] = split("-", $this->param[$cnt]);
411                }
412            }
413            $cnt++;
414        }
415    }
416}
417?>
Note: See TracBrowser for help on using the repository browser.