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

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