Warning: Can't use blame annotator:
svn blame failed on branches/feature-module-update/data/class/util/SC_Utils.php: バイナリファイル 'file:///home/svn/open/branches/feature-module-update/data/class/util/SC_Utils.php' に対しては blame で各行の最終変更者を計算できません 195004

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

Revision 15473, 70.6 KB checked in by nanasess, 17 years ago (diff)

クラス化に伴う修正.
svn:mime-type 変更

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