source: branches/feature-module-update/data/class/util/SC_Utils.php @ 15538

Revision 15538, 70.9 KB checked in by nanasess, 17 years ago (diff)

未定義変数の修正

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