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

Revision 340, 74.2 KB checked in by inoue, 19 years ago (diff)

変数未定義(初期化してない)に対応

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