| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2007 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 | * 主に static 参照するユーティリティ系の関数群 |
|---|
| 28 | * |
|---|
| 29 | * :XXX: 内部でインスタンスを生成している関数は, Helper クラスへ移動するべき... |
|---|
| 30 | * |
|---|
| 31 | * @package Util |
|---|
| 32 | * @author LOCKON CO.,LTD. |
|---|
| 33 | * @version $Id:SC_Utils.php 15532 2007-08-31 14:39:46Z nanasess $ |
|---|
| 34 | */ |
|---|
| 35 | class SC_Utils { |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * サイト管理情報から値を取得する。 |
|---|
| 39 | * データが存在する場合、必ず1以上の数値が設定されている。 |
|---|
| 40 | * 0を返した場合は、呼び出し元で対応すること。 |
|---|
| 41 | * |
|---|
| 42 | * @param $control_id 管理ID |
|---|
| 43 | * @param $dsn DataSource |
|---|
| 44 | * @return $control_flg フラグ |
|---|
| 45 | */ |
|---|
| 46 | function sfGetSiteControlFlg($control_id, $dsn = "") { |
|---|
| 47 | |
|---|
| 48 | // データソース |
|---|
| 49 | if($dsn == "") { |
|---|
| 50 | if(defined('DEFAULT_DSN')) { |
|---|
| 51 | $dsn = DEFAULT_DSN; |
|---|
| 52 | } else { |
|---|
| 53 | return; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | // クエリ生成 |
|---|
| 58 | $target_column = "control_flg"; |
|---|
| 59 | $table_name = "dtb_site_control"; |
|---|
| 60 | $where = "control_id = ?"; |
|---|
| 61 | $arrval = array($control_id); |
|---|
| 62 | $control_flg = 0; |
|---|
| 63 | |
|---|
| 64 | // クエリ発行 |
|---|
| 65 | $objQuery = new SC_Query($dsn, true, true); |
|---|
| 66 | $arrSiteControl = $objQuery->select($target_column, $table_name, $where, $arrval); |
|---|
| 67 | |
|---|
| 68 | // データが存在すればフラグを取得する |
|---|
| 69 | if (count($arrSiteControl) > 0) { |
|---|
| 70 | $control_flg = $arrSiteControl[0]["control_flg"]; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | return $control_flg; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | // インストール初期処理 |
|---|
| 77 | function sfInitInstall() { |
|---|
| 78 | // インストール済みが定義されていない。 |
|---|
| 79 | if(!defined('ECCUBE_INSTALL')) { |
|---|
| 80 | if(!ereg("/install/", $_SERVER['PHP_SELF'])) { |
|---|
| 81 | header("Location: ./install/"); // TODO 絶対URL にする |
|---|
| 82 | } |
|---|
| 83 | } else { |
|---|
| 84 | $path = HTML_PATH . "install/index.php"; |
|---|
| 85 | if(file_exists($path)) { |
|---|
| 86 | SC_Utils::sfErrorHeader(">> /install/index.phpは、インストール完了後にファイルを削除してください。"); |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | // アップデートで生成されたPHPを読み出し |
|---|
| 92 | function sfLoadUpdateModule() { |
|---|
| 93 | // URL設定ディレクトリを削除 |
|---|
| 94 | $main_php = ereg_replace(URL_DIR, "", $_SERVER['PHP_SELF']); |
|---|
| 95 | $extern_php = UPDATE_PATH . $main_php; |
|---|
| 96 | if(file_exists($extern_php)) { |
|---|
| 97 | require_once($extern_php); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | // 装飾付きエラーメッセージの表示 |
|---|
| 102 | function sfErrorHeader($mess, $print = false) { |
|---|
| 103 | global $GLOBAL_ERR; |
|---|
| 104 | $GLOBAL_ERR.="<div style='color: #F00; font-weight: bold; font-size: 12px;" |
|---|
| 105 | . "background-color: #FEB; text-align: center; padding: 5px;'>"; |
|---|
| 106 | $GLOBAL_ERR.= $mess; |
|---|
| 107 | $GLOBAL_ERR.= "</div>"; |
|---|
| 108 | if($print) { |
|---|
| 109 | print($GLOBAL_ERR); |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | /* エラーページの表示 */ |
|---|
| 114 | function sfDispError($type) { |
|---|
| 115 | |
|---|
| 116 | require_once(CLASS_EX_PATH . "page_extends/error/LC_Page_Error_DispError_Ex.php"); |
|---|
| 117 | |
|---|
| 118 | $objPage = new LC_Page_Error_DispError_Ex(); |
|---|
| 119 | register_shutdown_function(array($objPage, "destroy")); |
|---|
| 120 | $objPage->init(); |
|---|
| 121 | $objPage->type = $type; |
|---|
| 122 | $objPage->process(); |
|---|
| 123 | exit; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /* サイトエラーページの表示 */ |
|---|
| 127 | function sfDispSiteError($type, $objSiteSess = "", $return_top = false, $err_msg = "", $is_mobile = false) { |
|---|
| 128 | global $objCampaignSess; |
|---|
| 129 | |
|---|
| 130 | require_once(CLASS_EX_PATH . "page_extends/error/LC_Page_Error_Ex.php"); |
|---|
| 131 | |
|---|
| 132 | $objPage = new LC_Page_Error_Ex(); |
|---|
| 133 | register_shutdown_function(array($objPage, "destroy")); |
|---|
| 134 | $objPage->init(); |
|---|
| 135 | $objPage->type = $type; |
|---|
| 136 | $objPage->objSiteSess = $objSiteSess; |
|---|
| 137 | $objPage->return_top = $return_top; |
|---|
| 138 | $objPage->err_msg = $err_msg; |
|---|
| 139 | $objPage->is_mobile = $is_mobile; |
|---|
| 140 | $objPage->process(); |
|---|
| 141 | exit; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | /* 認証の可否判定 */ |
|---|
| 145 | function sfIsSuccess($objSess, $disp_error = true) { |
|---|
| 146 | $ret = $objSess->IsSuccess(); |
|---|
| 147 | if($ret != SUCCESS) { |
|---|
| 148 | if($disp_error) { |
|---|
| 149 | // エラーページの表示 |
|---|
| 150 | SC_Utils::sfDispError($ret); |
|---|
| 151 | } |
|---|
| 152 | return false; |
|---|
| 153 | } |
|---|
| 154 | // リファラーチェック(CSRFの暫定的な対策) |
|---|
| 155 | // 「リファラ無」 の場合はスルー |
|---|
| 156 | // 「リファラ有」 かつ 「管理画面からの遷移でない」 場合にエラー画面を表示する |
|---|
| 157 | if ( empty($_SERVER['HTTP_REFERER']) ) { |
|---|
| 158 | // TODO 警告表示させる? |
|---|
| 159 | // sfErrorHeader('>> referrerが無効になっています。'); |
|---|
| 160 | } else { |
|---|
| 161 | $domain = SC_Utils::sfIsHTTPS() ? SSL_URL : SITE_URL; |
|---|
| 162 | $pattern = sprintf('|^%s.*|', $domain); |
|---|
| 163 | $referer = $_SERVER['HTTP_REFERER']; |
|---|
| 164 | |
|---|
| 165 | // 管理画面から以外の遷移の場合はエラー画面を表示 |
|---|
| 166 | if (!preg_match($pattern, $referer)) { |
|---|
| 167 | if ($disp_error) SC_Utils::sfDispError(INVALID_MOVE_ERRORR); |
|---|
| 168 | return false; |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | return true; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | /** |
|---|
| 175 | * 文字列をアスタリスクへ変換する. |
|---|
| 176 | * |
|---|
| 177 | * @param string $passlen 変換する文字列 |
|---|
| 178 | * @return string アスタリスクへ変換した文字列 |
|---|
| 179 | */ |
|---|
| 180 | function lfPassLen($passlen){ |
|---|
| 181 | $ret = ""; |
|---|
| 182 | for ($i=0;$i<$passlen;true){ |
|---|
| 183 | $ret.="*"; |
|---|
| 184 | $i++; |
|---|
| 185 | } |
|---|
| 186 | return $ret; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | /** |
|---|
| 190 | * HTTPSかどうかを判定 |
|---|
| 191 | * |
|---|
| 192 | * @return bool |
|---|
| 193 | */ |
|---|
| 194 | function sfIsHTTPS () { |
|---|
| 195 | // HTTPS時には$_SERVER['HTTPS']には空でない値が入る |
|---|
| 196 | // $_SERVER['HTTPS'] != 'off' はIIS用 |
|---|
| 197 | if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { |
|---|
| 198 | return true; |
|---|
| 199 | } else { |
|---|
| 200 | return false; |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | /** |
|---|
| 205 | * 正規の遷移がされているかを判定 |
|---|
| 206 | * 前画面でuniqidを埋め込んでおく必要がある |
|---|
| 207 | * @param obj SC_Session, SC_SiteSession |
|---|
| 208 | * @return bool |
|---|
| 209 | */ |
|---|
| 210 | function sfIsValidTransition($objSess) { |
|---|
| 211 | // 前画面からPOSTされるuniqidが正しいものかどうかをチェック |
|---|
| 212 | $uniqid = $objSess->getUniqId(); |
|---|
| 213 | if ( !empty($_POST['uniqid']) && ($_POST['uniqid'] === $uniqid) ) { |
|---|
| 214 | return true; |
|---|
| 215 | } else { |
|---|
| 216 | return false; |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | /* 前のページで正しく登録が行われたか判定 */ |
|---|
| 221 | function sfIsPrePage(&$objSiteSess, $is_mobile = false) { |
|---|
| 222 | $ret = $objSiteSess->isPrePage(); |
|---|
| 223 | if($ret != true) { |
|---|
| 224 | // エラーページの表示 |
|---|
| 225 | SC_Utils::sfDispSiteError(PAGE_ERROR, $objSiteSess, false, "", $is_mobile); |
|---|
| 226 | } |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | function sfCheckNormalAccess(&$objSiteSess, &$objCartSess) { |
|---|
| 230 | // ユーザユニークIDの取得 |
|---|
| 231 | $uniqid = $objSiteSess->getUniqId(); |
|---|
| 232 | // 購入ボタンを押した時のカート内容がコピーされていない場合のみコピーする。 |
|---|
| 233 | $objCartSess->saveCurrentCart($uniqid); |
|---|
| 234 | // POSTのユニークIDとセッションのユニークIDを比較(ユニークIDがPOSTされていない場合はスルー) |
|---|
| 235 | $ret = $objSiteSess->checkUniqId(); |
|---|
| 236 | if($ret != true) { |
|---|
| 237 | // エラーページの表示 |
|---|
| 238 | SC_Utils_Ex::sfDispSiteError(CANCEL_PURCHASE, $objSiteSess); |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | // カート内が空でないか || 購入ボタンを押してから変化がないか |
|---|
| 242 | $quantity = $objCartSess->getTotalQuantity(); |
|---|
| 243 | $ret = $objCartSess->checkChangeCart(); |
|---|
| 244 | if($ret == true || !($quantity > 0)) { |
|---|
| 245 | // カート情報表示に強制移動する |
|---|
| 246 | // FIXME false を返して, Page クラスで遷移させるべき... |
|---|
| 247 | if (defined("MOBILE_SITE")) { |
|---|
| 248 | header("Location: ". MOBILE_URL_CART_TOP |
|---|
| 249 | . "?" . session_name() . "=" . session_id()); |
|---|
| 250 | } else { |
|---|
| 251 | header("Location: ".URL_CART_TOP); |
|---|
| 252 | } |
|---|
| 253 | } |
|---|
| 254 | return $uniqid; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | /* DB用日付文字列取得 */ |
|---|
| 258 | function sfGetTimestamp($year, $month, $day, $last = false) { |
|---|
| 259 | if($year != "" && $month != "" && $day != "") { |
|---|
| 260 | if($last) { |
|---|
| 261 | $time = "23:59:59"; |
|---|
| 262 | } else { |
|---|
| 263 | $time = "00:00:00"; |
|---|
| 264 | } |
|---|
| 265 | $date = $year."-".$month."-".$day." ".$time; |
|---|
| 266 | } else { |
|---|
| 267 | $date = ""; |
|---|
| 268 | } |
|---|
| 269 | return $date; |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | // INT型の数値チェック |
|---|
| 273 | function sfIsInt($value) { |
|---|
| 274 | if($value != "" && strlen($value) <= INT_LEN && is_numeric($value)) { |
|---|
| 275 | return true; |
|---|
| 276 | } |
|---|
| 277 | return false; |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | function sfCSVDownload($data, $prefix = ""){ |
|---|
| 281 | |
|---|
| 282 | if($prefix == "") { |
|---|
| 283 | $dir_name = SC_Utils::sfUpDirName(); |
|---|
| 284 | $file_name = $dir_name . date("ymdHis") .".csv"; |
|---|
| 285 | } else { |
|---|
| 286 | $file_name = $prefix . date("ymdHis") .".csv"; |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | /* HTTPヘッダの出力 */ |
|---|
| 290 | Header("Content-disposition: attachment; filename=${file_name}"); |
|---|
| 291 | Header("Content-type: application/octet-stream; name=${file_name}"); |
|---|
| 292 | Header("Cache-Control: "); |
|---|
| 293 | Header("Pragma: "); |
|---|
| 294 | |
|---|
| 295 | if (mb_internal_encoding() == CHAR_CODE){ |
|---|
| 296 | $data = mb_convert_encoding($data,'SJIS',CHAR_CODE); |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | /* データを出力 */ |
|---|
| 300 | echo $data; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | /* 1階層上のディレクトリ名を取得する */ |
|---|
| 304 | function sfUpDirName() { |
|---|
| 305 | $path = $_SERVER['PHP_SELF']; |
|---|
| 306 | $arrVal = split("/", $path); |
|---|
| 307 | $cnt = count($arrVal); |
|---|
| 308 | return $arrVal[($cnt - 2)]; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | /** |
|---|
| 315 | * 現在のサイトを更新(ただしポストは行わない) |
|---|
| 316 | * |
|---|
| 317 | * @deprecated LC_Page::reload() を使用して下さい. |
|---|
| 318 | */ |
|---|
| 319 | function sfReload($get = "") { |
|---|
| 320 | if ($_SERVER["SERVER_PORT"] == "443" ){ |
|---|
| 321 | $url = ereg_replace(URL_DIR . "$", "", SSL_URL); |
|---|
| 322 | } else { |
|---|
| 323 | $url = ereg_replace(URL_DIR . "$", "", SITE_URL); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | if($get != "") { |
|---|
| 327 | header("Location: ". $url . $_SERVER['PHP_SELF'] . "?" . $get); |
|---|
| 328 | } else { |
|---|
| 329 | header("Location: ". $url . $_SERVER['PHP_SELF']); |
|---|
| 330 | } |
|---|
| 331 | exit; |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | // チェックボックスの値をマージ |
|---|
| 335 | function sfMergeCBValue($keyname, $max) { |
|---|
| 336 | $conv = ""; |
|---|
| 337 | $cnt = 1; |
|---|
| 338 | for($cnt = 1; $cnt <= $max; $cnt++) { |
|---|
| 339 | if ($_POST[$keyname . $cnt] == "1") { |
|---|
| 340 | $conv.= "1"; |
|---|
| 341 | } else { |
|---|
| 342 | $conv.= "0"; |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | return $conv; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | // html_checkboxesの値をマージして2進数形式に変更する。 |
|---|
| 349 | function sfMergeCheckBoxes($array, $max) { |
|---|
| 350 | $ret = ""; |
|---|
| 351 | if(is_array($array)) { |
|---|
| 352 | foreach($array as $val) { |
|---|
| 353 | $arrTmp[$val] = "1"; |
|---|
| 354 | } |
|---|
| 355 | } |
|---|
| 356 | for($i = 1; $i <= $max; $i++) { |
|---|
| 357 | if(isset($arrTmp[$i]) && $arrTmp[$i] == "1") { |
|---|
| 358 | $ret.= "1"; |
|---|
| 359 | } else { |
|---|
| 360 | $ret.= "0"; |
|---|
| 361 | } |
|---|
| 362 | } |
|---|
| 363 | return $ret; |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | // html_checkboxesの値をマージして「-」でつなげる。 |
|---|
| 368 | function sfMergeParamCheckBoxes($array) { |
|---|
| 369 | $ret = ''; |
|---|
| 370 | if(is_array($array)) { |
|---|
| 371 | foreach($array as $val) { |
|---|
| 372 | if($ret != "") { |
|---|
| 373 | $ret.= "-$val"; |
|---|
| 374 | } else { |
|---|
| 375 | $ret = $val; |
|---|
| 376 | } |
|---|
| 377 | } |
|---|
| 378 | } else { |
|---|
| 379 | $ret = $array; |
|---|
| 380 | } |
|---|
| 381 | return $ret; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | // html_checkboxesの値をマージしてSQL検索用に変更する。 |
|---|
| 385 | function sfSearchCheckBoxes($array) { |
|---|
| 386 | $max = 0; |
|---|
| 387 | $ret = ""; |
|---|
| 388 | foreach($array as $val) { |
|---|
| 389 | $arrTmp[$val] = "1"; |
|---|
| 390 | if($val > $max) { |
|---|
| 391 | $max = $val; |
|---|
| 392 | } |
|---|
| 393 | } |
|---|
| 394 | for($i = 1; $i <= $max; $i++) { |
|---|
| 395 | if($arrTmp[$i] == "1") { |
|---|
| 396 | $ret.= "1"; |
|---|
| 397 | } else { |
|---|
| 398 | $ret.= "_"; |
|---|
| 399 | } |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | if($ret != "") { |
|---|
| 403 | $ret.= "%"; |
|---|
| 404 | } |
|---|
| 405 | return $ret; |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | // 2進数形式の値をhtml_checkboxes対応の値に切り替える |
|---|
| 409 | function sfSplitCheckBoxes($val) { |
|---|
| 410 | $arrRet = array(); |
|---|
| 411 | $len = strlen($val); |
|---|
| 412 | for($i = 0; $i < $len; $i++) { |
|---|
| 413 | if(substr($val, $i, 1) == "1") { |
|---|
| 414 | $arrRet[] = ($i + 1); |
|---|
| 415 | } |
|---|
| 416 | } |
|---|
| 417 | return $arrRet; |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | // チェックボックスの値をマージ |
|---|
| 421 | function sfMergeCBSearchValue($keyname, $max) { |
|---|
| 422 | $conv = ""; |
|---|
| 423 | $cnt = 1; |
|---|
| 424 | for($cnt = 1; $cnt <= $max; $cnt++) { |
|---|
| 425 | if ($_POST[$keyname . $cnt] == "1") { |
|---|
| 426 | $conv.= "1"; |
|---|
| 427 | } else { |
|---|
| 428 | $conv.= "_"; |
|---|
| 429 | } |
|---|
| 430 | } |
|---|
| 431 | return $conv; |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | // チェックボックスの値を分解 |
|---|
| 435 | function sfSplitCBValue($val, $keyname = "") { |
|---|
| 436 | $len = strlen($val); |
|---|
| 437 | $no = 1; |
|---|
| 438 | for ($cnt = 0; $cnt < $len; $cnt++) { |
|---|
| 439 | if($keyname != "") { |
|---|
| 440 | $arr[$keyname . $no] = substr($val, $cnt, 1); |
|---|
| 441 | } else { |
|---|
| 442 | $arr[] = substr($val, $cnt, 1); |
|---|
| 443 | } |
|---|
| 444 | $no++; |
|---|
| 445 | } |
|---|
| 446 | return $arr; |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | // キーと値をセットした配列を取得 |
|---|
| 450 | function sfArrKeyValue($arrList, $keyname, $valname, $len_max = "", $keysize = "") { |
|---|
| 451 | $arrRet = array(); |
|---|
| 452 | $max = count($arrList); |
|---|
| 453 | |
|---|
| 454 | if($len_max != "" && $max > $len_max) { |
|---|
| 455 | $max = $len_max; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | for($cnt = 0; $cnt < $max; $cnt++) { |
|---|
| 459 | if($keysize != "") { |
|---|
| 460 | $key = SC_Utils::sfCutString($arrList[$cnt][$keyname], $keysize); |
|---|
| 461 | } else { |
|---|
| 462 | $key = $arrList[$cnt][$keyname]; |
|---|
| 463 | } |
|---|
| 464 | $val = $arrList[$cnt][$valname]; |
|---|
| 465 | |
|---|
| 466 | if(!isset($arrRet[$key])) { |
|---|
| 467 | $arrRet[$key] = $val; |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | } |
|---|
| 471 | return $arrRet; |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | // キーと値をセットした配列を取得(値が複数の場合) |
|---|
| 475 | function sfArrKeyValues($arrList, $keyname, $valname, $len_max = "", $keysize = "", $connect = "") { |
|---|
| 476 | |
|---|
| 477 | $max = count($arrList); |
|---|
| 478 | |
|---|
| 479 | if($len_max != "" && $max > $len_max) { |
|---|
| 480 | $max = $len_max; |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | for($cnt = 0; $cnt < $max; $cnt++) { |
|---|
| 484 | if($keysize != "") { |
|---|
| 485 | $key = SC_Utils::sfCutString($arrList[$cnt][$keyname], $keysize); |
|---|
| 486 | } else { |
|---|
| 487 | $key = $arrList[$cnt][$keyname]; |
|---|
| 488 | } |
|---|
| 489 | $val = $arrList[$cnt][$valname]; |
|---|
| 490 | |
|---|
| 491 | if($connect != "") { |
|---|
| 492 | $arrRet[$key].= "$val".$connect; |
|---|
| 493 | } else { |
|---|
| 494 | $arrRet[$key][] = $val; |
|---|
| 495 | } |
|---|
| 496 | } |
|---|
| 497 | return $arrRet; |
|---|
| 498 | } |
|---|
| 499 | |
|---|
| 500 | // 配列の値をカンマ区切りで返す。 |
|---|
| 501 | function sfGetCommaList($array, $space=true) { |
|---|
| 502 | if (count($array) > 0) { |
|---|
| 503 | $line = ""; |
|---|
| 504 | foreach($array as $val) { |
|---|
| 505 | if ($space) { |
|---|
| 506 | $line .= $val . ", "; |
|---|
| 507 | }else{ |
|---|
| 508 | $line .= $val . ","; |
|---|
| 509 | } |
|---|
| 510 | } |
|---|
| 511 | if ($space) { |
|---|
| 512 | $line = ereg_replace(", $", "", $line); |
|---|
| 513 | }else{ |
|---|
| 514 | $line = ereg_replace(",$", "", $line); |
|---|
| 515 | } |
|---|
| 516 | return $line; |
|---|
| 517 | }else{ |
|---|
| 518 | return false; |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | } |
|---|
| 522 | |
|---|
| 523 | /* 配列の要素をCSVフォーマットで出力する。*/ |
|---|
| 524 | function sfGetCSVList($array) { |
|---|
| 525 | $line = ""; |
|---|
| 526 | if (count($array) > 0) { |
|---|
| 527 | foreach($array as $key => $val) { |
|---|
| 528 | $val = mb_convert_encoding($val, CHAR_CODE, CHAR_CODE); |
|---|
| 529 | $line .= "\"".$val."\","; |
|---|
| 530 | } |
|---|
| 531 | $line = ereg_replace(",$", "\r\n", $line); |
|---|
| 532 | }else{ |
|---|
| 533 | return false; |
|---|
| 534 | } |
|---|
| 535 | return $line; |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | /* 配列の要素をPDFフォーマットで出力する。*/ |
|---|
| 539 | function sfGetPDFList($array) { |
|---|
| 540 | foreach($array as $key => $val) { |
|---|
| 541 | $line .= "\t".$val; |
|---|
| 542 | } |
|---|
| 543 | $line.="\n"; |
|---|
| 544 | return $line; |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | /*-----------------------------------------------------------------*/ |
|---|
| 550 | /* check_set_term |
|---|
| 551 | /* 年月日に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
|---|
| 552 | /* 引数 (開始年,開始月,開始日,終了年,終了月,終了日) |
|---|
| 553 | /* 戻値 array(1,2,3) |
|---|
| 554 | /* 1.開始年月日 (YYYY/MM/DD 000000) |
|---|
| 555 | /* 2.終了年月日 (YYYY/MM/DD 235959) |
|---|
| 556 | /* 3.エラー ( 0 = OK, 1 = NG ) |
|---|
| 557 | /*-----------------------------------------------------------------*/ |
|---|
| 558 | function sfCheckSetTerm ( $start_year, $start_month, $start_day, $end_year, $end_month, $end_day ) { |
|---|
| 559 | |
|---|
| 560 | // 期間指定 |
|---|
| 561 | $error = 0; |
|---|
| 562 | if ( $start_month || $start_day || $start_year){ |
|---|
| 563 | if ( ! checkdate($start_month, $start_day , $start_year) ) $error = 1; |
|---|
| 564 | } else { |
|---|
| 565 | $error = 1; |
|---|
| 566 | } |
|---|
| 567 | if ( $end_month || $end_day || $end_year){ |
|---|
| 568 | if ( ! checkdate($end_month ,$end_day ,$end_year) ) $error = 2; |
|---|
| 569 | } |
|---|
| 570 | if ( ! $error ){ |
|---|
| 571 | $date1 = $start_year ."/".sprintf("%02d",$start_month) ."/".sprintf("%02d",$start_day) ." 000000"; |
|---|
| 572 | $date2 = $end_year ."/".sprintf("%02d",$end_month) ."/".sprintf("%02d",$end_day) ." 235959"; |
|---|
| 573 | if ($date1 > $date2) $error = 3; |
|---|
| 574 | } else { |
|---|
| 575 | $error = 1; |
|---|
| 576 | } |
|---|
| 577 | return array($date1, $date2, $error); |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | // エラー箇所の背景色を変更するためのfunction SC_Viewで読み込む |
|---|
| 581 | function sfSetErrorStyle(){ |
|---|
| 582 | return 'style="background-color:'.ERR_COLOR.'"'; |
|---|
| 583 | } |
|---|
| 584 | |
|---|
| 585 | /* DBに渡す数値のチェック |
|---|
| 586 | * 10桁以上はオーバーフローエラーを起こすので。 |
|---|
| 587 | */ |
|---|
| 588 | function sfCheckNumLength( $value ){ |
|---|
| 589 | if ( ! is_numeric($value) ){ |
|---|
| 590 | return false; |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | if ( strlen($value) > 9 ) { |
|---|
| 594 | return false; |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | return true; |
|---|
| 598 | } |
|---|
| 599 | |
|---|
| 600 | // 一致した値のキー名を取得 |
|---|
| 601 | function sfSearchKey($array, $word, $default) { |
|---|
| 602 | foreach($array as $key => $val) { |
|---|
| 603 | if($val == $word) { |
|---|
| 604 | return $key; |
|---|
| 605 | } |
|---|
| 606 | } |
|---|
| 607 | return $default; |
|---|
| 608 | } |
|---|
| 609 | |
|---|
| 610 | function sfGetErrorColor($val) { |
|---|
| 611 | if($val != "") { |
|---|
| 612 | return "background-color:" . ERR_COLOR; |
|---|
| 613 | } |
|---|
| 614 | return ""; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | function sfGetEnabled($val) { |
|---|
| 618 | if( ! $val ) { |
|---|
| 619 | return " disabled=\"disabled\""; |
|---|
| 620 | } |
|---|
| 621 | return ""; |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | function sfGetChecked($param, $value) { |
|---|
| 625 | if($param == $value) { |
|---|
| 626 | return "checked=\"checked\""; |
|---|
| 627 | } |
|---|
| 628 | return ""; |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | function sfTrim($str) { |
|---|
| 632 | $ret = ereg_replace("^[ \n\r]*", "", $str); |
|---|
| 633 | $ret = ereg_replace("[ \n\r]*$", "", $ret); |
|---|
| 634 | return $ret; |
|---|
| 635 | } |
|---|
| 636 | |
|---|
| 637 | /* 税金計算 */ |
|---|
| 638 | function sfTax($price, $tax, $tax_rule) { |
|---|
| 639 | $real_tax = $tax / 100; |
|---|
| 640 | $ret = $price * $real_tax; |
|---|
| 641 | switch($tax_rule) { |
|---|
| 642 | // 四捨五入 |
|---|
| 643 | case 1: |
|---|
| 644 | $ret = round($ret); |
|---|
| 645 | break; |
|---|
| 646 | // 切り捨て |
|---|
| 647 | case 2: |
|---|
| 648 | $ret = floor($ret); |
|---|
| 649 | break; |
|---|
| 650 | // 切り上げ |
|---|
| 651 | case 3: |
|---|
| 652 | $ret = ceil($ret); |
|---|
| 653 | break; |
|---|
| 654 | // デフォルト:切り上げ |
|---|
| 655 | default: |
|---|
| 656 | $ret = ceil($ret); |
|---|
| 657 | break; |
|---|
| 658 | } |
|---|
| 659 | return $ret; |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | /* 税金付与 */ |
|---|
| 663 | function sfPreTax($price, $tax, $tax_rule) { |
|---|
| 664 | $real_tax = $tax / 100; |
|---|
| 665 | $ret = $price * (1 + $real_tax); |
|---|
| 666 | |
|---|
| 667 | switch($tax_rule) { |
|---|
| 668 | // 四捨五入 |
|---|
| 669 | case 1: |
|---|
| 670 | $ret = round($ret); |
|---|
| 671 | break; |
|---|
| 672 | // 切り捨て |
|---|
| 673 | case 2: |
|---|
| 674 | $ret = floor($ret); |
|---|
| 675 | break; |
|---|
| 676 | // 切り上げ |
|---|
| 677 | case 3: |
|---|
| 678 | $ret = ceil($ret); |
|---|
| 679 | break; |
|---|
| 680 | // デフォルト:切り上げ |
|---|
| 681 | default: |
|---|
| 682 | $ret = ceil($ret); |
|---|
| 683 | break; |
|---|
| 684 | } |
|---|
| 685 | return $ret; |
|---|
| 686 | } |
|---|
| 687 | |
|---|
| 688 | // 桁数を指定して四捨五入 |
|---|
| 689 | function sfRound($value, $pow = 0){ |
|---|
| 690 | $adjust = pow(10 ,$pow-1); |
|---|
| 691 | |
|---|
| 692 | // 整数且つ0出なければ桁数指定を行う |
|---|
| 693 | if(SC_Utils::sfIsInt($adjust) and $pow > 1){ |
|---|
| 694 | $ret = (round($value * $adjust)/$adjust); |
|---|
| 695 | } |
|---|
| 696 | |
|---|
| 697 | $ret = round($ret); |
|---|
| 698 | |
|---|
| 699 | return $ret; |
|---|
| 700 | } |
|---|
| 701 | |
|---|
| 702 | /* ポイント付与 */ |
|---|
| 703 | function sfPrePoint($price, $point_rate, $rule = POINT_RULE, $product_id = "") { |
|---|
| 704 | if(SC_Utils::sfIsInt($product_id)) { |
|---|
| 705 | $objQuery = new SC_Query(); |
|---|
| 706 | $where = "now() >= cast(start_date as date) AND "; |
|---|
| 707 | $where .= "now() < cast(end_date as date) AND "; |
|---|
| 708 | |
|---|
| 709 | $where .= "del_flg = 0 AND campaign_id IN (SELECT campaign_id FROM dtb_campaign_detail where product_id = ? )"; |
|---|
| 710 | //登録(更新)日付順 |
|---|
| 711 | $objQuery->setorder('update_date DESC'); |
|---|
| 712 | //キャンペーンポイントの取得 |
|---|
| 713 | $arrRet = $objQuery->select("campaign_name, campaign_point_rate", "dtb_campaign", $where, array($product_id)); |
|---|
| 714 | } |
|---|
| 715 | //複数のキャンペーンに登録されている商品は、最新のキャンペーンからポイントを取得 |
|---|
| 716 | if(isset($arrRet[0]['campaign_point_rate']) |
|---|
| 717 | && $arrRet[0]['campaign_point_rate'] != "") { |
|---|
| 718 | |
|---|
| 719 | $campaign_point_rate = $arrRet[0]['campaign_point_rate']; |
|---|
| 720 | $real_point = $campaign_point_rate / 100; |
|---|
| 721 | } else { |
|---|
| 722 | $real_point = $point_rate / 100; |
|---|
| 723 | } |
|---|
| 724 | $ret = $price * $real_point; |
|---|
| 725 | switch($rule) { |
|---|
| 726 | // 四捨五入 |
|---|
| 727 | case 1: |
|---|
| 728 | $ret = round($ret); |
|---|
| 729 | break; |
|---|
| 730 | // 切り捨て |
|---|
| 731 | case 2: |
|---|
| 732 | $ret = floor($ret); |
|---|
| 733 | break; |
|---|
| 734 | // 切り上げ |
|---|
| 735 | case 3: |
|---|
| 736 | $ret = ceil($ret); |
|---|
| 737 | break; |
|---|
| 738 | // デフォルト:切り上げ |
|---|
| 739 | default: |
|---|
| 740 | $ret = ceil($ret); |
|---|
| 741 | break; |
|---|
| 742 | } |
|---|
| 743 | //キャンペーン商品の場合 |
|---|
| 744 | if(isset($campaign_point_rate) && $campaign_point_rate != "") { |
|---|
| 745 | $ret = "(".$arrRet[0]['campaign_name']."ポイント率".$campaign_point_rate."%)".$ret; |
|---|
| 746 | } |
|---|
| 747 | return $ret; |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | /* 規格分類の件数取得 */ |
|---|
| 751 | function sfGetClassCatCount() { |
|---|
| 752 | $sql = "select count(dtb_class.class_id) as count, dtb_class.class_id "; |
|---|
| 753 | $sql.= "from dtb_class inner join dtb_classcategory on dtb_class.class_id = dtb_classcategory.class_id "; |
|---|
| 754 | $sql.= "where dtb_class.del_flg = 0 AND dtb_classcategory.del_flg = 0 "; |
|---|
| 755 | $sql.= "group by dtb_class.class_id, dtb_class.name"; |
|---|
| 756 | $objQuery = new SC_Query(); |
|---|
| 757 | $arrList = $objQuery->getall($sql); |
|---|
| 758 | // キーと値をセットした配列を取得 |
|---|
| 759 | $arrRet = SC_Utils::sfArrKeyValue($arrList, 'class_id', 'count'); |
|---|
| 760 | |
|---|
| 761 | return $arrRet; |
|---|
| 762 | } |
|---|
| 763 | |
|---|
| 764 | /* 規格の登録 */ |
|---|
| 765 | function sfInsertProductClass($objQuery, $arrList, $product_id) { |
|---|
| 766 | // すでに規格登録があるかどうかをチェックする。 |
|---|
| 767 | $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0"; |
|---|
| 768 | $count = $objQuery->count("dtb_products_class", $where, array($product_id)); |
|---|
| 769 | |
|---|
| 770 | // すでに規格登録がない場合 |
|---|
| 771 | if($count == 0) { |
|---|
| 772 | // 既存規格の削除 |
|---|
| 773 | $where = "product_id = ?"; |
|---|
| 774 | $objQuery->delete("dtb_products_class", $where, array($product_id)); |
|---|
| 775 | |
|---|
| 776 | // 配列の添字を定義 |
|---|
| 777 | $checkArray = array("product_code", "stock", "stock_unlimited", "price01", "price02"); |
|---|
| 778 | $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray); |
|---|
| 779 | |
|---|
| 780 | $sqlval['product_id'] = $product_id; |
|---|
| 781 | $sqlval['classcategory_id1'] = '0'; |
|---|
| 782 | $sqlval['classcategory_id2'] = '0'; |
|---|
| 783 | $sqlval['product_code'] = $arrList["product_code"]; |
|---|
| 784 | $sqlval['stock'] = $arrList["stock"]; |
|---|
| 785 | $sqlval['stock_unlimited'] = $arrList["stock_unlimited"]; |
|---|
| 786 | $sqlval['price01'] = $arrList['price01']; |
|---|
| 787 | $sqlval['price02'] = $arrList['price02']; |
|---|
| 788 | $sqlval['creator_id'] = $_SESSION['member_id']; |
|---|
| 789 | $sqlval['create_date'] = "now()"; |
|---|
| 790 | |
|---|
| 791 | if($_SESSION['member_id'] == "") { |
|---|
| 792 | $sqlval['creator_id'] = '0'; |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | // INSERTの実行 |
|---|
| 796 | $objQuery->insert("dtb_products_class", $sqlval); |
|---|
| 797 | } |
|---|
| 798 | } |
|---|
| 799 | |
|---|
| 800 | function sfGetProductClassId($product_id, $classcategory_id1, $classcategory_id2) { |
|---|
| 801 | $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?"; |
|---|
| 802 | $objQuery = new SC_Query(); |
|---|
| 803 | $ret = $objQuery->get("dtb_products_class", "product_class_id", $where, Array($product_id, $classcategory_id1, $classcategory_id2)); |
|---|
| 804 | return $ret; |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | /* 文末の「/」をなくす */ |
|---|
| 808 | function sfTrimURL($url) { |
|---|
| 809 | $ret = ereg_replace("[/]+$", "", $url); |
|---|
| 810 | return $ret; |
|---|
| 811 | } |
|---|
| 812 | |
|---|
| 813 | /* DBから取り出した日付の文字列を調整する。*/ |
|---|
| 814 | function sfDispDBDate($dbdate, $time = true) { |
|---|
| 815 | list($y, $m, $d, $H, $M) = split("[- :]", $dbdate); |
|---|
| 816 | |
|---|
| 817 | if(strlen($y) > 0 && strlen($m) > 0 && strlen($d) > 0) { |
|---|
| 818 | if ($time) { |
|---|
| 819 | $str = sprintf("%04d/%02d/%02d %02d:%02d", $y, $m, $d, $H, $M); |
|---|
| 820 | } else { |
|---|
| 821 | $str = sprintf("%04d/%02d/%02d", $y, $m, $d, $H, $M); |
|---|
| 822 | } |
|---|
| 823 | } else { |
|---|
| 824 | $str = ""; |
|---|
| 825 | } |
|---|
| 826 | return $str; |
|---|
| 827 | } |
|---|
| 828 | |
|---|
| 829 | /* 配列をキー名ごとの配列に変更する */ |
|---|
| 830 | function sfSwapArray($array, $isColumnName = true) { |
|---|
| 831 | $arrRet = array(); |
|---|
| 832 | $max = count($array); |
|---|
| 833 | for($i = 0; $i < $max; $i++) { |
|---|
| 834 | $j = 0; |
|---|
| 835 | foreach($array[$i] as $key => $val) { |
|---|
| 836 | if ($isColumnName) { |
|---|
| 837 | $arrRet[$key][] = $val; |
|---|
| 838 | } else { |
|---|
| 839 | $arrRet[$j][] = $val; |
|---|
| 840 | } |
|---|
| 841 | $j++; |
|---|
| 842 | } |
|---|
| 843 | } |
|---|
| 844 | return $arrRet; |
|---|
| 845 | } |
|---|
| 846 | |
|---|
| 847 | /** |
|---|
| 848 | * 連想配列から新たな配列を生成して返す. |
|---|
| 849 | * |
|---|
| 850 | * $requires が指定された場合, $requires に含まれるキーの値のみを返す. |
|---|
| 851 | * |
|---|
| 852 | * @param array 連想配列 |
|---|
| 853 | * @param array 必須キーの配列 |
|---|
| 854 | * @return array 連想配列の値のみの配列 |
|---|
| 855 | */ |
|---|
| 856 | function getHash2Array($hash, $requires = array()) { |
|---|
| 857 | $array = array(); |
|---|
| 858 | $i = 0; |
|---|
| 859 | foreach ($hash as $key => $val) { |
|---|
| 860 | if (!empty($requires)) { |
|---|
| 861 | if (in_array($key, $requires)) { |
|---|
| 862 | $array[$i] = $val; |
|---|
| 863 | $i++; |
|---|
| 864 | } |
|---|
| 865 | } else { |
|---|
| 866 | $array[$i] = $val; |
|---|
| 867 | $i++; |
|---|
| 868 | } |
|---|
| 869 | } |
|---|
| 870 | return $array; |
|---|
| 871 | } |
|---|
| 872 | |
|---|
| 873 | /* かけ算をする(Smarty用) */ |
|---|
| 874 | function sfMultiply($num1, $num2) { |
|---|
| 875 | return ($num1 * $num2); |
|---|
| 876 | } |
|---|
| 877 | |
|---|
| 878 | // カードの処理結果を返す |
|---|
| 879 | function sfGetAuthonlyResult($dir, $file_name, $name01, $name02, $card_no, $card_exp, $amount, $order_id, $jpo_info = "10"){ |
|---|
| 880 | |
|---|
| 881 | $path = $dir .$file_name; // cgiファイルのフルパス生成 |
|---|
| 882 | $now_dir = getcwd(); // requireがうまくいかないので、cgi実行ディレクトリに移動する |
|---|
| 883 | chdir($dir); |
|---|
| 884 | |
|---|
| 885 | // パイプ渡しでコマンドラインからcgi起動 |
|---|
| 886 | $cmd = "$path card_no=$card_no name01=$name01 name02=$name02 card_exp=$card_exp amount=$amount order_id=$order_id jpo_info=$jpo_info"; |
|---|
| 887 | |
|---|
| 888 | $tmpResult = popen($cmd, "r"); |
|---|
| 889 | |
|---|
| 890 | // 結果取得 |
|---|
| 891 | while( ! FEOF ( $tmpResult ) ) { |
|---|
| 892 | $result .= FGETS($tmpResult); |
|---|
| 893 | } |
|---|
| 894 | pclose($tmpResult); // パイプを閉じる |
|---|
| 895 | chdir($now_dir); // 元にいたディレクトリに帰る |
|---|
| 896 | |
|---|
| 897 | // 結果を連想配列へ格納 |
|---|
| 898 | $result = ereg_replace("&$", "", $result); |
|---|
| 899 | foreach (explode("&",$result) as $data) { |
|---|
| 900 | list($key, $val) = explode("=", $data, 2); |
|---|
| 901 | $return[$key] = $val; |
|---|
| 902 | } |
|---|
| 903 | |
|---|
| 904 | return $return; |
|---|
| 905 | } |
|---|
| 906 | |
|---|
| 907 | /* 加算ポイントの計算式 */ |
|---|
| 908 | function sfGetAddPoint($totalpoint, $use_point, $arrInfo) { |
|---|
| 909 | // 購入商品の合計ポイントから利用したポイントのポイント換算価値を引く方式 |
|---|
| 910 | $add_point = $totalpoint - intval($use_point * ($arrInfo['point_rate'] / 100)); |
|---|
| 911 | |
|---|
| 912 | if($add_point < 0) { |
|---|
| 913 | $add_point = '0'; |
|---|
| 914 | } |
|---|
| 915 | return $add_point; |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | /* 一意かつ予測されにくいID */ |
|---|
| 919 | function sfGetUniqRandomId($head = "") { |
|---|
| 920 | // 予測されないようにランダム文字列を付与する。 |
|---|
| 921 | $random = GC_Utils_Ex::gfMakePassword(8); |
|---|
| 922 | // 同一ホスト内で一意なIDを生成 |
|---|
| 923 | $id = uniqid($head); |
|---|
| 924 | return ($id . $random); |
|---|
| 925 | } |
|---|
| 926 | |
|---|
| 927 | // カテゴリ別オススメ品の取得 |
|---|
| 928 | function sfGetBestProducts( $conn, $category_id = 0){ |
|---|
| 929 | // 既に登録されている内容を取得する |
|---|
| 930 | $sql = "SELECT name, main_image, main_list_image, price01_min, price01_max, price02_min, price02_max, point_rate, |
|---|
| 931 | A.product_id, A.comment FROM dtb_best_products as A LEFT JOIN vw_products_allclass AS allcls |
|---|
| 932 | USING (product_id) WHERE A.category_id = ? AND A.del_flg = 0 AND status = 1 ORDER BY A.rank"; |
|---|
| 933 | $arrItems = $conn->getAll($sql, array($category_id)); |
|---|
| 934 | |
|---|
| 935 | return $arrItems; |
|---|
| 936 | } |
|---|
| 937 | |
|---|
| 938 | // 特殊制御文字の手動エスケープ |
|---|
| 939 | function sfManualEscape($data) { |
|---|
| 940 | // 配列でない場合 |
|---|
| 941 | if(!is_array($data)) { |
|---|
| 942 | if (DB_TYPE == "pgsql") { |
|---|
| 943 | $ret = pg_escape_string($data); |
|---|
| 944 | }else if(DB_TYPE == "mysql"){ |
|---|
| 945 | $ret = mysql_real_escape_string($data); |
|---|
| 946 | } |
|---|
| 947 | $ret = ereg_replace("%", "\\%", $ret); |
|---|
| 948 | $ret = ereg_replace("_", "\\_", $ret); |
|---|
| 949 | return $ret; |
|---|
| 950 | } |
|---|
| 951 | |
|---|
| 952 | // 配列の場合 |
|---|
| 953 | foreach($data as $val) { |
|---|
| 954 | if (DB_TYPE == "pgsql") { |
|---|
| 955 | $ret = pg_escape_string($val); |
|---|
| 956 | }else if(DB_TYPE == "mysql"){ |
|---|
| 957 | $ret = mysql_real_escape_string($val); |
|---|
| 958 | } |
|---|
| 959 | |
|---|
| 960 | $ret = ereg_replace("%", "\\%", $ret); |
|---|
| 961 | $ret = ereg_replace("_", "\\_", $ret); |
|---|
| 962 | $arrRet[] = $ret; |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | return $arrRet; |
|---|
| 966 | } |
|---|
| 967 | |
|---|
| 968 | /* ドメイン間で有効なセッションのスタート */ |
|---|
| 969 | function sfDomainSessionStart() { |
|---|
| 970 | $ret = session_id(); |
|---|
| 971 | /* |
|---|
| 972 | ヘッダーを送信していてもsession_start()が必要なページがあるので |
|---|
| 973 | コメントアウトしておく |
|---|
| 974 | if($ret == "" && !headers_sent()) { |
|---|
| 975 | */ |
|---|
| 976 | if($ret == "") { |
|---|
| 977 | /* セッションパラメータの指定 |
|---|
| 978 | ・ブラウザを閉じるまで有効 |
|---|
| 979 | ・すべてのパスで有効 |
|---|
| 980 | ・同じドメイン間で共有 */ |
|---|
| 981 | session_set_cookie_params (0, "/", DOMAIN_NAME); |
|---|
| 982 | |
|---|
| 983 | if(!ini_get("session.auto_start")){ |
|---|
| 984 | // セッション開始 |
|---|
| 985 | session_start(); |
|---|
| 986 | } |
|---|
| 987 | } |
|---|
| 988 | } |
|---|
| 989 | |
|---|
| 990 | /* 文字列に強制的に改行を入れる */ |
|---|
| 991 | function sfPutBR($str, $size) { |
|---|
| 992 | $i = 0; |
|---|
| 993 | $cnt = 0; |
|---|
| 994 | $line = array(); |
|---|
| 995 | $ret = ""; |
|---|
| 996 | |
|---|
| 997 | while($str[$i] != "") { |
|---|
| 998 | $line[$cnt].=$str[$i]; |
|---|
| 999 | $i++; |
|---|
| 1000 | if(strlen($line[$cnt]) > $size) { |
|---|
| 1001 | $line[$cnt].="<br />"; |
|---|
| 1002 | $cnt++; |
|---|
| 1003 | } |
|---|
| 1004 | } |
|---|
| 1005 | |
|---|
| 1006 | foreach($line as $val) { |
|---|
| 1007 | $ret.=$val; |
|---|
| 1008 | } |
|---|
| 1009 | return $ret; |
|---|
| 1010 | } |
|---|
| 1011 | |
|---|
| 1012 | // 二回以上繰り返されているスラッシュ[/]を一つに変換する。 |
|---|
| 1013 | function sfRmDupSlash($istr){ |
|---|
| 1014 | if(ereg("^http://", $istr)) { |
|---|
| 1015 | $str = substr($istr, 7); |
|---|
| 1016 | $head = "http://"; |
|---|
| 1017 | } else if(ereg("^https://", $istr)) { |
|---|
| 1018 | $str = substr($istr, 8); |
|---|
| 1019 | $head = "https://"; |
|---|
| 1020 | } else { |
|---|
| 1021 | $str = $istr; |
|---|
| 1022 | } |
|---|
| 1023 | $str = ereg_replace("[/]+", "/", $str); |
|---|
| 1024 | $ret = $head . $str; |
|---|
| 1025 | return $ret; |
|---|
| 1026 | } |
|---|
| 1027 | |
|---|
| 1028 | function sfEncodeFile($filepath, $enc_type, $out_dir) { |
|---|
| 1029 | $ifp = fopen($filepath, "r"); |
|---|
| 1030 | |
|---|
| 1031 | $basename = basename($filepath); |
|---|
| 1032 | $outpath = $out_dir . "enc_" . $basename; |
|---|
| 1033 | |
|---|
| 1034 | $ofp = fopen($outpath, "w+"); |
|---|
| 1035 | |
|---|
| 1036 | while(!feof($ifp)) { |
|---|
| 1037 | $line = fgets($ifp); |
|---|
| 1038 | $line = mb_convert_encoding($line, $enc_type, "auto"); |
|---|
| 1039 | fwrite($ofp, $line); |
|---|
| 1040 | } |
|---|
| 1041 | |
|---|
| 1042 | fclose($ofp); |
|---|
| 1043 | fclose($ifp); |
|---|
| 1044 | |
|---|
| 1045 | return $outpath; |
|---|
| 1046 | } |
|---|
| 1047 | |
|---|
| 1048 | function sfCutString($str, $len, $byte = true, $commadisp = true) { |
|---|
| 1049 | if($byte) { |
|---|
| 1050 | if(strlen($str) > ($len + 2)) { |
|---|
| 1051 | $ret =substr($str, 0, $len); |
|---|
| 1052 | $cut = substr($str, $len); |
|---|
| 1053 | } else { |
|---|
| 1054 | $ret = $str; |
|---|
| 1055 | $commadisp = false; |
|---|
| 1056 | } |
|---|
| 1057 | } else { |
|---|
| 1058 | if(mb_strlen($str) > ($len + 1)) { |
|---|
| 1059 | $ret = mb_substr($str, 0, $len); |
|---|
| 1060 | $cut = mb_substr($str, $len); |
|---|
| 1061 | } else { |
|---|
| 1062 | $ret = $str; |
|---|
| 1063 | $commadisp = false; |
|---|
| 1064 | } |
|---|
| 1065 | } |
|---|
| 1066 | |
|---|
| 1067 | // 絵文字タグの途中で分断されないようにする。 |
|---|
| 1068 | if (isset($cut)) { |
|---|
| 1069 | // 分割位置より前の最後の [ 以降を取得する。 |
|---|
| 1070 | $head = strrchr($ret, '['); |
|---|
| 1071 | |
|---|
| 1072 | // 分割位置より後の最初の ] 以前を取得する。 |
|---|
| 1073 | $tail_pos = strpos($cut, ']'); |
|---|
| 1074 | if ($tail_pos !== false) { |
|---|
| 1075 | $tail = substr($cut, 0, $tail_pos + 1); |
|---|
| 1076 | } |
|---|
| 1077 | |
|---|
| 1078 | // 分割位置より前に [、後に ] が見つかった場合は、[ から ] までを |
|---|
| 1079 | // 接続して絵文字タグ1個分になるかどうかをチェックする。 |
|---|
| 1080 | if ($head !== false && $tail_pos !== false) { |
|---|
| 1081 | $subject = $head . $tail; |
|---|
| 1082 | if (preg_match('/^\[emoji:e?\d+\]$/', $subject)) { |
|---|
| 1083 | // 絵文字タグが見つかったので削除する。 |
|---|
| 1084 | $ret = substr($ret, 0, -strlen($head)); |
|---|
| 1085 | } |
|---|
| 1086 | } |
|---|
| 1087 | } |
|---|
| 1088 | |
|---|
| 1089 | if($commadisp){ |
|---|
| 1090 | $ret = $ret . "..."; |
|---|
| 1091 | } |
|---|
| 1092 | return $ret; |
|---|
| 1093 | } |
|---|
| 1094 | |
|---|
| 1095 | // 年、月、締め日から、先月の締め日+1、今月の締め日を求める。 |
|---|
| 1096 | function sfTermMonth($year, $month, $close_day) { |
|---|
| 1097 | $end_year = $year; |
|---|
| 1098 | $end_month = $month; |
|---|
| 1099 | |
|---|
| 1100 | // 開始月が終了月と同じか否か |
|---|
| 1101 | $same_month = false; |
|---|
| 1102 | |
|---|
| 1103 | // 該当月の末日を求める。 |
|---|
| 1104 | $end_last_day = date("d", mktime(0, 0, 0, $month + 1, 0, $year)); |
|---|
| 1105 | |
|---|
| 1106 | // 月の末日が締め日より少ない場合 |
|---|
| 1107 | if($end_last_day < $close_day) { |
|---|
| 1108 | // 締め日を月末日に合わせる |
|---|
| 1109 | $end_day = $end_last_day; |
|---|
| 1110 | } else { |
|---|
| 1111 | $end_day = $close_day; |
|---|
| 1112 | } |
|---|
| 1113 | |
|---|
| 1114 | // 前月の取得 |
|---|
| 1115 | $tmp_year = date("Y", mktime(0, 0, 0, $month, 0, $year)); |
|---|
| 1116 | $tmp_month = date("m", mktime(0, 0, 0, $month, 0, $year)); |
|---|
| 1117 | // 前月の末日を求める。 |
|---|
| 1118 | $start_last_day = date("d", mktime(0, 0, 0, $month, 0, $year)); |
|---|
| 1119 | |
|---|
| 1120 | // 前月の末日が締め日より少ない場合 |
|---|
| 1121 | if ($start_last_day < $close_day) { |
|---|
| 1122 | // 月末日に合わせる |
|---|
| 1123 | $tmp_day = $start_last_day; |
|---|
| 1124 | } else { |
|---|
| 1125 | $tmp_day = $close_day; |
|---|
| 1126 | } |
|---|
| 1127 | |
|---|
| 1128 | // 先月の末日の翌日を取得する |
|---|
| 1129 | $start_year = date("Y", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
|---|
| 1130 | $start_month = date("m", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
|---|
| 1131 | $start_day = date("d", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
|---|
| 1132 | |
|---|
| 1133 | // 日付の作成 |
|---|
| 1134 | $start_date = sprintf("%d/%d/%d 00:00:00", $start_year, $start_month, $start_day); |
|---|
| 1135 | $end_date = sprintf("%d/%d/%d 23:59:59", $end_year, $end_month, $end_day); |
|---|
| 1136 | |
|---|
| 1137 | return array($start_date, $end_date); |
|---|
| 1138 | } |
|---|
| 1139 | |
|---|
| 1140 | // PDF用のRGBカラーを返す |
|---|
| 1141 | function sfGetPdfRgb($hexrgb) { |
|---|
| 1142 | $hex = substr($hexrgb, 0, 2); |
|---|
| 1143 | $r = hexdec($hex) / 255; |
|---|
| 1144 | |
|---|
| 1145 | $hex = substr($hexrgb, 2, 2); |
|---|
| 1146 | $g = hexdec($hex) / 255; |
|---|
| 1147 | |
|---|
| 1148 | $hex = substr($hexrgb, 4, 2); |
|---|
| 1149 | $b = hexdec($hex) / 255; |
|---|
| 1150 | |
|---|
| 1151 | return array($r, $g, $b); |
|---|
| 1152 | } |
|---|
| 1153 | |
|---|
| 1154 | //メルマガ仮登録とメール配信 |
|---|
| 1155 | /* |
|---|
| 1156 | * FIXME |
|---|
| 1157 | */ |
|---|
| 1158 | function sfRegistTmpMailData($mail_flag, $email){ |
|---|
| 1159 | $objQuery = new SC_Query(); |
|---|
| 1160 | $objConn = new SC_DBConn(); |
|---|
| 1161 | $objPage = new LC_Page(); |
|---|
| 1162 | |
|---|
| 1163 | $random_id = sfGetUniqRandomId(); |
|---|
| 1164 | $arrRegistMailMagazine["mail_flag"] = $mail_flag; |
|---|
| 1165 | $arrRegistMailMagazine["email"] = $email; |
|---|
| 1166 | $arrRegistMailMagazine["temp_id"] =$random_id; |
|---|
| 1167 | $arrRegistMailMagazine["end_flag"]='0'; |
|---|
| 1168 | $arrRegistMailMagazine["update_date"] = 'now()'; |
|---|
| 1169 | |
|---|
| 1170 | //メルマガ仮登録用フラグ |
|---|
| 1171 | $flag = $objQuery->count("dtb_customer_mail_temp", "email=?", array($email)); |
|---|
| 1172 | $objConn->query("BEGIN"); |
|---|
| 1173 | switch ($flag){ |
|---|
| 1174 | case '0': |
|---|
| 1175 | $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine); |
|---|
| 1176 | break; |
|---|
| 1177 | |
|---|
| 1178 | case '1': |
|---|
| 1179 | $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine, "email = " .SC_Utils::sfQuoteSmart($email)); |
|---|
| 1180 | break; |
|---|
| 1181 | } |
|---|
| 1182 | $objConn->query("COMMIT"); |
|---|
| 1183 | $subject = sfMakeSubject('メルマガ仮登録が完了しました。'); |
|---|
| 1184 | $objPage->tpl_url = SSL_URL."mailmagazine/regist.php?temp_id=".$arrRegistMailMagazine['temp_id']; |
|---|
| 1185 | switch ($mail_flag){ |
|---|
| 1186 | case '1': |
|---|
| 1187 | $objPage->tpl_name = "登録"; |
|---|
| 1188 | $objPage->tpl_kindname = "HTML"; |
|---|
| 1189 | break; |
|---|
| 1190 | |
|---|
| 1191 | case '2': |
|---|
| 1192 | $objPage->tpl_name = "登録"; |
|---|
| 1193 | $objPage->tpl_kindname = "テキスト"; |
|---|
| 1194 | break; |
|---|
| 1195 | |
|---|
| 1196 | case '3': |
|---|
| 1197 | $objPage->tpl_name = "解除"; |
|---|
| 1198 | break; |
|---|
| 1199 | } |
|---|
| 1200 | $objPage->tpl_email = $email; |
|---|
| 1201 | sfSendTplMail($email, $subject, 'mail_templates/mailmagazine_temp.tpl', $objPage); |
|---|
| 1202 | } |
|---|
| 1203 | |
|---|
| 1204 | // 再帰的に多段配列を検索して一次元配列(Hidden引渡し用配列)に変換する。 |
|---|
| 1205 | function sfMakeHiddenArray($arrSrc, $arrDst = array(), $parent_key = "") { |
|---|
| 1206 | if(is_array($arrSrc)) { |
|---|
| 1207 | foreach($arrSrc as $key => $val) { |
|---|
| 1208 | if($parent_key != "") { |
|---|
| 1209 | $keyname = $parent_key . "[". $key . "]"; |
|---|
| 1210 | } else { |
|---|
| 1211 | $keyname = $key; |
|---|
| 1212 | } |
|---|
| 1213 | if(is_array($val)) { |
|---|
| 1214 | $arrDst = SC_Utils::sfMakeHiddenArray($val, $arrDst, $keyname); |
|---|
| 1215 | } else { |
|---|
| 1216 | $arrDst[$keyname] = $val; |
|---|
| 1217 | } |
|---|
| 1218 | } |
|---|
| 1219 | } |
|---|
| 1220 | return $arrDst; |
|---|
| 1221 | } |
|---|
| 1222 | |
|---|
| 1223 | // DB取得日時をタイムに変換 |
|---|
| 1224 | function sfDBDatetoTime($db_date) { |
|---|
| 1225 | $date = ereg_replace("\..*$","",$db_date); |
|---|
| 1226 | $time = strtotime($date); |
|---|
| 1227 | return $time; |
|---|
| 1228 | } |
|---|
| 1229 | |
|---|
| 1230 | // 出力の際にテンプレートを切り替えられる |
|---|
| 1231 | /* |
|---|
| 1232 | index.php?tpl=test.tpl |
|---|
| 1233 | */ |
|---|
| 1234 | function sfCustomDisplay(&$objPage, $is_mobile = false) { |
|---|
| 1235 | $basename = basename($_SERVER["REQUEST_URI"]); |
|---|
| 1236 | |
|---|
| 1237 | if($basename == "") { |
|---|
| 1238 | $path = $_SERVER["REQUEST_URI"] . "index.php"; |
|---|
| 1239 | } else { |
|---|
| 1240 | $path = $_SERVER["REQUEST_URI"]; |
|---|
| 1241 | } |
|---|
| 1242 | |
|---|
| 1243 | if(isset($_GET['tpl']) && $_GET['tpl'] != "") { |
|---|
| 1244 | $tpl_name = $_GET['tpl']; |
|---|
| 1245 | } else { |
|---|
| 1246 | $tpl_name = ereg_replace("^/", "", $path); |
|---|
| 1247 | $tpl_name = ereg_replace("/", "_", $tpl_name); |
|---|
| 1248 | $tpl_name = ereg_replace("(\.php$|\.html$)", ".tpl", $tpl_name); |
|---|
| 1249 | } |
|---|
| 1250 | |
|---|
| 1251 | $template_path = TEMPLATE_FTP_DIR . $tpl_name; |
|---|
| 1252 | |
|---|
| 1253 | if($is_mobile === true) { |
|---|
| 1254 | $objView = new SC_MobileView(); |
|---|
| 1255 | $objView->assignobj($objPage); |
|---|
| 1256 | $objView->display(SITE_FRAME); |
|---|
| 1257 | } else if(file_exists($template_path)) { |
|---|
| 1258 | $objView = new SC_UserView(TEMPLATE_FTP_DIR, COMPILE_FTP_DIR); |
|---|
| 1259 | $objView->assignobj($objPage); |
|---|
| 1260 | $objView->display($tpl_name); |
|---|
| 1261 | } else { |
|---|
| 1262 | $objView = new SC_SiteView(); |
|---|
| 1263 | $objView->assignobj($objPage); |
|---|
| 1264 | $objView->display(SITE_FRAME); |
|---|
| 1265 | } |
|---|
| 1266 | } |
|---|
| 1267 | |
|---|
| 1268 | // PHPのmb_convert_encoding関数をSmartyでも使えるようにする |
|---|
| 1269 | function sf_mb_convert_encoding($str, $encode = 'CHAR_CODE') { |
|---|
| 1270 | return mb_convert_encoding($str, $encode); |
|---|
| 1271 | } |
|---|
| 1272 | |
|---|
| 1273 | // PHPのmktime関数をSmartyでも使えるようにする |
|---|
| 1274 | function sf_mktime($format, $hour=0, $minute=0, $second=0, $month=1, $day=1, $year=1999) { |
|---|
| 1275 | return date($format,mktime($hour, $minute, $second, $month, $day, $year)); |
|---|
| 1276 | } |
|---|
| 1277 | |
|---|
| 1278 | // PHPのdate関数をSmartyでも使えるようにする |
|---|
| 1279 | function sf_date($format, $timestamp = '') { |
|---|
| 1280 | return date( $format, $timestamp); |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | // チェックボックスの型を変換する |
|---|
| 1284 | function sfChangeCheckBox($data , $tpl = false){ |
|---|
| 1285 | if ($tpl) { |
|---|
| 1286 | if ($data == 1){ |
|---|
| 1287 | return 'checked'; |
|---|
| 1288 | }else{ |
|---|
| 1289 | return ""; |
|---|
| 1290 | } |
|---|
| 1291 | }else{ |
|---|
| 1292 | if ($data == "on"){ |
|---|
| 1293 | return 1; |
|---|
| 1294 | }else{ |
|---|
| 1295 | return 2; |
|---|
| 1296 | } |
|---|
| 1297 | } |
|---|
| 1298 | } |
|---|
| 1299 | |
|---|
| 1300 | // 2つの配列を用いて連想配列を作成する |
|---|
| 1301 | function sfarrCombine($arrKeys, $arrValues) { |
|---|
| 1302 | |
|---|
| 1303 | if(count($arrKeys) <= 0 and count($arrValues) <= 0) return array(); |
|---|
| 1304 | |
|---|
| 1305 | $keys = array_values($arrKeys); |
|---|
| 1306 | $vals = array_values($arrValues); |
|---|
| 1307 | |
|---|
| 1308 | $max = max( count( $keys ), count( $vals ) ); |
|---|
| 1309 | $combine_ary = array(); |
|---|
| 1310 | for($i=0; $i<$max; $i++) { |
|---|
| 1311 | $combine_ary[$keys[$i]] = $vals[$i]; |
|---|
| 1312 | } |
|---|
| 1313 | if(is_array($combine_ary)) return $combine_ary; |
|---|
| 1314 | |
|---|
| 1315 | return false; |
|---|
| 1316 | } |
|---|
| 1317 | |
|---|
| 1318 | /* 子ID所属する親IDを取得する */ |
|---|
| 1319 | function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) { |
|---|
| 1320 | $max = count($arrData); |
|---|
| 1321 | $parent = ""; |
|---|
| 1322 | for($i = 0; $i < $max; $i++) { |
|---|
| 1323 | if($arrData[$i][$id_name] == $child) { |
|---|
| 1324 | $parent = $arrData[$i][$pid_name]; |
|---|
| 1325 | break; |
|---|
| 1326 | } |
|---|
| 1327 | } |
|---|
| 1328 | return $parent; |
|---|
| 1329 | } |
|---|
| 1330 | |
|---|
| 1331 | /* 階層構造のテーブルから与えられたIDの兄弟を取得する */ |
|---|
| 1332 | function sfGetBrothersArray($arrData, $pid_name, $id_name, $arrPID) { |
|---|
| 1333 | $max = count($arrData); |
|---|
| 1334 | |
|---|
| 1335 | $arrBrothers = array(); |
|---|
| 1336 | foreach($arrPID as $id) { |
|---|
| 1337 | // 親IDを検索する |
|---|
| 1338 | for($i = 0; $i < $max; $i++) { |
|---|
| 1339 | if($arrData[$i][$id_name] == $id) { |
|---|
| 1340 | $parent = $arrData[$i][$pid_name]; |
|---|
| 1341 | break; |
|---|
| 1342 | } |
|---|
| 1343 | } |
|---|
| 1344 | // 兄弟IDを検索する |
|---|
| 1345 | for($i = 0; $i < $max; $i++) { |
|---|
| 1346 | if($arrData[$i][$pid_name] == $parent) { |
|---|
| 1347 | $arrBrothers[] = $arrData[$i][$id_name]; |
|---|
| 1348 | } |
|---|
| 1349 | } |
|---|
| 1350 | } |
|---|
| 1351 | return $arrBrothers; |
|---|
| 1352 | } |
|---|
| 1353 | |
|---|
| 1354 | /* 階層構造のテーブルから与えられたIDの直属の子を取得する */ |
|---|
| 1355 | function sfGetUnderChildrenArray($arrData, $pid_name, $id_name, $parent) { |
|---|
| 1356 | $max = count($arrData); |
|---|
| 1357 | |
|---|
| 1358 | $arrChildren = array(); |
|---|
| 1359 | // 子IDを検索する |
|---|
| 1360 | for($i = 0; $i < $max; $i++) { |
|---|
| 1361 | if($arrData[$i][$pid_name] == $parent) { |
|---|
| 1362 | $arrChildren[] = $arrData[$i][$id_name]; |
|---|
| 1363 | } |
|---|
| 1364 | } |
|---|
| 1365 | return $arrChildren; |
|---|
| 1366 | } |
|---|
| 1367 | |
|---|
| 1368 | // SQLシングルクォート対応 |
|---|
| 1369 | function sfQuoteSmart($in){ |
|---|
| 1370 | |
|---|
| 1371 | if (is_int($in) || is_double($in)) { |
|---|
| 1372 | return $in; |
|---|
| 1373 | } elseif (is_bool($in)) { |
|---|
| 1374 | return $in ? 1 : 0; |
|---|
| 1375 | } elseif (is_null($in)) { |
|---|
| 1376 | return 'NULL'; |
|---|
| 1377 | } else { |
|---|
| 1378 | return "'" . str_replace("'", "''", $in) . "'"; |
|---|
| 1379 | } |
|---|
| 1380 | } |
|---|
| 1381 |
|
|---|
| 1382 | // ディレクトリを再帰的に生成する
|
|---|
| 1383 | function sfMakeDir($path) {
|
|---|
| 1384 | static $count = 0;
|
|---|
| 1385 | $count++; // 無限ループ回避
|
|---|
| 1386 | $dir = dirname($path);
|
|---|
| 1387 | if(ereg("^[/]$", $dir) || ereg("^[A-Z]:[\\]$", $dir) || $count > 256) {
|
|---|
| 1388 | // ルートディレクトリで終了
|
|---|
| 1389 | return;
|
|---|
| 1390 | } else {
|
|---|
| 1391 | if(is_writable(dirname($dir))) {
|
|---|
| 1392 | if(!file_exists($dir)) {
|
|---|
| 1393 | mkdir($dir);
|
|---|
| 1394 | GC_Utils::gfPrintLog("mkdir $dir");
|
|---|
| 1395 | }
|
|---|
| 1396 | } else {
|
|---|
| 1397 | SC_Utils::sfMakeDir($dir);
|
|---|
| 1398 | if(is_writable(dirname($dir))) {
|
|---|
| 1399 | if(!file_exists($dir)) {
|
|---|
| 1400 | mkdir($dir);
|
|---|
| 1401 | GC_Utils::gfPrintLog("mkdir $dir");
|
|---|
| 1402 | }
|
|---|
| 1403 | }
|
|---|
| 1404 | }
|
|---|
| 1405 | }
|
|---|
| 1406 | return;
|
|---|
| 1407 | }
|
|---|
| 1408 | |
|---|
| 1409 | // ディレクトリ以下のファイルを再帰的にコピー |
|---|
| 1410 | function sfCopyDir($src, $des, $mess = "", $override = false){ |
|---|
| 1411 | if(!is_dir($src)){ |
|---|
| 1412 | return false; |
|---|
| 1413 | } |
|---|
| 1414 | |
|---|
| 1415 | $oldmask = umask(0); |
|---|
| 1416 | $mod= stat($src); |
|---|
| 1417 | |
|---|
| 1418 | // ディレクトリがなければ作成する |
|---|
| 1419 | if(!file_exists($des)) { |
|---|
| 1420 | if(!mkdir($des, $mod[2])) { |
|---|
| 1421 | print("path:" . $des); |
|---|
| 1422 | } |
|---|
| 1423 | } |
|---|
| 1424 | |
|---|
| 1425 | $fileArray=glob( $src."*" ); |
|---|
| 1426 | foreach( $fileArray as $key => $data_ ){ |
|---|
| 1427 | // CVS管理ファイルはコピーしない |
|---|
| 1428 | if(ereg("/CVS/Entries", $data_)) { |
|---|
| 1429 | break; |
|---|
| 1430 | } |
|---|
| 1431 | if(ereg("/CVS/Repository", $data_)) { |
|---|
| 1432 | break; |
|---|
| 1433 | } |
|---|
| 1434 | if(ereg("/CVS/Root", $data_)) { |
|---|
| 1435 | break; |
|---|
| 1436 | } |
|---|
| 1437 | |
|---|
| 1438 | mb_ereg("^(.*[\/])(.*)",$data_, $matches); |
|---|
| 1439 | $data=$matches[2]; |
|---|
| 1440 | if( is_dir( $data_ ) ){ |
|---|
| 1441 | $mess = SC_Utils::sfCopyDir( $data_.'/', $des.$data.'/', $mess); |
|---|
| 1442 | }else{ |
|---|
| 1443 | if(!$override && file_exists($des.$data)) { |
|---|
| 1444 | $mess.= $des.$data . ":ファイルが存在します\n"; |
|---|
| 1445 | } else { |
|---|
| 1446 | if(@copy( $data_, $des.$data)) { |
|---|
| 1447 | $mess.= $des.$data . ":コピー成功\n"; |
|---|
| 1448 | } else { |
|---|
| 1449 | $mess.= $des.$data . ":コピー失敗\n"; |
|---|
| 1450 | } |
|---|
| 1451 | } |
|---|
| 1452 | $mod=stat($data_ ); |
|---|
| 1453 | } |
|---|
| 1454 | } |
|---|
| 1455 | umask($oldmask); |
|---|
| 1456 | return $mess; |
|---|
| 1457 | } |
|---|
| 1458 | |
|---|
| 1459 | // 指定したフォルダ内のファイルを全て削除する |
|---|
| 1460 | function sfDelFile($dir){
|
|---|
| 1461 | if(file_exists($dir)) {
|
|---|
| 1462 | $dh = opendir($dir); |
|---|
| 1463 | // フォルダ内のファイルを削除 |
|---|
| 1464 | while($file = readdir($dh)){ |
|---|
| 1465 | if ($file == "." or $file == "..") continue; |
|---|
| 1466 | $del_file = $dir . "/" . $file; |
|---|
| 1467 | if(is_file($del_file)){ |
|---|
| 1468 | $ret = unlink($dir . "/" . $file); |
|---|
| 1469 | }else if (is_dir($del_file)){ |
|---|
| 1470 | $ret = SC_Utils::sfDelFile($del_file); |
|---|
| 1471 | } |
|---|
| 1472 | |
|---|
| 1473 | if(!$ret){ |
|---|
| 1474 | return $ret; |
|---|
| 1475 | } |
|---|
| 1476 | } |
|---|
| 1477 | |
|---|
| 1478 | // 閉じる |
|---|
| 1479 | closedir($dh); |
|---|
| 1480 | |
|---|
| 1481 | // フォルダを削除 |
|---|
| 1482 | return rmdir($dir);
|
|---|
| 1483 | } |
|---|
| 1484 | } |
|---|
| 1485 | |
|---|
| 1486 | /* |
|---|
| 1487 | * 関数名:sfWriteFile |
|---|
| 1488 | * 引数1 :書き込むデータ |
|---|
| 1489 | * 引数2 :ファイルパス |
|---|
| 1490 | * 引数3 :書き込みタイプ |
|---|
| 1491 | * 引数4 :パーミッション |
|---|
| 1492 | * 戻り値:結果フラグ 成功なら true 失敗なら false |
|---|
| 1493 | * 説明 :ファイル書き出し |
|---|
| 1494 | */ |
|---|
| 1495 | function sfWriteFile($str, $path, $type, $permission = "") { |
|---|
| 1496 | //ファイルを開く |
|---|
| 1497 | if (!($file = fopen ($path, $type))) { |
|---|
| 1498 | return false; |
|---|
| 1499 | } |
|---|
| 1500 | |
|---|
| 1501 | //ファイルロック |
|---|
| 1502 | flock ($file, LOCK_EX); |
|---|
| 1503 | //ファイルの書き込み |
|---|
| 1504 | fputs ($file, $str); |
|---|
| 1505 | //ファイルロックの解除 |
|---|
| 1506 | flock ($file, LOCK_UN); |
|---|
| 1507 | //ファイルを閉じる |
|---|
| 1508 | fclose ($file); |
|---|
| 1509 | // 権限を指定 |
|---|
| 1510 | if($permission != "") { |
|---|
| 1511 | chmod($path, $permission); |
|---|
| 1512 | } |
|---|
| 1513 | |
|---|
| 1514 | return true; |
|---|
| 1515 | } |
|---|
| 1516 | |
|---|
| 1517 | function sfFlush($output = " ", $sleep = 0){ |
|---|
| 1518 | // 実行時間を制限しない |
|---|
| 1519 | set_time_limit(0); |
|---|
| 1520 | // 出力をバッファリングしない(==日本語自動変換もしない) |
|---|
| 1521 | ob_end_clean(); |
|---|
| 1522 | |
|---|
| 1523 | // IEのために256バイト空文字出力 |
|---|
| 1524 | echo str_pad('',256); |
|---|
| 1525 | |
|---|
| 1526 | // 出力はブランクだけでもいいと思う |
|---|
| 1527 | echo $output; |
|---|
| 1528 | // 出力をフラッシュする |
|---|
| 1529 | flush(); |
|---|
| 1530 | |
|---|
| 1531 | ob_flush(); |
|---|
| 1532 | ob_start(); |
|---|
| 1533 | |
|---|
| 1534 | // 時間のかかる処理 |
|---|
| 1535 | sleep($sleep); |
|---|
| 1536 | } |
|---|
| 1537 | |
|---|
| 1538 | // @versionの記載があるファイルからバージョンを取得する。 |
|---|
| 1539 | function sfGetFileVersion($path) { |
|---|
| 1540 | if(file_exists($path)) { |
|---|
| 1541 | $src_fp = fopen($path, "rb"); |
|---|
| 1542 | if($src_fp) { |
|---|
| 1543 | while (!feof($src_fp)) { |
|---|
| 1544 | $line = fgets($src_fp); |
|---|
| 1545 | if(ereg("@version", $line)) { |
|---|
| 1546 | $arrLine = split(" ", $line); |
|---|
| 1547 | $version = $arrLine[5]; |
|---|
| 1548 | } |
|---|
| 1549 | } |
|---|
| 1550 | fclose($src_fp); |
|---|
| 1551 | } |
|---|
| 1552 | } |
|---|
| 1553 | return $version; |
|---|
| 1554 | } |
|---|
| 1555 | |
|---|
| 1556 | // 指定したURLに対してPOSTでデータを送信する |
|---|
| 1557 | function sfSendPostData($url, $arrData, $arrOkCode = array()){ |
|---|
| 1558 | require_once(DATA_PATH . "module/Request.php"); |
|---|
| 1559 | |
|---|
| 1560 | // 送信インスタンス生成 |
|---|
| 1561 | $req = new HTTP_Request($url); |
|---|
| 1562 | |
|---|
| 1563 | $req->addHeader('User-Agent', 'DoCoMo/2.0 P2101V(c100)'); |
|---|
| 1564 | $req->setMethod(HTTP_REQUEST_METHOD_POST); |
|---|
| 1565 | |
|---|
| 1566 | // POSTデータ送信 |
|---|
| 1567 | $req->addPostDataArray($arrData); |
|---|
| 1568 | |
|---|
| 1569 | // エラーが無ければ、応答情報を取得する |
|---|
| 1570 | if (!PEAR::isError($req->sendRequest())) { |
|---|
| 1571 | |
|---|
| 1572 | // レスポンスコードがエラー判定なら、空を返す |
|---|
| 1573 | $res_code = $req->getResponseCode(); |
|---|
| 1574 | |
|---|
| 1575 | if(!in_array($res_code, $arrOkCode)){ |
|---|
| 1576 | $response = ""; |
|---|
| 1577 | }else{ |
|---|
| 1578 | $response = $req->getResponseBody(); |
|---|
| 1579 | } |
|---|
| 1580 | |
|---|
| 1581 | } else { |
|---|
| 1582 | $response = ""; |
|---|
| 1583 | } |
|---|
| 1584 | |
|---|
| 1585 | // POSTデータクリア |
|---|
| 1586 | $req->clearPostData(); |
|---|
| 1587 | |
|---|
| 1588 | return $response; |
|---|
| 1589 | } |
|---|
| 1590 | |
|---|
| 1591 | /** |
|---|
| 1592 | * $array の要素を $arrConvList で指定した方式で mb_convert_kana を適用する. |
|---|
| 1593 | * |
|---|
| 1594 | * @param array $array 変換する文字列の配列 |
|---|
| 1595 | * @param array $arrConvList mb_convert_kana の適用ルール |
|---|
| 1596 | * @return array 変換後の配列 |
|---|
| 1597 | * @see mb_convert_kana |
|---|
| 1598 | */ |
|---|
| 1599 | function mbConvertKanaWithArray($array, $arrConvList) { |
|---|
| 1600 | foreach ($arrConvList as $key => $val) { |
|---|
| 1601 | if(isset($array[$key])) { |
|---|
| 1602 | $array[$key] = mb_convert_kana($array[$key] ,$val); |
|---|
| 1603 | } |
|---|
| 1604 | } |
|---|
| 1605 | return $array; |
|---|
| 1606 | } |
|---|
| 1607 | |
|---|
| 1608 | /** |
|---|
| 1609 | * 配列の添字が未定義の場合は空文字を代入して定義する. |
|---|
| 1610 | * |
|---|
| 1611 | * @param array $array 添字をチェックする配列 |
|---|
| 1612 | * @param array $defineIndexes チェックする添字 |
|---|
| 1613 | * @return array 添字を定義した配列 |
|---|
| 1614 | */ |
|---|
| 1615 | function arrayDefineIndexes($array, $defineIndexes) { |
|---|
| 1616 | foreach ($defineIndexes as $key) { |
|---|
| 1617 | if (!isset($array[$key])) $array[$key] = ""; |
|---|
| 1618 | } |
|---|
| 1619 | return $array; |
|---|
| 1620 | } |
|---|
| 1621 | |
|---|
| 1622 | /** |
|---|
| 1623 | * XML宣言を出力する. |
|---|
| 1624 | * |
|---|
| 1625 | * XML宣言があると問題が発生する UA は出力しない. |
|---|
| 1626 | * |
|---|
| 1627 | * @return string XML宣言の文字列 |
|---|
| 1628 | */ |
|---|
| 1629 | function printXMLDeclaration() { |
|---|
| 1630 | $ua = $_SERVER['HTTP_USER_AGENT']; |
|---|
| 1631 | if (!preg_match("/MSIE/", $ua) || preg_match("/MSIE 7/", $ua)) { |
|---|
| 1632 | print("<?xml version='1.0' encoding='" . CHAR_CODE . "'?>\n"); |
|---|
| 1633 | } |
|---|
| 1634 | } |
|---|
| 1635 |
|
|---|
| 1636 | /*
|
|---|
| 1637 | * 関数名:sfGetFileList()
|
|---|
| 1638 | * 説明 :指定パス配下のディレクトリ取得
|
|---|
| 1639 | * 引数1 :取得するディレクトリパス
|
|---|
| 1640 | */
|
|---|
| 1641 | function sfGetFileList($dir) {
|
|---|
| 1642 | $arrFileList = array();
|
|---|
| 1643 | $arrDirList = array();
|
|---|
| 1644 |
|
|---|
| 1645 | if (is_dir($dir)) {
|
|---|
| 1646 | if ($dh = opendir($dir)) {
|
|---|
| 1647 | $cnt = 0;
|
|---|
| 1648 | // 行末の/を取り除く
|
|---|
| 1649 | while (($file = readdir($dh)) !== false) $arrDir[] = $file;
|
|---|
| 1650 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 1651 | // アルファベットと数字でソート
|
|---|
| 1652 | natcasesort($arrDir);
|
|---|
| 1653 | foreach($arrDir as $file) {
|
|---|
| 1654 | // ./ と ../を除くファイルのみを取得
|
|---|
| 1655 | if($file != "." && $file != "..") {
|
|---|
| 1656 |
|
|---|
| 1657 | $path = $dir."/".$file;
|
|---|
| 1658 | // SELECT内の見た目を整えるため指定文字数で切る
|
|---|
| 1659 | $file_name = SC_Utils::sfCutString($file, FILE_NAME_LEN);
|
|---|
| 1660 | $file_size = SC_Utils::sfCutString(SC_Utils::sfGetDirSize($path), FILE_NAME_LEN);
|
|---|
| 1661 | $file_time = date("Y/m/d", filemtime($path));
|
|---|
| 1662 |
|
|---|
| 1663 | // ディレクトリとファイルで格納配列を変える
|
|---|
| 1664 | if(is_dir($path)) {
|
|---|
| 1665 | $arrDirList[$cnt]['file_name'] = $file;
|
|---|
| 1666 | $arrDirList[$cnt]['file_path'] = $path;
|
|---|
| 1667 | $arrDirList[$cnt]['file_size'] = $file_size;
|
|---|
| 1668 | $arrDirList[$cnt]['file_time'] = $file_time;
|
|---|
| 1669 | $arrDirList[$cnt]['is_dir'] = true;
|
|---|
| 1670 | } else {
|
|---|
| 1671 | $arrFileList[$cnt]['file_name'] = $file;
|
|---|
| 1672 | $arrFileList[$cnt]['file_path'] = $path;
|
|---|
| 1673 | $arrFileList[$cnt]['file_size'] = $file_size;
|
|---|
| 1674 | $arrFileList[$cnt]['file_time'] = $file_time;
|
|---|
| 1675 | $arrFileList[$cnt]['is_dir'] = false;
|
|---|
| 1676 | }
|
|---|
| 1677 | $cnt++;
|
|---|
| 1678 | }
|
|---|
| 1679 | }
|
|---|
| 1680 | closedir($dh);
|
|---|
| 1681 | }
|
|---|
| 1682 | }
|
|---|
| 1683 |
|
|---|
| 1684 | // フォルダを先頭にしてマージ
|
|---|
| 1685 | return array_merge($arrDirList, $arrFileList);
|
|---|
| 1686 | }
|
|---|
| 1687 |
|
|---|
| 1688 | /*
|
|---|
| 1689 | * 関数名:sfGetDirSize()
|
|---|
| 1690 | * 説明 :指定したディレクトリのバイト数を取得
|
|---|
| 1691 | * 引数1 :ディレクトリ
|
|---|
| 1692 | */
|
|---|
| 1693 | function sfGetDirSize($dir) {
|
|---|
| 1694 | if(file_exists($dir)) {
|
|---|
| 1695 | // ディレクトリの場合下層ファイルの総量を取得
|
|---|
| 1696 | if (is_dir($dir)) {
|
|---|
| 1697 | $handle = opendir($dir);
|
|---|
| 1698 | while ($file = readdir($handle)) {
|
|---|
| 1699 | // 行末の/を取り除く
|
|---|
| 1700 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 1701 | $path = $dir."/".$file;
|
|---|
| 1702 | if ($file != '..' && $file != '.' && !is_dir($path)) {
|
|---|
| 1703 | $bytes += filesize($path);
|
|---|
| 1704 | } else if (is_dir($path) && $file != '..' && $file != '.') {
|
|---|
| 1705 | // 下層ファイルのバイト数を取得する為、再帰的に呼び出す。
|
|---|
| 1706 | $bytes += SC_Utils::sfGetDirSize($path);
|
|---|
| 1707 | }
|
|---|
| 1708 | }
|
|---|
| 1709 | } else {
|
|---|
| 1710 | // ファイルの場合
|
|---|
| 1711 | $bytes = filesize($dir);
|
|---|
| 1712 | }
|
|---|
| 1713 | }
|
|---|
| 1714 | // ディレクトリ(ファイル)が存在しない場合は0byteを返す
|
|---|
| 1715 | if($bytes == "") $bytes = 0;
|
|---|
| 1716 |
|
|---|
| 1717 | return $bytes;
|
|---|
| 1718 | }
|
|---|
| 1719 |
|
|---|
| 1720 | /*
|
|---|
| 1721 | * 関数名:sfDeleteDir()
|
|---|
| 1722 | * 説明 :指定したディレクトリを削除
|
|---|
| 1723 | * 引数1 :削除ファイル
|
|---|
| 1724 | */
|
|---|
| 1725 | function sfDeleteDir($dir) {
|
|---|
| 1726 | $arrResult = array();
|
|---|
| 1727 | if(file_exists($dir)) {
|
|---|
| 1728 | // ディレクトリかチェック
|
|---|
| 1729 | if (is_dir($dir)) {
|
|---|
| 1730 | if ($handle = opendir("$dir")) {
|
|---|
| 1731 | $cnt = 0;
|
|---|
| 1732 | while (false !== ($item = readdir($handle))) {
|
|---|
| 1733 | if ($item != "." && $item != "..") {
|
|---|
| 1734 | if (is_dir("$dir/$item")) {
|
|---|
| 1735 | sfDeleteDir("$dir/$item");
|
|---|
| 1736 | } else {
|
|---|
| 1737 | $arrResult[$cnt]['result'] = @unlink("$dir/$item");
|
|---|
| 1738 | $arrResult[$cnt]['file_name'] = "$dir/$item";
|
|---|
| 1739 | }
|
|---|
| 1740 | }
|
|---|
| 1741 | $cnt++;
|
|---|
| 1742 | }
|
|---|
| 1743 | }
|
|---|
| 1744 | closedir($handle);
|
|---|
| 1745 | $arrResult[$cnt]['result'] = @rmdir($dir);
|
|---|
| 1746 | $arrResult[$cnt]['file_name'] = "$dir/$item";
|
|---|
| 1747 | } else {
|
|---|
| 1748 | // ファイル削除
|
|---|
| 1749 | $arrResult[0]['result'] = @unlink("$dir");
|
|---|
| 1750 | $arrResult[0]['file_name'] = "$dir";
|
|---|
| 1751 | }
|
|---|
| 1752 | }
|
|---|
| 1753 |
|
|---|
| 1754 | return $arrResult;
|
|---|
| 1755 | }
|
|---|
| 1756 |
|
|---|
| 1757 | /*
|
|---|
| 1758 | * 関数名:sfGetFileTree()
|
|---|
| 1759 | * 説明 :ツリー生成用配列取得(javascriptに渡す用)
|
|---|
| 1760 | * 引数1 :ディレクトリ
|
|---|
| 1761 | * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
|
|---|
| 1762 | */
|
|---|
| 1763 | function sfGetFileTree($dir, $tree_status) {
|
|---|
| 1764 |
|
|---|
| 1765 | $cnt = 0;
|
|---|
| 1766 | $arrTree = array();
|
|---|
| 1767 | $default_rank = count(split('/', $dir));
|
|---|
| 1768 |
|
|---|
| 1769 | // 文末の/を取り除く
|
|---|
| 1770 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 1771 | // 最上位層を格納(user_data/)
|
|---|
| 1772 | if(sfDirChildExists($dir)) {
|
|---|
| 1773 | $arrTree[$cnt]['type'] = "_parent";
|
|---|
| 1774 | } else {
|
|---|
| 1775 | $arrTree[$cnt]['type'] = "_child";
|
|---|
| 1776 | }
|
|---|
| 1777 | $arrTree[$cnt]['path'] = $dir;
|
|---|
| 1778 | $arrTree[$cnt]['rank'] = 0;
|
|---|
| 1779 | $arrTree[$cnt]['count'] = $cnt;
|
|---|
| 1780 | // 初期表示はオープン
|
|---|
| 1781 | if($_POST['mode'] != '') {
|
|---|
| 1782 | $arrTree[$cnt]['open'] = lfIsFileOpen($dir, $tree_status);
|
|---|
| 1783 | } else {
|
|---|
| 1784 | $arrTree[$cnt]['open'] = true;
|
|---|
| 1785 | }
|
|---|
| 1786 | $cnt++;
|
|---|
| 1787 |
|
|---|
| 1788 | sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree, $tree_status);
|
|---|
| 1789 |
|
|---|
| 1790 | return $arrTree;
|
|---|
| 1791 | }
|
|---|
| 1792 |
|
|---|
| 1793 | /*
|
|---|
| 1794 | * 関数名:sfGetFileTree()
|
|---|
| 1795 | * 説明 :ツリー生成用配列取得(javascriptに渡す用)
|
|---|
| 1796 | * 引数1 :ディレクトリ
|
|---|
| 1797 | * 引数2 :デフォルトの階層(/区切りで 0,1,2・・・とカウント)
|
|---|
| 1798 | * 引数3 :連番
|
|---|
| 1799 | * 引数4 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
|
|---|
| 1800 | */
|
|---|
| 1801 | function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) {
|
|---|
| 1802 |
|
|---|
| 1803 | if(file_exists($dir)) {
|
|---|
| 1804 | if ($handle = opendir("$dir")) {
|
|---|
| 1805 | while (false !== ($item = readdir($handle))) $arrDir[] = $item;
|
|---|
| 1806 | // アルファベットと数字でソート
|
|---|
| 1807 | natcasesort($arrDir);
|
|---|
| 1808 | foreach($arrDir as $item) {
|
|---|
| 1809 | if ($item != "." && $item != "..") {
|
|---|
| 1810 | // 文末の/を取り除く
|
|---|
| 1811 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 1812 | $path = $dir."/".$item;
|
|---|
| 1813 | // ディレクトリのみ取得
|
|---|
| 1814 | if (is_dir($path)) {
|
|---|
| 1815 | $arrTree[$cnt]['path'] = $path;
|
|---|
| 1816 | if(sfDirChildExists($path)) {
|
|---|
| 1817 | $arrTree[$cnt]['type'] = "_parent";
|
|---|
| 1818 | } else {
|
|---|
| 1819 | $arrTree[$cnt]['type'] = "_child";
|
|---|
| 1820 | }
|
|---|
| 1821 |
|
|---|
| 1822 | // 階層を割り出す
|
|---|
| 1823 | $arrCnt = split('/', $path);
|
|---|
| 1824 | $rank = count($arrCnt);
|
|---|
| 1825 | $arrTree[$cnt]['rank'] = $rank - $default_rank + 1;
|
|---|
| 1826 | $arrTree[$cnt]['count'] = $cnt;
|
|---|
| 1827 | // フォルダが開いているか
|
|---|
| 1828 | $arrTree[$cnt]['open'] = lfIsFileOpen($path, $tree_status);
|
|---|
| 1829 | $cnt++;
|
|---|
| 1830 | // 下層ディレクトリ取得の為、再帰的に呼び出す
|
|---|
| 1831 | sfGetFileTreeSub($path, $default_rank, $cnt, $arrTree, $tree_status);
|
|---|
| 1832 | }
|
|---|
| 1833 | }
|
|---|
| 1834 | }
|
|---|
| 1835 | }
|
|---|
| 1836 | closedir($handle);
|
|---|
| 1837 | }
|
|---|
| 1838 | }
|
|---|
| 1839 |
|
|---|
| 1840 | /*
|
|---|
| 1841 | * 関数名:sfDirChildExists()
|
|---|
| 1842 | * 説明 :指定したディレクトリ配下にファイルがあるか
|
|---|
| 1843 | * 引数1 :ディレクトリ
|
|---|
| 1844 | */
|
|---|
| 1845 | function sfDirChildExists($dir) {
|
|---|
| 1846 | if(file_exists($dir)) {
|
|---|
| 1847 | if (is_dir($dir)) {
|
|---|
| 1848 | $handle = opendir($dir);
|
|---|
| 1849 | while ($file = readdir($handle)) {
|
|---|
| 1850 | // 行末の/を取り除く
|
|---|
| 1851 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 1852 | $path = $dir."/".$file;
|
|---|
| 1853 | if ($file != '..' && $file != '.' && is_dir($path)) {
|
|---|
| 1854 | return true;
|
|---|
| 1855 | }
|
|---|
| 1856 | }
|
|---|
| 1857 | }
|
|---|
| 1858 | }
|
|---|
| 1859 |
|
|---|
| 1860 | return false;
|
|---|
| 1861 | }
|
|---|
| 1862 |
|
|---|
| 1863 | /*
|
|---|
| 1864 | * 関数名:lfIsFileOpen()
|
|---|
| 1865 | * 説明 :指定したファイルが前回開かれた状態にあったかチェック
|
|---|
| 1866 | * 引数1 :ディレクトリ
|
|---|
| 1867 | * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
|
|---|
| 1868 | */
|
|---|
| 1869 | function lfIsFileOpen($dir, $tree_status) {
|
|---|
| 1870 | $arrTreeStatus = split('\|', $tree_status);
|
|---|
| 1871 | if(in_array($dir, $arrTreeStatus)) {
|
|---|
| 1872 | return true;
|
|---|
| 1873 | }
|
|---|
| 1874 |
|
|---|
| 1875 | return false;
|
|---|
| 1876 | }
|
|---|
| 1877 |
|
|---|
| 1878 | /*
|
|---|
| 1879 | * 関数名:sfDownloadFile()
|
|---|
| 1880 | * 引数1 :ファイルパス
|
|---|
| 1881 | * 説明 :ファイルのダウンロード
|
|---|
| 1882 | */
|
|---|
| 1883 | function sfDownloadFile($file) {
|
|---|
| 1884 | // ファイルの場合はダウンロードさせる
|
|---|
| 1885 | Header("Content-disposition: attachment; filename=".basename($file));
|
|---|
| 1886 | Header("Content-type: application/octet-stream; name=".basename($file));
|
|---|
| 1887 | Header("Cache-Control: ");
|
|---|
| 1888 | Header("Pragma: ");
|
|---|
| 1889 | echo (sfReadFile($file));
|
|---|
| 1890 | }
|
|---|
| 1891 |
|
|---|
| 1892 | /*
|
|---|
| 1893 | * 関数名:sfCreateFile()
|
|---|
| 1894 | * 引数1 :ファイルパス
|
|---|
| 1895 | * 引数2 :パーミッション
|
|---|
| 1896 | * 説明 :ファイル作成
|
|---|
| 1897 | */
|
|---|
| 1898 | function sfCreateFile($file, $mode = "") {
|
|---|
| 1899 | // 行末の/を取り除く
|
|---|
| 1900 | if($mode != "") {
|
|---|
| 1901 | $ret = @mkdir($file, $mode);
|
|---|
| 1902 | } else {
|
|---|
| 1903 | $ret = @mkdir($file);
|
|---|
| 1904 | }
|
|---|
| 1905 |
|
|---|
| 1906 | return $ret;
|
|---|
| 1907 | }
|
|---|
| 1908 |
|
|---|
| 1909 | /*
|
|---|
| 1910 | * 関数名:sfReadFile()
|
|---|
| 1911 | * 引数1 :ファイルパス
|
|---|
| 1912 | * 説明 :ファイル読込
|
|---|
| 1913 | */
|
|---|
| 1914 | function sfReadFile($filename) {
|
|---|
| 1915 | $str = "";
|
|---|
| 1916 | // バイナリモードでオープン
|
|---|
| 1917 | $fp = @fopen($filename, "rb" );
|
|---|
| 1918 | //ファイル内容を全て変数に読み込む
|
|---|
| 1919 | if($fp) {
|
|---|
| 1920 | $str = @fread($fp, filesize($filename)+1);
|
|---|
| 1921 | }
|
|---|
| 1922 | @fclose($fp);
|
|---|
| 1923 |
|
|---|
| 1924 | return $str;
|
|---|
| 1925 | }
|
|---|
| 1926 |
|
|---|
| 1927 | /**
|
|---|
| 1928 | * 出力バッファをフラッシュし, バッファリングを開始する.
|
|---|
| 1929 | *
|
|---|
| 1930 | * @return void
|
|---|
| 1931 | */
|
|---|
| 1932 | function flush() {
|
|---|
| 1933 | flush();
|
|---|
| 1934 | ob_end_flush();
|
|---|
| 1935 | ob_start();
|
|---|
| 1936 | }
|
|---|
| 1937 | |
|---|
| 1938 | /* デバッグ用 ------------------------------------------------------------------------------------------------*/ |
|---|
| 1939 | function sfPrintR($obj) { |
|---|
| 1940 | print("<div style='font-size: 12px;color: #00FF00;'>\n"); |
|---|
| 1941 | print("<strong>**デバッグ中**</strong><br />\n"); |
|---|
| 1942 | print("<pre>\n"); |
|---|
| 1943 | //print_r($obj); |
|---|
| 1944 | var_dump($obj); |
|---|
| 1945 | print("</pre>\n"); |
|---|
| 1946 | print("<strong>**デバッグ中**</strong></div>\n"); |
|---|
| 1947 | } |
|---|
| 1948 | } |
|---|
| 1949 | ?> |
|---|