| 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
| 4 | * |
---|
| 5 | * http://www.lockon.co.jp/ |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | // {{{ requires |
---|
| 9 | require_once(CLASS_PATH . "page_extends/error/LC_Page_Error_Ex.php"); |
---|
| 10 | |
---|
| 11 | /** |
---|
| 12 | * 各種ユーティリティクラス. |
---|
| 13 | * |
---|
| 14 | * 主に static 参照するユーティリティ系の関数群 |
---|
| 15 | * |
---|
| 16 | * @package Util |
---|
| 17 | * @author LOCKON CO.,LTD. |
---|
| 18 | * @version $Id$ |
---|
| 19 | */ |
---|
| 20 | class SC_Utils { |
---|
| 21 | |
---|
| 22 | /** |
---|
| 23 | * サイト管理情報から値を取得する。 |
---|
| 24 | * データが存在する場合、必ず1以上の数値が設定されている。 |
---|
| 25 | * 0を返した場合は、呼び出し元で対応すること。 |
---|
| 26 | * |
---|
| 27 | * @param $control_id 管理ID |
---|
| 28 | * @param $dsn DataSource |
---|
| 29 | * @return $control_flg フラグ |
---|
| 30 | */ |
---|
| 31 | function sfGetSiteControlFlg($control_id, $dsn = "") { |
---|
| 32 | |
---|
| 33 | // データソース |
---|
| 34 | if($dsn == "") { |
---|
| 35 | if(defined('DEFAULT_DSN')) { |
---|
| 36 | $dsn = DEFAULT_DSN; |
---|
| 37 | } else { |
---|
| 38 | return; |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | // クエリ生成 |
---|
| 43 | $target_column = "control_flg"; |
---|
| 44 | $table_name = "dtb_site_control"; |
---|
| 45 | $where = "control_id = ?"; |
---|
| 46 | $arrval = array($control_id); |
---|
| 47 | $control_flg = 0; |
---|
| 48 | |
---|
| 49 | // クエリ発行 |
---|
| 50 | $objQuery = new SC_Query($dsn, true, true); |
---|
| 51 | $arrSiteControl = $objQuery->select($target_column, $table_name, $where, $arrval); |
---|
| 52 | |
---|
| 53 | // データが存在すればフラグを取得する |
---|
| 54 | if (count($arrSiteControl) > 0) { |
---|
| 55 | $control_flg = $arrSiteControl[0]["control_flg"]; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | return $control_flg; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | // インストール初期処理 |
---|
| 62 | function sfInitInstall() { |
---|
| 63 | // インストール済みが定義されていない。 |
---|
| 64 | if(!defined('ECCUBE_INSTALL')) { |
---|
| 65 | if(!ereg("/install/", $_SERVER['PHP_SELF'])) { |
---|
| 66 | header("Location: ./install/"); |
---|
| 67 | } |
---|
| 68 | } else { |
---|
| 69 | $path = HTML_PATH . "install/index.php"; |
---|
| 70 | if(file_exists($path)) { |
---|
| 71 | sfErrorHeader(">> /install/index.phpは、インストール完了後にファイルを削除してください。"); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | // 旧バージョンのinstall.phpのチェック |
---|
| 75 | $path = HTML_PATH . "install.php"; |
---|
| 76 | if(file_exists($path)) { |
---|
| 77 | sfErrorHeader(">> /install.phpはセキュリティーホールとなります。削除してください。"); |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | // アップデートで生成されたPHPを読み出し |
---|
| 83 | function sfLoadUpdateModule() { |
---|
| 84 | // URL設定ディレクトリを削除 |
---|
| 85 | $main_php = ereg_replace(URL_DIR, "", $_SERVER['PHP_SELF']); |
---|
| 86 | $extern_php = UPDATE_PATH . $main_php; |
---|
| 87 | if(file_exists($extern_php)) { |
---|
| 88 | require_once($extern_php); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // 装飾付きエラーメッセージの表示 |
---|
| 93 | function sfErrorHeader($mess, $print = false) { |
---|
| 94 | global $GLOBAL_ERR; |
---|
| 95 | if($GLOBAL_ERR == "") { |
---|
| 96 | $GLOBAL_ERR = "<meta http-equiv='Content-Type' content='text/html; charset=" . CHAR_CODE . "'>\n"; |
---|
| 97 | } |
---|
| 98 | $GLOBAL_ERR.= "<table width='100%' border='0' cellspacing='0' cellpadding='0' summary=' '>\n"; |
---|
| 99 | $GLOBAL_ERR.= "<tr>\n"; |
---|
| 100 | $GLOBAL_ERR.= "<td bgcolor='#ffeebb' height='25' colspan='2' align='center'>\n"; |
---|
| 101 | $GLOBAL_ERR.= "<SPAN style='color:red; font-size:12px'><strong>" . $mess . "</strong></span>\n"; |
---|
| 102 | $GLOBAL_ERR.= "</td>\n"; |
---|
| 103 | $GLOBAL_ERR.= " </tr>\n"; |
---|
| 104 | $GLOBAL_ERR.= "</table>\n"; |
---|
| 105 | |
---|
| 106 | if($print) { |
---|
| 107 | print($GLOBAL_ERR); |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | /* エラーページの表示 */ |
---|
| 112 | function sfDispError($type) { |
---|
| 113 | |
---|
| 114 | $objPage = new LC_Page_Error_Ex(); |
---|
| 115 | $objPage->init(); |
---|
| 116 | $objView = new SC_AdminView(); |
---|
| 117 | |
---|
| 118 | switch ($type) { |
---|
| 119 | case LOGIN_ERROR: |
---|
| 120 | $objPage->tpl_error="IDまたはパスワードが正しくありません。<br />もう一度ご確認のうえ、再度入力してください。"; |
---|
| 121 | break; |
---|
| 122 | case ACCESS_ERROR: |
---|
| 123 | $objPage->tpl_error="ログイン認証の有効期限切れの可能性があります。<br />もう一度ご確認のうえ、再度ログインしてください。"; |
---|
| 124 | break; |
---|
| 125 | case AUTH_ERROR: |
---|
| 126 | $objPage->tpl_error="このファイルにはアクセス権限がありません。<br />もう一度ご確認のうえ、再度ログインしてください。"; |
---|
| 127 | break; |
---|
| 128 | case INVALID_MOVE_ERRORR: |
---|
| 129 | $objPage->tpl_error="不正なページ移動です。<br />もう一度ご確認のうえ、再度入力してください。"; |
---|
| 130 | break; |
---|
| 131 | default: |
---|
| 132 | $objPage->tpl_error="エラーが発生しました。<br />もう一度ご確認のうえ、再度ログインしてください。"; |
---|
| 133 | break; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | $objView->assignobj($objPage); |
---|
| 137 | $objView->display(LOGIN_FRAME); |
---|
| 138 | |
---|
| 139 | exit; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /* サイトエラーページの表示 */ |
---|
| 143 | function sfDispSiteError($type, $objSiteSess = "", $return_top = false, $err_msg = "", $is_mobile = false) { |
---|
| 144 | // FIXME |
---|
| 145 | global $objCampaignSess; |
---|
| 146 | |
---|
| 147 | if ($objSiteSess != "") { |
---|
| 148 | $objSiteSess->setNowPage('error'); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | $objPage = new LC_Page_Error_Ex(); |
---|
| 152 | $objPage->init(); |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | if($is_mobile === true) { |
---|
| 156 | $objView = new SC_MobileView(); |
---|
| 157 | } else { |
---|
| 158 | $objView = new SC_SiteView(); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | switch ($type) { |
---|
| 162 | case PRODUCT_NOT_FOUND: |
---|
| 163 | $objPage->tpl_error="ご指定のページはございません。"; |
---|
| 164 | break; |
---|
| 165 | case PAGE_ERROR: |
---|
| 166 | $objPage->tpl_error="不正なページ移動です。"; |
---|
| 167 | break; |
---|
| 168 | case CART_EMPTY: |
---|
| 169 | $objPage->tpl_error="カートに商品ががありません。"; |
---|
| 170 | break; |
---|
| 171 | case CART_ADD_ERROR: |
---|
| 172 | $objPage->tpl_error="購入処理中は、カートに商品を追加することはできません。"; |
---|
| 173 | break; |
---|
| 174 | case CANCEL_PURCHASE: |
---|
| 175 | $objPage->tpl_error="この手続きは無効となりました。以下の要因が考えられます。<br />・セッション情報の有効期限が切れてる場合<br />・購入手続き中に新しい購入手続きを実行した場合<br />・すでに購入手続きを完了している場合"; |
---|
| 176 | break; |
---|
| 177 | case CATEGORY_NOT_FOUND: |
---|
| 178 | $objPage->tpl_error="ご指定のカテゴリは存在しません。"; |
---|
| 179 | break; |
---|
| 180 | case SITE_LOGIN_ERROR: |
---|
| 181 | $objPage->tpl_error="メールアドレスもしくはパスワードが正しくありません。"; |
---|
| 182 | break; |
---|
| 183 | case TEMP_LOGIN_ERROR: |
---|
| 184 | $objPage->tpl_error="メールアドレスもしくはパスワードが正しくありません。<br />本登録がお済みでない場合は、仮登録メールに記載されている<br />URLより本登録を行ってください。"; |
---|
| 185 | break; |
---|
| 186 | case CUSTOMER_ERROR: |
---|
| 187 | $objPage->tpl_error="不正なアクセスです。"; |
---|
| 188 | break; |
---|
| 189 | case SOLD_OUT: |
---|
| 190 | $objPage->tpl_error="申し訳ございませんが、ご購入の直前で売り切れた商品があります。この手続きは無効となりました。"; |
---|
| 191 | break; |
---|
| 192 | case CART_NOT_FOUND: |
---|
| 193 | $objPage->tpl_error="申し訳ございませんが、カート内の商品情報の取得に失敗しました。この手続きは無効となりました。"; |
---|
| 194 | break; |
---|
| 195 | case LACK_POINT: |
---|
| 196 | $objPage->tpl_error="申し訳ございませんが、ポイントが不足しております。この手続きは無効となりました。"; |
---|
| 197 | break; |
---|
| 198 | case FAVORITE_ERROR: |
---|
| 199 | $objPage->tpl_error="既にお気に入りに追加されている商品です。"; |
---|
| 200 | break; |
---|
| 201 | case EXTRACT_ERROR: |
---|
| 202 | $objPage->tpl_error="ファイルの解凍に失敗しました。\n指定のディレクトリに書き込み権限が与えられていない可能性があります。"; |
---|
| 203 | break; |
---|
| 204 | case FTP_DOWNLOAD_ERROR: |
---|
| 205 | $objPage->tpl_error="ファイルのFTPダウンロードに失敗しました。"; |
---|
| 206 | break; |
---|
| 207 | case FTP_LOGIN_ERROR: |
---|
| 208 | $objPage->tpl_error="FTPログインに失敗しました。"; |
---|
| 209 | break; |
---|
| 210 | case FTP_CONNECT_ERROR: |
---|
| 211 | $objPage->tpl_error="FTPログインに失敗しました。"; |
---|
| 212 | break; |
---|
| 213 | case CREATE_DB_ERROR: |
---|
| 214 | $objPage->tpl_error="DBの作成に失敗しました。\n指定のユーザーには、DB作成の権限が与えられていない可能性があります。"; |
---|
| 215 | break; |
---|
| 216 | case DB_IMPORT_ERROR: |
---|
| 217 | $objPage->tpl_error="データベース構造のインポートに失敗しました。\nsqlファイルが壊れている可能性があります。"; |
---|
| 218 | break; |
---|
| 219 | case FILE_NOT_FOUND: |
---|
| 220 | $objPage->tpl_error="指定のパスに、設定ファイルが存在しません。"; |
---|
| 221 | break; |
---|
| 222 | case WRITE_FILE_ERROR: |
---|
| 223 | $objPage->tpl_error="設定ファイルに書き込めません。\n設定ファイルに書き込み権限を与えてください。"; |
---|
| 224 | break; |
---|
| 225 | case FREE_ERROR_MSG: |
---|
| 226 | $objPage->tpl_error=$err_msg; |
---|
| 227 | break; |
---|
| 228 | default: |
---|
| 229 | $objPage->tpl_error="エラーが発生しました。"; |
---|
| 230 | break; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | $objPage->return_top = $return_top; |
---|
| 234 | |
---|
| 235 | $objView->assignobj($objPage); |
---|
| 236 | |
---|
| 237 | if(is_object($objCampaignSess)) { |
---|
| 238 | // フレームを選択(キャンペーンページから遷移なら変更) |
---|
| 239 | $objCampaignSess->pageView($objView); |
---|
| 240 | } else { |
---|
| 241 | $objView->display(SITE_FRAME); |
---|
| 242 | } |
---|
| 243 | register_shutdown_function(array($objPage, "destroy")); |
---|
| 244 | exit; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | /* 認証の可否判定 */ |
---|
| 248 | function sfIsSuccess($objSess, $disp_error = true) { |
---|
| 249 | $ret = $objSess->IsSuccess(); |
---|
| 250 | if($ret != SUCCESS) { |
---|
| 251 | if($disp_error) { |
---|
| 252 | // エラーページの表示 |
---|
| 253 | SC_Utils::sfDispError($ret); |
---|
| 254 | } |
---|
| 255 | return false; |
---|
| 256 | } |
---|
| 257 | // リファラーチェック(CSRFの暫定的な対策) |
---|
| 258 | // 「リファラ無」 の場合はスルー |
---|
| 259 | // 「リファラ有」 かつ 「管理画面からの遷移でない」 場合にエラー画面を表示する |
---|
| 260 | if ( empty($_SERVER['HTTP_REFERER']) ) { |
---|
| 261 | // 警告表示させる? |
---|
| 262 | // sfErrorHeader('>> referrerが無効になっています。'); |
---|
| 263 | } else { |
---|
| 264 | $domain = SC_Utils::sfIsHTTPS() ? SSL_URL : SITE_URL; |
---|
| 265 | $pattern = sprintf('|^%s.*|', $domain); |
---|
| 266 | $referer = $_SERVER['HTTP_REFERER']; |
---|
| 267 | |
---|
| 268 | // 管理画面から以外の遷移の場合はエラー画面を表示 |
---|
| 269 | if (!preg_match($pattern, $referer)) { |
---|
| 270 | if ($disp_error) SC_Utils::sfDispError(INVALID_MOVE_ERRORR); |
---|
| 271 | return false; |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | return true; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | /** |
---|
| 278 | * 文字列をアスタリスクへ変換する. |
---|
| 279 | * |
---|
| 280 | * @param string $passlen 変換する文字列 |
---|
| 281 | * @return string アスタリスクへ変換した文字列 |
---|
| 282 | */ |
---|
| 283 | function lfPassLen($passlen){ |
---|
| 284 | $ret = ""; |
---|
| 285 | for ($i=0;$i<$passlen;true){ |
---|
| 286 | $ret.="*"; |
---|
| 287 | $i++; |
---|
| 288 | } |
---|
| 289 | return $ret; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | /** |
---|
| 293 | * HTTPSかどうかを判定 |
---|
| 294 | * |
---|
| 295 | * @return bool |
---|
| 296 | */ |
---|
| 297 | function sfIsHTTPS () { |
---|
| 298 | // HTTPS時には$_SERVER['HTTPS']には空でない値が入る |
---|
| 299 | // $_SERVER['HTTPS'] != 'off' はIIS用 |
---|
| 300 | if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { |
---|
| 301 | return true; |
---|
| 302 | } else { |
---|
| 303 | return false; |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | /** |
---|
| 308 | * 正規の遷移がされているかを判定 |
---|
| 309 | * 前画面でuniqidを埋め込んでおく必要がある |
---|
| 310 | * @param obj SC_Session, SC_SiteSession |
---|
| 311 | * @return bool |
---|
| 312 | */ |
---|
| 313 | function sfIsValidTransition($objSess) { |
---|
| 314 | // 前画面からPOSTされるuniqidが正しいものかどうかをチェック |
---|
| 315 | $uniqid = $objSess->getUniqId(); |
---|
| 316 | if ( !empty($_POST['uniqid']) && ($_POST['uniqid'] === $uniqid) ) { |
---|
| 317 | return true; |
---|
| 318 | } else { |
---|
| 319 | return false; |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | /* 前のページで正しく登録が行われたか判定 */ |
---|
| 324 | function sfIsPrePage($objSiteSess, $is_mobile = false) { |
---|
| 325 | $ret = $objSiteSess->isPrePage(); |
---|
| 326 | if($ret != true) { |
---|
| 327 | // エラーページの表示 |
---|
| 328 | sfDispSiteError(PAGE_ERROR, $objSiteSess, false, "", $is_mobile); |
---|
| 329 | } |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | function sfCheckNormalAccess($objSiteSess, $objCartSess) { |
---|
| 333 | // ユーザユニークIDの取得 |
---|
| 334 | $uniqid = $objSiteSess->getUniqId(); |
---|
| 335 | // 購入ボタンを押した時のカート内容がコピーされていない場合のみコピーする。 |
---|
| 336 | $objCartSess->saveCurrentCart($uniqid); |
---|
| 337 | // POSTのユニークIDとセッションのユニークIDを比較(ユニークIDがPOSTされていない場合はスルー) |
---|
| 338 | $ret = $objSiteSess->checkUniqId(); |
---|
| 339 | if($ret != true) { |
---|
| 340 | // エラーページの表示 |
---|
| 341 | sfDispSiteError(CANCEL_PURCHASE, $objSiteSess); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | // カート内が空でないか || 購入ボタンを押してから変化がないか |
---|
| 345 | $quantity = $objCartSess->getTotalQuantity(); |
---|
| 346 | $ret = $objCartSess->checkChangeCart(); |
---|
| 347 | if($ret == true || !($quantity > 0)) { |
---|
| 348 | // カート情報表示に強制移動する |
---|
| 349 | header("Location: ".URL_CART_TOP); |
---|
| 350 | exit; |
---|
| 351 | } |
---|
| 352 | return $uniqid; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | /* DB用日付文字列取得 */ |
---|
| 356 | function sfGetTimestamp($year, $month, $day, $last = false) { |
---|
| 357 | if($year != "" && $month != "" && $day != "") { |
---|
| 358 | if($last) { |
---|
| 359 | $time = "23:59:59"; |
---|
| 360 | } else { |
---|
| 361 | $time = "00:00:00"; |
---|
| 362 | } |
---|
| 363 | $date = $year."-".$month."-".$day." ".$time; |
---|
| 364 | } else { |
---|
| 365 | $date = ""; |
---|
| 366 | } |
---|
| 367 | return $date; |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | // INT型の数値チェック |
---|
| 371 | function sfIsInt($value) { |
---|
| 372 | if($value != "" && strlen($value) <= INT_LEN && is_numeric($value)) { |
---|
| 373 | return true; |
---|
| 374 | } |
---|
| 375 | return false; |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | function sfCSVDownload($data, $prefix = ""){ |
---|
| 379 | |
---|
| 380 | if($prefix == "") { |
---|
| 381 | $dir_name = sfUpDirName(); |
---|
| 382 | $file_name = $dir_name . date("ymdHis") .".csv"; |
---|
| 383 | } else { |
---|
| 384 | $file_name = $prefix . date("ymdHis") .".csv"; |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | /* HTTPヘッダの出力 */ |
---|
| 388 | Header("Content-disposition: attachment; filename=${file_name}"); |
---|
| 389 | Header("Content-type: application/octet-stream; name=${file_name}"); |
---|
| 390 | Header("Cache-Control: "); |
---|
| 391 | Header("Pragma: "); |
---|
| 392 | |
---|
| 393 | /* i18n~ だと正常に動作しないため、mb~ に変更 |
---|
| 394 | if (i18n_discover_encoding($data) == CHAR_CODE){ |
---|
| 395 | $data = i18n_convert($data,'SJIS',CHAR_CODE); |
---|
| 396 | } |
---|
| 397 | */ |
---|
| 398 | if (mb_internal_encoding() == CHAR_CODE){ |
---|
| 399 | $data = mb_convert_encoding($data,'SJIS',CHAR_CODE); |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | /* データを出力 */ |
---|
| 403 | echo $data; |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | /* 1階層上のディレクトリ名を取得する */ |
---|
| 407 | function sfUpDirName() { |
---|
| 408 | $path = $_SERVER['PHP_SELF']; |
---|
| 409 | $arrVal = split("/", $path); |
---|
| 410 | $cnt = count($arrVal); |
---|
| 411 | return $arrVal[($cnt - 2)]; |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | /** |
---|
| 418 | * 現在のサイトを更新(ただしポストは行わない) |
---|
| 419 | * |
---|
| 420 | * @deprecated LC_Page::reload() を使用して下さい. |
---|
| 421 | */ |
---|
| 422 | function sfReload($get = "") { |
---|
| 423 | if ($_SERVER["SERVER_PORT"] == "443" ){ |
---|
| 424 | $url = ereg_replace(URL_DIR . "$", "", SSL_URL); |
---|
| 425 | } else { |
---|
| 426 | $url = ereg_replace(URL_DIR . "$", "", SITE_URL); |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | if($get != "") { |
---|
| 430 | header("Location: ". $url . $_SERVER['PHP_SELF'] . "?" . $get); |
---|
| 431 | } else { |
---|
| 432 | header("Location: ". $url . $_SERVER['PHP_SELF']); |
---|
| 433 | } |
---|
| 434 | exit; |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | // チェックボックスの値をマージ |
---|
| 438 | function sfMergeCBValue($keyname, $max) { |
---|
| 439 | $conv = ""; |
---|
| 440 | $cnt = 1; |
---|
| 441 | for($cnt = 1; $cnt <= $max; $cnt++) { |
---|
| 442 | if ($_POST[$keyname . $cnt] == "1") { |
---|
| 443 | $conv.= "1"; |
---|
| 444 | } else { |
---|
| 445 | $conv.= "0"; |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | return $conv; |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | // html_checkboxesの値をマージして2進数形式に変更する。 |
---|
| 452 | function sfMergeCheckBoxes($array, $max) { |
---|
| 453 | $ret = ""; |
---|
| 454 | if(is_array($array)) { |
---|
| 455 | foreach($array as $val) { |
---|
| 456 | $arrTmp[$val] = "1"; |
---|
| 457 | } |
---|
| 458 | } |
---|
| 459 | for($i = 1; $i <= $max; $i++) { |
---|
| 460 | if($arrTmp[$i] == "1") { |
---|
| 461 | $ret.= "1"; |
---|
| 462 | } else { |
---|
| 463 | $ret.= "0"; |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | return $ret; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | |
---|
| 470 | // html_checkboxesの値をマージして「-」でつなげる。 |
---|
| 471 | function sfMergeParamCheckBoxes($array) { |
---|
| 472 | $ret = ''; |
---|
| 473 | if(is_array($array)) { |
---|
| 474 | foreach($array as $val) { |
---|
| 475 | if($ret != "") { |
---|
| 476 | $ret.= "-$val"; |
---|
| 477 | } else { |
---|
| 478 | $ret = $val; |
---|
| 479 | } |
---|
| 480 | } |
---|
| 481 | } else { |
---|
| 482 | $ret = $array; |
---|
| 483 | } |
---|
| 484 | return $ret; |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | // html_checkboxesの値をマージしてSQL検索用に変更する。 |
---|
| 488 | function sfSearchCheckBoxes($array) { |
---|
| 489 | $max = 0; |
---|
| 490 | $ret = ""; |
---|
| 491 | foreach($array as $val) { |
---|
| 492 | $arrTmp[$val] = "1"; |
---|
| 493 | if($val > $max) { |
---|
| 494 | $max = $val; |
---|
| 495 | } |
---|
| 496 | } |
---|
| 497 | for($i = 1; $i <= $max; $i++) { |
---|
| 498 | if($arrTmp[$i] == "1") { |
---|
| 499 | $ret.= "1"; |
---|
| 500 | } else { |
---|
| 501 | $ret.= "_"; |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | if($ret != "") { |
---|
| 506 | $ret.= "%"; |
---|
| 507 | } |
---|
| 508 | return $ret; |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | // 2進数形式の値をhtml_checkboxes対応の値に切り替える |
---|
| 512 | function sfSplitCheckBoxes($val) { |
---|
| 513 | $len = strlen($val); |
---|
| 514 | for($i = 0; $i < $len; $i++) { |
---|
| 515 | if(substr($val, $i, 1) == "1") { |
---|
| 516 | $arrRet[] = ($i + 1); |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | return $arrRet; |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | // チェックボックスの値をマージ |
---|
| 523 | function sfMergeCBSearchValue($keyname, $max) { |
---|
| 524 | $conv = ""; |
---|
| 525 | $cnt = 1; |
---|
| 526 | for($cnt = 1; $cnt <= $max; $cnt++) { |
---|
| 527 | if ($_POST[$keyname . $cnt] == "1") { |
---|
| 528 | $conv.= "1"; |
---|
| 529 | } else { |
---|
| 530 | $conv.= "_"; |
---|
| 531 | } |
---|
| 532 | } |
---|
| 533 | return $conv; |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | // チェックボックスの値を分解 |
---|
| 537 | function sfSplitCBValue($val, $keyname = "") { |
---|
| 538 | $len = strlen($val); |
---|
| 539 | $no = 1; |
---|
| 540 | for ($cnt = 0; $cnt < $len; $cnt++) { |
---|
| 541 | if($keyname != "") { |
---|
| 542 | $arr[$keyname . $no] = substr($val, $cnt, 1); |
---|
| 543 | } else { |
---|
| 544 | $arr[] = substr($val, $cnt, 1); |
---|
| 545 | } |
---|
| 546 | $no++; |
---|
| 547 | } |
---|
| 548 | return $arr; |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | // キーと値をセットした配列を取得 |
---|
| 552 | function sfArrKeyValue($arrList, $keyname, $valname, $len_max = "", $keysize = "") { |
---|
| 553 | |
---|
| 554 | $max = count($arrList); |
---|
| 555 | |
---|
| 556 | if($len_max != "" && $max > $len_max) { |
---|
| 557 | $max = $len_max; |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
| 561 | if($keysize != "") { |
---|
| 562 | $key = $this->sfCutString($arrList[$cnt][$keyname], $keysize); |
---|
| 563 | } else { |
---|
| 564 | $key = $arrList[$cnt][$keyname]; |
---|
| 565 | } |
---|
| 566 | $val = $arrList[$cnt][$valname]; |
---|
| 567 | |
---|
| 568 | if(!isset($arrRet[$key])) { |
---|
| 569 | $arrRet[$key] = $val; |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | } |
---|
| 573 | return $arrRet; |
---|
| 574 | } |
---|
| 575 | |
---|
| 576 | // キーと値をセットした配列を取得(値が複数の場合) |
---|
| 577 | function sfArrKeyValues($arrList, $keyname, $valname, $len_max = "", $keysize = "", $connect = "") { |
---|
| 578 | |
---|
| 579 | $max = count($arrList); |
---|
| 580 | |
---|
| 581 | if($len_max != "" && $max > $len_max) { |
---|
| 582 | $max = $len_max; |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
| 586 | if($keysize != "") { |
---|
| 587 | $key = $this->sfCutString($arrList[$cnt][$keyname], $keysize); |
---|
| 588 | } else { |
---|
| 589 | $key = $arrList[$cnt][$keyname]; |
---|
| 590 | } |
---|
| 591 | $val = $arrList[$cnt][$valname]; |
---|
| 592 | |
---|
| 593 | if($connect != "") { |
---|
| 594 | $arrRet[$key].= "$val".$connect; |
---|
| 595 | } else { |
---|
| 596 | $arrRet[$key][] = $val; |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | return $arrRet; |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | // 配列の値をカンマ区切りで返す。 |
---|
| 603 | function sfGetCommaList($array, $space=true) { |
---|
| 604 | if (count($array) > 0) { |
---|
| 605 | $line = ""; |
---|
| 606 | foreach($array as $val) { |
---|
| 607 | if ($space) { |
---|
| 608 | $line .= $val . ", "; |
---|
| 609 | }else{ |
---|
| 610 | $line .= $val . ","; |
---|
| 611 | } |
---|
| 612 | } |
---|
| 613 | if ($space) { |
---|
| 614 | $line = ereg_replace(", $", "", $line); |
---|
| 615 | }else{ |
---|
| 616 | $line = ereg_replace(",$", "", $line); |
---|
| 617 | } |
---|
| 618 | return $line; |
---|
| 619 | }else{ |
---|
| 620 | return false; |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | /* 配列の要素をCSVフォーマットで出力する。*/ |
---|
| 626 | function sfGetCSVList($array) { |
---|
| 627 | if (count($array) > 0) { |
---|
| 628 | foreach($array as $key => $val) { |
---|
| 629 | $val = mb_convert_encoding($val, CHAR_CODE, CHAR_CODE); |
---|
| 630 | $line .= "\"".$val."\","; |
---|
| 631 | } |
---|
| 632 | $line = ereg_replace(",$", "\n", $line); |
---|
| 633 | }else{ |
---|
| 634 | return false; |
---|
| 635 | } |
---|
| 636 | return $line; |
---|
| 637 | } |
---|
| 638 | |
---|
| 639 | /* 配列の要素をPDFフォーマットで出力する。*/ |
---|
| 640 | function sfGetPDFList($array) { |
---|
| 641 | foreach($array as $key => $val) { |
---|
| 642 | $line .= "\t".$val; |
---|
| 643 | } |
---|
| 644 | $line.="\n"; |
---|
| 645 | return $line; |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | |
---|
| 649 | |
---|
| 650 | /*-----------------------------------------------------------------*/ |
---|
| 651 | /* check_set_term |
---|
| 652 | /* 年月日に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
---|
| 653 | /* 引数 (開始年,開始月,開始日,終了年,終了月,終了日) |
---|
| 654 | /* 戻値 array(1,2,3) |
---|
| 655 | /* 1.開始年月日 (YYYY/MM/DD 000000) |
---|
| 656 | /* 2.終了年月日 (YYYY/MM/DD 235959) |
---|
| 657 | /* 3.エラー ( 0 = OK, 1 = NG ) |
---|
| 658 | /*-----------------------------------------------------------------*/ |
---|
| 659 | function sfCheckSetTerm ( $start_year, $start_month, $start_day, $end_year, $end_month, $end_day ) { |
---|
| 660 | |
---|
| 661 | // 期間指定 |
---|
| 662 | $error = 0; |
---|
| 663 | if ( $start_month || $start_day || $start_year){ |
---|
| 664 | if ( ! checkdate($start_month, $start_day , $start_year) ) $error = 1; |
---|
| 665 | } else { |
---|
| 666 | $error = 1; |
---|
| 667 | } |
---|
| 668 | if ( $end_month || $end_day || $end_year){ |
---|
| 669 | if ( ! checkdate($end_month ,$end_day ,$end_year) ) $error = 2; |
---|
| 670 | } |
---|
| 671 | if ( ! $error ){ |
---|
| 672 | $date1 = $start_year ."/".sprintf("%02d",$start_month) ."/".sprintf("%02d",$start_day) ." 000000"; |
---|
| 673 | $date2 = $end_year ."/".sprintf("%02d",$end_month) ."/".sprintf("%02d",$end_day) ." 235959"; |
---|
| 674 | if ($date1 > $date2) $error = 3; |
---|
| 675 | } else { |
---|
| 676 | $error = 1; |
---|
| 677 | } |
---|
| 678 | return array($date1, $date2, $error); |
---|
| 679 | } |
---|
| 680 | |
---|
| 681 | // エラー箇所の背景色を変更するためのfunction SC_Viewで読み込む |
---|
| 682 | function sfSetErrorStyle(){ |
---|
| 683 | return 'style="background-color:'.ERR_COLOR.'"'; |
---|
| 684 | } |
---|
| 685 | |
---|
| 686 | /* DBに渡す数値のチェック |
---|
| 687 | * 10桁以上はオーバーフローエラーを起こすので。 |
---|
| 688 | */ |
---|
| 689 | function sfCheckNumLength( $value ){ |
---|
| 690 | if ( ! is_numeric($value) ){ |
---|
| 691 | return false; |
---|
| 692 | } |
---|
| 693 | |
---|
| 694 | if ( strlen($value) > 9 ) { |
---|
| 695 | return false; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | return true; |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | // 一致した値のキー名を取得 |
---|
| 702 | function sfSearchKey($array, $word, $default) { |
---|
| 703 | foreach($array as $key => $val) { |
---|
| 704 | if($val == $word) { |
---|
| 705 | return $key; |
---|
| 706 | } |
---|
| 707 | } |
---|
| 708 | return $default; |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | // カテゴリツリーの取得($products_check:true商品登録済みのものだけ取得) |
---|
| 712 | function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) { |
---|
| 713 | $objQuery = new SC_Query(); |
---|
| 714 | $where = "del_flg = 0"; |
---|
| 715 | |
---|
| 716 | if($addwhere != "") { |
---|
| 717 | $where.= " AND $addwhere"; |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | $objQuery->setoption("ORDER BY rank DESC"); |
---|
| 721 | |
---|
| 722 | if($products_check) { |
---|
| 723 | $col = "T1.category_id, category_name, level"; |
---|
| 724 | $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id"; |
---|
| 725 | $where .= " AND product_count > 0"; |
---|
| 726 | } else { |
---|
| 727 | $col = "category_id, category_name, level"; |
---|
| 728 | $from = "dtb_category"; |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | $arrRet = $objQuery->select($col, $from, $where); |
---|
| 732 | |
---|
| 733 | $max = count($arrRet); |
---|
| 734 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
| 735 | $id = $arrRet[$cnt]['category_id']; |
---|
| 736 | $name = $arrRet[$cnt]['category_name']; |
---|
| 737 | $arrList[$id] = ""; |
---|
| 738 | /* |
---|
| 739 | for($n = 1; $n < $arrRet[$cnt]['level']; $n++) { |
---|
| 740 | $arrList[$id].= " "; |
---|
| 741 | } |
---|
| 742 | */ |
---|
| 743 | for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) { |
---|
| 744 | $arrList[$id].= $head; |
---|
| 745 | } |
---|
| 746 | $arrList[$id].= $name; |
---|
| 747 | } |
---|
| 748 | return $arrList; |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | // カテゴリツリーの取得(親カテゴリのValue:0) |
---|
| 752 | function sfGetLevelCatList($parent_zero = true) { |
---|
| 753 | $objQuery = new SC_Query(); |
---|
| 754 | $col = "category_id, category_name, level"; |
---|
| 755 | $where = "del_flg = 0"; |
---|
| 756 | $objQuery->setoption("ORDER BY rank DESC"); |
---|
| 757 | $arrRet = $objQuery->select($col, "dtb_category", $where); |
---|
| 758 | $max = count($arrRet); |
---|
| 759 | |
---|
| 760 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
| 761 | if($parent_zero) { |
---|
| 762 | if($arrRet[$cnt]['level'] == LEVEL_MAX) { |
---|
| 763 | $arrValue[$cnt] = $arrRet[$cnt]['category_id']; |
---|
| 764 | } else { |
---|
| 765 | $arrValue[$cnt] = ""; |
---|
| 766 | } |
---|
| 767 | } else { |
---|
| 768 | $arrValue[$cnt] = $arrRet[$cnt]['category_id']; |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | $arrOutput[$cnt] = ""; |
---|
| 772 | /* |
---|
| 773 | for($n = 1; $n < $arrRet[$cnt]['level']; $n++) { |
---|
| 774 | $arrOutput[$cnt].= " "; |
---|
| 775 | } |
---|
| 776 | */ |
---|
| 777 | for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) { |
---|
| 778 | $arrOutput[$cnt].= CATEGORY_HEAD; |
---|
| 779 | } |
---|
| 780 | $arrOutput[$cnt].= $arrRet[$cnt]['category_name']; |
---|
| 781 | } |
---|
| 782 | return array($arrValue, $arrOutput); |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | function sfGetErrorColor($val) { |
---|
| 786 | if($val != "") { |
---|
| 787 | return "background-color:" . ERR_COLOR; |
---|
| 788 | } |
---|
| 789 | return ""; |
---|
| 790 | } |
---|
| 791 | |
---|
| 792 | |
---|
| 793 | function sfGetEnabled($val) { |
---|
| 794 | if( ! $val ) { |
---|
| 795 | return " disabled=\"disabled\""; |
---|
| 796 | } |
---|
| 797 | return ""; |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | function sfGetChecked($param, $value) { |
---|
| 801 | if($param == $value) { |
---|
| 802 | return "checked=\"checked\""; |
---|
| 803 | } |
---|
| 804 | return ""; |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | function sfTrim($str) { |
---|
| 808 | $ret = ereg_replace("^[ \n\r]*", "", $str); |
---|
| 809 | $ret = ereg_replace("[ \n\r]*$", "", $ret); |
---|
| 810 | return $ret; |
---|
| 811 | } |
---|
| 812 | |
---|
| 813 | /* 所属するすべての階層の親IDを配列で返す */ |
---|
| 814 | function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) { |
---|
| 815 | $arrRet = SC_Utils::sfGetParentsArray($table, $pid_name, $id_name, $id); |
---|
| 816 | // 配列の先頭1つを削除する。 |
---|
| 817 | array_shift($arrRet); |
---|
| 818 | return $arrRet; |
---|
| 819 | } |
---|
| 820 | |
---|
| 821 | |
---|
| 822 | /* 親IDの配列を元に特定のカラムを取得する。*/ |
---|
| 823 | function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) { |
---|
| 824 | $col = $col_name; |
---|
| 825 | $len = count($arrId); |
---|
| 826 | $where = ""; |
---|
| 827 | |
---|
| 828 | for($cnt = 0; $cnt < $len; $cnt++) { |
---|
| 829 | if($where == "") { |
---|
| 830 | $where = "$id_name = ?"; |
---|
| 831 | } else { |
---|
| 832 | $where.= " OR $id_name = ?"; |
---|
| 833 | } |
---|
| 834 | } |
---|
| 835 | |
---|
| 836 | $objQuery->setorder("level"); |
---|
| 837 | $arrRet = $objQuery->select($col, $table, $where, $arrId); |
---|
| 838 | return $arrRet; |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | /* 子IDの配列を返す */ |
---|
| 842 | function sfGetChildsID($table, $pid_name, $id_name, $id) { |
---|
| 843 | $arrRet = SC_Utils::sfGetChildrenArray($table, $pid_name, $id_name, $id); |
---|
| 844 | return $arrRet; |
---|
| 845 | } |
---|
| 846 | |
---|
| 847 | /* カテゴリ変更時の移動処理 */ |
---|
| 848 | function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) { |
---|
| 849 | if ($old_catid == $new_catid) { |
---|
| 850 | return; |
---|
| 851 | } |
---|
| 852 | // 旧カテゴリでのランク削除処理 |
---|
| 853 | // 移動レコードのランクを取得する。 |
---|
| 854 | $where = "$id_name = ?"; |
---|
| 855 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
---|
| 856 | // 削除レコードのランクより上のレコードを一つ下にずらす。 |
---|
| 857 | $where = "rank > ? AND $cat_name = ?"; |
---|
| 858 | $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; |
---|
| 859 | $objQuery->exec($sqlup, array($rank, $old_catid)); |
---|
| 860 | // 新カテゴリでの登録処理 |
---|
| 861 | // 新カテゴリの最大ランクを取得する。 |
---|
| 862 | $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1; |
---|
| 863 | $where = "$id_name = ?"; |
---|
| 864 | $sqlup = "UPDATE $table SET rank = ? WHERE $where"; |
---|
| 865 | $objQuery->exec($sqlup, array($max_rank, $id)); |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | /* 税金計算 */ |
---|
| 869 | function sfTax($price, $tax, $tax_rule) { |
---|
| 870 | $real_tax = $tax / 100; |
---|
| 871 | $ret = $price * $real_tax; |
---|
| 872 | switch($tax_rule) { |
---|
| 873 | // 四捨五入 |
---|
| 874 | case 1: |
---|
| 875 | $ret = round($ret); |
---|
| 876 | break; |
---|
| 877 | // 切り捨て |
---|
| 878 | case 2: |
---|
| 879 | $ret = floor($ret); |
---|
| 880 | break; |
---|
| 881 | // 切り上げ |
---|
| 882 | case 3: |
---|
| 883 | $ret = ceil($ret); |
---|
| 884 | break; |
---|
| 885 | // デフォルト:切り上げ |
---|
| 886 | default: |
---|
| 887 | $ret = ceil($ret); |
---|
| 888 | break; |
---|
| 889 | } |
---|
| 890 | return $ret; |
---|
| 891 | } |
---|
| 892 | |
---|
| 893 | /* 税金付与 */ |
---|
| 894 | function sfPreTax($price, $tax, $tax_rule) { |
---|
| 895 | $real_tax = $tax / 100; |
---|
| 896 | $ret = $price * (1 + $real_tax); |
---|
| 897 | |
---|
| 898 | switch($tax_rule) { |
---|
| 899 | // 四捨五入 |
---|
| 900 | case 1: |
---|
| 901 | $ret = round($ret); |
---|
| 902 | break; |
---|
| 903 | // 切り捨て |
---|
| 904 | case 2: |
---|
| 905 | $ret = floor($ret); |
---|
| 906 | break; |
---|
| 907 | // 切り上げ |
---|
| 908 | case 3: |
---|
| 909 | $ret = ceil($ret); |
---|
| 910 | break; |
---|
| 911 | // デフォルト:切り上げ |
---|
| 912 | default: |
---|
| 913 | $ret = ceil($ret); |
---|
| 914 | break; |
---|
| 915 | } |
---|
| 916 | return $ret; |
---|
| 917 | } |
---|
| 918 | |
---|
| 919 | // 桁数を指定して四捨五入 |
---|
| 920 | function sfRound($value, $pow = 0){ |
---|
| 921 | $adjust = pow(10 ,$pow-1); |
---|
| 922 | |
---|
| 923 | // 整数且つ0出なければ桁数指定を行う |
---|
| 924 | if(SC_Utils::sfIsInt($adjust) and $pow > 1){ |
---|
| 925 | $ret = (round($value * $adjust)/$adjust); |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | $ret = round($ret); |
---|
| 929 | |
---|
| 930 | return $ret; |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | /* ポイント付与 */ |
---|
| 934 | function sfPrePoint($price, $point_rate, $rule = POINT_RULE, $product_id = "") { |
---|
| 935 | if(SC_Utils::sfIsInt($product_id)) { |
---|
| 936 | $objQuery = new SC_Query(); |
---|
| 937 | $where = "now() >= cast(start_date as date) AND "; |
---|
| 938 | $where .= "now() < cast(end_date as date) AND "; |
---|
| 939 | |
---|
| 940 | $where .= "del_flg = 0 AND campaign_id IN (SELECT campaign_id FROM dtb_campaign_detail where product_id = ? )"; |
---|
| 941 | //登録(更新)日付順 |
---|
| 942 | $objQuery->setorder('update_date DESC'); |
---|
| 943 | //キャンペーンポイントの取得 |
---|
| 944 | $arrRet = $objQuery->select("campaign_name, campaign_point_rate", "dtb_campaign", $where, array($product_id)); |
---|
| 945 | } |
---|
| 946 | //複数のキャンペーンに登録されている商品は、最新のキャンペーンからポイントを取得 |
---|
| 947 | if($arrRet[0]['campaign_point_rate'] != "") { |
---|
| 948 | $campaign_point_rate = $arrRet[0]['campaign_point_rate']; |
---|
| 949 | $real_point = $campaign_point_rate / 100; |
---|
| 950 | } else { |
---|
| 951 | $real_point = $point_rate / 100; |
---|
| 952 | } |
---|
| 953 | $ret = $price * $real_point; |
---|
| 954 | switch($rule) { |
---|
| 955 | // 四捨五入 |
---|
| 956 | case 1: |
---|
| 957 | $ret = round($ret); |
---|
| 958 | break; |
---|
| 959 | // 切り捨て |
---|
| 960 | case 2: |
---|
| 961 | $ret = floor($ret); |
---|
| 962 | break; |
---|
| 963 | // 切り上げ |
---|
| 964 | case 3: |
---|
| 965 | $ret = ceil($ret); |
---|
| 966 | break; |
---|
| 967 | // デフォルト:切り上げ |
---|
| 968 | default: |
---|
| 969 | $ret = ceil($ret); |
---|
| 970 | break; |
---|
| 971 | } |
---|
| 972 | //キャンペーン商品の場合 |
---|
| 973 | if($campaign_point_rate != "") { |
---|
| 974 | $ret = "(".$arrRet[0]['campaign_name']."ポイント率".$campaign_point_rate."%)".$ret; |
---|
| 975 | } |
---|
| 976 | return $ret; |
---|
| 977 | } |
---|
| 978 | |
---|
| 979 | /* 規格分類の件数取得 */ |
---|
| 980 | function sfGetClassCatCount() { |
---|
| 981 | $sql = "select count(dtb_class.class_id) as count, dtb_class.class_id "; |
---|
| 982 | $sql.= "from dtb_class inner join dtb_classcategory on dtb_class.class_id = dtb_classcategory.class_id "; |
---|
| 983 | $sql.= "where dtb_class.del_flg = 0 AND dtb_classcategory.del_flg = 0 "; |
---|
| 984 | $sql.= "group by dtb_class.class_id, dtb_class.name"; |
---|
| 985 | $objQuery = new SC_Query(); |
---|
| 986 | $arrList = $objQuery->getall($sql); |
---|
| 987 | // キーと値をセットした配列を取得 |
---|
| 988 | $arrRet = sfArrKeyValue($arrList, 'class_id', 'count'); |
---|
| 989 | |
---|
| 990 | return $arrRet; |
---|
| 991 | } |
---|
| 992 | |
---|
| 993 | /* 規格の登録 */ |
---|
| 994 | function sfInsertProductClass($objQuery, $arrList, $product_id) { |
---|
| 995 | // すでに規格登録があるかどうかをチェックする。 |
---|
| 996 | $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0"; |
---|
| 997 | $count = $objQuery->count("dtb_products_class", $where, array($product_id)); |
---|
| 998 | |
---|
| 999 | // すでに規格登録がない場合 |
---|
| 1000 | if($count == 0) { |
---|
| 1001 | // 既存規格の削除 |
---|
| 1002 | $where = "product_id = ?"; |
---|
| 1003 | $objQuery->delete("dtb_products_class", $where, array($product_id)); |
---|
| 1004 | $sqlval['product_id'] = $product_id; |
---|
| 1005 | $sqlval['classcategory_id1'] = '0'; |
---|
| 1006 | $sqlval['classcategory_id2'] = '0'; |
---|
| 1007 | $sqlval['product_code'] = $arrList["product_code"]; |
---|
| 1008 | $sqlval['stock'] = $arrList["stock"]; |
---|
| 1009 | $sqlval['stock_unlimited'] = $arrList["stock_unlimited"]; |
---|
| 1010 | $sqlval['price01'] = $arrList['price01']; |
---|
| 1011 | $sqlval['price02'] = $arrList['price02']; |
---|
| 1012 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
| 1013 | $sqlval['create_date'] = "now()"; |
---|
| 1014 | |
---|
| 1015 | if($_SESSION['member_id'] == "") { |
---|
| 1016 | $sqlval['creator_id'] = '0'; |
---|
| 1017 | } |
---|
| 1018 | |
---|
| 1019 | // INSERTの実行 |
---|
| 1020 | $objQuery->insert("dtb_products_class", $sqlval); |
---|
| 1021 | } |
---|
| 1022 | } |
---|
| 1023 | |
---|
| 1024 | function sfGetProductClassId($product_id, $classcategory_id1, $classcategory_id2) { |
---|
| 1025 | $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?"; |
---|
| 1026 | $objQuery = new SC_Query(); |
---|
| 1027 | $ret = $objQuery->get("dtb_products_class", "product_class_id", $where, Array($product_id, $classcategory_id1, $classcategory_id2)); |
---|
| 1028 | return $ret; |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | /* 文末の「/」をなくす */ |
---|
| 1032 | function sfTrimURL($url) { |
---|
| 1033 | $ret = ereg_replace("[/]+$", "", $url); |
---|
| 1034 | return $ret; |
---|
| 1035 | } |
---|
| 1036 | |
---|
| 1037 | /* 集計情報を元に最終計算 */ |
---|
| 1038 | function sfTotalConfirm($arrData, $objPage, $objCartSess, $arrInfo, $objCustomer = "") { |
---|
| 1039 | // 商品の合計個数 |
---|
| 1040 | $total_quantity = $objCartSess->getTotalQuantity(true); |
---|
| 1041 | |
---|
| 1042 | // 税金の取得 |
---|
| 1043 | $arrData['tax'] = $objPage->tpl_total_tax; |
---|
| 1044 | // 小計の取得 |
---|
| 1045 | $arrData['subtotal'] = $objPage->tpl_total_pretax; |
---|
| 1046 | |
---|
| 1047 | // 合計送料の取得 |
---|
| 1048 | $arrData['deliv_fee'] = 0; |
---|
| 1049 | |
---|
| 1050 | // 商品ごとの送料が有効の場合 |
---|
| 1051 | if (OPTION_PRODUCT_DELIV_FEE == 1) { |
---|
| 1052 | $arrData['deliv_fee']+= $objCartSess->getAllProductsDelivFee(); |
---|
| 1053 | } |
---|
| 1054 | |
---|
| 1055 | // 配送業者の送料が有効の場合 |
---|
| 1056 | if (OPTION_DELIV_FEE == 1) { |
---|
| 1057 | // 送料の合計を計算する |
---|
| 1058 | $arrData['deliv_fee']+= SC_Utils::sfGetDelivFee($arrData['deliv_pref'], $arrData['payment_id']); |
---|
| 1059 | } |
---|
| 1060 | |
---|
| 1061 | // 送料無料の購入数が設定されている場合 |
---|
| 1062 | if(DELIV_FREE_AMOUNT > 0) { |
---|
| 1063 | if($total_quantity >= DELIV_FREE_AMOUNT) { |
---|
| 1064 | $arrData['deliv_fee'] = 0; |
---|
| 1065 | } |
---|
| 1066 | } |
---|
| 1067 | |
---|
| 1068 | // 送料無料条件が設定されている場合 |
---|
| 1069 | if($arrInfo['free_rule'] > 0) { |
---|
| 1070 | // 小計が無料条件を超えている場合 |
---|
| 1071 | if($arrData['subtotal'] >= $arrInfo['free_rule']) { |
---|
| 1072 | $arrData['deliv_fee'] = 0; |
---|
| 1073 | } |
---|
| 1074 | } |
---|
| 1075 | |
---|
| 1076 | // 合計の計算 |
---|
| 1077 | $arrData['total'] = $objPage->tpl_total_pretax; // 商品合計 |
---|
| 1078 | $arrData['total']+= $arrData['deliv_fee']; // 送料 |
---|
| 1079 | $arrData['total']+= $arrData['charge']; // 手数料 |
---|
| 1080 | // お支払い合計 |
---|
| 1081 | $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE); |
---|
| 1082 | // 加算ポイントの計算 |
---|
| 1083 | $arrData['add_point'] = SC_Utils::sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point'], $arrInfo); |
---|
| 1084 | |
---|
| 1085 | if($objCustomer != "") { |
---|
| 1086 | // 誕生日月であった場合 |
---|
| 1087 | if($objCustomer->isBirthMonth()) { |
---|
| 1088 | $arrData['birth_point'] = BIRTH_MONTH_POINT; |
---|
| 1089 | $arrData['add_point'] += $arrData['birth_point']; |
---|
| 1090 | } |
---|
| 1091 | } |
---|
| 1092 | |
---|
| 1093 | if($arrData['add_point'] < 0) { |
---|
| 1094 | $arrData['add_point'] = 0; |
---|
| 1095 | } |
---|
| 1096 | |
---|
| 1097 | return $arrData; |
---|
| 1098 | } |
---|
| 1099 | |
---|
| 1100 | /* DBから取り出した日付の文字列を調整する。*/ |
---|
| 1101 | function sfDispDBDate($dbdate, $time = true) { |
---|
| 1102 | list($y, $m, $d, $H, $M) = split("[- :]", $dbdate); |
---|
| 1103 | |
---|
| 1104 | if(strlen($y) > 0 && strlen($m) > 0 && strlen($d) > 0) { |
---|
| 1105 | if ($time) { |
---|
| 1106 | $str = sprintf("%04d/%02d/%02d %02d:%02d", $y, $m, $d, $H, $M); |
---|
| 1107 | } else { |
---|
| 1108 | $str = sprintf("%04d/%02d/%02d", $y, $m, $d, $H, $M); |
---|
| 1109 | } |
---|
| 1110 | } else { |
---|
| 1111 | $str = ""; |
---|
| 1112 | } |
---|
| 1113 | return $str; |
---|
| 1114 | } |
---|
| 1115 | |
---|
| 1116 | function sfGetDelivTime($payment_id = "") { |
---|
| 1117 | $objQuery = new SC_Query(); |
---|
| 1118 | |
---|
| 1119 | $deliv_id = ""; |
---|
| 1120 | |
---|
| 1121 | if($payment_id != "") { |
---|
| 1122 | $where = "del_flg = 0 AND payment_id = ?"; |
---|
| 1123 | $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id)); |
---|
| 1124 | $deliv_id = $arrRet[0]['deliv_id']; |
---|
| 1125 | } |
---|
| 1126 | |
---|
| 1127 | if($deliv_id != "") { |
---|
| 1128 | $objQuery->setorder("time_id"); |
---|
| 1129 | $where = "deliv_id = ?"; |
---|
| 1130 | $arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id)); |
---|
| 1131 | } |
---|
| 1132 | |
---|
| 1133 | return $arrRet; |
---|
| 1134 | } |
---|
| 1135 | |
---|
| 1136 | |
---|
| 1137 | // 都道府県、支払い方法から配送料金を取得する |
---|
| 1138 | function sfGetDelivFee($pref, $payment_id = "") { |
---|
| 1139 | $objQuery = new SC_Query(); |
---|
| 1140 | |
---|
| 1141 | $deliv_id = ""; |
---|
| 1142 | |
---|
| 1143 | // 支払い方法が指定されている場合は、対応した配送業者を取得する |
---|
| 1144 | if($payment_id != "") { |
---|
| 1145 | $where = "del_flg = 0 AND payment_id = ?"; |
---|
| 1146 | $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id)); |
---|
| 1147 | $deliv_id = $arrRet[0]['deliv_id']; |
---|
| 1148 | // 支払い方法が指定されていない場合は、先頭の配送業者を取得する |
---|
| 1149 | } else { |
---|
| 1150 | $where = "del_flg = 0"; |
---|
| 1151 | $objQuery->setOrder("rank DESC"); |
---|
| 1152 | $objQuery->setLimitOffset(1); |
---|
| 1153 | $arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where); |
---|
| 1154 | $deliv_id = $arrRet[0]['deliv_id']; |
---|
| 1155 | } |
---|
| 1156 | |
---|
| 1157 | // 配送業者から配送料を取得 |
---|
| 1158 | if($deliv_id != "") { |
---|
| 1159 | |
---|
| 1160 | // 都道府県が指定されていない場合は、東京都の番号を指定しておく |
---|
| 1161 | if($pref == "") { |
---|
| 1162 | $pref = 13; |
---|
| 1163 | } |
---|
| 1164 | |
---|
| 1165 | $objQuery = new SC_Query(); |
---|
| 1166 | $where = "deliv_id = ? AND pref = ?"; |
---|
| 1167 | $arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref)); |
---|
| 1168 | } |
---|
| 1169 | return $arrRet[0]['fee']; |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | /* 支払い方法の取得 */ |
---|
| 1173 | function sfGetPayment() { |
---|
| 1174 | $objQuery = new SC_Query(); |
---|
| 1175 | // 購入金額が条件額以下の項目を取得 |
---|
| 1176 | $where = "del_flg = 0"; |
---|
| 1177 | $objQuery->setorder("fix, rank DESC"); |
---|
| 1178 | $arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where); |
---|
| 1179 | return $arrRet; |
---|
| 1180 | } |
---|
| 1181 | |
---|
| 1182 | /* 配列をキー名ごとの配列に変更する */ |
---|
| 1183 | function sfSwapArray($array) { |
---|
| 1184 | $max = count($array); |
---|
| 1185 | for($i = 0; $i < $max; $i++) { |
---|
| 1186 | foreach($array[$i] as $key => $val) { |
---|
| 1187 | $arrRet[$key][] = $val; |
---|
| 1188 | } |
---|
| 1189 | } |
---|
| 1190 | return $arrRet; |
---|
| 1191 | } |
---|
| 1192 | |
---|
| 1193 | /* かけ算をする(Smarty用) */ |
---|
| 1194 | function sfMultiply($num1, $num2) { |
---|
| 1195 | return ($num1 * $num2); |
---|
| 1196 | } |
---|
| 1197 | |
---|
| 1198 | /* DBに登録されたテンプレートメールの送信 */ |
---|
| 1199 | function sfSendTemplateMail($to, $to_name, $template_id, $objPage) { |
---|
| 1200 | global $arrMAILTPLPATH; |
---|
| 1201 | $objQuery = new SC_Query(); |
---|
| 1202 | // メールテンプレート情報の取得 |
---|
| 1203 | $where = "template_id = ?"; |
---|
| 1204 | $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id)); |
---|
| 1205 | $objPage->tpl_header = $arrRet[0]['header']; |
---|
| 1206 | $objPage->tpl_footer = $arrRet[0]['footer']; |
---|
| 1207 | $tmp_subject = $arrRet[0]['subject']; |
---|
| 1208 | |
---|
| 1209 | $objSiteInfo = new SC_SiteInfo(); |
---|
| 1210 | $arrInfo = $objSiteInfo->data; |
---|
| 1211 | |
---|
| 1212 | $objMailView = new SC_SiteView(); |
---|
| 1213 | // メール本文の取得 |
---|
| 1214 | $objMailView->assignobj($objPage); |
---|
| 1215 | $body = $objMailView->fetch($arrMAILTPLPATH[$template_id]); |
---|
| 1216 | |
---|
| 1217 | // メール送信処理 |
---|
| 1218 | $objSendMail = new GC_SendMail(); |
---|
| 1219 | $from = $arrInfo['email03']; |
---|
| 1220 | $error = $arrInfo['email04']; |
---|
| 1221 | $tosubject = $tmp_subject; |
---|
| 1222 | $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error); |
---|
| 1223 | $objSendMail->setTo($to, $to_name); |
---|
| 1224 | $objSendMail->sendMail(); // メール送信 |
---|
| 1225 | } |
---|
| 1226 | |
---|
| 1227 | /* 受注完了メール送信 */ |
---|
| 1228 | function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) { |
---|
| 1229 | global $arrMAILTPLPATH; |
---|
| 1230 | |
---|
| 1231 | $objPage = new LC_Page(); |
---|
| 1232 | $objSiteInfo = new SC_SiteInfo(); |
---|
| 1233 | $arrInfo = $objSiteInfo->data; |
---|
| 1234 | $objPage->arrInfo = $arrInfo; |
---|
| 1235 | |
---|
| 1236 | $objQuery = new SC_Query(); |
---|
| 1237 | |
---|
| 1238 | if($subject == "" && $header == "" && $footer == "") { |
---|
| 1239 | // メールテンプレート情報の取得 |
---|
| 1240 | $where = "template_id = ?"; |
---|
| 1241 | $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array('1')); |
---|
| 1242 | $objPage->tpl_header = $arrRet[0]['header']; |
---|
| 1243 | $objPage->tpl_footer = $arrRet[0]['footer']; |
---|
| 1244 | $tmp_subject = $arrRet[0]['subject']; |
---|
| 1245 | } else { |
---|
| 1246 | $objPage->tpl_header = $header; |
---|
| 1247 | $objPage->tpl_footer = $footer; |
---|
| 1248 | $tmp_subject = $subject; |
---|
| 1249 | } |
---|
| 1250 | |
---|
| 1251 | // 受注情報の取得 |
---|
| 1252 | $where = "order_id = ?"; |
---|
| 1253 | $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id)); |
---|
| 1254 | $arrOrder = $arrRet[0]; |
---|
| 1255 | $arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id)); |
---|
| 1256 | |
---|
| 1257 | $objPage->Message_tmp = $arrOrder['message']; |
---|
| 1258 | |
---|
| 1259 | // 顧客情報の取得 |
---|
| 1260 | $customer_id = $arrOrder['customer_id']; |
---|
| 1261 | $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); |
---|
| 1262 | $arrCustomer = $arrRet[0]; |
---|
| 1263 | |
---|
| 1264 | $objPage->arrCustomer = $arrCustomer; |
---|
| 1265 | $objPage->arrOrder = $arrOrder; |
---|
| 1266 | |
---|
| 1267 | //その他決済情報 |
---|
| 1268 | if($arrOrder['memo02'] != "") { |
---|
| 1269 | $arrOther = unserialize($arrOrder['memo02']); |
---|
| 1270 | |
---|
| 1271 | foreach($arrOther as $other_key => $other_val){ |
---|
| 1272 | if(sfTrim($other_val["value"]) == ""){ |
---|
| 1273 | $arrOther[$other_key]["value"] = ""; |
---|
| 1274 | } |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | $objPage->arrOther = $arrOther; |
---|
| 1278 | } |
---|
| 1279 | |
---|
| 1280 | // 都道府県変換 |
---|
| 1281 | global $arrPref; |
---|
| 1282 | $objPage->arrOrder['deliv_pref'] = $arrPref[$objPage->arrOrder['deliv_pref']]; |
---|
| 1283 | |
---|
| 1284 | $objPage->arrOrderDetail = $arrOrderDetail; |
---|
| 1285 | |
---|
| 1286 | $objCustomer = new SC_Customer(); |
---|
| 1287 | $objPage->tpl_user_point = $objCustomer->getValue('point'); |
---|
| 1288 | |
---|
| 1289 | $objMailView = new SC_SiteView(); |
---|
| 1290 | // メール本文の取得 |
---|
| 1291 | $objMailView->assignobj($objPage); |
---|
| 1292 | $body = $objMailView->fetch($arrMAILTPLPATH[$template_id]); |
---|
| 1293 | |
---|
| 1294 | // メール送信処理 |
---|
| 1295 | $objSendMail = new GC_SendMail(); |
---|
| 1296 | $bcc = $arrInfo['email01']; |
---|
| 1297 | $from = $arrInfo['email03']; |
---|
| 1298 | $error = $arrInfo['email04']; |
---|
| 1299 | |
---|
| 1300 | $tosubject = sfMakeSubject($tmp_subject); |
---|
| 1301 | |
---|
| 1302 | $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
| 1303 | $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." 様"); |
---|
| 1304 | |
---|
| 1305 | |
---|
| 1306 | // 送信フラグ:trueの場合は、送信する。 |
---|
| 1307 | if($send) { |
---|
| 1308 | if ($objSendMail->sendMail()) { |
---|
| 1309 | sfSaveMailHistory($order_id, $template_id, $tosubject, $body); |
---|
| 1310 | } |
---|
| 1311 | } |
---|
| 1312 | |
---|
| 1313 | return $objSendMail; |
---|
| 1314 | } |
---|
| 1315 | |
---|
| 1316 | // テンプレートを使用したメールの送信 |
---|
| 1317 | function sfSendTplMail($to, $subject, $tplpath, $objPage) { |
---|
| 1318 | $objMailView = new SC_SiteView(); |
---|
| 1319 | $objSiteInfo = new SC_SiteInfo(); |
---|
| 1320 | $arrInfo = $objSiteInfo->data; |
---|
| 1321 | // メール本文の取得 |
---|
| 1322 | $objPage->tpl_shopname=$arrInfo['shop_name']; |
---|
| 1323 | $objPage->tpl_infoemail = $arrInfo['email02']; |
---|
| 1324 | $objMailView->assignobj($objPage); |
---|
| 1325 | $body = $objMailView->fetch($tplpath); |
---|
| 1326 | // メール送信処理 |
---|
| 1327 | $objSendMail = new GC_SendMail(); |
---|
| 1328 | $to = mb_encode_mimeheader($to); |
---|
| 1329 | $bcc = $arrInfo['email01']; |
---|
| 1330 | $from = $arrInfo['email03']; |
---|
| 1331 | $error = $arrInfo['email04']; |
---|
| 1332 | $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
| 1333 | $objSendMail->sendMail(); |
---|
| 1334 | } |
---|
| 1335 | |
---|
| 1336 | // 通常のメール送信 |
---|
| 1337 | function sfSendMail($to, $subject, $body) { |
---|
| 1338 | $objSiteInfo = new SC_SiteInfo(); |
---|
| 1339 | $arrInfo = $objSiteInfo->data; |
---|
| 1340 | // メール送信処理 |
---|
| 1341 | $objSendMail = new GC_SendMail(); |
---|
| 1342 | $bcc = $arrInfo['email01']; |
---|
| 1343 | $from = $arrInfo['email03']; |
---|
| 1344 | $error = $arrInfo['email04']; |
---|
| 1345 | $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
| 1346 | $objSendMail->sendMail(); |
---|
| 1347 | } |
---|
| 1348 | |
---|
| 1349 | //件名にテンプレートを用いる |
---|
| 1350 | function sfMakeSubject($subject){ |
---|
| 1351 | |
---|
| 1352 | $objQuery = new SC_Query(); |
---|
| 1353 | $objMailView = new SC_SiteView(); |
---|
| 1354 | $objPage = new LC_Page(); |
---|
| 1355 | |
---|
| 1356 | $arrInfo = $objQuery->select("*","dtb_baseinfo"); |
---|
| 1357 | $arrInfo = $arrInfo[0]; |
---|
| 1358 | $objPage->tpl_shopname=$arrInfo['shop_name']; |
---|
| 1359 | $objPage->tpl_infoemail=$subject; |
---|
| 1360 | $objMailView->assignobj($objPage); |
---|
| 1361 | $mailtitle = $objMailView->fetch('mail_templates/mail_title.tpl'); |
---|
| 1362 | $ret = $mailtitle.$subject; |
---|
| 1363 | return $ret; |
---|
| 1364 | } |
---|
| 1365 | |
---|
| 1366 | // メール配信履歴への登録 |
---|
| 1367 | function sfSaveMailHistory($order_id, $template_id, $subject, $body) { |
---|
| 1368 | $sqlval['subject'] = $subject; |
---|
| 1369 | $sqlval['order_id'] = $order_id; |
---|
| 1370 | $sqlval['template_id'] = $template_id; |
---|
| 1371 | $sqlval['send_date'] = "Now()"; |
---|
| 1372 | if($_SESSION['member_id'] != "") { |
---|
| 1373 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
| 1374 | } else { |
---|
| 1375 | $sqlval['creator_id'] = '0'; |
---|
| 1376 | } |
---|
| 1377 | $sqlval['mail_body'] = $body; |
---|
| 1378 | |
---|
| 1379 | $objQuery = new SC_Query(); |
---|
| 1380 | $objQuery->insert("dtb_mail_history", $sqlval); |
---|
| 1381 | } |
---|
| 1382 | |
---|
| 1383 | /* 会員のメルマガ登録があるかどうかのチェック(仮会員を含まない) */ |
---|
| 1384 | function sfCheckCustomerMailMaga($email) { |
---|
| 1385 | $col = "email, mailmaga_flg, customer_id"; |
---|
| 1386 | $from = "dtb_customer"; |
---|
| 1387 | $where = "email = ? AND status = 2"; |
---|
| 1388 | $objQuery = new SC_Query(); |
---|
| 1389 | $arrRet = $objQuery->select($col, $from, $where, array($email)); |
---|
| 1390 | // 会員のメールアドレスが登録されている |
---|
| 1391 | if($arrRet[0]['customer_id'] != "") { |
---|
| 1392 | return true; |
---|
| 1393 | } |
---|
| 1394 | return false; |
---|
| 1395 | } |
---|
| 1396 | |
---|
| 1397 | // カードの処理結果を返す |
---|
| 1398 | function sfGetAuthonlyResult($dir, $file_name, $name01, $name02, $card_no, $card_exp, $amount, $order_id, $jpo_info = "10"){ |
---|
| 1399 | |
---|
| 1400 | $path = $dir .$file_name; // cgiファイルのフルパス生成 |
---|
| 1401 | $now_dir = getcwd(); // requireがうまくいかないので、cgi実行ディレクトリに移動する |
---|
| 1402 | chdir($dir); |
---|
| 1403 | |
---|
| 1404 | // パイプ渡しでコマンドラインからcgi起動 |
---|
| 1405 | $cmd = "$path card_no=$card_no name01=$name01 name02=$name02 card_exp=$card_exp amount=$amount order_id=$order_id jpo_info=$jpo_info"; |
---|
| 1406 | |
---|
| 1407 | $tmpResult = popen($cmd, "r"); |
---|
| 1408 | |
---|
| 1409 | // 結果取得 |
---|
| 1410 | while( ! FEOF ( $tmpResult ) ) { |
---|
| 1411 | $result .= FGETS($tmpResult); |
---|
| 1412 | } |
---|
| 1413 | pclose($tmpResult); // パイプを閉じる |
---|
| 1414 | chdir($now_dir); // 元にいたディレクトリに帰る |
---|
| 1415 | |
---|
| 1416 | // 結果を連想配列へ格納 |
---|
| 1417 | $result = ereg_replace("&$", "", $result); |
---|
| 1418 | foreach (explode("&",$result) as $data) { |
---|
| 1419 | list($key, $val) = explode("=", $data, 2); |
---|
| 1420 | $return[$key] = $val; |
---|
| 1421 | } |
---|
| 1422 | |
---|
| 1423 | return $return; |
---|
| 1424 | } |
---|
| 1425 | |
---|
| 1426 | // カテゴリID取得判定用のグローバル変数(一度取得されていたら再取得しないようにする) |
---|
| 1427 | //$g_category_on = false; |
---|
| 1428 | //$g_category_id = ""; |
---|
| 1429 | |
---|
| 1430 | /* 選択中のカテゴリを取得する */ |
---|
| 1431 | function sfGetCategoryId($product_id, $category_id) { |
---|
| 1432 | global $g_category_on; |
---|
| 1433 | global $g_category_id; |
---|
| 1434 | if(!$g_category_on) { |
---|
| 1435 | $g_category_on = true; |
---|
| 1436 | $category_id = (int) $category_id; |
---|
| 1437 | $product_id = (int) $product_id; |
---|
| 1438 | if(SC_Utils_Ex::sfIsInt($category_id) && SC_Utils_Ex::sfIsRecord("dtb_category","category_id", $category_id)) { |
---|
| 1439 | $g_category_id = $category_id; |
---|
| 1440 | } else if (SC_Utils_Ex::sfIsInt($product_id) && SC_Utils_Ex::sfIsRecord("dtb_products","product_id", $product_id, "status = 1")) { |
---|
| 1441 | $objQuery = new SC_Query(); |
---|
| 1442 | $where = "product_id = ?"; |
---|
| 1443 | $category_id = $objQuery->get("dtb_products", "category_id", $where, array($product_id)); |
---|
| 1444 | $g_category_id = $category_id; |
---|
| 1445 | } else { |
---|
| 1446 | // 不正な場合は、0を返す。 |
---|
| 1447 | $g_category_id = 0; |
---|
| 1448 | } |
---|
| 1449 | } |
---|
| 1450 | return $g_category_id; |
---|
| 1451 | } |
---|
| 1452 | |
---|
| 1453 | /* カテゴリから商品を検索する場合のWHERE文と値を返す */ |
---|
| 1454 | function sfGetCatWhere($category_id) { |
---|
| 1455 | // 子カテゴリIDの取得 |
---|
| 1456 | $arrRet = SC_Utils::sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id); |
---|
| 1457 | $tmp_where = ""; |
---|
| 1458 | foreach ($arrRet as $val) { |
---|
| 1459 | if($tmp_where == "") { |
---|
| 1460 | $tmp_where.= " category_id IN ( ?"; |
---|
| 1461 | } else { |
---|
| 1462 | $tmp_where.= ",? "; |
---|
| 1463 | } |
---|
| 1464 | $arrval[] = $val; |
---|
| 1465 | } |
---|
| 1466 | $tmp_where.= " ) "; |
---|
| 1467 | return array($tmp_where, $arrval); |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | /* 加算ポイントの計算式 */ |
---|
| 1471 | function sfGetAddPoint($totalpoint, $use_point, $arrInfo) { |
---|
| 1472 | // 購入商品の合計ポイントから利用したポイントのポイント換算価値を引く方式 |
---|
| 1473 | $add_point = $totalpoint - intval($use_point * ($arrInfo['point_rate'] / 100)); |
---|
| 1474 | |
---|
| 1475 | if($add_point < 0) { |
---|
| 1476 | $add_point = '0'; |
---|
| 1477 | } |
---|
| 1478 | return $add_point; |
---|
| 1479 | } |
---|
| 1480 | |
---|
| 1481 | /* 一意かつ予測されにくいID */ |
---|
| 1482 | function sfGetUniqRandomId($head = "") { |
---|
| 1483 | // 予測されないようにランダム文字列を付与する。 |
---|
| 1484 | $random = GC_Utils_Ex::gfMakePassword(8); |
---|
| 1485 | // 同一ホスト内で一意なIDを生成 |
---|
| 1486 | $id = uniqid($head); |
---|
| 1487 | return ($id . $random); |
---|
| 1488 | } |
---|
| 1489 | |
---|
| 1490 | // カテゴリ別オススメ品の取得 |
---|
| 1491 | function sfGetBestProducts( $conn, $category_id = 0){ |
---|
| 1492 | // 既に登録されている内容を取得する |
---|
| 1493 | $sql = "SELECT name, main_image, main_list_image, price01_min, price01_max, price02_min, price02_max, point_rate, |
---|
| 1494 | A.product_id, A.comment FROM dtb_best_products as A LEFT JOIN vw_products_allclass AS allcls |
---|
| 1495 | USING (product_id) WHERE A.category_id = ? AND A.del_flg = 0 AND status = 1 ORDER BY A.rank"; |
---|
| 1496 | $arrItems = $conn->getAll($sql, array($category_id)); |
---|
| 1497 | |
---|
| 1498 | return $arrItems; |
---|
| 1499 | } |
---|
| 1500 | |
---|
| 1501 | // 特殊制御文字の手動エスケープ |
---|
| 1502 | function sfManualEscape($data) { |
---|
| 1503 | // 配列でない場合 |
---|
| 1504 | if(!is_array($data)) { |
---|
| 1505 | if (DB_TYPE == "pgsql") { |
---|
| 1506 | $ret = pg_escape_string($data); |
---|
| 1507 | }else if(DB_TYPE == "mysql"){ |
---|
| 1508 | $ret = mysql_real_escape_string($data); |
---|
| 1509 | } |
---|
| 1510 | $ret = ereg_replace("%", "\\%", $ret); |
---|
| 1511 | $ret = ereg_replace("_", "\\_", $ret); |
---|
| 1512 | return $ret; |
---|
| 1513 | } |
---|
| 1514 | |
---|
| 1515 | // 配列の場合 |
---|
| 1516 | foreach($data as $val) { |
---|
| 1517 | if (DB_TYPE == "pgsql") { |
---|
| 1518 | $ret = pg_escape_string($val); |
---|
| 1519 | }else if(DB_TYPE == "mysql"){ |
---|
| 1520 | $ret = mysql_real_escape_string($val); |
---|
| 1521 | } |
---|
| 1522 | |
---|
| 1523 | $ret = ereg_replace("%", "\\%", $ret); |
---|
| 1524 | $ret = ereg_replace("_", "\\_", $ret); |
---|
| 1525 | $arrRet[] = $ret; |
---|
| 1526 | } |
---|
| 1527 | |
---|
| 1528 | return $arrRet; |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | // 受注番号、利用ポイント、加算ポイントから最終ポイントを取得 |
---|
| 1532 | function sfGetCustomerPoint($order_id, $use_point, $add_point) { |
---|
| 1533 | $objQuery = new SC_Query(); |
---|
| 1534 | $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id)); |
---|
| 1535 | $customer_id = $arrRet[0]['customer_id']; |
---|
| 1536 | if($customer_id != "" && $customer_id >= 1) { |
---|
| 1537 | $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); |
---|
| 1538 | $point = $arrRet[0]['point']; |
---|
| 1539 | $total_point = $arrRet[0]['point'] - $use_point + $add_point; |
---|
| 1540 | } else { |
---|
| 1541 | $total_point = ""; |
---|
| 1542 | $point = ""; |
---|
| 1543 | } |
---|
| 1544 | return array($point, $total_point); |
---|
| 1545 | } |
---|
| 1546 | |
---|
| 1547 | /* ドメイン間で有効なセッションのスタート */ |
---|
| 1548 | function sfDomainSessionStart() { |
---|
| 1549 | $ret = session_id(); |
---|
| 1550 | /* |
---|
| 1551 | ヘッダーを送信していてもsession_start()が必要なページがあるので |
---|
| 1552 | コメントアウトしておく |
---|
| 1553 | if($ret == "" && !headers_sent()) { |
---|
| 1554 | */ |
---|
| 1555 | if($ret == "") { |
---|
| 1556 | /* セッションパラメータの指定 |
---|
| 1557 | ・ブラウザを閉じるまで有効 |
---|
| 1558 | ・すべてのパスで有効 |
---|
| 1559 | ・同じドメイン間で共有 */ |
---|
| 1560 | session_set_cookie_params (0, "/", DOMAIN_NAME); |
---|
| 1561 | |
---|
| 1562 | if(!ini_get("session.auto_start")){ |
---|
| 1563 | // セッション開始 |
---|
| 1564 | session_start(); |
---|
| 1565 | } |
---|
| 1566 | } |
---|
| 1567 | } |
---|
| 1568 | |
---|
| 1569 | /* 文字列に強制的に改行を入れる */ |
---|
| 1570 | function sfPutBR($str, $size) { |
---|
| 1571 | $i = 0; |
---|
| 1572 | $cnt = 0; |
---|
| 1573 | $line = array(); |
---|
| 1574 | $ret = ""; |
---|
| 1575 | |
---|
| 1576 | while($str[$i] != "") { |
---|
| 1577 | $line[$cnt].=$str[$i]; |
---|
| 1578 | $i++; |
---|
| 1579 | if(strlen($line[$cnt]) > $size) { |
---|
| 1580 | $line[$cnt].="<br />"; |
---|
| 1581 | $cnt++; |
---|
| 1582 | } |
---|
| 1583 | } |
---|
| 1584 | |
---|
| 1585 | foreach($line as $val) { |
---|
| 1586 | $ret.=$val; |
---|
| 1587 | } |
---|
| 1588 | return $ret; |
---|
| 1589 | } |
---|
| 1590 | |
---|
| 1591 | // 二回以上繰り返されているスラッシュ[/]を一つに変換する。 |
---|
| 1592 | function sfRmDupSlash($istr){ |
---|
| 1593 | if(ereg("^http://", $istr)) { |
---|
| 1594 | $str = substr($istr, 7); |
---|
| 1595 | $head = "http://"; |
---|
| 1596 | } else if(ereg("^https://", $istr)) { |
---|
| 1597 | $str = substr($istr, 8); |
---|
| 1598 | $head = "https://"; |
---|
| 1599 | } else { |
---|
| 1600 | $str = $istr; |
---|
| 1601 | } |
---|
| 1602 | $str = ereg_replace("[/]+", "/", $str); |
---|
| 1603 | $ret = $head . $str; |
---|
| 1604 | return $ret; |
---|
| 1605 | } |
---|
| 1606 | |
---|
| 1607 | function sfEncodeFile($filepath, $enc_type, $out_dir) { |
---|
| 1608 | $ifp = fopen($filepath, "r"); |
---|
| 1609 | |
---|
| 1610 | $basename = basename($filepath); |
---|
| 1611 | $outpath = $out_dir . "enc_" . $basename; |
---|
| 1612 | |
---|
| 1613 | $ofp = fopen($outpath, "w+"); |
---|
| 1614 | |
---|
| 1615 | while(!feof($ifp)) { |
---|
| 1616 | $line = fgets($ifp); |
---|
| 1617 | $line = mb_convert_encoding($line, $enc_type, "auto"); |
---|
| 1618 | fwrite($ofp, $line); |
---|
| 1619 | } |
---|
| 1620 | |
---|
| 1621 | fclose($ofp); |
---|
| 1622 | fclose($ifp); |
---|
| 1623 | |
---|
| 1624 | return $outpath; |
---|
| 1625 | } |
---|
| 1626 | |
---|
| 1627 | function sfCutString($str, $len, $byte = true, $commadisp = true) { |
---|
| 1628 | if($byte) { |
---|
| 1629 | if(strlen($str) > ($len + 2)) { |
---|
| 1630 | $ret =substr($str, 0, $len); |
---|
| 1631 | $cut = substr($str, $len); |
---|
| 1632 | } else { |
---|
| 1633 | $ret = $str; |
---|
| 1634 | $commadisp = false; |
---|
| 1635 | } |
---|
| 1636 | } else { |
---|
| 1637 | if(mb_strlen($str) > ($len + 1)) { |
---|
| 1638 | $ret = mb_substr($str, 0, $len); |
---|
| 1639 | $cut = mb_substr($str, $len); |
---|
| 1640 | } else { |
---|
| 1641 | $ret = $str; |
---|
| 1642 | $commadisp = false; |
---|
| 1643 | } |
---|
| 1644 | } |
---|
| 1645 | |
---|
| 1646 | // 絵文字タグの途中で分断されないようにする。 |
---|
| 1647 | if (isset($cut)) { |
---|
| 1648 | // 分割位置より前の最後の [ 以降を取得する。 |
---|
| 1649 | $head = strrchr($ret, '['); |
---|
| 1650 | |
---|
| 1651 | // 分割位置より後の最初の ] 以前を取得する。 |
---|
| 1652 | $tail_pos = strpos($cut, ']'); |
---|
| 1653 | if ($tail_pos !== false) { |
---|
| 1654 | $tail = substr($cut, 0, $tail_pos + 1); |
---|
| 1655 | } |
---|
| 1656 | |
---|
| 1657 | // 分割位置より前に [、後に ] が見つかった場合は、[ から ] までを |
---|
| 1658 | // 接続して絵文字タグ1個分になるかどうかをチェックする。 |
---|
| 1659 | if ($head !== false && $tail_pos !== false) { |
---|
| 1660 | $subject = $head . $tail; |
---|
| 1661 | if (preg_match('/^\[emoji:e?\d+\]$/', $subject)) { |
---|
| 1662 | // 絵文字タグが見つかったので削除する。 |
---|
| 1663 | $ret = substr($ret, 0, -strlen($head)); |
---|
| 1664 | } |
---|
| 1665 | } |
---|
| 1666 | } |
---|
| 1667 | |
---|
| 1668 | if($commadisp){ |
---|
| 1669 | $ret = $ret . "..."; |
---|
| 1670 | } |
---|
| 1671 | return $ret; |
---|
| 1672 | } |
---|
| 1673 | |
---|
| 1674 | // 年、月、締め日から、先月の締め日+1、今月の締め日を求める。 |
---|
| 1675 | function sfTermMonth($year, $month, $close_day) { |
---|
| 1676 | $end_year = $year; |
---|
| 1677 | $end_month = $month; |
---|
| 1678 | |
---|
| 1679 | // 開始月が終了月と同じか否か |
---|
| 1680 | $same_month = false; |
---|
| 1681 | |
---|
| 1682 | // 該当月の末日を求める。 |
---|
| 1683 | $end_last_day = date("d", mktime(0, 0, 0, $month + 1, 0, $year)); |
---|
| 1684 | |
---|
| 1685 | // 月の末日が締め日より少ない場合 |
---|
| 1686 | if($end_last_day < $close_day) { |
---|
| 1687 | // 締め日を月末日に合わせる |
---|
| 1688 | $end_day = $end_last_day; |
---|
| 1689 | } else { |
---|
| 1690 | $end_day = $close_day; |
---|
| 1691 | } |
---|
| 1692 | |
---|
| 1693 | // 前月の取得 |
---|
| 1694 | $tmp_year = date("Y", mktime(0, 0, 0, $month, 0, $year)); |
---|
| 1695 | $tmp_month = date("m", mktime(0, 0, 0, $month, 0, $year)); |
---|
| 1696 | // 前月の末日を求める。 |
---|
| 1697 | $start_last_day = date("d", mktime(0, 0, 0, $month, 0, $year)); |
---|
| 1698 | |
---|
| 1699 | // 前月の末日が締め日より少ない場合 |
---|
| 1700 | if ($start_last_day < $close_day) { |
---|
| 1701 | // 月末日に合わせる |
---|
| 1702 | $tmp_day = $start_last_day; |
---|
| 1703 | } else { |
---|
| 1704 | $tmp_day = $close_day; |
---|
| 1705 | } |
---|
| 1706 | |
---|
| 1707 | // 先月の末日の翌日を取得する |
---|
| 1708 | $start_year = date("Y", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
---|
| 1709 | $start_month = date("m", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
---|
| 1710 | $start_day = date("d", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
---|
| 1711 | |
---|
| 1712 | // 日付の作成 |
---|
| 1713 | $start_date = sprintf("%d/%d/%d 00:00:00", $start_year, $start_month, $start_day); |
---|
| 1714 | $end_date = sprintf("%d/%d/%d 23:59:59", $end_year, $end_month, $end_day); |
---|
| 1715 | |
---|
| 1716 | return array($start_date, $end_date); |
---|
| 1717 | } |
---|
| 1718 | |
---|
| 1719 | // PDF用のRGBカラーを返す |
---|
| 1720 | function sfGetPdfRgb($hexrgb) { |
---|
| 1721 | $hex = substr($hexrgb, 0, 2); |
---|
| 1722 | $r = hexdec($hex) / 255; |
---|
| 1723 | |
---|
| 1724 | $hex = substr($hexrgb, 2, 2); |
---|
| 1725 | $g = hexdec($hex) / 255; |
---|
| 1726 | |
---|
| 1727 | $hex = substr($hexrgb, 4, 2); |
---|
| 1728 | $b = hexdec($hex) / 255; |
---|
| 1729 | |
---|
| 1730 | return array($r, $g, $b); |
---|
| 1731 | } |
---|
| 1732 | |
---|
| 1733 | //メルマガ仮登録とメール配信 |
---|
| 1734 | function sfRegistTmpMailData($mail_flag, $email){ |
---|
| 1735 | $objQuery = new SC_Query(); |
---|
| 1736 | $objConn = new SC_DBConn(); |
---|
| 1737 | $objPage = new LC_Page(); |
---|
| 1738 | |
---|
| 1739 | $random_id = sfGetUniqRandomId(); |
---|
| 1740 | $arrRegistMailMagazine["mail_flag"] = $mail_flag; |
---|
| 1741 | $arrRegistMailMagazine["email"] = $email; |
---|
| 1742 | $arrRegistMailMagazine["temp_id"] =$random_id; |
---|
| 1743 | $arrRegistMailMagazine["end_flag"]='0'; |
---|
| 1744 | $arrRegistMailMagazine["update_date"] = 'now()'; |
---|
| 1745 | |
---|
| 1746 | //メルマガ仮登録用フラグ |
---|
| 1747 | $flag = $objQuery->count("dtb_customer_mail_temp", "email=?", array($email)); |
---|
| 1748 | $objConn->query("BEGIN"); |
---|
| 1749 | switch ($flag){ |
---|
| 1750 | case '0': |
---|
| 1751 | $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine); |
---|
| 1752 | break; |
---|
| 1753 | |
---|
| 1754 | case '1': |
---|
| 1755 | $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine, "email = '" .addslashes($email). "'"); |
---|
| 1756 | break; |
---|
| 1757 | } |
---|
| 1758 | $objConn->query("COMMIT"); |
---|
| 1759 | $subject = sfMakeSubject('メルマガ仮登録が完了しました。'); |
---|
| 1760 | $objPage->tpl_url = SSL_URL."mailmagazine/regist.php?temp_id=".$arrRegistMailMagazine['temp_id']; |
---|
| 1761 | switch ($mail_flag){ |
---|
| 1762 | case '1': |
---|
| 1763 | $objPage->tpl_name = "登録"; |
---|
| 1764 | $objPage->tpl_kindname = "HTML"; |
---|
| 1765 | break; |
---|
| 1766 | |
---|
| 1767 | case '2': |
---|
| 1768 | $objPage->tpl_name = "登録"; |
---|
| 1769 | $objPage->tpl_kindname = "テキスト"; |
---|
| 1770 | break; |
---|
| 1771 | |
---|
| 1772 | case '3': |
---|
| 1773 | $objPage->tpl_name = "解除"; |
---|
| 1774 | break; |
---|
| 1775 | } |
---|
| 1776 | $objPage->tpl_email = $email; |
---|
| 1777 | sfSendTplMail($email, $subject, 'mail_templates/mailmagazine_temp.tpl', $objPage); |
---|
| 1778 | } |
---|
| 1779 | |
---|
| 1780 | // 再帰的に多段配列を検索して一次元配列(Hidden引渡し用配列)に変換する。 |
---|
| 1781 | function sfMakeHiddenArray($arrSrc, $arrDst = array(), $parent_key = "") { |
---|
| 1782 | if(is_array($arrSrc)) { |
---|
| 1783 | foreach($arrSrc as $key => $val) { |
---|
| 1784 | if($parent_key != "") { |
---|
| 1785 | $keyname = $parent_key . "[". $key . "]"; |
---|
| 1786 | } else { |
---|
| 1787 | $keyname = $key; |
---|
| 1788 | } |
---|
| 1789 | if(is_array($val)) { |
---|
| 1790 | $arrDst = sfMakeHiddenArray($val, $arrDst, $keyname); |
---|
| 1791 | } else { |
---|
| 1792 | $arrDst[$keyname] = $val; |
---|
| 1793 | } |
---|
| 1794 | } |
---|
| 1795 | } |
---|
| 1796 | return $arrDst; |
---|
| 1797 | } |
---|
| 1798 | |
---|
| 1799 | // DB取得日時をタイムに変換 |
---|
| 1800 | function sfDBDatetoTime($db_date) { |
---|
| 1801 | $date = ereg_replace("\..*$","",$db_date); |
---|
| 1802 | $time = strtotime($date); |
---|
| 1803 | return $time; |
---|
| 1804 | } |
---|
| 1805 | |
---|
| 1806 | // 出力の際にテンプレートを切り替えられる |
---|
| 1807 | /* |
---|
| 1808 | index.php?tpl=test.tpl |
---|
| 1809 | */ |
---|
| 1810 | function sfCustomDisplay($objPage, $is_mobile = false) { |
---|
| 1811 | $basename = basename($_SERVER["REQUEST_URI"]); |
---|
| 1812 | |
---|
| 1813 | if($basename == "") { |
---|
| 1814 | $path = $_SERVER["REQUEST_URI"] . "index.php"; |
---|
| 1815 | } else { |
---|
| 1816 | $path = $_SERVER["REQUEST_URI"]; |
---|
| 1817 | } |
---|
| 1818 | |
---|
| 1819 | if($_GET['tpl'] != "") { |
---|
| 1820 | $tpl_name = $_GET['tpl']; |
---|
| 1821 | } else { |
---|
| 1822 | $tpl_name = ereg_replace("^/", "", $path); |
---|
| 1823 | $tpl_name = ereg_replace("/", "_", $tpl_name); |
---|
| 1824 | $tpl_name = ereg_replace("(\.php$|\.html$)", ".tpl", $tpl_name); |
---|
| 1825 | } |
---|
| 1826 | |
---|
| 1827 | $template_path = TEMPLATE_FTP_DIR . $tpl_name; |
---|
| 1828 | |
---|
| 1829 | if($is_mobile === true) { |
---|
| 1830 | $objView = new SC_MobileView(); |
---|
| 1831 | $objView->assignobj($objPage); |
---|
| 1832 | $objView->display(SITE_FRAME); |
---|
| 1833 | } else if(file_exists($template_path)) { |
---|
| 1834 | $objView = new SC_UserView(TEMPLATE_FTP_DIR, COMPILE_FTP_DIR); |
---|
| 1835 | $objView->assignobj($objPage); |
---|
| 1836 | $objView->display($tpl_name); |
---|
| 1837 | } else { |
---|
| 1838 | $objView = new SC_SiteView(); |
---|
| 1839 | $objView->assignobj($objPage); |
---|
| 1840 | $objView->display(SITE_FRAME); |
---|
| 1841 | } |
---|
| 1842 | } |
---|
| 1843 | |
---|
| 1844 | //会員編集登録処理 |
---|
| 1845 | function sfEditCustomerData($array, $arrRegistColumn) { |
---|
| 1846 | $objQuery = new SC_Query(); |
---|
| 1847 | |
---|
| 1848 | foreach ($arrRegistColumn as $data) { |
---|
| 1849 | if ($data["column"] != "password") { |
---|
| 1850 | if($array[ $data['column'] ] != "") { |
---|
| 1851 | $arrRegist[ $data["column"] ] = $array[ $data["column"] ]; |
---|
| 1852 | } else { |
---|
| 1853 | $arrRegist[ $data['column'] ] = NULL; |
---|
| 1854 | } |
---|
| 1855 | } |
---|
| 1856 | } |
---|
| 1857 | if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) { |
---|
| 1858 | $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00"; |
---|
| 1859 | } else { |
---|
| 1860 | $arrRegist["birth"] = NULL; |
---|
| 1861 | } |
---|
| 1862 | |
---|
| 1863 | //-- パスワードの更新がある場合は暗号化。(更新がない場合はUPDATE文を構成しない) |
---|
| 1864 | if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC); |
---|
| 1865 | $arrRegist["update_date"] = "NOW()"; |
---|
| 1866 | |
---|
| 1867 | //-- 編集登録実行 |
---|
| 1868 | if (defined('MOBILE_SITE')) { |
---|
| 1869 | $arrRegist['email_mobile'] = $arrRegist['email']; |
---|
| 1870 | unset($arrRegist['email']); |
---|
| 1871 | } |
---|
| 1872 | $objQuery->begin(); |
---|
| 1873 | $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id'])); |
---|
| 1874 | $objQuery->commit(); |
---|
| 1875 | } |
---|
| 1876 | |
---|
| 1877 | // PHPのmb_convert_encoding関数をSmartyでも使えるようにする |
---|
| 1878 | function sf_mb_convert_encoding($str, $encode = 'CHAR_CODE') { |
---|
| 1879 | return mb_convert_encoding($str, $encode); |
---|
| 1880 | } |
---|
| 1881 | |
---|
| 1882 | // PHPのmktime関数をSmartyでも使えるようにする |
---|
| 1883 | function sf_mktime($format, $hour=0, $minute=0, $second=0, $month=1, $day=1, $year=1999) { |
---|
| 1884 | return date($format,mktime($hour, $minute, $second, $month, $day, $year)); |
---|
| 1885 | } |
---|
| 1886 | |
---|
| 1887 | // PHPのdate関数をSmartyでも使えるようにする |
---|
| 1888 | function sf_date($format, $timestamp = '') { |
---|
| 1889 | return date( $format, $timestamp); |
---|
| 1890 | } |
---|
| 1891 | |
---|
| 1892 | // チェックボックスの型を変換する |
---|
| 1893 | function sfChangeCheckBox($data , $tpl = false){ |
---|
| 1894 | if ($tpl) { |
---|
| 1895 | if ($data == 1){ |
---|
| 1896 | return 'checked'; |
---|
| 1897 | }else{ |
---|
| 1898 | return ""; |
---|
| 1899 | } |
---|
| 1900 | }else{ |
---|
| 1901 | if ($data == "on"){ |
---|
| 1902 | return 1; |
---|
| 1903 | }else{ |
---|
| 1904 | return 2; |
---|
| 1905 | } |
---|
| 1906 | } |
---|
| 1907 | } |
---|
| 1908 | |
---|
| 1909 | function sfCategory_Count($objQuery){ |
---|
| 1910 | $sql = ""; |
---|
| 1911 | |
---|
| 1912 | //テーブル内容の削除 |
---|
| 1913 | $objQuery->query("DELETE FROM dtb_category_count"); |
---|
| 1914 | $objQuery->query("DELETE FROM dtb_category_total_count"); |
---|
| 1915 | |
---|
| 1916 | //各カテゴリ内の商品数を数えて格納 |
---|
| 1917 | $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) "; |
---|
| 1918 | $sql .= " SELECT T1.category_id, count(T2.category_id), now() FROM dtb_category AS T1 LEFT JOIN dtb_products AS T2 "; |
---|
| 1919 | $sql .= " ON T1.category_id = T2.category_id "; |
---|
| 1920 | $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 "; |
---|
| 1921 | $sql .= " GROUP BY T1.category_id, T2.category_id "; |
---|
| 1922 | $objQuery->query($sql); |
---|
| 1923 | |
---|
| 1924 | //子カテゴリ内の商品数を集計する |
---|
| 1925 | $arrCat = $objQuery->getAll("SELECT * FROM dtb_category"); |
---|
| 1926 | |
---|
| 1927 | $sql = ""; |
---|
| 1928 | foreach($arrCat as $key => $val){ |
---|
| 1929 | |
---|
| 1930 | // 子ID一覧を取得 |
---|
| 1931 | $arrRet = sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']); |
---|
| 1932 | $line = sfGetCommaList($arrRet); |
---|
| 1933 | |
---|
| 1934 | $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) "; |
---|
| 1935 | $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count "; |
---|
| 1936 | $sql .= " WHERE category_id IN (" . $line . ")"; |
---|
| 1937 | |
---|
| 1938 | $objQuery->query($sql, array($val['category_id'])); |
---|
| 1939 | } |
---|
| 1940 | } |
---|
| 1941 | |
---|
| 1942 | // 2つの配列を用いて連想配列を作成する |
---|
| 1943 | function sfarrCombine($arrKeys, $arrValues) { |
---|
| 1944 | |
---|
| 1945 | if(count($arrKeys) <= 0 and count($arrValues) <= 0) return array(); |
---|
| 1946 | |
---|
| 1947 | $keys = array_values($arrKeys); |
---|
| 1948 | $vals = array_values($arrValues); |
---|
| 1949 | |
---|
| 1950 | $max = max( count( $keys ), count( $vals ) ); |
---|
| 1951 | $combine_ary = array(); |
---|
| 1952 | for($i=0; $i<$max; $i++) { |
---|
| 1953 | $combine_ary[$keys[$i]] = $vals[$i]; |
---|
| 1954 | } |
---|
| 1955 | if(is_array($combine_ary)) return $combine_ary; |
---|
| 1956 | |
---|
| 1957 | return false; |
---|
| 1958 | } |
---|
| 1959 | |
---|
| 1960 | /* 階層構造のテーブルから子ID配列を取得する */ |
---|
| 1961 | function sfGetChildrenArray($table, $pid_name, $id_name, $id) { |
---|
| 1962 | $objQuery = new SC_Query(); |
---|
| 1963 | $col = $pid_name . "," . $id_name; |
---|
| 1964 | $arrData = $objQuery->select($col, $table); |
---|
| 1965 | |
---|
| 1966 | $arrPID = array(); |
---|
| 1967 | $arrPID[] = $id; |
---|
| 1968 | $arrChildren = array(); |
---|
| 1969 | $arrChildren[] = $id; |
---|
| 1970 | |
---|
| 1971 | $arrRet = SC_Utils::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID); |
---|
| 1972 | |
---|
| 1973 | while(count($arrRet) > 0) { |
---|
| 1974 | $arrChildren = array_merge($arrChildren, $arrRet); |
---|
| 1975 | $arrRet = SC_Utils::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet); |
---|
| 1976 | } |
---|
| 1977 | |
---|
| 1978 | return $arrChildren; |
---|
| 1979 | } |
---|
| 1980 | |
---|
| 1981 | /* 親ID直下の子IDをすべて取得する */ |
---|
| 1982 | function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) { |
---|
| 1983 | $arrChildren = array(); |
---|
| 1984 | $max = count($arrData); |
---|
| 1985 | |
---|
| 1986 | for($i = 0; $i < $max; $i++) { |
---|
| 1987 | foreach($arrPID as $val) { |
---|
| 1988 | if($arrData[$i][$pid_name] == $val) { |
---|
| 1989 | $arrChildren[] = $arrData[$i][$id_name]; |
---|
| 1990 | } |
---|
| 1991 | } |
---|
| 1992 | } |
---|
| 1993 | return $arrChildren; |
---|
| 1994 | } |
---|
| 1995 | |
---|
| 1996 | |
---|
| 1997 | /* 階層構造のテーブルから親ID配列を取得する */ |
---|
| 1998 | function sfGetParentsArray($table, $pid_name, $id_name, $id) { |
---|
| 1999 | $objQuery = new SC_Query(); |
---|
| 2000 | $col = $pid_name . "," . $id_name; |
---|
| 2001 | $arrData = $objQuery->select($col, $table); |
---|
| 2002 | |
---|
| 2003 | $arrParents = array(); |
---|
| 2004 | $arrParents[] = $id; |
---|
| 2005 | $child = $id; |
---|
| 2006 | |
---|
| 2007 | $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child); |
---|
| 2008 | |
---|
| 2009 | while($ret != "") { |
---|
| 2010 | $arrParents[] = $ret; |
---|
| 2011 | $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret); |
---|
| 2012 | } |
---|
| 2013 | |
---|
| 2014 | $arrParents = array_reverse($arrParents); |
---|
| 2015 | |
---|
| 2016 | return $arrParents; |
---|
| 2017 | } |
---|
| 2018 | |
---|
| 2019 | /* 子ID所属する親IDを取得する */ |
---|
| 2020 | function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) { |
---|
| 2021 | $max = count($arrData); |
---|
| 2022 | $parent = ""; |
---|
| 2023 | for($i = 0; $i < $max; $i++) { |
---|
| 2024 | if($arrData[$i][$id_name] == $child) { |
---|
| 2025 | $parent = $arrData[$i][$pid_name]; |
---|
| 2026 | break; |
---|
| 2027 | } |
---|
| 2028 | } |
---|
| 2029 | return $parent; |
---|
| 2030 | } |
---|
| 2031 | |
---|
| 2032 | /* 階層構造のテーブルから与えられたIDの兄弟を取得する */ |
---|
| 2033 | function sfGetBrothersArray($arrData, $pid_name, $id_name, $arrPID) { |
---|
| 2034 | $max = count($arrData); |
---|
| 2035 | |
---|
| 2036 | $arrBrothers = array(); |
---|
| 2037 | foreach($arrPID as $id) { |
---|
| 2038 | // 親IDを検索する |
---|
| 2039 | for($i = 0; $i < $max; $i++) { |
---|
| 2040 | if($arrData[$i][$id_name] == $id) { |
---|
| 2041 | $parent = $arrData[$i][$pid_name]; |
---|
| 2042 | break; |
---|
| 2043 | } |
---|
| 2044 | } |
---|
| 2045 | // 兄弟IDを検索する |
---|
| 2046 | for($i = 0; $i < $max; $i++) { |
---|
| 2047 | if($arrData[$i][$pid_name] == $parent) { |
---|
| 2048 | $arrBrothers[] = $arrData[$i][$id_name]; |
---|
| 2049 | } |
---|
| 2050 | } |
---|
| 2051 | } |
---|
| 2052 | return $arrBrothers; |
---|
| 2053 | } |
---|
| 2054 | |
---|
| 2055 | /* 階層構造のテーブルから与えられたIDの直属の子を取得する */ |
---|
| 2056 | function sfGetUnderChildrenArray($arrData, $pid_name, $id_name, $parent) { |
---|
| 2057 | $max = count($arrData); |
---|
| 2058 | |
---|
| 2059 | $arrChildren = array(); |
---|
| 2060 | // 子IDを検索する |
---|
| 2061 | for($i = 0; $i < $max; $i++) { |
---|
| 2062 | if($arrData[$i][$pid_name] == $parent) { |
---|
| 2063 | $arrChildren[] = $arrData[$i][$id_name]; |
---|
| 2064 | } |
---|
| 2065 | } |
---|
| 2066 | return $arrChildren; |
---|
| 2067 | } |
---|
| 2068 | |
---|
| 2069 | |
---|
| 2070 | // カテゴリツリーの取得 |
---|
| 2071 | function sfGetCatTree($parent_category_id, $count_check = false) { |
---|
| 2072 | $objQuery = new SC_Query(); |
---|
| 2073 | $col = ""; |
---|
| 2074 | $col .= " cat.category_id,"; |
---|
| 2075 | $col .= " cat.category_name,"; |
---|
| 2076 | $col .= " cat.parent_category_id,"; |
---|
| 2077 | $col .= " cat.level,"; |
---|
| 2078 | $col .= " cat.rank,"; |
---|
| 2079 | $col .= " cat.creator_id,"; |
---|
| 2080 | $col .= " cat.create_date,"; |
---|
| 2081 | $col .= " cat.update_date,"; |
---|
| 2082 | $col .= " cat.del_flg, "; |
---|
| 2083 | $col .= " ttl.product_count"; |
---|
| 2084 | $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id"; |
---|
| 2085 | // 登録商品数のチェック |
---|
| 2086 | if($count_check) { |
---|
| 2087 | $where = "del_flg = 0 AND product_count > 0"; |
---|
| 2088 | } else { |
---|
| 2089 | $where = "del_flg = 0"; |
---|
| 2090 | } |
---|
| 2091 | $objQuery->setoption("ORDER BY rank DESC"); |
---|
| 2092 | $arrRet = $objQuery->select($col, $from, $where); |
---|
| 2093 | |
---|
| 2094 | $arrParentID = sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id); |
---|
| 2095 | |
---|
| 2096 | foreach($arrRet as $key => $array) { |
---|
| 2097 | foreach($arrParentID as $val) { |
---|
| 2098 | if($array['category_id'] == $val) { |
---|
| 2099 | $arrRet[$key]['display'] = 1; |
---|
| 2100 | break; |
---|
| 2101 | } |
---|
| 2102 | } |
---|
| 2103 | } |
---|
| 2104 | |
---|
| 2105 | return $arrRet; |
---|
| 2106 | } |
---|
| 2107 | |
---|
| 2108 | // 親カテゴリーを連結した文字列を取得する |
---|
| 2109 | function sfGetCatCombName($category_id){ |
---|
| 2110 | // 商品が属するカテゴリIDを縦に取得 |
---|
| 2111 | $objQuery = new SC_Query(); |
---|
| 2112 | $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
---|
| 2113 | $ConbName = ""; |
---|
| 2114 | |
---|
| 2115 | // カテゴリー名称を取得する |
---|
| 2116 | foreach($arrCatID as $key => $val){ |
---|
| 2117 | $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; |
---|
| 2118 | $arrVal = array($val); |
---|
| 2119 | $CatName = $objQuery->getOne($sql,$arrVal); |
---|
| 2120 | $ConbName .= $CatName . ' | '; |
---|
| 2121 | } |
---|
| 2122 | // 最後の | をカットする |
---|
| 2123 | $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2); |
---|
| 2124 | |
---|
| 2125 | return $ConbName; |
---|
| 2126 | } |
---|
| 2127 | |
---|
| 2128 | // 指定したカテゴリーIDの大カテゴリーを取得する |
---|
| 2129 | function sfGetFirstCat($category_id){ |
---|
| 2130 | // 商品が属するカテゴリIDを縦に取得 |
---|
| 2131 | $objQuery = new SC_Query(); |
---|
| 2132 | $arrRet = array(); |
---|
| 2133 | $arrCatID = SC_Utils_Ex::sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
---|
| 2134 | $arrRet['id'] = $arrCatID[0]; |
---|
| 2135 | |
---|
| 2136 | // カテゴリー名称を取得する |
---|
| 2137 | $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; |
---|
| 2138 | $arrVal = array($arrRet['id']); |
---|
| 2139 | $arrRet['name'] = $objQuery->getOne($sql,$arrVal); |
---|
| 2140 | |
---|
| 2141 | return $arrRet; |
---|
| 2142 | } |
---|
| 2143 | |
---|
| 2144 | // SQLシングルクォート対応 |
---|
| 2145 | function sfQuoteSmart($in){ |
---|
| 2146 | |
---|
| 2147 | if (is_int($in) || is_double($in)) { |
---|
| 2148 | return $in; |
---|
| 2149 | } elseif (is_bool($in)) { |
---|
| 2150 | return $in ? 1 : 0; |
---|
| 2151 | } elseif (is_null($in)) { |
---|
| 2152 | return 'NULL'; |
---|
| 2153 | } else { |
---|
| 2154 | return "'" . str_replace("'", "''", $in) . "'"; |
---|
| 2155 | } |
---|
| 2156 | } |
---|
| 2157 | |
---|
| 2158 | // ディレクトリ以下のファイルを再帰的にコピー |
---|
| 2159 | function sfCopyDir($src, $des, $mess, $override = false){ |
---|
| 2160 | if(!is_dir($src)){ |
---|
| 2161 | return false; |
---|
| 2162 | } |
---|
| 2163 | |
---|
| 2164 | $oldmask = umask(0); |
---|
| 2165 | $mod= stat($src); |
---|
| 2166 | |
---|
| 2167 | // ディレクトリがなければ作成する |
---|
| 2168 | if(!file_exists($des)) { |
---|
| 2169 | if(!mkdir($des, $mod[2])) { |
---|
| 2170 | print("path:" . $des); |
---|
| 2171 | } |
---|
| 2172 | } |
---|
| 2173 | |
---|
| 2174 | $fileArray=glob( $src."*" ); |
---|
| 2175 | foreach( $fileArray as $key => $data_ ){ |
---|
| 2176 | // CVS管理ファイルはコピーしない |
---|
| 2177 | if(ereg("/CVS/Entries", $data_)) { |
---|
| 2178 | break; |
---|
| 2179 | } |
---|
| 2180 | if(ereg("/CVS/Repository", $data_)) { |
---|
| 2181 | break; |
---|
| 2182 | } |
---|
| 2183 | if(ereg("/CVS/Root", $data_)) { |
---|
| 2184 | break; |
---|
| 2185 | } |
---|
| 2186 | |
---|
| 2187 | mb_ereg("^(.*[\/])(.*)",$data_, $matches); |
---|
| 2188 | $data=$matches[2]; |
---|
| 2189 | if( is_dir( $data_ ) ){ |
---|
| 2190 | $mess = sfCopyDir( $data_.'/', $des.$data.'/', $mess); |
---|
| 2191 | }else{ |
---|
| 2192 | if(!$override && file_exists($des.$data)) { |
---|
| 2193 | $mess.= $des.$data . ":ファイルが存在します\n"; |
---|
| 2194 | } else { |
---|
| 2195 | if(@copy( $data_, $des.$data)) { |
---|
| 2196 | $mess.= $des.$data . ":コピー成功\n"; |
---|
| 2197 | } else { |
---|
| 2198 | $mess.= $des.$data . ":コピー失敗\n"; |
---|
| 2199 | } |
---|
| 2200 | } |
---|
| 2201 | $mod=stat($data_ ); |
---|
| 2202 | } |
---|
| 2203 | } |
---|
| 2204 | umask($oldmask); |
---|
| 2205 | return $mess; |
---|
| 2206 | } |
---|
| 2207 | |
---|
| 2208 | // 指定したフォルダ内のファイルを全て削除する |
---|
| 2209 | function sfDelFile($dir){ |
---|
| 2210 | $dh = opendir($dir); |
---|
| 2211 | // フォルダ内のファイルを削除 |
---|
| 2212 | while($file = readdir($dh)){ |
---|
| 2213 | if ($file == "." or $file == "..") continue; |
---|
| 2214 | $del_file = $dir . "/" . $file; |
---|
| 2215 | if(is_file($del_file)){ |
---|
| 2216 | $ret = unlink($dir . "/" . $file); |
---|
| 2217 | }else if (is_dir($del_file)){ |
---|
| 2218 | $ret = sfDelFile($del_file); |
---|
| 2219 | } |
---|
| 2220 | |
---|
| 2221 | if(!$ret){ |
---|
| 2222 | return $ret; |
---|
| 2223 | } |
---|
| 2224 | } |
---|
| 2225 | |
---|
| 2226 | // 閉じる |
---|
| 2227 | closedir($dh); |
---|
| 2228 | |
---|
| 2229 | // フォルダを削除 |
---|
| 2230 | return rmdir($dir); |
---|
| 2231 | } |
---|
| 2232 | |
---|
| 2233 | /* |
---|
| 2234 | * 関数名:sfWriteFile |
---|
| 2235 | * 引数1 :書き込むデータ |
---|
| 2236 | * 引数2 :ファイルパス |
---|
| 2237 | * 引数3 :書き込みタイプ |
---|
| 2238 | * 引数4 :パーミッション |
---|
| 2239 | * 戻り値:結果フラグ 成功なら true 失敗なら false |
---|
| 2240 | * 説明 :ファイル書き出し |
---|
| 2241 | */ |
---|
| 2242 | function sfWriteFile($str, $path, $type, $permission = "") { |
---|
| 2243 | //ファイルを開く |
---|
| 2244 | if (!($file = fopen ($path, $type))) { |
---|
| 2245 | return false; |
---|
| 2246 | } |
---|
| 2247 | |
---|
| 2248 | //ファイルロック |
---|
| 2249 | flock ($file, LOCK_EX); |
---|
| 2250 | //ファイルの書き込み |
---|
| 2251 | fputs ($file, $str); |
---|
| 2252 | //ファイルロックの解除 |
---|
| 2253 | flock ($file, LOCK_UN); |
---|
| 2254 | //ファイルを閉じる |
---|
| 2255 | fclose ($file); |
---|
| 2256 | // 権限を指定 |
---|
| 2257 | if($permission != "") { |
---|
| 2258 | chmod($path, $permission); |
---|
| 2259 | } |
---|
| 2260 | |
---|
| 2261 | return true; |
---|
| 2262 | } |
---|
| 2263 | |
---|
| 2264 | function sfFlush($output = " ", $sleep = 0){ |
---|
| 2265 | // 実行時間を制限しない |
---|
| 2266 | set_time_limit(0); |
---|
| 2267 | // 出力をバッファリングしない(==日本語自動変換もしない) |
---|
| 2268 | ob_end_clean(); |
---|
| 2269 | |
---|
| 2270 | // IEのために256バイト空文字出力 |
---|
| 2271 | echo str_pad('',256); |
---|
| 2272 | |
---|
| 2273 | // 出力はブランクだけでもいいと思う |
---|
| 2274 | echo $output; |
---|
| 2275 | // 出力をフラッシュする |
---|
| 2276 | flush(); |
---|
| 2277 | |
---|
| 2278 | ob_end_flush(); |
---|
| 2279 | ob_start(); |
---|
| 2280 | |
---|
| 2281 | // 時間のかかる処理 |
---|
| 2282 | sleep($sleep); |
---|
| 2283 | } |
---|
| 2284 | |
---|
| 2285 | // @versionの記載があるファイルからバージョンを取得する。 |
---|
| 2286 | function sfGetFileVersion($path) { |
---|
| 2287 | if(file_exists($path)) { |
---|
| 2288 | $src_fp = fopen($path, "rb"); |
---|
| 2289 | if($src_fp) { |
---|
| 2290 | while (!feof($src_fp)) { |
---|
| 2291 | $line = fgets($src_fp); |
---|
| 2292 | if(ereg("@version", $line)) { |
---|
| 2293 | $arrLine = split(" ", $line); |
---|
| 2294 | $version = $arrLine[5]; |
---|
| 2295 | } |
---|
| 2296 | } |
---|
| 2297 | fclose($src_fp); |
---|
| 2298 | } |
---|
| 2299 | } |
---|
| 2300 | return $version; |
---|
| 2301 | } |
---|
| 2302 | |
---|
| 2303 | // 指定したURLに対してPOSTでデータを送信する |
---|
| 2304 | function sfSendPostData($url, $arrData, $arrOkCode = array()){ |
---|
| 2305 | require_once(DATA_PATH . "module/Request.php"); |
---|
| 2306 | |
---|
| 2307 | // 送信インスタンス生成 |
---|
| 2308 | $req = new HTTP_Request($url); |
---|
| 2309 | |
---|
| 2310 | $req->addHeader('User-Agent', 'DoCoMo/2.0 P2101V(c100)'); |
---|
| 2311 | $req->setMethod(HTTP_REQUEST_METHOD_POST); |
---|
| 2312 | |
---|
| 2313 | // POSTデータ送信 |
---|
| 2314 | $req->addPostDataArray($arrData); |
---|
| 2315 | |
---|
| 2316 | // エラーが無ければ、応答情報を取得する |
---|
| 2317 | if (!PEAR::isError($req->sendRequest())) { |
---|
| 2318 | |
---|
| 2319 | // レスポンスコードがエラー判定なら、空を返す |
---|
| 2320 | $res_code = $req->getResponseCode(); |
---|
| 2321 | |
---|
| 2322 | if(!in_array($res_code, $arrOkCode)){ |
---|
| 2323 | $response = ""; |
---|
| 2324 | }else{ |
---|
| 2325 | $response = $req->getResponseBody(); |
---|
| 2326 | } |
---|
| 2327 | |
---|
| 2328 | } else { |
---|
| 2329 | $response = ""; |
---|
| 2330 | } |
---|
| 2331 | |
---|
| 2332 | // POSTデータクリア |
---|
| 2333 | $req->clearPostData(); |
---|
| 2334 | |
---|
| 2335 | return $response; |
---|
| 2336 | } |
---|
| 2337 | |
---|
| 2338 | /** |
---|
| 2339 | * $array の要素を $arrConvList で指定した方式で mb_convert_kana を適用する. |
---|
| 2340 | * |
---|
| 2341 | * @param array $array 変換する文字列の配列 |
---|
| 2342 | * @param array $arrConvList mb_convert_kana の適用ルール |
---|
| 2343 | * @return array 変換後の配列 |
---|
| 2344 | * @see mb_convert_kana |
---|
| 2345 | */ |
---|
| 2346 | function mbConvertKanaWithArray($array, $arrConvList) { |
---|
| 2347 | foreach ($arrConvList as $key => $val) { |
---|
| 2348 | if(isset($array[$key])) { |
---|
| 2349 | $array[$key] = mb_convert_kana($array[$key] ,$val); |
---|
| 2350 | } |
---|
| 2351 | } |
---|
| 2352 | return $array; |
---|
| 2353 | } |
---|
| 2354 | |
---|
| 2355 | /* デバッグ用 ------------------------------------------------------------------------------------------------*/ |
---|
| 2356 | function sfPrintR($obj) { |
---|
| 2357 | print("<div style='font-size: 12px;color: #00FF00;'>\n"); |
---|
| 2358 | print("<strong>**デバッグ中**</strong><br />\n"); |
---|
| 2359 | print("<pre>\n"); |
---|
| 2360 | print_r($obj); |
---|
| 2361 | print("</pre>\n"); |
---|
| 2362 | print("<strong>**デバッグ中**</strong></div>\n"); |
---|
| 2363 | } |
---|
| 2364 | } |
---|
| 2365 | ?> |
---|