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

Revision 15474, 70.7 KB checked in by nanasess, 17 years ago (diff)

XXX コメント追加

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