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

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