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

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