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 | |
---|
24 | /*---------------------------------------------------------------------- |
---|
25 | * [名称] SC_CheckError |
---|
26 | * [概要] エラーチェッククラス |
---|
27 | *---------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | class SC_CheckError |
---|
30 | { |
---|
31 | var $arrErr = array(); |
---|
32 | var $arrParam; |
---|
33 | |
---|
34 | // チェック対象の値が含まれる配列をセットする。 |
---|
35 | function __construct($array = '') |
---|
36 | { |
---|
37 | if ($array != '') { |
---|
38 | $this->arrParam = $array; |
---|
39 | } else { |
---|
40 | $this->arrParam = $_POST; |
---|
41 | } |
---|
42 | |
---|
43 | } |
---|
44 | |
---|
45 | function doFunc($value, $arrFunc) |
---|
46 | { |
---|
47 | foreach ($arrFunc as $key) { |
---|
48 | $this->$key($value); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * HTMLのタグをチェックする |
---|
54 | * |
---|
55 | * @param array $value value[0] = 項目名 value[1] = 判定対象 value[2] = 許可するタグが格納された配列 |
---|
56 | * @return void |
---|
57 | */ |
---|
58 | function HTML_TAG_CHECK($value) |
---|
59 | { |
---|
60 | if (isset($this->arrErr[$value[1]])) { |
---|
61 | return; |
---|
62 | } |
---|
63 | $this->createParam($value); |
---|
64 | // HTMLに含まれているタグを抽出する |
---|
65 | preg_match_all('/<\/?([a-z]+)/i', $this->arrParam[$value[1]], $arrTagIncludedHtml); |
---|
66 | |
---|
67 | $arrDiffTag = array_diff($arrTagIncludedHtml[1], $value[2]); |
---|
68 | |
---|
69 | if (empty($arrDiffTag)) return; |
---|
70 | |
---|
71 | // 少々荒っぽいが、表示用 HTML に変換する |
---|
72 | foreach ($arrDiffTag as &$tag) { |
---|
73 | $tag = '[' . htmlspecialchars($tag) . ']'; |
---|
74 | } |
---|
75 | $html_diff_tag_list = implode(', ', $arrDiffTag); |
---|
76 | |
---|
77 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'に許可されていないタグ ' . $html_diff_tag_list . ' が含まれています。<br />'; |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * 必須入力の判定 |
---|
82 | * |
---|
83 | * 受け取りがない場合エラーを返す |
---|
84 | * @param array $value value[0] = 項目名 value[1] = 判定対象 |
---|
85 | * @return void |
---|
86 | */ |
---|
87 | function EXIST_CHECK($value) |
---|
88 | { |
---|
89 | if (isset($this->arrErr[$value[1]])) { |
---|
90 | return; |
---|
91 | } |
---|
92 | $this->createParam($value); |
---|
93 | if (!is_array($this->arrParam[$value[1]]) && strlen($this->arrParam[$value[1]]) == 0) { |
---|
94 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'が入力されていません。<br />'; |
---|
95 | } else if (is_array($this->arrParam[$value[1]]) && count($this->arrParam[$value[1]]) == 0) { |
---|
96 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'が選択されていません。<br />'; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * 必須入力の判定(逆順) |
---|
102 | * |
---|
103 | * 受け取りがない場合エラーを返す |
---|
104 | * @param array $value value[0] = 判定対象 value[1] = 項目名 |
---|
105 | * @return void |
---|
106 | */ |
---|
107 | function EXIST_CHECK_REVERSE($value) |
---|
108 | { |
---|
109 | if (isset($this->arrErr[$value[0]])) { |
---|
110 | return; |
---|
111 | } |
---|
112 | $this->createParam($value); |
---|
113 | if (strlen($this->arrParam[$value[0]]) == 0) { |
---|
114 | $this->arrErr[$value[0]] = '※ ' . $value[0] . 'が入力されていません。<br />'; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * スペース、タブの判定 |
---|
120 | * |
---|
121 | * 受け取りがない場合エラーを返す |
---|
122 | * @param array $value value[0] = 項目名 value[1] = 判定対象 |
---|
123 | * @return void |
---|
124 | */ |
---|
125 | function SPTAB_CHECK($value) |
---|
126 | { |
---|
127 | if (isset($this->arrErr[$value[1]])) { |
---|
128 | return; |
---|
129 | } |
---|
130 | $this->createParam($value); |
---|
131 | if (strlen($this->arrParam[$value[1]]) != 0 && preg_match("/^[ \t\r\n]+$/", $this->arrParam[$value[1]])) { |
---|
132 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'にスペース、タブ、改行のみの入力はできません。<br />'; |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * スペース、タブの判定 |
---|
138 | * |
---|
139 | * 受け取りがない場合エラーを返す |
---|
140 | * @param array $value value[0] = 項目名 value[1] = 判定対象 |
---|
141 | * @return void |
---|
142 | */ |
---|
143 | function NO_SPTAB($value) |
---|
144 | { |
---|
145 | if (isset($this->arrErr[$value[1]])) { |
---|
146 | return; |
---|
147 | } |
---|
148 | $this->createParam($value); |
---|
149 | if (strlen($this->arrParam[$value[1]]) != 0 && preg_match("/[ \t\r\n]+/u", $this->arrParam[$value[1]])) { |
---|
150 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'にスペース、タブ、改行は含めないで下さい。<br />'; |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | /* ゼロで開始されている数値の判定 */ |
---|
155 | function ZERO_START($value) |
---|
156 | { |
---|
157 | if (isset($this->arrErr[$value[1]])) { |
---|
158 | return; |
---|
159 | } |
---|
160 | $this->createParam($value); |
---|
161 | if (strlen($this->arrParam[$value[1]]) != 0 && preg_match("/^[0]+[0-9]+$/", $this->arrParam[$value[1]])) { |
---|
162 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'に0で始まる数値が入力されています。<br />'; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | /** |
---|
167 | * 必須選択の判定 |
---|
168 | * |
---|
169 | * プルダウンなどで選択されていない場合エラーを返す |
---|
170 | * @param array $value value[0] = 項目名 value[1] = 判定対象 |
---|
171 | * @return void |
---|
172 | */ |
---|
173 | function SELECT_CHECK($value) |
---|
174 | { |
---|
175 | if (isset($this->arrErr[$value[1]])) { |
---|
176 | return; |
---|
177 | } |
---|
178 | $this->createParam($value); |
---|
179 | if (strlen($this->arrParam[$value[1]]) == 0) { |
---|
180 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'が選択されていません。<br />'; |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | /** |
---|
185 | * 同一性の判定 |
---|
186 | * |
---|
187 | * 入力が指定文字数以上ならエラーを返す |
---|
188 | * @param array $value value[0] = 項目名1 value[1] = 項目名2 value[2] = 判定対象文字列1 value[3] = 判定対象文字列2 |
---|
189 | * @return void |
---|
190 | */ |
---|
191 | function EQUAL_CHECK($value) |
---|
192 | { |
---|
193 | if (isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[3]])) { |
---|
194 | return; |
---|
195 | } |
---|
196 | $this->createParam($value); |
---|
197 | // 文字数の取得 |
---|
198 | if ($this->arrParam[$value[2]] !== $this->arrParam[$value[3]]) { |
---|
199 | $this->arrErr[$value[2]] = '※ ' . $value[0] . 'と' . $value[1] . 'が一致しません。<br />'; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * 値が異なることの判定 |
---|
205 | * |
---|
206 | * 入力が指定文字数以上ならエラーを返す |
---|
207 | * @param array $value value[0] = 項目名1 value[1] = 項目名2 value[2] = 判定対象文字列1 value[3] = 判定対象文字列2 |
---|
208 | * @return void |
---|
209 | */ |
---|
210 | function DIFFERENT_CHECK($value) |
---|
211 | { |
---|
212 | if (isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[3]])) { |
---|
213 | return; |
---|
214 | } |
---|
215 | $this->createParam($value); |
---|
216 | // 文字数の取得 |
---|
217 | if ($this->arrParam[$value[2]] == $this->arrParam[$value[3]]) { |
---|
218 | $this->arrErr[$value[2]] = '※ ' . $value[0] . 'と' . $value[1] . 'は、同じ値を使用できません。<br />'; |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | /** |
---|
223 | * 値の大きさを比較する value[2] < value[3]でなければエラー |
---|
224 | * |
---|
225 | * 入力が指定文字数以上ならエラーを返す |
---|
226 | * @param array $value value[0] = 項目名1 value[1] = 項目名2 value[2] = 判定対象文字列1 value[3] = 判定対象文字列2 |
---|
227 | * @return void |
---|
228 | */ |
---|
229 | function GREATER_CHECK($value) |
---|
230 | { |
---|
231 | if (isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[3]])) { |
---|
232 | return; |
---|
233 | } |
---|
234 | $this->createParam($value); |
---|
235 | // 文字数の取得 |
---|
236 | if ($this->arrParam[$value[2]] != '' && $this->arrParam[$value[3]] != '' && ($this->arrParam[$value[2]] > $this->arrParam[$value[3]])) { |
---|
237 | $this->arrErr[$value[2]] = '※ ' . $value[0] . 'は' . $value[1] . 'より大きい値を入力できません。<br />'; |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | /** |
---|
242 | * 最大文字数制限の判定 |
---|
243 | * |
---|
244 | * 入力が指定文字数以上ならエラーを返す |
---|
245 | * @param array $value value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最大文字数(半角も全角も1文字として数える) |
---|
246 | * @return void |
---|
247 | */ |
---|
248 | function MAX_LENGTH_CHECK($value) |
---|
249 | { |
---|
250 | if (isset($this->arrErr[$value[1]])) { |
---|
251 | return; |
---|
252 | } |
---|
253 | $this->createParam($value); |
---|
254 | // 文字数の取得 |
---|
255 | if (mb_strlen($this->arrParam[$value[1]]) > $value[2]) { |
---|
256 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は' . $value[2] . '字以下で入力してください。<br />'; |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | /** |
---|
261 | * 最小文字数制限の判定 |
---|
262 | * |
---|
263 | * 入力が指定文字数未満ならエラーを返す |
---|
264 | * @param array $value value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最小文字数(半角も全角も1文字として数える) |
---|
265 | * @return void |
---|
266 | */ |
---|
267 | function MIN_LENGTH_CHECK($value) |
---|
268 | { |
---|
269 | if (isset($this->arrErr[$value[1]])) { |
---|
270 | return; |
---|
271 | } |
---|
272 | $this->createParam($value); |
---|
273 | // 文字数の取得 |
---|
274 | if (mb_strlen($this->arrParam[$value[1]]) < $value[2]) { |
---|
275 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は' . $value[2] . '字以上で入力してください。<br />'; |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | /** |
---|
280 | * 最大文字数制限の判定 |
---|
281 | * |
---|
282 | * 入力が最大数以上ならエラーを返す |
---|
283 | * @param array $value value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最大数] |
---|
284 | * @return void |
---|
285 | */ |
---|
286 | function MAX_CHECK($value) |
---|
287 | { |
---|
288 | if (isset($this->arrErr[$value[1]])) { |
---|
289 | return; |
---|
290 | } |
---|
291 | $this->createParam($value); |
---|
292 | // 文字数の取得 |
---|
293 | if ($this->arrParam[$value[1]] > $value[2]) { |
---|
294 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は' . $value[2] . '以下で入力してください。<br />'; |
---|
295 | } |
---|
296 | } |
---|
297 | |
---|
298 | /** |
---|
299 | * 最小数値制限の判定 |
---|
300 | * |
---|
301 | * 入力が最小数未満ならエラーを返す |
---|
302 | * @param array $value value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最小数 |
---|
303 | * @return void |
---|
304 | */ |
---|
305 | function MIN_CHECK($value) |
---|
306 | { |
---|
307 | if (isset($this->arrErr[$value[1]])) { |
---|
308 | return; |
---|
309 | } |
---|
310 | $this->createParam($value); |
---|
311 | if ($this->arrParam[$value[1]] < $value[2]) { |
---|
312 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は' . $value[2] . '以上で入力してください。<br />'; |
---|
313 | } |
---|
314 | } |
---|
315 | |
---|
316 | /** |
---|
317 | * 数字の判定 |
---|
318 | * |
---|
319 | * 入力文字が数字以外ならエラーを返す |
---|
320 | * @param array $value value[0] = 項目名 value[1] = 判定対象文字列 |
---|
321 | * @return void |
---|
322 | */ |
---|
323 | function NUM_CHECK($value) |
---|
324 | { |
---|
325 | if (isset($this->arrErr[$value[1]])) { |
---|
326 | return; |
---|
327 | } |
---|
328 | $this->createParam($value); |
---|
329 | if ($this->numelicCheck($this->arrParam[$value[1]])) { |
---|
330 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は数字で入力してください。<br />'; |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | /** |
---|
335 | * 小数点を含む数字の判定 |
---|
336 | * |
---|
337 | * 入力文字が数字以外ならエラーを返す |
---|
338 | * @param array $value value[0] = 項目名 value[1] = 判定対象文字列 |
---|
339 | * @return void |
---|
340 | */ |
---|
341 | function NUM_POINT_CHECK($value) |
---|
342 | { |
---|
343 | if (isset($this->arrErr[$value[1]])) { |
---|
344 | return; |
---|
345 | } |
---|
346 | $this->createParam($value); |
---|
347 | if (strlen($this->arrParam[$value[1]]) > 0 && !is_numeric($this->arrParam[$value[1]])) { |
---|
348 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は数字で入力してください。<br />'; |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | function ALPHA_CHECK($value) |
---|
353 | { |
---|
354 | if (isset($this->arrErr[$value[1]])) { |
---|
355 | return; |
---|
356 | } |
---|
357 | $this->createParam($value); |
---|
358 | if (strlen($this->arrParam[$value[1]]) > 0 && !ctype_alpha($this->arrParam[$value[1]])) { |
---|
359 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は半角英字で入力してください。<br />'; |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | /** |
---|
364 | * 電話番号の判定 |
---|
365 | * |
---|
366 | * 数字チェックと文字数チェックを実施する。 |
---|
367 | * @param array $value 各要素は以下の通り。<br> |
---|
368 | * [0]: 項目名<br> |
---|
369 | * [1]: 電番1項目目<br> |
---|
370 | * [2]: 電番2項目目<br> |
---|
371 | * [3]: 電番3項目目<br> |
---|
372 | * [4]: 電話番号各項目制限 (指定なしの場合、TEL_ITEM_LEN)<br> |
---|
373 | * [5]: 電話番号総数 (指定なしの場合、TEL_LEN) |
---|
374 | * @return void |
---|
375 | */ |
---|
376 | function TEL_CHECK($value) |
---|
377 | { |
---|
378 | $telItemLen = isset($value[4]) ? $value[4] : TEL_ITEM_LEN; |
---|
379 | $telLen = isset($value[5]) ? $value[5] : TEL_LEN; |
---|
380 | |
---|
381 | if (isset($this->arrErr[$value[1]]) || isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[3]])) { |
---|
382 | return; |
---|
383 | } |
---|
384 | $this->createParam($value); |
---|
385 | $cnt = 0; |
---|
386 | |
---|
387 | for ($i = 1; $i <= 3; $i++) { |
---|
388 | if (strlen($this->arrParam[$value[$i]]) > 0) { |
---|
389 | $cnt++; |
---|
390 | } |
---|
391 | } |
---|
392 | |
---|
393 | // すべての項目が満たされていない場合を判定(一部だけ入力されている状態) |
---|
394 | if ($cnt > 0 && $cnt < 3) { |
---|
395 | $this->arrErr[$value[1]] .= '※ ' . $value[0] . 'はすべての項目を入力してください。<br />'; |
---|
396 | } |
---|
397 | |
---|
398 | $total_count = 0; |
---|
399 | for ($i = 1; $i <= 3; $i++) { |
---|
400 | if (strlen($this->arrParam[$value[$i]]) > 0 && strlen($this->arrParam[$value[$i]]) > $telItemLen) { |
---|
401 | $this->arrErr[$value[$i]] .= '※ ' . $value[0] . $i . 'は' . $telItemLen . '字以内で入力してください。<br />'; |
---|
402 | } else if ($this->numelicCheck($this->arrParam[$value[1]])) { |
---|
403 | $this->arrErr[$value[$i]] .= '※ ' . $value[0] . $i . 'は数字で入力してください。<br />'; |
---|
404 | } |
---|
405 | $total_count += strlen($this->arrParam[$value[$i]]); |
---|
406 | } |
---|
407 | |
---|
408 | // 合計値チェック |
---|
409 | if ($total_count > $telLen) { |
---|
410 | $this->arrErr[$value[3]] .= '※ ' . $value[0] . 'は' . $telLen . '文字以内で入力してください。<br />'; |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | /* 関連項目が完全に満たされているか判定 |
---|
415 | value[0] : 項目名 |
---|
416 | value[1] : 判定対象要素名 |
---|
417 | */ |
---|
418 | function FULL_EXIST_CHECK($value) |
---|
419 | { |
---|
420 | $max = count($value); |
---|
421 | $this->createParam($value); |
---|
422 | // 既に該当項目にエラーがある場合は、判定しない。 |
---|
423 | for ($i = 1; $i < $max; $i++) { |
---|
424 | if (isset($this->arrErr[$value[$i]])) { |
---|
425 | return; |
---|
426 | } |
---|
427 | } |
---|
428 | |
---|
429 | // すべての項目が入力されていない場合はエラーとする。 |
---|
430 | $blank = false; |
---|
431 | |
---|
432 | for ($i = 1; $i < $max; $i++) { |
---|
433 | if (strlen($this->arrParam[$value[$i]]) <= 0) { |
---|
434 | $blank = true; |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | if ($blank) { |
---|
439 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'が入力されていません。<br />'; |
---|
440 | } |
---|
441 | } |
---|
442 | |
---|
443 | /* 関連項目がすべて満たされているか判定 |
---|
444 | value[0] : 項目名 |
---|
445 | value[1] : 判定対象要素名 |
---|
446 | */ |
---|
447 | function ALL_EXIST_CHECK($value) |
---|
448 | { |
---|
449 | $max = count($value); |
---|
450 | |
---|
451 | // 既に該当項目にエラーがある場合は、判定しない。 |
---|
452 | for ($i = 1; $i < $max; $i++) { |
---|
453 | if (isset($this->arrErr[$value[$i]])) { |
---|
454 | return; |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | $blank = false; |
---|
459 | $input = false; |
---|
460 | |
---|
461 | // すべての項目がブランクでないか、すべての項目が入力されていない場合はエラーとする。 |
---|
462 | for ($i = 1; $i < $max; $i++) { |
---|
463 | if (strlen($this->arrParam[$value[$i]]) <= 0) { |
---|
464 | $blank = true; |
---|
465 | } else { |
---|
466 | $input = true; |
---|
467 | } |
---|
468 | } |
---|
469 | |
---|
470 | if ($blank && $input) { |
---|
471 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'はすべての項目を入力して下さい。<br />'; |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | /* 関連項目がどれか一つ満たされているか判定 |
---|
476 | value[0] : 項目名 |
---|
477 | value[1] : 判定対象要素名 |
---|
478 | */ |
---|
479 | function ONE_EXIST_CHECK($value) |
---|
480 | { |
---|
481 | $max = count($value); |
---|
482 | $this->createParam($value); |
---|
483 | // 既に該当項目にエラーがある場合は、判定しない。 |
---|
484 | for ($i = 1; $i < $max; $i++) { |
---|
485 | if (isset($this->arrErr[$value[$i]])) { |
---|
486 | return; |
---|
487 | } |
---|
488 | } |
---|
489 | |
---|
490 | $input = false; |
---|
491 | |
---|
492 | // すべての項目がブランクでないか、すべての項目が入力されていない場合はエラーとする。 |
---|
493 | for ($i = 1; $i < $max; $i++) { |
---|
494 | if (strlen($this->arrParam[$value[$i]]) > 0) { |
---|
495 | $input = true; |
---|
496 | } |
---|
497 | } |
---|
498 | |
---|
499 | if (!$input) { |
---|
500 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'が入力されていません。<br />'; |
---|
501 | } |
---|
502 | } |
---|
503 | |
---|
504 | /* 上位の項目が満たされているか判定 |
---|
505 | value[0] : 項目名 |
---|
506 | value[1] : 判定対象要素名 |
---|
507 | */ |
---|
508 | function TOP_EXIST_CHECK($value) |
---|
509 | { |
---|
510 | $max = count($value); |
---|
511 | $this->createParam($value); |
---|
512 | |
---|
513 | // 既に該当項目にエラーがある場合は、判定しない。 |
---|
514 | for ($i = 1; $i < $max; $i++) { |
---|
515 | if (isset($this->arrErr[$value[$i]])) { |
---|
516 | return; |
---|
517 | } |
---|
518 | } |
---|
519 | |
---|
520 | $blank = false; |
---|
521 | $error = false; |
---|
522 | |
---|
523 | // すべての項目がブランクでないか、すべての項目が入力されていない場合はエラーとする。 |
---|
524 | for ($i = 1; $i < $max; $i++) { |
---|
525 | if (strlen($this->arrParam[$value[$i]]) <= 0) { |
---|
526 | $blank = true; |
---|
527 | } else { |
---|
528 | if ($blank) { |
---|
529 | $error = true; |
---|
530 | } |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | if ($error) { |
---|
535 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は先頭の項目から順番に入力して下さい。<br />'; |
---|
536 | } |
---|
537 | } |
---|
538 | |
---|
539 | /* カタカナの判定 */ |
---|
540 | // 入力文字がカナ以外ならエラーを返す |
---|
541 | // value[0] = 項目名 value[1] = 判定対象文字列 |
---|
542 | function KANA_CHECK($value) |
---|
543 | { |
---|
544 | if (isset($this->arrErr[$value[1]])) { |
---|
545 | return; |
---|
546 | } |
---|
547 | $this->createParam($value); |
---|
548 | if (strlen($this->arrParam[$value[1]]) > 0 && !preg_match("/^[ァ-ヶヲ-゚ー]+$/u", $this->arrParam[$value[1]])) { |
---|
549 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'はカタカナで入力してください。<br />'; |
---|
550 | } |
---|
551 | } |
---|
552 | |
---|
553 | /* カタカナの判定2 (タブ、スペースは許可する) */ |
---|
554 | // 入力文字がカナ以外ならエラーを返す |
---|
555 | // value[0] = 項目名 value[1] = 判定対象文字列 |
---|
556 | function KANABLANK_CHECK($value) |
---|
557 | { |
---|
558 | if (isset($this->arrErr[$value[1]])) { |
---|
559 | return; |
---|
560 | } |
---|
561 | $this->createParam($value); |
---|
562 | if (strlen($this->arrParam[$value[1]]) > 0 && !preg_match("/^([ \t\r\n]|[ァ-ヶ]|[ー])+$/u", $this->arrParam[$value[1]])) { |
---|
563 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'はカタカナで入力してください。<br />'; |
---|
564 | } |
---|
565 | } |
---|
566 | |
---|
567 | /* 英数字の判定 */ |
---|
568 | // 入力文字が英数字以外ならエラーを返す |
---|
569 | // value[0] = 項目名 value[1] = 判定対象文字列 |
---|
570 | function ALNUM_CHECK($value) |
---|
571 | { |
---|
572 | if (isset($this->arrErr[$value[1]])) { |
---|
573 | return; |
---|
574 | } |
---|
575 | $this->createParam($value); |
---|
576 | if (strlen($this->arrParam[$value[1]]) > 0 && !ctype_alnum($this->arrParam[$value[1]])) { |
---|
577 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は英数字で入力してください。<br />'; |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | /* 英数記号の判定 */ |
---|
582 | // 入力文字が英数記号以外ならエラーを返す |
---|
583 | // value[0] = 項目名 value[1] = 判定対象文字列 |
---|
584 | function GRAPH_CHECK($value) |
---|
585 | { |
---|
586 | if (isset($this->arrErr[$value[1]])) { |
---|
587 | return; |
---|
588 | } |
---|
589 | $this->createParam($value); |
---|
590 | if (strlen($this->arrParam[$value[1]]) > 0 && !preg_match("/^[[:graph:][:space:]]+$/i", $this->arrParam[$value[1]])) { |
---|
591 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は英数記号で入力してください。<br />'; |
---|
592 | } |
---|
593 | } |
---|
594 | |
---|
595 | /* 必須選択の判定 */ |
---|
596 | // 入力値で0が許されない場合エラーを返す |
---|
597 | // value[0] = 項目名 value[1] = 判定対象 |
---|
598 | function ZERO_CHECK($value) |
---|
599 | { |
---|
600 | $this->createParam($value); |
---|
601 | if ($this->arrParam[$value[1]] == '0') { |
---|
602 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は1以上を入力してください。<br />'; |
---|
603 | } |
---|
604 | } |
---|
605 | |
---|
606 | /* 桁数の判定 (最小最大)*/ |
---|
607 | // 入力文字の桁数判定 → 最小桁数<入力文字列<最大桁数 |
---|
608 | // value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最小桁数 value[3] = 最大桁数 |
---|
609 | function NUM_RANGE_CHECK($value) |
---|
610 | { |
---|
611 | if (isset($this->arrErr[$value[1]])) { |
---|
612 | return; |
---|
613 | } |
---|
614 | $this->createParam($value); |
---|
615 | // $this->arrParam[$value[0]] = mb_convert_kana($this->arrParam[$value[0]], 'n'); |
---|
616 | $count = strlen($this->arrParam[$value[1]]); |
---|
617 | if (($count > 0) && $value[2] > $count || $value[3] < $count) { |
---|
618 | $this->arrErr[$value[1]] = "※ $value[0]は$value[2]桁~$value[3]桁で入力して下さい。<br />"; |
---|
619 | } |
---|
620 | } |
---|
621 | |
---|
622 | /* 桁数の判定 */ |
---|
623 | // 入力文字の桁数判定 → 入力文字列 = 桁数 以外はNGの場合 |
---|
624 | // value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 桁数 |
---|
625 | function NUM_COUNT_CHECK($value) |
---|
626 | { |
---|
627 | if (isset($this->arrErr[$value[1]])) { |
---|
628 | return; |
---|
629 | } |
---|
630 | $this->createParam($value); |
---|
631 | $count = strlen($this->arrParam[$value[1]]); |
---|
632 | if (($count > 0) && $count != $value[2]) { |
---|
633 | $this->arrErr[$value[1]] = "※ $value[0]は$value[2]桁で入力して下さい。<br />"; |
---|
634 | } |
---|
635 | } |
---|
636 | |
---|
637 | /** |
---|
638 | * メールアドレス形式の判定 |
---|
639 | * |
---|
640 | * @param array $value 各要素は以下の通り。<br> |
---|
641 | * [0]: 項目名<br> |
---|
642 | * [1]: 判定対象を格納している配列キー |
---|
643 | * @return void |
---|
644 | */ |
---|
645 | function EMAIL_CHECK($value) |
---|
646 | { |
---|
647 | if (isset($this->arrErr[$value[1]])) { |
---|
648 | return; |
---|
649 | } |
---|
650 | |
---|
651 | $this->createParam($value); |
---|
652 | |
---|
653 | // 入力がない場合処理しない |
---|
654 | if (strlen($this->arrParam[$value[1]]) === 0) { |
---|
655 | return; |
---|
656 | } |
---|
657 | |
---|
658 | $wsp = '[\x20\x09]'; |
---|
659 | $vchar = '[\x21-\x7e]'; |
---|
660 | $quoted_pair = "\\\\(?:$vchar|$wsp)"; |
---|
661 | $qtext = '[\x21\x23-\x5b\x5d-\x7e]'; |
---|
662 | $qcontent = "(?:$qtext|$quoted_pair)"; |
---|
663 | $quoted_string = "\"$qcontent*\""; |
---|
664 | $atext = '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]'; |
---|
665 | $dot_atom = "$atext+(?:[.]$atext+)*"; |
---|
666 | $local_part = "(?:$dot_atom|$quoted_string)"; |
---|
667 | $domain = $dot_atom; |
---|
668 | $addr_spec = "{$local_part}[@]$domain"; |
---|
669 | |
---|
670 | $dot_atom_loose = "$atext+(?:[.]|$atext)*"; |
---|
671 | $local_part_loose = "(?:$dot_atom_loose|$quoted_string)"; |
---|
672 | $addr_spec_loose = "{$local_part_loose}[@]$domain"; |
---|
673 | |
---|
674 | if (RFC_COMPLIANT_EMAIL_CHECK) { |
---|
675 | $regexp = "/\A{$addr_spec}\z/"; |
---|
676 | } else { |
---|
677 | // 携帯メールアドレス用に、..や.@を許容する。 |
---|
678 | $regexp = "/\A{$addr_spec_loose}\z/"; |
---|
679 | } |
---|
680 | |
---|
681 | if (!preg_match($regexp, $this->arrParam[$value[1]])) { |
---|
682 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'の形式が不正です。<br />'; |
---|
683 | return; |
---|
684 | } |
---|
685 | |
---|
686 | // 最大文字数制限の判定 (#871) |
---|
687 | $arrValueTemp = $value; |
---|
688 | $arrValueTemp[2] = 256; |
---|
689 | $this->MAX_LENGTH_CHECK($arrValueTemp); |
---|
690 | } |
---|
691 | |
---|
692 | /* メールアドレスに使用できる文字の判定 */ |
---|
693 | // メールアドレスに使用する文字を正規表現で判定する |
---|
694 | // value[0] = 項目名 value[1] = 判定対象メールアドレス |
---|
695 | function EMAIL_CHAR_CHECK($value) |
---|
696 | { |
---|
697 | if (isset($this->arrErr[$value[1]])) { |
---|
698 | return; |
---|
699 | } |
---|
700 | $this->createParam($value); |
---|
701 | if (strlen($this->arrParam[$value[1]]) > 0 && !preg_match("/^[a-zA-Z0-9_\.@\+\?-]+$/i",$this->arrParam[$value[1]])) { |
---|
702 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'に使用する文字を正しく入力してください。<br />'; |
---|
703 | } |
---|
704 | } |
---|
705 | |
---|
706 | /* URL形式の判定 */ |
---|
707 | // URLを正規表現で判定する。デフォルトでhttp://があってもOK |
---|
708 | // value[0] = 項目名 value[1] = 判定対象URL |
---|
709 | function URL_CHECK($value) |
---|
710 | { |
---|
711 | if (isset($this->arrErr[$value[1]])) { |
---|
712 | return; |
---|
713 | } |
---|
714 | if (strlen($this->arrParam[$value[1]]) > 0 && !preg_match("@^https?://+($|[a-zA-Z0-9_~=:&\?\.\/-])+$@i", $this->arrParam[$value[1]])) { |
---|
715 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'を正しく入力してください。<br />'; |
---|
716 | } |
---|
717 | } |
---|
718 | |
---|
719 | /* IPアドレスの判定 */ |
---|
720 | // value[0] = 項目名 value[1] = 判定対象IPアドレス文字列 |
---|
721 | function IP_CHECK($value) |
---|
722 | { |
---|
723 | if (isset($this->arrErr[$value[1]])) { |
---|
724 | return; |
---|
725 | } |
---|
726 | //改行コードが含まれている場合には配列に変換 |
---|
727 | $params = str_replace("\r",'',$this->arrParam[$value[1]]); |
---|
728 | if (!empty($params)) { |
---|
729 | if (strpos($params,"\n") === false) { |
---|
730 | $params .= "\n"; |
---|
731 | } |
---|
732 | $params = explode("\n",$params); |
---|
733 | foreach ($params as $param) { |
---|
734 | $param = trim($param); |
---|
735 | if (long2ip(ip2long($param)) != trim($param) && !empty($param)) { |
---|
736 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'に正しい形式のIPアドレスを入力してください。<br />'; |
---|
737 | } |
---|
738 | } |
---|
739 | } |
---|
740 | } |
---|
741 | |
---|
742 | /* 拡張子の判定 */ |
---|
743 | // 受け取りがない場合エラーを返す |
---|
744 | // value[0] = 項目名 value[1] = 判定対象 value[2]=array(拡張子) |
---|
745 | function FILE_EXT_CHECK($value) |
---|
746 | { |
---|
747 | if (isset($this->arrErr[$value[1]]) || count($value[2]) == 0) { |
---|
748 | return; |
---|
749 | } |
---|
750 | $this->createParam($value); |
---|
751 | |
---|
752 | $match = false; |
---|
753 | if (strlen($_FILES[$value[1]]['name']) >= 1) { |
---|
754 | $filename = $_FILES[$value[1]]['name']; |
---|
755 | |
---|
756 | foreach ($value[2] as $check_ext) { |
---|
757 | $match = preg_match('/' . preg_quote('.' . $check_ext) . '$/i', $filename) >= 1; |
---|
758 | if ($match === true) { |
---|
759 | break 1; |
---|
760 | } |
---|
761 | } |
---|
762 | } |
---|
763 | if ($match === false) { |
---|
764 | $str_ext = implode('・', $value[2]); |
---|
765 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'で許可されている形式は、' . $str_ext . 'です。<br />'; |
---|
766 | } |
---|
767 | } |
---|
768 | |
---|
769 | /* ファイルが存在するかチェックする */ |
---|
770 | // 受け取りがない場合エラーを返す |
---|
771 | // value[0] = 項目名 value[1] = 判定対象 value[2] = 指定ディレクトリ |
---|
772 | function FIND_FILE($value) |
---|
773 | { |
---|
774 | if (isset($this->arrErr[$value[1]])) { |
---|
775 | return; |
---|
776 | } |
---|
777 | |
---|
778 | $this->createParam($value); |
---|
779 | if ($value[2] != '') { |
---|
780 | $dir = $value[2]; |
---|
781 | } else { |
---|
782 | $dir = IMAGE_SAVE_REALDIR; |
---|
783 | } |
---|
784 | |
---|
785 | $path = $dir . '/' . $this->arrParam[$value[1]]; |
---|
786 | $path = str_replace('//', '/', $path); |
---|
787 | |
---|
788 | if ($this->arrParam[$value[1]] != '' && !file_exists($path)) { |
---|
789 | $this->arrErr[$value[1]] = '※ ' . $path . 'が見つかりません。<br />'; |
---|
790 | } |
---|
791 | } |
---|
792 | |
---|
793 | /* ファイルが上げられたか確認 */ |
---|
794 | // 受け取りがない場合エラーを返す |
---|
795 | // value[0] = 項目名 value[1] = 判定対象 value[2] = 指定サイズ(KB) |
---|
796 | function FILE_EXIST_CHECK($value) |
---|
797 | { |
---|
798 | if (isset($this->arrErr[$value[1]])) { |
---|
799 | return; |
---|
800 | } |
---|
801 | $this->createParam($value); |
---|
802 | if (!($_FILES[$value[1]]['size'] != '' && $_FILES[$value[1]]['size'] > 0)) { |
---|
803 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'をアップロードして下さい。<br />'; |
---|
804 | } |
---|
805 | } |
---|
806 | |
---|
807 | /* ファイルサイズの判定 */ |
---|
808 | // 受け取りがない場合エラーを返す |
---|
809 | // value[0] = 項目名 value[1] = 判定対象 value[2] = 指定サイズ(KB) |
---|
810 | function FILE_SIZE_CHECK($value) |
---|
811 | { |
---|
812 | if (isset($this->arrErr[$value[1]])) { |
---|
813 | return; |
---|
814 | } |
---|
815 | $this->createParam($value); |
---|
816 | if ($_FILES[$value[1]]['size'] > $value[2] * 1024) { |
---|
817 | $byte = 'KB'; |
---|
818 | if ($value[2] >= 1000) { |
---|
819 | $value[2] = $value[2] / 1000; |
---|
820 | $byte = 'MB'; |
---|
821 | } |
---|
822 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'のファイルサイズは' . $value[2] . $byte . '以下のものを使用してください。<br />'; |
---|
823 | } |
---|
824 | } |
---|
825 | |
---|
826 | /* ファイル名の判定 */ |
---|
827 | // 入力文字が英数字,'_','-'以外ならエラーを返す |
---|
828 | // value[0] = 項目名 value[1] = 判定対象文字列 |
---|
829 | function FILE_NAME_CHECK($value) |
---|
830 | { |
---|
831 | if (isset($this->arrErr[$value[1]])) { |
---|
832 | return; |
---|
833 | } |
---|
834 | $this->createParam($value); |
---|
835 | if (strlen($_FILES[$value[1]]['name']) > 0 && !preg_match("/^[[:alnum:]_\.-]+$/i", $_FILES[$value[1]]['name'])) { |
---|
836 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'のファイル名に日本語やスペースは使用しないで下さい。<br />'; |
---|
837 | } |
---|
838 | } |
---|
839 | |
---|
840 | /* ファイル名の判定(アップロード以外の時) */ |
---|
841 | // 入力文字が英数字,'_','-'以外ならエラーを返す |
---|
842 | // value[0] = 項目名 value[1] = 判定対象文字列 |
---|
843 | function FILE_NAME_CHECK_BY_NOUPLOAD($value) |
---|
844 | { |
---|
845 | if (isset($this->arrErr[$value[1]])) { |
---|
846 | return; |
---|
847 | } |
---|
848 | $this->createParam($value); |
---|
849 | if (strlen($this->arrParam[$value[1]]) > 0 && !preg_match("/^[[:alnum:]_\.-]+$/i", $this->arrParam[$value[1]]) || preg_match('/[\\]/' ,$this->arrParam[$value[1]])) { |
---|
850 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'のファイル名に日本語やスペースは使用しないで下さい。<br />'; |
---|
851 | } |
---|
852 | } |
---|
853 | |
---|
854 | //日付チェック |
---|
855 | // value[0] = 項目名 |
---|
856 | // value[1] = YYYY |
---|
857 | // value[2] = MM |
---|
858 | // value[3] = DD |
---|
859 | function CHECK_DATE($value) |
---|
860 | { |
---|
861 | if (isset($this->arrErr[$value[1]])) { |
---|
862 | return; |
---|
863 | } |
---|
864 | $this->createParam($value); |
---|
865 | // 少なくともどれか一つが入力されている。 |
---|
866 | if ($this->arrParam[$value[1]] > 0 || $this->arrParam[$value[2]] > 0 || $this->arrParam[$value[3]] > 0) { |
---|
867 | // 年月日のどれかが入力されていない。 |
---|
868 | if (!(strlen($this->arrParam[$value[1]]) > 0 && strlen($this->arrParam[$value[2]]) > 0 && strlen($this->arrParam[$value[3]]) > 0)) { |
---|
869 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'はすべての項目を入力して下さい。<br />'; |
---|
870 | } else if (! checkdate($this->arrParam[$value[2]], $this->arrParam[$value[3]], $this->arrParam[$value[1]])) { |
---|
871 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'が正しくありません。<br />'; |
---|
872 | } |
---|
873 | } |
---|
874 | } |
---|
875 | |
---|
876 | //日付チェック |
---|
877 | // value[0] = 項目名 |
---|
878 | // value[1] = YYYY |
---|
879 | // value[2] = MM |
---|
880 | // value[3] = DD |
---|
881 | // value[4] = HH |
---|
882 | // value[5] = mm |
---|
883 | function CHECK_DATE2($value) |
---|
884 | { |
---|
885 | if (isset($this->arrErr[$value[1]])) { |
---|
886 | return; |
---|
887 | } |
---|
888 | $this->createParam($value); |
---|
889 | // 少なくともどれか一つが入力されている。 |
---|
890 | if ($this->arrParam[$value[1]] > 0 || $this->arrParam[$value[2]] > 0 || $this->arrParam[$value[3]] > 0 || $this->arrParam[$value[4]] >= 0 || $this->arrParam[$value[5]] >= 0) { |
---|
891 | // 年月日時のどれかが入力されていない。 |
---|
892 | if (!(strlen($this->arrParam[$value[1]]) > 0 && strlen($this->arrParam[$value[2]]) > 0 && strlen($this->arrParam[$value[3]]) > 0 && strlen($this->arrParam[$value[4]]) > 0 && strlen($this->arrParam[$value[5]]) > 0)) { |
---|
893 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'はすべての項目を入力して下さい。<br />'; |
---|
894 | } else if (! checkdate($this->arrParam[$value[2]], $this->arrParam[$value[3]], $this->arrParam[$value[1]])) { |
---|
895 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'が正しくありません。<br />'; |
---|
896 | } |
---|
897 | } |
---|
898 | } |
---|
899 | |
---|
900 | //日付チェック |
---|
901 | // value[0] = 項目名 |
---|
902 | // value[1] = YYYY |
---|
903 | // value[2] = MM |
---|
904 | function CHECK_DATE3($value) |
---|
905 | { |
---|
906 | if (isset($this->arrErr[$value[1]])) { |
---|
907 | return; |
---|
908 | } |
---|
909 | $this->createParam($value); |
---|
910 | // 少なくともどれか一つが入力されている。 |
---|
911 | if ($this->arrParam[$value[1]] > 0 || $this->arrParam[$value[2]] > 0) { |
---|
912 | // 年月日時のどれかが入力されていない。 |
---|
913 | if (!(strlen($this->arrParam[$value[1]]) > 0 && strlen($this->arrParam[$value[2]]) > 0)) { |
---|
914 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'はすべての項目を入力して下さい。<br />'; |
---|
915 | } else if (! checkdate($this->arrParam[$value[2]], 1, $this->arrParam[$value[1]])) { |
---|
916 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'が正しくありません。<br />'; |
---|
917 | } |
---|
918 | } |
---|
919 | } |
---|
920 | |
---|
921 | //誕生日チェック |
---|
922 | // value[0] = 項目名 |
---|
923 | // value[1] = YYYY |
---|
924 | // value[2] = MM |
---|
925 | // value[3] = DD |
---|
926 | function CHECK_BIRTHDAY($value) |
---|
927 | { |
---|
928 | if (isset($this->arrErr[$value[1]])) { |
---|
929 | return; |
---|
930 | } |
---|
931 | |
---|
932 | $this->createParam($value); |
---|
933 | // 年が入力されている。 |
---|
934 | if ($this->arrParam[$value[1]] > 0) { |
---|
935 | |
---|
936 | // 年の数字チェック、最小数値制限チェック |
---|
937 | $this->doFunc(array($value[0].'(年)', $value[1], BIRTH_YEAR), array('NUM_CHECK', 'MIN_CHECK')); |
---|
938 | // 上のチェックでエラーある場合、中断する。 |
---|
939 | if (isset($this->arrErr[$value[1]])) { |
---|
940 | return; |
---|
941 | } |
---|
942 | |
---|
943 | // 年の最大数値制限チェック |
---|
944 | $this->doFunc(array($value[0].'(年)', $value[1], date('Y',strtotime('now'))), array('MAX_CHECK')); |
---|
945 | // 上のチェックでエラーある場合、中断する。 |
---|
946 | if (isset($this->arrErr[$value[1]])) { |
---|
947 | return; |
---|
948 | } |
---|
949 | } |
---|
950 | |
---|
951 | // XXX createParam() が二重に呼ばれる問題を抱える |
---|
952 | $this->CHECK_DATE($value); |
---|
953 | } |
---|
954 | |
---|
955 | /*-----------------------------------------------------------------*/ |
---|
956 | /* CHECK_SET_TERM |
---|
957 | /* 年月日に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
---|
958 | /* 引数 (開始年,開始月,開始日,終了年,終了月,終了日) |
---|
959 | /* 戻値 array(1,2,3) |
---|
960 | /* 1.開始年月日 (YYYYMMDD 000000) |
---|
961 | /* 2.終了年月日 (YYYYMMDD 235959) |
---|
962 | /* 3.エラー (0 = OK, 1 = NG) |
---|
963 | /*-----------------------------------------------------------------*/ |
---|
964 | // value[0] = 項目名1 |
---|
965 | // value[1] = 項目名2 |
---|
966 | // value[2] = start_year |
---|
967 | // value[3] = start_month |
---|
968 | // value[4] = start_day |
---|
969 | // value[5] = end_year |
---|
970 | // value[6] = end_month |
---|
971 | // value[7] = end_day |
---|
972 | function CHECK_SET_TERM($value) |
---|
973 | { |
---|
974 | |
---|
975 | // 期間指定 |
---|
976 | if (isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[5]])) { |
---|
977 | return; |
---|
978 | } |
---|
979 | $this->createParam($value); |
---|
980 | if ((strlen($this->arrParam[$value[2]]) > 0 || strlen($this->arrParam[$value[3]]) > 0 || strlen($this->arrParam[$value[4]]) > 0) && ! checkdate($this->arrParam[$value[3]], $this->arrParam[$value[4]], $this->arrParam[$value[2]])) { |
---|
981 | $this->arrErr[$value[2]] = '※ ' . $value[0] . 'を正しく指定してください。<br />'; |
---|
982 | } |
---|
983 | if ((strlen($this->arrParam[$value[5]]) > 0 || strlen($this->arrParam[$value[6]]) > 0 || strlen($this->arrParam[$value[7]]) > 0) && ! checkdate($this->arrParam[$value[6]], $this->arrParam[$value[7]], $this->arrParam[$value[5]])) { |
---|
984 | $this->arrErr[$value[5]] = '※ ' . $value[1] . 'を正しく指定してください。<br />'; |
---|
985 | } |
---|
986 | if ((strlen($this->arrParam[$value[2]]) > 0 && strlen($this->arrParam[$value[3]]) > 0 && strlen($this->arrParam[$value[4]]) > 0) && (strlen($this->arrParam[$value[5]]) > 0 || strlen($this->arrParam[$value[6]]) > 0 || strlen($this->arrParam[$value[7]]) > 0)) { |
---|
987 | |
---|
988 | $date1 = $this->arrParam[$value[2]] .sprintf('%02d', $this->arrParam[$value[3]]) .sprintf('%02d',$this->arrParam[$value[4]]) .'000000'; |
---|
989 | $date2 = $this->arrParam[$value[5]] .sprintf('%02d', $this->arrParam[$value[6]]) .sprintf('%02d',$this->arrParam[$value[7]]) .'235959'; |
---|
990 | |
---|
991 | if (($this->arrErr[$value[2]] == '' && $this->arrErr[$value[5]] == '') && $date1 > $date2) { |
---|
992 | $this->arrErr[$value[2]] = '※ ' .$value[0]. 'と' .$value[1]. 'の期間指定が不正です。<br />'; |
---|
993 | } |
---|
994 | } |
---|
995 | } |
---|
996 | |
---|
997 | /*-----------------------------------------------------------------*/ |
---|
998 | /* CHECK_SET_TERM2 |
---|
999 | /* 年月日時に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
---|
1000 | /* 引数 (開始年,開始月,開始日,開始時間,開始分,開始秒, |
---|
1001 | /* 終了年,終了月,終了日,終了時間,終了分,終了秒) |
---|
1002 | /* 戻値 array(1,2,3) |
---|
1003 | /* 1.開始年月日 (YYYYMMDDHHmmss) |
---|
1004 | /* 2.終了年月日 (YYYYMMDDHHmmss) |
---|
1005 | /* 3.エラー (0 = OK, 1 = NG) |
---|
1006 | /*-----------------------------------------------------------------*/ |
---|
1007 | // value[0] = 項目名1 |
---|
1008 | // value[1] = 項目名2 |
---|
1009 | // value[2] = start_year |
---|
1010 | // value[3] = start_month |
---|
1011 | // value[4] = start_day |
---|
1012 | // value[5] = start_hour |
---|
1013 | // value[6] = start_minute |
---|
1014 | // value[7] = start_second |
---|
1015 | // value[8] = end_year |
---|
1016 | // value[9] = end_month |
---|
1017 | // value[10] = end_day |
---|
1018 | // value[11] = end_hour |
---|
1019 | // value[12] = end_minute |
---|
1020 | // value[13] = end_second |
---|
1021 | |
---|
1022 | /*-----------------------------------------------------------------*/ |
---|
1023 | function CHECK_SET_TERM2($value) |
---|
1024 | { |
---|
1025 | |
---|
1026 | // 期間指定 |
---|
1027 | if (isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[8]])) { |
---|
1028 | return; |
---|
1029 | } |
---|
1030 | $this->createParam($value); |
---|
1031 | if ((strlen($this->arrParam[$value[2]]) > 0 || strlen($this->arrParam[$value[3]]) > 0 || strlen($this->arrParam[$value[4]]) > 0 || strlen($this->arrParam[$value[5]]) > 0) && ! checkdate($this->arrParam[$value[3]], $this->arrParam[$value[4]], $this->arrParam[$value[2]])) { |
---|
1032 | $this->arrErr[$value[2]] = '※ ' . $value[0] . 'を正しく指定してください。<br />'; |
---|
1033 | } |
---|
1034 | if ((strlen($this->arrParam[$value[8]]) > 0 || strlen($this->arrParam[$value[9]]) > 0 || strlen($this->arrParam[$value[10]]) > 0 || strlen($this->arrParam[$value[11]]) > 0) && ! checkdate($this->arrParam[$value[9]], $this->arrParam[$value[10]], $this->arrParam[$value[8]])) { |
---|
1035 | $this->arrErr[$value[8]] = '※ ' . $value[1] . 'を正しく指定してください。<br />'; |
---|
1036 | } |
---|
1037 | if ((strlen($this->arrParam[$value[2]]) > 0 && strlen($this->arrParam[$value[3]]) > 0 && strlen($this->arrParam[$value[4]]) > 0 && strlen($this->arrParam[$value[5]]) > 0) && (strlen($this->arrParam[$value[8]]) > 0 || strlen($this->arrParam[$value[9]]) > 0 || strlen($this->arrParam[$value[10]]) > 0 || strlen($this->arrParam[$value[11]]) > 0)) { |
---|
1038 | |
---|
1039 | $date1 = $this->arrParam[$value[2]] .sprintf('%02d', $this->arrParam[$value[3]]) .sprintf('%02d',$this->arrParam[$value[4]]) .sprintf('%02d',$this->arrParam[$value[5]]).sprintf('%02d',$this->arrParam[$value[6]]).sprintf('%02d',$this->arrParam[$value[7]]); |
---|
1040 | $date2 = $this->arrParam[$value[8]] .sprintf('%02d', $this->arrParam[$value[9]]) .sprintf('%02d',$this->arrParam[$value[10]]) .sprintf('%02d',$this->arrParam[$value[11]]).sprintf('%02d',$this->arrParam[$value[12]]).sprintf('%02d',$this->arrParam[$value[13]]); |
---|
1041 | |
---|
1042 | if (($this->arrErr[$value[2]] == '' && $this->arrErr[$value[8]] == '') && $date1 > $date2) { |
---|
1043 | $this->arrErr[$value[2]] = '※ ' .$value[0]. 'と' .$value[1]. 'の期間指定が不正です。<br />'; |
---|
1044 | } |
---|
1045 | if ($date1 == $date2) { |
---|
1046 | $this->arrErr[$value[2]] = '※ ' .$value[0]. 'と' .$value[1]. 'の期間指定が不正です。<br />'; |
---|
1047 | } |
---|
1048 | |
---|
1049 | } |
---|
1050 | } |
---|
1051 | |
---|
1052 | /*-----------------------------------------------------------------*/ |
---|
1053 | /* CHECK_SET_TERM3 |
---|
1054 | /* 年月に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
---|
1055 | /* 引数 (開始年,開始月,終了年,終了月) |
---|
1056 | /* 戻値 array(1,2,3) |
---|
1057 | /* 1.開始年月日 (YYYYMMDD 000000) |
---|
1058 | /* 2.終了年月日 (YYYYMMDD 235959) |
---|
1059 | /* 3.エラー (0 = OK, 1 = NG) |
---|
1060 | /*-----------------------------------------------------------------*/ |
---|
1061 | // value[0] = 項目名1 |
---|
1062 | // value[1] = 項目名2 |
---|
1063 | // value[2] = start_year |
---|
1064 | // value[3] = start_month |
---|
1065 | // value[4] = end_year |
---|
1066 | // value[5] = end_month |
---|
1067 | function CHECK_SET_TERM3($value) |
---|
1068 | { |
---|
1069 | |
---|
1070 | // 期間指定 |
---|
1071 | if (isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[4]])) { |
---|
1072 | return; |
---|
1073 | } |
---|
1074 | $this->createParam($value); |
---|
1075 | if ((strlen($this->arrParam[$value[2]]) > 0 || strlen($this->arrParam[$value[3]]) > 0) && ! checkdate($this->arrParam[$value[3]], 1, $this->arrParam[$value[2]])) { |
---|
1076 | $this->arrErr[$value[2]] = '※ ' . $value[0] . 'を正しく指定してください。<br />'; |
---|
1077 | } |
---|
1078 | if ((strlen($this->arrParam[$value[4]]) > 0 || strlen($this->arrParam[$value[5]]) > 0) && ! checkdate($this->arrParam[$value[5]], 1, $this->arrParam[$value[4]])) { |
---|
1079 | $this->arrErr[$value[4]] = '※ ' . $value[1] . 'を正しく指定してください。<br />'; |
---|
1080 | } |
---|
1081 | if ((strlen($this->arrParam[$value[2]]) > 0 && strlen($this->arrParam[$value[3]]) > 0 && (strlen($this->arrParam[$value[4]]) > 0 || strlen($this->arrParam[$value[5]]) > 0))) { |
---|
1082 | |
---|
1083 | $date1 = $this->arrParam[$value[2]] .sprintf('%02d', $this->arrParam[$value[3]]); |
---|
1084 | $date2 = $this->arrParam[$value[4]] .sprintf('%02d', $this->arrParam[$value[5]]); |
---|
1085 | |
---|
1086 | if (($this->arrErr[$value[2]] == '' && $this->arrErr[$value[5]] == '') && $date1 > $date2) { |
---|
1087 | $this->arrErr[$value[2]] = '※ ' .$value[0]. 'と' .$value[1]. 'の期間指定が不正です。<br />'; |
---|
1088 | } |
---|
1089 | } |
---|
1090 | } |
---|
1091 | |
---|
1092 | //ディレクトリ存在チェック |
---|
1093 | function DIR_CHECK($value) |
---|
1094 | { |
---|
1095 | if (isset($this->arrErr[$value[1]])) { |
---|
1096 | return; |
---|
1097 | } |
---|
1098 | $this->createParam($value); |
---|
1099 | if (!is_dir($this->arrParam[$value[1]])) { |
---|
1100 | $this->arrErr[$value[1]] = '※ 指定した' . $value[0] . 'は存在しません。<br />'; |
---|
1101 | } |
---|
1102 | } |
---|
1103 | |
---|
1104 | // ドメインチェック |
---|
1105 | function DOMAIN_CHECK($value) |
---|
1106 | { |
---|
1107 | if (isset($this->arrErr[$value[1]])) { |
---|
1108 | return; |
---|
1109 | } |
---|
1110 | if (strlen($this->arrParam[$value[1]]) > 0 && !preg_match("/^\.[^.]+\..+/i", $this->arrParam[$value[1]])) { |
---|
1111 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'の形式が不正です。<br />'; |
---|
1112 | } |
---|
1113 | } |
---|
1114 | |
---|
1115 | /* 携帯メールアドレスの判定 */ |
---|
1116 | // メールアドレスを正規表現で判定する |
---|
1117 | // value[0] = 項目名 value[1] = 判定対象メールアドレス |
---|
1118 | function MOBILE_EMAIL_CHECK($value) |
---|
1119 | { |
---|
1120 | if (isset($this->arrErr[$value[1]])) { |
---|
1121 | return; |
---|
1122 | } |
---|
1123 | $this->createParam($value); |
---|
1124 | $objMobile = new SC_Helper_Mobile_Ex(); |
---|
1125 | if (strlen($this->arrParam[$value[1]]) > 0 && !$objMobile->gfIsMobileMailAddress($this->arrParam[$value[1]])) { |
---|
1126 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は携帯電話のものではありません。<br />'; |
---|
1127 | } |
---|
1128 | } |
---|
1129 | |
---|
1130 | /** |
---|
1131 | * CHECK_REGIST_CUSTOMER_EMAIL |
---|
1132 | * |
---|
1133 | * メールアドレスが会員登録されているか調べる |
---|
1134 | * @param array $value value[0] = 項目名 value[1] = 判定対象メールアドレス |
---|
1135 | * @access public |
---|
1136 | * @return void |
---|
1137 | */ |
---|
1138 | function CHECK_REGIST_CUSTOMER_EMAIL($value) |
---|
1139 | { |
---|
1140 | if (isset($this->arrErr[$value[1]])) { |
---|
1141 | return; |
---|
1142 | } |
---|
1143 | $this->createParam($value); |
---|
1144 | |
---|
1145 | $register_user_flg = SC_Helper_Customer_Ex::sfCheckRegisterUserFromEmail($this->arrParam[$value[1]]); |
---|
1146 | switch ($register_user_flg) { |
---|
1147 | case 1: |
---|
1148 | $this->arrErr[$value[1]] .= '※ すでに会員登録で使用されている' . $value[0] . 'です。<br />'; |
---|
1149 | break; |
---|
1150 | case 2: |
---|
1151 | $this->arrErr[$value[1]] .= '※ 退会から一定期間の間は、同じ' . $value[0] . 'を使用することはできません。<br />'; |
---|
1152 | break; |
---|
1153 | default: |
---|
1154 | break; |
---|
1155 | } |
---|
1156 | } |
---|
1157 | |
---|
1158 | /** |
---|
1159 | * 禁止文字列のチェック |
---|
1160 | * value[0] = 項目名 value[1] = 判定対象文字列 |
---|
1161 | * value[2] = 入力を禁止する文字列(配列) |
---|
1162 | * |
---|
1163 | * @example $objErr->doFunc(array('URL', 'contents', $arrReviewDenyURL), array('PROHIBITED_STR_CHECK')); |
---|
1164 | */ |
---|
1165 | function PROHIBITED_STR_CHECK($value) |
---|
1166 | { |
---|
1167 | if (isset($this->arrErr[$value[1]]) || empty($this->arrParam[$value[1]])) { |
---|
1168 | return; |
---|
1169 | } |
---|
1170 | $this->createParam($value); |
---|
1171 | $targetStr = $this->arrParam[$value[1]]; |
---|
1172 | $prohibitedStr = str_replace(array('|', '/'), array('\|', '\/'), $value[2]); |
---|
1173 | |
---|
1174 | $pattern = '/' . join('|', $prohibitedStr) . '/i'; |
---|
1175 | if (preg_match_all($pattern, $targetStr, $matches = array())) { |
---|
1176 | $this->arrErr[$value[1]] = '※ ' . $value[0] . 'は入力できません。<br />'; |
---|
1177 | } |
---|
1178 | } |
---|
1179 | |
---|
1180 | /** |
---|
1181 | * パラメーターとして適切な文字列かチェックする. |
---|
1182 | * |
---|
1183 | * @access private |
---|
1184 | * @param array $value [0] => 項目名, [1] => 評価する文字列 |
---|
1185 | * @return void |
---|
1186 | */ |
---|
1187 | function EVAL_CHECK($value) |
---|
1188 | { |
---|
1189 | if (isset($this->arrErr[$value[0]])) { |
---|
1190 | return; |
---|
1191 | } |
---|
1192 | $this->createParam($value); |
---|
1193 | if ($this->evalCheck($value[1]) === false) { |
---|
1194 | $this->arrErr[$value[0]] = '※ ' . $value[0] . ' の形式が不正です。<br />'; |
---|
1195 | } |
---|
1196 | } |
---|
1197 | |
---|
1198 | /** |
---|
1199 | * パラメーターとして適切な文字列かチェックする.(サブルーチン) |
---|
1200 | * |
---|
1201 | * 下記を満たす場合を真とする。 |
---|
1202 | * ・PHPコードとして評価可能であること。 |
---|
1203 | * ・評価した結果がスカラデータ(定数に指定できる値)であること。 |
---|
1204 | * 本メソッドの利用や改訂にあたっては、eval 関数の危険性を意識する必要がある。 |
---|
1205 | * @access private |
---|
1206 | * @param string 評価する文字列 |
---|
1207 | * @return bool パラメーターとして適切な文字列か |
---|
1208 | */ |
---|
1209 | function evalCheck($value) |
---|
1210 | { |
---|
1211 | return @eval('return is_scalar(' . $value . ');'); |
---|
1212 | } |
---|
1213 | |
---|
1214 | /** |
---|
1215 | * 未定義の $this->arrParam に空要素を代入する. |
---|
1216 | * |
---|
1217 | * @access private |
---|
1218 | * @param array $value 配列 |
---|
1219 | * @return void |
---|
1220 | */ |
---|
1221 | function createParam($value) |
---|
1222 | { |
---|
1223 | foreach ($value as $key) { |
---|
1224 | if (is_string($key) || is_int($key)) { |
---|
1225 | if (!isset($this->arrParam[$key])) $this->arrParam[$key] = ''; |
---|
1226 | } |
---|
1227 | } |
---|
1228 | } |
---|
1229 | |
---|
1230 | /** |
---|
1231 | * 値が数字だけかどうかチェックする |
---|
1232 | * |
---|
1233 | * @access private |
---|
1234 | * @param string $string チェックする文字列 |
---|
1235 | * @return boolean 値が10進数の数値表現のみの場合 true |
---|
1236 | */ |
---|
1237 | function numelicCheck($string) |
---|
1238 | { |
---|
1239 | /* |
---|
1240 | * XXX 10進数の数値表現か否かを調べたいだけだが, |
---|
1241 | * ctype_digit() は文字列以外 false を返す. |
---|
1242 | * string ではなく int 型の数値が入る場合がある. |
---|
1243 | */ |
---|
1244 | $string = (string) $string; |
---|
1245 | return strlen($string) > 0 && !ctype_digit($string); |
---|
1246 | } |
---|
1247 | } |
---|