Changeset 21645 for branches/version-2_12-dev
- Timestamp:
- 2012/03/14 14:37:35 (12 years ago)
- Location:
- branches/version-2_12-dev/data/class
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/SC_FormParam.php
r21593 r21645 32 32 class SC_FormParam { 33 33 34 var $param; 35 var $disp_name; 36 var $keyname; 37 var $length; 38 var $convert; 39 var $arrCheck; 40 /** 何も入力されていないときに表示する値 */ 41 var $default; 34 /** 35 * 何も入力されていないときに表示する値 36 * キーはキー名 37 */ 38 var $arrValue = array(); 39 40 /** 表示名 */ 41 var $disp_name = array(); 42 43 /** キー名 */ 44 var $keyname = array(); 45 46 var $length = array(); 47 var $convert = array(); 48 var $arrCheck = array(); 49 50 /** 51 * 何も入力されていないときに表示する値 52 * キーはキー名 53 */ 54 var $arrDefault = array(); 55 42 56 /** DBにそのまま挿入可能か否か */ 43 var $input_db; 44 var $html_disp_name; 45 46 // コンストラクタ 47 function SC_FormParam() { 57 var $input_db = array(); 58 59 var $html_disp_name = array(); 60 61 /** 62 * コンストラクタ 63 */ 64 function __construct() { 48 65 $this->check_dir = IMAGE_SAVE_REALDIR; 49 $this->initParam(); 50 } 51 52 /** 53 * パラメーターの初期化 54 * 55 * @return void 66 } 67 68 /** 69 * 前方互換用 70 * 71 * @deprecated 2.12.0 #1702 56 72 */ 57 73 function initParam() { … … 61 77 $this->convert = array(); 62 78 $this->arrCheck = array(); 63 $this-> default = array();79 $this->arrDefault = array(); 64 80 $this->input_db = array(); 65 81 } 66 82 67 83 // パラメーターの追加 68 function addParam($disp_name, $keyname, $length = '', $convert = '', $arrCheck = array(), $default = '', $input_db = 'true') {84 function addParam($disp_name, $keyname, $length = '', $convert = '', $arrCheck = array(), $default = '', $input_db = true) { 69 85 $this->disp_name[] = $disp_name; 70 86 $this->keyname[] = $keyname; … … 72 88 $this->convert[] = $convert; 73 89 $this->arrCheck[] = $arrCheck; 74 $this->default[] = $default; 90 // XXX このタイミングで arrValue へ格納するほうがスマートかもしれない。しかし、バリデーションや変換の対象となるので、その良し悪しは気になる。 91 $this->arrDefault[$keyname] = $default; 75 92 $this->input_db[] = $input_db; 76 93 } … … 81 98 function setParam($arrVal, $seq = false) { 82 99 if (!is_array($arrVal)) return; 83 $cnt = 0;84 100 if (!$seq) { 85 foreach ($this->keyname as $val) { 86 if (array_key_exists($val, $arrVal)) { 87 $this->setValue($val, $arrVal[$val]); 88 } 101 foreach ($arrVal as $key => $val) { 102 $this->setValue($key, $val); 89 103 } 90 104 } else { 91 foreach ($this->keyname as $val) { 92 $this->param[$cnt] = $arrVal[$cnt]; 93 $cnt++; 105 foreach ($this->keyname as $index => $key) { 106 $this->setValue($key, $arrVal[$index]); 94 107 } 95 108 } … … 98 111 // 画面表示用タイトル生成 99 112 function setHtmlDispNameArray() { 100 $cnt = 0; 101 foreach ($this->keyname as $val) { 113 foreach ($this->keyname as $index => $key) { 102 114 $find = false; 103 foreach ($this->arrCheck[$ cnt] as $val) {115 foreach ($this->arrCheck[$index] as $val) { 104 116 if ($val == 'EXIST_CHECK') { 105 117 $find = true; … … 108 120 109 121 if ($find) { 110 $this->html_disp_name[$ cnt] = $this->disp_name[$cnt] . '<span class="red">(※ 必須)</span>';122 $this->html_disp_name[$index] = $this->disp_name[$index] . '<span class="red">(※ 必須)</span>'; 111 123 } else { 112 $this->html_disp_name[$cnt] = $this->disp_name[$cnt]; 113 } 114 if ($this->default[$cnt] != '') { 115 $this->html_disp_name[$cnt] .= ' [省略時初期値: ' . $this->default[$cnt] . ']'; 116 } 117 if ($this->input_db[$cnt] == false) { 118 $this->html_disp_name[$cnt] .= ' [登録・更新不可] '; 119 } 120 $cnt++; 124 $this->html_disp_name[$index] = $this->disp_name[$index]; 125 } 126 if ($this->arrDefault[$key] != '') { 127 $this->html_disp_name[$index] .= ' [省略時初期値: ' . $this->arrDefault[$key] . ']'; 128 } 129 if ($this->input_db[$index] == false) { 130 $this->html_disp_name[$index] .= ' [登録・更新不可] '; 131 } 121 132 } 122 133 } … … 128 139 129 140 // 複数列パラメーターの取得 130 function setParamList($arrVal , $keyname) {141 function setParamList($arrVal2d, $keyname) { 131 142 // DBの件数を取得する。 132 $count = count($arrVal);133 143 $no = 1; 134 for ($cnt = 0; $cnt < $count; $cnt++) { 135 $key = $keyname.$no; 136 if ($arrVal[$cnt][$keyname] != '') { 137 $this->setValue($key, $arrVal[$cnt][$keyname]); 138 } 144 foreach ($arrVal2d as $arrVal) { 145 $key = $keyname . $no; 146 $this->setValue($key, $arrVal[$keyname]); 139 147 $no++; 140 148 } … … 142 150 143 151 function setDBDate($db_date, $year_key = 'year', $month_key = 'month', $day_key = 'day') { 144 145 if (!empty($db_date)) {146 list($y, $m, $d) = preg_split('/[- ]/', $db_date);147 $this->setValue($year_key, $y);148 $this->setValue($month_key, $m);149 $this->setValue($day_key, $d);150 }152 if (empty($db_date)) { 153 return; 154 } 155 list($y, $m, $d) = preg_split('/[- ]/', $db_date); 156 $this->setValue($year_key, $y); 157 $this->setValue($month_key, $m); 158 $this->setValue($day_key, $d); 151 159 } 152 160 153 161 // キーに対応した値をセットする。 154 function setValue($key, $param) { 155 $cnt = 0; 156 foreach ($this->keyname as $val) { 157 if ($val == $key) { 158 $this->param[$cnt] = $param; 159 // 複数一致の場合もあるので break してはいけない。 160 } 161 $cnt++; 162 } 162 function setValue($key, $value) { 163 if (!in_array($key, $this->keyname)) { 164 // TODO 警告発生 165 return; 166 } 167 $this->arrValue[$key] = $value; 163 168 } 164 169 165 170 function toLower($key) { 166 $cnt = 0; 167 foreach ($this->keyname as $val) { 168 if ($val == $key) { 169 $this->param[$cnt] = strtolower($this->param[$cnt]); 170 // 複数一致の場合もあるので break してはいけない。 171 } 172 $cnt++; 171 if (isset($this->arrValue[$key])) { 172 $this->arrValue[$key] = strtolower($this->arrValue[$key]); 173 173 } 174 174 } … … 178 178 $objErr->arrErr = array(); 179 179 180 $cnt = 0; 181 foreach ($this->keyname as $val) { 182 foreach ($this->arrCheck[$cnt] as $func) { 183 if (!isset($this->param[$cnt])) $this->param[$cnt] = ''; 180 foreach ($this->keyname as $index => $key) { 181 foreach ($this->arrCheck[$index] as $func) { 182 $value = $this->getValue($key); 184 183 switch ($func) { 185 184 case 'EXIST_CHECK': … … 208 207 case 'SELECT_CHECK': 209 208 case 'FILE_NAME_CHECK_BY_NOUPLOAD': 210 $this->recursionCheck($this->disp_name[$cnt], $func, 211 $this->param[$cnt], $objErr->arrErr, 212 $val, $this->length[$cnt]); 209 $this->recursionCheck($this->disp_name[$index], $func, 210 $value, $objErr->arrErr, $key, $this->length[$index]); 213 211 break; 214 212 // 小文字に変換 215 213 case 'CHANGE_LOWER': 216 $this-> param[$cnt] = strtolower($this->param[$cnt]);214 $this->toLower($key); 217 215 break; 218 216 // ファイルの存在チェック 219 217 case 'FILE_EXISTS': 220 if ($ this->param[$cnt] != '' && !file_exists($this->check_dir . $this->param[$cnt])) {221 $objErr->arrErr[$ val] = '※ ' . $this->disp_name[$cnt] . 'のファイルが存在しません。<br>';218 if ($value != '' && !file_exists($this->check_dir . $value)) { 219 $objErr->arrErr[$key] = '※ ' . $this->disp_name[$index] . 'のファイルが存在しません。<br>'; 222 220 } 223 221 break; 224 222 // ダウンロード用ファイルの存在チェック 225 223 case 'DOWN_FILE_EXISTS': 226 if ($ this->param[$cnt] != '' && !file_exists(DOWN_SAVE_REALDIR . $this->param[$cnt])) {227 $objErr->arrErr[$ val] = '※ ' . $this->disp_name[$cnt] . 'のファイルが存在しません。<br>';224 if ($value != '' && !file_exists(DOWN_SAVE_REALDIR . $value)) { 225 $objErr->arrErr[$key] = '※ ' . $this->disp_name[$index] . 'のファイルが存在しません。<br>'; 228 226 } 229 227 break; 230 228 default: 231 $objErr->arrErr[$ val] = "※※ エラーチェック形式($func)には対応していません ※※ <br>";229 $objErr->arrErr[$key] = "※※ エラーチェック形式($func)には対応していません ※※ <br>"; 232 230 break; 233 231 } 234 232 } 235 233 236 if (isset($objErr->arrErr[$val]) && !$br) { 237 $objErr->arrErr[$val] = preg_replace("/<br(\s+\/)?>/i", '', $objErr->arrErr[$val]); 238 } 239 $cnt++; 234 if (isset($objErr->arrErr[$key]) && !$br) { 235 $objErr->arrErr[$key] = preg_replace("/<br(\s+\/)?>/i", '', $objErr->arrErr[$key]); 236 } 240 237 } 241 238 return $objErr->arrErr; … … 260 257 */ 261 258 function recursionCheck($disp_name, $func, $value, &$arrErr, $error_key, 262 $length = 0, $depth = 0, $error_last_key = null) { 259 $length = 0, $depth = 0, $error_last_key = null 260 ) { 263 261 if (is_array($value)) { 264 262 $depth++; … … 290 288 * フォームの入力パラメーターに応じて, 再帰的に mb_convert_kana 関数を実行する. 291 289 * 292 * @return voi 290 * @return void 293 291 * @see mb_convert_kana 294 292 */ 295 293 function convParam() { 296 $cnt = 0; 297 foreach ($this->keyname as $val) { 298 if (!isset($this->param[$cnt])) $this->param[$cnt] = ''; 299 $this->recursionConvParam($this->param[$cnt], $this->convert[$cnt]); 300 $cnt++; 294 foreach ($this->keyname as $index => $key) { 295 if (isset($this->arrValue[$key])) { 296 $this->recursionConvParam($this->arrValue[$key], $this->convert[$index]); 297 } 301 298 } 302 299 } … … 330 327 foreach ($this->keyname as $index => $keyname) { 331 328 if (empty($arrKey) || in_array($keyname, $arrKey)) { 332 $arrRet[$keyname] = isset($this->param[$index]) ? $this->param[$index] : '';329 $arrRet[$keyname] = $this->getValue($keyname); 333 330 } 334 331 } … … 338 335 // DB格納用配列の作成 339 336 function getDbArray() { 340 $cnt = 0; 341 foreach ($this->keyname as $val) { 342 if ($this->input_db[$cnt]) { 343 $arrRet[$val] = isset($this->param[$cnt]) ? $this->param[$cnt] : ''; 344 } 345 $cnt++; 337 foreach ($this->keyname as $index => $key) { 338 if ($this->input_db[$index]) { 339 $arrRet[$key] = $this->getValue($key); 340 } 346 341 } 347 342 return $arrRet; … … 372 367 // フォームに渡す用のパラメーターを返す 373 368 function getFormParamList() { 374 $cnt = 0; 375 foreach ($this->keyname as $val) { 376 369 foreach ($this->keyname as $index => $key) { 377 370 // キー名 378 $arrRet[$val]['keyname'] = $this->keyname[$cnt]; 371 $arrRet[$key]['keyname'] = $key; 372 // 表示名 373 $arrRet[$key]['disp_name'] = $this->disp_name[$index]; 379 374 // 文字数制限 380 $arrRet[$ val]['length'] = $this->length[$cnt];375 $arrRet[$key]['length'] = $this->length[$index]; 381 376 // 入力値 382 if (isset($this->param[$cnt])) { 383 $arrRet[$val]['value'] = $this->param[$cnt]; 384 } 385 386 if (!isset($this->param[$cnt])) $this->param[$cnt] = ''; 387 388 if ($this->default[$cnt] != '' && $this->param[$cnt] == '') { 389 $arrRet[$val]['value'] = $this->default[$cnt]; 390 } 391 392 $cnt++; 377 $arrRet[$key]['value'] = $this->getValue($key); 393 378 } 394 379 return $arrRet; … … 406 391 // キー名と一致した値を返す 407 392 function getValue($keyname, $default = '') { 408 $cnt = 0;409 393 $ret = null; 410 foreach ($this->keyname as $ val) {411 if ($ val== $keyname) {412 $ret = isset($this-> param[$cnt]) ? $this->param[$cnt] : '';394 foreach ($this->keyname as $index => $key) { 395 if ($key == $keyname) { 396 $ret = isset($this->arrValue[$key]) ? $this->arrValue[$key] : $this->arrDefault[$key]; 413 397 break; 414 398 } 415 $cnt++;416 399 } 417 400 … … 434 417 */ 435 418 function splitParamCheckBoxes($keyname) { 436 $cnt = 0; 437 foreach ($this->keyname as $val) { 438 if ($val == $keyname) { 439 if (isset($this->param[$cnt]) && !is_array($this->param[$cnt])) { 440 $this->param[$cnt] = explode('-', $this->param[$cnt]); 419 foreach ($this->keyname as $key) { 420 if ($key == $keyname) { 421 if (isset($this->arrValue[$key]) && !is_array($this->arrValue[$key])) { 422 $this->arrValue[$key] = explode('-', $this->arrValue[$key]); 441 423 } 442 424 } 443 $cnt++;444 425 } 445 426 } … … 452 433 */ 453 434 function trimParam($has_wide_space = true) { 454 $cnt = 0; 455 foreach ($this->keyname as $val) { 456 if (!isset($this->param[$cnt])) $this->param[$cnt] = ''; 457 $this->recursionTrim($this->param[$cnt], $has_wide_space); 458 $cnt++; 435 foreach ($this->arrValue as &$value) { 436 $this->recursionTrim($value, $has_wide_space); 459 437 } 460 438 } … … 492 470 */ 493 471 function getSearchArray($prefix = 'search_') { 494 $cnt = 0;495 472 $arrResults = array(); 496 foreach ($this->keyname as $ key) {473 foreach ($this->keyname as $index => $key) { 497 474 if (preg_match('/^' . $prefix . '/', $key)) { 498 $arrResults[$key] = isset($this->param[$cnt]) 499 ? $this->param[$cnt] : ''; 500 } 501 $cnt++; 475 $arrResults[$key] = $this->getValue($key); 476 } 502 477 } 503 478 return $arrResults; 504 479 } 505 480 506 507 // addParam の内容をそのまま返す 481 /** 482 * 前方互換用 483 * 484 * 1次キーが添字なのが特徴だったと思われる。 485 * @deprecated 2.12.0 必要ならば getFormParamList メソッドに引数を追加するなどで実現可能 486 */ 508 487 function getFormDispArray() { 509 $cnt = 0; 510 foreach ($this->keyname as $val) { 488 foreach ($this->keyname as $index => $key) { 511 489 // キー名 512 $arrRet[$cnt]['keyname'] = $this->keyname[$cnt]; 490 $arrRet[$index]['keyname'] = $key; 491 // 表示名 492 $arrRet[$index]['disp_name'] = $this->disp_name[$index]; 513 493 // 文字数制限 514 $arrRet[$cnt]['length'] = $this->length[$cnt]; 515 516 $arrRet[$cnt]['disp_name'] = $this->disp_name[$cnt]; 494 $arrRet[$index]['length'] = $this->length[$index]; 517 495 // 入力値 518 if (isset($this->param[$cnt])) { 519 $arrRet[$cnt]['value'] = $this->param[$cnt]; 520 } 521 522 if (!isset($this->param[$cnt])) $this->param[$cnt] = ''; 523 524 if ($this->default[$cnt] != '' && $this->param[$cnt] == '') { 525 $arrRet[$cnt]['value'] = $this->default[$cnt]; 526 } 527 $cnt++; 496 $arrRet[$index]['value'] = $this->getValue($key); 528 497 } 529 498 return $arrRet; 530 499 } 531 532 533 500 } -
branches/version-2_12-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_DeliveryInput.php
r21592 r21645 75 75 $objPlugin->doAction('lc_page_admin_basis_deliveryinput_action_start', array($this)); 76 76 77 $objFormParam = new SC_FormParam_Ex();78 77 $this->lfInitParam($this->mode, $objFormParam); 79 78 $objFormParam->setParam($_POST); … … 118 117 /* パラメーター情報の初期化 */ 119 118 function lfInitParam($mode, &$objFormParam) { 120 $objFormParam ->initParam();119 $objFormParam = new SC_FormParam_Ex(); 121 120 122 121 switch ($mode) {
Note: See TracChangeset
for help on using the changeset viewer.