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