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

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