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

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