source: branches/feature-module-paygent/data/lib/slib.php @ 15120

Revision 15120, 79.6 KB checked in by adati, 17 years ago (diff)

1.4.2betaのマージ

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$INC_PATH = realpath( dirname( __FILE__) );
10require_once( $INC_PATH ."/../conf/conf.php" );
11require_once( $INC_PATH ."/../class/SC_DbConn.php" );
12require_once( $INC_PATH ."/../class/SC_Query.php" );
13require_once( $INC_PATH ."/../class/SC_CampaignSession.php" );
14require_once( $INC_PATH ."/../include/session.inc" );
15
16// Á´¥Ú¡¼¥¸¶¦ÄÌ¥¨¥é¡¼
17$GLOBAL_ERR = "";
18// ¥¤¥ó¥¹¥È¡¼¥ë½é´ü½èÍý
19sfInitInstall();
20
21/* ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ð¡¼¥¸¥ç¥ó½êÆÀ */
22function sfGetDBVersion($dsn = "") {
23    if($dsn == "") {
24        if(defined('DEFAULT_DSN')) {
25            $dsn = DEFAULT_DSN;
26        } else {
27            return;
28        }
29    }
30   
31    $objQuery = new SC_Query($dsn, true, true);
32    list($db_type) = split(":", $dsn);
33    if($db_type == 'mysql') {
34        $val = $objQuery->getOne("select version()");
35        $version = "MySQL " . $val;
36    }   
37    if($db_type == 'pgsql') {
38        $val = $objQuery->getOne("select version()");
39        $arrLine = split(" " , $val);
40        $version = $arrLine[0] . " " . $arrLine[1];
41    }
42    return $version;
43}
44
45/* ¥Æ¡¼¥Ö¥ë¤Î¸ºß¥Á¥§¥Ã¥¯ */
46function sfTabaleExists($table_name, $dsn = "") {
47    if($dsn == "") {
48        if(defined('DEFAULT_DSN')) {
49            $dsn = DEFAULT_DSN;
50        } else {
51            return;
52        }
53    }
54   
55    $objQuery = new SC_Query($dsn, true, true);
56    // Àµ¾ï¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç
57    if(!$objQuery->isError()) {
58        list($db_type) = split(":", $dsn);
59        // postgresql¤Èmysql¤È¤Ç½èÍý¤òʬ¤±¤ë
60        if ($db_type == "pgsql") {
61            $sql = "SELECT
62                        relname
63                    FROM
64                        pg_class
65                    WHERE
66                        (relkind = 'r' OR relkind = 'v') AND
67                        relname = ?
68                    GROUP BY
69                        relname";
70            $arrRet = $objQuery->getAll($sql, array($table_name));
71            if(count($arrRet) > 0) {
72                return true;
73            }
74        }else if ($db_type == "mysql") {
75            $sql = "SHOW TABLE STATUS LIKE ?";
76            $arrRet = $objQuery->getAll($sql, array($table_name));
77            if(count($arrRet) > 0) {
78                return true;
79            }
80        }
81    }
82    return false;
83}
84
85// ¥«¥é¥à¤Î¸ºß¥Á¥§¥Ã¥¯¤ÈºîÀ®
86function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) {
87    if($dsn == "") {
88        if(defined('DEFAULT_DSN')) {
89            $dsn = DEFAULT_DSN;
90        } else {
91            return;
92        }
93    }
94
95    // ¥Æ¡¼¥Ö¥ë¤¬Ìµ¤±¤ì¤Ð¥¨¥é¡¼
96    if(!sfTabaleExists($table_name, $dsn)) return false;
97   
98    $objQuery = new SC_Query($dsn, true, true);
99    // Àµ¾ï¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç
100    if(!$objQuery->isError()) {
101        list($db_type) = split(":", $dsn);
102       
103        // ¥«¥é¥à¥ê¥¹¥È¤ò¼èÆÀ
104        $arrRet = sfGetColumnList($table_name, $objQuery, $db_type);
105        if(count($arrRet) > 0) {
106            if(in_array($col_name, $arrRet)){
107                return true;
108            }
109        }
110    }
111   
112    // ¥«¥é¥à¤òÄɲ乤ë
113    if($add){
114        $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type ");
115        return true;
116    }
117   
118    return false;
119}
120
121// ¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î¸ºß¥Á¥§¥Ã¥¯¤ÈºîÀ®
122function sfIndexExists($table_name, $col_name, $index_name, $length = "", $dsn = "", $add = false) {
123    if($dsn == "") {
124        if(defined('DEFAULT_DSN')) {
125            $dsn = DEFAULT_DSN;
126        } else {
127            return;
128        }
129    }
130
131    // ¥Æ¡¼¥Ö¥ë¤¬Ìµ¤±¤ì¤Ð¥¨¥é¡¼
132    if(!sfTabaleExists($table_name, $dsn)) return false;
133   
134    $objQuery = new SC_Query($dsn, true, true);
135    // Àµ¾ï¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç
136    if(!$objQuery->isError()) {
137        list($db_type) = split(":", $dsn);     
138        switch($db_type) {
139        case 'pgsql':
140            // ¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î¸ºß³Îǧ
141            $arrRet = $objQuery->getAll("SELECT relname FROM pg_class WHERE relname = ?", array($index_name));
142            break;
143        case 'mysql':
144            // ¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î¸ºß³Îǧ
145            $arrRet = $objQuery->getAll("SHOW INDEX FROM ? WHERE Key_name = ?", array($table_name, $index_name));           
146            break;
147        default:
148            return false;
149        }
150        // ¤¹¤Ç¤Ë¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬Â¸ºß¤¹¤ë¾ì¹ç
151        if(count($arrRet) > 0) {
152            return true;
153        }
154    }
155   
156    // ¥¤¥ó¥Ç¥Ã¥¯¥¹¤òºîÀ®¤¹¤ë
157    if($add){
158        switch($db_type) {
159        case 'pgsql':
160            $objQuery->query("CREATE INDEX ? ON ? (?)", array($index_name, $table_name, $col_name));
161            break;
162        case 'mysql':
163            $objQuery->query("CREATE INDEX ? ON ? (?(?))", array($index_name, $table_name, $col_name, $length));           
164            break;
165        default:
166            return false;
167        }
168        return true;
169    }   
170    return false;
171}
172
173// ¥Ç¡¼¥¿¤Î¸ºß¥Á¥§¥Ã¥¯
174function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) {
175    if($dsn == "") {
176        if(defined('DEFAULT_DSN')) {
177            $dsn = DEFAULT_DSN;
178        } else {
179            return;
180        }
181    }
182    $objQuery = new SC_Query($dsn, true, true);
183    $count = $objQuery->count($table_name, $where, $arrval);
184
185    if($count > 0) {
186        $ret = true;
187    } else {
188        $ret = false;
189    }
190    // ¥Ç¡¼¥¿¤òÄɲ乤ë
191    if(!$ret && $add) {
192        $objQuery->exec($sql);
193    }
194   
195    return $ret;
196}
197
198/*
199 * ¥µ¥¤¥È´ÉÍý¾ðÊ󤫤éÃͤò¼èÆÀ¤¹¤ë¡£
200 * ¥Ç¡¼¥¿¤¬Â¸ºß¤¹¤ë¾ì¹ç¡¢É¬¤º1°Ê¾å¤Î¿ôÃͤ¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¡£
201 * 0¤òÊÖ¤·¤¿¾ì¹ç¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤ÇÂбþ¤¹¤ë¤³¤È¡£
202 *
203 * @param $control_id ´ÉÍýID
204 * @param $dsn DataSource
205 * @return $control_flg ¥Õ¥é¥°
206 */
207function sfGetSiteControlFlg($control_id, $dsn = "") {
208
209    // ¥Ç¡¼¥¿¥½¡¼¥¹
210    if($dsn == "") {
211        if(defined('DEFAULT_DSN')) {
212            $dsn = DEFAULT_DSN;
213        } else {
214            return;
215        }
216    }
217
218    // ¥¯¥¨¥êÀ¸À®
219    $target_column = "control_flg";
220    $table_name = "dtb_site_control";
221    $where = "control_id = ?";
222    $arrval = array($control_id);
223    $control_flg = 0;
224
225    // ¥¯¥¨¥êȯ¹Ô
226    $objQuery = new SC_Query($dsn, true, true);
227    $arrSiteControl = $objQuery->select($target_column, $table_name, $where, $arrval);
228
229    // ¥Ç¡¼¥¿¤¬Â¸ºß¤¹¤ì¤Ð¥Õ¥é¥°¤ò¼èÆÀ¤¹¤ë
230    if (count($arrSiteControl) > 0) {
231        $control_flg = $arrSiteControl[0]["control_flg"];
232    }
233   
234    return $control_flg;
235}
236
237// ¥Æ¡¼¥Ö¥ë¤Î¥«¥é¥à°ìÍ÷¤ò¼èÆÀ¤¹¤ë
238function sfGetColumnList($table_name, $objQuery = "", $db_type = DB_TYPE){
239    if($objQuery == "") $objQuery = new SC_Query();
240    $arrRet = array();
241   
242    // postgresql¤Èmysql¤È¤Ç½èÍý¤òʬ¤±¤ë
243    if ($db_type == "pgsql") {
244        $sql = "SELECT a.attname FROM pg_class c, pg_attribute a WHERE c.relname=? AND c.oid=a.attrelid AND a.attnum > 0 AND not a.attname like '........pg.dropped.%........' ORDER BY a.attnum";
245        $arrColList = $objQuery->getAll($sql, array($table_name));
246        $arrColList = sfswaparray($arrColList);
247        $arrRet = $arrColList["attname"];
248    }else if ($db_type == "mysql") {
249        $sql = "SHOW COLUMNS FROM $table_name";
250        $arrColList = $objQuery->getAll($sql);
251        $arrColList = sfswaparray($arrColList);
252        $arrRet = $arrColList["Field"];
253    }
254    return $arrRet;
255}
256
257// ¥¤¥ó¥¹¥È¡¼¥ë½é´ü½èÍý
258function sfInitInstall() {
259    // ¥¤¥ó¥¹¥È¡¼¥ëºÑ¤ß¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
260    if(!defined('ECCUBE_INSTALL')) {
261        if(!ereg("/install/", $_SERVER['PHP_SELF'])) {
262            header("Location: ./install/");
263        }
264    } else {
265        $path = HTML_PATH . "install/index.php";
266        if(file_exists($path)) {
267            sfErrorHeader(">> /install/index.php¤Ï¡¢¥¤¥ó¥¹¥È¡¼¥ë´°Î»¸å¤Ë¥Õ¥¡¥¤¥ë¤òºï½ü¤·¤Æ¤¯¤À¤µ¤¤¡£");
268        }
269       
270        // µì¥Ð¡¼¥¸¥ç¥ó¤Îinstall.php¤Î¥Á¥§¥Ã¥¯
271        $path = HTML_PATH . "install.php";
272        if(file_exists($path)) {
273            sfErrorHeader(">> /install.php¤Ï¥»¥­¥å¥ê¥Æ¥£¡¼¥Û¡¼¥ë¤È¤Ê¤ê¤Þ¤¹¡£ºï½ü¤·¤Æ¤¯¤À¤µ¤¤¡£");
274        }       
275    }
276}
277
278// ¥¢¥Ã¥×¥Ç¡¼¥È¤ÇÀ¸À®¤µ¤ì¤¿PHP¤òÆɤ߽Ф·
279function sfLoadUpdateModule() {
280    // URLÀßÄê¥Ç¥£¥ì¥¯¥È¥ê¤òºï½ü
281    $main_php = ereg_replace(URL_DIR, "", $_SERVER['PHP_SELF']);
282    $extern_php = UPDATE_PATH . $main_php;
283    if(file_exists($extern_php)) {
284        require_once($extern_php);
285    }
286}
287
288function sf_getBasisData() {
289    //DB¤«¤éÀßÄê¾ðÊó¤ò¼èÆÀ
290    $objConn = new SC_DbConn(DEFAULT_DSN);
291    $result = $objConn->getAll("SELECT * FROM dtb_baseinfo");
292    if(is_array($result[0])) {
293        foreach ( $result[0] as $key=>$value ){
294            $CONF["$key"] = $value;
295        }
296    }
297    return $CONF;
298}
299
300// Áõ¾þÉÕ¤­¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤Îɽ¼¨
301function sfErrorHeader($mess, $print = false) {
302    global $GLOBAL_ERR;
303    if($GLOBAL_ERR == "") {
304        $GLOBAL_ERR = "<meta http-equiv='Content-Type' content='text/html; charset=" . CHAR_CODE . "'>\n";
305    }
306    $GLOBAL_ERR.= "<table width='100%' border='0' cellspacing='0' cellpadding='0' summary=' '>\n";
307    $GLOBAL_ERR.= "<tr>\n";
308    $GLOBAL_ERR.= "<td bgcolor='#ffeebb' height='25' colspan='2' align='center'>\n";
309    $GLOBAL_ERR.= "<SPAN style='color:red; font-size:12px'><strong>" . $mess . "</strong></span>\n";
310    $GLOBAL_ERR.= "</td>\n";
311    $GLOBAL_ERR.= " </tr>\n";
312    $GLOBAL_ERR.= "</table>\n";
313   
314    if($print) {
315        print($GLOBAL_ERR);
316    }
317}
318
319/* ¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨ */
320function sfDispError($type) {
321   
322    class LC_ErrorPage {
323        function LC_ErrorPage() {
324            $this->tpl_mainpage = 'login_error.tpl';
325            $this->tpl_title = '¥¨¥é¡¼';
326        }
327    }
328
329    $objPage = new LC_ErrorPage();
330    $objView = new SC_AdminView();
331   
332    switch ($type) {
333        case LOGIN_ERROR:
334            $objPage->tpl_error="£É£Ä¤Þ¤¿¤Ï¥Ñ¥¹¥ï¡¼¥É¤¬Àµ¤·¤¯¤¢¤ê¤Þ¤»¤ó¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£";
335            break;
336        case ACCESS_ERROR:
337            $objPage->tpl_error="¥í¥°¥¤¥óǧ¾Ú¤ÎÍ­¸ú´ü¸ÂÀÚ¤ì¤Î²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙ¥í¥°¥¤¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£";
338            break;
339        case AUTH_ERROR:
340            $objPage->tpl_error="¤³¤Î¥Õ¥¡¥¤¥ë¤Ë¤Ï¥¢¥¯¥»¥¹¸¢¸Â¤¬¤¢¤ê¤Þ¤»¤ó¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙ¥í¥°¥¤¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£";
341            break;
342        case INVALID_MOVE_ERRORR:
343            $objPage->tpl_error="ÉÔÀµ¤Ê¥Ú¡¼¥¸°ÜÆ°¤Ç¤¹¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£";
344            break;
345        default:
346            $objPage->tpl_error="¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙ¥í¥°¥¤¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£";
347            break;
348    }
349   
350    $objView->assignobj($objPage);
351    $objView->display(LOGIN_FRAME);
352   
353    exit;
354}
355
356/* ¥µ¥¤¥È¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨ */
357function sfDispSiteError($type, $objSiteSess = "", $return_top = false, $err_msg = "", $is_mobile = false) {
358    global $objCampaignSess;
359   
360    if ($objSiteSess != "") {
361        $objSiteSess->setNowPage('error');
362    }
363   
364    class LC_ErrorPage {
365        function LC_ErrorPage() {
366            $this->tpl_mainpage = 'error.tpl';
367            $this->tpl_css = URL_DIR.'css/layout/error.css';
368            $this->tpl_title = '¥¨¥é¡¼';
369        }
370    }
371   
372    $objPage = new LC_ErrorPage();
373   
374    if($is_mobile === true) {
375        $objView = new SC_MobileView();     
376    } else {
377        $objView = new SC_SiteView();
378    }
379   
380    switch ($type) {
381        case PRODUCT_NOT_FOUND:
382            $objPage->tpl_error="¤´»ØÄê¤Î¥Ú¡¼¥¸¤Ï¤´¤¶¤¤¤Þ¤»¤ó¡£";
383            break;
384        case PAGE_ERROR:
385            $objPage->tpl_error="ÉÔÀµ¤Ê¥Ú¡¼¥¸°ÜÆ°¤Ç¤¹¡£";
386            break;
387        case CART_EMPTY:
388            $objPage->tpl_error="¥«¡¼¥È¤Ë¾¦Éʤ¬¤¬¤¢¤ê¤Þ¤»¤ó¡£";
389            break;
390        case CART_ADD_ERROR:
391            $objPage->tpl_error="¹ØÆþ½èÍýÃæ¤Ï¡¢¥«¡¼¥È¤Ë¾¦ÉʤòÄɲ乤뤳¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£";
392            break;
393        case CANCEL_PURCHASE:
394            $objPage->tpl_error="¤³¤Î¼ê³¤­¤Ï̵¸ú¤È¤Ê¤ê¤Þ¤·¤¿¡£°Ê²¼¤ÎÍ×°ø¤¬¹Í¤¨¤é¤ì¤Þ¤¹¡£<br />¡¦¥»¥Ã¥·¥ç¥ó¾ðÊó¤ÎÍ­¸ú´ü¸Â¤¬ÀÚ¤ì¤Æ¤ë¾ì¹ç<br />¡¦¹ØÆþ¼ê³¤­Ãæ¤Ë¿·¤·¤¤¹ØÆþ¼ê³¤­¤ò¼Â¹Ô¤·¤¿¾ì¹ç<br />¡¦¤¹¤Ç¤Ë¹ØÆþ¼ê³¤­¤ò´°Î»¤·¤Æ¤¤¤ë¾ì¹ç";
395            break;
396        case CATEGORY_NOT_FOUND:
397            $objPage->tpl_error="¤´»ØÄê¤Î¥«¥Æ¥´¥ê¤Ï¸ºß¤·¤Þ¤»¤ó¡£";
398            break;
399        case SITE_LOGIN_ERROR:
400            $objPage->tpl_error="¥á¡¼¥ë¥¢¥É¥ì¥¹¤â¤·¤¯¤Ï¥Ñ¥¹¥ï¡¼¥É¤¬Àµ¤·¤¯¤¢¤ê¤Þ¤»¤ó¡£";
401            break;
402        case TEMP_LOGIN_ERROR:
403            $objPage->tpl_error="¥á¡¼¥ë¥¢¥É¥ì¥¹¤â¤·¤¯¤Ï¥Ñ¥¹¥ï¡¼¥É¤¬Àµ¤·¤¯¤¢¤ê¤Þ¤»¤ó¡£<br />ËÜÅÐÏ¿¤¬¤ªºÑ¤ß¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢²¾ÅÐÏ¿¥á¡¼¥ë¤Ëµ­ºÜ¤µ¤ì¤Æ¤¤¤ë<br />URL¤è¤êËÜÅÐÏ¿¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤¡£";
404            break;
405        case CUSTOMER_ERROR:
406            $objPage->tpl_error="ÉÔÀµ¤Ê¥¢¥¯¥»¥¹¤Ç¤¹¡£";
407            break;
408        case SOLD_OUT:
409            $objPage->tpl_error="¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤´¹ØÆþ¤ÎľÁ°¤ÇÇä¤êÀڤ줿¾¦Éʤ¬¤¢¤ê¤Þ¤¹¡£¤³¤Î¼ê³¤­¤Ï̵¸ú¤È¤Ê¤ê¤Þ¤·¤¿¡£";
410            break;
411        case CART_NOT_FOUND:
412            $objPage->tpl_error="¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¥«¡¼¥ÈÆâ¤Î¾¦ÉʾðÊó¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£¤³¤Î¼ê³¤­¤Ï̵¸ú¤È¤Ê¤ê¤Þ¤·¤¿¡£";
413            break;
414        case LACK_POINT:
415            $objPage->tpl_error="¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¥Ý¥¤¥ó¥È¤¬ÉÔ­¤·¤Æ¤ª¤ê¤Þ¤¹¡£¤³¤Î¼ê³¤­¤Ï̵¸ú¤È¤Ê¤ê¤Þ¤·¤¿¡£";
416            break;
417        case FAVORITE_ERROR:
418            $objPage->tpl_error="´û¤Ë¤ªµ¤¤ËÆþ¤ê¤ËÄɲ䵤ì¤Æ¤¤¤ë¾¦ÉʤǤ¹¡£";
419            break;
420        case EXTRACT_ERROR:
421            $objPage->tpl_error="¥Õ¥¡¥¤¥ë¤Î²òÅà¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\n»ØÄê¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë½ñ¤­¹þ¤ß¸¢¸Â¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Ê¤¤²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£";
422            break;
423        case FTP_DOWNLOAD_ERROR:
424            $objPage->tpl_error="¥Õ¥¡¥¤¥ë¤ÎFTP¥À¥¦¥ó¥í¡¼¥É¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£";
425            break;
426        case FTP_LOGIN_ERROR:
427            $objPage->tpl_error="FTP¥í¥°¥¤¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£";
428            break;
429        case FTP_CONNECT_ERROR:
430            $objPage->tpl_error="FTP¥í¥°¥¤¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£";
431            break;
432        case CREATE_DB_ERROR:
433            $objPage->tpl_error="DB¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\n»ØÄê¤Î¥æ¡¼¥¶¡¼¤Ë¤Ï¡¢DBºîÀ®¤Î¸¢¸Â¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Ê¤¤²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£";
434            break;
435        case DB_IMPORT_ERROR:
436            $objPage->tpl_error="¥Ç¡¼¥¿¥Ù¡¼¥¹¹½Â¤¤Î¥¤¥ó¥Ý¡¼¥È¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\nsql¥Õ¥¡¥¤¥ë¤¬²õ¤ì¤Æ¤¤¤ë²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£";
437            break;
438        case FILE_NOT_FOUND:
439            $objPage->tpl_error="»ØÄê¤Î¥Ñ¥¹¤Ë¡¢ÀßÄê¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤»¤ó¡£";
440            break;
441        case WRITE_FILE_ERROR:
442            $objPage->tpl_error="ÀßÄê¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤á¤Þ¤»¤ó¡£\nÀßÄê¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤ß¸¢¸Â¤òÍ¿¤¨¤Æ¤¯¤À¤µ¤¤¡£";
443            break;
444        case FREE_ERROR_MSG:
445            $objPage->tpl_error=$err_msg;
446            break;
447        default:
448            $objPage->tpl_error="¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿¡£";
449            break;
450    }
451   
452    $objPage->return_top = $return_top;
453   
454    $objView->assignobj($objPage);
455   
456    if(is_object($objCampaignSess)) {
457        // ¥Õ¥ì¡¼¥à¤òÁªÂò(¥­¥ã¥ó¥Ú¡¼¥ó¥Ú¡¼¥¸¤«¤éÁ«°Ü¤Ê¤éÊѹ¹)
458        $objCampaignSess->pageView($objView);
459    } else {
460        $objView->display(SITE_FRAME);
461    }   
462    exit;
463}
464
465/* ǧ¾Ú¤Î²ÄÈÝȽÄê */
466function sfIsSuccess($objSess, $disp_error = true) {
467    $ret = $objSess->IsSuccess();
468    if($ret != SUCCESS) {
469        if($disp_error) {
470            // ¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨
471            sfDispError($ret);
472        }
473        return false;
474    }
475    // ¥ê¥Õ¥¡¥é¡¼¥Á¥§¥Ã¥¯(CSRF¤Î»ÃÄêŪ¤ÊÂкö)
476    // ¡Ö¥ê¥Õ¥¡¥é̵¡× ¤Î¾ì¹ç¤Ï¥¹¥ë¡¼
477    // ¡Ö¥ê¥Õ¥¡¥éÍ­¡× ¤«¤Ä ¡Ö´ÉÍý²èÌ̤«¤é¤ÎÁ«°Ü¤Ç¤Ê¤¤¡× ¾ì¹ç¤Ë¥¨¥é¡¼²èÌ̤òɽ¼¨¤¹¤ë
478    if ( empty($_SERVER['HTTP_REFERER']) ) {
479        // ·Ù¹ðɽ¼¨¤µ¤»¤ë¡©
480        // sfErrorHeader('>> referrer¤¬Ìµ¸ú¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£');
481    } else {
482        $domain  = sfIsHTTPS() ? SSL_URL : SITE_URL;
483        $pattern = sprintf('|^%s.*|', $domain);
484        $referer = $_SERVER['HTTP_REFERER'];
485
486        // ´ÉÍý²èÌ̤«¤é°Ê³°¤ÎÁ«°Ü¤Î¾ì¹ç¤Ï¥¨¥é¡¼²èÌ̤òɽ¼¨
487        if (!preg_match($pattern, $referer)) {
488            if ($disp_error) sfDispError(INVALID_MOVE_ERRORR);
489            return false;
490        }
491    }
492    return true;
493}
494
495/**
496 * HTTPS¤«¤É¤¦¤«¤òȽÄê
497 *
498 * @return bool
499 */
500function sfIsHTTPS () {
501    // HTTPS»þ¤Ë¤Ï$_SERVER['HTTPS']¤Ë¤Ï¶õ¤Ç¤Ê¤¤Ãͤ¬Æþ¤ë
502    // $_SERVER['HTTPS'] != 'off' ¤ÏIISÍÑ
503    if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
504        return true;
505    } else {
506        return false;
507    }
508}
509
510/**
511 *  Àµµ¬¤ÎÁ«°Ü¤¬¤µ¤ì¤Æ¤¤¤ë¤«¤òȽÄê
512 *  Á°²èÌ̤Çuniqid¤òËä¤á¹þ¤ó¤Ç¤ª¤¯É¬Íפ¬¤¢¤ë
513 *  @param  obj  SC_Session, SC_SiteSession
514 *  @return bool
515 */
516function sfIsValidTransition($objSess) {
517    // Á°²èÌ̤«¤éPOST¤µ¤ì¤ëuniqid¤¬Àµ¤·¤¤¤â¤Î¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯
518    $uniqid = $objSess->getUniqId();
519    if ( !empty($_POST['uniqid']) && ($_POST['uniqid'] === $uniqid) ) {
520        return true;
521    } else {
522        return false;
523    }
524}
525
526/* Á°¤Î¥Ú¡¼¥¸¤ÇÀµ¤·¤¯ÅÐÏ¿¤¬¹Ô¤ï¤ì¤¿¤«È½Äê */
527function sfIsPrePage($objSiteSess, $is_mobile = false) {
528    $ret = $objSiteSess->isPrePage();
529    if($ret != true) {
530        // ¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨
531        sfDispSiteError(PAGE_ERROR, $objSiteSess, false, "", $is_mobile);           
532    }
533}
534
535function sfCheckNormalAccess($objSiteSess, $objCartSess) {
536    // ¥æ¡¼¥¶¥æ¥Ë¡¼¥¯ID¤Î¼èÆÀ
537    $uniqid = $objSiteSess->getUniqId();
538    // ¹ØÆþ¥Ü¥¿¥ó¤ò²¡¤·¤¿»þ¤Î¥«¡¼¥ÈÆâÍƤ¬¥³¥Ô¡¼¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Î¤ß¥³¥Ô¡¼¤¹¤ë¡£
539    $objCartSess->saveCurrentCart($uniqid);
540    // POST¤Î¥æ¥Ë¡¼¥¯ID¤È¥»¥Ã¥·¥ç¥ó¤Î¥æ¥Ë¡¼¥¯ID¤òÈæ³Ó(¥æ¥Ë¡¼¥¯ID¤¬POST¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¥¹¥ë¡¼)
541    $ret = $objSiteSess->checkUniqId();
542    if($ret != true) {
543        // ¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨
544        sfDispSiteError(CANCEL_PURCHASE, $objSiteSess);
545    }
546   
547    // ¥«¡¼¥ÈÆ⤬¶õ¤Ç¤Ê¤¤¤« || ¹ØÆþ¥Ü¥¿¥ó¤ò²¡¤·¤Æ¤«¤éÊѲ½¤¬¤Ê¤¤¤«
548    $quantity = $objCartSess->getTotalQuantity();
549    $ret = $objCartSess->checkChangeCart();
550    if($ret == true || !($quantity > 0)) {
551        // ¥«¡¼¥È¾ðÊóɽ¼¨¤Ë¶¯À©°ÜÆ°¤¹¤ë
552        header("Location: ".URL_CART_TOP);
553        exit;
554    }
555    return $uniqid;
556}
557
558/* DBÍÑÆüÉÕʸ»úÎó¼èÆÀ */
559function sfGetTimestamp($year, $month, $day, $last = false) {
560    if($year != "" && $month != "" && $day != "") {
561        if($last) {
562            $time = "23:59:59";
563        } else {
564            $time = "00:00:00";
565        }
566        $date = $year."-".$month."-".$day." ".$time;
567    } else {
568        $date = "";
569    }
570    return  $date;
571}
572
573// INT·¿¤Î¿ôÃÍ¥Á¥§¥Ã¥¯
574function sfIsInt($value) {
575    if($value != "" && strlen($value) <= INT_LEN && is_numeric($value)) {
576        return true;
577    }
578    return false;
579}
580
581function sfCSVDownload($data, $prefix = ""){
582   
583    if($prefix == "") {
584        $dir_name = sfUpDirName();
585        $file_name = $dir_name . date("ymdHis") .".csv";
586    } else {
587        $file_name = $prefix . date("ymdHis") .".csv";
588    }
589   
590    /* HTTP¥Ø¥Ã¥À¤Î½ÐÎÏ */
591    Header("Content-disposition: attachment; filename=${file_name}");
592    Header("Content-type: application/octet-stream; name=${file_name}");
593    Header("Cache-Control: ");
594    Header("Pragma: ");
595   
596    /* i18n¢· ¤À¤ÈÀµ¾ï¤ËÆ°ºî¤·¤Ê¤¤¤¿¤á¡¢mb¢· ¤ËÊѹ¹
597    if (i18n_discover_encoding($data) == CHAR_CODE){
598        $data = i18n_convert($data,'SJIS',CHAR_CODE);
599    }
600    */
601    if (mb_internal_encoding() == CHAR_CODE){
602        $data = mb_convert_encoding($data,'SJIS',CHAR_CODE);
603    }
604   
605    /* ¥Ç¡¼¥¿¤ò½ÐÎÏ */
606    echo $data;
607}
608
609/* 1³¬Áؾå¤Î¥Ç¥£¥ì¥¯¥È¥ê̾¤ò¼èÆÀ¤¹¤ë */
610function sfUpDirName() {
611    $path = $_SERVER['PHP_SELF'];
612    $arrVal = split("/", $path);
613    $cnt = count($arrVal);
614    return $arrVal[($cnt - 2)];
615}
616
617// ¸½ºß¤Î¥µ¥¤¥È¤ò¹¹¿·¡Ê¤¿¤À¤·¥Ý¥¹¥È¤Ï¹Ô¤ï¤Ê¤¤¡Ë
618function sfReload($get = "") {
619    if ($_SERVER["SERVER_PORT"] == "443" ){
620        $url = ereg_replace(URL_DIR . "$", "", SSL_URL);
621    } else {
622        $url = ereg_replace(URL_DIR . "$", "", SITE_URL);
623    }
624   
625    if($get != "") {
626        header("Location: ". $url . $_SERVER['PHP_SELF'] . "?" . $get);
627    } else {
628        header("Location: ". $url . $_SERVER['PHP_SELF']);
629    }
630    exit;
631}
632
633// ¥é¥ó¥­¥ó¥°¤ò¾å¤²¤ë¡£
634function sfRankUp($table, $colname, $id, $andwhere = "") {
635    $objQuery = new SC_Query();
636    $objQuery->begin();
637    $where = "$colname = ?";
638    if($andwhere != "") {
639        $where.= " AND $andwhere";
640    }
641    // ÂоݹàÌܤΥé¥ó¥¯¤ò¼èÆÀ
642    $rank = $objQuery->get($table, "rank", $where, array($id));
643    // ¥é¥ó¥¯¤ÎºÇÂçÃͤò¼èÆÀ
644    $maxrank = $objQuery->max($table, "rank", $andwhere);
645    // ¥é¥ó¥¯¤¬ºÇÂçÃͤè¤ê¤â¾®¤µ¤¤¾ì¹ç¤Ë¼Â¹Ô¤¹¤ë¡£
646    if($rank < $maxrank) {
647        // ¥é¥ó¥¯¤¬°ì¤Ä¾å¤ÎID¤ò¼èÆÀ¤¹¤ë¡£
648        $where = "rank = ?";
649        if($andwhere != "") {
650            $where.= " AND $andwhere";
651        }
652        $uprank = $rank + 1;
653        $up_id = $objQuery->get($table, $colname, $where, array($uprank));
654        // ¥é¥ó¥¯Æþ¤ìÂؤ¨¤Î¼Â¹Ô
655        $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";
656        $objQuery->exec($sqlup, array($rank + 1, $id));
657        $objQuery->exec($sqlup, array($rank, $up_id));
658    }
659    $objQuery->commit();
660}
661
662// ¥é¥ó¥­¥ó¥°¤ò²¼¤²¤ë¡£
663function sfRankDown($table, $colname, $id, $andwhere = "") {
664    $objQuery = new SC_Query();
665    $objQuery->begin();
666    $where = "$colname = ?";
667    if($andwhere != "") {
668        $where.= " AND $andwhere";
669    }
670    // ÂоݹàÌܤΥé¥ó¥¯¤ò¼èÆÀ
671    $rank = $objQuery->get($table, "rank", $where, array($id));
672       
673    // ¥é¥ó¥¯¤¬1(ºÇ¾®ÃÍ)¤è¤ê¤âÂ礭¤¤¾ì¹ç¤Ë¼Â¹Ô¤¹¤ë¡£
674    if($rank > 1) {
675        // ¥é¥ó¥¯¤¬°ì¤Ä²¼¤ÎID¤ò¼èÆÀ¤¹¤ë¡£
676        $where = "rank = ?";
677        if($andwhere != "") {
678            $where.= " AND $andwhere";
679        }
680        $downrank = $rank - 1;
681        $down_id = $objQuery->get($table, $colname, $where, array($downrank));
682        // ¥é¥ó¥¯Æþ¤ìÂؤ¨¤Î¼Â¹Ô
683        $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";
684        $objQuery->exec($sqlup, array($rank - 1, $id));
685        $objQuery->exec($sqlup, array($rank, $down_id));
686    }
687    $objQuery->commit();
688}
689
690//----¡¡»ØÄê½ç°Ì¤Ø°ÜÆ°
691function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") {
692    $objQuery = new SC_Query();
693    $objQuery->begin();
694       
695    // ¼«¿È¤Î¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë
696    $rank = $objQuery->get($tableName, "rank", "$keyIdColumn = ?", array($keyId)); 
697    $max = $objQuery->max($tableName, "rank", $where);
698       
699    // ÃͤÎÄ´À°¡ÊµÕ½ç¡Ë
700    if($pos > $max) {
701        $position = 1;
702    } else if($pos < 1) {
703        $position = $max;
704    } else {
705        $position = $max - $pos + 1;
706    }
707   
708    if( $position > $rank ) $term = "rank - 1"; //Æþ¤ìÂؤ¨Àè¤Î½ç°Ì¤¬Æþ¤ì´¹¤¨¸µ¤Î½ç°Ì¤è¤êÂ礭¤¤¾ì¹ç
709    if( $position < $rank ) $term = "rank + 1"; //Æþ¤ìÂؤ¨Àè¤Î½ç°Ì¤¬Æþ¤ì´¹¤¨¸µ¤Î½ç°Ì¤è¤ê¾®¤µ¤¤¾ì¹ç
710
711    //--¡¡»ØÄꤷ¤¿½ç°Ì¤Î¾¦Éʤ«¤é°ÜÆ°¤µ¤»¤ë¾¦ÉʤޤǤÎrank¤ò£±¤Ä¤º¤é¤¹
712    $sql = "UPDATE $tableName SET rank = $term, update_date = NOW() WHERE rank BETWEEN ? AND ? AND del_flg = 0";
713    if($where != "") {
714        $sql.= " AND $where";
715    }
716   
717    if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position ));
718    if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 ));
719
720    //-- »ØÄꤷ¤¿½ç°Ì¤Ørank¤ò½ñ¤­´¹¤¨¤ë¡£
721    $sql  = "UPDATE $tableName SET rank = ?, update_date = NOW() WHERE $keyIdColumn = ? AND del_flg = 0 ";
722    if($where != "") {
723        $sql.= " AND $where";
724    }
725   
726    $objQuery->exec( $sql, array( $position, $keyId ) );
727    $objQuery->commit();
728}
729
730// ¥é¥ó¥¯¤ò´Þ¤à¥ì¥³¡¼¥É¤Îºï½ü
731// ¥ì¥³¡¼¥É¤´¤Èºï½ü¤¹¤ë¾ì¹ç¤Ï¡¢$delete¤òtrue¤Ë¤¹¤ë¡£
732function sfDeleteRankRecord($table, $colname, $id, $andwhere = "", $delete = false) {
733    $objQuery = new SC_Query();
734    $objQuery->begin();
735    // ºï½ü¥ì¥³¡¼¥É¤Î¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë¡£     
736    $where = "$colname = ?";
737    if($andwhere != "") {
738        $where.= " AND $andwhere";
739    }
740    $rank = $objQuery->get($table, "rank", $where, array($id));
741
742    if(!$delete) {
743        // ¥é¥ó¥¯¤òºÇ²¼°Ì¤Ë¤¹¤ë¡¢DEL¥Õ¥é¥°ON
744        $sqlup = "UPDATE $table SET rank = 0, del_flg = 1, update_date = Now() ";
745        $sqlup.= "WHERE $colname = ?";
746        // UPDATE¤Î¼Â¹Ô
747        $objQuery->exec($sqlup, array($id));
748    } else {
749        $objQuery->delete($table, "$colname = ?", array($id));
750    }
751   
752    // Äɲå쥳¡¼¥É¤Î¥é¥ó¥¯¤è¤ê¾å¤Î¥ì¥³¡¼¥É¤ò°ì¤Ä¤º¤é¤¹¡£
753    $where = "rank > ?";
754    if($andwhere != "") {
755        $where.= " AND $andwhere";
756    }
757    $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
758    $objQuery->exec($sqlup, array($rank));
759    $objQuery->commit();
760}
761
762// ¥ì¥³¡¼¥É¤Î¸ºß¥Á¥§¥Ã¥¯
763function sfIsRecord($table, $col, $arrval, $addwhere = "") {
764    $objQuery = new SC_Query();
765    $arrCol = split("[, ]", $col);
766       
767    $where = "del_flg = 0";
768   
769    if($addwhere != "") {
770        $where.= " AND $addwhere";
771    }
772       
773    foreach($arrCol as $val) {
774        if($val != "") {
775            if($where == "") {
776                $where = "$val = ?";
777            } else {
778                $where.= " AND $val = ?";
779            }
780        }
781    }
782    $ret = $objQuery->get($table, $col, $where, $arrval);
783   
784    if($ret != "") {
785        return true;
786    }
787    return false;
788}
789
790// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤ÎÃͤò¥Þ¡¼¥¸
791function sfMergeCBValue($keyname, $max) {
792    $conv = "";
793    $cnt = 1;
794    for($cnt = 1; $cnt <= $max; $cnt++) {
795        if ($_POST[$keyname . $cnt] == "1") {
796            $conv.= "1";
797        } else {
798            $conv.= "0";
799        }
800    }
801    return $conv;
802}
803
804// html_checkboxes¤ÎÃͤò¥Þ¡¼¥¸¤·¤Æ2¿Ê¿ô·Á¼°¤ËÊѹ¹¤¹¤ë¡£
805function sfMergeCheckBoxes($array, $max) {
806    $ret = "";
807    if(is_array($array)) { 
808        foreach($array as $val) {
809            $arrTmp[$val] = "1";
810        }
811    }
812    for($i = 1; $i <= $max; $i++) {
813        if($arrTmp[$i] == "1") {
814            $ret.= "1";
815        } else {
816            $ret.= "0";
817        }
818    }
819    return $ret;
820}
821
822
823// html_checkboxes¤ÎÃͤò¥Þ¡¼¥¸¤·¤Æ¡Ö-¡×¤Ç¤Ä¤Ê¤²¤ë¡£
824function sfMergeParamCheckBoxes($array) {
825    $ret = '';
826    if(is_array($array)) {
827        foreach($array as $val) {
828            if($ret != "") {
829                $ret.= "-$val";
830            } else {
831                $ret = $val;           
832            }
833        }
834    } else {
835        $ret = $array;
836    }
837    return $ret;
838}
839
840// html_checkboxes¤ÎÃͤò¥Þ¡¼¥¸¤·¤ÆSQL¸¡º÷ÍѤËÊѹ¹¤¹¤ë¡£
841function sfSearchCheckBoxes($array) {
842    $max = 0;
843    $ret = "";
844    foreach($array as $val) {
845        $arrTmp[$val] = "1";
846        if($val > $max) {
847            $max = $val;
848        }
849    }
850    for($i = 1; $i <= $max; $i++) {
851        if($arrTmp[$i] == "1") {
852            $ret.= "1";
853        } else {
854            $ret.= "_";
855        }
856    }
857   
858    if($ret != "") {   
859        $ret.= "%";
860    }
861    return $ret;
862}
863
864// 2¿Ê¿ô·Á¼°¤ÎÃͤòhtml_checkboxesÂбþ¤ÎÃͤËÀÚ¤êÂؤ¨¤ë
865function sfSplitCheckBoxes($val) {
866    $len = strlen($val);
867    for($i = 0; $i < $len; $i++) {
868        if(substr($val, $i, 1) == "1") {
869            $arrRet[] = ($i + 1);
870        }
871    }
872    return $arrRet;
873}
874
875// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤ÎÃͤò¥Þ¡¼¥¸
876function sfMergeCBSearchValue($keyname, $max) {
877    $conv = "";
878    $cnt = 1;
879    for($cnt = 1; $cnt <= $max; $cnt++) {
880        if ($_POST[$keyname . $cnt] == "1") {
881            $conv.= "1";
882        } else {
883            $conv.= "_";
884        }
885    }
886    return $conv;
887}
888
889// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤ÎÃͤòʬ²ò
890function sfSplitCBValue($val, $keyname = "") {
891    $len = strlen($val);
892    $no = 1;
893    for ($cnt = 0; $cnt < $len; $cnt++) {
894        if($keyname != "") {
895            $arr[$keyname . $no] = substr($val, $cnt, 1);
896        } else {
897            $arr[] = substr($val, $cnt, 1);
898        }
899        $no++;
900    }
901    return $arr;
902}
903
904// ¥­¡¼¤ÈÃͤò¥»¥Ã¥È¤·¤¿ÇÛÎó¤ò¼èÆÀ
905function sfArrKeyValue($arrList, $keyname, $valname, $len_max = "", $keysize = "") {
906   
907    $max = count($arrList);
908   
909    if($len_max != "" && $max > $len_max) {
910        $max = $len_max;
911    }
912   
913    for($cnt = 0; $cnt < $max; $cnt++) {
914        if($keysize != "") {
915            $key = sfCutString($arrList[$cnt][$keyname], $keysize);
916        } else {
917            $key = $arrList[$cnt][$keyname];
918        }
919        $val = $arrList[$cnt][$valname];
920       
921        if(!isset($arrRet[$key])) {
922            $arrRet[$key] = $val;
923        }
924       
925    }
926    return $arrRet;
927}
928
929// ¥­¡¼¤ÈÃͤò¥»¥Ã¥È¤·¤¿ÇÛÎó¤ò¼èÆÀ(Ãͤ¬Ê£¿ô¤Î¾ì¹ç)
930function sfArrKeyValues($arrList, $keyname, $valname, $len_max = "", $keysize = "", $connect = "") {
931   
932    $max = count($arrList);
933   
934    if($len_max != "" && $max > $len_max) {
935        $max = $len_max;
936    }
937   
938    for($cnt = 0; $cnt < $max; $cnt++) {
939        if($keysize != "") {
940            $key = sfCutString($arrList[$cnt][$keyname], $keysize);
941        } else {
942            $key = $arrList[$cnt][$keyname];
943        }
944        $val = $arrList[$cnt][$valname];
945       
946        if($connect != "") {
947            $arrRet[$key].= "$val".$connect;
948        } else {
949            $arrRet[$key][] = $val;     
950        }
951    }
952    return $arrRet;
953}
954
955// ÇÛÎó¤ÎÃͤò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊÖ¤¹¡£
956function sfGetCommaList($array, $space=true) {
957    if (count($array) > 0) {
958        $line = "";
959        foreach($array as $val) {
960            if ($space) {
961                $line .= $val . ", ";
962            }else{
963                $line .= $val . ",";
964            }
965        }
966        if ($space) {
967            $line = ereg_replace(", $", "", $line);
968        }else{
969            $line = ereg_replace(",$", "", $line);
970        }
971        return $line;
972    }else{
973        return false;
974    }
975   
976}
977
978/* ÇÛÎó¤ÎÍ×ÁǤòCSV¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç½ÐÎϤ¹¤ë¡£*/
979function sfGetCSVList($array) {
980    if (count($array) > 0) {
981        foreach($array as $key => $val) {
982            $val = mb_convert_encoding($val, CHAR_CODE, CHAR_CODE);
983            $line .= "\"".$val."\",";
984        }
985        $line = ereg_replace(",$", "\n", $line);
986    }else{
987        return false;
988    }
989    return $line;
990}
991
992/* ÇÛÎó¤ÎÍ×ÁǤòPDF¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç½ÐÎϤ¹¤ë¡£*/
993function sfGetPDFList($array) {
994    foreach($array as $key => $val) {
995        $line .= "\t".$val;
996    }
997    $line.="\n";
998    return $line;
999}
1000
1001
1002
1003/*-----------------------------------------------------------------*/
1004/*  check_set_term
1005/*  ǯ·îÆü¤ËÊ̤줿2¤Ä¤Î´ü´Ö¤ÎÂÅÅöÀ­¤ò¥Á¥§¥Ã¥¯¤·¡¢À°¹çÀ­¤È´ü´Ö¤òÊÖ¤¹
1006/*¡¡°ú¿ô (³«»Ïǯ,³«»Ï·î,³«»ÏÆü,½ªÎ»Ç¯,½ªÎ»·î,½ªÎ»Æü)
1007/*¡¡ÌáÃÍ array(£±¡¤£²¡¤£³¡Ë
1008/*          £±¡¥³«»Ïǯ·îÆü (YYYY/MM/DD 000000)
1009/*          £²¡¥½ªÎ»Ç¯·îÆü (YYYY/MM/DD 235959)
1010/*          £³¡¥¥¨¥é¡¼ ( 0 = OK, 1 = NG )
1011/*-----------------------------------------------------------------*/
1012function sfCheckSetTerm ( $start_year, $start_month, $start_day, $end_year, $end_month, $end_day ) {
1013
1014    // ´ü´Ö»ØÄê
1015    $error = 0;
1016    if ( $start_month || $start_day || $start_year){
1017        if ( ! checkdate($start_month, $start_day , $start_year) ) $error = 1;
1018    } else {
1019        $error = 1;
1020    }
1021    if ( $end_month || $end_day || $end_year){
1022        if ( ! checkdate($end_month ,$end_day ,$end_year) ) $error = 2;
1023    }
1024    if ( ! $error ){
1025        $date1 = $start_year ."/".sprintf("%02d",$start_month) ."/".sprintf("%02d",$start_day) ." 000000";
1026        $date2 = $end_year   ."/".sprintf("%02d",$end_month)   ."/".sprintf("%02d",$end_day)   ." 235959";
1027        if ($date1 > $date2) $error = 3;
1028    } else {
1029        $error = 1;
1030    }
1031    return array($date1, $date2, $error);
1032}
1033
1034// ¥¨¥é¡¼²Õ½ê¤ÎÇØ·Ê¿§¤òÊѹ¹¤¹¤ë¤¿¤á¤Îfunction SC_View¤ÇÆɤ߹þ¤à
1035function sfSetErrorStyle(){
1036    return 'style="background-color:'.ERR_COLOR.'"';
1037}
1038
1039/* DB¤ËÅϤ¹¿ôÃͤΥÁ¥§¥Ã¥¯
1040 * 10·å°Ê¾å¤Ï¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¥¨¥é¡¼¤òµ¯¤³¤¹¤Î¤Ç¡£
1041 */
1042function sfCheckNumLength( $value ){
1043    if ( ! is_numeric($value)  ){
1044        return false;
1045    }
1046   
1047    if ( strlen($value) > 9 ) {
1048        return false;
1049    }
1050   
1051    return true;
1052}
1053
1054// °ìÃפ·¤¿ÃͤΥ­¡¼Ì¾¤ò¼èÆÀ
1055function sfSearchKey($array, $word, $default) {
1056    foreach($array as $key => $val) {
1057        if($val == $word) {
1058            return $key;
1059        }
1060    }
1061    return $default;
1062}
1063
1064// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ($products_check:true¾¦ÉÊÅÐÏ¿ºÑ¤ß¤Î¤â¤Î¤À¤±¼èÆÀ)
1065function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) {
1066    $objQuery = new SC_Query();
1067    $where = "del_flg = 0";
1068   
1069    if($addwhere != "") {
1070        $where.= " AND $addwhere";
1071    }
1072       
1073    $objQuery->setoption("ORDER BY rank DESC");
1074   
1075    if($products_check) {
1076        $col = "T1.category_id, category_name, level";
1077        $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id";
1078        $where .= " AND product_count > 0";
1079    } else {
1080        $col = "category_id, category_name, level";
1081        $from = "dtb_category";
1082    }
1083   
1084    $arrRet = $objQuery->select($col, $from, $where);
1085           
1086    $max = count($arrRet);
1087    for($cnt = 0; $cnt < $max; $cnt++) {
1088        $id = $arrRet[$cnt]['category_id'];
1089        $name = $arrRet[$cnt]['category_name'];
1090        $arrList[$id] = "";
1091        /*
1092        for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {
1093            $arrList[$id].= "¡¡";
1094        }
1095        */
1096        for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {
1097            $arrList[$id].= $head;
1098        }
1099        $arrList[$id].= $name;
1100    }
1101    return $arrList;
1102}
1103
1104// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ¡Ê¿Æ¥«¥Æ¥´¥ê¤ÎValue:0)
1105function sfGetLevelCatList($parent_zero = true) {
1106    $objQuery = new SC_Query();
1107    $col = "category_id, category_name, level";
1108    $where = "del_flg = 0";
1109    $objQuery->setoption("ORDER BY rank DESC");
1110    $arrRet = $objQuery->select($col, "dtb_category", $where);
1111    $max = count($arrRet);
1112   
1113    for($cnt = 0; $cnt < $max; $cnt++) {
1114        if($parent_zero) {
1115            if($arrRet[$cnt]['level'] == LEVEL_MAX) {
1116                $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
1117            } else {
1118                $arrValue[$cnt] = "";
1119            }
1120        } else {
1121            $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
1122        }
1123       
1124        $arrOutput[$cnt] = "";
1125        /*         
1126        for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {
1127            $arrOutput[$cnt].= "¡¡";
1128        }
1129        */
1130        for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {
1131            $arrOutput[$cnt].= CATEGORY_HEAD;
1132        }
1133        $arrOutput[$cnt].= $arrRet[$cnt]['category_name'];
1134    }
1135    return array($arrValue, $arrOutput);
1136}
1137
1138function sfGetErrorColor($val) {
1139    if($val != "") {
1140        return "background-color:" . ERR_COLOR;
1141    }
1142    return "";
1143}
1144
1145
1146function sfGetEnabled($val) {
1147    if( ! $val ) {
1148        return " disabled=\"disabled\"";
1149    }
1150    return "";
1151}
1152
1153function sfGetChecked($param, $value) {
1154    if($param == $value) {
1155        return "checked=\"checked\"";
1156    }
1157    return "";
1158}
1159
1160// SELECT¥Ü¥Ã¥¯¥¹Íѥꥹ¥È¤ÎºîÀ®
1161function sfGetIDValueList($table, $keyname, $valname) {
1162    $objQuery = new SC_Query();
1163    $col = "$keyname, $valname";
1164    $objQuery->setwhere("del_flg = 0");
1165    $objQuery->setorder("rank DESC");
1166    $arrList = $objQuery->select($col, $table);
1167    $count = count($arrList);
1168    for($cnt = 0; $cnt < $count; $cnt++) {
1169        $key = $arrList[$cnt][$keyname];
1170        $val = $arrList[$cnt][$valname];
1171        $arrRet[$key] = $val;
1172    }
1173    return $arrRet;
1174}
1175
1176function sfTrim($str) {
1177    $ret = ereg_replace("^[¡¡ \n\r]*", "", $str);
1178    $ret = ereg_replace("[¡¡ \n\r]*$", "", $ret);
1179    return $ret;
1180}
1181
1182/* ½ê°¤¹¤ë¤¹¤Ù¤Æ¤Î³¬ÁؤοÆID¤òÇÛÎó¤ÇÊÖ¤¹ */
1183function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) {
1184    $arrRet = sfGetParentsArray($table, $pid_name, $id_name, $id);
1185    // ÇÛÎó¤ÎÀèƬ1¤Ä¤òºï½ü¤¹¤ë¡£
1186    array_shift($arrRet);
1187    return $arrRet;
1188}
1189
1190
1191/* ¿ÆID¤ÎÇÛÎó¤ò¸µ¤ËÆÃÄê¤Î¥«¥é¥à¤ò¼èÆÀ¤¹¤ë¡£*/
1192function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) {
1193    $col = $col_name;
1194    $len = count($arrId);
1195    $where = "";
1196   
1197    for($cnt = 0; $cnt < $len; $cnt++) {
1198        if($where == "") {
1199            $where = "$id_name = ?";
1200        } else {
1201            $where.= " OR $id_name = ?";
1202        }
1203    }
1204   
1205    $objQuery->setorder("level");
1206    $arrRet = $objQuery->select($col, $table, $where, $arrId);
1207    return $arrRet;
1208}
1209
1210/* »ÒID¤ÎÇÛÎó¤òÊÖ¤¹ */
1211function sfGetChildsID($table, $pid_name, $id_name, $id) {
1212    $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id);
1213    return $arrRet;
1214}
1215
1216/* ¥«¥Æ¥´¥êÊѹ¹»þ¤Î°ÜÆ°½èÍý */
1217function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) {
1218    if ($old_catid == $new_catid) {
1219        return;
1220    }
1221    // µì¥«¥Æ¥´¥ê¤Ç¤Î¥é¥ó¥¯ºï½ü½èÍý
1222    // °ÜÆ°¥ì¥³¡¼¥É¤Î¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë¡£     
1223    $where = "$id_name = ?";
1224    $rank = $objQuery->get($table, "rank", $where, array($id));
1225    // ºï½ü¥ì¥³¡¼¥É¤Î¥é¥ó¥¯¤è¤ê¾å¤Î¥ì¥³¡¼¥É¤ò°ì¤Ä²¼¤Ë¤º¤é¤¹¡£
1226    $where = "rank > ? AND $cat_name = ?";
1227    $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
1228    $objQuery->exec($sqlup, array($rank, $old_catid));
1229    // ¿·¥«¥Æ¥´¥ê¤Ç¤ÎÅÐÏ¿½èÍý
1230    // ¿·¥«¥Æ¥´¥ê¤ÎºÇÂç¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë¡£
1231    $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1;
1232    $where = "$id_name = ?";
1233    $sqlup = "UPDATE $table SET rank = ? WHERE $where";
1234    $objQuery->exec($sqlup, array($max_rank, $id));
1235}
1236
1237/* ÀǶâ·×»» */
1238function sfTax($price, $tax, $tax_rule) {
1239    $real_tax = $tax / 100;
1240    $ret = $price * $real_tax;
1241    switch($tax_rule) {
1242    // »Í¼Î¸ÞÆþ
1243    case 1:
1244        $ret = round($ret);
1245        break;
1246    // ÀÚ¤ê¼Î¤Æ
1247    case 2:
1248        $ret = floor($ret);
1249        break;
1250    // ÀÚ¤ê¾å¤²
1251    case 3:
1252        $ret = ceil($ret);
1253        break;
1254    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1255    default:
1256        $ret = ceil($ret);
1257        break;
1258    }
1259    return $ret;
1260}
1261
1262/* ÀǶâÉÕÍ¿ */
1263function sfPreTax($price, $tax, $tax_rule) {
1264    $real_tax = $tax / 100;
1265    $ret = $price * (1 + $real_tax);
1266   
1267    switch($tax_rule) {
1268    // »Í¼Î¸ÞÆþ
1269    case 1:
1270        $ret = round($ret);
1271        break;
1272    // ÀÚ¤ê¼Î¤Æ
1273    case 2:
1274        $ret = floor($ret);
1275        break;
1276    // ÀÚ¤ê¾å¤²
1277    case 3:
1278        $ret = ceil($ret);
1279        break;
1280    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1281    default:
1282        $ret = ceil($ret);
1283        break;
1284    }
1285    return $ret;
1286}
1287
1288// ·å¿ô¤ò»ØÄꤷ¤Æ»Í¼Î¸ÞÆþ
1289function sfRound($value, $pow = 0){
1290    $adjust = pow(10 ,$pow-1);
1291
1292    // À°¿ô³î¤Ä0½Ð¤Ê¤±¤ì¤Ð·å¿ô»ØÄê¤ò¹Ô¤¦
1293    if(sfIsInt($adjust) and $pow > 1){
1294        $ret = (round($value * $adjust)/$adjust);
1295    }
1296   
1297    $ret = round($ret);
1298
1299    return $ret;
1300}
1301
1302/* ¥Ý¥¤¥ó¥ÈÉÕÍ¿ */
1303function sfPrePoint($price, $point_rate, $rule = POINT_RULE, $product_id = "") {
1304    if(sfIsInt($product_id)) {
1305        $objQuery = new SC_Query();
1306        $where = "now() >= cast(start_date as date) AND ";
1307        $where .= "now() < cast(end_date as date) AND ";
1308       
1309        $where .= "del_flg = 0 AND campaign_id IN (SELECT campaign_id FROM dtb_campaign_detail where product_id = ? )";
1310        //ÅÐÏ¿(¹¹¿·)ÆüÉÕ½ç
1311        $objQuery->setorder('update_date DESC');
1312        //¥­¥ã¥ó¥Ú¡¼¥ó¥Ý¥¤¥ó¥È¤Î¼èÆÀ
1313        $arrRet = $objQuery->select("campaign_name, campaign_point_rate", "dtb_campaign", $where, array($product_id));
1314    }
1315    //Ê£¿ô¤Î¥­¥ã¥ó¥Ú¡¼¥ó¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¾¦Éʤϡ¢ºÇ¿·¤Î¥­¥ã¥ó¥Ú¡¼¥ó¤«¤é¥Ý¥¤¥ó¥È¤ò¼èÆÀ
1316    if($arrRet[0]['campaign_point_rate'] != "") {
1317        $campaign_point_rate = $arrRet[0]['campaign_point_rate'];
1318        $real_point = $campaign_point_rate / 100;
1319    } else {
1320        $real_point = $point_rate / 100;
1321    }
1322    $ret = $price * $real_point;
1323    switch($rule) {
1324    // »Í¼Î¸ÞÆþ
1325    case 1:
1326        $ret = round($ret);
1327        break;
1328    // ÀÚ¤ê¼Î¤Æ
1329    case 2:
1330        $ret = floor($ret);
1331        break;
1332    // ÀÚ¤ê¾å¤²
1333    case 3:
1334        $ret = ceil($ret);
1335        break;
1336    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1337    default:
1338        $ret = ceil($ret);
1339        break;
1340    }
1341    //¥­¥ã¥ó¥Ú¡¼¥ó¾¦Éʤξì¹ç
1342    if($campaign_point_rate != "") {
1343        $ret = "(".$arrRet[0]['campaign_name']."¥Ý¥¤¥ó¥ÈΨ".$campaign_point_rate."%)".$ret;
1344    }
1345    return $ret;
1346}
1347
1348/* µ¬³ÊʬÎà¤Î·ï¿ô¼èÆÀ */
1349function sfGetClassCatCount() {
1350    $sql = "select count(dtb_class.class_id) as count, dtb_class.class_id ";
1351    $sql.= "from dtb_class inner join dtb_classcategory on dtb_class.class_id = dtb_classcategory.class_id ";
1352    $sql.= "where dtb_class.del_flg = 0 AND dtb_classcategory.del_flg = 0 ";
1353    $sql.= "group by dtb_class.class_id, dtb_class.name";
1354    $objQuery = new SC_Query();
1355    $arrList = $objQuery->getall($sql);
1356    // ¥­¡¼¤ÈÃͤò¥»¥Ã¥È¤·¤¿ÇÛÎó¤ò¼èÆÀ
1357    $arrRet = sfArrKeyValue($arrList, 'class_id', 'count');
1358   
1359    return $arrRet;
1360}
1361
1362/* µ¬³Ê¤ÎÅÐÏ¿ */
1363function sfInsertProductClass($objQuery, $arrList, $product_id) {
1364    // ¤¹¤Ç¤Ëµ¬³ÊÅÐÏ¿¤¬¤¢¤ë¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¡£
1365    $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0";
1366    $count = $objQuery->count("dtb_products_class", $where,  array($product_id));
1367   
1368    // ¤¹¤Ç¤Ëµ¬³ÊÅÐÏ¿¤¬¤Ê¤¤¾ì¹ç
1369    if($count == 0) {
1370        // ´û¸µ¬³Ê¤Îºï½ü
1371        $where = "product_id = ?";
1372        $objQuery->delete("dtb_products_class", $where, array($product_id));
1373        $sqlval['product_id'] = $product_id;
1374        $sqlval['classcategory_id1'] = '0';
1375        $sqlval['classcategory_id2'] = '0';
1376        $sqlval['product_code'] = $arrList["product_code"];
1377        $sqlval['stock'] = $arrList["stock"];
1378        $sqlval['stock_unlimited'] = $arrList["stock_unlimited"];
1379        $sqlval['price01'] = $arrList['price01'];
1380        $sqlval['price02'] = $arrList['price02'];
1381        $sqlval['creator_id'] = $_SESSION['member_id'];
1382        $sqlval['create_date'] = "now()";
1383       
1384        if($_SESSION['member_id'] == "") {
1385            $sqlval['creator_id'] = '0';
1386        }
1387       
1388        // INSERT¤Î¼Â¹Ô
1389        $objQuery->insert("dtb_products_class", $sqlval);
1390    }
1391}
1392
1393function sfGetProductClassId($product_id, $classcategory_id1, $classcategory_id2) {
1394    $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
1395    $objQuery = new SC_Query();
1396    $ret = $objQuery->get("dtb_products_class", "product_class_id", $where, Array($product_id, $classcategory_id1, $classcategory_id2));
1397    return $ret;
1398}
1399
1400/* ʸËö¤Î¡Ö/¡×¤ò¤Ê¤¯¤¹ */
1401function sfTrimURL($url) {
1402    $ret = ereg_replace("[/]+$", "", $url);
1403    return $ret;
1404}
1405
1406/* ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ */
1407function sfGetProductsClass($arrID) {
1408    list($product_id, $classcategory_id1, $classcategory_id2) = $arrID;
1409   
1410    if($classcategory_id1 == "") {
1411        $classcategory_id1 = '0';
1412    }
1413    if($classcategory_id2 == "") {
1414        $classcategory_id2 = '0';
1415    }
1416       
1417    // ¾¦Éʵ¬³Ê¼èÆÀ
1418    $objQuery = new SC_Query();
1419    $col = "product_id, deliv_fee, name, product_code, main_list_image, main_image, price01, price02, point_rate, product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited, sale_limit, sale_unlimited";
1420    $table = "vw_product_class AS prdcls";
1421    $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
1422    $objQuery->setorder("rank1 DESC, rank2 DESC");
1423    $arrRet = $objQuery->select($col, $table, $where, array($product_id, $classcategory_id1, $classcategory_id2));
1424    return $arrRet[0];
1425}
1426
1427/* ½¸·×¾ðÊó¤ò¸µ¤ËºÇ½ª·×»» */
1428function sfTotalConfirm($arrData, $objPage, $objCartSess, $arrInfo, $objCustomer = "") {
1429    // ¾¦Éʤιç·×¸Ä¿ô
1430    $total_quantity = $objCartSess->getTotalQuantity(true);
1431   
1432    // ÀǶâ¤Î¼èÆÀ
1433    $arrData['tax'] = $objPage->tpl_total_tax;
1434    // ¾®·×¤Î¼èÆÀ
1435    $arrData['subtotal'] = $objPage->tpl_total_pretax; 
1436   
1437    // ¹ç·×Á÷ÎÁ¤Î¼èÆÀ
1438    $arrData['deliv_fee'] = 0;
1439       
1440    // ¾¦Éʤ´¤È¤ÎÁ÷ÎÁ¤¬Í­¸ú¤Î¾ì¹ç
1441    if (OPTION_PRODUCT_DELIV_FEE == 1) {
1442        $arrData['deliv_fee']+= $objCartSess->getAllProductsDelivFee();
1443    }
1444   
1445    // ÇÛÁ÷¶È¼Ô¤ÎÁ÷ÎÁ¤¬Í­¸ú¤Î¾ì¹ç
1446    if (OPTION_DELIV_FEE == 1) {
1447        // Á÷ÎÁ¤Î¹ç·×¤ò·×»»¤¹¤ë
1448        $arrData['deliv_fee']+= sfGetDelivFee($arrData['deliv_pref'], $arrData['payment_id']);
1449    }
1450   
1451    // Á÷ÎÁ̵ÎÁ¤Î¹ØÆþ¿ô¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç
1452    if(DELIV_FREE_AMOUNT > 0) {
1453        if($total_quantity >= DELIV_FREE_AMOUNT) {
1454            $arrData['deliv_fee'] = 0;
1455        }   
1456    }
1457       
1458    // Á÷ÎÁ̵ÎÁ¾ò·ï¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç
1459    if($arrInfo['free_rule'] > 0) {
1460        // ¾®·×¤¬ÌµÎÁ¾ò·ï¤òĶ¤¨¤Æ¤¤¤ë¾ì¹ç
1461        if($arrData['subtotal'] >= $arrInfo['free_rule']) {
1462            $arrData['deliv_fee'] = 0;
1463        }
1464    }
1465
1466    // ¹ç·×¤Î·×»»
1467    $arrData['total'] = $objPage->tpl_total_pretax; // ¾¦Éʹç·×
1468    $arrData['total']+= $arrData['deliv_fee'];      // Á÷ÎÁ
1469    $arrData['total']+= $arrData['charge'];         // ¼ê¿ôÎÁ
1470    // ¤ª»Ùʧ¤¤¹ç·×
1471    $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE);
1472    // ²Ã»»¥Ý¥¤¥ó¥È¤Î·×»»
1473    $arrData['add_point'] = sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point'], $arrInfo);
1474   
1475    if($objCustomer != "") {
1476        // ÃÂÀ¸Æü·î¤Ç¤¢¤Ã¤¿¾ì¹ç
1477        if($objCustomer->isBirthMonth()) {
1478            $arrData['birth_point'] = BIRTH_MONTH_POINT;
1479            $arrData['add_point'] += $arrData['birth_point'];
1480        }
1481    }
1482   
1483    if($arrData['add_point'] < 0) {
1484        $arrData['add_point'] = 0;
1485    }
1486   
1487    return $arrData;
1488}
1489
1490/* ¥«¡¼¥ÈÆ⾦Éʤν¸·×½èÍý */
1491function sfTotalCart($objPage, $objCartSess, $arrInfo) {
1492    // µ¬³Ê̾°ìÍ÷
1493    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
1494    // µ¬³ÊʬÎà̾°ìÍ÷
1495    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
1496   
1497    $objPage->tpl_total_pretax = 0;     // ÈñÍѹç·×(Àǹþ¤ß)
1498    $objPage->tpl_total_tax = 0;        // ¾ÃÈñÀǹç·×
1499    $objPage->tpl_total_point = 0;      // ¥Ý¥¤¥ó¥È¹ç·×
1500   
1501    // ¥«¡¼¥ÈÆâ¾ðÊó¤Î¼èÆÀ
1502    $arrCart = $objCartSess->getCartList();
1503    $max = count($arrCart);
1504    $cnt = 0;
1505
1506    for ($i = 0; $i < $max; $i++) {
1507        // ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ   
1508        $arrData = sfGetProductsClass($arrCart[$i]['id']);
1509        $limit = "";
1510        // DB¤Ë¸ºß¤¹¤ë¾¦ÉÊ
1511        if (count($arrData) > 0) {
1512           
1513            // ¹ØÆþÀ©¸Â¿ô¤òµá¤á¤ë¡£         
1514            if ($arrData['stock_unlimited'] != '1' && $arrData['sale_unlimited'] != '1') {
1515                if($arrData['sale_limit'] < $arrData['stock']) {
1516                    $limit = $arrData['sale_limit'];
1517                } else {
1518                    $limit = $arrData['stock'];
1519                }
1520            } else {
1521                if ($arrData['sale_unlimited'] != '1') {
1522                    $limit = $arrData['sale_limit'];
1523                }
1524                if ($arrData['stock_unlimited'] != '1') {
1525                    $limit = $arrData['stock'];
1526                }
1527            }
1528                       
1529            if($limit != "" && $limit < $arrCart[$i]['quantity']) {
1530                // ¥«¡¼¥ÈÆ⾦ÉÊ¿ô¤òÀ©¸Â¤Ë¹ç¤ï¤»¤ë
1531                $objCartSess->setProductValue($arrCart[$i]['id'], 'quantity', $limit);
1532                $quantity = $limit;
1533                $objPage->tpl_message = "¢¨¡Ö" . $arrData['name'] . "¡×¤ÏÈÎÇäÀ©¸Â¤·¤Æ¤ª¤ê¤Þ¤¹¡¢°ìÅ٤ˤ³¤ì°Ê¾å¤Î¹ØÆþ¤Ï¤Ç¤­¤Þ¤»¤ó¡£";
1534            } else {
1535                $quantity = $arrCart[$i]['quantity'];
1536            }
1537           
1538            $objPage->arrProductsClass[$cnt] = $arrData;
1539            $objPage->arrProductsClass[$cnt]['quantity'] = $quantity;
1540            $objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart[$i]['cart_no'];
1541            $objPage->arrProductsClass[$cnt]['class_name1'] = $arrClassName[$arrData['class_id1']];
1542            $objPage->arrProductsClass[$cnt]['class_name2'] = $arrClassName[$arrData['class_id2']];
1543            $objPage->arrProductsClass[$cnt]['classcategory_name1'] = $arrClassCatName[$arrData['classcategory_id1']];
1544            $objPage->arrProductsClass[$cnt]['classcategory_name2'] = $arrClassCatName[$arrData['classcategory_id2']];
1545           
1546            // ²èÁü¥µ¥¤¥º
1547            list($image_width, $image_height) = getimagesize(IMAGE_SAVE_DIR . basename($objPage->arrProductsClass[$cnt]["main_image"]));
1548            $objPage->arrProductsClass[$cnt]["tpl_image_width"] = $image_width + 60;
1549            $objPage->arrProductsClass[$cnt]["tpl_image_height"] = $image_height + 80;
1550           
1551            // ²Á³Ê¤ÎÅÐÏ¿
1552            if ($arrData['price02'] != "") {
1553                $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price02']);
1554                $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price02'];
1555            } else {
1556                $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price01']);
1557                $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price01'];
1558            }
1559            // ¥Ý¥¤¥ó¥ÈÉÕͿΨ¤ÎÅÐÏ¿
1560            $objCartSess->setProductValue($arrCart[$i]['id'], 'point_rate', $arrData['point_rate']);
1561            // ¾¦Éʤ´¤È¤Î¹ç·×¶â³Û
1562            $objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arrInfo, $arrCart[$i]['id']);
1563            // Á÷ÎÁ¤Î¹ç·×¤ò·×»»¤¹¤ë
1564            $objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart[$i]['quantity']);
1565            $cnt++;
1566        } else {
1567            // DB¤Ë¾¦Éʤ¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï¥«¡¼¥È¾¦Éʤκï½ü
1568            $objCartSess->delProductKey('id', $arrCart[$i]['id']);
1569        }
1570    }
1571   
1572    // Á´¾¦Éʹç·×¶â³Û(Àǹþ¤ß)
1573    $objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
1574    // Á´¾¦Éʹç·×¾ÃÈñÀÇ
1575    $objPage->tpl_total_tax = $objCartSess->getAllProductsTax($arrInfo);
1576    // Á´¾¦Éʹç·×¥Ý¥¤¥ó¥È
1577    $objPage->tpl_total_point = $objCartSess->getAllProductsPoint();
1578   
1579    return $objPage;   
1580}
1581
1582/* DB¤«¤é¼è¤ê½Ð¤·¤¿ÆüÉÕ¤Îʸ»úÎó¤òÄ´À°¤¹¤ë¡£*/
1583function sfDispDBDate($dbdate, $time = true) {
1584    list($y, $m, $d, $H, $M) = split("[- :]", $dbdate);
1585
1586    if(strlen($y) > 0 && strlen($m) > 0 && strlen($d) > 0) {
1587        if ($time) {
1588            $str = sprintf("%04d/%02d/%02d %02d:%02d", $y, $m, $d, $H, $M);
1589        } else {
1590            $str = sprintf("%04d/%02d/%02d", $y, $m, $d, $H, $M);                       
1591        }
1592    } else {
1593        $str = "";
1594    }
1595    return $str;
1596}
1597
1598function sfGetDelivTime($payment_id = "") {
1599    $objQuery = new SC_Query();
1600   
1601    $deliv_id = "";
1602   
1603    if($payment_id != "") {
1604        $where = "del_flg = 0 AND payment_id = ?";
1605        $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1606        $deliv_id = $arrRet[0]['deliv_id'];
1607    }
1608   
1609    if($deliv_id != "") {
1610        $objQuery->setorder("time_id");
1611        $where = "deliv_id = ?";
1612        $arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id));
1613    }
1614   
1615    return $arrRet;
1616}
1617
1618
1619// ÅÔÆ»Éܸ©¡¢»Ùʧ¤¤ÊýË¡¤«¤éÇÛÁ÷ÎÁ¶â¤ò¼èÆÀ¤¹¤ë
1620function sfGetDelivFee($pref, $payment_id = "") {
1621    $objQuery = new SC_Query();
1622   
1623    $deliv_id = "";
1624   
1625    // »Ùʧ¤¤ÊýË¡¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢Âбþ¤·¤¿ÇÛÁ÷¶È¼Ô¤ò¼èÆÀ¤¹¤ë
1626    if($payment_id != "") {
1627        $where = "del_flg = 0 AND payment_id = ?";
1628        $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1629        $deliv_id = $arrRet[0]['deliv_id'];
1630    // »Ùʧ¤¤ÊýË¡¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢ÀèƬ¤ÎÇÛÁ÷¶È¼Ô¤ò¼èÆÀ¤¹¤ë
1631    } else {
1632        $where = "del_flg = 0";
1633        $objQuery->setOrder("rank DESC");
1634        $objQuery->setLimitOffset(1);
1635        $arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where);
1636        $deliv_id = $arrRet[0]['deliv_id'];
1637    }
1638   
1639    // ÇÛÁ÷¶È¼Ô¤«¤éÇÛÁ÷ÎÁ¤ò¼èÆÀ
1640    if($deliv_id != "") {
1641       
1642        // ÅÔÆ»Éܸ©¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢ÅìµþÅÔ¤ÎÈÖ¹æ¤ò»ØÄꤷ¤Æ¤ª¤¯
1643        if($pref == "") {
1644            $pref = 13;
1645        }
1646       
1647        $objQuery = new SC_Query();
1648        $where = "deliv_id = ? AND pref = ?";
1649        $arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref));
1650    }   
1651    return $arrRet[0]['fee'];   
1652}
1653
1654/* »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ */
1655function sfGetPayment() {
1656    $objQuery = new SC_Query();
1657    // ¹ØÆþ¶â³Û¤¬¾ò·ï³Û°Ê²¼¤Î¹àÌܤò¼èÆÀ
1658    $where = "del_flg = 0";
1659    $objQuery->setorder("fix, rank DESC");
1660    $arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where);
1661    return $arrRet;
1662}
1663
1664/* ÇÛÎó¤ò¥­¡¼Ì¾¤´¤È¤ÎÇÛÎó¤ËÊѹ¹¤¹¤ë */
1665function sfSwapArray($array) {
1666    $max = count($array);
1667    for($i = 0; $i < $max; $i++) {
1668        foreach($array[$i] as $key => $val) {
1669            $arrRet[$key][] = $val;
1670        }
1671    }
1672    return $arrRet;
1673}
1674
1675/* ¤«¤±»»¤ò¤¹¤ë¡ÊSmartyÍÑ) */
1676function sfMultiply($num1, $num2) {
1677    return ($num1 * $num2);
1678}
1679
1680/* DB¤ËÅÐÏ¿¤µ¤ì¤¿¥Æ¥ó¥×¥ì¡¼¥È¥á¡¼¥ë¤ÎÁ÷¿® */
1681function sfSendTemplateMail($to, $to_name, $template_id, $objPage) {
1682    global $arrMAILTPLPATH;
1683    $objQuery = new SC_Query();
1684    // ¥á¡¼¥ë¥Æ¥ó¥×¥ì¡¼¥È¾ðÊó¤Î¼èÆÀ
1685    $where = "template_id = ?";
1686    $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
1687    $objPage->tpl_header = $arrRet[0]['header'];
1688    $objPage->tpl_footer = $arrRet[0]['footer'];
1689    $tmp_subject = $arrRet[0]['subject'];
1690   
1691    $objSiteInfo = new SC_SiteInfo();
1692    $arrInfo = $objSiteInfo->data;
1693   
1694    $objMailView = new SC_SiteView();
1695    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1696    $objMailView->assignobj($objPage);
1697    $body = $objMailView->fetch($arrMAILTPLPATH[$template_id]);
1698   
1699    // ¥á¡¼¥ëÁ÷¿®½èÍý
1700    $objSendMail = new GC_SendMail();
1701    $from = $arrInfo['email03'];
1702    $error = $arrInfo['email04'];
1703    $tosubject = $tmp_subject;
1704    $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error);
1705    $objSendMail->setTo($to, $to_name);
1706    $objSendMail->sendMail();   // ¥á¡¼¥ëÁ÷¿®
1707}
1708
1709/** ¼õÃí´°Î»¥á¡¼¥ëÁ÷¿®
1710 *  $template_id ¤¬ 1¡§·ÈÂÓÍѥƥó¥×¥ì¡¼¥È¡¢0¡§PCÍѥƥó¥×¥ì¡¼¥È
1711 */
1712function sfSendOrderMail($order_id, $template_id, $subject = "", $body = "", $send = true) {
1713    global $arrMAILTPLPATH;
1714   
1715    $objPage = new LC_Page();
1716    $objSiteInfo = new SC_SiteInfo();
1717    $arrInfo = $objSiteInfo->data;
1718    $objPage->arrInfo = $arrInfo;
1719   
1720    $objQuery = new SC_Query();
1721       
1722    if($subject == "" && $body == "" ) {
1723        // ¥á¡¼¥ë¥Æ¥ó¥×¥ì¡¼¥È¾ðÊó¤Î¼èÆÀ
1724        $where = "template_id = ?";
1725        $arrRet = $objQuery->select("subject, body", "dtb_mailtemplate", $where, array($template_id));
1726        $objPage->tpl_body = $arrRet[0]['body'];
1727        $tmp_subject = $arrRet[0]['subject'];
1728    } else {
1729        $objPage->tpl_body = $body;
1730        $tmp_subject = $subject;
1731    }
1732   
1733    // ¼õÃí¾ðÊó¤Î¼èÆÀ
1734    $where = "order_id = ?";
1735    $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
1736    $arrOrder = $arrRet[0];
1737    $arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id));
1738   
1739    $objPage->Message_tmp = $arrOrder['message'];
1740       
1741    // ¸ÜµÒ¾ðÊó¤Î¼èÆÀ
1742    $customer_id = $arrOrder['customer_id'];
1743    $arrRet = $objQuery->select("point,name01,name02", "dtb_customer", "customer_id = ?", array($customer_id));
1744    $arrCustomer = $arrRet[0];
1745
1746    $objPage->arrCustomer = $arrCustomer;
1747    $objPage->arrOrder = $arrOrder;
1748   
1749    //¤½¤Î¾·èºÑ¾ðÊó
1750    if($arrOrder['memo02'] != "") {
1751        $arrOther = unserialize($arrOrder['memo02']);
1752       
1753        foreach($arrOther as $other_key => $other_val){
1754            if(sfTrim($other_val["value"]) == ""){
1755                $arrOther[$other_key]["value"] = "";
1756            }
1757        }
1758       
1759        $objPage->arrOther = $arrOther;
1760    }
1761
1762    // ÅÔÆ»Éܸ©ÊÑ´¹
1763    global $arrPref;
1764    $objPage->arrOrder['deliv_pref'] = $arrPref[$objPage->arrOrder['deliv_pref']];
1765   
1766    $objPage->arrOrderDetail = $arrOrderDetail;
1767   
1768    $objCustomer = new SC_Customer();
1769    $objPage->tpl_user_point = $objCustomer->getValue('point');
1770   
1771    $objMailView = new SC_SiteView();
1772    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1773    $objMailView->assignobj($objPage);
1774    $name = $objPage->arrOrder['order_name01']." ".$objPage->arrOrder['order_name02'];
1775    $objPage->tpl_body = ereg_replace( "(\{name\})", $name ,  $objPage->tpl_body );
1776    $tmp_subject = ereg_replace( "(\{name\})", $name ,  $tmp_subject );
1777   
1778    // $template_id==1¤Ï·ÈÂÓÍÑ
1779    if($template_id == '1'){
1780       $body = $objMailView->fetch($arrMAILTPLPATH[1]);
1781       $body = ereg_replace( "(\{order\})", $body ,  $objPage->tpl_body );
1782    }else{
1783       $body = $objMailView->fetch($arrMAILTPLPATH[0]);
1784       $body = ereg_replace( "(\{order\})", $body ,  $objPage->tpl_body );
1785    }
1786   
1787    // ¥á¡¼¥ëÁ÷¿®½èÍý
1788    $objSendMail = new GC_SendMail();
1789    $bcc = $arrInfo['email01'];
1790    $from = $arrInfo['email03'];
1791    $error = $arrInfo['email04'];
1792
1793    $tosubject = sfMakeSubject($tmp_subject);
1794   
1795    $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1796    $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." ÍÍ");
1797
1798
1799    // Á÷¿®¥Õ¥é¥°:true¤Î¾ì¹ç¤Ï¡¢Á÷¿®¤¹¤ë¡£
1800    if($send) {
1801        if ($objSendMail->sendMail()) {
1802            sfSaveMailHistory($order_id, $template_id, $tosubject, $body);
1803        }
1804    }
1805    return $objSendMail;
1806}
1807
1808// ¥Æ¥ó¥×¥ì¡¼¥È¤ò»ÈÍѤ·¤¿¥á¡¼¥ë¤ÎÁ÷¿®
1809function sfSendTplMail($to, $subject, $tplpath, $objPage) {
1810    $objMailView = new SC_SiteView();
1811    $objSiteInfo = new SC_SiteInfo();
1812    $arrInfo = $objSiteInfo->data;
1813    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1814    $objPage->tpl_shopname=$arrInfo['shop_name'];
1815    $objPage->tpl_infoemail = $arrInfo['email02'];
1816    $objMailView->assignobj($objPage);
1817    $body = $objMailView->fetch($tplpath);
1818    // ¥á¡¼¥ëÁ÷¿®½èÍý
1819    $objSendMail = new GC_SendMail();
1820    $to = mb_encode_mimeheader($to);
1821    $bcc = $arrInfo['email01'];
1822    $from = $arrInfo['email03'];
1823    $error = $arrInfo['email04'];
1824    $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1825    $objSendMail->sendMail();   
1826}
1827
1828// Ä̾ï¤Î¥á¡¼¥ëÁ÷¿®
1829function sfSendMail($to, $subject, $body) {
1830    $objSiteInfo = new SC_SiteInfo();
1831    $arrInfo = $objSiteInfo->data;
1832    // ¥á¡¼¥ëÁ÷¿®½èÍý
1833    $objSendMail = new GC_SendMail();
1834    $bcc = $arrInfo['email01'];
1835    $from = $arrInfo['email03'];
1836    $error = $arrInfo['email04'];
1837    $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1838    $objSendMail->sendMail();
1839}
1840
1841//·ï̾¤Ë¥Æ¥ó¥×¥ì¡¼¥È¤òÍѤ¤¤ë
1842function sfMakeSubject($subject){
1843   
1844    $objQuery = new SC_Query();
1845    $objMailView = new SC_SiteView();
1846    $objPage = new LC_Page();
1847   
1848    $arrInfo = $objQuery->select("*","dtb_baseinfo");
1849    $arrInfo = $arrInfo[0];
1850    $objPage->tpl_shopname=$arrInfo['shop_name'];
1851    $objPage->tpl_infoemail=$subject;
1852    $objMailView->assignobj($objPage);
1853    $mailtitle = $objMailView->fetch('mail_templates/mail_title.tpl');
1854    $ret = $mailtitle.$subject;
1855    return $ret;
1856}
1857
1858// ¥á¡¼¥ëÇÛ¿®ÍúÎò¤Ø¤ÎÅÐÏ¿
1859function sfSaveMailHistory($order_id, $template_id, $subject, $body) {
1860    $sqlval['subject'] = $subject;
1861    $sqlval['order_id'] = $order_id;
1862    $sqlval['template_id'] = $template_id;
1863    $sqlval['send_date'] = "Now()";
1864    if($_SESSION['member_id'] != "") {
1865        $sqlval['creator_id'] = $_SESSION['member_id'];
1866    } else {
1867        $sqlval['creator_id'] = '0';
1868    }
1869    $sqlval['mail_body'] = $body;
1870   
1871    $objQuery = new SC_Query();
1872    $objQuery->insert("dtb_mail_history", $sqlval);
1873}
1874
1875/* ²ñ°÷¾ðÊó¤ò°ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤Ø */
1876function sfGetCustomerSqlVal($uniqid, $sqlval) {
1877    $objCustomer = new SC_Customer();
1878    // ²ñ°÷¾ðÊóÅÐÏ¿½èÍý
1879    if ($objCustomer->isLoginSuccess()) {
1880        // ÅÐÏ¿¥Ç¡¼¥¿¤ÎºîÀ®
1881        $sqlval['order_temp_id'] = $uniqid;
1882        $sqlval['update_date'] = 'Now()';
1883        $sqlval['customer_id'] = $objCustomer->getValue('customer_id');
1884        $sqlval['order_name01'] = $objCustomer->getValue('name01');
1885        $sqlval['order_name02'] = $objCustomer->getValue('name02');
1886        $sqlval['order_kana01'] = $objCustomer->getValue('kana01');
1887        $sqlval['order_kana02'] = $objCustomer->getValue('kana02');
1888        $sqlval['order_sex'] = $objCustomer->getValue('sex');
1889        $sqlval['order_zip01'] = $objCustomer->getValue('zip01');
1890        $sqlval['order_zip02'] = $objCustomer->getValue('zip02');
1891        $sqlval['order_pref'] = $objCustomer->getValue('pref');
1892        $sqlval['order_addr01'] = $objCustomer->getValue('addr01');
1893        $sqlval['order_addr02'] = $objCustomer->getValue('addr02');
1894        $sqlval['order_tel01'] = $objCustomer->getValue('tel01');
1895        $sqlval['order_tel02'] = $objCustomer->getValue('tel02');
1896        $sqlval['order_tel03'] = $objCustomer->getValue('tel03');
1897        if (defined('MOBILE_SITE')) {
1898            $sqlval['order_email'] = $objCustomer->getValue('email_mobile');
1899        } else {
1900            $sqlval['order_email'] = $objCustomer->getValue('email');
1901        }
1902        $sqlval['order_job'] = $objCustomer->getValue('job');
1903        $sqlval['order_birth'] = $objCustomer->getValue('birth');
1904    }
1905    return $sqlval;
1906}
1907
1908// ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤Ø¤Î½ñ¤­¹þ¤ß½èÍý
1909function sfRegistTempOrder($uniqid, $sqlval) {
1910    if($uniqid != "") {
1911        // ´û¸¥Ç¡¼¥¿¤Î¥Á¥§¥Ã¥¯
1912        $objQuery = new SC_Query();
1913        $where = "order_temp_id = ?";
1914        $cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid));
1915        // ´û¸¥Ç¡¼¥¿¤¬¤Ê¤¤¾ì¹ç
1916        if ($cnt == 0) {
1917            // ½é²ó½ñ¤­¹þ¤ß»þ¤Ë²ñ°÷¤ÎÅÐÏ¿ºÑ¤ß¾ðÊó¤ò¼è¤ê¹þ¤à
1918            $sqlval = sfGetCustomerSqlVal($uniqid, $sqlval);
1919            $sqlval['create_date'] = "now()";
1920            $objQuery->insert("dtb_order_temp", $sqlval);
1921        } else {
1922            $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid));
1923        }
1924    }
1925}
1926
1927/* ²ñ°÷¤Î¥á¥ë¥Þ¥¬ÅÐÏ¿¤¬¤¢¤ë¤«¤É¤¦¤«¤Î¥Á¥§¥Ã¥¯(²¾²ñ°÷¤ò´Þ¤Þ¤Ê¤¤) */
1928function sfCheckCustomerMailMaga($email) {
1929    $col = "email, mailmaga_flg, customer_id";
1930    $from = "dtb_customer";
1931    $where = "email = ? AND status = 2";
1932    $objQuery = new SC_Query();
1933    $arrRet = $objQuery->select($col, $from, $where, array($email));
1934    // ²ñ°÷¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë
1935    if($arrRet[0]['customer_id'] != "") {
1936        return true;
1937    }
1938    return false;
1939}
1940
1941// ¥«¡¼¥É¤Î½èÍý·ë²Ì¤òÊÖ¤¹
1942function sfGetAuthonlyResult($dir, $file_name, $name01, $name02, $card_no, $card_exp, $amount, $order_id, $jpo_info = "10"){
1943
1944    $path = $dir .$file_name;       // cgi¥Õ¥¡¥¤¥ë¤Î¥Õ¥ë¥Ñ¥¹À¸À®
1945    $now_dir = getcwd();            // require¤¬¤¦¤Þ¤¯¤¤¤«¤Ê¤¤¤Î¤Ç¡¢cgi¼Â¹Ô¥Ç¥£¥ì¥¯¥È¥ê¤Ë°ÜÆ°¤¹¤ë
1946    chdir($dir);
1947   
1948    // ¥Ñ¥¤¥×ÅϤ·¤Ç¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤écgiµ¯Æ°
1949    $cmd = "$path card_no=$card_no name01=$name01 name02=$name02 card_exp=$card_exp amount=$amount order_id=$order_id jpo_info=$jpo_info";
1950
1951    $tmpResult = popen($cmd, "r");
1952   
1953    // ·ë²Ì¼èÆÀ
1954    while( ! FEOF ( $tmpResult ) ) {
1955        $result .= FGETS($tmpResult);
1956    }
1957    pclose($tmpResult);             //  ¥Ñ¥¤¥×¤òÊĤ¸¤ë
1958    chdir($now_dir);                //¡¡¸µ¤Ë¤¤¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Ëµ¢¤ë
1959   
1960    // ·ë²Ì¤òÏ¢ÁÛÇÛÎó¤Ø³ÊǼ
1961    $result = ereg_replace("&$", "", $result);
1962    foreach (explode("&",$result) as $data) {
1963        list($key, $val) = explode("=", $data, 2);
1964        $return[$key] = $val;
1965    }
1966   
1967    return $return;
1968}
1969
1970// ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¾ðÊó¤ò¼èÆÀ¤¹¤ë
1971function sfGetOrderTemp($order_temp_id) {
1972    $objQuery = new SC_Query();
1973    $where = "order_temp_id = ?";
1974    $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id));
1975    return $arrRet[0];
1976}
1977
1978// ¥«¥Æ¥´¥êID¼èÆÀȽÄêÍѤΥ°¥í¡¼¥Ð¥ëÊÑ¿ô(°ìÅÙ¼èÆÀ¤µ¤ì¤Æ¤¤¤¿¤éºÆ¼èÆÀ¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë)
1979$g_category_on = false;
1980$g_category_id = "";
1981
1982/* ÁªÂòÃæ¤Î¥«¥Æ¥´¥ê¤ò¼èÆÀ¤¹¤ë */
1983function sfGetCategoryId($product_id, $category_id) {
1984    global $g_category_on;
1985    global $g_category_id;
1986    if(!$g_category_on) {
1987        $g_category_on = true;
1988        $category_id = (int) $category_id;
1989        $product_id = (int) $product_id;
1990        if(sfIsInt($category_id) && sfIsRecord("dtb_category","category_id", $category_id)) {
1991            $g_category_id = $category_id;
1992        } else if (sfIsInt($product_id) && sfIsRecord("dtb_products","product_id", $product_id, "status = 1")) {
1993            $objQuery = new SC_Query();
1994            $where = "product_id = ?";
1995            $category_id = $objQuery->get("dtb_products", "category_id", $where, array($product_id));
1996            $g_category_id = $category_id;
1997        } else {
1998            // ÉÔÀµ¤Ê¾ì¹ç¤Ï¡¢0¤òÊÖ¤¹¡£
1999            $g_category_id = 0;
2000        }
2001    }
2002    return $g_category_id;
2003}
2004
2005// ROOTID¼èÆÀȽÄêÍѤΥ°¥í¡¼¥Ð¥ëÊÑ¿ô(°ìÅÙ¼èÆÀ¤µ¤ì¤Æ¤¤¤¿¤éºÆ¼èÆÀ¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë)
2006$g_root_on = false;
2007$g_root_id = "";
2008
2009/* ÁªÂòÃæ¤Î¥¢¥¤¥Æ¥à¤Î¥ë¡¼¥È¥«¥Æ¥´¥êID¤ò¼èÆÀ¤¹¤ë */
2010function sfGetRootId() {
2011    global $g_root_on;
2012    global $g_root_id;
2013    if(!$g_root_on) {
2014        $g_root_on = true;
2015        $objQuery = new SC_Query();
2016        if($_GET['product_id'] != "" || $_GET['category_id'] != "") {
2017            // ÁªÂòÃæ¤Î¥«¥Æ¥´¥êID¤òȽÄꤹ¤ë
2018            $category_id = sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
2019            // ROOT¥«¥Æ¥´¥êID¤Î¼èÆÀ
2020             $arrRet = sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
2021             $root_id = $arrRet[0];
2022        } else {
2023            // ROOT¥«¥Æ¥´¥êID¤ò¤Ê¤·¤ËÀßÄꤹ¤ë
2024            $root_id = "";
2025        }
2026        $g_root_id = $root_id;
2027    }
2028    return $g_root_id;
2029}
2030
2031/* ¥«¥Æ¥´¥ê¤«¤é¾¦Éʤò¸¡º÷¤¹¤ë¾ì¹ç¤ÎWHEREʸ¤ÈÃͤòÊÖ¤¹ */
2032function sfGetCatWhere($category_id) {
2033    // »Ò¥«¥Æ¥´¥êID¤Î¼èÆÀ
2034    $arrRet = sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id);
2035    $tmp_where = "";
2036    foreach ($arrRet as $val) {
2037        if($tmp_where == "") {
2038            $tmp_where.= " category_id IN ( ?";
2039        } else {
2040            $tmp_where.= ",? ";
2041        }
2042        $arrval[] = $val;
2043    }
2044    $tmp_where.= " ) ";
2045    return array($tmp_where, $arrval);
2046}
2047
2048/* ²Ã»»¥Ý¥¤¥ó¥È¤Î·×»»¼° */
2049function sfGetAddPoint($totalpoint, $use_point, $arrInfo) {
2050    // ¹ØÆþ¾¦Éʤιç·×¥Ý¥¤¥ó¥È¤«¤éÍøÍѤ·¤¿¥Ý¥¤¥ó¥È¤Î¥Ý¥¤¥ó¥È´¹»»²ÁÃͤò°ú¤¯Êý¼°
2051    $add_point = $totalpoint - intval($use_point * ($arrInfo['point_rate'] / 100));
2052   
2053    if($add_point < 0) {
2054        $add_point = '0';
2055    }
2056    return $add_point;
2057}
2058
2059/* °ì°Õ¤«¤Äͽ¬¤µ¤ì¤Ë¤¯¤¤ID */
2060function sfGetUniqRandomId($head = "") {
2061    // ͽ¬¤µ¤ì¤Ê¤¤¤è¤¦¤Ë¥é¥ó¥À¥àʸ»úÎó¤òÉÕÍ¿¤¹¤ë¡£
2062    $random = gfMakePassword(8);
2063    // Ʊ°ì¥Û¥¹¥ÈÆâ¤Ç°ì°Õ¤ÊID¤òÀ¸À®
2064    $id = uniqid($head);
2065    return ($id . $random);
2066}
2067
2068// ¥«¥Æ¥´¥êÊÌ¥ª¥¹¥¹¥áÉʤμèÆÀ
2069function sfGetBestProducts( $conn, $category_id = 0){
2070    // ´û¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ëÆâÍƤò¼èÆÀ¤¹¤ë
2071    $sql = "SELECT name, main_image, main_list_image, price01_min, price01_max, price02_min, price02_max, point_rate,
2072             A.product_id, A.comment FROM dtb_best_products as A LEFT JOIN vw_products_allclass AS allcls
2073            USING (product_id) WHERE A.category_id = ? AND A.del_flg = 0 AND status = 1 ORDER BY A.rank";
2074    $arrItems = $conn->getAll($sql, array($category_id));
2075
2076    return $arrItems;
2077}
2078
2079// ÆüìÀ©¸æʸ»ú¤Î¼êÆ°¥¨¥¹¥±¡¼¥×
2080function sfManualEscape($data) {
2081    // ÇÛÎó¤Ç¤Ê¤¤¾ì¹ç
2082    if(!is_array($data)) {
2083        if (DB_TYPE == "pgsql") {
2084            $ret = pg_escape_string($data);
2085        }else if(DB_TYPE == "mysql"){
2086            $ret = mysql_real_escape_string($data);
2087        }
2088        $ret = ereg_replace("%", "\\%", $ret);
2089        $ret = ereg_replace("_", "\\_", $ret);
2090        return $ret;
2091    }
2092   
2093    // ÇÛÎó¤Î¾ì¹ç
2094    foreach($data as $val) {
2095        if (DB_TYPE == "pgsql") {
2096            $ret = pg_escape_string($val);
2097        }else if(DB_TYPE == "mysql"){
2098            $ret = mysql_real_escape_string($val);
2099        }
2100
2101        $ret = ereg_replace("%", "\\%", $ret);
2102        $ret = ereg_replace("_", "\\_", $ret);
2103        $arrRet[] = $ret;
2104    }
2105
2106    return $arrRet;
2107}
2108
2109// ¼õÃíÈֹ桢ÍøÍѥݥ¤¥ó¥È¡¢²Ã»»¥Ý¥¤¥ó¥È¤«¤éºÇ½ª¥Ý¥¤¥ó¥È¤ò¼èÆÀ
2110function sfGetCustomerPoint($order_id, $use_point, $add_point) {
2111    $objQuery = new SC_Query();
2112    $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id));
2113    $customer_id = $arrRet[0]['customer_id'];
2114    if($customer_id != "" && $customer_id >= 1) {
2115        $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
2116        $point = $arrRet[0]['point'];
2117        $total_point = $arrRet[0]['point'] - $use_point + $add_point;
2118    } else {
2119        $total_point = "";
2120        $point = "";
2121    }
2122    return array($point, $total_point);
2123}
2124
2125/* ¥É¥á¥¤¥ó´Ö¤ÇÍ­¸ú¤Ê¥»¥Ã¥·¥ç¥ó¤Î¥¹¥¿¡¼¥È */
2126function sfDomainSessionStart() {
2127    $ret = session_id();
2128/*
2129    ¥Ø¥Ã¥À¡¼¤òÁ÷¿®¤·¤Æ¤¤¤Æ¤âsession_start()¤¬É¬Íפʥڡ¼¥¸¤¬¤¢¤ë¤Î¤Ç
2130    ¥³¥á¥ó¥È¥¢¥¦¥È¤·¤Æ¤ª¤¯
2131    if($ret == "" && !headers_sent()) {
2132*/
2133    if($ret == "") {
2134        /* ¥»¥Ã¥·¥ç¥ó¥Ñ¥é¥á¡¼¥¿¤Î»ØÄê
2135         ¡¦¥Ö¥é¥¦¥¶¤òÊĤ¸¤ë¤Þ¤ÇÍ­¸ú
2136         ¡¦¤¹¤Ù¤Æ¤Î¥Ñ¥¹¤ÇÍ­¸ú
2137         ¡¦Æ±¤¸¥É¥á¥¤¥ó´Ö¤Ç¶¦Í­ */
2138        session_set_cookie_params (0, "/", DOMAIN_NAME);
2139
2140        if(!ini_get("session.auto_start")){
2141            // ¥»¥Ã¥·¥ç¥ó³«»Ï
2142            session_start();
2143        }
2144    }
2145}
2146
2147/* ʸ»úÎó¤Ë¶¯À©Åª¤Ë²þ¹Ô¤òÆþ¤ì¤ë */
2148function sfPutBR($str, $size) {
2149    $i = 0;
2150    $cnt = 0;
2151    $line = array();
2152    $ret = "";
2153   
2154    while($str[$i] != "") {
2155        $line[$cnt].=$str[$i];
2156        $i++;
2157        if(strlen($line[$cnt]) > $size) {
2158            $line[$cnt].="<br />";
2159            $cnt++;
2160        }
2161    }
2162   
2163    foreach($line as $val) {
2164        $ret.=$val;
2165    }
2166    return $ret;
2167}
2168
2169// Æó²ó°Ê¾å·«¤êÊÖ¤µ¤ì¤Æ¤¤¤ë¥¹¥é¥Ã¥·¥å[/]¤ò°ì¤Ä¤ËÊÑ´¹¤¹¤ë¡£
2170function sfRmDupSlash($istr){
2171    if(ereg("^http://", $istr)) {
2172        $str = substr($istr, 7);
2173        $head = "http://";
2174    } else if(ereg("^https://", $istr)) {
2175        $str = substr($istr, 8);
2176        $head = "https://";
2177    } else {
2178        $str = $istr;
2179    }
2180    $str = ereg_replace("[/]+", "/", $str);
2181    $ret = $head . $str;
2182    return $ret;   
2183}
2184
2185function sfEncodeFile($filepath, $enc_type, $out_dir) {
2186    $ifp = fopen($filepath, "r");
2187   
2188    $basename = basename($filepath);
2189    $outpath = $out_dir . "enc_" . $basename;
2190   
2191    $ofp = fopen($outpath, "w+");
2192   
2193    while(!feof($ifp)) {
2194        $line = fgets($ifp);
2195        $line = mb_convert_encoding($line, $enc_type, "auto");
2196        fwrite($ofp,  $line);
2197    }
2198   
2199    fclose($ofp);
2200    fclose($ifp);
2201   
2202    return  $outpath;
2203}
2204
2205function sfCutString($str, $len, $byte = true, $commadisp = true) {
2206    if($byte) {
2207        if(strlen($str) > ($len + 2)) {
2208            $ret =substr($str, 0, $len);
2209            $cut = substr($str, $len);
2210        } else {
2211            $ret = $str;
2212            $commadisp = false;
2213        }
2214    } else {
2215        if(mb_strlen($str) > ($len + 1)) {
2216            $ret = mb_substr($str, 0, $len);
2217            $cut = mb_substr($str, $len);
2218        } else {
2219            $ret = $str;
2220            $commadisp = false;
2221        }
2222    }
2223
2224    // ³¨Ê¸»ú¥¿¥°¤ÎÅÓÃæ¤ÇʬÃǤµ¤ì¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£
2225    if (isset($cut)) {
2226        // ʬ³ä°ÌÃÖ¤è¤êÁ°¤ÎºÇ¸å¤Î [ °Ê¹ß¤ò¼èÆÀ¤¹¤ë¡£
2227        $head = strrchr($ret, '[');
2228
2229        // ʬ³ä°ÌÃÖ¤è¤ê¸å¤ÎºÇ½é¤Î ] °ÊÁ°¤ò¼èÆÀ¤¹¤ë¡£
2230        $tail_pos = strpos($cut, ']');
2231        if ($tail_pos !== false) {
2232            $tail = substr($cut, 0, $tail_pos + 1);
2233        }
2234
2235        // ʬ³ä°ÌÃÖ¤è¤êÁ°¤Ë [¡¢¸å¤Ë ] ¤¬¸«¤Ä¤«¤Ã¤¿¾ì¹ç¤Ï¡¢[ ¤«¤é ] ¤Þ¤Ç¤ò
2236        // Àܳ¤·¤Æ³¨Ê¸»ú¥¿¥°1¸Äʬ¤Ë¤Ê¤ë¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¡£
2237        if ($head !== false && $tail_pos !== false) {
2238            $subject = $head . $tail;
2239            if (preg_match('/^\[emoji:e?\d+\]$/', $subject)) {
2240                // ³¨Ê¸»ú¥¿¥°¤¬¸«¤Ä¤«¤Ã¤¿¤Î¤Çºï½ü¤¹¤ë¡£
2241                $ret = substr($ret, 0, -strlen($head));
2242            }
2243        }
2244    }
2245
2246    if($commadisp){
2247        $ret = $ret . "...";
2248    }
2249    return $ret;
2250}
2251
2252// ǯ¡¢·î¡¢Äù¤áÆü¤«¤é¡¢Àè·î¤ÎÄù¤áÆü+1¡¢º£·î¤ÎÄù¤áÆü¤òµá¤á¤ë¡£
2253function sfTermMonth($year, $month, $close_day) {
2254    $end_year = $year;
2255    $end_month = $month;
2256   
2257    // ³«»Ï·î¤¬½ªÎ»·î¤ÈƱ¤¸¤«Èݤ«
2258    $same_month = false;
2259   
2260    // ³ºÅö·î¤ÎËöÆü¤òµá¤á¤ë¡£
2261    $end_last_day = date("d", mktime(0, 0, 0, $month + 1, 0, $year));
2262   
2263    // ·î¤ÎËöÆü¤¬Äù¤áÆü¤è¤ê¾¯¤Ê¤¤¾ì¹ç
2264    if($end_last_day < $close_day) {
2265        // Äù¤áÆü¤ò·îËöÆü¤Ë¹ç¤ï¤»¤ë
2266        $end_day = $end_last_day;
2267    } else {
2268        $end_day = $close_day;
2269    }
2270   
2271    // Á°·î¤Î¼èÆÀ
2272    $tmp_year = date("Y", mktime(0, 0, 0, $month, 0, $year));
2273    $tmp_month = date("m", mktime(0, 0, 0, $month, 0, $year));
2274    // Á°·î¤ÎËöÆü¤òµá¤á¤ë¡£
2275    $start_last_day = date("d", mktime(0, 0, 0, $month, 0, $year));
2276   
2277    // Á°·î¤ÎËöÆü¤¬Äù¤áÆü¤è¤ê¾¯¤Ê¤¤¾ì¹ç
2278    if ($start_last_day < $close_day) {
2279        // ·îËöÆü¤Ë¹ç¤ï¤»¤ë
2280        $tmp_day = $start_last_day;
2281    } else {
2282        $tmp_day = $close_day;
2283    }
2284   
2285    // Àè·î¤ÎËöÆü¤ÎÍâÆü¤ò¼èÆÀ¤¹¤ë
2286    $start_year = date("Y", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2287    $start_month = date("m", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2288    $start_day = date("d", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2289   
2290    // ÆüÉդκîÀ®
2291    $start_date = sprintf("%d/%d/%d 00:00:00", $start_year, $start_month, $start_day);
2292    $end_date = sprintf("%d/%d/%d 23:59:59", $end_year, $end_month, $end_day);
2293   
2294    return array($start_date, $end_date);
2295}
2296
2297// PDFÍѤÎRGB¥«¥é¡¼¤òÊÖ¤¹
2298function sfGetPdfRgb($hexrgb) {
2299    $hex = substr($hexrgb, 0, 2);
2300    $r = hexdec($hex) / 255;
2301   
2302    $hex = substr($hexrgb, 2, 2);
2303    $g = hexdec($hex) / 255;
2304   
2305    $hex = substr($hexrgb, 4, 2);
2306    $b = hexdec($hex) / 255;
2307   
2308    return array($r, $g, $b);   
2309}
2310
2311//¥á¥ë¥Þ¥¬²¾ÅÐÏ¿¤È¥á¡¼¥ëÇÛ¿®
2312function sfRegistTmpMailData($mail_flag, $email){
2313    $objQuery = new SC_Query();
2314    $objConn = new SC_DBConn();
2315    $objPage = new LC_Page();
2316   
2317    $random_id = sfGetUniqRandomId();
2318    $arrRegistMailMagazine["mail_flag"] = $mail_flag;
2319    $arrRegistMailMagazine["email"] = $email;
2320    $arrRegistMailMagazine["temp_id"] =$random_id;
2321    $arrRegistMailMagazine["end_flag"]='0';
2322    $arrRegistMailMagazine["update_date"] = 'now()';
2323   
2324    //¥á¥ë¥Þ¥¬²¾ÅÐÏ¿Íѥե饰
2325    $flag = $objQuery->count("dtb_customer_mail_temp", "email=?", array($email));
2326    $objConn->query("BEGIN");
2327    switch ($flag){
2328        case '0':
2329        $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine);
2330        break;
2331   
2332        case '1':
2333        $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine, "email = '" .addslashes($email). "'");
2334        break;
2335    }
2336    $objConn->query("COMMIT");
2337    $subject = sfMakeSubject('¥á¥ë¥Þ¥¬²¾ÅÐÏ¿¤¬´°Î»¤·¤Þ¤·¤¿¡£');
2338    $objPage->tpl_url = SSL_URL."mailmagazine/regist.php?temp_id=".$arrRegistMailMagazine['temp_id'];
2339    switch ($mail_flag){
2340        case '1':
2341        $objPage->tpl_name = "ÅÐÏ¿";
2342        $objPage->tpl_kindname = "HTML";
2343        break;
2344       
2345        case '2':
2346        $objPage->tpl_name = "ÅÐÏ¿";
2347        $objPage->tpl_kindname = "¥Æ¥­¥¹¥È";
2348        break;
2349       
2350        case '3':
2351        $objPage->tpl_name = "²ò½ü";
2352        break;
2353    }
2354        $objPage->tpl_email = $email;
2355    sfSendTplMail($email, $subject, 'mail_templates/mailmagazine_temp.tpl', $objPage);
2356}
2357
2358// ºÆµ¢Åª¤Ë¿ÃÊÇÛÎó¤ò¸¡º÷¤·¤Æ°ì¼¡¸µÇÛÎó(Hidden°úÅϤ·ÍÑÇÛÎó)¤ËÊÑ´¹¤¹¤ë¡£
2359function sfMakeHiddenArray($arrSrc, $arrDst = array(), $parent_key = "") {
2360    if(is_array($arrSrc)) {
2361        foreach($arrSrc as $key => $val) {
2362            if($parent_key != "") {
2363                $keyname = $parent_key . "[". $key . "]";
2364            } else {
2365                $keyname = $key;
2366            }
2367            if(is_array($val)) {
2368                $arrDst = sfMakeHiddenArray($val, $arrDst, $keyname);
2369            } else {
2370                $arrDst[$keyname] = $val;
2371            }
2372        }
2373    }
2374    return $arrDst;
2375}
2376
2377// DB¼èÆÀÆü»þ¤ò¥¿¥¤¥à¤ËÊÑ´¹
2378function sfDBDatetoTime($db_date) {
2379    $date = ereg_replace("\..*$","",$db_date);
2380    $time = strtotime($date);
2381    return $time;
2382}
2383
2384// ½ÐÎϤκݤ˥ƥó¥×¥ì¡¼¥È¤òÀÚ¤êÂؤ¨¤é¤ì¤ë
2385/*
2386    index.php?tpl=test.tpl
2387*/
2388function sfCustomDisplay($objPage, $is_mobile = false) {
2389    $basename = basename($_SERVER["REQUEST_URI"]);
2390
2391    if($basename == "") {
2392        $path = $_SERVER["REQUEST_URI"] . "index.php";
2393    } else {
2394        $path = $_SERVER["REQUEST_URI"];
2395    }   
2396
2397    if($_GET['tpl'] != "") {
2398        $tpl_name = $_GET['tpl'];
2399    } else {
2400        $tpl_name = ereg_replace("^/", "", $path);
2401        $tpl_name = ereg_replace("/", "_", $tpl_name);
2402        $tpl_name = ereg_replace("(\.php$|\.html$)", ".tpl", $tpl_name);
2403    }
2404
2405    $template_path = TEMPLATE_FTP_DIR . $tpl_name;
2406
2407    if($is_mobile === true) {
2408        $objView = new SC_MobileView();         
2409        $objView->assignobj($objPage);
2410        $objView->display(SITE_FRAME);     
2411    } else if(file_exists($template_path)) {
2412        $objView = new SC_UserView(TEMPLATE_FTP_DIR, COMPILE_FTP_DIR);
2413        $objView->assignobj($objPage);
2414        $objView->display($tpl_name);
2415    } else {
2416        $objView = new SC_SiteView();
2417        $objView->assignobj($objPage);
2418        $objView->display(SITE_FRAME);
2419    }
2420}
2421
2422//²ñ°÷ÊÔ½¸ÅÐÏ¿½èÍý
2423function sfEditCustomerData($array, $arrRegistColumn) {
2424    $objQuery = new SC_Query();
2425   
2426    foreach ($arrRegistColumn as $data) {
2427        if ($data["column"] != "password") {
2428            if($array[ $data['column'] ] != "") {
2429                $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
2430            } else {
2431                $arrRegist[ $data['column'] ] = NULL;
2432            }
2433        }
2434    }
2435    if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) {
2436        $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00";
2437    } else {
2438        $arrRegist["birth"] = NULL;
2439    }
2440
2441    //-- ¥Ñ¥¹¥ï¡¼¥É¤Î¹¹¿·¤¬¤¢¤ë¾ì¹ç¤Ï°Å¹æ²½¡£¡Ê¹¹¿·¤¬¤Ê¤¤¾ì¹ç¤ÏUPDATEʸ¤ò¹½À®¤·¤Ê¤¤¡Ë
2442    if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC);
2443    $arrRegist["update_date"] = "NOW()";
2444   
2445    //-- ÊÔ½¸ÅÐÏ¿¼Â¹Ô
2446    if (defined('MOBILE_SITE')) {
2447        $arrRegist['email_mobile'] = $arrRegist['email'];
2448        unset($arrRegist['email']);
2449    }
2450    $objQuery->begin();
2451    $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id']));
2452    $objQuery->commit();
2453}
2454
2455// PHP¤Îmb_convert_encoding´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2456function sf_mb_convert_encoding($str, $encode = 'CHAR_CODE') {
2457    return  mb_convert_encoding($str, $encode);
2458}   
2459
2460// PHP¤Îmktime´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2461function sf_mktime($format, $hour=0, $minute=0, $second=0, $month=1, $day=1, $year=1999) {
2462    return  date($format,mktime($hour, $minute, $second, $month, $day, $year));
2463}   
2464
2465// PHP¤Îdate´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2466function sf_date($format, $timestamp = '') {
2467    return  date( $format, $timestamp);
2468}
2469
2470// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤Î·¿¤òÊÑ´¹¤¹¤ë
2471function sfChangeCheckBox($data , $tpl = false){
2472    if ($tpl) {
2473        if ($data == 1){
2474            return 'checked';
2475        }else{
2476            return "";
2477        }
2478    }else{
2479        if ($data == "on"){
2480            return 1;
2481        }else{
2482            return 2;
2483        }
2484    }
2485}
2486
2487function sfCategory_Count($objQuery){
2488    $sql = "";
2489   
2490    //¥Æ¡¼¥Ö¥ëÆâÍƤκï½ü
2491    $objQuery->query("DELETE FROM dtb_category_count");
2492    $objQuery->query("DELETE FROM dtb_category_total_count");
2493   
2494    //³Æ¥«¥Æ¥´¥êÆâ¤Î¾¦ÉÊ¿ô¤ò¿ô¤¨¤Æ³ÊǼ
2495    $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) ";
2496    $sql .= " SELECT T1.category_id, count(T2.category_id), now() FROM dtb_category AS T1 LEFT JOIN dtb_products AS T2 ";
2497    $sql .= " ON T1.category_id = T2.category_id  ";
2498    $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 ";
2499    $sql .= " GROUP BY T1.category_id, T2.category_id ";
2500    $objQuery->query($sql);
2501   
2502    //»Ò¥«¥Æ¥´¥êÆâ¤Î¾¦ÉÊ¿ô¤ò½¸·×¤¹¤ë
2503    $arrCat = $objQuery->getAll("SELECT * FROM dtb_category");
2504   
2505    $sql = "";
2506    foreach($arrCat as $key => $val){
2507       
2508        // »ÒID°ìÍ÷¤ò¼èÆÀ
2509        $arrRet = sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']);
2510        $line = sfGetCommaList($arrRet);
2511       
2512        $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) ";
2513        $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count ";
2514        $sql .= " WHERE category_id IN (" . $line . ")";
2515               
2516        $objQuery->query($sql, array($val['category_id']));
2517    }
2518}
2519
2520// 2¤Ä¤ÎÇÛÎó¤òÍѤ¤¤ÆÏ¢ÁÛÇÛÎó¤òºîÀ®¤¹¤ë
2521function sfarrCombine($arrKeys, $arrValues) {
2522
2523    if(count($arrKeys) <= 0 and count($arrValues) <= 0) return array();
2524   
2525    $keys = array_values($arrKeys);
2526    $vals = array_values($arrValues);
2527   
2528    $max = max( count( $keys ), count( $vals ) );
2529    $combine_ary = array();
2530    for($i=0; $i<$max; $i++) {
2531        $combine_ary[$keys[$i]] = $vals[$i];
2532    }
2533    if(is_array($combine_ary)) return $combine_ary;
2534   
2535    return false;
2536}
2537
2538/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤é»ÒIDÇÛÎó¤ò¼èÆÀ¤¹¤ë */
2539function sfGetChildrenArray($table, $pid_name, $id_name, $id) {
2540    $objQuery = new SC_Query();
2541    $col = $pid_name . "," . $id_name;
2542    $arrData = $objQuery->select($col, $table);
2543   
2544    $arrPID = array();
2545    $arrPID[] = $id;
2546    $arrChildren = array();
2547    $arrChildren[] = $id;
2548   
2549    $arrRet = sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID);
2550   
2551    while(count($arrRet) > 0) {
2552        $arrChildren = array_merge($arrChildren, $arrRet);
2553        $arrRet = sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet);
2554    }
2555   
2556    return $arrChildren;
2557}
2558
2559/* ¿ÆIDľ²¼¤Î»ÒID¤ò¤¹¤Ù¤Æ¼èÆÀ¤¹¤ë */
2560function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) {
2561    $arrChildren = array();
2562    $max = count($arrData);
2563   
2564    for($i = 0; $i < $max; $i++) {
2565        foreach($arrPID as $val) {
2566            if($arrData[$i][$pid_name] == $val) {
2567                $arrChildren[] = $arrData[$i][$id_name];
2568            }
2569        }
2570    }   
2571    return $arrChildren;
2572}
2573
2574
2575/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤é¿ÆIDÇÛÎó¤ò¼èÆÀ¤¹¤ë */
2576function sfGetParentsArray($table, $pid_name, $id_name, $id) {
2577    $objQuery = new SC_Query();
2578    $col = $pid_name . "," . $id_name;
2579    $arrData = $objQuery->select($col, $table);
2580   
2581    $arrParents = array();
2582    $arrParents[] = $id;
2583    $child = $id;
2584   
2585    $ret = sfGetParentsArraySub($arrData, $pid_name, $id_name, $child);
2586
2587    while($ret != "") {
2588        $arrParents[] = $ret;
2589        $ret = sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret);
2590    }
2591   
2592    $arrParents = array_reverse($arrParents);
2593   
2594    return $arrParents;
2595}
2596
2597/* »ÒID½ê°¤¹¤ë¿ÆID¤ò¼èÆÀ¤¹¤ë */
2598function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) {
2599    $max = count($arrData);
2600    $parent = "";
2601    for($i = 0; $i < $max; $i++) {
2602        if($arrData[$i][$id_name] == $child) {
2603            $parent = $arrData[$i][$pid_name];
2604            break;
2605        }
2606    }
2607    return $parent;
2608}
2609
2610/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤éÍ¿¤¨¤é¤ì¤¿ID¤Î·»Äï¤ò¼èÆÀ¤¹¤ë */
2611function sfGetBrothersArray($arrData, $pid_name, $id_name, $arrPID) {
2612    $max = count($arrData);
2613   
2614    $arrBrothers = array();
2615    foreach($arrPID as $id) {
2616        // ¿ÆID¤ò¸¡º÷¤¹¤ë
2617        for($i = 0; $i < $max; $i++) {
2618            if($arrData[$i][$id_name] == $id) {
2619                $parent = $arrData[$i][$pid_name];
2620                break;
2621            }
2622        }
2623        // ·»ÄïID¤ò¸¡º÷¤¹¤ë
2624        for($i = 0; $i < $max; $i++) {
2625            if($arrData[$i][$pid_name] == $parent) {
2626                $arrBrothers[] = $arrData[$i][$id_name];
2627            }
2628        }                   
2629    }
2630    return $arrBrothers;
2631}
2632
2633/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤éÍ¿¤¨¤é¤ì¤¿ID¤Îľ°¤Î»Ò¤ò¼èÆÀ¤¹¤ë */
2634function sfGetUnderChildrenArray($arrData, $pid_name, $id_name, $parent) {
2635    $max = count($arrData);
2636   
2637    $arrChildren = array();
2638    // »ÒID¤ò¸¡º÷¤¹¤ë
2639    for($i = 0; $i < $max; $i++) {
2640        if($arrData[$i][$pid_name] == $parent) {
2641            $arrChildren[] = $arrData[$i][$id_name];
2642        }
2643    }                   
2644    return $arrChildren;
2645}
2646
2647
2648// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ
2649function sfGetCatTree($parent_category_id, $count_check = false) {
2650    $objQuery = new SC_Query();
2651    $col = "";
2652    $col .= " cat.category_id,";
2653    $col .= " cat.category_name,";
2654    $col .= " cat.parent_category_id,";
2655    $col .= " cat.level,";
2656    $col .= " cat.rank,";
2657    $col .= " cat.creator_id,";
2658    $col .= " cat.create_date,";
2659    $col .= " cat.update_date,";
2660    $col .= " cat.del_flg, ";
2661    $col .= " ttl.product_count";   
2662    $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";
2663    // ÅÐÏ¿¾¦ÉÊ¿ô¤Î¥Á¥§¥Ã¥¯
2664    if($count_check) {
2665        $where = "del_flg = 0 AND product_count > 0";
2666    } else {
2667        $where = "del_flg = 0";
2668    }
2669    $objQuery->setoption("ORDER BY rank DESC");
2670    $arrRet = $objQuery->select($col, $from, $where);
2671   
2672    $arrParentID = sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
2673   
2674    foreach($arrRet as $key => $array) {
2675        foreach($arrParentID as $val) {
2676            if($array['category_id'] == $val) {
2677                $arrRet[$key]['display'] = 1;
2678                break;
2679            }
2680        }
2681    }
2682
2683    return $arrRet;
2684}
2685
2686// ¿Æ¥«¥Æ¥´¥ê¡¼¤òÏ¢·ë¤·¤¿Ê¸»úÎó¤ò¼èÆÀ¤¹¤ë
2687function sfGetCatCombName($category_id){
2688    // ¾¦Éʤ¬Â°¤¹¤ë¥«¥Æ¥´¥êID¤ò½Ä¤Ë¼èÆÀ
2689    $objQuery = new SC_Query();
2690    $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
2691    $ConbName = "";
2692   
2693    // ¥«¥Æ¥´¥ê¡¼Ì¾¾Î¤ò¼èÆÀ¤¹¤ë
2694    foreach($arrCatID as $key => $val){
2695        $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
2696        $arrVal = array($val);
2697        $CatName = $objQuery->getOne($sql,$arrVal);
2698        $ConbName .= $CatName . ' | ';
2699    }
2700    // ºÇ¸å¤Î ¡Ã ¤ò¥«¥Ã¥È¤¹¤ë
2701    $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2);
2702   
2703    return $ConbName;
2704}
2705
2706// »ØÄꤷ¤¿¥«¥Æ¥´¥ê¡¼ID¤ÎÂ祫¥Æ¥´¥ê¡¼¤ò¼èÆÀ¤¹¤ë
2707function sfGetFirstCat($category_id){
2708    // ¾¦Éʤ¬Â°¤¹¤ë¥«¥Æ¥´¥êID¤ò½Ä¤Ë¼èÆÀ
2709    $objQuery = new SC_Query();
2710    $arrRet = array();
2711    $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
2712    $arrRet['id'] = $arrCatID[0];
2713   
2714    // ¥«¥Æ¥´¥ê¡¼Ì¾¾Î¤ò¼èÆÀ¤¹¤ë
2715    $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
2716    $arrVal = array($arrRet['id']);
2717    $arrRet['name'] = $objQuery->getOne($sql,$arrVal);
2718   
2719    return $arrRet;
2720}
2721
2722//MySQLÍѤÎSQLʸ¤ËÊѹ¹¤¹¤ë
2723function sfChangeMySQL($sql){
2724    // ²þ¹Ô¡¢¥¿¥Ö¤ò1¥¹¥Ú¡¼¥¹¤ËÊÑ´¹
2725    $sql = preg_replace("/[\r\n\t]/"," ",$sql);
2726   
2727    $sql = sfChangeView($sql);      // viewɽ¤ò¥¤¥ó¥é¥¤¥ó¥Ó¥å¡¼¤ËÊÑ´¹¤¹¤ë
2728    $sql = sfChangeILIKE($sql);     // ILIKE¸¡º÷¤òLIKE¸¡º÷¤ËÊÑ´¹¤¹¤ë
2729    $sql = sfChangeRANDOM($sql);    // RANDOM()¤òRAND()¤ËÊÑ´¹¤¹¤ë
2730
2731    return $sql;
2732}
2733
2734// SQL¤ÎÃæ¤Ëview¤¬Â¸ºß¤·¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯¤ò¹Ô¤¦¡£
2735function sfInArray($sql){
2736    global $arrView;
2737
2738    foreach($arrView as $key => $val){
2739        if (strcasecmp($sql, $val) == 0){
2740            $changesql = eregi_replace("($key)", "$val", $sql);
2741            sfInArray($changesql);
2742        }
2743    }
2744    return false;
2745}
2746
2747// SQL¥·¥ó¥°¥ë¥¯¥©¡¼¥ÈÂбþ
2748function sfQuoteSmart($in){
2749   
2750    if (is_int($in) || is_double($in)) {
2751        return $in;
2752    } elseif (is_bool($in)) {
2753        return $in ? 1 : 0;
2754    } elseif (is_null($in)) {
2755        return 'NULL';
2756    } else {
2757        return "'" . str_replace("'", "''", $in) . "'";
2758    }
2759}
2760   
2761// viewɽ¤ò¥¤¥ó¥é¥¤¥ó¥Ó¥å¡¼¤ËÊÑ´¹¤¹¤ë
2762function sfChangeView($sql){
2763    global $arrView;
2764    global $arrViewWhere;
2765   
2766    $arrViewTmp = $arrView;
2767
2768    // view¤Îwhere¤òÊÑ´¹
2769    foreach($arrViewTmp as $key => $val){
2770        $arrViewTmp[$key] = strtr($arrViewTmp[$key], $arrViewWhere);
2771    }
2772   
2773    // view¤òÊÑ´¹
2774    $changesql = strtr($sql, $arrViewTmp);
2775
2776    return $changesql;
2777}
2778
2779// ILIKE¸¡º÷¤òLIKE¸¡º÷¤ËÊÑ´¹¤¹¤ë
2780function sfChangeILIKE($sql){
2781    $changesql = eregi_replace("(ILIKE )", "LIKE BINARY ", $sql);
2782    return $changesql;
2783}
2784
2785// RANDOM()¤òRAND()¤ËÊÑ´¹¤¹¤ë
2786function sfChangeRANDOM($sql){
2787    $changesql = eregi_replace("( RANDOM)", " RAND", $sql);
2788    return $changesql;
2789}
2790
2791// view¤Îwhere¤òÃÖ´¹¤¹¤ë
2792function sfViewWhere($target, $where = "", $arrval = array(), $option = ""){
2793    global $arrViewWhere;
2794    $arrWhere = split("[?]", $where);
2795    $where_tmp = " WHERE " . $arrWhere[0];
2796    for($i = 1; $i < count($arrWhere); $i++){
2797        $where_tmp .= sfQuoteSmart($arrval[$i - 1]) . $arrWhere[$i];
2798    }
2799    $arrViewWhere[$target] = $where_tmp . " " . $option;
2800}
2801
2802// ¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤Î¥Õ¥¡¥¤¥ë¤òºÆµ¢Åª¤Ë¥³¥Ô¡¼
2803function sfCopyDir($src, $des, $mess, $override = false){
2804    if(!is_dir($src)){
2805        return false;
2806    }
2807
2808    $oldmask = umask(0);
2809    $mod= stat($src);
2810   
2811    // ¥Ç¥£¥ì¥¯¥È¥ê¤¬¤Ê¤±¤ì¤ÐºîÀ®¤¹¤ë
2812    if(!file_exists($des)) {
2813        if(!mkdir($des, $mod[2])) {
2814            print("path:" . $des);
2815        }
2816    }
2817   
2818    $fileArray=glob( $src."*" );
2819    foreach( $fileArray as $key => $data_ ){
2820        // CVS´ÉÍý¥Õ¥¡¥¤¥ë¤Ï¥³¥Ô¡¼¤·¤Ê¤¤
2821        if(ereg("/CVS/Entries", $data_)) {
2822            break;
2823        }
2824        if(ereg("/CVS/Repository", $data_)) {
2825            break;
2826        }
2827        if(ereg("/CVS/Root", $data_)) {
2828            break;
2829        }
2830       
2831        mb_ereg("^(.*[\/])(.*)",$data_, $matches);
2832        $data=$matches[2];
2833        if( is_dir( $data_ ) ){
2834            $mess = sfCopyDir( $data_.'/', $des.$data.'/', $mess);
2835        }else{
2836            if(!$override && file_exists($des.$data)) {
2837                $mess.= $des.$data . "¡§¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤¹\n";
2838            } else {
2839                if(@copy( $data_, $des.$data)) {
2840                    $mess.= $des.$data . "¡§¥³¥Ô¡¼À®¸ù\n";
2841                } else {
2842                    $mess.= $des.$data . "¡§¥³¥Ô¡¼¼ºÇÔ\n";
2843                }
2844            }
2845            $mod=stat($data_ );
2846        }
2847    }
2848    umask($oldmask);
2849    return $mess;
2850}
2851
2852// »ØÄꤷ¤¿¥Õ¥©¥ë¥ÀÆâ¤Î¥Õ¥¡¥¤¥ë¤òÁ´¤Æºï½ü¤¹¤ë
2853function sfDelFile($dir){
2854    $dh = opendir($dir);
2855    // ¥Õ¥©¥ë¥ÀÆâ¤Î¥Õ¥¡¥¤¥ë¤òºï½ü
2856    while($file = readdir($dh)){
2857        if ($file == "." or $file == "..") continue;
2858        $del_file = $dir . "/" . $file;
2859        if(is_file($del_file)){
2860            $ret = unlink($dir . "/" . $file);
2861        }else if (is_dir($del_file)){
2862            $ret = sfDelFile($del_file);
2863        }
2864       
2865        if(!$ret){
2866            return $ret;
2867        }
2868    }
2869   
2870    // ÊĤ¸¤ë
2871    closedir($dh);
2872   
2873    // ¥Õ¥©¥ë¥À¤òºï½ü
2874    return rmdir($dir);
2875}
2876
2877/*
2878 * ´Ø¿ô̾¡§sfWriteFile
2879 * °ú¿ô1 ¡§½ñ¤­¹þ¤à¥Ç¡¼¥¿
2880 * °ú¿ô2 ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹
2881 * °ú¿ô3 ¡§½ñ¤­¹þ¤ß¥¿¥¤¥×
2882 * °ú¿ô4 ¡§¥Ñ¡¼¥ß¥Ã¥·¥ç¥ó
2883 * Ìá¤êÃÍ¡§·ë²Ì¥Õ¥é¥° À®¸ù¤Ê¤é true ¼ºÇԤʤé false
2884 * ÀâÌÀ¡¡¡§¥Õ¥¡¥¤¥ë½ñ¤­½Ð¤·
2885 */
2886function sfWriteFile($str, $path, $type, $permission = "") {
2887    //¥Õ¥¡¥¤¥ë¤ò³«¤¯
2888    if (!($file = fopen ($path, $type))) {
2889        return false;
2890    }
2891
2892    //¥Õ¥¡¥¤¥ë¥í¥Ã¥¯
2893    flock ($file, LOCK_EX);
2894    //¥Õ¥¡¥¤¥ë¤Î½ñ¤­¹þ¤ß
2895    fputs ($file, $str);
2896    //¥Õ¥¡¥¤¥ë¥í¥Ã¥¯¤Î²ò½ü
2897    flock ($file, LOCK_UN);
2898    //¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë
2899    fclose ($file);
2900    // ¸¢¸Â¤ò»ØÄê
2901    if($permission != "") {
2902        chmod($path, $permission);
2903    }
2904   
2905    return true;
2906}
2907   
2908function sfFlush($output = " ", $sleep = 0){
2909    // ¼Â¹Ô»þ´Ö¤òÀ©¸Â¤·¤Ê¤¤
2910    set_time_limit(0);
2911    // ½ÐÎϤò¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤·¤Ê¤¤(==ÆüËܸ켫ưÊÑ´¹¤â¤·¤Ê¤¤)
2912    ob_end_clean();
2913   
2914    // IE¤Î¤¿¤á¤Ë256¥Ð¥¤¥È¶õʸ»ú½ÐÎÏ
2915    echo str_pad('',256);
2916   
2917    // ½ÐÎϤϥ֥é¥ó¥¯¤À¤±¤Ç¤â¤¤¤¤¤È»×¤¦
2918    echo $output;
2919    // ½ÐÎϤò¥Õ¥é¥Ã¥·¥å¤¹¤ë
2920    flush();
2921   
2922    ob_end_flush();
2923    ob_start();
2924   
2925    // »þ´Ö¤Î¤«¤«¤ë½èÍý
2926    sleep($sleep);
2927}
2928
2929// @version¤Îµ­ºÜ¤¬¤¢¤ë¥Õ¥¡¥¤¥ë¤«¤é¥Ð¡¼¥¸¥ç¥ó¤ò¼èÆÀ¤¹¤ë¡£
2930function sfGetFileVersion($path) {
2931    if(file_exists($path)) {
2932        $src_fp = fopen($path, "rb");
2933        if($src_fp) {
2934            while (!feof($src_fp)) {
2935                $line = fgets($src_fp);
2936                if(ereg("@version", $line)) {
2937                    $arrLine = split(" ", $line);
2938                    $version = $arrLine[5];
2939                }
2940            }
2941            fclose($src_fp);
2942        }
2943    }
2944    return $version;
2945}
2946
2947// »ØÄꤷ¤¿URL¤ËÂФ·¤ÆPOST¤Ç¥Ç¡¼¥¿¤òÁ÷¿®¤¹¤ë
2948function sfSendPostData($url, $arrData, $arrOkCode = array()){
2949    require_once(DATA_PATH . "module/Request.php");
2950   
2951    // Á÷¿®¥¤¥ó¥¹¥¿¥ó¥¹À¸À®
2952    $req = new HTTP_Request($url);
2953   
2954    $req->addHeader('User-Agent', 'DoCoMo/2.0¡¡P2101V(c100)');
2955    $req->setMethod(HTTP_REQUEST_METHOD_POST);
2956   
2957    // POST¥Ç¡¼¥¿Á÷¿®
2958    $req->addPostDataArray($arrData);
2959   
2960    // ¥¨¥é¡¼¤¬Ìµ¤±¤ì¤Ð¡¢±þÅú¾ðÊó¤ò¼èÆÀ¤¹¤ë
2961    if (!PEAR::isError($req->sendRequest())) {
2962       
2963        // ¥ì¥¹¥Ý¥ó¥¹¥³¡¼¥É¤¬¥¨¥é¡¼È½Äê¤Ê¤é¡¢¶õ¤òÊÖ¤¹
2964        $res_code = $req->getResponseCode();
2965       
2966        if(!in_array($res_code, $arrOkCode)){
2967            $response = "";
2968        }else{
2969            $response = $req->getResponseBody();
2970        }
2971       
2972    } else {
2973        $response = "";
2974    }
2975   
2976    // POST¥Ç¡¼¥¿¥¯¥ê¥¢
2977    $req->clearPostData(); 
2978   
2979    return $response;
2980}
2981
2982/** ¥Ç¥Ð¥Ã¥°ÍÑ´Ø¿ô **/
2983
2984/**
2985 *  ÅϤµ¤ì¤¿ÊÑ¿ô¤òDump¤¹¤ë
2986 *
2987 *  @param  mixed  $obj   Dump¤·¤¿¤¤ÊÑ¿ô
2988 *  @param  string $color ½ÐÎϤ¹¤ë¿§
2989 * 
2990 *  @return void ¤Ê¤·
2991 */
2992function sfPrintR($obj, $color='green') {
2993    if ( DEBUG_MODE === false ) {
2994        return;
2995    }
2996   
2997    $arrColor = array(
2998        'green' => '#00FF00',
2999        'red'   => '#FF0000',
3000        'blue'  => '#0000FF'
3001    );
3002   
3003    if ( empty($arrColor[$color]) ) {
3004        $color = $arrColor['green'];
3005    } else {
3006        $color = $arrColor[$color];
3007    }
3008   
3009    print("<div style='font-size: 12px;color: $color;'>\n");
3010    print("<strong>**¥Ç¥Ð¥Ã¥°Ãæ**</strong><br />\n");
3011    print("<pre>\n");
3012    print_r($obj);
3013    print("</pre>\n");
3014    print("<strong>**¥Ç¥Ð¥Ã¥°Ãæ**</strong></div>\n");
3015}
3016
3017?>
Note: See TracBrowser for help on using the repository browser.