source: branches/dev/data/lib/slib.php @ 11581

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