| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 6 | * |
|---|
| 7 | * http://www.lockon.co.jp/ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or |
|---|
| 10 | * modify it under the terms of the GNU General Public License |
|---|
| 11 | * as published by the Free Software Foundation; either version 2 |
|---|
| 12 | * of the License, or (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /*---------------------------------------------------------------------- |
|---|
| 25 | * [名称] SC_CheckError |
|---|
| 26 | * [概要] エラーチェッククラス |
|---|
| 27 | *---------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | class SC_CheckError { |
|---|
| 30 | var $arrErr = array(); |
|---|
| 31 | var $arrParam; |
|---|
| 32 | |
|---|
| 33 | // チェック対象の値が含まれる配列をセットする。 |
|---|
| 34 | function SC_CheckError($array = "") { |
|---|
| 35 | if($array != "") { |
|---|
| 36 | $this->arrParam = $array; |
|---|
| 37 | } else { |
|---|
| 38 | $this->arrParam = $_POST; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | function doFunc($value, $arrFunc) { |
|---|
| 44 | foreach ( $arrFunc as $key ) { |
|---|
| 45 | $this->$key($value); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /* HTMLのタグをチェックする */ |
|---|
| 50 | // value[0] = 項目名 value[1] = 判定対象 value[2] = 許可するタグが格納された配列 |
|---|
| 51 | function HTML_TAG_CHECK($value) { |
|---|
| 52 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 53 | return; |
|---|
| 54 | } |
|---|
| 55 | $this->createParam($value); |
|---|
| 56 | // 含まれているタグを抽出する |
|---|
| 57 | preg_match_all("/<([\/]?[a-z]+)/", $this->arrParam[$value[1]], $arrTag); |
|---|
| 58 | |
|---|
| 59 | foreach($arrTag[1] as $val) { |
|---|
| 60 | $find = false; |
|---|
| 61 | |
|---|
| 62 | foreach($value[2] as $tag) { |
|---|
| 63 | if(eregi("^" . $tag . "$", $val)) { |
|---|
| 64 | $find = true; |
|---|
| 65 | } else { |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | if(!$find) { |
|---|
| 70 | $this->arrErr[$value[1]] = "※ " . $value[0] . "に許可されていないタグ[" . strtoupper($val) . "]が含まれています。<br />"; |
|---|
| 71 | return; |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /* 必須入力の判定 */ |
|---|
| 77 | // value[0] = 項目名 value[1] = 判定対象 |
|---|
| 78 | function EXIST_CHECK( $value ) { // 受け取りがない場合エラーを返す |
|---|
| 79 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 80 | return; |
|---|
| 81 | } |
|---|
| 82 | $this->createParam($value); |
|---|
| 83 | if( strlen($this->arrParam[$value[1]]) == 0 ){ |
|---|
| 84 | $this->arrErr[$value[1]] = "※ " . $value[0] . "が入力されていません。<br />"; |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /* 必須入力の判定(逆順) */ |
|---|
| 89 | // value[0] = 判定対象 value[1] = 項目名 |
|---|
| 90 | function EXIST_CHECK_REVERSE( $value ) { // 受け取りがない場合エラーを返す |
|---|
| 91 | if(isset($this->arrErr[$value[0]])) { |
|---|
| 92 | return; |
|---|
| 93 | } |
|---|
| 94 | $this->createParam($value); |
|---|
| 95 | if( strlen($this->arrParam[$value[0]]) == 0 ){ |
|---|
| 96 | $this->arrErr[$value[0]] = "※ " . $value[0] . "が入力されていません。<br />"; |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /* スペース、タブの判定 */ |
|---|
| 101 | // value[0] = 項目名 value[1] = 判定対象 |
|---|
| 102 | function SPTAB_CHECK( $value ) { // 受け取りがない場合エラーを返す |
|---|
| 103 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 104 | return; |
|---|
| 105 | } |
|---|
| 106 | $this->createParam($value); |
|---|
| 107 | if(strlen($this->arrParam[$value[1]]) != 0 && ereg("^[ \t\r\n]+$", $this->arrParam[$value[1]])){ |
|---|
| 108 | $this->arrErr[$value[1]] = "※ " . $value[0] . "にスペース、タブ、改行のみの入力はできません。<br />"; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /* スペース、タブの判定 */ |
|---|
| 113 | // value[0] = 項目名 value[1] = 判定対象 |
|---|
| 114 | function NO_SPTAB( $value ) { // 受け取りがない場合エラーを返す |
|---|
| 115 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 116 | return; |
|---|
| 117 | } |
|---|
| 118 | $this->createParam($value); |
|---|
| 119 | if(strlen($this->arrParam[$value[1]]) != 0 && mb_ereg("[ \t\r\n]+", $this->arrParam[$value[1]])){ |
|---|
| 120 | $this->arrErr[$value[1]] = "※ " . $value[0] . "にスペース、タブ、改行は含めないで下さい。<br />"; |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | /* ゼロで開始されている数値の判定 */ |
|---|
| 125 | function ZERO_START($value) { |
|---|
| 126 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 127 | return; |
|---|
| 128 | } |
|---|
| 129 | $this->createParam($value); |
|---|
| 130 | if(strlen($this->arrParam[$value[1]]) != 0 && ereg("^[0]+[0-9]+$", $this->arrParam[$value[1]])){ |
|---|
| 131 | $this->arrErr[$value[1]] = "※ " . $value[0] . "に0で始まる数値が入力されています。<br />"; |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | /* 必須選択の判定 */ |
|---|
| 136 | // value[0] = 項目名 value[1] = 判定対象 |
|---|
| 137 | function SELECT_CHECK( $value ) { // プルダウンなどで選択されていない場合エラーを返す |
|---|
| 138 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 139 | return; |
|---|
| 140 | } |
|---|
| 141 | $this->createParam($value); |
|---|
| 142 | if( strlen($this->arrParam[$value[1]]) == 0 ){ |
|---|
| 143 | $this->arrErr[$value[1]] = "※ " . $value[0] . "が選択されていません。<br />"; |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | /* 同一性の判定 */ |
|---|
| 148 | // value[0] = 項目名1 value[1] = 項目名2 value[2] = 判定対象文字列1 value[3] = 判定対象文字列2 |
|---|
| 149 | function EQUAL_CHECK( $value ) { // 入力が指定文字数以上ならエラーを返す |
|---|
| 150 | if(isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[3]])) { |
|---|
| 151 | return; |
|---|
| 152 | } |
|---|
| 153 | $this->createParam($value); |
|---|
| 154 | // 文字数の取得 |
|---|
| 155 | if( $this->arrParam[$value[2]] != $this->arrParam[$value[3]]) { |
|---|
| 156 | $this->arrErr[$value[2]] = "※ " . $value[0] . "と" . $value[1] . "が一致しません。<br />"; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | /* 値が異なることの判定 */ |
|---|
| 161 | // value[0] = 項目名1 value[1] = 項目名2 value[2] = 判定対象文字列1 value[3] = 判定対象文字列2 |
|---|
| 162 | function DIFFERENT_CHECK( $value ) { // 入力が指定文字数以上ならエラーを返す |
|---|
| 163 | if(isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[3]])) { |
|---|
| 164 | return; |
|---|
| 165 | } |
|---|
| 166 | $this->createParam($value); |
|---|
| 167 | // 文字数の取得 |
|---|
| 168 | if( $this->arrParam[$value[2]] == $this->arrParam[$value[3]]) { |
|---|
| 169 | $this->arrErr[$value[2]] = "※ " . $value[0] . "と" . $value[1] . "は、同じ値を使用できません。<br />"; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | /* 値の大きさを比較する value[2] < value[3]でなければエラー */ |
|---|
| 174 | // value[0] = 項目名1 value[1] = 項目名2 value[2] = 判定対象文字列1 value[3] = 判定対象文字列2 |
|---|
| 175 | function GREATER_CHECK($value) { // 入力が指定文字数以上ならエラーを返す |
|---|
| 176 | if(isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[3]])) { |
|---|
| 177 | return; |
|---|
| 178 | } |
|---|
| 179 | $this->createParam($value); |
|---|
| 180 | // 文字数の取得 |
|---|
| 181 | if($this->arrParam[$value[2]] != "" && $this->arrParam[$value[3]] != "" && ($this->arrParam[$value[2]] > $this->arrParam[$value[3]])) { |
|---|
| 182 | $this->arrErr[$value[2]] = "※ " . $value[0] . "は" . $value[1] . "より大きい値を入力できません。<br />"; |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | /* 最大文字数制限の判定 */ |
|---|
| 188 | // value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最大文字数(半角も全角も1文字として数える) |
|---|
| 189 | function MAX_LENGTH_CHECK( $value ) { // 入力が指定文字数以上ならエラーを返す |
|---|
| 190 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 191 | return; |
|---|
| 192 | } |
|---|
| 193 | $this->createParam($value); |
|---|
| 194 | // 文字数の取得 |
|---|
| 195 | if( mb_strlen($this->arrParam[$value[1]]) > $value[2] ) { |
|---|
| 196 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は" . $value[2] . "字以下で入力してください。<br />"; |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | /* 最小文字数制限の判定 */ |
|---|
| 201 | // value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最小文字数(半角も全角も1文字として数える) |
|---|
| 202 | function MIN_LENGTH_CHECK( $value ) { // 入力が指定文字数未満ならエラーを返す |
|---|
| 203 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 204 | return; |
|---|
| 205 | } |
|---|
| 206 | $this->createParam($value); |
|---|
| 207 | // 文字数の取得 |
|---|
| 208 | if( mb_strlen($this->arrParam[$value[1]]) < $value[2] ) { |
|---|
| 209 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は" . $value[2] . "字以上で入力してください。<br />"; |
|---|
| 210 | } |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | /* 最大文字数制限の判定 */ |
|---|
| 214 | // value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最大数 |
|---|
| 215 | function MAX_CHECK( $value ) { // 入力が最大数以上ならエラーを返す |
|---|
| 216 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 217 | return; |
|---|
| 218 | } |
|---|
| 219 | $this->createParam($value); |
|---|
| 220 | // 文字数の取得 |
|---|
| 221 | if($this->arrParam[$value[1]] > $value[2] ) { |
|---|
| 222 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は" . $value[2] . "以下で入力してください。<br />"; |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | /* 最小数値制限の判定 */ |
|---|
| 227 | // value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最小数 |
|---|
| 228 | function MIN_CHECK( $value ) { // 入力が最小数未満ならエラーを返す |
|---|
| 229 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 230 | return; |
|---|
| 231 | } |
|---|
| 232 | $this->createParam($value); |
|---|
| 233 | if($this->arrParam[$value[1]] < $value[2] ) { |
|---|
| 234 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は" . $value[2] . "以上で入力してください。<br />"; |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | /* 数字の判定 */ |
|---|
| 240 | // value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 241 | function NUM_CHECK( $value ) { // 入力文字が数字以外ならエラーを返す |
|---|
| 242 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 243 | return; |
|---|
| 244 | } |
|---|
| 245 | $this->createParam($value); |
|---|
| 246 | if( strlen($this->arrParam[$value[1]]) > 0 && !EregI("^[[:digit:]]+$", $this->arrParam[$value[1]])) { |
|---|
| 247 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は数字で入力してください。<br />"; |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | /* 小数点を含む数字の判定 */ |
|---|
| 252 | // value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 253 | function NUM_POINT_CHECK( $value ) { // 入力文字が数字以外ならエラーを返す |
|---|
| 254 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 255 | return; |
|---|
| 256 | } |
|---|
| 257 | $this->createParam($value); |
|---|
| 258 | if( strlen($this->arrParam[$value[1]]) > 0 && !EregI("^[[:digit:]]+[\.]?[[:digit:]]+$", $this->arrParam[$value[1]])) { |
|---|
| 259 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は数字で入力してください。<br />"; |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | function ALPHA_CHECK($value) { |
|---|
| 264 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 265 | return; |
|---|
| 266 | } |
|---|
| 267 | $this->createParam($value); |
|---|
| 268 | if( strlen($this->arrParam[$value[1]]) > 0 && !EregI("^[[:alpha:]]+$", $this->arrParam[$value[1]])) { |
|---|
| 269 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は半角英字で入力してください。<br />"; |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | /** |
|---|
| 274 | * 電話番号の判定 |
|---|
| 275 | * |
|---|
| 276 | * 数字チェックと文字数チェックを実施する。 |
|---|
| 277 | * @param array $value 各要素は以下の通り。<br> |
|---|
| 278 | * [0]: 項目名<br> |
|---|
| 279 | * [1]: 電番1項目目<br> |
|---|
| 280 | * [2]: 電番2項目目<br> |
|---|
| 281 | * [3]: 電番3項目目<br> |
|---|
| 282 | * [4]: 電話番号各項目制限 (指定なしの場合、TEL_ITEM_LEN)<br> |
|---|
| 283 | * [5]: 電話番号総数 (指定なしの場合、TEL_LEN) |
|---|
| 284 | */ |
|---|
| 285 | function TEL_CHECK($value) { |
|---|
| 286 | $telItemLen = isset($value[4]) ? $value[4] : TEL_ITEM_LEN; |
|---|
| 287 | $telLen = isset($value[5]) ? $value[5] : TEL_LEN; |
|---|
| 288 | |
|---|
| 289 | if (isset($this->arrErr[$value[1]]) || isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[3]])) { |
|---|
| 290 | return; |
|---|
| 291 | } |
|---|
| 292 | $this->createParam($value); |
|---|
| 293 | $cnt = 0; |
|---|
| 294 | |
|---|
| 295 | for($i = 1; $i <= 3; $i++) { |
|---|
| 296 | if(strlen($this->arrParam[$value[$i]]) > 0) { |
|---|
| 297 | $cnt++; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | // すべての項目が満たされていない場合を判定(一部だけ入力されている状態) |
|---|
| 302 | if($cnt > 0 && $cnt < 3) { |
|---|
| 303 | $this->arrErr[$value[1]] .= "※ " . $value[0] . "はすべての項目を入力してください。<br />"; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | $total_count = 0; |
|---|
| 307 | for($i = 1; $i <= 3; $i++) { |
|---|
| 308 | if(strlen($this->arrParam[$value[$i]]) > 0 && strlen($this->arrParam[$value[$i]]) > $telItemLen) { |
|---|
| 309 | $this->arrErr[$value[$i]] .= "※ " . $value[0] . $i . "は" . $telItemLen . "字以内で入力してください。<br />"; |
|---|
| 310 | } else if (strlen($this->arrParam[$value[$i]]) > 0 && !EregI("^[[:digit:]]+$", $this->arrParam[$value[$i]])) { |
|---|
| 311 | $this->arrErr[$value[$i]] .= "※ " . $value[0] . $i . "は数字で入力してください。<br />"; |
|---|
| 312 | } |
|---|
| 313 | $total_count += strlen($this->arrParam[$value[$i]]); |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | // 合計値チェック |
|---|
| 317 | if ($total_count > $telLen) { |
|---|
| 318 | $this->arrErr[$value[3]] .= "※ " . $value[0] . "は" . $telLen . "文字以内で入力してください。<br />"; |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | /* 関連項目が完全に満たされているか判定 |
|---|
| 323 | value[0] : 項目名 |
|---|
| 324 | value[1] : 判定対象要素名 |
|---|
| 325 | */ |
|---|
| 326 | function FULL_EXIST_CHECK($value) { |
|---|
| 327 | $max = count($value); |
|---|
| 328 | $this->createParam($value); |
|---|
| 329 | // 既に該当項目にエラーがある場合は、判定しない。 |
|---|
| 330 | for($i = 1; $i < $max; $i++) { |
|---|
| 331 | if(isset($this->arrErr[$value[$i]])) { |
|---|
| 332 | return; |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | $blank = false; |
|---|
| 337 | |
|---|
| 338 | // すべての項目がブランクでないか、すべての項目が入力されていない場合はエラーとする。 |
|---|
| 339 | for($i = 1; $i < $max; $i++) { |
|---|
| 340 | if(strlen($this->arrParam[$value[$i]]) <= 0) { |
|---|
| 341 | $blank = true; |
|---|
| 342 | } |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | if($blank) { |
|---|
| 346 | $this->arrErr[$value[1]] = "※ " . $value[0] . "が入力されていません。<br />"; |
|---|
| 347 | } |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | /* 関連項目がすべて満たされているか判定 |
|---|
| 351 | value[0] : 項目名 |
|---|
| 352 | value[1] : 判定対象要素名 |
|---|
| 353 | */ |
|---|
| 354 | function ALL_EXIST_CHECK($value) { |
|---|
| 355 | $max = count($value); |
|---|
| 356 | |
|---|
| 357 | // 既に該当項目にエラーがある場合は、判定しない。 |
|---|
| 358 | for($i = 1; $i < $max; $i++) { |
|---|
| 359 | if(isset($this->arrErr[$value[$i]])) { |
|---|
| 360 | return; |
|---|
| 361 | } |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | $blank = false; |
|---|
| 365 | $input = false; |
|---|
| 366 | |
|---|
| 367 | // すべての項目がブランクでないか、すべての項目が入力されていない場合はエラーとする。 |
|---|
| 368 | for($i = 1; $i < $max; $i++) { |
|---|
| 369 | if(strlen($this->arrParam[$value[$i]]) <= 0) { |
|---|
| 370 | $blank = true; |
|---|
| 371 | } else { |
|---|
| 372 | $input = true; |
|---|
| 373 | } |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | if($blank && $input) { |
|---|
| 377 | $this->arrErr[$value[1]] = "※ " . $value[0] . "はすべての項目を入力して下さい。<br />"; |
|---|
| 378 | } |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | /* 関連項目がどれか一つ満たされているか判定 |
|---|
| 382 | value[0] : 項目名 |
|---|
| 383 | value[1] : 判定対象要素名 |
|---|
| 384 | */ |
|---|
| 385 | function ONE_EXIST_CHECK($value) { |
|---|
| 386 | $max = count($value); |
|---|
| 387 | $this->createParam($value); |
|---|
| 388 | // 既に該当項目にエラーがある場合は、判定しない。 |
|---|
| 389 | for($i = 1; $i < $max; $i++) { |
|---|
| 390 | if(isset($this->arrErr[$value[$i]])) { |
|---|
| 391 | return; |
|---|
| 392 | } |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | $input = false; |
|---|
| 396 | |
|---|
| 397 | // すべての項目がブランクでないか、すべての項目が入力されていない場合はエラーとする。 |
|---|
| 398 | for($i = 1; $i < $max; $i++) { |
|---|
| 399 | if(strlen($this->arrParam[$value[$i]]) > 0) { |
|---|
| 400 | $input = true; |
|---|
| 401 | } |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | if(!$input) { |
|---|
| 405 | $this->arrErr[$value[1]] = "※ " . $value[0] . "が入力されていません。<br />"; |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | /* 上位の項目が満たされているか判定 |
|---|
| 410 | value[0] : 項目名 |
|---|
| 411 | value[1] : 判定対象要素名 |
|---|
| 412 | */ |
|---|
| 413 | function TOP_EXIST_CHECK($value) { |
|---|
| 414 | $max = count($value); |
|---|
| 415 | $this->createParam($value); |
|---|
| 416 | |
|---|
| 417 | // 既に該当項目にエラーがある場合は、判定しない。 |
|---|
| 418 | for($i = 1; $i < $max; $i++) { |
|---|
| 419 | if(isset($this->arrErr[$value[$i]])) { |
|---|
| 420 | return; |
|---|
| 421 | } |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | $blank = false; |
|---|
| 425 | $error = false; |
|---|
| 426 | |
|---|
| 427 | // すべての項目がブランクでないか、すべての項目が入力されていない場合はエラーとする。 |
|---|
| 428 | for($i = 1; $i < $max; $i++) { |
|---|
| 429 | if(strlen($this->arrParam[$value[$i]]) <= 0) { |
|---|
| 430 | $blank = true; |
|---|
| 431 | } else { |
|---|
| 432 | if($blank) { |
|---|
| 433 | $error = true; |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | if($error) { |
|---|
| 439 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は先頭の項目から順番に入力して下さい。<br />"; |
|---|
| 440 | } |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | /* カタカナの判定 */ |
|---|
| 445 | // value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 446 | function KANA_CHECK( $value ) { // 入力文字がカナ以外ならエラーを返す |
|---|
| 447 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 448 | return; |
|---|
| 449 | } |
|---|
| 450 | $this->createParam($value); |
|---|
| 451 | if(strlen($this->arrParam[$value[1]]) > 0 && ! mb_ereg("^[ァ-ヶヲ-゚ー]+$", $this->arrParam[$value[1]])) { |
|---|
| 452 | $this->arrErr[$value[1]] = "※ " . $value[0] . "はカタカナで入力してください。<br />"; |
|---|
| 453 | } |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | /* カタカナの判定2 (タブ、スペースは許可する) */ |
|---|
| 457 | // value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 458 | function KANABLANK_CHECK( $value ) { // 入力文字がカナ以外ならエラーを返す |
|---|
| 459 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 460 | return; |
|---|
| 461 | } |
|---|
| 462 | $this->createParam($value); |
|---|
| 463 | if(strlen($this->arrParam[$value[1]]) > 0 && ! mb_ereg("^([ \t\r\n]|[ァ-ヶ]|[ー])+$", $this->arrParam[$value[1]])) { |
|---|
| 464 | $this->arrErr[$value[1]] = "※ " . $value[0] . "はカタカナで入力してください。<br />"; |
|---|
| 465 | } |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | /* 英数字の判定 */ |
|---|
| 469 | // value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 470 | function ALNUM_CHECK( $value ) { // 入力文字が英数字以外ならエラーを返す |
|---|
| 471 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 472 | return; |
|---|
| 473 | } |
|---|
| 474 | $this->createParam($value); |
|---|
| 475 | if( strlen($this->arrParam[$value[1]]) > 0 && ! EregI("^[[:alnum:]]+$", $this->arrParam[$value[1]] ) ) { |
|---|
| 476 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は英数字で入力してください。<br />"; |
|---|
| 477 | } |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | /* 英数記号の判定 */ |
|---|
| 481 | // value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 482 | function GRAPH_CHECK( $value ) { // 入力文字が英数記号以外ならエラーを返す |
|---|
| 483 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 484 | return; |
|---|
| 485 | } |
|---|
| 486 | $this->createParam($value); |
|---|
| 487 | if( strlen($this->arrParam[$value[1]]) > 0 && ! EregI("^[[:graph:]]+$", $this->arrParam[$value[1]] ) ) { |
|---|
| 488 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は英数記号で入力してください。<br />"; |
|---|
| 489 | } |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | /* 必須選択の判定 */ |
|---|
| 493 | // value[0] = 項目名 value[1] = 判定対象 |
|---|
| 494 | function ZERO_CHECK( $value ) { // 入力値で0が許されない場合エラーを返す |
|---|
| 495 | $this->createParam($value); |
|---|
| 496 | if($this->arrParam[$value[1]] == "0" ){ |
|---|
| 497 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は1以上を入力してください。<br />"; |
|---|
| 498 | } |
|---|
| 499 | } |
|---|
| 500 | |
|---|
| 501 | /* 桁数の判定 (最小最大)*/ |
|---|
| 502 | // value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 最小桁数 value[3] = 最大桁数 |
|---|
| 503 | function NUM_RANGE_CHECK( $value ) { // 入力文字の桁数判定 → 最小桁数<入力文字列<最大桁数 |
|---|
| 504 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 505 | return; |
|---|
| 506 | } |
|---|
| 507 | $this->createParam($value); |
|---|
| 508 | // $this->arrParam[$value[0]] = mb_convert_kana($this->arrParam[$value[0]], "n"); |
|---|
| 509 | $count = strlen($this->arrParam[$value[1]]); |
|---|
| 510 | if( ( $count > 0 ) && $value[2] > $count || $value[3] < $count ) { |
|---|
| 511 | $this->arrErr[$value[1]] = "※ $value[0]は$value[2]桁~$value[3]桁で入力して下さい。<br />"; |
|---|
| 512 | } |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | /* 桁数の判定 */ |
|---|
| 516 | // value[0] = 項目名 value[1] = 判定対象文字列 value[2] = 桁数 |
|---|
| 517 | function NUM_COUNT_CHECK( $value ) { // 入力文字の桁数判定 → 入力文字列 = 桁数 以外はNGの場合 |
|---|
| 518 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 519 | return; |
|---|
| 520 | } |
|---|
| 521 | $this->createParam($value); |
|---|
| 522 | $count = strlen($this->arrParam[$value[1]]); |
|---|
| 523 | if(($count > 0) && $count != $value[2] ) { |
|---|
| 524 | $this->arrErr[$value[1]] = "※ $value[0]は$value[2]桁で入力して下さい。<br />"; |
|---|
| 525 | } |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | /* メールアドレス形式の判定 */ |
|---|
| 529 | // value[0] = 項目名 value[1] = 判定対象メールアドレス |
|---|
| 530 | function EMAIL_CHECK( $value ){ // メールアドレスを正規表現で判定する |
|---|
| 531 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 532 | return; |
|---|
| 533 | } |
|---|
| 534 | $this->createParam($value); |
|---|
| 535 | |
|---|
| 536 | $wsp = '[\x20\x09]'; |
|---|
| 537 | $vchar = '[\x21-\x7e]'; |
|---|
| 538 | $quoted_pair = "\\\\(?:$vchar|$wsp)"; |
|---|
| 539 | $qtext = '[\x21\x23-\x5b\x5d-\x7e]'; |
|---|
| 540 | $qcontent = "(?:$qtext|$quoted_pair)"; |
|---|
| 541 | $quoted_string = "\"$qcontent*\""; |
|---|
| 542 | $atext = '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]'; |
|---|
| 543 | $dot_atom_text = "$atext+(?:[.]$atext+)*"; |
|---|
| 544 | $dot_atom = $dot_atom_text; |
|---|
| 545 | $local_part = "(?:$dot_atom|$quoted_string)"; |
|---|
| 546 | $domain = $dot_atom; |
|---|
| 547 | $addr_spec = "${local_part}[@]$domain"; |
|---|
| 548 | |
|---|
| 549 | $dot_atom_loose = "$atext+(?:[.]|$atext)*"; |
|---|
| 550 | $local_part_loose = "(?:$dot_atom_loose|$quoted_string)"; |
|---|
| 551 | $addr_spec_loose = "${local_part_loose}[@]$domain"; |
|---|
| 552 | |
|---|
| 553 | if (RFC_COMPLIANT_EMAIL_CHECK) { |
|---|
| 554 | $regexp = "/\A${addr_spec}\z/"; |
|---|
| 555 | } else { |
|---|
| 556 | // 携帯メールアドレス用に、..や.@を許容する。 |
|---|
| 557 | $regexp = "/\A${addr_spec_loose}\z/"; |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | if(strlen($this->arrParam[$value[1]]) > 0 && !preg_match($regexp, $this->arrParam[$value[1]])) { |
|---|
| 561 | $this->arrErr[$value[1]] = "※ " . $value[0] . "の形式が不正です。<br />"; |
|---|
| 562 | } |
|---|
| 563 | } |
|---|
| 564 | |
|---|
| 565 | /* メールアドレスに使用できる文字の判定 */ |
|---|
| 566 | // value[0] = 項目名 value[1] = 判定対象メールアドレス |
|---|
| 567 | function EMAIL_CHAR_CHECK( $value ){ // メールアドレスに使用する文字を正規表現で判定する |
|---|
| 568 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 569 | return; |
|---|
| 570 | } |
|---|
| 571 | $this->createParam($value); |
|---|
| 572 | if(strlen($this->arrParam[$value[1]]) > 0 && !ereg("^[a-zA-Z0-9_\.@\+\?-]+$",$this->arrParam[$value[1]]) ) { |
|---|
| 573 | $this->arrErr[$value[1]] = "※ " . $value[0] . "に使用する文字を正しく入力してください。<br />"; |
|---|
| 574 | } |
|---|
| 575 | } |
|---|
| 576 | |
|---|
| 577 | /* URL形式の判定 */ |
|---|
| 578 | // value[0] = 項目名 value[1] = 判定対象URL |
|---|
| 579 | function URL_CHECK( $value ){ // URLを正規表現で判定する。デフォルトでhttp://があってもOK |
|---|
| 580 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 581 | return; |
|---|
| 582 | } |
|---|
| 583 | if( strlen($this->arrParam[$value[1]]) > 0 && !ereg( "^https?://+($|[a-zA-Z0-9_~=:&\?\.\/-])+$", $this->arrParam[$value[1]] ) ) { |
|---|
| 584 | $this->arrErr[$value[1]] = "※ " . $value[0] . "を正しく入力してください。<br />"; |
|---|
| 585 | } |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | /* 拡張子の判定 */ |
|---|
| 589 | // value[0] = 項目名 value[1] = 判定対象 value[2]=array(拡張子) |
|---|
| 590 | function FILE_EXT_CHECK( $value ) { // 受け取りがない場合エラーを返す |
|---|
| 591 | if(isset($this->arrErr[$value[1]]) || count($value[2]) == 0) { |
|---|
| 592 | return; |
|---|
| 593 | } |
|---|
| 594 | $this->createParam($value); |
|---|
| 595 | |
|---|
| 596 | if($_FILES[$value[1]]['name'] != "" ) { |
|---|
| 597 | $errFlag = 1; |
|---|
| 598 | $array_ext = explode(".", $_FILES[$value[1]]['name']); |
|---|
| 599 | $ext = $array_ext[ count ( $array_ext ) - 1 ]; |
|---|
| 600 | $ext = strtolower($ext); |
|---|
| 601 | |
|---|
| 602 | $strExt = ""; |
|---|
| 603 | |
|---|
| 604 | foreach ( $value[2] as $checkExt ){ |
|---|
| 605 | if ( $ext == $checkExt) { |
|---|
| 606 | $errFlag = 0; |
|---|
| 607 | } |
|---|
| 608 | |
|---|
| 609 | if($strExt == "") { |
|---|
| 610 | $strExt.= $checkExt; |
|---|
| 611 | } else { |
|---|
| 612 | $strExt.= "・$checkExt"; |
|---|
| 613 | } |
|---|
| 614 | } |
|---|
| 615 | } |
|---|
| 616 | if ($errFlag == 1) { |
|---|
| 617 | $this->arrErr[$value[1]] = "※ " . $value[0] . "で許可されている形式は、" . $strExt . "です。<br />"; |
|---|
| 618 | } |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | /* ファイルが存在するかチェックする */ |
|---|
| 622 | // value[0] = 項目名 value[1] = 判定対象 value[2] = 指定ディレクトリ |
|---|
| 623 | function FIND_FILE( $value ) { // 受け取りがない場合エラーを返す |
|---|
| 624 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 625 | return; |
|---|
| 626 | } |
|---|
| 627 | |
|---|
| 628 | $this->createParam($value); |
|---|
| 629 | if($value[2] != "") { |
|---|
| 630 | $dir = $value[2]; |
|---|
| 631 | } else { |
|---|
| 632 | $dir = IMAGE_SAVE_DIR; |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | $path = $dir . "/" . $this->arrParam[$value[1]]; |
|---|
| 636 | $path = ereg_replace("//", "/", $path); |
|---|
| 637 | |
|---|
| 638 | if($this->arrParam[$value[1]] != "" && !file_exists($path)){ |
|---|
| 639 | $this->arrErr[$value[1]] = "※ " . $path . "が見つかりません。<br />"; |
|---|
| 640 | } |
|---|
| 641 | } |
|---|
| 642 | |
|---|
| 643 | /* ファイルが上げられたか確認 */ |
|---|
| 644 | // value[0] = 項目名 value[1] = 判定対象 value[2] = 指定サイズ(KB) |
|---|
| 645 | function FILE_EXIST_CHECK( $value ) { // 受け取りがない場合エラーを返す |
|---|
| 646 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 647 | return; |
|---|
| 648 | } |
|---|
| 649 | $this->createParam($value); |
|---|
| 650 | if(!($_FILES[$value[1]]['size'] != "" && $_FILES[$value[1]]['size'] > 0)){ |
|---|
| 651 | $this->arrErr[$value[1]] = "※ " . $value[0] . "をアップロードして下さい。<br />"; |
|---|
| 652 | } |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | /* ファイルサイズの判定 */ |
|---|
| 656 | // value[0] = 項目名 value[1] = 判定対象 value[2] = 指定サイズ(KB) |
|---|
| 657 | function FILE_SIZE_CHECK( $value ) { // 受け取りがない場合エラーを返す |
|---|
| 658 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 659 | return; |
|---|
| 660 | } |
|---|
| 661 | $this->createParam($value); |
|---|
| 662 | if( $_FILES[$value[1]]['size'] > $value[2] * 1024 ){ |
|---|
| 663 | $byte = "KB"; |
|---|
| 664 | if( $value[2] >= 1000 ) { |
|---|
| 665 | $value[2] = $value[2] / 1000; |
|---|
| 666 | $byte = "MB"; |
|---|
| 667 | } |
|---|
| 668 | $this->arrErr[$value[1]] = "※ " . $value[0] . "のファイルサイズは" . $value[2] . $byte . "以下のものを使用してください。<br />"; |
|---|
| 669 | } |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | /* ファイル名の判定 */ |
|---|
| 673 | // value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 674 | function FILE_NAME_CHECK( $value ) { // 入力文字が英数字,"_","-"以外ならエラーを返す |
|---|
| 675 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 676 | return; |
|---|
| 677 | } |
|---|
| 678 | $this->createParam($value); |
|---|
| 679 | if( strlen($_FILES[$value[1]]['name']) > 0 && ! EregI("^[[:alnum:]_\.-]+$", $_FILES[$value[1]]['name']) ) { |
|---|
| 680 | $this->arrErr[$value[1]] = "※ " . $value[0] . "のファイル名に日本語やスペースは使用しないで下さい。<br />"; |
|---|
| 681 | } |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | /* ファイル名の判定(アップロード以外の時) */ |
|---|
| 685 | // value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 686 | function FILE_NAME_CHECK_BY_NOUPLOAD( $value ) { // 入力文字が英数字,"_","-"以外ならエラーを返す |
|---|
| 687 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 688 | return; |
|---|
| 689 | } |
|---|
| 690 | $this->createParam($value); |
|---|
| 691 | if( strlen($this->arrParam[$value[1]]) > 0 && ! EregI("^[[:alnum:]_\.-]+$", $this->arrParam[$value[1]]) || EregI("[\\]" ,$this->arrParam[$value[1]])) { |
|---|
| 692 | $this->arrErr[$value[1]] = "※ " . $value[0] . "のファイル名に日本語やスペースは使用しないで下さい。<br />"; |
|---|
| 693 | } |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | //日付チェック |
|---|
| 697 | // value[0] = 項目名 |
|---|
| 698 | // value[1] = YYYY |
|---|
| 699 | // value[2] = MM |
|---|
| 700 | // value[3] = DD |
|---|
| 701 | function CHECK_DATE($value) { |
|---|
| 702 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 703 | return; |
|---|
| 704 | } |
|---|
| 705 | $this->createParam($value); |
|---|
| 706 | // 少なくともどれか一つが入力されている。 |
|---|
| 707 | if($this->arrParam[$value[1]] > 0 || $this->arrParam[$value[2]] > 0 || $this->arrParam[$value[3]] > 0) { |
|---|
| 708 | // 年月日のどれかが入力されていない。 |
|---|
| 709 | if(!(strlen($this->arrParam[$value[1]]) > 0 && strlen($this->arrParam[$value[2]]) > 0 && strlen($this->arrParam[$value[3]]) > 0)) { |
|---|
| 710 | $this->arrErr[$value[1]] = "※ " . $value[0] . "はすべての項目を入力して下さい。<br />"; |
|---|
| 711 | } else if ( ! checkdate($this->arrParam[$value[2]], $this->arrParam[$value[3]], $this->arrParam[$value[1]])) { |
|---|
| 712 | $this->arrErr[$value[1]] = "※ " . $value[0] . "が正しくありません。<br />"; |
|---|
| 713 | } |
|---|
| 714 | } |
|---|
| 715 | } |
|---|
| 716 | |
|---|
| 717 | //日付チェック |
|---|
| 718 | // value[0] = 項目名 |
|---|
| 719 | // value[1] = YYYY |
|---|
| 720 | // value[2] = MM |
|---|
| 721 | // value[3] = DD |
|---|
| 722 | // value[4] = HH |
|---|
| 723 | // value[5] = mm |
|---|
| 724 | function CHECK_DATE2($value) { |
|---|
| 725 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 726 | return; |
|---|
| 727 | } |
|---|
| 728 | $this->createParam($value); |
|---|
| 729 | // 少なくともどれか一つが入力されている。 |
|---|
| 730 | 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) { |
|---|
| 731 | // 年月日時のどれかが入力されていない。 |
|---|
| 732 | 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 )) { |
|---|
| 733 | $this->arrErr[$value[1]] = "※ " . $value[0] . "はすべての項目を入力して下さい。<br />"; |
|---|
| 734 | } else if ( ! checkdate($this->arrParam[$value[2]], $this->arrParam[$value[3]], $this->arrParam[$value[1]])) { |
|---|
| 735 | $this->arrErr[$value[1]] = "※ " . $value[0] . "が正しくありません。<br />"; |
|---|
| 736 | } |
|---|
| 737 | } |
|---|
| 738 | } |
|---|
| 739 | |
|---|
| 740 | //日付チェック |
|---|
| 741 | // value[0] = 項目名 |
|---|
| 742 | // value[1] = YYYY |
|---|
| 743 | // value[2] = MM |
|---|
| 744 | function CHECK_DATE3($value) { |
|---|
| 745 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 746 | return; |
|---|
| 747 | } |
|---|
| 748 | $this->createParam($value); |
|---|
| 749 | // 少なくともどれか一つが入力されている。 |
|---|
| 750 | if($this->arrParam[$value[1]] > 0 || $this->arrParam[$value[2]] > 0) { |
|---|
| 751 | // 年月日時のどれかが入力されていない。 |
|---|
| 752 | if(!(strlen($this->arrParam[$value[1]]) > 0 && strlen($this->arrParam[$value[2]]) > 0)) { |
|---|
| 753 | $this->arrErr[$value[1]] = "※ " . $value[0] . "はすべての項目を入力して下さい。<br />"; |
|---|
| 754 | } else if ( ! checkdate($this->arrParam[$value[2]], 1, $this->arrParam[$value[1]])) { |
|---|
| 755 | $this->arrErr[$value[1]] = "※ " . $value[0] . "が正しくありません。<br />"; |
|---|
| 756 | } |
|---|
| 757 | } |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | //誕生日チェック |
|---|
| 761 | // value[0] = 項目名 |
|---|
| 762 | // value[1] = YYYY |
|---|
| 763 | // value[2] = MM |
|---|
| 764 | // value[3] = DD |
|---|
| 765 | function CHECK_BIRTHDAY($value) { |
|---|
| 766 | if (isset($this->arrErr[$value[1]])) { |
|---|
| 767 | return; |
|---|
| 768 | } |
|---|
| 769 | |
|---|
| 770 | $this->createParam($value); |
|---|
| 771 | // 年が入力されている。 |
|---|
| 772 | if ($this->arrParam[$value[1]] > 0) { |
|---|
| 773 | |
|---|
| 774 | // 年の数字チェック、最小数値制限チェック |
|---|
| 775 | $this->doFunc(array($value[0].'(年)', $value[1], START_BIRTH_YEAR), array("NUM_CHECK", "MIN_CHECK")); |
|---|
| 776 | // 上のチェックでエラーある場合、中断する。 |
|---|
| 777 | if (isset($this->arrErr[$value[1]])) { |
|---|
| 778 | return; |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | // 年の最大数値制限チェック |
|---|
| 782 | $this->doFunc(array($value[0].'(年)', $value[1], date("Y",strtotime("now"))), array("MAX_CHECK")); |
|---|
| 783 | // 上のチェックでエラーある場合、中断する。 |
|---|
| 784 | if (isset($this->arrErr[$value[1]])) { |
|---|
| 785 | return; |
|---|
| 786 | } |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | // XXX createParam() が二重に呼ばれる問題を抱える |
|---|
| 790 | $this->CHECK_DATE($value); |
|---|
| 791 | } |
|---|
| 792 | |
|---|
| 793 | /*-----------------------------------------------------------------*/ |
|---|
| 794 | /* CHECK_SET_TERM |
|---|
| 795 | /* 年月日に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
|---|
| 796 | /* 引数 (開始年,開始月,開始日,終了年,終了月,終了日) |
|---|
| 797 | /* 戻値 array(1,2,3) |
|---|
| 798 | /* 1.開始年月日 (YYYYMMDD 000000) |
|---|
| 799 | /* 2.終了年月日 (YYYYMMDD 235959) |
|---|
| 800 | /* 3.エラー ( 0 = OK, 1 = NG ) |
|---|
| 801 | /*-----------------------------------------------------------------*/ |
|---|
| 802 | // value[0] = 項目名1 |
|---|
| 803 | // value[1] = 項目名2 |
|---|
| 804 | // value[2] = start_year |
|---|
| 805 | // value[3] = start_month |
|---|
| 806 | // value[4] = start_day |
|---|
| 807 | // value[5] = end_year |
|---|
| 808 | // value[6] = end_month |
|---|
| 809 | // value[7] = end_day |
|---|
| 810 | function CHECK_SET_TERM ($value) { |
|---|
| 811 | |
|---|
| 812 | // 期間指定 |
|---|
| 813 | if(isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[5]])) { |
|---|
| 814 | return; |
|---|
| 815 | } |
|---|
| 816 | $this->createParam($value); |
|---|
| 817 | $error = 0; |
|---|
| 818 | 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]]) ) { |
|---|
| 819 | $this->arrErr[$value[2]] = "※ " . $value[0] . "を正しく指定してください。<br />"; |
|---|
| 820 | } |
|---|
| 821 | 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]]) ) { |
|---|
| 822 | $this->arrErr[$value[5]] = "※ " . $value[1] . "を正しく指定してください。<br />"; |
|---|
| 823 | } |
|---|
| 824 | 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) ){ |
|---|
| 825 | |
|---|
| 826 | $date1 = $this->arrParam[$value[2]] .sprintf("%02d", $this->arrParam[$value[3]]) .sprintf("%02d",$this->arrParam[$value[4]]) ."000000"; |
|---|
| 827 | $date2 = $this->arrParam[$value[5]] .sprintf("%02d", $this->arrParam[$value[6]]) .sprintf("%02d",$this->arrParam[$value[7]]) ."235959"; |
|---|
| 828 | |
|---|
| 829 | if (($this->arrErr[$value[2]] == "" && $this->arrErr[$value[5]] == "") && $date1 > $date2) { |
|---|
| 830 | $this->arrErr[$value[2]] = "※ " .$value[0]. "と" .$value[1]. "の期間指定が不正です。<br />"; |
|---|
| 831 | } |
|---|
| 832 | } |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| 835 | /*-----------------------------------------------------------------*/ |
|---|
| 836 | /* CHECK_SET_TERM2 |
|---|
| 837 | /* 年月日時に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
|---|
| 838 | /* 引数 (開始年,開始月,開始日,開始時間,開始分,開始秒, |
|---|
| 839 | /* 終了年,終了月,終了日,終了時間,終了分,終了秒) |
|---|
| 840 | /* 戻値 array(1,2,3) |
|---|
| 841 | /* 1.開始年月日 (YYYYMMDDHHmmss) |
|---|
| 842 | /* 2.終了年月日 (YYYYMMDDHHmmss) |
|---|
| 843 | /* 3.エラー ( 0 = OK, 1 = NG ) |
|---|
| 844 | /*-----------------------------------------------------------------*/ |
|---|
| 845 | // value[0] = 項目名1 |
|---|
| 846 | // value[1] = 項目名2 |
|---|
| 847 | // value[2] = start_year |
|---|
| 848 | // value[3] = start_month |
|---|
| 849 | // value[4] = start_day |
|---|
| 850 | // value[5] = start_hour |
|---|
| 851 | // value[6] = start_minute |
|---|
| 852 | // value[7] = start_second |
|---|
| 853 | // value[8] = end_year |
|---|
| 854 | // value[9] = end_month |
|---|
| 855 | // value[10] = end_day |
|---|
| 856 | // value[11] = end_hour |
|---|
| 857 | // value[12] = end_minute |
|---|
| 858 | // value[13] = end_second |
|---|
| 859 | |
|---|
| 860 | /*-----------------------------------------------------------------*/ |
|---|
| 861 | function CHECK_SET_TERM2 ($value) { |
|---|
| 862 | |
|---|
| 863 | // 期間指定 |
|---|
| 864 | if(isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[8]])) { |
|---|
| 865 | return; |
|---|
| 866 | } |
|---|
| 867 | $this->createParam($value); |
|---|
| 868 | $error = 0; |
|---|
| 869 | 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]]) ) { |
|---|
| 870 | $this->arrErr[$value[2]] = "※ " . $value[0] . "を正しく指定してください。<br />"; |
|---|
| 871 | } |
|---|
| 872 | 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]]) ) { |
|---|
| 873 | $this->arrErr[$value[8]] = "※ " . $value[1] . "を正しく指定してください。<br />"; |
|---|
| 874 | } |
|---|
| 875 | 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) ){ |
|---|
| 876 | |
|---|
| 877 | $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]]); |
|---|
| 878 | $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]]); |
|---|
| 879 | |
|---|
| 880 | if (($this->arrErr[$value[2]] == "" && $this->arrErr[$value[8]] == "") && $date1 > $date2) { |
|---|
| 881 | $this->arrErr[$value[2]] = "※ " .$value[0]. "と" .$value[1]. "の期間指定が不正です。<br />"; |
|---|
| 882 | } |
|---|
| 883 | if($date1 == $date2) { |
|---|
| 884 | $this->arrErr[$value[2]] = "※ " .$value[0]. "と" .$value[1]. "の期間指定が不正です。<br />"; |
|---|
| 885 | } |
|---|
| 886 | |
|---|
| 887 | } |
|---|
| 888 | } |
|---|
| 889 | |
|---|
| 890 | /*-----------------------------------------------------------------*/ |
|---|
| 891 | /* CHECK_SET_TERM3 |
|---|
| 892 | /* 年月に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
|---|
| 893 | /* 引数 (開始年,開始月,終了年,終了月) |
|---|
| 894 | /* 戻値 array(1,2,3) |
|---|
| 895 | /* 1.開始年月日 (YYYYMMDD 000000) |
|---|
| 896 | /* 2.終了年月日 (YYYYMMDD 235959) |
|---|
| 897 | /* 3.エラー ( 0 = OK, 1 = NG ) |
|---|
| 898 | /*-----------------------------------------------------------------*/ |
|---|
| 899 | // value[0] = 項目名1 |
|---|
| 900 | // value[1] = 項目名2 |
|---|
| 901 | // value[2] = start_year |
|---|
| 902 | // value[3] = start_month |
|---|
| 903 | // value[4] = end_year |
|---|
| 904 | // value[5] = end_month |
|---|
| 905 | function CHECK_SET_TERM3 ($value) { |
|---|
| 906 | |
|---|
| 907 | // 期間指定 |
|---|
| 908 | if(isset($this->arrErr[$value[2]]) || isset($this->arrErr[$value[4]])) { |
|---|
| 909 | return; |
|---|
| 910 | } |
|---|
| 911 | $this->createParam($value); |
|---|
| 912 | $error = 0; |
|---|
| 913 | if ( (strlen($this->arrParam[$value[2]]) > 0 || strlen($this->arrParam[$value[3]]) > 0) && ! checkdate($this->arrParam[$value[3]], 1, $this->arrParam[$value[2]]) ) { |
|---|
| 914 | $this->arrErr[$value[2]] = "※ " . $value[0] . "を正しく指定してください。<br />"; |
|---|
| 915 | } |
|---|
| 916 | if ( (strlen($this->arrParam[$value[4]]) > 0 || strlen($this->arrParam[$value[5]]) > 0) && ! checkdate($this->arrParam[$value[5]], 1, $this->arrParam[$value[4]]) ) { |
|---|
| 917 | $this->arrErr[$value[4]] = "※ " . $value[1] . "を正しく指定してください。<br />"; |
|---|
| 918 | } |
|---|
| 919 | 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 ))) { |
|---|
| 920 | |
|---|
| 921 | $date1 = $this->arrParam[$value[2]] .sprintf("%02d", $this->arrParam[$value[3]]); |
|---|
| 922 | $date2 = $this->arrParam[$value[4]] .sprintf("%02d", $this->arrParam[$value[5]]); |
|---|
| 923 | |
|---|
| 924 | if (($this->arrErr[$value[2]] == "" && $this->arrErr[$value[5]] == "") && $date1 > $date2) { |
|---|
| 925 | $this->arrErr[$value[2]] = "※ " .$value[0]. "と" .$value[1]. "の期間指定が不正です。<br />"; |
|---|
| 926 | } |
|---|
| 927 | } |
|---|
| 928 | } |
|---|
| 929 | |
|---|
| 930 | //ディレクトリ存在チェック |
|---|
| 931 | function DIR_CHECK ($value) { |
|---|
| 932 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 933 | return; |
|---|
| 934 | } |
|---|
| 935 | $this->createParam($value); |
|---|
| 936 | if(!is_dir($this->arrParam[$value[1]])) { |
|---|
| 937 | $this->arrErr[$value[1]] = "※ 指定した" . $value[0] . "は存在しません。<br />"; |
|---|
| 938 | } |
|---|
| 939 | } |
|---|
| 940 | |
|---|
| 941 | //ディレクトリ存在チェック |
|---|
| 942 | function DOMAIN_CHECK ($value) { |
|---|
| 943 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 944 | return; |
|---|
| 945 | } |
|---|
| 946 | if(strlen($this->arrParam[$value[1]]) > 0 && !ereg("^\.[^.]+\..+", $this->arrParam[$value[1]])) { |
|---|
| 947 | $this->arrErr[$value[1]] = "※ " . $value[0] . "の形式が不正です。<br />"; |
|---|
| 948 | } |
|---|
| 949 | } |
|---|
| 950 | |
|---|
| 951 | /* 携帯メールアドレスの判定 */ |
|---|
| 952 | // value[0] = 項目名 value[1] = 判定対象メールアドレス |
|---|
| 953 | function MOBILE_EMAIL_CHECK( $value ){ // メールアドレスを正規表現で判定する |
|---|
| 954 | if(isset($this->arrErr[$value[1]])) { |
|---|
| 955 | return; |
|---|
| 956 | } |
|---|
| 957 | $this->createParam($value); |
|---|
| 958 | $objMobile = new SC_Helper_Mobile_Ex(); |
|---|
| 959 | if(strlen($this->arrParam[$value[1]]) > 0 && !$objMobile->gfIsMobileMailAddress($this->arrParam[$value[1]])) { |
|---|
| 960 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は携帯電話のものではありません。<br />"; |
|---|
| 961 | } |
|---|
| 962 | } |
|---|
| 963 | /** |
|---|
| 964 | * 禁止文字列のチェック |
|---|
| 965 | * value[0] = 項目名 value[1] = 判定対象文字列 |
|---|
| 966 | * value[2] = 入力を禁止する文字列(配列) |
|---|
| 967 | * |
|---|
| 968 | * @example $objErr->doFunc(array("URL", "contents", $arrReviewDenyURL), array("PROHIBITED_STR_CHECK")); |
|---|
| 969 | */ |
|---|
| 970 | function PROHIBITED_STR_CHECK( $value ) { |
|---|
| 971 | if( isset($this->arrErr[$value[1]]) || empty($this->arrParam[$value[1]]) ) { |
|---|
| 972 | return; |
|---|
| 973 | } |
|---|
| 974 | $this->createParam($value); |
|---|
| 975 | $targetStr = $this->arrParam[$value[1]]; |
|---|
| 976 | $prohibitedStr = str_replace(array('|', '/'), array('\|', '\/'), $value[2]); |
|---|
| 977 | |
|---|
| 978 | $pattern = '/' . join('|', $prohibitedStr) . '/i'; |
|---|
| 979 | if(preg_match_all($pattern, $this->arrParam[$value[1]], $matches)) { |
|---|
| 980 | $this->arrErr[$value[1]] = "※ " . $value[0] . "は入力できません。<br />"; |
|---|
| 981 | } |
|---|
| 982 | } |
|---|
| 983 | |
|---|
| 984 | /** |
|---|
| 985 | * PHPコードとして評価可能かチェックする. |
|---|
| 986 | * |
|---|
| 987 | * @access private |
|---|
| 988 | * @param array $value [0] => 項目名, [1] => 評価する文字列 |
|---|
| 989 | * @return void |
|---|
| 990 | */ |
|---|
| 991 | function EVAL_CHECK($value) { |
|---|
| 992 | if (isset($this->arrErr[$value[0]])) { |
|---|
| 993 | return; |
|---|
| 994 | } |
|---|
| 995 | $this->createParam($value); |
|---|
| 996 | if ($this->evalCheck($value[1]) === false) { |
|---|
| 997 | $this->arrErr[$value[0]] = "※ " . $value[0] . " の形式が不正です。<br />"; |
|---|
| 998 | } |
|---|
| 999 | } |
|---|
| 1000 | |
|---|
| 1001 | /** |
|---|
| 1002 | * $value が PHPコードとして評価可能かチェックする. |
|---|
| 1003 | * |
|---|
| 1004 | * @access private |
|---|
| 1005 | * @param mixed PHPコードとして評価する文字列 |
|---|
| 1006 | * @return mixed PHPコードとして評価できない場合 false, |
|---|
| 1007 | * 評価可能な場合は評価した値 |
|---|
| 1008 | */ |
|---|
| 1009 | function evalCheck($value) { |
|---|
| 1010 | // falseは、正当な式と評価する。 |
|---|
| 1011 | if($value === "false") { |
|---|
| 1012 | return true; |
|---|
| 1013 | } |
|---|
| 1014 | return @eval("return " . $value . ";"); |
|---|
| 1015 | } |
|---|
| 1016 | |
|---|
| 1017 | /** |
|---|
| 1018 | * 未定義の $this->arrParam に空要素を代入する. |
|---|
| 1019 | * |
|---|
| 1020 | * @access private |
|---|
| 1021 | * @param array $value 配列 |
|---|
| 1022 | * @return void |
|---|
| 1023 | */ |
|---|
| 1024 | function createParam($value) { |
|---|
| 1025 | foreach ($value as $key) { |
|---|
| 1026 | if (is_string($key) || is_int($key)) { |
|---|
| 1027 | if (!isset($this->arrParam[$key])) $this->arrParam[$key] = ""; |
|---|
| 1028 | } |
|---|
| 1029 | } |
|---|
| 1030 | } |
|---|
| 1031 | } |
|---|
| 1032 | ?> |
|---|