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

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

* empty log message *

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