source: temp/trunk/data/lib/slib.php @ 7424

Revision 7424, 70.1 KB checked in by kakinaka, 20 years ago (diff)

* empty log message *

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