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

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