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

Revision 15520, 70.8 KB checked in by nanasess, 17 years ago (diff)

エラー表示の Bugfix

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