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

Revision 8112, 71.0 KB checked in by kakinaka, 20 years ago (diff)

blank

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