source: temp/trunk/data/lib/slib.php @ 6315

Revision 6315, 69.0 KB checked in by naka, 20 years ago (diff)

* empty log message *

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