source: temp/branches/ec-cube-beta/data/lib/slib.php @ 10856

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