| 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
| 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
| 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * パラメータ管理クラス |
---|
| 26 | * |
---|
| 27 | * :XXX: addParam と setParam で言う「パラメータ」が用語として競合しているように感じる。(2009/10/17 Seasoft 塚田) |
---|
| 28 | * |
---|
| 29 | * @package SC |
---|
| 30 | * @author LOCKON CO.,LTD. |
---|
| 31 | */ |
---|
| 32 | class SC_FormParam { |
---|
| 33 | |
---|
| 34 | var $param; |
---|
| 35 | var $disp_name; |
---|
| 36 | var $keyname; |
---|
| 37 | var $length; |
---|
| 38 | var $convert; |
---|
| 39 | var $arrCheck; |
---|
| 40 | var $default; // 何も入力されていないときに表示する値 |
---|
| 41 | var $input_db; // DBにそのまま挿入可能か否か |
---|
| 42 | var $html_disp_name; |
---|
| 43 | |
---|
| 44 | // コンストラクタ |
---|
| 45 | function SC_FormParam() { |
---|
| 46 | $this->check_dir = IMAGE_SAVE_DIR; |
---|
| 47 | $this->initParam(); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * パラメータの初期化 |
---|
| 52 | * |
---|
| 53 | * @return void |
---|
| 54 | */ |
---|
| 55 | function initParam() { |
---|
| 56 | $this->disp_name = array(); |
---|
| 57 | $this->keyname = array(); |
---|
| 58 | $this->length = array(); |
---|
| 59 | $this->convert = array(); |
---|
| 60 | $this->arrCheck = array(); |
---|
| 61 | $this->default = array(); |
---|
| 62 | $this->input_db = array(); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | // パラメータの追加 |
---|
| 66 | function addParam($disp_name, $keyname, $length="", $convert="", $arrCheck=array(), $default="", $input_db="true") { |
---|
| 67 | $this->disp_name[] = $disp_name; |
---|
| 68 | $this->keyname[] = $keyname; |
---|
| 69 | $this->length[] = $length; |
---|
| 70 | $this->convert[] = $convert; |
---|
| 71 | $this->arrCheck[] = $arrCheck; |
---|
| 72 | $this->default[] = $default; |
---|
| 73 | $this->input_db[] = $input_db; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // パラメータの入力 |
---|
| 77 | // $arrVal :$arrVal['keyname']・・の配列を一致したキーのインスタンスに格納する |
---|
| 78 | // $seq :trueの場合、$arrVal[0]~の配列を登録順にインスタンスに格納する |
---|
| 79 | function setParam($arrVal, $seq = false) { |
---|
| 80 | $cnt = 0; |
---|
| 81 | if(!$seq){ |
---|
| 82 | foreach($this->keyname as $val) { |
---|
| 83 | if(isset($arrVal[$val])) { |
---|
| 84 | $this->setValue($val, $arrVal[$val]); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | } else { |
---|
| 88 | foreach($this->keyname as $val) { |
---|
| 89 | $this->param[$cnt] = $arrVal[$cnt]; |
---|
| 90 | $cnt++; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | // 画面表示用タイトル生成 |
---|
| 96 | function setHtmlDispNameArray() { |
---|
| 97 | $cnt = 0; |
---|
| 98 | foreach($this->keyname as $val) { |
---|
| 99 | $find = false; |
---|
| 100 | foreach($this->arrCheck[$cnt] as $val) { |
---|
| 101 | if($val == "EXIST_CHECK") { |
---|
| 102 | $find = true; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | if($find) { |
---|
| 107 | $this->html_disp_name[$cnt] = $this->disp_name[$cnt] . "<span class='red'>(※ 必須)</span>"; |
---|
| 108 | } else { |
---|
| 109 | $this->html_disp_name[$cnt] = $this->disp_name[$cnt]; |
---|
| 110 | } |
---|
| 111 | $cnt++; |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | // 画面表示用タイトル取得 |
---|
| 116 | function getHtmlDispNameArray() { |
---|
| 117 | return $this->html_disp_name; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | // 複数列パラメータの取得 |
---|
| 121 | function setParamList($arrVal, $keyname) { |
---|
| 122 | // DBの件数を取得する。 |
---|
| 123 | $count = count($arrVal); |
---|
| 124 | $no = 1; |
---|
| 125 | for($cnt = 0; $cnt < $count; $cnt++) { |
---|
| 126 | $key = $keyname.$no; |
---|
| 127 | if($arrVal[$cnt][$keyname] != "") { |
---|
| 128 | $this->setValue($key, $arrVal[$cnt][$keyname]); |
---|
| 129 | } |
---|
| 130 | $no++; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | function setDBDate($db_date, $year_key = 'year', $month_key = 'month', $day_key = 'day') { |
---|
| 135 | |
---|
| 136 | if (!empty($db_date)) { |
---|
| 137 | list($y, $m, $d) = split("[- ]", $db_date); |
---|
| 138 | $this->setValue($year_key, $y); |
---|
| 139 | $this->setValue($month_key, $m); |
---|
| 140 | $this->setValue($day_key, $d); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | // キーに対応した値をセットする。 |
---|
| 145 | function setValue($key, $param) { |
---|
| 146 | $cnt = 0; |
---|
| 147 | foreach($this->keyname as $val) { |
---|
| 148 | if($val == $key) { |
---|
| 149 | $this->param[$cnt] = $param; |
---|
| 150 | // 複数一致の場合もあるので break してはいけない。 |
---|
| 151 | } |
---|
| 152 | $cnt++; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | function toLower($key) { |
---|
| 157 | $cnt = 0; |
---|
| 158 | foreach($this->keyname as $val) { |
---|
| 159 | if($val == $key) { |
---|
| 160 | $this->param[$cnt] = strtolower($this->param[$cnt]); |
---|
| 161 | // 複数一致の場合もあるので break してはいけない。 |
---|
| 162 | } |
---|
| 163 | $cnt++; |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | // エラーチェック |
---|
| 168 | function checkError($br = true, $keyname = "") { |
---|
| 169 | // 連想配列の取得 |
---|
| 170 | $arrRet = $this->getHashArray($keyname); |
---|
| 171 | $objErr = new SC_CheckError($arrRet); |
---|
| 172 | |
---|
| 173 | $cnt = 0; |
---|
| 174 | foreach($this->keyname as $val) { |
---|
| 175 | foreach($this->arrCheck[$cnt] as $func) { |
---|
| 176 | if (!isset($this->param[$cnt])) $this->param[$cnt] = ""; |
---|
| 177 | switch($func) { |
---|
| 178 | case 'EXIST_CHECK': |
---|
| 179 | case 'NUM_CHECK': |
---|
| 180 | case 'EMAIL_CHECK': |
---|
| 181 | case 'EMAIL_CHAR_CHECK': |
---|
| 182 | case 'ALNUM_CHECK': |
---|
| 183 | case 'GRAPH_CHECK': |
---|
| 184 | case 'KANA_CHECK': |
---|
| 185 | case 'URL_CHECK': |
---|
| 186 | case 'SPTAB_CHECK': |
---|
| 187 | case 'ZERO_CHECK': |
---|
| 188 | case 'ALPHA_CHECK': |
---|
| 189 | case 'ZERO_START': |
---|
| 190 | case 'FIND_FILE': |
---|
| 191 | case 'NO_SPTAB': |
---|
| 192 | case 'DIR_CHECK': |
---|
| 193 | case 'DOMAIN_CHECK': |
---|
| 194 | case 'FILE_NAME_CHECK': |
---|
| 195 | case 'MOBILE_EMAIL_CHECK': |
---|
| 196 | |
---|
| 197 | if(!is_array($this->param[$cnt])) { |
---|
| 198 | $objErr->doFunc(array($this->disp_name[$cnt], $val), array($func)); |
---|
| 199 | } else { |
---|
| 200 | $max = count($this->param[$cnt]); |
---|
| 201 | for($i = 0; $i < $max; $i++) { |
---|
| 202 | $objSubErr = new SC_CheckError($this->param[$cnt]); |
---|
| 203 | $objSubErr->doFunc(array($this->disp_name[$cnt], $i), array($func)); |
---|
| 204 | if(count($objSubErr->arrErr) > 0) { |
---|
| 205 | foreach($objSubErr->arrErr as $mess) { |
---|
| 206 | if($mess != "") { |
---|
| 207 | $objErr->arrErr[$val] = $mess; |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | break; |
---|
| 214 | case 'MAX_LENGTH_CHECK': |
---|
| 215 | case 'MIN_LENGTH_CHECK': |
---|
| 216 | case 'NUM_COUNT_CHECK': |
---|
| 217 | if(!is_array($this->param[$cnt])) { |
---|
| 218 | $objErr->doFunc(array($this->disp_name[$cnt], $val, $this->length[$cnt]), array($func)); |
---|
| 219 | } else { |
---|
| 220 | $max = count($this->param[$cnt]); |
---|
| 221 | for($i = 0; $i < $max; $i++) { |
---|
| 222 | $objSubErr = new SC_CheckError($this->param[$cnt]); |
---|
| 223 | $objSubErr->doFunc(array($this->disp_name[$cnt], $i, $this->length[$cnt]), array($func)); |
---|
| 224 | if(count($objSubErr->arrErr) > 0) { |
---|
| 225 | foreach($objSubErr->arrErr as $mess) { |
---|
| 226 | if($mess != "") { |
---|
| 227 | $objErr->arrErr[$val] = $mess; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | break; |
---|
| 234 | // 小文字に変換 |
---|
| 235 | case 'CHANGE_LOWER': |
---|
| 236 | $this->param[$cnt] = strtolower($this->param[$cnt]); |
---|
| 237 | break; |
---|
| 238 | // ファイルの存在チェック |
---|
| 239 | case 'FILE_EXISTS': |
---|
| 240 | if($this->param[$cnt] != "" && !file_exists($this->check_dir . $this->param[$cnt])) { |
---|
| 241 | $objErr->arrErr[$val] = "※ " . $this->disp_name[$cnt] . "のファイルが存在しません。<br>"; |
---|
| 242 | } |
---|
| 243 | break; |
---|
| 244 | default: |
---|
| 245 | $objErr->arrErr[$val] = "※※ エラーチェック形式($func)には対応していません ※※ <br>"; |
---|
| 246 | break; |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | if (isset($objErr->arrErr[$val]) && !$br) { |
---|
| 251 | $objErr->arrErr[$val] = ereg_replace("<br>$", "", $objErr->arrErr[$val]); |
---|
| 252 | } |
---|
| 253 | $cnt++; |
---|
| 254 | } |
---|
| 255 | return $objErr->arrErr; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | // 入力文字の変換 |
---|
| 259 | function convParam() { |
---|
| 260 | /* |
---|
| 261 | * 文字列の変換 |
---|
| 262 | * K : 「半角(ハンカク)片仮名」を「全角片仮名」に変換 |
---|
| 263 | * C : 「全角ひら仮名」を「全角かた仮名」に変換 |
---|
| 264 | * V : 濁点付きの文字を一文字に変換。"K","H"と共に使用します |
---|
| 265 | * n : 「全角」数字を「半角(ハンカク)」に変換 |
---|
| 266 | * a : 「全角」英字を「半角」英字に変換 |
---|
| 267 | */ |
---|
| 268 | $cnt = 0; |
---|
| 269 | foreach ($this->keyname as $val) { |
---|
| 270 | if (!isset($this->param[$cnt])) $this->param[$cnt] = ""; |
---|
| 271 | |
---|
| 272 | if(!is_array($this->param[$cnt])) { |
---|
| 273 | if($this->convert[$cnt] != "") { |
---|
| 274 | $this->param[$cnt] = mb_convert_kana($this->param[$cnt] ,$this->convert[$cnt]); |
---|
| 275 | } |
---|
| 276 | } else { |
---|
| 277 | $max = count($this->param[$cnt]); |
---|
| 278 | for($i = 0; $i < $max; $i++) { |
---|
| 279 | if($this->convert[$cnt] != "") { |
---|
| 280 | $this->param[$cnt][$i] = mb_convert_kana($this->param[$cnt][$i] ,$this->convert[$cnt]); |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | $cnt++; |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | // 連想配列の作成 |
---|
| 289 | function getHashArray($keyname = "") { |
---|
| 290 | $arrRet = array(); |
---|
| 291 | $cnt = 0; |
---|
| 292 | foreach($this->keyname as $val) { |
---|
| 293 | if($keyname == "" || $keyname == $val) { |
---|
| 294 | $arrRet[$val] = isset($this->param[$cnt]) ? $this->param[$cnt] : ""; |
---|
| 295 | $cnt++; |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | return $arrRet; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | // DB格納用配列の作成 |
---|
| 302 | function getDbArray() { |
---|
| 303 | $cnt = 0; |
---|
| 304 | foreach ($this->keyname as $val) { |
---|
| 305 | if ($this->input_db[$cnt]) { |
---|
| 306 | $arrRet[$val] = isset($this->param[$cnt]) ? $this->param[$cnt] : ""; |
---|
| 307 | } |
---|
| 308 | $cnt++; |
---|
| 309 | } |
---|
| 310 | return $arrRet; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | // 配列の縦横を入れ替えて返す |
---|
| 314 | function getSwapArray($arrKey) { |
---|
| 315 | foreach($arrKey as $keyname) { |
---|
| 316 | $arrVal = $this->getValue($keyname); |
---|
| 317 | $max = count($arrVal); |
---|
| 318 | for($i = 0; $i < $max; $i++) { |
---|
| 319 | $arrRet[$i][$keyname] = $arrVal[$i]; |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | return $arrRet; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | // 項目名一覧の取得 |
---|
| 326 | function getTitleArray() { |
---|
| 327 | return $this->disp_name; |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | // 項目数を返す |
---|
| 331 | function getCount() { |
---|
| 332 | $count = count($this->keyname); |
---|
| 333 | return $count; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | // フォームに渡す用のパラメータを返す |
---|
| 337 | function getFormParamList() { |
---|
| 338 | $cnt = 0; |
---|
| 339 | foreach($this->keyname as $val) { |
---|
| 340 | |
---|
| 341 | // キー名 |
---|
| 342 | $arrRet[$val]['keyname'] = $this->keyname[$cnt]; |
---|
| 343 | // 文字数制限 |
---|
| 344 | $arrRet[$val]['length'] = $this->length[$cnt]; |
---|
| 345 | // 入力値 |
---|
| 346 | if (isset($this->param[$cnt])) { |
---|
| 347 | $arrRet[$val]['value'] = $this->param[$cnt]; |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | if (!isset($this->param[$cnt])) $this->param[$cnt] = ""; |
---|
| 351 | |
---|
| 352 | if($this->default[$cnt] != "" && $this->param[$cnt] == "") { |
---|
| 353 | $arrRet[$val]['value'] = $this->default[$cnt]; |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | $cnt++; |
---|
| 357 | } |
---|
| 358 | return $arrRet; |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | // キー名の一覧を返す |
---|
| 362 | function getKeyList() { |
---|
| 363 | foreach($this->keyname as $val) { |
---|
| 364 | $arrRet[] = $val; |
---|
| 365 | } |
---|
| 366 | return $arrRet; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | // キー名と一致した値を返す |
---|
| 370 | function getValue($keyname) { |
---|
| 371 | $cnt = 0; |
---|
| 372 | foreach($this->keyname as $val) { |
---|
| 373 | if($val == $keyname) { |
---|
| 374 | $ret = isset($this->param[$cnt]) ? $this->param[$cnt] : ""; |
---|
| 375 | break; |
---|
| 376 | } |
---|
| 377 | $cnt++; |
---|
| 378 | } |
---|
| 379 | return $ret; |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | function splitCheckBoxes($keyname) { |
---|
| 383 | $cnt = 0; |
---|
| 384 | foreach($this->keyname as $val) { |
---|
| 385 | if($val == $keyname) { |
---|
| 386 | $this->param[$cnt] = sfSplitCheckBoxes($this->param[$cnt]); |
---|
| 387 | } |
---|
| 388 | $cnt++; |
---|
| 389 | } |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | function splitParamCheckBoxes($keyname) { |
---|
| 393 | $cnt = 0; |
---|
| 394 | foreach($this->keyname as $val) { |
---|
| 395 | if($val == $keyname) { |
---|
| 396 | if(isset($this->param[$cnt]) && !is_array($this->param[$cnt])) { |
---|
| 397 | $this->param[$cnt] = split("-", $this->param[$cnt]); |
---|
| 398 | } |
---|
| 399 | } |
---|
| 400 | $cnt++; |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | ?> |
---|