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

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