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

Revision 9412, 72.1 KB checked in by kakinaka, 20 years ago (diff)

blank

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