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