source: branches/version-2/data/class/SC_FormParam.php @ 17411

Revision 17411, 12.8 KB checked in by satou, 16 years ago (diff)

英数記号チェック(GRAPH_CHECK)の追加

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